From a4a3eca41d50e437807113782385b8df7abb2d37 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Fri, 27 Jun 2014 22:52:27 -0400 Subject: [PATCH] Add sniffer support to ADuCRF101 This works with the examples/cc2538dk/sniffer/ project and the corresponding "sensniff" host-side tool. --- cpu/arm/aducrf101/dev/radio.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cpu/arm/aducrf101/dev/radio.c b/cpu/arm/aducrf101/dev/radio.c index 24586b727..71f78f41b 100644 --- a/cpu/arm/aducrf101/dev/radio.c +++ b/cpu/arm/aducrf101/dev/radio.c @@ -58,6 +58,19 @@ static int current_channel = 915000000; static int current_power = 31; static int radio_is_on = 0; +/*---------------------------------------------------------------------------*/ +/* Sniffer configuration. We can re-use the CC2538 sniffer application + if we also accept CC2538_RF_CONF_SNIFFER. */ +#ifndef ADUCRF101_RF_CONF_SNIFFER +#if CC2538_RF_CONF_SNIFFER +#define ADUCRF101_RF_CONF_SNIFFER 1 +#endif +#endif + +#if ADUCRF101_RF_CONF_SNIFFER +#include "dev/uart.h" +static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /* Snif */ +#endif /*---------------------------------------------------------------------------*/ /* "Channel" is really frequency, and can be within the bands: 431000000 Hz to 464000000 Hz @@ -209,13 +222,14 @@ static int read(void *buf, unsigned short buf_len) { uint8_t packet_len; + int8_t rssi; if(buf_len > MAX_PACKET_LEN) { buf_len = MAX_PACKET_LEN; } /* Read already-received packet */ - if(RadioRxPacketRead(buf_len, &packet_len, buf, NULL) != RIE_Success) { + if(RadioRxPacketRead(buf_len, &packet_len, buf, &rssi) != RIE_Success) { return 0; } @@ -226,6 +240,20 @@ read(void *buf, unsigned short buf_len) /* Re-enter receive mode immediately after receiving a packet */ RadioRxPacketVariableLen(); +#if ADUCRF101_RF_CONF_SNIFFER + uart_put(magic[0]); + uart_put(magic[1]); + uart_put(magic[2]); + uart_put(magic[3]); + uart_put(packet_len + 2); + for(int i = 0; i < packet_len; i++) { + uart_put(((uint8_t *)buf)[i]); + } + /* FCS value is Wireshark's "TI CC24xx format" option: */ + uart_put(rssi); /* RSSI */ + uart_put(0x80); /* CRC is OK, LQI correlation is 0 */ +#endif + return packet_len; } /*---------------------------------------------------------------------------*/