diff --git a/apps/BaseStation15.4/Makefile b/apps/BaseStation15.4/Makefile index c58ce5213c..4bd5457f3b 100644 --- a/apps/BaseStation15.4/Makefile +++ b/apps/BaseStation15.4/Makefile @@ -1,14 +1,14 @@ COMPONENT=BaseStationC -CFLAGS += -DCC2420_NO_ACKNOWLEDGEMENTS +#CFLAGS += -DCC2420_NO_ACKNOWLEDGEMENTS +CFLAGS += -DCC2420_HW_ACKNOWLEDGEMENTS CFLAGS += -DCC2420_NO_ADDRESS_RECOGNITION BUILD_EXTRA_DEPS += seriallisten15-4 CLEAN_EXTRA = seriallisten15-4.o seriallisten15-4 seriallisten15-4: seriallisten15-4.o - gcc -o $@ $< $(TOSDIR)/../support/sdk/c/sf/libmote.a + gcc -o $@ $< $(TOSDIR)/../support/sdk/c/sf/libmote.a -I /usr/msp430/include/ -I /usr/lib/gcc/msp430/4.6.3/include/ -I /usr/include/i386-linux-gnu -I /usr/include/c++/4.6/parallel/ -I /usr/include/i386-linux-gnu/bits/ seriallisten15-4.o: seriallisten15-4.c - gcc -c -o $@ -I$(TOSDIR)/../support/sdk/c/sf -I$(TOSDIR)/lib/serial -I$(TOSDIR)/types $< - + gcc -c -o $@ -I$(TOSDIR)/../support/sdk/c/sf -I$(TOSDIR)/lib/serial -I$(TOSDIR)/types $< -I /usr/msp430/include/ -I /usr/lib/gcc/msp430/4.6.3/include/ -I /usr/include/i386-linux-gnu -I /usr/include/c++/4.6/parallel/ -I /usr/include/i386-linux-gnu/bits/ include $(MAKERULES) diff --git a/apps/BaseStation15.4/readme.txt b/apps/BaseStation15.4/readme.txt new file mode 100644 index 0000000000..bcb3e79ac9 --- /dev/null +++ b/apps/BaseStation15.4/readme.txt @@ -0,0 +1,91 @@ +Sniffer +----------------------------------- + + by Silvia Krug + date 20120921 + + +----------------------------------- +Hardware +----------- + +tmote / telosB Knoten + +----------------------------------- +Software - auf Knoten +----------- + Anwendung: packetsniffer + Pfad: tinyos-2.x/apps/tests/tkn15.4/packetsniffer + + notwendige Einstellungen: + Kanal: in app_profile.h INITAL_RADIO_CHANNEL setzen + + übersetzen mit: + make tmote install, + + = Knoten-ID + +Der Knoten ist in dieser Anwendung passiv und zeichnet alle Pakete auf +der Luftschnittstelle auf. Die Anwendung stellt eine Art Basisstation +bereit, d.h. die Pakete werden über die Serielle Schnittstelle zum +Rechner übertragen. + +----------------------------------- +Software - auf Rechnerseite +----------- + Anwendung: BaseStation15.4 + Pfad: tinyos-2.x/apps/BaseStation15.4 + + übersetzen mit: + make tmote + +Auf Rechnerseite wird ein C-Programm verwendet, das sich im genannten +Ordner befindet. Dieses wurde erweitert, um + + 1) Pakete im Wireshark-Format pcap zu speichern und + 2) die Zusatzinformationen (LQI,RSSI,CRC ok,MAC Header Länge,PHY + Kanal und Zeitstemple) des TKN15.4-Protokolls anzuzeigen + +Das C.Programm wird mit der Anwendung übersetzt und ist anschließend +einsatzbereit. Die Wireshark-Datei wird im gleichen Verzeichnis angelegt. + + Aufruf: + ./seriallisten15-4 iframe 115200 + + = Serielle Schnittstelle an der der Sniffer + angeschlossen ist + + = Datei, in der die Pakete für Wireshark gespeichert + werden + +Fehlermeldungen werden in die Konsole geschrieben. Ggf. ist nach dem +Start des C-Programms ein Reset der Knotens notwendig. + + +----------------------------------- +Auswertung mit Wireshark +----------- + +Die erzeugte Datei kann mit Wireshark geöffnet und analysiert werden. +Der Funkchip der Tmotes schneidet die letzen 2 Byte (CRC des Paketes) ab +und ersetzt sie durch andere Informationen. Damit die Pakete in +Wireshark korrekt angezeigt werden sind folgende Einstellungen +notwendig: + + Unter: Eintstellungen -> Protokolle -> IEEE 802.15.4 + den Haken bei 'TI CC24xx FCS format' setzen + + +Pakete, die mit Blip 1 versendet wurden können aber nicht korrekt +entschlüsselt werden. Ohne weitere Einstellungen werden diese Pakete +ggf. als ZigBee Pakete interpretiert. Um dies zu verhindern sollten die +ZigBee-Protokolle in Wireshark deaktiviert werden. + + Unter: Analyze -> Enabled Protocols + die entsprechenden Haken bei ZigBee entfernen. + +Blip 2 Pakete sollten von der in Wireshark enthaltenen 6LoWPAN Engine +dekodiert werden können. + + + diff --git a/apps/BaseStation15.4/seriallisten15-4 b/apps/BaseStation15.4/seriallisten15-4 new file mode 100755 index 0000000000..acddfb6acf Binary files /dev/null and b/apps/BaseStation15.4/seriallisten15-4 differ diff --git a/apps/BaseStation15.4/seriallisten15-4.c b/apps/BaseStation15.4/seriallisten15-4.c index e84272a380..8acc81861b 100644 --- a/apps/BaseStation15.4/seriallisten15-4.c +++ b/apps/BaseStation15.4/seriallisten15-4.c @@ -1,9 +1,33 @@ #include #include #include +#include + +#include #include "serialsource.h" +FILE * f; // file handle for capture file +unsigned int snap = 65535; + +typedef struct pcaprec_hdr_s { // header for each packet + unsigned int ts_sec; + unsigned int ts_usec; + unsigned int incl_len; + unsigned int orig_len; +} pcaprec_hdr_t; + +typedef struct pcap_hdr_s { // header for capture file + unsigned int magic_number; + unsigned short version_major; + unsigned short version_minor; + int thiszone; + unsigned int sigfigs; + unsigned int snaplen; + unsigned int network; +} pcap_hdr_t; + + static char *msgs[] = { "unknown_packet_type", "ack_timeout" , @@ -17,11 +41,50 @@ static char *msgs[] = { "unix_error" }; +void capture_global(){ // write file header with values for 802.15.4 - no change needed + pcap_hdr_t globalheader; + + globalheader.magic_number = 0xa1b2c3d4; + globalheader.version_major = 0x0204; + globalheader.version_minor = 0x0204; + globalheader.thiszone = -3600; + globalheader.sigfigs = 0; + globalheader.snaplen = snap; + globalheader.network = 195; + + fwrite(&globalheader, sizeof(globalheader),1,f); + +} + +void capture_packet_header (int wire_len, int org_len){ // write packet header + pcaprec_hdr_t headerpkt; + + struct timeb temps; + ftime(&temps); + + headerpkt.ts_sec = temps.time; + headerpkt.ts_usec = temps.millitm; + headerpkt.incl_len = wire_len; + headerpkt.orig_len = org_len; + + fwrite(&headerpkt, sizeof(headerpkt), 1, f); + +} + void stderr_msg(serial_source_msg problem) { fprintf(stderr, "Note: %s\n", msgs[problem]); } +void sign_handler(int signum){ + switch (signum) { + case SIGINT: + fclose(f); + exit(0); + break; + } +} + enum { TOS_SERIAL_802_15_4_ID = 2, }; @@ -30,8 +93,8 @@ int main(int argc, char **argv) { serial_source src; int iframes = 0; - if (argc != 4) { - fprintf(stderr, "Usage: %s - dump packets from a serial port\n", argv[0]); + if (argc != 5) { + fprintf(stderr, "Usage: %s - dump packets from a serial port\n", argv[0]); exit(2); } @@ -53,13 +116,22 @@ int main(int argc, char **argv) argv[2], argv[3]); exit(1); } + + f=fopen(argv[4],"wb"); // open capture file, name provided by user + capture_global(); // write header + signal(SIGINT, sign_handler); for (;;) { - int len, i, plen; + int len, i, plen, x; short fcf; + int offset_serial = 2; + int offset_meta = 9; + int offset = offset_serial - offset_meta; const unsigned char *packet = read_serial_packet(src, &len); + unsigned char wireshark_packet[len - offset]; int intraPan = 0; + int ack = 0; if (!packet) exit(0); @@ -69,10 +141,19 @@ int main(int argc, char **argv) plen = packet[1]; printf("Received packet of length %i: \n", plen); + if (plen != len) { printf("Packet format error: read packet length (%hhx) is different than expected from frame (%hhx).\n", plen, len); } + for(x=2; x> 10) & 0x3; - short saddr = 0; - long long laddr = 0; - - // 16- and 64-bit destinations have a PAN ID - if (addrLen == 2 || addrLen == 3) { - short destPan = packet[i++] << 8 | packet[i++]; - printf(" Destination PAN: 0x%02hx\n", destPan); - } - - switch (addrLen) { - case 0: - printf(" Destination address: none\n"); - break; - case 1: - printf(" Destination address: invalid? (0x01)\n"); - break; - case 2: - saddr = (packet[i] << 8 | packet[i+1]); - i += 2; - printf(" Destination address: 0x%04hx\n", saddr); - break; - case 3: { - int j; - for (j = 0; j < 8; j++) { - laddr = laddr << 8; - laddr |= packet[i++]; + if (ack != 1) { // no addresses, no payload + { + char addrLen = (fcf >> 10) & 0x3; + short saddr = 0; + long long laddr = 0; + + // 16- and 64-bit destinations have a PAN ID + if (addrLen == 2 || addrLen == 3) { + short destPan = packet[i++] << 8 | packet[i++]; + printf(" Destination PAN: 0x%02hx\n", destPan); } - printf(" Destination address: 0x%016llx\n", laddr); - break; - } - default: - printf(" Destination address: parse serror\n"); - } - } + + switch (addrLen) { + case 0: + printf(" Destination address: none\n"); + break; + case 1: + printf(" Destination address: invalid? (0x01)\n"); + break; + case 2: + saddr = (packet[i] << 8 | packet[i+1]); + i += 2; + printf(" Destination address: 0x%04hx\n", saddr); + break; + case 3: { + int j; + for (j = 0; j < 8; j++) { + laddr = laddr << 8; + laddr |= packet[i++]; + } + printf(" Destination address: 0x%016llx\n", laddr); + break; + } + default: + printf(" Destination address: parse serror\n"); + } + } - { - char addrLen = (fcf >> 14) & 0x3; - short saddr = 0; - long long laddr = 0; - - if (!intraPan) { // Intra-PAN packet - short srcPan = packet[i] << 8 | packet[i+1]; - i += 2; - printf(" Source PAN: 0x%02hx\n", srcPan); - } - - switch (addrLen) { - case 0: - printf(" Source address: none\n"); - break; - case 1: - printf(" Source address: invalid? (0x01)\n"); - break; - case 2: - saddr = (packet[i] << 8 | packet[i + 1]); - i += 2; - printf(" Source address: 0x%04hx\n", saddr); - break; - case 3: { - int j; - for (j = 0; j < 8; j++) { - laddr = laddr << 8; - laddr |= packet[i++]; + { + char addrLen = (fcf >> 14) & 0x3; + short saddr = 0; + long long laddr = 0; + + if (!intraPan) { // Intra-PAN packet + short srcPan = packet[i] << 8 | packet[i+1]; + i += 2; + printf(" Source PAN: 0x%02hx\n", srcPan); } - printf(" Source address: 0x%016llx\n", laddr); - break; - } - default: - printf(" Source address: parse serror\n"); - } - } - if (iframes) { - printf(" I-Frame: %s\n", (packet[i++] == 0x3f)? "yes":"no"); - } + switch (addrLen) { + case 0: + printf(" Source address: none\n"); + break; + case 1: + printf(" Source address: invalid? (0x01)\n"); + break; + case 2: + saddr = (packet[i] << 8 | packet[i + 1]); + i += 2; + printf(" Source address: 0x%04hx\n", saddr); + break; + case 3: { + int j; + for (j = 0; j < 8; j++) { + laddr = laddr << 8; + laddr |= packet[i++]; + } + printf(" Source address: 0x%016llx\n", laddr); + break; + } + default: + printf(" Source address: parse serror\n"); + } + } + + if (iframes) { + printf(" I-Frame: %s\n", (packet[i++] == 0x3f)? "yes":"no"); + } - printf(" AM type: 0x%02hhx\n", packet[i++]); + printf(" AM type: 0x%02hhx\n", packet[i++]); + + if (i >= plen) { + printf("Packet format error: read packet is shorter than expected.\n"); + } + else { + printf(" Payload: "); + for (; i < plen + 2; i++) { // first two bytes of len where skipped by i but are not counted for plen + printf("0x%02hhx ", packet[i]); + } - if (i >= plen) { - printf("Packet format error: read packet is shorter than expected.\n"); + printf("\n\n"); + } } - else { - printf(" Payload: "); - for (; i < plen; i++) { - printf("0x%02hhx ", packet[i]); - } - printf("\n\n"); - putchar('\n'); + + // additional info from tkn15.4 Mac Layer + + printf(" LQI: 0x%02hhx \n", packet[i++]); + printf(" RSSI: 0x%02hhx \n", packet[i++]); + printf(" CRC ok: 0x%02hhx \n", packet[i++]); + printf(" MAC Header length: 0x%02hhx \n", packet[i++]); + printf(" PHY channel: 0x%02hhx \n", packet[i++]); + printf("\n"); + printf(" Timestamp: "); + + while(i < len){ + printf("0x%02hhx ", packet[i++]); } + + printf("\n\n"); + putchar('\n'); + free((void *)packet); } } diff --git a/apps/BaseStation15.4/seriallisten15-4.o b/apps/BaseStation15.4/seriallisten15-4.o new file mode 100644 index 0000000000..d46ee27dac Binary files /dev/null and b/apps/BaseStation15.4/seriallisten15-4.o differ diff --git a/apps/PppRouter/Makefile b/apps/PppRouter/Makefile index 297ff80863..f88d3fb504 100644 --- a/apps/PppRouter/Makefile +++ b/apps/PppRouter/Makefile @@ -1,6 +1,18 @@ COMPONENT=PppRouterC -# PFLAGS += -DENABLE_SPI0_DMA -# PFLAGS += -DCC2420_DEF_CHANNEL=21 +#PFLAGS += -DENABLE_SPI0_DMA +PFLAGS += -DCC2420_DEF_CHANNEL=13 + +#IRIS Software-Ack +CFLAGS+=-DRF230_HARDWARE_ACK +CFLAGS+=-DCC2420_HARDWARE_ACK + +CFLAGS += -DHARDWAREACK +CFLAGS += -DCC2420_HARDWAREACK +CFLAGS += -DRF230_HARDWAREACK + +CFLAGS+=-DCC2420_HW_ACKNOWLEDGEMENTS +CFLAGS+=-DRF230_HW_ACKNOWLEDGEMENTS +#CFLAGS += -DSOFTWAREACK_TIMEOUT=3000 # use rpl PFLAGS += -DRPL_ROUTING -DRPL_STORING_MODE -I$(LOWPAN_ROOT)/tos/lib/net/rpl @@ -20,4 +32,14 @@ PFLAGS += -DIN6_PREFIX=\"fec0::\" # derive short address from the dhcp address assignment, if possible PFLAGS += -DBLIP_DERIVE_SHORTADDRS +# tell the 6lowpan layer to not generate hc-compressed headers +#PFLAGS += -DLIB6LOWPAN_HC_VERSION=-1 + +#LPL FLAGS +#CFLAGS += -DLOW_POWER_LISTENING +#CFLAGS += -DLPL_SLEEP_INTERVAL=512 +#CFLAGS += -DBLIP_L2_RETRIES=2 +#CFLAGS += -DBLIP_L2_DELAY=2048 +#CFLAGS += -DDUTY_ON_TIME=15 + include $(MAKERULES) diff --git a/apps/UDPEcho/Makefile b/apps/UDPEcho/Makefile old mode 100644 new mode 100755 index e26d94923e..45d1b218ee --- a/apps/UDPEcho/Makefile +++ b/apps/UDPEcho/Makefile @@ -1,41 +1,53 @@ -COMPONENT=UDPEchoC -# uncomment this for network programming support -# BOOTLOADER=tosboot - -# radio options -# CFLAGS += -DCC2420_DEF_CHANNEL=26 -# CFLAGS += -DRF230_DEF_CHANNEL=26 -# CFLAGS += -DCC2420_DEF_RFPOWER=4 -DENABLE_SPI0_DMA - -# enable dma on the radio -# PFLAGS += -DENABLE_SPI0_DMA - -# you can compile with or without a routing protocol... of course, -# without it, you will only be able to use link-local communication. -PFLAGS += -DRPL_ROUTING -DRPL_STORING_MODE -I$(TOSDIR)/lib/net/rpl -# PFLAGS += -DRPL_OF_MRHOF - -# tell the 6lowpan layer to not generate hc-compressed headers -# PFLAGS += -DLIB6LOWPAN_HC_VERSION=-1 - -# if this is set, motes will send debugging information to the address -# listed. BLIP_STATS causes blip to record statistics. -# you can log this information using the util/Listener.py script -# PFLAGS += -DREPORT_DEST=\"fec0::100\" -DBLIP_STATS - -# if you're using DHCP, set this to try and derive a 16-bit address -# from the IA received from the server. This will work if the server -# gives out addresses from a /112 prefix. If this is not set, blip -# will only use EUI64-based link addresses. If not using DHCP, this -# causes blip to use TOS_NODE_ID as short address. Otherwise the -# EUI will be used in either case. -PFLAGS += -DBLIP_DERIVE_SHORTADDRS - -# this disables dhcp and statically chooses a prefix. the motes form -# their ipv6 address by combining this with TOS_NODE_ID -PFLAGS += -DIN6_PREFIX=\"fec0::\" - -# PFLAGS += -DNEW_PRINTF_SEMANTICS -DPRINTFUART_ENABLED - -include $(MAKERULES) - +COMPONENT=UDPEchoC +# uncomment this for network programming support +# BOOTLOADER=tosboot + +# radio options +CFLAGS += -DCC2420_DEF_CHANNEL=13 +CFLAGS += -DRF230_DEF_CHANNEL=13 +CFLAGS += -DCC2420_DEF_RFPOWER=4 -DENABLE_SPI0_DMA + +#IRIS Software-Ack +CFLAGS+=-DRF230_HARDWARE_ACK +CFLAGS+=-DCC2420_HARDWARE_ACK + +CFLAGS += -DHARDWAREACK +CFLAGS += -DCC2420_HARDWAREACK +#CFLAGS += -DRF230_HARDWAREACK + +CFLAGS+=-DCC2420_HW_ACKNOWLEDGEMENTS +CFLAGS+=-DRF230_HW_ACKNOWLEDGEMENTS +CFLAGS += -DSOFTWAREACK_TIMEOUT=3000 + +# enable dma on the radio +# PFLAGS += -DENABLE_SPI0_DMA + +# you can compile with or without a routing protocol... of course, +# without it, you will only be able to use link-local communication. +PFLAGS += -DRPL_ROUTING -DRPL_STORING_MODE -I$(TOSDIR)/lib/net/rpl +# PFLAGS += -DRPL_OF_MRHOF + +# tell the 6lowpan layer to not generate hc-compressed headers +#PFLAGS += -DLIB6LOWPAN_HC_VERSION=-1 + +# if this is set, motes will send debugging information to the address +# listed. BLIP_STATS causes blip to record statistics. +# you can log this information using the util/Listener.py script +PFLAGS += -DREPORT_DEST=\"fec0::100\" #-DBLIP_STATS -BLIP_STAPS_IP_MEM + +# if you're using DHCP, set this to try and derive a 16-bit address +# from the IA received from the server. This will work if the server +# gives out addresses from a /112 prefix. If this is not set, blip +# will only use EUI64-based link addresses. If not using DHCP, this +# causes blip to use TOS_NODE_ID as short address. Otherwise the +# EUI will be used in either case. +PFLAGS += -DBLIP_DERIVE_SHORTADDRS + +# this disables dhcp and statically chooses a prefix. the motes form +# their ipv6 address by combining this with TOS_NODE_ID +PFLAGS += -DIN6_PREFIX=\"fec0::\" + +# PFLAGS += -DNEW_PRINTF_SEMANTICS -DPRINTFUART_ENABLED + +include $(MAKERULES) + diff --git a/apps/UDPEcho/UDPEchoC.nc b/apps/UDPEcho/UDPEchoC.nc old mode 100644 new mode 100755 diff --git a/apps/UDPEcho/UDPEchoP.nc b/apps/UDPEcho/UDPEchoP.nc old mode 100644 new mode 100755 diff --git a/apps/tests/tkn154/packetsniffer/app_profile.h b/apps/tests/tkn154/packetsniffer/app_profile.h index ab843b10bf..d6f7de2c39 100644 --- a/apps/tests/tkn154/packetsniffer/app_profile.h +++ b/apps/tests/tkn154/packetsniffer/app_profile.h @@ -37,7 +37,7 @@ #define __APP_PROFILE_H enum { - INITAL_RADIO_CHANNEL = 26, // may be changed later via command over serial line + INITAL_RADIO_CHANNEL = 13, // may be changed later via command over serial line RX_QUEUE_SIZE = 10, // max. packets queued after received over radio }; diff --git a/tos/chips/atm128rfa1/radio/BareMessageC.nc b/tos/chips/atm128rfa1/radio/BareMessageC.nc new file mode 100644 index 0000000000..1cd59170e8 --- /dev/null +++ b/tos/chips/atm128rfa1/radio/BareMessageC.nc @@ -0,0 +1,25 @@ +configuration BareMessageC +{ + provides + { + interface BareSend; + interface BareReceive; + interface Packet as BarePacket; + interface PacketLink; + interface LowPowerListening; + interface SplitControl as RadioControl; + interface ShortAddressConfig; + } +} +implementation +{ + components RFA1RadioC; + + BareSend = RFA1RadioC; + BareReceive = RFA1RadioC; + BarePacket = RFA1RadioC.BarePacket; + PacketLink = RFA1RadioC; + LowPowerListening = RFA1RadioC; + RadioControl = RFA1RadioC.SplitControl; + ShortAddressConfig = RFA1RadioC; +} diff --git a/tos/chips/atm128rfa1/radio/RFA1BarePacketP.nc b/tos/chips/atm128rfa1/radio/RFA1BarePacketP.nc new file mode 100644 index 0000000000..9ed60e9e99 --- /dev/null +++ b/tos/chips/atm128rfa1/radio/RFA1BarePacketP.nc @@ -0,0 +1,37 @@ +module RFA1BarePacketP +{ + provides interface Packet as BarePacket; + uses interface RadioPacket; +} +implementation +{ + command void BarePacket.clear(message_t *msg) + { + call RadioPacket.clear(msg); + } + + command uint8_t BarePacket.payloadLength(message_t *msg) + { + //return call RadioPacket.payloadLength(msg); + return call RadioPacket.payloadLength(msg)+sizeof(rfa1_header_t); + } + + command void BarePacket.setPayloadLength(message_t *msg, uint8_t len) + { + //call RadioPacket.setPayloadLength(msg, len); + call RadioPacket.setPayloadLength(msg, len-sizeof(rfa1_header_t)); + } + + command uint8_t BarePacket.maxPayloadLength() + { + return call RadioPacket.maxPayloadLength(); + } + + command void *BarePacket.getPayload(message_t *msg, uint8_t len) + { + if (len > call RadioPacket.maxPayloadLength()) + return NULL; + else + return (void*)msg; + } +} diff --git a/tos/chips/atm128rfa1/radio/RFA1Ieee154MessageC.nc b/tos/chips/atm128rfa1/radio/RFA1Ieee154MessageC.nc new file mode 100644 index 0000000000..98e6b6e1df --- /dev/null +++ b/tos/chips/atm128rfa1/radio/RFA1Ieee154MessageC.nc @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2007, Vanderbilt University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the copyright holder nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Miklos Maroti + */ + +#include + +#ifdef TFRAMES_ENABLED +#error "You cannot use Ieee154MessageC with TFRAMES_ENABLED defined" +#endif + +configuration RFA1Ieee154MessageC +{ + provides + { + interface SplitControl; + + interface Ieee154Send; + interface Receive as Ieee154Receive; + interface SendNotifier; + + interface Ieee154Packet; + interface Packet; + interface Resource as SendResource[uint8_t clint]; + + interface PacketAcknowledgements; + interface LowPowerListening; + interface PacketLink; + + interface RadioChannel; + + interface PacketField as PacketLinkQuality; + interface PacketField as PacketTransmitPower; + interface PacketField as PacketRSSI; + + interface LocalTime as LocalTimeRadio; + interface PacketTimeStamp as PacketTimeStampRadio; + interface PacketTimeStamp as PacketTimeStampMilli; + } +} + +implementation +{ + components RFA1RadioC; + + SplitControl = RFA1RadioC; + + Ieee154Send = RFA1RadioC.Ieee154Send; + Ieee154Receive = RFA1RadioC.Ieee154Receive; + SendNotifier = RFA1RadioC.Ieee154Notifier; + + Packet = RFA1RadioC.PacketForIeee154Message; + Ieee154Packet = RFA1RadioC; + SendResource = RFA1RadioC; + + PacketAcknowledgements = RFA1RadioC; + LowPowerListening = RFA1RadioC; + PacketLink = RFA1RadioC; + + RadioChannel = RFA1RadioC; + + PacketLinkQuality = RFA1RadioC.PacketLinkQuality; + PacketTransmitPower = RFA1RadioC.PacketTransmitPower; + PacketRSSI = RFA1RadioC.PacketRSSI; + + LocalTimeRadio = RFA1RadioC; + PacketTimeStampMilli = RFA1RadioC; + PacketTimeStampRadio = RFA1RadioC; +} diff --git a/tos/chips/atm128rfa1/radio/RFA1RadioC.nc b/tos/chips/atm128rfa1/radio/RFA1RadioC.nc index ecd27566a6..1ee1ee8fbb 100644 --- a/tos/chips/atm128rfa1/radio/RFA1RadioC.nc +++ b/tos/chips/atm128rfa1/radio/RFA1RadioC.nc @@ -57,13 +57,17 @@ configuration RFA1RadioC #ifndef TFRAMES_ENABLED interface Ieee154Send; + interface BareSend; interface Receive as Ieee154Receive; + interface BareReceive; interface SendNotifier as Ieee154Notifier; interface Resource as SendResource[uint8_t clint]; interface Ieee154Packet; interface Packet as PacketForIeee154Message; + interface Packet as BarePacket; + interface ShortAddressConfig; #endif interface PacketAcknowledgements; @@ -95,6 +99,15 @@ implementation // -------- RadioP components RFA1RadioP as RadioP; + + BareSend = TinyosNetworkLayerC.Ieee154Send; + BareReceive = TinyosNetworkLayerC.Ieee154Receive; + ShortAddressConfig = RadioP; + + components RFA1BarePacketP as BarePacketP; + BarePacket = BarePacketP; + BarePacketP.RadioPacket -> RadioDriverLayerC; + #ifdef RADIO_DEBUG components AssertC; diff --git a/tos/chips/atm128rfa1/radio/RFA1RadioP.nc b/tos/chips/atm128rfa1/radio/RFA1RadioP.nc index bcc921bcf7..36b4da65b0 100644 --- a/tos/chips/atm128rfa1/radio/RFA1RadioP.nc +++ b/tos/chips/atm128rfa1/radio/RFA1RadioP.nc @@ -51,6 +51,8 @@ module RFA1RadioP interface ActiveMessageConfig; interface DummyConfig; + interface ShortAddressConfig; + #ifdef LOW_POWER_LISTENING interface LowPowerListeningConfig; #endif @@ -230,6 +232,20 @@ implementation * congestion backoff = 0x7 * CC2420_BACKOFF_PERIOD = 70 jiffies = 2240 microsec */ +/*----------------- ShortAddressConfig-----------------*/ + + command void ShortAddressConfig.setShortAddr(uint16_t address) + { + // TODO: actually write the new ID + signal ShortAddressConfig.setShortAddrDone(FAIL); + } + + default event void ShortAddressConfig.setShortAddrDone(error_t error) + { + } + + /*----------------- LowPowerListening -----------------*/ + #ifndef LOW_POWER_LISTENING #ifndef RFA1_BACKOFF_MIN diff --git a/tos/chips/rf212/RF212RadioP.nc b/tos/chips/rf212/RF212RadioP.nc index 33da2970e7..951acff101 100644 --- a/tos/chips/rf212/RF212RadioP.nc +++ b/tos/chips/rf212/RF212RadioP.nc @@ -176,7 +176,6 @@ implementation // SHR: BPSK: 40; OQPSK: 10 // phySymbolsPerOctet: BPSK: 8; OQPSK: 2 // plus we add a constant for safety -//TODO: this const seems way too high. I think we can even go with 0... #ifndef SOFTWAREACK_TIMEOUT_PLUS #define SOFTWAREACK_TIMEOUT_PLUS 1000 #endif @@ -282,32 +281,24 @@ implementation /*----------------- RandomCollisionConfig -----------------*/ - -#ifndef RF212_BACKOFF_MIN -#define RF212_BACKOFF_MIN 20 -#endif +// 802.15.4 constants: +// aUnitBackoffPeriod: 20 symbol +// macMinBE:0..5 (8), default 3 +// but we don't care about the standard yet, just converted the rf230 lpl timeouts to SymbolTime base async command uint16_t RandomCollisionConfig.getMinimumBackoff() { - return (uint16_t)(RF212_BACKOFF_MIN * getSymbolTime() * RADIO_ALARM_MICROSEC); + return (uint16_t)(10 * 8 * getSymbolTime() * RADIO_ALARM_MICROSEC); } -#ifndef RF212_BACKOFF_INIT -#define RF212_BACKOFF_INIT 310 -#endif - async command uint16_t RandomCollisionConfig.getInitialBackoff(message_t* msg) { - return (uint16_t)(RF212_BACKOFF_INIT * getSymbolTime() * RADIO_ALARM_MICROSEC); + return (uint16_t)(50 * 8 * getSymbolTime() * RADIO_ALARM_MICROSEC); } - -#ifndef RF212_BACKOFF_CONG -#define RF212_BACKOFF_CONG 140 -#endif async command uint16_t RandomCollisionConfig.getCongestionBackoff(message_t* msg) { - return (uint16_t)(RF212_BACKOFF_CONG * getSymbolTime() * RADIO_ALARM_MICROSEC); + return (uint16_t)(100 * 8 * getSymbolTime() * RADIO_ALARM_MICROSEC); } // 802.15.4 standard: SIFS (no ack requested): 12 symbol; LIFS (ack requested): 40 symbol diff --git a/tos/chips/rf230/BareMessageC.nc b/tos/chips/rf230/BareMessageC.nc new file mode 100644 index 0000000000..86564410a4 --- /dev/null +++ b/tos/chips/rf230/BareMessageC.nc @@ -0,0 +1,25 @@ +configuration BareMessageC +{ + provides + { + interface BareSend; + interface BareReceive; + interface Packet as BarePacket; + interface PacketLink; + interface LowPowerListening; + interface SplitControl as RadioControl; + interface ShortAddressConfig; + } +} +implementation +{ + components RF230RadioC; + + BareSend = RF230RadioC; + BareReceive = RF230RadioC; + BarePacket = RF230RadioC.BarePacket; + PacketLink = RF230RadioC; + LowPowerListening = RF230RadioC; + RadioControl = RF230RadioC.SplitControl; + ShortAddressConfig = RF230RadioC; +} diff --git a/tos/chips/rf230/RF230BarePacketP.nc b/tos/chips/rf230/RF230BarePacketP.nc new file mode 100644 index 0000000000..ecb07cb035 --- /dev/null +++ b/tos/chips/rf230/RF230BarePacketP.nc @@ -0,0 +1,37 @@ +module RF230BarePacketP +{ + provides interface Packet as BarePacket; + uses interface RadioPacket; +} +implementation +{ + command void BarePacket.clear(message_t *msg) + { + call RadioPacket.clear(msg); + } + + command uint8_t BarePacket.payloadLength(message_t *msg) + { + //return call RadioPacket.payloadLength(msg); + return call RadioPacket.payloadLength(msg)+sizeof(rf230_header_t); + } + + command void BarePacket.setPayloadLength(message_t *msg, uint8_t len) + { + //call RadioPacket.setPayloadLength(msg, len); + call RadioPacket.setPayloadLength(msg, len-sizeof(rf230_header_t)); + } + + command uint8_t BarePacket.maxPayloadLength() + { + return call RadioPacket.maxPayloadLength(); + } + + command void *BarePacket.getPayload(message_t *msg, uint8_t len) + { + if (len > call RadioPacket.maxPayloadLength()) + return NULL; + else + return (void*)msg; + } +} diff --git a/tos/chips/rf230/RF230RadioC.nc b/tos/chips/rf230/RF230RadioC.nc index 59042f02a6..b013f0159c 100644 --- a/tos/chips/rf230/RF230RadioC.nc +++ b/tos/chips/rf230/RF230RadioC.nc @@ -56,13 +56,17 @@ configuration RF230RadioC #ifndef TFRAMES_ENABLED interface Ieee154Send; + interface BareSend; interface Receive as Ieee154Receive; + interface BareReceive; interface SendNotifier as Ieee154Notifier; interface Resource as SendResource[uint8_t clint]; interface Ieee154Packet; interface Packet as PacketForIeee154Message; + interface Packet as BarePacket; + interface ShortAddressConfig; #endif interface PacketAcknowledgements; @@ -94,6 +98,15 @@ implementation // -------- RadioP components RF230RadioP as RadioP; + + BareSend = TinyosNetworkLayerC.Ieee154Send; + BareReceive = TinyosNetworkLayerC.Ieee154Receive; + ShortAddressConfig = RadioP; + + components RF230BarePacketP as BarePacketP; + BarePacket = BarePacketP; + BarePacketP.RadioPacket -> RadioDriverLayerC; + #ifdef RADIO_DEBUG components AssertC; @@ -175,6 +188,7 @@ implementation components new Ieee154PacketLayerC(); Ieee154PacketLayerC.SubPacket -> PacketLinkLayerC; + // -------- UniqueLayer Send part (wired twice) components new UniqueLayerC(); diff --git a/tos/chips/rf230/RF230RadioP.nc b/tos/chips/rf230/RF230RadioP.nc index db0e48467e..1f21a2bffe 100644 --- a/tos/chips/rf230/RF230RadioP.nc +++ b/tos/chips/rf230/RF230RadioP.nc @@ -50,6 +50,8 @@ module RF230RadioP interface ActiveMessageConfig; interface DummyConfig; + interface ShortAddressConfig; + #ifdef LOW_POWER_LISTENING interface LowPowerListeningConfig; #endif @@ -78,6 +80,7 @@ implementation async command uint8_t RF230DriverConfig.maxPayloadLength() { return sizeof(rf230packet_header_t) + TOSH_DATA_LENGTH; + } async command uint8_t RF230DriverConfig.metadataLength(message_t* msg) @@ -129,7 +132,7 @@ implementation } #ifndef SOFTWAREACK_TIMEOUT -#define SOFTWAREACK_TIMEOUT 1000 +#define SOFTWAREACK_TIMEOUT 3000//1000 #endif async command uint16_t SoftwareAckConfig.getAckTimeout() @@ -235,6 +238,20 @@ implementation * congestion backoff = 0x7 * CC2420_BACKOFF_PERIOD = 70 jiffies = 2240 microsec */ +/*----------------- ShortAddressConfig-----------------*/ + + command void ShortAddressConfig.setShortAddr(uint16_t address) + { + // TODO: actually write the new ID + signal ShortAddressConfig.setShortAddrDone(FAIL); + } + + default event void ShortAddressConfig.setShortAddrDone(error_t error) + { + } + + /*----------------- LowPowerListening -----------------*/ + #ifndef LOW_POWER_LISTENING #ifndef RF230_BACKOFF_MIN @@ -337,7 +354,7 @@ implementation command uint16_t LowPowerListeningConfig.getListenLength() { - return 5; + return 12;//5 } async command uint16_t RandomCollisionConfig.getMinimumBackoff() diff --git a/tos/lib/net/blip/IPAddressP.nc b/tos/lib/net/blip/IPAddressP.nc index 755c45fb10..304fce9cc7 100644 --- a/tos/lib/net/blip/IPAddressP.nc +++ b/tos/lib/net/blip/IPAddressP.nc @@ -31,7 +31,15 @@ module IPAddressP { interface Ieee154Address; } } implementation { + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + bool m_valid_addr = FALSE, m_short_addr = TRUE; +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + bool m_valid_addr = FALSE, m_short_addr = FALSE; +#else bool m_valid_addr = FALSE, m_short_addr = FALSE; +#endif + struct in6_addr m_addr; command bool IPAddress.getLLAddr(struct in6_addr *addr) { diff --git a/tos/lib/net/blip/IPDispatchC.nc b/tos/lib/net/blip/IPDispatchC.nc index 95a61a2c9d..961f9aab1c 100644 --- a/tos/lib/net/blip/IPDispatchC.nc +++ b/tos/lib/net/blip/IPDispatchC.nc @@ -40,7 +40,16 @@ configuration IPDispatchC { /* IPDispatchP wiring -- fragment rassembly and lib6lowpan bindings */ components IPDispatchP; + + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + components BareMessageC as MessageC; +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + components CC2420RadioC as MessageC; +#else components CC2420RadioC as MessageC; +#endif + components ReadLqiC; components new TimerMilliC(); @@ -58,8 +67,17 @@ configuration IPDispatchC { IPDispatchP.RadioControl -> MessageC; IPDispatchP.BarePacket -> MessageC.BarePacket; + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + IPDispatchP.BareSend -> MessageC; + IPDispatchP.BareReceive -> MessageC; +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + IPDispatchP.Ieee154Send -> MessageC.BareSend; + IPDispatchP.Ieee154Receive -> MessageC.BareReceive; +#else IPDispatchP.Ieee154Send -> MessageC.BareSend; IPDispatchP.Ieee154Receive -> MessageC.BareReceive; +#endif #ifdef LOW_POWER_LISTENING IPDispatchP.LowPowerListening -> MessageC; diff --git a/tos/lib/net/blip/IPDispatchP.nc b/tos/lib/net/blip/IPDispatchP.nc index 628f39a0dd..02cb409ede 100644 --- a/tos/lib/net/blip/IPDispatchP.nc +++ b/tos/lib/net/blip/IPDispatchP.nc @@ -55,8 +55,17 @@ module IPDispatchP { interface SplitControl as RadioControl; interface Packet as BarePacket; + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + interface BareSend; + interface BareReceive; +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + interface Send as Ieee154Send; + interface Receive as Ieee154Receive; +#else interface Send as Ieee154Send; interface Receive as Ieee154Receive; +#endif /* context lookup */ interface NeighborDiscovery; @@ -332,6 +341,102 @@ void SENDINFO_DECR(struct send_info *si) { return ret; } +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + event message_t *BareReceive.receive(message_t *msg) { + struct packed_lowmsg lowmsg; + struct ieee154_frame_addr frame_address; + uint8_t len = call BarePacket.payloadLength(msg); + void *msg_payload = call BarePacket.getPayload(msg, len); + uint8_t *buf = msg_payload; + + // printf(" -- RECEIVE -- len : %i\n", len); + + BLIP_STATS_INCR(stats.rx_total); + + /* unpack the 802.15.4 address fields */ + buf = unpack_ieee154_hdr(msg_payload, &frame_address); + len -= buf - (uint8_t *)msg_payload; + + /* unpack and 6lowpan headers */ + lowmsg.data = buf; + lowmsg.len = len; + lowmsg.headers = getHeaderBitmap(&lowmsg); + if (lowmsg.headers == LOWMSG_NALP) { + goto fail; + } + + if (hasFrag1Header(&lowmsg) || hasFragNHeader(&lowmsg)) { + // start reassembly + int rv; + struct lowpan_reconstruct *recon; + uint16_t tag, source_key; + + source_key = ieee154_hashaddr(&frame_address.ieee_src); + getFragDgramTag(&lowmsg, &tag); + recon = get_reconstruct(source_key, tag); + if (!recon) { + goto fail; + } + + /* fill in metadata: on fragmented packets, it applies to the + first fragment only */ + memcpy(&recon->r_meta.sender, &frame_address.ieee_src, + sizeof(ieee154_addr_t)); + recon->r_meta.lqi = call ReadLqi.readLqi(msg); + recon->r_meta.rssi = call ReadLqi.readRssi(msg); + + if (hasFrag1Header(&lowmsg)) { + if (recon->r_buf != NULL) goto fail; + rv = lowpan_recon_start(&frame_address, recon, buf, len); + } else { + rv = lowpan_recon_add(recon, buf, len); + } + + if (rv < 0) { + recon->r_timeout = T_FAILED1; + goto fail; + } else { + // printf("start recon buf: %p\n", recon->r_buf); + recon->r_timeout = T_ACTIVE; + recon->r_source_key = source_key; + recon->r_tag = tag; + } + + if (recon->r_size == recon->r_bytes_rcvd) { + deliver(recon); + } + + } else { + /* no fragmentation, just deliver it */ + int rv; + struct lowpan_reconstruct recon; + + /* fill in metadata */ + memcpy(&recon.r_meta.sender, &frame_address.ieee_src, + sizeof(ieee154_addr_t)); + recon.r_meta.lqi = call ReadLqi.readLqi(msg); + recon.r_meta.rssi = call ReadLqi.readRssi(msg); + + buf = getLowpanPayload(&lowmsg); + if ((rv = lowpan_recon_start(&frame_address, &recon, buf, len)) < 0) { + goto fail; + } + + if (recon.r_size == recon.r_bytes_rcvd) { + deliver(&recon); + } else { + // printf("ip_free(%p)\n", recon.r_buf); + ip_free(recon.r_buf); + } + } + goto done; + fail: + BLIP_STATS_INCR(stats.rx_drop); + done: + return msg; + } + +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) event message_t *Ieee154Receive.receive(message_t *msg, void *msg_payload, uint8_t len) { struct packed_lowmsg lowmsg; struct ieee154_frame_addr frame_address; @@ -423,8 +528,99 @@ void SENDINFO_DECR(struct send_info *si) { done: return msg; } +#else + event message_t *Ieee154Receive.receive(message_t *msg, void *msg_payload, uint8_t len) { + struct packed_lowmsg lowmsg; + struct ieee154_frame_addr frame_address; + uint8_t *buf = msg_payload; + + // printf(" -- RECEIVE -- len : %i\n", len); + + BLIP_STATS_INCR(stats.rx_total); + + /* unpack the 802.15.4 address fields */ + buf = unpack_ieee154_hdr(msg_payload, &frame_address); + len -= buf - (uint8_t *)msg_payload; + + /* unpack and 6lowpan headers */ + lowmsg.data = buf; + lowmsg.len = len; + lowmsg.headers = getHeaderBitmap(&lowmsg); + if (lowmsg.headers == LOWMSG_NALP) { + goto fail; + } + + if (hasFrag1Header(&lowmsg) || hasFragNHeader(&lowmsg)) { + // start reassembly + int rv; + struct lowpan_reconstruct *recon; + uint16_t tag, source_key; + + source_key = ieee154_hashaddr(&frame_address.ieee_src); + getFragDgramTag(&lowmsg, &tag); + recon = get_reconstruct(source_key, tag); + if (!recon) { + goto fail; + } + + /* fill in metadata: on fragmented packets, it applies to the + first fragment only */ + memcpy(&recon->r_meta.sender, &frame_address.ieee_src, + sizeof(ieee154_addr_t)); + recon->r_meta.lqi = call ReadLqi.readLqi(msg); + recon->r_meta.rssi = call ReadLqi.readRssi(msg); + + if (hasFrag1Header(&lowmsg)) { + if (recon->r_buf != NULL) goto fail; + rv = lowpan_recon_start(&frame_address, recon, buf, len); + } else { + rv = lowpan_recon_add(recon, buf, len); + } + + if (rv < 0) { + recon->r_timeout = T_FAILED1; + goto fail; + } else { + // printf("start recon buf: %p\n", recon->r_buf); + recon->r_timeout = T_ACTIVE; + recon->r_source_key = source_key; + recon->r_tag = tag; + } + + if (recon->r_size == recon->r_bytes_rcvd) { + deliver(recon); + } + + } else { + /* no fragmentation, just deliver it */ + int rv; + struct lowpan_reconstruct recon; + /* fill in metadata */ + memcpy(&recon.r_meta.sender, &frame_address.ieee_src, + sizeof(ieee154_addr_t)); + recon.r_meta.lqi = call ReadLqi.readLqi(msg); + recon.r_meta.rssi = call ReadLqi.readRssi(msg); + + buf = getLowpanPayload(&lowmsg); + if ((rv = lowpan_recon_start(&frame_address, &recon, buf, len)) < 0) { + goto fail; + } + if (recon.r_size == recon.r_bytes_rcvd) { + deliver(&recon); + } else { + // printf("ip_free(%p)\n", recon.r_buf); + ip_free(recon.r_buf); + } + } + goto done; + fail: + BLIP_STATS_INCR(stats.rx_drop); + done: + return msg; + } +#endif /* * Send-side functionality */ @@ -448,6 +644,24 @@ void SENDINFO_DECR(struct send_info *si) { goto fail; } +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + if (call BareSend.send(s_entry->msg) != SUCCESS) { + dbg("Drops", "drops: sendTask: send failed\n"); + goto fail; + } else { + radioBusy = TRUE; + } + +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + if ((call Ieee154Send.send(s_entry->msg, + call BarePacket.payloadLength(s_entry->msg))) != SUCCESS) { + dbg("Drops", "drops: sendTask: send failed\n"); + goto fail; + } else { + radioBusy = TRUE; + } + +#else if ((call Ieee154Send.send(s_entry->msg, call BarePacket.payloadLength(s_entry->msg))) != SUCCESS) { dbg("Drops", "drops: sendTask: send failed\n"); @@ -456,6 +670,8 @@ void SENDINFO_DECR(struct send_info *si) { radioBusy = TRUE; } +#endif + return; fail: printf("SEND FAIL\n"); @@ -491,6 +707,9 @@ void SENDINFO_DECR(struct send_info *si) { struct send_entry *s_entry; message_t *outgoing; +//#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) + uint8_t max_len; +//#endif int frag_len = 1; error_t rc = SUCCESS; @@ -530,11 +749,28 @@ void SENDINFO_DECR(struct send_info *si) { } call BarePacket.clear(outgoing); - frag_len = lowpan_frag_get(call Ieee154Send.getPayload(outgoing, 0), +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + max_len = call BarePacket.maxPayloadLength()-1; + frag_len = lowpan_frag_get(call BarePacket.getPayload(outgoing, max_len), + max_len, + msg, + frame_addr, + &ctx); +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + max_len = call BarePacket.maxPayloadLength();//TEST############ + frag_len = lowpan_frag_get(call Ieee154Send.getPayload(outgoing, max_len),//max_len statt 0################## + call BarePacket.maxPayloadLength(), //TEST################ + msg, + frame_addr, + &ctx); +#else +frag_len = lowpan_frag_get(call Ieee154Send.getPayload(outgoing, 0), call BarePacket.maxPayloadLength(), msg, frame_addr, &ctx); +#endif + if (frag_len < 0) { printf(" get frag error: %i\n", frag_len); } @@ -578,7 +814,47 @@ void SENDINFO_DECR(struct send_info *si) { cleanup_outer: return rc; } +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + event void BareSend.sendDone(message_t *msg, error_t error) { + struct send_entry *s_entry = call SendQueue.head(); + radioBusy = FALSE; + + // printf("sendDone: %p %i\n", msg, error); + + if (state == S_STOPPING) { + call RadioControl.stop(); + state = S_STOPPED; + goto done; + } + + s_entry->info->link_transmissions += (call PacketLink.getRetries(msg)); + s_entry->info->link_fragment_attempts++; + + if (!call PacketLink.wasDelivered(msg)) { + printf("sendDone: was not delivered! (%i tries)\n", + call PacketLink.getRetries(msg)); + s_entry->info->failed = TRUE; + signal IPLower.sendDone(s_entry->info); +/* if (s_entry->info->policy.dest[0] != 0xffff) */ +/* dbg("Drops", "drops: sendDone: frag was not delivered\n"); */ + // need to check for broadcast frames + // BLIP_STATS_INCR(stats.tx_drop); + } else if (s_entry->info->link_fragment_attempts == + s_entry->info->link_fragments) { + signal IPLower.sendDone(s_entry->info); + } + + done: + // kill off any pending fragments + SENDINFO_DECR(s_entry->info); + call FragPool.put(s_entry->msg); + call SendEntryPool.put(s_entry); + call SendQueue.dequeue(); + + post sendTask(); + } +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) event void Ieee154Send.sendDone(message_t *msg, error_t error) { struct send_entry *s_entry = call SendQueue.head(); @@ -619,6 +895,47 @@ void SENDINFO_DECR(struct send_info *si) { post sendTask(); } +#else + event void Ieee154Send.sendDone(message_t *msg, error_t error) { + struct send_entry *s_entry = call SendQueue.head(); + + radioBusy = FALSE; + + // printf("sendDone: %p %i\n", msg, error); + + if (state == S_STOPPING) { + call RadioControl.stop(); + state = S_STOPPED; + goto done; + } + + s_entry->info->link_transmissions += (call PacketLink.getRetries(msg)); + s_entry->info->link_fragment_attempts++; + + if (!call PacketLink.wasDelivered(msg)) { + printf("sendDone: was not delivered! (%i tries)\n", + call PacketLink.getRetries(msg)); + s_entry->info->failed = TRUE; + signal IPLower.sendDone(s_entry->info); +/* if (s_entry->info->policy.dest[0] != 0xffff) */ +/* dbg("Drops", "drops: sendDone: frag was not delivered\n"); */ + // need to check for broadcast frames + // BLIP_STATS_INCR(stats.tx_drop); + } else if (s_entry->info->link_fragment_attempts == + s_entry->info->link_fragments) { + signal IPLower.sendDone(s_entry->info); + } + + done: + // kill off any pending fragments + SENDINFO_DECR(s_entry->info); + call FragPool.put(s_entry->msg); + call SendEntryPool.put(s_entry); + call SendQueue.dequeue(); + + post sendTask(); + } +#endif #if 0 command struct tlv_hdr *IPExtensions.findTlv(struct ip6_ext *ext, uint8_t tlv_val) { int len = ext->len - sizeof(struct ip6_ext); @@ -669,3 +986,4 @@ void SENDINFO_DECR(struct send_info *si) { /* struct ip_metadata *meta) { */ /* } */ } + diff --git a/tos/lib/net/blip/Ieee154AddressC.nc b/tos/lib/net/blip/Ieee154AddressC.nc index 74d83eb43d..77edf3f980 100644 --- a/tos/lib/net/blip/Ieee154AddressC.nc +++ b/tos/lib/net/blip/Ieee154AddressC.nc @@ -5,13 +5,30 @@ configuration Ieee154AddressC { } implementation { components Ieee154AddressP; components LocalIeeeEui64C; + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + components BareMessageC; +#endif + components MainC; Ieee154Address = Ieee154AddressP; MainC.SoftwareInit -> Ieee154AddressP; Ieee154AddressP.LocalIeeeEui64 -> LocalIeeeEui64C; +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + Ieee154AddressP.ShortAddressConfig -> BareMessageC; + +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) // workaround until the radio stack uses this interface components CC2420ControlC; Ieee154AddressP.CC2420Config -> CC2420ControlC; + +#else + // workaround until the radio stack uses this interface + components CC2420ControlC; + Ieee154AddressP.CC2420Config -> CC2420ControlC; +#endif + + } diff --git a/tos/lib/net/blip/Ieee154AddressP.nc b/tos/lib/net/blip/Ieee154AddressP.nc index 82a58a8b81..e70001286c 100644 --- a/tos/lib/net/blip/Ieee154AddressP.nc +++ b/tos/lib/net/blip/Ieee154AddressP.nc @@ -6,7 +6,14 @@ module Ieee154AddressP { } uses { interface LocalIeeeEui64; + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + interface ShortAddressConfig; +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + interface CC2420Config; +#else interface CC2420Config; +#endif } } implementation { ieee154_saddr_t m_saddr; @@ -40,11 +47,29 @@ module Ieee154AddressP { command error_t Ieee154Address.setShortAddr(ieee154_saddr_t addr) { m_saddr = addr; + +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + call ShortAddressConfig.setShortAddr(addr); +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + call CC2420Config.setShortAddr(addr); + call CC2420Config.sync(); +#else call CC2420Config.setShortAddr(addr); call CC2420Config.sync(); +#endif + + signal Ieee154Address.changed(); return SUCCESS; } - event void CC2420Config.syncDone(error_t err) {} +#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_UCMINI) + event void ShortAddressConfig.setShortAddrDone(error_t error){} +#elif defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) + event void CC2420Config.syncDone(error_t err) {} +#else + event void CC2420Config.syncDone(error_t err) {} +#endif + + } diff --git a/tos/lib/net/blip/ReadLqiC.nc b/tos/lib/net/blip/ReadLqiC.nc index 3949c209b1..1ab920c2f8 100644 --- a/tos/lib/net/blip/ReadLqiC.nc +++ b/tos/lib/net/blip/ReadLqiC.nc @@ -20,11 +20,16 @@ configuration ReadLqiC { components CC2420ReadLqiC, CC2420PacketC; ReadLqi = CC2420ReadLqiC; CC2420ReadLqiC.CC2420Packet -> CC2420PacketC; -#elif defined(PLATFORM_IRIS) || defined(PLATFORM_MULLE) +#elif defined(PLATFORM_IRIS) || defined(PLATFORM_MULLE) components RF230ReadLqiC, RF230Ieee154MessageC; ReadLqi = RF230ReadLqiC; RF230ReadLqiC.SubLqi -> RF230Ieee154MessageC.PacketLinkQuality; RF230ReadLqiC.SubRssi -> RF230Ieee154MessageC.PacketRSSI; +#elif defined(PLATFORM_UCMINI) + components RF230ReadLqiC, RFA1Ieee154MessageC; + ReadLqi = RF230ReadLqiC; + RF230ReadLqiC.SubLqi -> RFA1Ieee154MessageC.PacketLinkQuality; + RF230ReadLqiC.SubRssi -> RFA1Ieee154MessageC.PacketRSSI; #else #error "No radio support is available for your platform" #endif diff --git a/tos/lib/net/blip/interfaces/ShortAddressConfig.nc b/tos/lib/net/blip/interfaces/ShortAddressConfig.nc new file mode 100644 index 0000000000..1b8c051abb --- /dev/null +++ b/tos/lib/net/blip/interfaces/ShortAddressConfig.nc @@ -0,0 +1,6 @@ +interface ShortAddressConfig +{ + command void setShortAddr(uint16_t address); + + event void setShortAddrDone(error_t error); +} diff --git a/tos/platforms/iris/chips/rf230/RadioConfig.h b/tos/platforms/iris/chips/rf230/RadioConfig.h index 5ae9ccc75a..8d91f35c61 100644 --- a/tos/platforms/iris/chips/rf230/RadioConfig.h +++ b/tos/platforms/iris/chips/rf230/RadioConfig.h @@ -67,12 +67,12 @@ enum /* This is the default value of the CHANNEL field of the PHY_CC_CCA register. */ #ifndef RF230_DEF_CHANNEL -#define RF230_DEF_CHANNEL 11 +#define RF230_DEF_CHANNEL 13 #endif /* The number of microseconds a sending IRIS mote will wait for an acknowledgement */ #ifndef SOFTWAREACK_TIMEOUT -#define SOFTWAREACK_TIMEOUT 1000 +#define SOFTWAREACK_TIMEOUT 5000 #endif /* diff --git a/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc b/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc index 462a2056f8..1f2891b348 100644 --- a/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc +++ b/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc @@ -147,9 +147,9 @@ implementation { call UARTControl.setUbr(0x08); call UARTControl.setUmctl(0xee); - /* 4000000hz smclk - call UARTControl.setUbr(0x22); - call UARTControl.setUmctl(0xdd); + /* 4mhz smclk + call UARTControl.setUbr(0x23); + call UARTControl.setUmctl(0xd6); */ #endif