Go to the documentation of this file.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"
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
00076 #ifndef MAX_PACKET_BUFFERS
00077 # define MAX_PACKET_BUFFERS (8)
00078 #endif
00079
00083 typedef enum
00084 {
00086 IDLE,
00088 EDSCAN,
00090 SCAN,
00092 SCAN_DONE,
00094 SNIFF
00095 } SHORTENUM sniffer_state_t;
00096
00100 typedef struct scan_result_tag
00101 {
00103 uint16_t framecnt;
00105 uint16_t crc_ok;
00106 uint16_t edsum;
00107 uint16_t lqisum;
00108 uint16_t ftypes[8];
00109 } scan_result_t;
00110
00115 typedef struct sniffer_context_tag
00116 {
00118 volatile sniffer_state_t state;
00120 channel_t cchan;
00122 uint8_t cpage;
00124 uint32_t cmask;
00125
00127 bool chkcrc;
00128
00130 timer_hdl_t thdl;
00132 time_t scanper;
00134 scan_result_t scanres[TRX_NB_CHANNELS];
00135 uint8_t scanres_reset;
00136 uint16_t frames;
00137 uint16_t irq_ur;
00138 uint16_t missed_frames;
00139 } sniffer_context_t;
00140
00141 typedef struct pcap_packet_tag
00142 {
00144 uint8_t len;
00146 time_stamp_t ts;
00148 uint8_t frame[MAX_FRAME_SIZE];
00149 } pcap_packet_t;
00150
00151
00152 typedef struct pcap_pool_tag
00153 {
00154 volatile uint8_t ridx;
00155 volatile uint8_t widx;
00156 pcap_packet_t packet[MAX_PACKET_BUFFERS];
00157 } pcap_pool_t;
00158
00159
00160
00161 extern sniffer_context_t ctx;
00162
00163
00164
00168 static inline void scan_update_frame(uint8_t flen, bool crc_ok, uint8_t lqi, uint8_t ed, uint8_t *rxbuf)
00169 {
00170 scan_result_t *scres;
00171
00172 scres = &ctx.scanres[(ctx.cchan - TRX_MIN_CHANNEL)];
00173 scres->framecnt ++;
00174 scres->edsum +=ed;
00175 scres->lqisum += lqi;
00176
00177 if (flen < 0x80)
00178 {
00179
00180 if (crc_ok == true)
00181 {
00182 scres->crc_ok++;
00183 scres->ftypes[rxbuf[0]&7] ++;
00184 }
00185
00186 }
00187 }
00188
00189
00190
00191
00192 #ifdef __cplusplus
00193 extern "C" {
00194 #endif
00195
00202 void sniffer_start(sniffer_state_t state);
00203 void sniffer_stop(void);
00204 void ctrl_process_input(void);
00205 void scan_init(void);
00206 void scan_continue(void);
00207 #ifdef __cplusplus
00208 }
00209 #endif
00210
00211 #endif