00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00038
00039 #include <avr/pgmspace.h>
00040 #include <string.h>
00041 #include <stdint.h>
00042 #include <stdlib.h>
00043
00044 #include <stdbool.h>
00045 #include <util/crc16.h>
00046 #include <avr/interrupt.h>
00047 #include "transceiver.h"
00048 #include "ioutil.h"
00049 #include "timer.h"
00050 #ifndef SNIFFER_H
00051 #define SNIFFER_H
00052
00053
00054
00055 #define SCAN_PERIOD_MS (2000)
00056 #define NL "\n\r"
00057 #define CHANNEL_OFFSET(x) (x > TRX_MAX_CHANNEL ? TRX_MIN_CHANNEL : (x - TRX_MIN_CHANNEL))
00058 #define CHANNEL_MAX_OFFSET (TRX_NB_CHANNELS-1)
00059 #define VERSION "0.1"
00060
00064 #define CHANNEL_NEXT_CIRCULAR(x) \
00065 do \
00066 { \
00067 (x)++; \
00068 if ((x) > TRX_MAX_CHANNEL) \
00069 { \
00070 (x) = TRX_MIN_CHANNEL; \
00071 } \
00072 } \
00073 while(0)
00074
00075
00079 typedef enum
00080 {
00082 IDLE,
00084 EDSCAN,
00086 SCAN,
00088 SCAN_DONE,
00090 SNIFF
00091 } SHORTENUM sniffer_state_t;
00092
00096 typedef struct scan_result_tag
00097 {
00099 uint16_t framecnt;
00101 uint16_t crc_ok;
00102 uint16_t edsum;
00103 uint16_t lqisum;
00104 uint16_t ftypes[8];
00105 } scan_result_t;
00106
00111 typedef struct sniffer_context_tag
00112 {
00114 sniffer_state_t state;
00116 channel_t cchan;
00118 uint8_t cpage;
00120 uint32_t cmask;
00121
00123 bool chkcrc;
00124
00126 timer_hdl_t thdl;
00128 time_t scanper;
00130 scan_result_t scanres[TRX_NB_CHANNELS];
00131 uint8_t scanres_reset;
00132 uint16_t frames;
00133 uint16_t irq_ur;
00134 uint16_t missed_frames;
00135 } sniffer_context_t;
00136
00137 typedef struct
00138 {
00139 uint8_t irql;
00140 uint8_t tmrl;
00141 uint8_t err;
00142 } dbg_t;
00143
00144
00145 typedef struct sniffer_packet_tag
00146 {
00147
00148 time_stamp_t ts;
00149 uint8_t flen;
00150 uint8_t *rxdata;
00151 uint8_t lqi;
00152 uint8_t ed;
00153 bool crc;
00154 } sniffer_packet_t;
00155
00156
00157 extern sniffer_context_t ctx;
00158
00159
00160
00164 static inline void scan_update_frame(uint8_t flen, bool crc_ok, uint8_t lqi, uint8_t ed, uint8_t *rxbuf)
00165 {
00166 scan_result_t *scres;
00167
00168 scres = &ctx.scanres[(ctx.cchan - TRX_MIN_CHANNEL)];
00169 scres->framecnt ++;
00170 scres->edsum +=ed;
00171 scres->lqisum += lqi;
00172
00173 if (flen < 0x80)
00174 {
00175
00176 if (crc_ok == true)
00177 {
00178 scres->crc_ok++;
00179 scres->ftypes[rxbuf[0]&7] ++;
00180 }
00181
00182 }
00183 }
00184
00185
00186
00187
00188 #ifdef __cplusplus
00189 extern "C" {
00190 #endif
00191
00198 void sniffer_start(sniffer_state_t state);
00199 void sniffer_stop(void);
00200 void ctrl_process_input(void);
00201
00202 void scan_init(void);
00203 void scan_continue(void);
00204 #ifdef __cplusplus
00205 }
00206 #endif
00207
00208 #endif