From e3e1e04948ae18d972cfa39b85fcfcd054fc283e Mon Sep 17 00:00:00 2001 From: dak664 Date: Tue, 21 Dec 2010 04:25:15 +0000 Subject: [PATCH] Add FCS comments and text2pcap dump routines of Roger Larsson. Don't send last two byte to xmit buffer since they will be overwritten by the checksum anyway. --- cpu/avr/radio/rf230bb/halbb.c | 8 +-- cpu/avr/radio/rf230bb/rf230bb.c | 94 +++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/cpu/avr/radio/rf230bb/halbb.c b/cpu/avr/radio/rf230bb/halbb.c index 7dcfcd7bb..602d23383 100644 --- a/cpu/avr/radio/rf230bb/halbb.c +++ b/cpu/avr/radio/rf230bb/halbb.c @@ -530,7 +530,6 @@ void //hal_frame_read(hal_rx_frame_t *rx_frame, rx_callback_t rx_callback) hal_frame_read(hal_rx_frame_t *rx_frame) { - // uint8_t *rx_data=0; uint8_t *rx_data; /* check that we have either valid frame pointer or callback pointer */ @@ -542,7 +541,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame) /*Send frame read command.*/ (void)HAL_SPI_TRANSFER(HAL_TRX_CMD_FR); - /*Read frame length.*/ + /*Read frame length. This includes the checksum. */ uint8_t frame_length = HAL_SPI_TRANSFER(0); /*Check for correct frame length.*/ @@ -623,9 +622,11 @@ hal_frame_write(uint8_t *write_buffer, uint8_t length) dummy_read = HAL_SPI_TRANSFER(length); /* Download to the Frame Buffer. */ + /* Note an autogenerated FCS is inserted into the last two bytes, so there is no + * need to transfer them to the buffer */ do{ dummy_read = HAL_SPI_TRANSFER(*write_buffer++); - } while (--length > 0); + } while (--length > 2); HAL_SPI_TRANSFER_CLOSE(); } @@ -794,7 +795,6 @@ HAL_RF230_ISR() #endif if (rf230_last_rssi >= RF230_MIN_RX_POWER) { #endif -// hal_frame_read(&rxframe, NULL); hal_frame_read(&rxframe); rf230_interrupt(); // trx_end_callback(isr_timestamp); diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c index 3e29d85d0..d6ea17e87 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.c +++ b/cpu/avr/radio/rf230bb/rf230bb.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: rf230bb.c,v 1.22 2010/12/18 20:49:00 dak664 Exp $ + * @(#)$Id: rf230bb.c,v 1.23 2010/12/21 04:25:15 dak664 Exp $ */ /* * This code is almost device independent and should be easy to port. @@ -61,13 +61,14 @@ #define WITH_SEND_CCA 0 +/* Timestamps have not been tested */ #if RF230_CONF_TIMESTAMPS #include "net/rime/timesynch.h" #define TIMESTAMP_LEN 3 #else /* RF230_CONF_TIMESTAMPS */ #define TIMESTAMP_LEN 0 #endif /* RF230_CONF_TIMESTAMPS */ -//#define FOOTER_LEN 2 +/* Nonzero FOOTER_LEN has not been tested */ #define FOOTER_LEN 0 #ifndef RF230_CONF_CHECKSUM @@ -92,7 +93,11 @@ static bool is_promiscuous; #endif /* RF230_CONF_CHECKSUM */ #define CHECKSUM_LEN 2 +/* Note the AUC_LEN is equal to the CHECKSUM_LEN in any tested configurations to date! */ #define AUX_LEN (CHECKSUM_LEN + TIMESTAMP_LEN + FOOTER_LEN) +#if AUX_LEN != CHECKSUM_LEN +#warning RF230 Untested Configuration! +#endif struct timestamp { uint16_t time; @@ -112,11 +117,20 @@ struct timestamp { #define DEBUG 0 #if DEBUG -#define PRINTF(...) //printf(__VA_ARGS__) -#define PRINTSHORT(...) printf(__VA_ARGS__) +#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) +#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args) #else #define PRINTF(...) -#define PRINTSHORT(...) //printf(__VA_ARGS__) +#define PRINTSHORT(...) +#endif +#if DEBUG>1 +/* Output format is suitable for text2pcap to convert to wireshark pcap file. + * Use $text2pcap -e 0x809a (these_outputs) capture.pcap + * Since the hardware calculates and appends the two byte checksum to Tx packets, + * we just add two zero bytes to the packet dump. Don't forget to enable wireshark + * 802.15.4 dissection even when the checksum is wrong! + */ +//int wireshark_offset; #endif /* See clock.c and httpd-cgi.c for RADIOSTATS code */ @@ -643,6 +657,19 @@ rf230_transmit(unsigned short payload_len) hal_set_slptr_low(); hal_frame_write(buffer, total_len); + PRINTF("rf230_transmit:\n"); +#if DEBUG>1 +/* Note the dumped packet will have a zero checksum since we don't know what it should be */ + { + uint8_t i; + PRINTF("0000"); //Start a new wireshark packet +// PRINTF("%02x%02x ", wireshark_offset>>8, wireshark_offset & 0xff); + for (i=0;i1 - for (len=0;len1 + { + uint8_t i; + PRINTF("0000"); + // PRINTF("%02x%02x ", wireshark_offset>>8, wireshark_offset & 0xff); + for (i=0;i RF230_MAX_PACKET_LEN) { @@ -1095,13 +1132,14 @@ if (RF230_receive_on) { // RELEASE_LOCK(); return 0; } - /* Transfer the frame, stripping the footer */ + /* Transfer the frame, stripping the footer, but copying the checksum */ framep=&(rxframe.data[0]); memcpy(buf,framep,len-AUX_LEN+CHECKSUM_LEN); - framep+=len-AUX_LEN; + /* Clear the length field to allow buffering of the next packet */ rxframe.length=0; - + /* Point to the checksum */ + framep+=len-AUX_LEN; #if RF230_CONF_CHECKSUM memcpy(&checksum,framep,CHECKSUM_LEN); #endif /* RF230_CONF_CHECKSUM */ @@ -1161,25 +1199,11 @@ if (RF230_receive_on) { } #endif - /* Clean up in case of FIFO overflow! This happens for every full - * length frame and is signaled by FIFOP = 1 and FIFO = 0. - */ - // if(FIFOP_IS_1 && !FIFO_IS_1) { - /* printf("rf230_read: FIFOP_IS_1 1\n");*/ - // flushrx(); - // } else if(FIFOP_IS_1) { - /* Another packet has been received and needs attention. */ - /* printf("attention\n");*/ - // process_poll(&rf230_process); -// } - - // RELEASE_LOCK(); - #ifdef RF230BB_HOOK_RX_PACKET RF230BB_HOOK_RX_PACKET(buf,len); #endif - + /* Here return just the data length. The checksum is however still in the buffer for packet sniffing */ return len - AUX_LEN; #if RADIOALWAYSON