diff --git a/.gitignore b/.gitignore index 0ff1ebfa2..811266435 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ COOJA.testlog *.simplelink *.sky *.firmware -*.srf06-cc26xx +*.cc26x0-cc13x0 *.zoul # do not ignore platform makefiles @@ -47,7 +47,7 @@ COOJA.testlog !Makefile.nrf52dk !Makefile.openmote-cc2538 !Makefile.sky -!Makefile.srf06-cc26xx +!Makefile.cc26x0-cc13x0 !Makefile.zoul # other nRF52 build artifacts diff --git a/.gitmodules b/.gitmodules index ed5ea056d..6481bbb93 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,10 +2,10 @@ path = tools/cc2538-bsl url = https://github.com/JelmerT/cc2538-bsl.git [submodule "arch/cpu/cc26xx-cc13xx/lib/cc26xxware"] - path = arch/cpu/cc26xx-cc13xx/lib/cc26xxware + path = arch/cpu/cc26x0-cc13x0/lib/cc26xxware url = https://github.com/contiki-ng/cc26xxware.git [submodule "arch/cpu/cc26xx-cc13xx/lib/cc13xxware"] - path = arch/cpu/cc26xx-cc13xx/lib/cc13xxware + path = arch/cpu/cc26x0-cc13x0/lib/cc13xxware url = https://github.com/contiki-ng/cc13xxware.git [submodule "tools/sensniff"] path = tools/sensniff @@ -26,5 +26,5 @@ path = arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx url = https://github.com/contiki-ng/coresdk_cc13xx_cc26xx.git [submodule "arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk"] - path = arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk + path = arch/cpu/cc26x0-cc13x0/lib/cc2640r2-sdk url = https://github.com/contiki-ng/cc2640r2-sdk.git diff --git a/.travis.yml b/.travis.yml index f5a58c609..d9c98d75d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,10 @@ before_install: docker push $DOCKER_IMG; fi fi - # Build Cooja - - ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar + # Build Cooja conditionally + - if [ ${BUILD_COOJA:-false} = true ] ; then + ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar ; + fi # Set permissions for Docker mount - sudo chgrp -hR 1000 $CNG_HOST_PATH @@ -55,14 +57,15 @@ env: - TEST_NAME='compile-base' - TEST_NAME='compile-arm-ports-01' - TEST_NAME='compile-arm-ports-02' - - TEST_NAME='rpl-lite' - - TEST_NAME='rpl-classic' - - TEST_NAME='tun-rpl-br' + - TEST_NAME='rpl-lite' BUILD_COOJA=true + - TEST_NAME='rpl-classic' BUILD_COOJA=true + - TEST_NAME='tun-rpl-br' BUILD_COOJA=true - TEST_NAME='coap-lwm2m' - - TEST_NAME='simulation-base' - - TEST_NAME='ieee802154' + - TEST_NAME='simulation-base' BUILD_COOJA=true + - TEST_NAME='ieee802154' BUILD_COOJA=true - TEST_NAME='compile-nxp-ports' - TEST_NAME='documentation' - TEST_NAME='compile-tools' - TEST_NAME='native-runs' - - TEST_NAME='ipv6' + - TEST_NAME='ipv6' BUILD_COOJA=true + - TEST_NAME='ipv6-nbr' BUILD_COOJA=true diff --git a/Makefile.embedded b/Makefile.embedded index 4654626c4..e6841926b 100644 --- a/Makefile.embedded +++ b/Makefile.embedded @@ -3,6 +3,9 @@ # Future extensions to the build system that are of a similar nature (for # embedded devices only), can be achieved by extending this Makefile here. +### +### Targets using the tools/serial-io +### RLWRAPGOALS = login serialdump serialview .PHONY: $(RLWRAPGOALS) @@ -31,3 +34,14 @@ serialview: $(SERIAL_DUMP_BIN) login: $(SERIAL_DUMP_BIN) $(SERIALDUMP) -b$(BAUDRATE) $(PORT) + +### +### Targets using tools/motelist +### +CONTIKI_NG_MOTELIST_DIR = $(TOOLS_DIR)/motelist +CONTIKI_NG_MOTELIST = python $(CONTIKI_NG_MOTELIST_DIR)/motelist.py + +.PHONY: motelist-all + +motelist-all: + $(CONTIKI_NG_MOTELIST) diff --git a/Makefile.help b/Makefile.help new file mode 100644 index 000000000..d8de20c00 --- /dev/null +++ b/Makefile.help @@ -0,0 +1,29 @@ +usage: + @echo "Usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [PORT=(PORT)] [target]" + @echo "" + @echo "Typical usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" + @echo "" + @echo " Will build Contiki-NG firmware(s) from the current example dir" + @echo " for platform TARGET, board BOARD." + @echo "" + @echo "Miscellaneous targets:" + @echo " targets Prints list of supported platforms" + @echo " boards Prints a list of supported boards for TARGET" + @echo " savetarget Saves TARGET and BOARD for future invocations of make" + @echo " savedefines Saves DEFINES for future invocations of make" + @echo " clean Removes all compiled files for TARGET" + @echo " distclean Removes all compiled files for all TARGETs" + @echo " viewconf Prints Contiki-NG build configuration for TARGET" + @echo " %.flashprof Shows a Flash/ROM profile of a given firmware (e.g. hello-world.flashprof)" + @echo " %.ramprof Shows a RAM profile of a given firmware (e.g. hello-world.ramprof)" + @echo " %.o Produces an object file from a given source file (e.g. hello-world.o)" + @echo " %.e Produces the pre-processed version of a given source file (e.g. hello-world.e)" + @echo " %.s Produces an assembly file from a given source file (e.g. hello-world.s)" + @echo " login View the serial output of the device connected to PORT" + @echo " serialview Same as login, but prepend serial output with a unix timestamp" + @echo " serialdump same as serialview, but also save the output to a file" + @echo " motelist-all Prints a list of connected devices" + +help: usage diff --git a/Makefile.include b/Makefile.include index 3578730eb..a194274bd 100644 --- a/Makefile.include +++ b/Makefile.include @@ -395,34 +395,7 @@ endif %.flashprof: %.$(TARGET) $(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4 -usage: - @echo "Usage:" - @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [PORT=(PORT)] [target]" - @echo "" - @echo "Typical usage:" - @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" - @echo "" - @echo " Will build Contiki-NG firmware(s) from the current example dir" - @echo " for platform TARGET, board BOARD." - @echo "" - @echo "Miscellaneous targets:" - @echo " targets Prints list of supported platforms" - @echo " boards Prints a list of supported boards for TARGET" - @echo " savetarget Saves TARGET and BOARD for future invocations of make" - @echo " savedefines Saves DEFINES for future invocations of make" - @echo " clean Removes all compiled files for TARGET" - @echo " distclean Removes all compiled files for all TARGETs" - @echo " viewconf Prints Contiki-NG build configuration for TARGET" - @echo " %.flashprof Shows a Flash/ROM profile of a given firmware (e.g. hello-world.flashprof)" - @echo " %.ramprof Shows a RAM profile of a given firmware (e.g. hello-world.ramprof)" - @echo " %.o Produces an object file from a given source file (e.g. hello-world.o)" - @echo " %.e Produces the pre-processed version of a given source file (e.g. hello-world.e)" - @echo " %.s Produces an assembly file from a given source file (e.g. hello-world.s)" - @echo " login View the serial output of the device connected to PORT" - @echo " serialview Same as login, but prepend serial output with a unix timestamp" - @echo " serialdump same as serialview, but also save the output to a file" - -help: usage +include $(CONTIKI)/Makefile.help targets: @ls $(CONTIKI)/arch/platform $(TARGETDIRS) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx b/arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 similarity index 65% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc13xx rename to arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 index ac050efe8..c29ee7270 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 @@ -1,7 +1,7 @@ TI_XXWARE_PATH = lib/cc13xxware -CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c +CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c cc13xx-50kbps-tsch.c CFLAGS += -DCPU_FAMILY_CC13X0=1 -DCPU_FAMILY_CC13XX=1 -include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx +include $(CONTIKI_CPU)/Makefile.cc26x0-cc13x0 diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0 similarity index 65% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc26xx rename to arch/cpu/cc26x0-cc13x0/Makefile.cc26x0 index 34a147f7b..51db3f205 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0 @@ -2,4 +2,4 @@ TI_XXWARE_PATH = lib/cc26xxware CFLAGS += -DCPU_FAMILY_CC26X0=1 -DCPU_FAMILY_CC26XX=1 -include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx +include $(CONTIKI_CPU)/Makefile.cc26x0-cc13x0 diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 similarity index 96% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx rename to arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 00f9ae232..e62b8be05 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -1,8 +1,8 @@ -CPU_ABS_PATH = arch/cpu/cc26xx-cc13xx +CPU_ABS_PATH = arch/cpu/cc26x0-cc13x0 TI_XXWARE = $(CONTIKI_CPU)/$(TI_XXWARE_PATH) -ifeq (,$(wildcard $(TI_XXWARE))) - $(warning $(TI_XXWARE) does not exist.) +ifeq (,$(wildcard $(TI_XXWARE)/*)) + $(warning $(TI_XXWARE) does not exist or is empty.) $(warning Did you run 'git submodule update --init' ?) $(error "") endif diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0r2f similarity index 67% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f rename to arch/cpu/cc26x0-cc13x0/Makefile.cc26x0r2f index 56d041516..5118cd6a8 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0r2f @@ -2,4 +2,4 @@ TI_XXWARE_PATH = lib/cc2640r2-sdk CFLAGS += -DCPU_FAMILY_CC26X0R2=1 -DCPU_FAMILY_CC26XXR2=1 -include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx +include $(CONTIKI_CPU)/Makefile.cc26x0-cc13x0 diff --git a/arch/cpu/cc26xx-cc13xx/ble-addr.c b/arch/cpu/cc26x0-cc13x0/ble-addr.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/ble-addr.c rename to arch/cpu/cc26x0-cc13x0/ble-addr.c diff --git a/arch/cpu/cc26xx-cc13xx/ble-addr.h b/arch/cpu/cc26x0-cc13x0/ble-addr.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/ble-addr.h rename to arch/cpu/cc26x0-cc13x0/ble-addr.h diff --git a/arch/cpu/cc26xx-cc13xx/cc13x0-cc26x0-cm3.h b/arch/cpu/cc26x0-cc13x0/cc13x0-cc26x0-cm3.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/cc13x0-cc26x0-cm3.h rename to arch/cpu/cc26x0-cc13x0/cc13x0-cc26x0-cm3.h diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h b/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h rename to arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-def.h similarity index 79% rename from arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h rename to arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-def.h index 47dbc4eb5..97b188e15 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-def.h @@ -36,12 +36,43 @@ /*---------------------------------------------------------------------------*/ /* TSCH related defines */ +/* 2 bytes header, 4 bytes CRC */ +#define CC13XX_RADIO_PHY_OVERHEAD 6 +/* 3 bytes preamble, 3 bytes sync */ +#define CC13XX_RADIO_PHY_HEADER_LEN 6 +/* The default data rate is 50 kbps */ +#define CC13XX_RADIO_BIT_RATE 50000 + /* 1 len byte, 2 bytes CRC */ -#define RADIO_PHY_OVERHEAD 3 -/* 250kbps data rate. One byte = 32us */ -#define RADIO_BYTE_AIR_TIME 32 +#define CC26XX_RADIO_PHY_OVERHEAD 3 +/* 4 bytes preamble, 1 byte sync */ +#define CC26XX_RADIO_PHY_HEADER_LEN 5 +/* The fixed data rate is 250 kbps */ +#define CC26XX_RADIO_BIT_RATE 250000 + +#if CPU_FAMILY_CC13XX +#define RADIO_PHY_HEADER_LEN CC13XX_RADIO_PHY_HEADER_LEN +#define RADIO_PHY_OVERHEAD CC13XX_RADIO_PHY_OVERHEAD +#define RADIO_BIT_RATE CC13XX_RADIO_BIT_RATE + +/* The TSCH default slot length of 10ms is too short, use custom one instead */ +#ifndef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING tsch_timing_cc13xx_50kbps +#endif /* TSCH_CONF_DEFAULT_TIMESLOT_TIMING */ + +/* Symbol for the custom TSCH timeslot timing template */ +#define TSCH_CONF_ARCH_HDR_PATH "rf-core/cc13xx-50kbps-tsch.h" + +#else +#define RADIO_PHY_HEADER_LEN CC26XX_RADIO_PHY_HEADER_LEN +#define RADIO_PHY_OVERHEAD CC26XX_RADIO_PHY_OVERHEAD +#define RADIO_BIT_RATE CC26XX_RADIO_BIT_RATE +#endif + +#define RADIO_BYTE_AIR_TIME (1000000 / (RADIO_BIT_RATE / 8)) + /* Delay between GO signal and SFD */ -#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(81)) +#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(RADIO_PHY_HEADER_LEN * RADIO_BYTE_AIR_TIME)) /* Delay between GO signal and start listening. * This value is so small because the radio is constantly on within each timeslot. */ #define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(15)) @@ -56,9 +87,6 @@ #define RADIO_TO_RTIMER(X) ((uint32_t)(((uint64_t)(X) * (RTIMER_SECOND / 256)) / (RADIO_TIMER_SECOND / 256))) #define USEC_TO_RADIO(X) ((X) * 4) -/* The PHY header (preamble + SFD, 4+1 bytes) duration is equivalent to 10 symbols */ -#define RADIO_IEEE_802154_PHY_HEADER_DURATION_USEC 160 - /* Do not turn off TSCH within a timeslot: not enough time */ #define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1 diff --git a/arch/cpu/cc26xx-cc13xx/cc26xx.ld b/arch/cpu/cc26x0-cc13x0/cc26xx.ld similarity index 100% rename from arch/cpu/cc26xx-cc13xx/cc26xx.ld rename to arch/cpu/cc26x0-cc13x0/cc26xx.ld diff --git a/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h b/arch/cpu/cc26x0-cc13x0/ccxxware-conf.h similarity index 98% rename from arch/cpu/cc26xx-cc13xx/ccxxware-conf.h rename to arch/cpu/cc26x0-cc13x0/ccxxware-conf.h index bc26f1171..c101deb08 100644 --- a/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h +++ b/arch/cpu/cc26x0-cc13x0/ccxxware-conf.h @@ -36,7 +36,7 @@ * @{ * * \file - * CCxxware-specific configuration for the cc26xx-cc13xx CPU family + * CCxxware-specific configuration for the cc26x0-cc13x0 CPU family */ #ifndef CCXXWARE_CONF_H_ #define CCXXWARE_CONF_H_ diff --git a/arch/cpu/cc26xx-cc13xx/clock.c b/arch/cpu/cc26x0-cc13x0/clock.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/clock.c rename to arch/cpu/cc26x0-cc13x0/clock.c diff --git a/arch/cpu/cc26xx-cc13xx/dbg.c b/arch/cpu/cc26x0-cc13x0/dbg.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dbg.c rename to arch/cpu/cc26x0-cc13x0/dbg.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c b/arch/cpu/cc26x0-cc13x0/dev/adc-sensor.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c rename to arch/cpu/cc26x0-cc13x0/dev/adc-sensor.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.h b/arch/cpu/cc26x0-cc13x0/dev/adc-sensor.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/adc-sensor.h rename to arch/cpu/cc26x0-cc13x0/dev/adc-sensor.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/aux-ctrl.c b/arch/cpu/cc26x0-cc13x0/dev/aux-ctrl.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/aux-ctrl.c rename to arch/cpu/cc26x0-cc13x0/dev/aux-ctrl.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/aux-ctrl.h b/arch/cpu/cc26x0-cc13x0/dev/aux-ctrl.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/aux-ctrl.h rename to arch/cpu/cc26x0-cc13x0/dev/aux-ctrl.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/batmon-sensor.c b/arch/cpu/cc26x0-cc13x0/dev/batmon-sensor.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/batmon-sensor.c rename to arch/cpu/cc26x0-cc13x0/dev/batmon-sensor.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/batmon-sensor.h b/arch/cpu/cc26x0-cc13x0/dev/batmon-sensor.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/batmon-sensor.h rename to arch/cpu/cc26x0-cc13x0/dev/batmon-sensor.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/cc26xx-uart.c b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/cc26xx-uart.c rename to arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/cc26xx-uart.h b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/cc26xx-uart.h rename to arch/cpu/cc26x0-cc13x0/dev/cc26xx-uart.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/contiki-watchdog.c b/arch/cpu/cc26x0-cc13x0/dev/contiki-watchdog.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/contiki-watchdog.c rename to arch/cpu/cc26x0-cc13x0/dev/contiki-watchdog.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c b/arch/cpu/cc26x0-cc13x0/dev/gpio-hal-arch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c rename to arch/cpu/cc26x0-cc13x0/dev/gpio-hal-arch.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h b/arch/cpu/cc26x0-cc13x0/dev/gpio-hal-arch.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h rename to arch/cpu/cc26x0-cc13x0/dev/gpio-hal-arch.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c b/arch/cpu/cc26x0-cc13x0/dev/gpio-interrupt.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c rename to arch/cpu/cc26x0-cc13x0/dev/gpio-interrupt.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/oscillators.c b/arch/cpu/cc26x0-cc13x0/dev/oscillators.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/oscillators.c rename to arch/cpu/cc26x0-cc13x0/dev/oscillators.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/oscillators.h b/arch/cpu/cc26x0-cc13x0/dev/oscillators.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/oscillators.h rename to arch/cpu/cc26x0-cc13x0/dev/oscillators.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c b/arch/cpu/cc26x0-cc13x0/dev/soc-rtc.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c rename to arch/cpu/cc26x0-cc13x0/dev/soc-rtc.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.h b/arch/cpu/cc26x0-cc13x0/dev/soc-rtc.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/soc-rtc.h rename to arch/cpu/cc26x0-cc13x0/dev/soc-rtc.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c b/arch/cpu/cc26x0-cc13x0/dev/soc-trng.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/soc-trng.c rename to arch/cpu/cc26x0-cc13x0/dev/soc-trng.c diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.h b/arch/cpu/cc26x0-cc13x0/dev/soc-trng.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/soc-trng.h rename to arch/cpu/cc26x0-cc13x0/dev/soc-trng.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26x0-cc13x0/dev/spi-arch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/spi-arch.c rename to arch/cpu/cc26x0-cc13x0/dev/spi-arch.c diff --git a/arch/cpu/cc26xx-cc13xx/doxygen-group.txt b/arch/cpu/cc26x0-cc13x0/doxygen-group.txt similarity index 100% rename from arch/cpu/cc26xx-cc13xx/doxygen-group.txt rename to arch/cpu/cc26x0-cc13x0/doxygen-group.txt diff --git a/arch/cpu/cc26xx-cc13xx/fault-handlers.c b/arch/cpu/cc26x0-cc13x0/fault-handlers.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/fault-handlers.c rename to arch/cpu/cc26x0-cc13x0/fault-handlers.c diff --git a/arch/cpu/cc26xx-cc13xx/ieee-addr.c b/arch/cpu/cc26x0-cc13x0/ieee-addr.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/ieee-addr.c rename to arch/cpu/cc26x0-cc13x0/ieee-addr.c diff --git a/arch/cpu/cc26xx-cc13xx/ieee-addr.h b/arch/cpu/cc26x0-cc13x0/ieee-addr.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/ieee-addr.h rename to arch/cpu/cc26x0-cc13x0/ieee-addr.h diff --git a/arch/cpu/cc26xx-cc13xx/int-master.c b/arch/cpu/cc26x0-cc13x0/int-master.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/int-master.c rename to arch/cpu/cc26x0-cc13x0/int-master.c diff --git a/arch/cpu/cc26xx-cc13xx/lib/cc13xxware b/arch/cpu/cc26x0-cc13x0/lib/cc13xxware similarity index 100% rename from arch/cpu/cc26xx-cc13xx/lib/cc13xxware rename to arch/cpu/cc26x0-cc13x0/lib/cc13xxware diff --git a/arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk b/arch/cpu/cc26x0-cc13x0/lib/cc2640r2-sdk similarity index 100% rename from arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk rename to arch/cpu/cc26x0-cc13x0/lib/cc2640r2-sdk diff --git a/arch/cpu/cc26xx-cc13xx/lib/cc26xxware b/arch/cpu/cc26x0-cc13x0/lib/cc26xxware similarity index 100% rename from arch/cpu/cc26xx-cc13xx/lib/cc26xxware rename to arch/cpu/cc26x0-cc13x0/lib/cc26xxware diff --git a/arch/cpu/cc26xx-cc13xx/lpm.c b/arch/cpu/cc26x0-cc13x0/lpm.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/lpm.c rename to arch/cpu/cc26x0-cc13x0/lpm.c diff --git a/arch/cpu/cc26xx-cc13xx/lpm.h b/arch/cpu/cc26x0-cc13x0/lpm.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/lpm.h rename to arch/cpu/cc26x0-cc13x0/lpm.h diff --git a/arch/cpu/cc26xx-cc13xx/random.c b/arch/cpu/cc26x0-cc13x0/random.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/random.c rename to arch/cpu/cc26x0-cc13x0/random.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/api/ieee_cmd.h b/arch/cpu/cc26x0-cc13x0/rf-core/api/ieee_cmd.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/api/ieee_cmd.h rename to arch/cpu/cc26x0-cc13x0/rf-core/api/ieee_cmd.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/api/ieee_mailbox.h b/arch/cpu/cc26x0-cc13x0/rf-core/api/ieee_mailbox.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/api/ieee_mailbox.h rename to arch/cpu/cc26x0-cc13x0/rf-core/api/ieee_mailbox.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-cc2650.c b/arch/cpu/cc26x0-cc13x0/rf-core/ble-cc2650.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/ble-cc2650.c rename to arch/cpu/cc26x0-cc13x0/rf-core/ble-cc2650.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c b/arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/ble-hal-cc26xx.c similarity index 99% rename from arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c rename to arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/ble-hal-cc26xx.c index a9b949d93..3245b9c4f 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c +++ b/arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/ble-hal-cc26xx.c @@ -386,7 +386,7 @@ on(void) rf_core_power_down(); return RF_CORE_CMD_ERROR; } - rf_core_setup_interrupts(0); + rf_core_setup_interrupts(); oscillators_switch_to_hf_xosc(); if(rf_ble_cmd_setup_ble_mode() != RF_BLE_CMD_OK) { diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.h b/arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/ble-hal-cc26xx.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.h rename to arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/ble-hal-cc26xx.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c b/arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/rf-ble-cmd.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c rename to arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/rf-ble-cmd.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h b/arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/rf-ble-cmd.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h rename to arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/rf-ble-cmd.h diff --git a/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c new file mode 100644 index 000000000..af76d63e3 --- /dev/null +++ b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * IEEE 802.15.4 TSCH timeslot timings for CC13xx chips at 50kbps datarate + * \author + * Atis Elsts + * + */ + +#include "contiki.h" +#include "net/mac/tsch/tsch.h" + +#define CC13XX_TSCH_DEFAULT_TS_CCA_OFFSET 1800 +#define CC13XX_TSCH_DEFAULT_TS_CCA 128 +#define CC13XX_TSCH_DEFAULT_TS_TX_OFFSET 2500 +#define CC13XX_TSCH_DEFAULT_TS_RX_OFFSET (CC13XX_TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2)) +#define CC13XX_TSCH_DEFAULT_TS_RX_ACK_DELAY 2000 +#define CC13XX_TSCH_DEFAULT_TS_TX_ACK_DELAY 3000 +#define CC13XX_TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT +#define CC13XX_TSCH_DEFAULT_TS_ACK_WAIT 3000 +#define CC13XX_TSCH_DEFAULT_TS_RX_TX 192 +#define CC13XX_TSCH_DEFAULT_TS_MAX_ACK 10000 +#define CC13XX_TSCH_DEFAULT_TS_MAX_TX 21600 + +/* Timeslot length: 40000 usec */ +#define CC13XX_TSCH_DEFAULT_TS_TIMESLOT_LENGTH 40000 + +/* TSCH timeslot timing (microseconds) */ +const uint16_t tsch_timing_cc13xx_50kbps[tsch_ts_elements_count] = { + CC13XX_TSCH_DEFAULT_TS_CCA_OFFSET, + CC13XX_TSCH_DEFAULT_TS_CCA, + CC13XX_TSCH_DEFAULT_TS_TX_OFFSET, + CC13XX_TSCH_DEFAULT_TS_RX_OFFSET, + CC13XX_TSCH_DEFAULT_TS_RX_ACK_DELAY, + CC13XX_TSCH_DEFAULT_TS_TX_ACK_DELAY, + CC13XX_TSCH_DEFAULT_TS_RX_WAIT, + CC13XX_TSCH_DEFAULT_TS_ACK_WAIT, + CC13XX_TSCH_DEFAULT_TS_RX_TX, + CC13XX_TSCH_DEFAULT_TS_MAX_ACK, + CC13XX_TSCH_DEFAULT_TS_MAX_TX, + CC13XX_TSCH_DEFAULT_TS_TIMESLOT_LENGTH, +}; diff --git a/tools/sky/uip6-bridge/project-conf.h b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.h similarity index 77% rename from tools/sky/uip6-bridge/project-conf.h rename to arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.h index 651d45cda..5d4fdb376 100644 --- a/tools/sky/uip6-bridge/project-conf.h +++ b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Swedish Institute of Computer Science. + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,24 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * + * This file is part of the Contiki operating system. + * */ -/** - * \file - * A brief description of what this file is - * \author - * Niclas Finne - * Joakim Eriksson - */ +#ifndef CC13XX_50KBPS_TSCH_H_ +#define CC13XX_50KBPS_TSCH_H_ -#ifndef BRIDGE_CONF_H_ -#define BRIDGE_CONF_H_ +#include "contiki.h" -#undef UIP_CONF_ROUTER +/* TSCH timeslot timing (microseconds) */ +extern const uint16_t tsch_timing_cc13xx_50kbps[]; -#undef UIP_CONF_LLH_LEN -#define UIP_CONF_LLH_LEN 14 - -#undef UIP_CONF_BUFFER_SIZE -#define UIP_CONF_BUFFER_SIZE 256 -#endif /* BRIDGE_CONF_H_ */ +#endif /* CC13XX_50KBPS_TSCH_H_ */ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h b/arch/cpu/cc26x0-cc13x0/rf-core/dot-15-4g.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h rename to arch/cpu/cc26x0-cc13x0/rf-core/dot-15-4g.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c b/arch/cpu/cc26x0-cc13x0/rf-core/ieee-mode.c similarity index 82% rename from arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c rename to arch/cpu/cc26x0-cc13x0/rf-core/ieee-mode.c index 3516147b5..9f4021d21 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c +++ b/arch/cpu/cc26x0-cc13x0/rf-core/ieee-mode.c @@ -120,6 +120,8 @@ static uint8_t rf_stats[16] = { 0 }; /* The size of the RF commands buffer */ #define RF_CMD_BUFFER_SIZE 128 /*---------------------------------------------------------------------------*/ +#define RAT_TIMESTAMP_OFFSET_2_4_GHZ 0 +/*---------------------------------------------------------------------------*/ /** * \brief Returns the current status of a running Radio Op command * \param a A pointer with the buffer used to initiate the command @@ -130,55 +132,9 @@ static uint8_t rf_stats[16] = { 0 }; */ #define RF_RADIO_OP_GET_STATUS(a) (((rfc_radioOp_t *)a)->status) /*---------------------------------------------------------------------------*/ -/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ -#define RF_CMD_CCA_REQ_RSSI_UNKNOWN -128 - -/* Used for the return value of channel_clear */ -#define RF_CCA_CLEAR 1 -#define RF_CCA_BUSY 0 - -/* Used as an error return value for get_cca_info */ -#define RF_GET_CCA_INFO_ERROR 0xFF - -/* - * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's - * status struct - */ -#define RF_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ -#define RF_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ -#define RF_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ - -#define RF_CMD_CCA_REQ_CCA_CORR_IDLE (0 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_BUSY (1 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_INVALID (3 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_MASK (3 << 4) - -#define RF_CMD_CCA_REQ_CCA_SYNC_BUSY (1 << 6) -/*---------------------------------------------------------------------------*/ #define IEEE_MODE_CHANNEL_MIN 11 #define IEEE_MODE_CHANNEL_MAX 26 /*---------------------------------------------------------------------------*/ -/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ -#define TX_WAIT_TIMEOUT (RTIMER_SECOND >> 11) - -/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ -#define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) - -/* How long to wait for the RF to react on CMD_ABORT: around 1 msec */ -#define RF_TURN_OFF_WAIT_TIMEOUT (RTIMER_SECOND >> 10) - -/* How long to wait for the RF to finish TX of a packet or an ACK */ -#define TX_FINISH_WAIT_TIMEOUT (RTIMER_SECOND >> 7) - -#define LIMITED_BUSYWAIT(cond, timeout) do { \ - rtimer_clock_t end_time = RTIMER_NOW() + timeout; \ - while(cond) { \ - if(!RTIMER_CLOCK_LT(RTIMER_NOW(), end_time)) { \ - break; \ - } \ - } \ - } while(0) -/*---------------------------------------------------------------------------*/ /* TX Power dBm lookup table - values from SmartRF Studio */ typedef struct output_config { radio_value_t dbm; @@ -211,33 +167,6 @@ static const output_config_t output_power[] = { /* Default TX Power - position in output_power[] */ static const output_config_t *tx_power_current = &output_power[0]; /*---------------------------------------------------------------------------*/ -static volatile int8_t last_rssi = 0; -static volatile uint8_t last_corr_lqi = 0; - -extern int32_t rat_offset; - -/*---------------------------------------------------------------------------*/ -/* SFD timestamp in RTIMER ticks */ -static volatile uint32_t last_packet_timestamp = 0; -/* SFD timestamp in RAT ticks (but 64 bits) */ -static uint64_t last_rat_timestamp64 = 0; - -/* For RAT overflow handling */ -static struct ctimer rat_overflow_timer; -static volatile uint32_t rat_overflow_counter = 0; -static rtimer_clock_t last_rat_overflow = 0; - -/* RAT has 32-bit register, overflows once 18 minutes */ -#define RAT_RANGE 4294967296ull -/* approximate value */ -#define RAT_OVERFLOW_PERIOD_SECONDS (60 * 18) - -/* XXX: don't know what exactly is this, looks like the time to Tx 3 octets */ -#define TIMESTAMP_OFFSET -(USEC_TO_RADIO(32 * 3) - 1) /* -95.75 usec */ -/*---------------------------------------------------------------------------*/ -/* Are we currently in poll mode? */ -static uint8_t poll_mode = 0; - static rfc_CMD_IEEE_MOD_FILT_t filter_cmd; /*---------------------------------------------------------------------------*/ /* @@ -256,27 +185,28 @@ static uint8_t cmd_ieee_rx_buf[RF_CMD_BUFFER_SIZE] CC_ALIGN(4); #define DATA_ENTRY_LENSZ_BYTE 1 #define DATA_ENTRY_LENSZ_WORD 2 /* 2 bytes */ -#define RX_BUF_SIZE 144 -/* Four receive buffers entries with room for 1 IEEE802.15.4 frame in each */ -static uint8_t rx_buf_0[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_1[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_2[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_3[RX_BUF_SIZE] CC_ALIGN(4); - -#define RX_BUF_INCLUDE_CRC 1 -#define RX_BUF_INCLUDE_RSSI 1 -#define RX_BUF_INCLUDE_CORR 1 -#define RX_BUF_INCLUDE_TIMESTAMP 1 - /* The size of the metadata (excluding the packet length field) */ #define RX_BUF_METADATA_SIZE \ - (2 * RX_BUF_INCLUDE_CRC + RX_BUF_INCLUDE_RSSI + RX_BUF_INCLUDE_CORR + 4 * RX_BUF_INCLUDE_TIMESTAMP) + (2 * RF_CORE_RX_BUF_INCLUDE_CRC \ + + RF_CORE_RX_BUF_INCLUDE_RSSI \ + + RF_CORE_RX_BUF_INCLUDE_CORR \ + + 4 * RF_CORE_RX_BUF_INCLUDE_TIMESTAMP) /* The offset of the packet length in a rx buffer */ #define RX_BUF_LENGTH_OFFSET sizeof(rfc_dataEntry_t) /* The offset of the packet data in a rx buffer */ #define RX_BUF_DATA_OFFSET (RX_BUF_LENGTH_OFFSET + 1) +#define RX_BUF_SIZE (RX_BUF_DATA_OFFSET \ + + NETSTACK_RADIO_MAX_PAYLOAD_LEN \ + + RX_BUF_METADATA_SIZE) + +/* Four receive buffers entries with room for 1 IEEE802.15.4 frame in each */ +static uint8_t rx_buf_0[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_1[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_2[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_3[RX_BUF_SIZE] CC_ALIGN(4); + /* The RX Data Queue */ static dataQueue_t rx_data_queue = { 0 }; @@ -358,8 +288,8 @@ transmitting(void) return 0; } - if((cmd.currentRssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN) && - (cmd.ccaInfo.ccaEnergy == RF_CMD_CCA_REQ_CCA_STATE_BUSY)) { + if((cmd.currentRssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) && + (cmd.ccaInfo.ccaEnergy == RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY)) { return 1; } @@ -368,12 +298,12 @@ transmitting(void) /*---------------------------------------------------------------------------*/ /** * \brief Returns CCA information - * \return RF_GET_CCA_INFO_ERROR if the RF was not on + * \return RF_CORE_GET_CCA_INFO_ERROR if the RF was not on * \return On success, the return value is formatted as per the ccaInfo field * of CMD_IEEE_CCA_REQ * * It is the caller's responsibility to make sure the RF is on. This function - * will return RF_GET_CCA_INFO_ERROR if the RF is off + * will return RF_CORE_GET_CCA_INFO_ERROR if the RF is off * * This function will in fact wait for a valid CCA state */ @@ -385,20 +315,20 @@ get_cca_info(void) if(!rf_is_on()) { PRINTF("get_cca_info: Not on\n"); - return RF_GET_CCA_INFO_ERROR; + return RF_CORE_GET_CCA_INFO_ERROR; } memset(&cmd, 0x00, sizeof(cmd)); - cmd.ccaInfo.ccaState = RF_CMD_CCA_REQ_CCA_STATE_INVALID; + cmd.ccaInfo.ccaState = RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID; - while(cmd.ccaInfo.ccaState == RF_CMD_CCA_REQ_CCA_STATE_INVALID) { + while(cmd.ccaInfo.ccaState == RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_IEEE_CCA_REQ; if(rf_core_send_cmd((uint32_t)&cmd, &cmd_status) == RF_CORE_CMD_ERROR) { PRINTF("get_cca_info: CMDSTA=0x%08lx\n", cmd_status); - return RF_GET_CCA_INFO_ERROR; + return RF_CORE_GET_CCA_INFO_ERROR; } } @@ -425,14 +355,14 @@ get_rssi(void) was_off = 1; if(on() != RF_CORE_CMD_OK) { PRINTF("get_rssi: on() failed\n"); - return RF_CMD_CCA_REQ_RSSI_UNKNOWN; + return RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; } } memset(&cmd, 0x00, sizeof(cmd)); - cmd.ccaInfo.ccaEnergy = RF_CMD_CCA_REQ_CCA_STATE_INVALID; + cmd.ccaInfo.ccaEnergy = RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID; - while(cmd.ccaInfo.ccaEnergy == RF_CMD_CCA_REQ_CCA_STATE_INVALID) { + while(cmd.ccaInfo.ccaEnergy == RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_IEEE_CCA_REQ; @@ -440,7 +370,7 @@ get_rssi(void) PRINTF("get_rssi: CMDSTA=0x%08lx\n", cmd_status); /* Make sure to return RSSI unknown */ - cmd.currentRssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + cmd.currentRssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; break; } } @@ -558,8 +488,8 @@ rf_cmd_ieee_rx() return RF_CORE_CMD_ERROR; } - LIMITED_BUSYWAIT(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE, - ENTER_RX_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == RF_CORE_RADIO_OP_STATUS_ACTIVE, + RF_CORE_ENTER_RX_TIMEOUT); /* Wait to enter RX */ if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE) { @@ -615,11 +545,11 @@ init_rf_params(void) cmd->rxConfig.bAutoFlushCrc = 1; cmd->rxConfig.bAutoFlushIgn = 0; cmd->rxConfig.bIncludePhyHdr = 0; - cmd->rxConfig.bIncludeCrc = RX_BUF_INCLUDE_CRC; - cmd->rxConfig.bAppendRssi = RX_BUF_INCLUDE_RSSI; - cmd->rxConfig.bAppendCorrCrc = RX_BUF_INCLUDE_CORR; + cmd->rxConfig.bIncludeCrc = RF_CORE_RX_BUF_INCLUDE_CRC; + cmd->rxConfig.bAppendRssi = RF_CORE_RX_BUF_INCLUDE_RSSI; + cmd->rxConfig.bAppendCorrCrc = RF_CORE_RX_BUF_INCLUDE_CORR; cmd->rxConfig.bAppendSrcInd = 0; - cmd->rxConfig.bAppendTimestamp = RX_BUF_INCLUDE_TIMESTAMP; + cmd->rxConfig.bAppendTimestamp = RF_CORE_RX_BUF_INCLUDE_TIMESTAMP; cmd->pRxQ = &rx_data_queue; cmd->pOutput = (rfc_ieeeRxOutput_t *)rf_stats; @@ -714,7 +644,7 @@ rx_off(void) } /* Wait for ongoing ACK TX to finish */ - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); /* Send a CMD_ABORT command to RF Core */ if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_ABORT), &cmd_status) != RF_CORE_CMD_OK) { @@ -722,7 +652,7 @@ rx_off(void) /* Continue nonetheless */ } - LIMITED_BUSYWAIT(rf_is_on(), RF_TURN_OFF_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!rf_is_on(), RF_CORE_TURN_OFF_TIMEOUT); if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_STOPPED || RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_ABORT) { @@ -773,8 +703,8 @@ soft_off(void) return; } - LIMITED_BUSYWAIT((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) == - RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_TURN_OFF_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) != + RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_CORE_TURN_OFF_TIMEOUT); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -791,71 +721,10 @@ soft_on(void) static const rf_core_primary_mode_t mode_ieee = { soft_off, soft_on, + rf_is_on, + RAT_TIMESTAMP_OFFSET_2_4_GHZ }; /*---------------------------------------------------------------------------*/ -static uint8_t -check_rat_overflow(bool first_time) -{ - static uint32_t last_value; - uint32_t current_value; - uint8_t interrupts_disabled; - - /* Bail out if the RF is not on */ - if(!rf_is_on()) { - return 0; - } - - interrupts_disabled = ti_lib_int_master_disable(); - if(first_time) { - last_value = HWREG(RFC_RAT_BASE + RATCNT); - } else { - current_value = HWREG(RFC_RAT_BASE + RATCNT); - if(current_value + RAT_RANGE / 4 < last_value) { - /* Overflow detected */ - last_rat_overflow = RTIMER_NOW(); - rat_overflow_counter++; - } - last_value = current_value; - } - if(!interrupts_disabled) { - ti_lib_int_master_enable(); - } - return 1; -} -/*---------------------------------------------------------------------------*/ -static void -handle_rat_overflow(void *unused) -{ - uint8_t success; - uint8_t was_off = 0; - - if(!rf_is_on()) { - was_off = 1; - if(on() != RF_CORE_CMD_OK) { - PRINTF("overflow: on() failed\n"); - ctimer_set(&rat_overflow_timer, CLOCK_SECOND, - handle_rat_overflow, NULL); - return; - } - } - - success = check_rat_overflow(false); - - if(was_off) { - off(); - } - - if(success) { - /* Retry after half of the interval */ - ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_PERIOD_SECONDS * CLOCK_SECOND / 2, - handle_rat_overflow, NULL); - } else { - /* Retry sooner */ - ctimer_set(&rat_overflow_timer, CLOCK_SECOND, - handle_rat_overflow, NULL); - } -} -/*---------------------------------------------------------------------------*/ static int init(void) { @@ -889,9 +758,7 @@ init(void) rf_core_primary_mode_register(&mode_ieee); - check_rat_overflow(true); - ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_PERIOD_SECONDS * CLOCK_SECOND / 2, - handle_rat_overflow, NULL); + rf_core_rat_init(); process_start(&rf_core_process, NULL); return 1; @@ -935,7 +802,7 @@ transmit(unsigned short transmit_len) do { tx_active = transmitting(); } while(tx_active == 1 && - (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TX_WAIT_TIMEOUT))); + (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + RF_CORE_TX_TIMEOUT))); if(tx_active) { PRINTF("transmit: Already TXing and wait timed out\n"); @@ -957,7 +824,7 @@ transmit(unsigned short transmit_len) cmd.startTrigger.triggerType = TRIG_NOW; /* Enable the LAST_FG_COMMAND_DONE interrupt, which will wake us up */ - rf_core_cmd_done_en(true, poll_mode); + rf_core_cmd_done_en(true); ret = rf_core_send_cmd((uint32_t)&cmd, &cmd_status); @@ -973,7 +840,7 @@ transmit(unsigned short transmit_len) * 1) make the `lpm_sleep()` call here unconditional; * 2) change the radio ISR priority to allow radio ISR to interrupt rtimer ISR. */ - if(!poll_mode) { + if(!rf_core_poll_mode) { lpm_sleep(); } } @@ -1007,7 +874,7 @@ transmit(unsigned short transmit_len) * Disable LAST_FG_COMMAND_DONE interrupt. We don't really care about it * except when we are transmitting */ - rf_core_cmd_done_dis(poll_mode); + rf_core_cmd_done_dis(); if(was_off) { off(); @@ -1036,46 +903,6 @@ release_data_entry(void) rx_read_entry = entry->pNextEntry; } /*---------------------------------------------------------------------------*/ -static uint32_t -calc_last_packet_timestamp(uint32_t rat_timestamp) -{ - uint64_t rat_timestamp64; - uint32_t adjusted_overflow_counter; - uint8_t was_off = 0; - - if(!rf_is_on()) { - was_off = 1; - on(); - } - - if(rf_is_on()) { - check_rat_overflow(false); - if(was_off) { - off(); - } - } - - adjusted_overflow_counter = rat_overflow_counter; - - /* if the timestamp is large and the last oveflow was recently, - assume that the timestamp refers to the time before the overflow */ - if(rat_timestamp > (uint32_t)(RAT_RANGE * 3 / 4)) { - if(RTIMER_CLOCK_LT(RTIMER_NOW(), - last_rat_overflow + RAT_OVERFLOW_PERIOD_SECONDS * RTIMER_SECOND / 4)) { - adjusted_overflow_counter--; - } - } - - /* add the overflowed time to the timestamp */ - rat_timestamp64 = rat_timestamp + RAT_RANGE * adjusted_overflow_counter; - /* correct timestamp so that it refers to the end of the SFD */ - rat_timestamp64 += TIMESTAMP_OFFSET; - - last_rat_timestamp64 = rat_timestamp64 - rat_offset; - - return RADIO_TO_RTIMER(rat_timestamp64 - rat_offset); -} -/*---------------------------------------------------------------------------*/ static int read_frame(void *buf, unsigned short buf_len) { @@ -1111,20 +938,20 @@ read_frame(void *buf, unsigned short buf_len) memcpy(buf, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET, len); - last_rssi = (int8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 2]; - last_corr_lqi = (uint8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 3] & STATUS_CORRELATION; + rf_core_last_rssi = (int8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len]; + rf_core_last_corr_lqi = (uint8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 1] & STATUS_CORRELATION; /* get the timestamp */ - memcpy(&rat_timestamp, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET + len + 4, 4); + memcpy(&rat_timestamp, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET + len + 2, 4); - last_packet_timestamp = calc_last_packet_timestamp(rat_timestamp); + rf_core_last_packet_timestamp = rf_core_convert_rat_to_rtimer(rat_timestamp); - if(!poll_mode) { + if(!rf_core_poll_mode) { /* Not in poll mode: packetbuf should not be accessed in interrupt context. * In poll mode, the last packet RSSI and link quality can be obtained through * RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */ - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, last_rssi); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, last_corr_lqi); + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rf_core_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rf_core_last_corr_lqi); } release_data_entry(); @@ -1137,7 +964,7 @@ channel_clear(void) { uint8_t was_off = 0; uint8_t cca_info; - int ret = RF_CCA_CLEAR; + int ret = RF_CORE_CCA_CLEAR; /* * If we are in the middle of a BLE operation, we got called by ContikiMAC @@ -1145,7 +972,7 @@ channel_clear(void) */ if(rf_ble_is_active() == RF_BLE_ACTIVE) { PRINTF("channel_clear: Interrupt context but BLE in progress\n"); - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } if(rf_is_on()) { @@ -1157,7 +984,7 @@ channel_clear(void) * * We could probably even simply return that the channel is clear */ - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); } else { was_off = 1; if(on() != RF_CORE_CMD_OK) { @@ -1165,21 +992,21 @@ channel_clear(void) if(was_off) { off(); } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } cca_info = get_cca_info(); - if(cca_info == RF_GET_CCA_INFO_ERROR) { + if(cca_info == RF_CORE_GET_CCA_INFO_ERROR) { PRINTF("channel_clear: CCA error\n"); - ret = RF_CCA_CLEAR; + ret = RF_CORE_CCA_CLEAR; } else { /* * cca_info bits 1:0 - ccaStatus * Return 1 (clear) if idle or invalid. */ - ret = (cca_info & 0x03) != RF_CMD_CCA_REQ_CCA_STATE_BUSY; + ret = (cca_info & 0x03) != RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY; } if(was_off) { @@ -1218,12 +1045,12 @@ receiving_packet(void) cca_info = get_cca_info(); /* If we can't read CCA info, return "not receiving" */ - if(cca_info == RF_GET_CCA_INFO_ERROR) { + if(cca_info == RF_CORE_GET_CCA_INFO_ERROR) { return 0; } /* If sync has been seen, return 1 (receiving) */ - if(cca_info & RF_CMD_CCA_REQ_CCA_SYNC_BUSY) { + if(cca_info & RF_CORE_CMD_CCA_REQ_CCA_SYNC_BUSY) { return 1; } @@ -1241,7 +1068,7 @@ pending_packet(void) if(entry->status == DATA_ENTRY_STATUS_FINISHED || entry->status == DATA_ENTRY_STATUS_BUSY) { rv = 1; - if(!poll_mode) { + if(!rf_core_poll_mode) { process_poll(&rf_core_process); } } @@ -1292,7 +1119,7 @@ on(void) return RF_CORE_CMD_ERROR; } - rf_core_setup_interrupts(poll_mode); + rf_core_setup_interrupts(); if(rf_radio_setup() != RF_CORE_CMD_OK) { PRINTF("on: radio_setup() failed\n"); @@ -1314,7 +1141,7 @@ off(void) return RF_CORE_CMD_OK; } - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); /* stopping the rx explicitly results in lower sleep-mode power usage */ rx_off(); @@ -1394,7 +1221,7 @@ get_value(radio_param_t param, radio_value_t *value) if(cmd->frameFiltOpt.autoAckEn) { *value |= RADIO_RX_MODE_AUTOACK; } - if(poll_mode) { + if(rf_core_poll_mode) { *value |= RADIO_RX_MODE_POLL_MODE; } @@ -1411,7 +1238,7 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_RSSI: *value = get_rssi(); - if(*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) { + if(*value == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) { return RADIO_RESULT_ERROR; } else { return RADIO_RESULT_OK; @@ -1429,10 +1256,25 @@ get_value(radio_param_t param, radio_value_t *value) *value = OUTPUT_POWER_MAX; return RADIO_RESULT_OK; case RADIO_PARAM_LAST_RSSI: - *value = last_rssi; + *value = rf_core_last_rssi; return RADIO_RESULT_OK; case RADIO_PARAM_LAST_LINK_QUALITY: - *value = last_corr_lqi; + *value = rf_core_last_corr_lqi; + return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: + *value = (radio_value_t)RADIO_PHY_OVERHEAD; + return RADIO_RESULT_OK; + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)RADIO_BYTE_AIR_TIME; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_TX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_RX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)RADIO_DELAY_BEFORE_DETECT; return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; @@ -1498,9 +1340,9 @@ set_value(radio_param_t param, radio_value_t value) cmd->frameFiltOpt.bPanCoord = 0; cmd->frameFiltOpt.bStrictLenFilter = 0; - old_poll_mode = poll_mode; - poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; - if(poll_mode == old_poll_mode) { + old_poll_mode = rf_core_poll_mode; + rf_core_poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; + if(rf_core_poll_mode == old_poll_mode) { uint32_t cmd_status; /* do not turn the radio on and off, just send an update command */ @@ -1552,7 +1394,7 @@ set_value(radio_param_t param, radio_value_t value) /* Restart the radio timer (RAT). This causes resynchronization between RAT and RTC: useful for TSCH. */ if(rf_core_restart_rat() == RF_CORE_CMD_OK) { - check_rat_overflow(false); + rf_core_check_rat_overflow(); } if(rx_on() != RF_CORE_CMD_OK) { @@ -1590,7 +1432,7 @@ get_object(radio_param_t param, void *dest, size_t size) if(size != sizeof(rtimer_clock_t) || !dest) { return RADIO_RESULT_INVALID_VALUE; } - *(rtimer_clock_t *)dest = last_packet_timestamp; + *(rtimer_clock_t *)dest = rf_core_last_packet_timestamp; return RADIO_RESULT_OK; } diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode-tx-power.c b/arch/cpu/cc26x0-cc13x0/rf-core/prop-mode-tx-power.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/prop-mode-tx-power.c rename to arch/cpu/cc26x0-cc13x0/rf-core/prop-mode-tx-power.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c b/arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.c similarity index 78% rename from arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c rename to arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.c index 66b4a4370..0ce6de5dd 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c +++ b/arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.c @@ -115,24 +115,6 @@ */ #define RF_RADIO_OP_GET_STATUS(a) GET_FIELD_V(a, radioOp, status) /*---------------------------------------------------------------------------*/ -/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ -#define RF_CMD_CCA_REQ_RSSI_UNKNOWN -128 - -/* Used for the return value of channel_clear */ -#define RF_CCA_CLEAR 1 -#define RF_CCA_BUSY 0 - -/* Used as an error return value for get_cca_info */ -#define RF_GET_CCA_INFO_ERROR 0xFF - -/* - * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's - * status struct - */ -#define RF_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ -#define RF_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ -#define RF_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ - #ifdef PROP_MODE_CONF_RSSI_THRESHOLD #define PROP_MODE_RSSI_THRESHOLD PROP_MODE_CONF_RSSI_THRESHOLD #else @@ -141,6 +123,8 @@ static int8_t rssi_threshold = PROP_MODE_RSSI_THRESHOLD; /*---------------------------------------------------------------------------*/ +static volatile uint8_t is_receiving_packet; +/*---------------------------------------------------------------------------*/ static int on(void); static int off(void); @@ -170,12 +154,6 @@ static rfc_propRxOutput_t rx_stats; #define DOT_4G_PHR_DW_BIT 0 #endif /*---------------------------------------------------------------------------*/ -/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ -#define TX_WAIT_TIMEOUT (RTIMER_SECOND >> 11) - -/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ -#define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) -/*---------------------------------------------------------------------------*/ /* TX power table for the 431-527MHz band */ #ifdef PROP_MODE_CONF_TX_POWER_431_527 #define PROP_MODE_TX_POWER_431_527 PROP_MODE_CONF_TX_POWER_431_527 @@ -222,12 +200,29 @@ static const prop_mode_tx_power_config_t *tx_power_current = &TX_POWER_DRIVER[1] #define DATA_ENTRY_LENSZ_BYTE 1 #define DATA_ENTRY_LENSZ_WORD 2 /* 2 bytes */ +/* The size of the metadata (excluding the packet length field) */ +#define RX_BUF_METADATA_SIZE \ + (CRC_LEN * RF_CORE_RX_BUF_INCLUDE_CRC \ + + RF_CORE_RX_BUF_INCLUDE_RSSI \ + + RF_CORE_RX_BUF_INCLUDE_CORR \ + + 4 * RF_CORE_RX_BUF_INCLUDE_TIMESTAMP) + +/* The offset of the packet length in a rx buffer */ +#define RX_BUF_LENGTH_OFFSET sizeof(rfc_dataEntry_t) +/* The offset of the packet data in a rx buffer */ +#define RX_BUF_DATA_OFFSET (RX_BUF_LENGTH_OFFSET + DOT_4G_PHR_LEN) + +#define ALIGN_TO_4(size) (((size) + 3) & ~3) + +#define RX_BUF_SIZE ALIGN_TO_4(RX_BUF_DATA_OFFSET \ + + NETSTACK_RADIO_MAX_PAYLOAD_LEN \ + + RX_BUF_METADATA_SIZE) + /* * RX buffers. * PROP_MODE_RX_BUF_CNT buffers of RX_BUF_SIZE bytes each. The start of each * buffer must be 4-byte aligned, therefore RX_BUF_SIZE must divide by 4 */ -#define RX_BUF_SIZE 140 static uint8_t rx_buf[PROP_MODE_RX_BUF_CNT][RX_BUF_SIZE] CC_ALIGN(4); /* The RX Data Queue */ @@ -236,6 +231,12 @@ static dataQueue_t rx_data_queue = { 0 }; /* Receive entry pointer to keep track of read items */ volatile static uint8_t *rx_read_entry; /*---------------------------------------------------------------------------*/ +/* + * Increasing this number causes unicast Tx immediately after broadcast Rx to have + * negative synchronization errors ("dr" in TSCH logs); decreasing it: the opposite. + */ +#define RAT_TIMESTAMP_OFFSET_SUB_GHZ USEC_TO_RADIO(160 * 6 - 240) +/*---------------------------------------------------------------------------*/ /* The outgoing frame buffer */ #define TX_BUF_PAYLOAD_LEN 180 #define TX_BUF_HDR_LEN 2 @@ -272,13 +273,13 @@ get_rssi(void) was_off = 1; if(on() != RF_CORE_CMD_OK) { PRINTF("get_rssi: on() failed\n"); - return RF_CMD_CCA_REQ_RSSI_UNKNOWN; + return RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; } } - rssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; - while((rssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) && ++attempts < 10) { + while((rssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) && ++attempts < 10) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_GET_RSSI; @@ -420,13 +421,17 @@ static uint8_t rf_cmd_prop_rx() { uint32_t cmd_status; - rtimer_clock_t t0; volatile rfc_CMD_PROP_RX_ADV_t *cmd_rx_adv; int ret; cmd_rx_adv = (rfc_CMD_PROP_RX_ADV_t *)&smartrf_settings_cmd_prop_rx_adv; cmd_rx_adv->status = RF_CORE_RADIO_OP_STATUS_IDLE; + cmd_rx_adv->rxConf.bIncludeCrc = RF_CORE_RX_BUF_INCLUDE_CRC; + cmd_rx_adv->rxConf.bAppendRssi = RF_CORE_RX_BUF_INCLUDE_RSSI; + cmd_rx_adv->rxConf.bAppendTimestamp = RF_CORE_RX_BUF_INCLUDE_TIMESTAMP; + cmd_rx_adv->rxConf.bAppendStatus = RF_CORE_RX_BUF_INCLUDE_CORR; + /* * Set the max Packet length. This is for the payload only, therefore * 2047 - length offset @@ -441,10 +446,8 @@ rf_cmd_prop_rx() return RF_CORE_CMD_ERROR; } - t0 = RTIMER_NOW(); - - while(cmd_rx_adv->status != RF_CORE_RADIO_OP_STATUS_ACTIVE && - (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ENTER_RX_WAIT_TIMEOUT))); + RTIMER_BUSYWAIT_UNTIL(cmd_rx_adv->status == RF_CORE_RADIO_OP_STATUS_ACTIVE, + RF_CORE_ENTER_RX_TIMEOUT); /* Wait to enter RX */ if(cmd_rx_adv->status != RF_CORE_RADIO_OP_STATUS_ACTIVE) { @@ -506,13 +509,16 @@ rx_off_prop(void) return RF_CORE_CMD_OK; } + /* Wait for ongoing ACK TX to finish */ + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); + /* Send a CMD_ABORT command to RF Core */ if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_ABORT), &cmd_status) != RF_CORE_CMD_OK) { PRINTF("rx_off_prop: CMD_ABORT status=0x%08lx\n", cmd_status); /* Continue nonetheless */ } - while(rf_is_on()); + RTIMER_BUSYWAIT_UNTIL(!rf_is_on(), RF_CORE_TURN_OFF_TIMEOUT); if(smartrf_settings_cmd_prop_rx_adv.status == PROP_DONE_STOPPED || smartrf_settings_cmd_prop_rx_adv.status == PROP_DONE_ABORT) { @@ -583,8 +589,8 @@ soft_off_prop(void) return; } - while((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) == - RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING); + RTIMER_BUSYWAIT_UNTIL((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) != + RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_CORE_TURN_OFF_TIMEOUT); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -606,6 +612,8 @@ soft_on_prop(void) static const rf_core_primary_mode_t mode_prop = { soft_off_prop, soft_on_prop, + rf_is_on, + RAT_TIMESTAMP_OFFSET_SUB_GHZ }; /*---------------------------------------------------------------------------*/ static int @@ -637,10 +645,15 @@ init(void) return RF_CORE_CMD_ERROR; } + /* Enable the "sync word seen" interrupt */ + ti_lib_rfc_hw_int_enable(RFC_DBELL_RFHWIEN_MDMSOFT); + ENERGEST_ON(ENERGEST_TYPE_LISTEN); rf_core_primary_mode_register(&mode_prop); + rf_core_rat_init(); + process_start(&rf_core_process, NULL); return 1; @@ -701,7 +714,7 @@ transmit(unsigned short transmit_len) rx_off_prop(); /* Enable the LAST_COMMAND_DONE interrupt to wake us up */ - rf_core_cmd_done_en(false, false); + rf_core_cmd_done_en(false); ret = rf_core_send_cmd((uint32_t)cmd_tx_adv, &cmd_status); @@ -714,7 +727,14 @@ transmit(unsigned short transmit_len) /* Idle away while the command is running */ while((cmd_tx_adv->status & RF_CORE_RADIO_OP_MASKED_STATUS) == RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING) { - lpm_sleep(); + /* Note: for now sleeping while Tx'ing in polling mode is disabled. + * To enable it: + * 1) make the `lpm_sleep()` call here unconditional; + * 2) change the radio ISR priority to allow radio ISR to interrupt rtimer ISR. + */ + if(!rf_core_poll_mode) { + lpm_sleep(); + } } if(cmd_tx_adv->status == RF_CORE_RADIO_OP_STATUS_PROP_DONE_OK) { @@ -743,7 +763,7 @@ transmit(unsigned short transmit_len) * Disable LAST_FG_COMMAND_DONE interrupt. We don't really care about it * except when we are transmitting */ - rf_core_cmd_done_dis(false); + rf_core_cmd_done_dis(); /* Workaround. Set status to IDLE */ cmd_tx_adv->status = RF_CORE_RADIO_OP_STATUS_IDLE; @@ -764,47 +784,98 @@ send(const void *payload, unsigned short payload_len) return transmit(payload_len); } /*---------------------------------------------------------------------------*/ -static int -read_frame(void *buf, unsigned short buf_len) +static void +release_data_entry(void) { - int_master_status_t status; rfc_dataEntryGeneral_t *entry = (rfc_dataEntryGeneral_t *)rx_read_entry; uint8_t *data_ptr = &entry->data; - int len = 0; + int_master_status_t interrupt_status; - if(entry->status == DATA_ENTRY_STATUS_FINISHED) { + /* Clear the length field (2 bytes) */ + data_ptr[0] = 0; + data_ptr[1] = 0; - /* - * First 2 bytes in the data entry are the length. - * Our data entry consists of: Payload + RSSI (1 byte) + Status (1 byte) - * This length includes all of those. - */ - len = (*(uint16_t *)data_ptr); - data_ptr += 2; - len -= 2; + /* Set status to 0 "Pending" in element */ + entry->status = DATA_ENTRY_STATUS_PENDING; + rx_read_entry = entry->pNextEntry; - if(len > 0) { - if(len <= buf_len) { - memcpy(buf, data_ptr, len); - } - - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, (int8_t)data_ptr[len]); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, 0x7F); - } - - /* Move read entry pointer to next entry */ - rx_read_entry = entry->pNextEntry; - entry->status = DATA_ENTRY_STATUS_PENDING; - } - - status = critical_enter(); - if(rx_is_full) { - rx_is_full = false; + interrupt_status = critical_enter(); + if(rf_core_rx_is_full) { + rf_core_rx_is_full = false; PRINTF("RXQ was full, re-enabling radio!\n"); rx_on_prop(); } - critical_exit(status); - + critical_exit(interrupt_status); + +} +/*---------------------------------------------------------------------------*/ +static int +read_frame(void *buf, unsigned short buf_len) +{ + rfc_dataEntryGeneral_t *entry = (rfc_dataEntryGeneral_t *)rx_read_entry; + uint8_t *data_ptr = &entry->data; + int len = 0; + uint32_t rat_timestamp; + + /* wait for entry to become finished */ + rtimer_clock_t t0 = RTIMER_NOW(); + while(entry->status == DATA_ENTRY_STATUS_BUSY + && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (RTIMER_SECOND / 50))); + + /* Make sure the flag is reset */ + is_receiving_packet = 0; + + if(entry->status != DATA_ENTRY_STATUS_FINISHED) { + /* No available data */ + return 0; + } + + /* + * First 2 bytes in the data entry are the length. + * Our data entry consists of: + * Payload + RSSI (1 byte) + Timestamp (4 bytes) + Status (1 byte) + * This length includes all of those. + */ + len = (*(uint16_t *)data_ptr); + + if(len <= RX_BUF_METADATA_SIZE) { + PRINTF("RF: too short!"); + + release_data_entry(); + return 0; + } + + data_ptr += 2; + len -= RX_BUF_METADATA_SIZE; + + if(len > buf_len) { + PRINTF("RF: too long\n"); + + release_data_entry(); + return 0; + } + + memcpy(buf, data_ptr, len); + + /* get the RSSI and status */ + rf_core_last_rssi = (int8_t)data_ptr[len]; + rf_core_last_corr_lqi = data_ptr[len + 5]; + + /* get the timestamp */ + memcpy(&rat_timestamp, data_ptr + len + 1, 4); + + rf_core_last_packet_timestamp = rf_core_convert_rat_to_rtimer(rat_timestamp); + + if(!rf_core_poll_mode) { + /* Not in poll mode: packetbuf should not be accessed in interrupt context. + * In poll mode, the last packet RSSI and link quality can be obtained through + * RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */ + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rf_core_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rf_core_last_corr_lqi); + } + + release_data_entry(); + return len; } /*---------------------------------------------------------------------------*/ @@ -813,14 +884,14 @@ channel_clear(void) { uint8_t was_off = 0; uint32_t cmd_status; - int8_t rssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + int8_t rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; /* * If we are in the middle of a BLE operation, we got called by ContikiMAC * from within an interrupt context. Indicate a clear channel */ if(rf_ble_is_active() == RF_BLE_ACTIVE) { - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } if(!rf_core_is_accessible()) { @@ -830,16 +901,16 @@ channel_clear(void) if(was_off) { off(); } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } else { if(transmitting()) { PRINTF("channel_clear: called while in TX\n"); - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } - while(rssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) { + while(rssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) { if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_GET_RSSI), &cmd_status) != RF_CORE_CMD_OK) { break; @@ -853,10 +924,10 @@ channel_clear(void) } if(rssi >= rssi_threshold) { - return RF_CCA_BUSY; + return RF_CORE_CCA_BUSY; } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } /*---------------------------------------------------------------------------*/ static int @@ -866,11 +937,23 @@ receiving_packet(void) return 0; } - if(channel_clear() == RF_CCA_CLEAR) { - return 0; + if(!is_receiving_packet) { + /* Look for the modem synchronization word detection interrupt flag. + * This flag is raised when the synchronization word is received. + */ + if(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFHWIFG) & RFC_DBELL_RFHWIFG_MDMSOFT) { + is_receiving_packet = 1; + } + } else { + /* After the start of the packet: reset the Rx flag once the channel gets clear */ + is_receiving_packet = (channel_clear() == RF_CORE_CCA_BUSY); + if(!is_receiving_packet) { + /* Clear the modem sync flag */ + ti_lib_rfc_hw_int_clear(RFC_DBELL_RFHWIFG_MDMSOFT); + } } - return 1; + return is_receiving_packet; } /*---------------------------------------------------------------------------*/ static int @@ -881,9 +964,12 @@ pending_packet(void) /* Go through all RX buffers and check their status */ do { - if(entry->status == DATA_ENTRY_STATUS_FINISHED) { - rv += 1; - process_poll(&rf_core_process); + if(entry->status == DATA_ENTRY_STATUS_FINISHED + || entry->status == DATA_ENTRY_STATUS_BUSY) { + rv = 1; + if(!rf_core_poll_mode) { + process_poll(&rf_core_process); + } } entry = (rfc_dataEntry_t *)entry->pNextEntry; @@ -904,18 +990,18 @@ on(void) return RF_CORE_CMD_OK; } - /* - * Request the HF XOSC as the source for the HF clock. Needed before we can - * use the FS. This will only request, it will _not_ perform the switch. - */ - oscillators_request_hf_xosc(); - if(rf_is_on()) { PRINTF("on: We were on. PD=%u, RX=0x%04x \n", rf_core_is_accessible(), smartrf_settings_cmd_prop_rx_adv.status); return RF_CORE_CMD_OK; } + /* + * Request the HF XOSC as the source for the HF clock. Needed before we can + * use the FS. This will only request, it will _not_ perform the switch. + */ + oscillators_request_hf_xosc(); + if(!rf_core_is_accessible()) { if(rf_core_power_up() != RF_CORE_CMD_OK) { PRINTF("on: rf_core_power_up() failed\n"); @@ -958,7 +1044,7 @@ on(void) } } - rf_core_setup_interrupts(false); + rf_core_setup_interrupts(); init_rx_buffers(); @@ -985,6 +1071,9 @@ on(void) static int off(void) { + int i; + rfc_dataEntry_t *entry; + /* * If we are in the middle of a BLE operation, we got called by ContikiMAC * from within an interrupt context. Abort, but pretend everything is OK. @@ -998,15 +1087,39 @@ off(void) ENERGEST_OFF(ENERGEST_TYPE_LISTEN); +#if !CC2650_FAST_RADIO_STARTUP /* Switch HF clock source to the RCOSC to preserve power */ oscillators_switch_to_hf_rc(); +#endif /* We pulled the plug, so we need to restore the status manually */ smartrf_settings_cmd_prop_rx_adv.status = RF_CORE_RADIO_OP_STATUS_IDLE; + /* + * Just in case there was an ongoing RX (which started after we begun the + * shutdown sequence), we don't want to leave the buffer in state == ongoing + */ + for(i = 0; i < PROP_MODE_RX_BUF_CNT; i++) { + entry = (rfc_dataEntry_t *)rx_buf[i]; + if(entry->status == DATA_ENTRY_STATUS_BUSY) { + entry->status = DATA_ENTRY_STATUS_PENDING; + } + } + return RF_CORE_CMD_OK; } /*---------------------------------------------------------------------------*/ +/* Enable or disable CCA before sending */ +static radio_result_t +set_send_on_cca(uint8_t enable) +{ + if(enable) { + /* this driver does not have support for CCA on Tx */ + return RADIO_RESULT_NOT_SUPPORTED; + } + return RADIO_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ static radio_result_t get_value(radio_param_t param, radio_value_t *value) { @@ -1022,6 +1135,15 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_CHANNEL: *value = (radio_value_t)get_channel(); return RADIO_RESULT_OK; + case RADIO_PARAM_RX_MODE: + *value = 0; + if(rf_core_poll_mode) { + *value |= RADIO_RX_MODE_POLL_MODE; + } + return RADIO_RESULT_OK; + case RADIO_PARAM_TX_MODE: + *value = 0; + return RADIO_RESULT_OK; case RADIO_PARAM_TXPOWER: *value = get_tx_power(); return RADIO_RESULT_OK; @@ -1031,7 +1153,7 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_RSSI: *value = get_rssi(); - if(*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) { + if(*value == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) { return RADIO_RESULT_ERROR; } else { return RADIO_RESULT_OK; @@ -1048,6 +1170,28 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_CONST_TXPOWER_MAX: *value = OUTPUT_POWER_MAX; return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_RSSI: + *value = rf_core_last_rssi; + return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_LINK_QUALITY: + *value = rf_core_last_corr_lqi; + return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: + /* 2 header bytes, 2 or 4 bytes CRC */ + *value = (radio_value_t)(DOT_4G_PHR_LEN + CRC_LEN); + return RADIO_RESULT_OK; + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)RADIO_BYTE_AIR_TIME; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_TX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_RX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)RADIO_DELAY_BEFORE_DETECT; + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -1056,8 +1200,8 @@ get_value(radio_param_t param, radio_value_t *value) static radio_result_t set_value(radio_param_t param, radio_value_t value) { - uint8_t was_off = 0; radio_result_t rv = RADIO_RESULT_OK; + uint8_t old_poll_mode; switch(param) { case RADIO_PARAM_POWER_MODE: @@ -1087,6 +1231,25 @@ set_value(radio_param_t param, radio_value_t value) set_channel((uint8_t)value); break; + + case RADIO_PARAM_RX_MODE: + if(value & ~(RADIO_RX_MODE_POLL_MODE)) { + return RADIO_RESULT_INVALID_VALUE; + } + + old_poll_mode = rf_core_poll_mode; + rf_core_poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; + if(rf_core_poll_mode == old_poll_mode) { + return RADIO_RESULT_OK; + } + break; + + case RADIO_PARAM_TX_MODE: + if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) { + return RADIO_RESULT_INVALID_VALUE; + } + return set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0); + case RADIO_PARAM_TXPOWER: if(value < TX_POWER_DRIVER[get_tx_power_array_last_element()].dbm || value > OUTPUT_POWER_MAX) { @@ -1103,8 +1266,7 @@ set_value(radio_param_t param, radio_value_t value) } return RADIO_RESULT_OK; - case RADIO_PARAM_RX_MODE: - return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: rssi_threshold = (int8_t)value; break; @@ -1112,28 +1274,29 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_NOT_SUPPORTED; } - /* If we reach here we had no errors. Apply new settings */ + /* If off, the new configuration will be applied the next time radio is started */ if(!rf_is_on()) { - was_off = 1; - if(on() != RF_CORE_CMD_OK) { - PRINTF("set_value: on() failed (2)\n"); - return RADIO_RESULT_ERROR; - } + return RADIO_RESULT_OK; } + /* If we reach here we had no errors. Apply new settings */ if(rx_off_prop() != RF_CORE_CMD_OK) { PRINTF("set_value: rx_off_prop() failed\n"); rv = RADIO_RESULT_ERROR; } - if(soft_on_prop() != RF_CORE_CMD_OK) { - PRINTF("set_value: rx_on_prop() failed\n"); - rv = RADIO_RESULT_ERROR; + /* Restart the radio timer (RAT). + This causes resynchronization between RAT and RTC: useful for TSCH. */ + if(rf_core_restart_rat() != RF_CORE_CMD_OK) { + PRINTF("set_value: rf_core_restart_rat() failed\n"); + /* do not set the error */ + } else { + rf_core_check_rat_overflow(); } - /* If we were off, turn back off */ - if(was_off) { - off(); + if(soft_on_prop() != RF_CORE_CMD_OK) { + PRINTF("set_value: soft_on_prop() failed\n"); + rv = RADIO_RESULT_ERROR; } return rv; @@ -1142,6 +1305,15 @@ set_value(radio_param_t param, radio_value_t value) static radio_result_t get_object(radio_param_t param, void *dest, size_t size) { + if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { + if(size != sizeof(rtimer_clock_t) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(rtimer_clock_t *)dest = rf_core_last_packet_timestamp; + + return RADIO_RESULT_OK; + } + return RADIO_RESULT_NOT_SUPPORTED; } /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.h b/arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.h rename to arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-ble.c b/arch/cpu/cc26x0-cc13x0/rf-core/rf-ble.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-ble.c rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-ble.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-ble.h b/arch/cpu/cc26x0-cc13x0/rf-core/rf-ble.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-ble.h rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-ble.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/arch/cpu/cc26x0-cc13x0/rf-core/rf-core.c similarity index 80% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-core.c index faa8f808b..7e638509d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/arch/cpu/cc26x0-cc13x0/rf-core/rf-core.c @@ -99,12 +99,37 @@ static rfc_radioOp_t *last_radio_op = NULL; /* A struct holding pointers to the primary mode's abort() and restore() */ static const rf_core_primary_mode_t *primary_mode = NULL; /*---------------------------------------------------------------------------*/ +/* RAT has 32-bit register, overflows once 18 minutes */ +#define RAT_RANGE 4294967296ull +/* approximate value */ +#define RAT_OVERFLOW_PERIOD_SECONDS (60 * 18) + +/* how often to check for the overflow, as a minimum */ +#define RAT_OVERFLOW_TIMER_INTERVAL (CLOCK_SECOND * RAT_OVERFLOW_PERIOD_SECONDS / 3) + /* Radio timer (RAT) offset as compared to the rtimer counter (RTC) */ -int32_t rat_offset = 0; -static bool rat_offset_known = false; +static int32_t rat_offset; +static bool rat_offset_known; + +/* Value during the last read of the RAT register */ +static uint32_t rat_last_value; + +/* For RAT overflow handling */ +static struct ctimer rat_overflow_timer; +static volatile uint32_t rat_overflow_counter; +static rtimer_clock_t rat_last_overflow; + +static void rat_overflow_check_timer_cb(void *); +/*---------------------------------------------------------------------------*/ +volatile int8_t rf_core_last_rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; +volatile uint8_t rf_core_last_corr_lqi = 0; +volatile uint32_t rf_core_last_packet_timestamp = 0; +/*---------------------------------------------------------------------------*/ +/* Are we currently in poll mode? */ +uint8_t rf_core_poll_mode = 0; /*---------------------------------------------------------------------------*/ /* Buffer full flag */ -volatile bool rx_is_full = false; +volatile bool rf_core_rx_is_full = false; /*---------------------------------------------------------------------------*/ PROCESS(rf_core_process, "CC13xx / CC26xx RF driver"); /*---------------------------------------------------------------------------*/ @@ -451,10 +476,10 @@ rf_core_restart_rat(void) } /*---------------------------------------------------------------------------*/ void -rf_core_setup_interrupts(bool poll_mode) +rf_core_setup_interrupts(void) { bool interrupts_disabled; - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; /* We are already turned on by the caller, so this should not happen */ if(!rf_core_is_accessible()) { @@ -485,19 +510,23 @@ rf_core_setup_interrupts(bool poll_mode) } /*---------------------------------------------------------------------------*/ void -rf_core_cmd_done_en(bool fg, bool poll_mode) +rf_core_cmd_done_en(bool fg) { - uint32_t irq = fg ? IRQ_LAST_FG_COMMAND_DONE : IRQ_LAST_COMMAND_DONE; - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + uint32_t irq = 0; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + + if(!rf_core_poll_mode) { + irq = fg ? IRQ_LAST_FG_COMMAND_DONE : IRQ_LAST_COMMAND_DONE; + } HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = enabled_irqs; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = enabled_irqs | irq; } /*---------------------------------------------------------------------------*/ void -rf_core_cmd_done_dis(bool poll_mode) +rf_core_cmd_done_dis(void) { - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = enabled_irqs; } /*---------------------------------------------------------------------------*/ @@ -544,6 +573,123 @@ rf_core_primary_mode_restore() return RF_CORE_CMD_ERROR; } /*---------------------------------------------------------------------------*/ +uint8_t +rf_core_rat_init(void) +{ + rat_last_value = HWREG(RFC_RAT_BASE + RATCNT); + + ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_TIMER_INTERVAL, + rat_overflow_check_timer_cb, NULL); + + return 1; +} +/*---------------------------------------------------------------------------*/ +uint8_t +rf_core_check_rat_overflow(void) +{ + uint32_t rat_current_value; + uint8_t interrupts_disabled; + + /* Bail out if the RF is not on */ + if(primary_mode == NULL || !primary_mode->is_on()) { + return 0; + } + + interrupts_disabled = ti_lib_int_master_disable(); + + rat_current_value = HWREG(RFC_RAT_BASE + RATCNT); + if(rat_current_value + RAT_RANGE / 4 < rat_last_value) { + /* Overflow detected */ + rat_last_overflow = RTIMER_NOW(); + rat_overflow_counter++; + } + rat_last_value = rat_current_value; + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } + + return 1; +} +/*---------------------------------------------------------------------------*/ +static void +rat_overflow_check_timer_cb(void *unused) +{ + uint8_t success = 0; + uint8_t was_off = 0; + + if(primary_mode != NULL) { + + if(!primary_mode->is_on()) { + was_off = 1; + if(NETSTACK_RADIO.on() != RF_CORE_CMD_OK) { + PRINTF("overflow: on() failed\n"); + ctimer_set(&rat_overflow_timer, CLOCK_SECOND, + rat_overflow_check_timer_cb, NULL); + return; + } + } + + success = rf_core_check_rat_overflow(); + + if(was_off) { + NETSTACK_RADIO.off(); + } + } + + if(success) { + /* Retry after half of the interval */ + ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_TIMER_INTERVAL, + rat_overflow_check_timer_cb, NULL); + } else { + /* Retry sooner */ + ctimer_set(&rat_overflow_timer, CLOCK_SECOND, + rat_overflow_check_timer_cb, NULL); + } +} +/*---------------------------------------------------------------------------*/ +uint32_t +rf_core_convert_rat_to_rtimer(uint32_t rat_timestamp) +{ + uint64_t rat_timestamp64; + uint32_t adjusted_overflow_counter; + uint8_t was_off = 0; + + if(primary_mode == NULL) { + PRINTF("rf_core_convert_rat_to_rtimer: not initialized\n"); + return 0; + } + + if(!primary_mode->is_on()) { + was_off = 1; + NETSTACK_RADIO.on(); + } + + rf_core_check_rat_overflow(); + + if(was_off) { + NETSTACK_RADIO.off(); + } + + adjusted_overflow_counter = rat_overflow_counter; + + /* if the timestamp is large and the last oveflow was recently, + assume that the timestamp refers to the time before the overflow */ + if(rat_timestamp > (uint32_t)(RAT_RANGE * 3 / 4)) { + if(RTIMER_CLOCK_LT(RTIMER_NOW(), + rat_last_overflow + RAT_OVERFLOW_PERIOD_SECONDS * RTIMER_SECOND / 4)) { + adjusted_overflow_counter--; + } + } + + /* add the overflowed time to the timestamp */ + rat_timestamp64 = rat_timestamp + RAT_RANGE * adjusted_overflow_counter; + /* correct timestamp so that it refers to the end of the SFD */ + rat_timestamp64 += primary_mode->sfd_timestamp_offset; + + return RADIO_TO_RTIMER(rat_timestamp64 - rat_offset); +} +/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rf_core_process, ev, data) { int len; @@ -582,11 +728,11 @@ cc26xx_rf_cpe1_isr(void) return; } } - + if(HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) & IRQ_RX_BUF_FULL) { PRINTF("\nRF: BUF_FULL\n\n"); /* set a flag that the buffer is full*/ - rx_is_full = true; + rf_core_rx_is_full = true; /* make sure read_frame() will be called to make space in RX buffer */ process_poll(&rf_core_process); /* Clear the IRQ_RX_BUF_FULL interrupt flag by writing zero to bit */ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h b/arch/cpu/cc26x0-cc13x0/rf-core/rf-core.h similarity index 86% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-core.h index c97ab0f8a..6cb65672d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h +++ b/arch/cpu/cc26x0-cc13x0/rf-core/rf-core.h @@ -133,6 +133,17 @@ typedef struct rf_core_primary_mode_s { * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR */ uint8_t (*restore)(void); + + /** + * \brief A pointer to a function that checks if the radio is on + * \return 1 or 0 + */ + uint8_t (*is_on)(void); + + /** + * \brief Offset of the end of SFD when compared to the radio HW-generated timestamp + */ + int16_t sfd_timestamp_offset; } rf_core_primary_mode_t; /*---------------------------------------------------------------------------*/ /* RF Command status constants - Correspond to values in the CMDSTA register */ @@ -263,12 +274,65 @@ typedef struct rf_core_primary_mode_s { /* Radio timer register */ #define RATCNT 0x00000004 /*---------------------------------------------------------------------------*/ -/* Buffer full flag */ -extern volatile bool rx_is_full; +/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ +#define RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN -128 + +/* Used for the return value of channel_clear */ +#define RF_CORE_CCA_CLEAR 1 +#define RF_CORE_CCA_BUSY 0 + +/* Used as an error return value for get_cca_info */ +#define RF_CORE_GET_CCA_INFO_ERROR 0xFF + +/* + * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's + * status struct + */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ + +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_IDLE (0 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_BUSY (1 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_INVALID (3 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_MASK (3 << 4) + +#define RF_CORE_CMD_CCA_REQ_CCA_SYNC_BUSY (1 << 6) +/*---------------------------------------------------------------------------*/ +#define RF_CORE_RX_BUF_INCLUDE_CRC 0 +#define RF_CORE_RX_BUF_INCLUDE_RSSI 1 +#define RF_CORE_RX_BUF_INCLUDE_CORR 1 +#define RF_CORE_RX_BUF_INCLUDE_TIMESTAMP 1 +/*---------------------------------------------------------------------------*/ +/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ +#define RF_CORE_TX_TIMEOUT (RTIMER_SECOND >> 11) + +/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ +#define RF_CORE_ENTER_RX_TIMEOUT (RTIMER_SECOND >> 10) + +/* How long to wait for the RF to react on CMD_ABORT: around 1 msec */ +#define RF_CORE_TURN_OFF_TIMEOUT (RTIMER_SECOND >> 10) + +/* How long to wait for the RF to finish TX of a packet or an ACK */ +#define RF_CORE_TX_FINISH_TIMEOUT (RTIMER_SECOND >> 7) + /*---------------------------------------------------------------------------*/ /* Make the main driver process visible to mode drivers */ PROCESS_NAME(rf_core_process); /*---------------------------------------------------------------------------*/ +/* Buffer full flag */ +extern volatile bool rf_core_rx_is_full; +/*---------------------------------------------------------------------------*/ +/* RSSI of the last read frame */ +extern volatile int8_t rf_core_last_rssi; +/* Correlation/LQI of the last read frame */ +extern volatile uint8_t rf_core_last_corr_lqi; +/* SFD timestamp of the last read frame, in rtimer ticks */ +extern volatile uint32_t rf_core_last_packet_timestamp; +/*---------------------------------------------------------------------------*/ +/* Are we currently in poll mode? */ +extern uint8_t rf_core_poll_mode; +/*---------------------------------------------------------------------------*/ /** * \brief Check whether the RF core is accessible * \retval RF_CORE_ACCESSIBLE The core is powered and ready for access @@ -383,20 +447,19 @@ uint8_t rf_core_boot(void); /** * \brief Setup RF core interrupts */ -void rf_core_setup_interrupts(bool poll_mode); +void rf_core_setup_interrupts(void); /** * \brief Enable interrupt on command done. * \param fg set true to enable irq on foreground command done and false for * background commands or if not in ieee mode. - * \param poll_mode true if the driver is in poll mode * * This is used within TX routines in order to be able to sleep the CM3 and * wake up after TX has finished * * \sa rf_core_cmd_done_dis() */ -void rf_core_cmd_done_en(bool fg, bool poll_mode); +void rf_core_cmd_done_en(bool fg); /** * \brief Disable the LAST_CMD_DONE and LAST_FG_CMD_DONE interrupts. @@ -405,7 +468,7 @@ void rf_core_cmd_done_en(bool fg, bool poll_mode); * * \sa rf_core_cmd_done_en() */ -void rf_core_cmd_done_dis(bool poll_mode); +void rf_core_cmd_done_dis(void); /** * \brief Returns a pointer to the most recent proto-dependent Radio Op @@ -467,6 +530,22 @@ void rf_core_primary_mode_abort(void); * \brief Abort the currently running primary radio op */ uint8_t rf_core_primary_mode_restore(void); + +/** + * \brief Initialize the RAT to RTC conversion machinery + */ +uint8_t rf_core_rat_init(void); + +/** + * \brief Check if RAT overflow has occured and increment the overflow counter if so + */ +uint8_t rf_core_check_rat_overflow(void); + +/** + * \brief Convert from RAT timestamp to rtimer ticks + */ +uint32_t rf_core_convert_rat_to_rtimer(uint32_t rat_timestamp); + /*---------------------------------------------------------------------------*/ #endif /* RF_CORE_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-switch.h b/arch/cpu/cc26x0-cc13x0/rf-core/rf-switch.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-switch.h rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-switch.h diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/smartrf-settings.c b/arch/cpu/cc26x0-cc13x0/rf-core/smartrf-settings.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/smartrf-settings.c rename to arch/cpu/cc26x0-cc13x0/rf-core/smartrf-settings.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/smartrf-settings.h b/arch/cpu/cc26x0-cc13x0/rf-core/smartrf-settings.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/smartrf-settings.h rename to arch/cpu/cc26x0-cc13x0/rf-core/smartrf-settings.h diff --git a/arch/cpu/cc26xx-cc13xx/rtimer-arch.c b/arch/cpu/cc26x0-cc13x0/rtimer-arch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rtimer-arch.c rename to arch/cpu/cc26x0-cc13x0/rtimer-arch.c diff --git a/arch/cpu/cc26xx-cc13xx/rtimer-arch.h b/arch/cpu/cc26x0-cc13x0/rtimer-arch.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rtimer-arch.h rename to arch/cpu/cc26x0-cc13x0/rtimer-arch.h diff --git a/arch/cpu/cc26xx-cc13xx/slip-arch.c b/arch/cpu/cc26x0-cc13x0/slip-arch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/slip-arch.c rename to arch/cpu/cc26x0-cc13x0/slip-arch.c diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib.h b/arch/cpu/cc26x0-cc13x0/ti-lib.h similarity index 99% rename from arch/cpu/cc26xx-cc13xx/ti-lib.h rename to arch/cpu/cc26x0-cc13x0/ti-lib.h index 6bba7c849..d6c7363ee 100644 --- a/arch/cpu/cc26xx-cc13xx/ti-lib.h +++ b/arch/cpu/cc26x0-cc13x0/ti-lib.h @@ -399,6 +399,9 @@ #define ti_lib_rfc_rtrim(...) RFCRTrim(__VA_ARGS__) #define ti_lib_rfc_adi3vco_ldo_voltage_mode(...) RFCAdi3VcoLdoVoltageMode(__VA_ARGS__) +#define ti_lib_rfc_hw_int_enable(...) RFCHwIntEnable(__VA_ARGS__) +#define ti_lib_rfc_hw_int_disable(...) RFCHwIntDisable(__VA_ARGS__) +#define ti_lib_rfc_hw_int_clear(...) RFCHwIntClear(__VA_ARGS__) /*---------------------------------------------------------------------------*/ /* sys_ctrl.h */ #include "driverlib/sys_ctrl.h" diff --git a/arch/cpu/msp430/uip-ipchksum.c b/arch/cpu/msp430/uip-ipchksum.c index e4cb308d0..442c154dc 100644 --- a/arch/cpu/msp430/uip-ipchksum.c +++ b/arch/cpu/msp430/uip-ipchksum.c @@ -51,7 +51,7 @@ uint16_t uip_ipchksum(void) { /* Assumes proper alignement of uip_buf. */ - uint16_t *p = (uint16_t *)&uip_buf[UIP_LLH_LEN]; + uint16_t *p = (uint16_t *)UIP_IP_BUF; register uint16_t sum; sum = p[0]; diff --git a/arch/cpu/native/net/tun6-net.c b/arch/cpu/native/net/tun6-net.c index d46d91d42..f1e8c2e77 100644 --- a/arch/cpu/native/net/tun6-net.c +++ b/arch/cpu/native/net/tun6-net.c @@ -263,7 +263,7 @@ output(const linkaddr_t *localdest) { LOG_DBG("SUT: %u\n", uip_len); if(uip_len > 0) { - return tun_output(&uip_buf[UIP_LLH_LEN], uip_len); + return tun_output(uip_buf, uip_len); } return 0; } @@ -297,7 +297,7 @@ handle_fd(fd_set *rset, fd_set *wset) LOG_INFO("Tun6-handle FD\n"); if(FD_ISSET(tunfd, rset)) { - size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf)); + size = tun_input(uip_buf, sizeof(uip_buf)); LOG_DBG("TUN data incoming read:%d\n", size); uip_len = size; tcpip_input(); diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx b/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx index dfd14637e..263c92b1b 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx +++ b/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx @@ -3,7 +3,7 @@ CC13x2_CC26x2_PRE_RTM ?= 1 -# Core SDK is placed as a submodule under arch/cpu/cc13xx-cc26xx/lib. +# Core SDK is placed as a submodule under arch/cpu/simplelink-cc13xx-cc26xx/lib. # Do a sanity check that Core SDK submodule has been initialized. ifndef CORE_SDK CORE_SDK := $(CONTIKI_CPU)/lib/coresdk_cc13xx_cc26xx diff --git a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 similarity index 84% rename from arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx rename to arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 03eefcf8b..43cc7ea3f 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -1,12 +1,12 @@ -# srf06-cc26xx platform makefile +# cc26x0-cc13x0 platform makefile ifndef CONTIKI $(error CONTIKI not defined! You must specify where CONTIKI resides!) endif ### Board and BSP selection -BOARD ?= srf06/cc26xx -BOARDS = srf06/cc26xx srf06/cc13xx launchpad/cc2640r2 launchpad/cc2650 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARD ?= srf06/cc26x0 +BOARDS = srf06/cc26x0 srf06/cc13x0 launchpad/cc2640r2 launchpad/cc2650 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 CONTIKI_TARGET_DIRS += . @@ -25,5 +25,5 @@ SMALL ?= 0 ### Define the CPU directory and pull in the correct CPU makefile. This will ### be defined by one of the makefiles included above and it can be either ### Makefile.cc26xx or Makefile.cc13xx -CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc26xx-cc13xx +CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc26x0-cc13x0 include $(CONTIKI_CPU)/Makefile.$(CPU_FAMILY) diff --git a/arch/platform/srf06-cc26xx/cfs-coffee-arch.h b/arch/platform/cc26x0-cc13x0/cfs-coffee-arch.h similarity index 100% rename from arch/platform/srf06-cc26xx/cfs-coffee-arch.h rename to arch/platform/cc26x0-cc13x0/cfs-coffee-arch.h diff --git a/arch/platform/srf06-cc26xx/common/xmem.c b/arch/platform/cc26x0-cc13x0/common/xmem.c similarity index 100% rename from arch/platform/srf06-cc26xx/common/xmem.c rename to arch/platform/cc26x0-cc13x0/common/xmem.c diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/cc26x0-cc13x0/contiki-conf.h similarity index 98% rename from arch/platform/srf06-cc26xx/contiki-conf.h rename to arch/platform/cc26x0-cc13x0/contiki-conf.h index 23c086db3..de61c102c 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/cc26x0-cc13x0/contiki-conf.h @@ -32,7 +32,7 @@ * @{ * * \file - * Configuration for the srf06-cc26xx platform + * Configuration for the cc26x0-cc13x0 platform */ #ifndef CONTIKI_CONF_H #define CONTIKI_CONF_H diff --git a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad b/arch/platform/cc26x0-cc13x0/launchpad/Makefile.launchpad similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad rename to arch/platform/cc26x0-cc13x0/launchpad/Makefile.launchpad diff --git a/arch/platform/srf06-cc26xx/launchpad/board-buttons.c b/arch/platform/cc26x0-cc13x0/launchpad/board-buttons.c similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/board-buttons.c rename to arch/platform/cc26x0-cc13x0/launchpad/board-buttons.c diff --git a/arch/platform/srf06-cc26xx/launchpad/board-peripherals.h b/arch/platform/cc26x0-cc13x0/launchpad/board-peripherals.h similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/board-peripherals.h rename to arch/platform/cc26x0-cc13x0/launchpad/board-peripherals.h diff --git a/arch/platform/srf06-cc26xx/launchpad/board.c b/arch/platform/cc26x0-cc13x0/launchpad/board.c similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/board.c rename to arch/platform/cc26x0-cc13x0/launchpad/board.c diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/Makefile.cc1310 b/arch/platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 similarity index 91% rename from arch/platform/srf06-cc26xx/launchpad/cc1310/Makefile.cc1310 rename to arch/platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 index 8d3d2abd4..e9f7bab91 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/Makefile.cc1310 +++ b/arch/platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 @@ -1,5 +1,5 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc13xx +CPU_FAMILY = cc13x0 ### Add to the source dirs CONTIKI_TARGET_DIRS += launchpad/cc1310 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/cc26x0-cc13x0/launchpad/cc1310/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1310/board.h rename to arch/platform/cc26x0-cc13x0/launchpad/cc1310/board.h diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/Makefile.cc1350 b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 similarity index 93% rename from arch/platform/srf06-cc26xx/launchpad/cc1350/Makefile.cc1350 rename to arch/platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 index 0d1f65359..811a3f61b 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/Makefile.cc1350 +++ b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 @@ -1,5 +1,5 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc13xx +CPU_FAMILY = cc13x0 ### Add to the source dirs CONTIKI_TARGET_DIRS += launchpad/cc1350 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1350/board.h rename to arch/platform/cc26x0-cc13x0/launchpad/cc1350/board.h diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/rf-switch.c similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c rename to arch/platform/cc26x0-cc13x0/launchpad/cc1350/rf-switch.c diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/tx-power-driver.c b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/tx-power-driver.c similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1350/tx-power-driver.c rename to arch/platform/cc26x0-cc13x0/launchpad/cc1350/tx-power-driver.c diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2640r2/Makefile.cc2640r2 b/arch/platform/cc26x0-cc13x0/launchpad/cc2640r2/Makefile.cc2640r2 similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc2640r2/Makefile.cc2640r2 rename to arch/platform/cc26x0-cc13x0/launchpad/cc2640r2/Makefile.cc2640r2 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2640r2/board.h b/arch/platform/cc26x0-cc13x0/launchpad/cc2640r2/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc2640r2/board.h rename to arch/platform/cc26x0-cc13x0/launchpad/cc2640r2/board.h diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/Makefile.cc2650 b/arch/platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 similarity index 91% rename from arch/platform/srf06-cc26xx/launchpad/cc2650/Makefile.cc2650 rename to arch/platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 index 72e50de3a..399cd79e5 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/Makefile.cc2650 +++ b/arch/platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 @@ -1,5 +1,5 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc26xx +CPU_FAMILY = cc26x0 ### Add to the source dirs CONTIKI_TARGET_DIRS += launchpad/cc2650 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/cc26x0-cc13x0/launchpad/cc2650/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/cc2650/board.h rename to arch/platform/cc26x0-cc13x0/launchpad/cc2650/board.h diff --git a/arch/platform/srf06-cc26xx/launchpad/leds-arch.c b/arch/platform/cc26x0-cc13x0/launchpad/leds-arch.c similarity index 100% rename from arch/platform/srf06-cc26xx/launchpad/leds-arch.c rename to arch/platform/cc26x0-cc13x0/launchpad/leds-arch.c diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/cc26x0-cc13x0/platform.c similarity index 100% rename from arch/platform/srf06-cc26xx/platform.c rename to arch/platform/cc26x0-cc13x0/platform.c diff --git a/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag b/arch/platform/cc26x0-cc13x0/sensortag/Makefile.sensortag similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag rename to arch/platform/cc26x0-cc13x0/sensortag/Makefile.sensortag diff --git a/arch/platform/srf06-cc26xx/sensortag/bmp-280-sensor.c b/arch/platform/cc26x0-cc13x0/sensortag/bmp-280-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/bmp-280-sensor.c rename to arch/platform/cc26x0-cc13x0/sensortag/bmp-280-sensor.c diff --git a/arch/platform/srf06-cc26xx/sensortag/bmp-280-sensor.h b/arch/platform/cc26x0-cc13x0/sensortag/bmp-280-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/bmp-280-sensor.h rename to arch/platform/cc26x0-cc13x0/sensortag/bmp-280-sensor.h diff --git a/arch/platform/srf06-cc26xx/sensortag/board-buttons.c b/arch/platform/cc26x0-cc13x0/sensortag/board-buttons.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/board-buttons.c rename to arch/platform/cc26x0-cc13x0/sensortag/board-buttons.c diff --git a/arch/platform/srf06-cc26xx/sensortag/board-i2c.c b/arch/platform/cc26x0-cc13x0/sensortag/board-i2c.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/board-i2c.c rename to arch/platform/cc26x0-cc13x0/sensortag/board-i2c.c diff --git a/arch/platform/srf06-cc26xx/sensortag/board-i2c.h b/arch/platform/cc26x0-cc13x0/sensortag/board-i2c.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/board-i2c.h rename to arch/platform/cc26x0-cc13x0/sensortag/board-i2c.h diff --git a/arch/platform/srf06-cc26xx/sensortag/board-peripherals.h b/arch/platform/cc26x0-cc13x0/sensortag/board-peripherals.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/board-peripherals.h rename to arch/platform/cc26x0-cc13x0/sensortag/board-peripherals.h diff --git a/arch/platform/srf06-cc26xx/sensortag/board.c b/arch/platform/cc26x0-cc13x0/sensortag/board.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/board.c rename to arch/platform/cc26x0-cc13x0/sensortag/board.c diff --git a/arch/platform/srf06-cc26xx/sensortag/buzzer.c b/arch/platform/cc26x0-cc13x0/sensortag/buzzer.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/buzzer.c rename to arch/platform/cc26x0-cc13x0/sensortag/buzzer.c diff --git a/arch/platform/srf06-cc26xx/sensortag/buzzer.h b/arch/platform/cc26x0-cc13x0/sensortag/buzzer.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/buzzer.h rename to arch/platform/cc26x0-cc13x0/sensortag/buzzer.h diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 b/arch/platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 similarity index 91% rename from arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 rename to arch/platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 index cdae4c2b1..f0f924e97 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 +++ b/arch/platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 @@ -1,5 +1,5 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc13xx +CPU_FAMILY = cc13x0 ### Add to the source dirs CONTIKI_TARGET_DIRS += sensortag/cc1350 diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h b/arch/platform/cc26x0-cc13x0/sensortag/cc1350/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/cc1350/board.h rename to arch/platform/cc26x0-cc13x0/sensortag/cc1350/board.h diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c b/arch/platform/cc26x0-cc13x0/sensortag/cc1350/leds-arch.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c rename to arch/platform/cc26x0-cc13x0/sensortag/cc1350/leds-arch.c diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 b/arch/platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 similarity index 91% rename from arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 rename to arch/platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 index e91cabda4..4aa83e352 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 +++ b/arch/platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 @@ -1,5 +1,5 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc26xx +CPU_FAMILY = cc26x0 ### Add to the source dirs CONTIKI_TARGET_DIRS += sensortag/cc2650 diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h b/arch/platform/cc26x0-cc13x0/sensortag/cc2650/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/cc2650/board.h rename to arch/platform/cc26x0-cc13x0/sensortag/cc2650/board.h diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c b/arch/platform/cc26x0-cc13x0/sensortag/cc2650/leds-arch.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c rename to arch/platform/cc26x0-cc13x0/sensortag/cc2650/leds-arch.c diff --git a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c b/arch/platform/cc26x0-cc13x0/sensortag/hdc-1000-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c rename to arch/platform/cc26x0-cc13x0/sensortag/hdc-1000-sensor.c diff --git a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h b/arch/platform/cc26x0-cc13x0/sensortag/hdc-1000-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h rename to arch/platform/cc26x0-cc13x0/sensortag/hdc-1000-sensor.h diff --git a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c b/arch/platform/cc26x0-cc13x0/sensortag/mpu-9250-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c rename to arch/platform/cc26x0-cc13x0/sensortag/mpu-9250-sensor.c diff --git a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.h b/arch/platform/cc26x0-cc13x0/sensortag/mpu-9250-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.h rename to arch/platform/cc26x0-cc13x0/sensortag/mpu-9250-sensor.h diff --git a/arch/platform/srf06-cc26xx/sensortag/opt-3001-sensor.c b/arch/platform/cc26x0-cc13x0/sensortag/opt-3001-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/opt-3001-sensor.c rename to arch/platform/cc26x0-cc13x0/sensortag/opt-3001-sensor.c diff --git a/arch/platform/srf06-cc26xx/sensortag/opt-3001-sensor.h b/arch/platform/cc26x0-cc13x0/sensortag/opt-3001-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/opt-3001-sensor.h rename to arch/platform/cc26x0-cc13x0/sensortag/opt-3001-sensor.h diff --git a/arch/platform/srf06-cc26xx/sensortag/sensor-common.c b/arch/platform/cc26x0-cc13x0/sensortag/sensor-common.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/sensor-common.c rename to arch/platform/cc26x0-cc13x0/sensortag/sensor-common.c diff --git a/arch/platform/srf06-cc26xx/sensortag/sensor-common.h b/arch/platform/cc26x0-cc13x0/sensortag/sensor-common.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/sensor-common.h rename to arch/platform/cc26x0-cc13x0/sensortag/sensor-common.h diff --git a/arch/platform/srf06-cc26xx/sensortag/sensortag-sensors.c b/arch/platform/cc26x0-cc13x0/sensortag/sensortag-sensors.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/sensortag-sensors.c rename to arch/platform/cc26x0-cc13x0/sensortag/sensortag-sensors.c diff --git a/arch/platform/srf06-cc26xx/sensortag/tmp-007-sensor.c b/arch/platform/cc26x0-cc13x0/sensortag/tmp-007-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/tmp-007-sensor.c rename to arch/platform/cc26x0-cc13x0/sensortag/tmp-007-sensor.c diff --git a/arch/platform/srf06-cc26xx/sensortag/tmp-007-sensor.h b/arch/platform/cc26x0-cc13x0/sensortag/tmp-007-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/sensortag/tmp-007-sensor.h rename to arch/platform/cc26x0-cc13x0/sensortag/tmp-007-sensor.h diff --git a/arch/platform/srf06-cc26xx/srf06/Makefile.srf06 b/arch/platform/cc26x0-cc13x0/srf06/Makefile.srf06 similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/Makefile.srf06 rename to arch/platform/cc26x0-cc13x0/srf06/Makefile.srf06 diff --git a/arch/platform/srf06-cc26xx/srf06/als-sensor.c b/arch/platform/cc26x0-cc13x0/srf06/als-sensor.c similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/als-sensor.c rename to arch/platform/cc26x0-cc13x0/srf06/als-sensor.c diff --git a/arch/platform/srf06-cc26xx/srf06/als-sensor.h b/arch/platform/cc26x0-cc13x0/srf06/als-sensor.h similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/als-sensor.h rename to arch/platform/cc26x0-cc13x0/srf06/als-sensor.h diff --git a/arch/platform/srf06-cc26xx/srf06/board-buttons.c b/arch/platform/cc26x0-cc13x0/srf06/board-buttons.c similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/board-buttons.c rename to arch/platform/cc26x0-cc13x0/srf06/board-buttons.c diff --git a/arch/platform/srf06-cc26xx/srf06/board-peripherals.h b/arch/platform/cc26x0-cc13x0/srf06/board-peripherals.h similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/board-peripherals.h rename to arch/platform/cc26x0-cc13x0/srf06/board-peripherals.h diff --git a/arch/platform/srf06-cc26xx/srf06/board.c b/arch/platform/cc26x0-cc13x0/srf06/board.c similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/board.c rename to arch/platform/cc26x0-cc13x0/srf06/board.c diff --git a/arch/platform/srf06-cc26xx/srf06/cc13xx/Makefile.cc13xx b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 similarity index 72% rename from arch/platform/srf06-cc26xx/srf06/cc13xx/Makefile.cc13xx rename to arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 index b83084651..ec20fcb63 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc13xx/Makefile.cc13xx +++ b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 @@ -1,7 +1,7 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc13xx +CPU_FAMILY = cc13x0 ### Include the common sensortag makefile include $(PLATFORM_ROOT_DIR)/srf06/Makefile.srf06 -CONTIKI_TARGET_DIRS += srf06/cc13xx +CONTIKI_TARGET_DIRS += srf06/cc13x0 diff --git a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/cc13xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc13x0/board.h diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/Makefile.cc26xx b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 similarity index 71% rename from arch/platform/srf06-cc26xx/srf06/cc26xx/Makefile.cc26xx rename to arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 index 841442a5c..84ef217a8 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc26xx/Makefile.cc26xx +++ b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 @@ -1,7 +1,7 @@ ### Will allow the inclusion of the correct CPU makefile -CPU_FAMILY = cc26xx +CPU_FAMILY = cc26x0 ### Include the common makefile include $(PLATFORM_ROOT_DIR)/srf06/Makefile.srf06 -CONTIKI_TARGET_DIRS += srf06/cc26xx +CONTIKI_TARGET_DIRS += srf06/cc26x0 diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/board.h similarity index 99% rename from arch/platform/srf06-cc26xx/srf06/cc26xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc26x0/board.h index f31a94fb3..cd6d2b1e4 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h +++ b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/board.h @@ -31,7 +31,7 @@ /** \addtogroup cc26xx-srf-tag * @{ * - * \defgroup srf06-cc26xx-peripherals Peripherals for the SmartRF06EB + CC26xxEM + * \defgroup cc26x0-cc13x0-peripherals Peripherals for the SmartRF06EB + CC26xxEM * * Defines related to the SmartRF06 Evaluation Board with a CC26xxEM * diff --git a/arch/platform/srf06-cc26xx/srf06/leds-arch.c b/arch/platform/cc26x0-cc13x0/srf06/leds-arch.c similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/leds-arch.c rename to arch/platform/cc26x0-cc13x0/srf06/leds-arch.c diff --git a/arch/platform/srf06-cc26xx/srf06/srf06-sensors.c b/arch/platform/cc26x0-cc13x0/srf06/srf06-sensors.c similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/srf06-sensors.c rename to arch/platform/cc26x0-cc13x0/srf06/srf06-sensors.c diff --git a/arch/platform/cooja/net/uip-driver.c b/arch/platform/cooja/net/uip-driver.c index 0e7209a6c..fd86cc9c6 100644 --- a/arch/platform/cooja/net/uip-driver.c +++ b/arch/platform/cooja/net/uip-driver.c @@ -48,7 +48,7 @@ static uint8_t uip_driver_send(const linkaddr_t *addr) { - packetbuf_copyfrom(&uip_buf[UIP_LLH_LEN], uip_len); + packetbuf_copyfrom(uip_buf, uip_len); /* XXX we should provide a callback function that is called when the packet is sent. For now, we just supply a NULL pointer. */ @@ -64,9 +64,8 @@ init(void) static void input(void) { - if(packetbuf_datalen() > 0 && - packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) { - memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen()); + if(packetbuf_datalen() > 0 && packetbuf_datalen() <= UIP_BUFSIZE) { + memcpy(uip_buf, packetbuf_dataptr(), packetbuf_datalen()); uip_len = packetbuf_datalen(); tcpip_input(); } diff --git a/arch/platform/jn516x/slip.c b/arch/platform/jn516x/slip.c index 173a14d60..41652e181 100644 --- a/arch/platform/jn516x/slip.c +++ b/arch/platform/jn516x/slip.c @@ -46,7 +46,6 @@ #include #include "net/ipv6/uip.h" -#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) #include "dev/slip.h" @@ -117,7 +116,7 @@ unsigned long slip_received, slip_frames; #ifdef SLIP_CONF_RX_BUFSIZE #define RX_BUFSIZE SLIP_CONF_RX_BUFSIZE -#if RX_BUFSIZE < (UIP_BUFSIZE - UIP_LLH_LEN + 16) +#if RX_BUFSIZE < (UIP_BUFSIZE + 16) #error "SLIP_CONF_RX_BUFSIZE too small for UIP_BUFSIZE" #endif @@ -195,7 +194,7 @@ slip_send(void) slip_arch_writeb(SLIP_END); - ptr = &uip_buf[UIP_LLH_LEN]; + ptr = uip_buf; for(i = 0; i < uip_len; ++i) { c = *ptr++; slip_write_char(c); @@ -317,8 +316,7 @@ PROCESS_THREAD(slip_process, ev, data) PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); /* Move packet from rxbuf to buffer provided by uIP. */ - uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN], - UIP_BUFSIZE - UIP_LLH_LEN); + uip_len = slip_poll_handler(uip_buf, UIP_BUFSIZE); PRINTF("SLIP: recv bytes %u frames RECV: %u. is_full %u, is_dropping %u.\n", end_counter, uip_len, is_full, is_dropping); diff --git a/arch/platform/nrf52dk/contiki-conf.h b/arch/platform/nrf52dk/contiki-conf.h index 7b3b66314..12d1b2fc9 100644 --- a/arch/platform/nrf52dk/contiki-conf.h +++ b/arch/platform/nrf52dk/contiki-conf.h @@ -74,6 +74,10 @@ /* Packet buffer */ #define PACKETBUF_CONF_SIZE 1280 /**< Required IPv6 MTU size */ + +/* Queuebuf */ +#define QUEUEBUF_CONF_ENABLED 0 + /** @} */ /** diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 38b86fd13..938abe035 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -46,23 +46,8 @@ MODULES += arch/dev/cc1200 arch/dev/rgb-led os/storage/cfs BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -### Use the specific Zoul subplatform to query for connected devices -ifdef MOTELIST_ZOLERTIA - MOTELIST_FLAGS += -b $(MOTELIST_ZOLERTIA) -endif - -### Detect if a mote is connected over serial port -ifeq ($(HOST_OS),Darwin) - USBDEVPREFIX= - MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos - MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,) -else -### If we are not running under Mac, we assume Linux - USBDEVPREFIX= - MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia - MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \ - perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') -endif +MOTES := $(shell python $(TOOLS_DIR)/motelist/motelist.py --omit-header \ + | grep $(MOTELIST_ZOLERTIA) | cut -f1 -d " ") ### If PORT is defined, override to keep backward compatibility ifdef PORT @@ -81,7 +66,8 @@ endif ### Variable that expands into a pattern rule to upload to a given MOTE. ### Requires $(MOTE) to be defined -### $$$$ Double escapes $s that need to be passed to the shell - once for when make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make. +### $$$$ Double escapes $s that need to be passed to the shell - once for when +### make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make. define UPLOAD_RULE %.$(MOTE): %.bin %.elf @echo "Flashing $(MOTE)" @@ -94,10 +80,8 @@ endef ### Create an upload rule for every MOTE connected $(foreach MOTE,$(MOTES),$(eval $(UPLOAD_RULE))) -motelist: - $(MOTELIST) -zoul-motelist: - $(MOTELIST) $(MOTELIST_FLAGS) +.PHONY: zoul-motes + zoul-motes: @echo $(MOTES) diff --git a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva index afecf9fa5..bfbcb03fb 100644 --- a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva +++ b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva @@ -1,2 +1,2 @@ -MOTELIST_ZOLERTIA = firefly +MOTELIST_ZOLERTIA := Firefly BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/firefly/Makefile.firefly b/arch/platform/zoul/firefly/Makefile.firefly index afecf9fa5..bfbcb03fb 100644 --- a/arch/platform/zoul/firefly/Makefile.firefly +++ b/arch/platform/zoul/firefly/Makefile.firefly @@ -1,2 +1,2 @@ -MOTELIST_ZOLERTIA = firefly +MOTELIST_ZOLERTIA := Firefly BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/orion/Makefile.orion b/arch/platform/zoul/orion/Makefile.orion index ebc1bdad4..b7313afc0 100644 --- a/arch/platform/zoul/orion/Makefile.orion +++ b/arch/platform/zoul/orion/Makefile.orion @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = orion +MOTELIST_ZOLERTIA := Orion MODULES += arch/dev/enc28j60 CC2538_ENC28J60_ARCH ?= gpio ifeq ($(WITH_IP64),1) diff --git a/arch/platform/zoul/remote-reva/Makefile.remote-reva b/arch/platform/zoul/remote-reva/Makefile.remote-reva index fcccdf0f4..ec4095265 100644 --- a/arch/platform/zoul/remote-reva/Makefile.remote-reva +++ b/arch/platform/zoul/remote-reva/Makefile.remote-reva @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = remote +MOTELIST_ZOLERTIA := RE-Mote BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/arch/platform/zoul/remote-revb/Makefile.remote-revb b/arch/platform/zoul/remote-revb/Makefile.remote-revb index fcccdf0f4..ec4095265 100644 --- a/arch/platform/zoul/remote-revb/Makefile.remote-revb +++ b/arch/platform/zoul/remote-revb/Makefile.remote-revb @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = remote +MOTELIST_ZOLERTIA := RE-Mote BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/examples/6tisch/6p-packet/Makefile b/examples/6tisch/6p-packet/Makefile index ac92805ae..3ba74d3b9 100644 --- a/examples/6tisch/6p-packet/Makefile +++ b/examples/6tisch/6p-packet/Makefile @@ -2,7 +2,6 @@ CONTIKI_PROJECT = sixp-node PROJECT_SOURCEFILES += test-sf.c PLATFORMS_EXCLUDE = sky nrf52dk native simplelink -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 CONTIKI = ../../../ diff --git a/examples/6tisch/channel-selection-demo/Makefile b/examples/6tisch/channel-selection-demo/Makefile index a44c76f10..ada4a5062 100644 --- a/examples/6tisch/channel-selection-demo/Makefile +++ b/examples/6tisch/channel-selection-demo/Makefile @@ -4,7 +4,7 @@ all: $(CONTIKI_PROJECT) CONTIKI=../../.. PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 # The channel selection library MODULES += os/services/tsch-cs diff --git a/examples/6tisch/etsi-plugtest-2017/Makefile b/examples/6tisch/etsi-plugtest-2017/Makefile index b5aeb66f5..6dc463078 100644 --- a/examples/6tisch/etsi-plugtest-2017/Makefile +++ b/examples/6tisch/etsi-plugtest-2017/Makefile @@ -2,7 +2,7 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) PLATFORMS_EXCLUDE = sky nrf52dk native simplelink -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARDS_EXCLUDE = sensortag/cc2650 sensortag/cc1350 MAKE_WITH_SECURITY ?= 0 # force Security from command line ifeq ($(MAKE_WITH_SECURITY),1) diff --git a/examples/6tisch/etsi-plugtest-2017/README.md b/examples/6tisch/etsi-plugtest-2017/README.md index ab296bff8..7369918fa 100644 --- a/examples/6tisch/etsi-plugtest-2017/README.md +++ b/examples/6tisch/etsi-plugtest-2017/README.md @@ -18,7 +18,7 @@ The following hardwares were used in the event: * Zolertia Remote (TARGET=`zoul`, BOARD=`remote`) * JN156x (TARGET=`jn516`) -* CC2650 LaunchPad (TARGET=`srf06-cc26xx`, BOARD=`launchpad/cc2650`) +* CC2650 LaunchPad (TARGET=`cc26x0-cc13x0`, BOARD=`launchpad/cc2650`) ## Usage diff --git a/examples/6tisch/simple-node/Makefile b/examples/6tisch/simple-node/Makefile index c2e976b4e..06a83ebdd 100644 --- a/examples/6tisch/simple-node/Makefile +++ b/examples/6tisch/simple-node/Makefile @@ -2,7 +2,6 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) PLATFORMS_EXCLUDE = sky nrf52dk native simplelink -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 CONTIKI=../../.. diff --git a/examples/6tisch/sixtop/Makefile b/examples/6tisch/sixtop/Makefile index 2469cd445..5c35696e4 100644 --- a/examples/6tisch/sixtop/Makefile +++ b/examples/6tisch/sixtop/Makefile @@ -2,7 +2,6 @@ CONTIKI_PROJECT = node-sixtop all: $(CONTIKI_PROJECT) PLATFORMS_EXCLUDE = sky nrf52dk native simplelink -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 PROJECT_SOURCEFILES += sf-simple.c CONTIKI=../../.. diff --git a/examples/6tisch/tsch-stats/Makefile b/examples/6tisch/tsch-stats/Makefile index 0c8863301..5fdb5feb6 100644 --- a/examples/6tisch/tsch-stats/Makefile +++ b/examples/6tisch/tsch-stats/Makefile @@ -4,7 +4,7 @@ all: $(CONTIKI_PROJECT) CONTIKI=../../.. PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 # force Orchestra from command line MAKE_WITH_ORCHESTRA ?= 0 diff --git a/examples/benchmarks/rpl-req-resp/Makefile b/examples/benchmarks/rpl-req-resp/Makefile index 11413ecd3..e23a35d5f 100644 --- a/examples/benchmarks/rpl-req-resp/Makefile +++ b/examples/benchmarks/rpl-req-resp/Makefile @@ -2,7 +2,7 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) PLATFORMS_EXCLUDE = sky nrf52dk native simplelink -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 MODULES_REL += ../testbeds MODULES += os/services/deployment diff --git a/examples/dev/button-hal/Makefile b/examples/dev/button-hal/Makefile index b2a73fe3c..263e9ec65 100644 --- a/examples/dev/button-hal/Makefile +++ b/examples/dev/button-hal/Makefile @@ -3,6 +3,6 @@ CONTIKI = ../../.. all: $(CONTIKI_PROJECT) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink +PLATFORMS_ONLY = cc26x0-cc13x0 cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.include diff --git a/examples/dev/gpio-hal/Makefile b/examples/dev/gpio-hal/Makefile index 70f38a11a..234388c09 100644 --- a/examples/dev/gpio-hal/Makefile +++ b/examples/dev/gpio-hal/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = gpio-hal-example CONTIKI = ../../.. -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink +PLATFORMS_ONLY = cc26x0-cc13x0 cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.identify-target diff --git a/examples/dev/gpio-hal/srf06-cc26xx/pins.c b/examples/dev/gpio-hal/cc26x0-cc13x0/pins.c similarity index 100% rename from examples/dev/gpio-hal/srf06-cc26xx/pins.c rename to examples/dev/gpio-hal/cc26x0-cc13x0/pins.c diff --git a/examples/dev/gpio-hal/gpio-hal-example.c b/examples/dev/gpio-hal/gpio-hal-example.c index 380c06388..75137e26a 100644 --- a/examples/dev/gpio-hal/gpio-hal-example.c +++ b/examples/dev/gpio-hal/gpio-hal-example.c @@ -46,9 +46,9 @@ static uint8_t counter; /*---------------------------------------------------------------------------*/ /* Print gpio_hal_pin_mask_t using the correct format */ #if GPIO_HAL_PIN_COUNT > 32 -#define PIN_MASK_FMT PRIx64 +#define PIN_MASK_FMT "0x%016" PRIx64 #else -#define PIN_MASK_FMT PRIx32 +#define PIN_MASK_FMT "0x%08" PRIx32 #endif /*---------------------------------------------------------------------------*/ PROCESS(gpio_hal_example, "GPIO HAL Example"); @@ -127,7 +127,7 @@ PROCESS_THREAD(gpio_hal_example, ev, data) } /* Test read */ - printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08" PIN_MASK_FMT "\n", + printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=" PIN_MASK_FMT "\n", counter & 7, gpio_hal_arch_read_pin(out_pin1), gpio_hal_arch_read_pin(out_pin2), diff --git a/examples/libs/ipv6-hooks/ipv6-hooks.c b/examples/libs/ipv6-hooks/ipv6-hooks.c index d3ca8861c..8d8561049 100644 --- a/examples/libs/ipv6-hooks/ipv6-hooks.c +++ b/examples/libs/ipv6-hooks/ipv6-hooks.c @@ -10,8 +10,6 @@ #define LOG_MODULE "App" #define LOG_LEVEL LOG_LEVEL_INFO -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - /*---------------------------------------------------------------------------*/ PROCESS(ipv6_hooks_process, "IPv6 Hooks"); AUTOSTART_PROCESSES(&ipv6_hooks_process); diff --git a/examples/libs/timers/all-timers.c b/examples/libs/timers/all-timers.c index 2a1f27b28..bb6dfed90 100644 --- a/examples/libs/timers/all-timers.c +++ b/examples/libs/timers/all-timers.c @@ -79,7 +79,7 @@ PROCESS_THREAD(timer_process, ev, data) PROCESS_BEGIN(); ctimer_set(&timer_ctimer, CLOCK_SECOND, ctimer_callback, NULL); - rtimer_set(&timer_rtimer, RTIMER_NOW() + CLOCK_SECOND / 2, 0, + rtimer_set(&timer_rtimer, RTIMER_NOW() + RTIMER_SECOND / 2, 0, rtimer_callback, NULL); while(1) { diff --git a/examples/mqtt-client/Makefile b/examples/mqtt-client/Makefile index a9ab11613..29b3267e1 100644 --- a/examples/mqtt-client/Makefile +++ b/examples/mqtt-client/Makefile @@ -8,6 +8,6 @@ CONTIKI = ../.. MODULES_REL += arch/platform/$(TARGET) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink +PLATFORMS_ONLY = cc26x0-cc13x0 cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.include diff --git a/examples/mqtt-client/arch/cpu/cc26xx-cc13xx/builtin-sensors.c b/examples/mqtt-client/arch/cpu/cc26x0-cc13x0/builtin-sensors.c similarity index 100% rename from examples/mqtt-client/arch/cpu/cc26xx-cc13xx/builtin-sensors.c rename to examples/mqtt-client/arch/cpu/cc26x0-cc13x0/builtin-sensors.c diff --git a/examples/mqtt-client/arch/cpu/cc26xx-cc13xx/builtin-sensors.h b/examples/mqtt-client/arch/cpu/cc26x0-cc13x0/builtin-sensors.h similarity index 100% rename from examples/mqtt-client/arch/cpu/cc26xx-cc13xx/builtin-sensors.h rename to examples/mqtt-client/arch/cpu/cc26x0-cc13x0/builtin-sensors.h diff --git a/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 new file mode 100644 index 000000000..7c74123c6 --- /dev/null +++ b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -0,0 +1 @@ +MODULES_REL += arch/cpu/cc26x0-cc13x0 diff --git a/examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/module-macros.h similarity index 100% rename from examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h rename to examples/mqtt-client/arch/platform/cc26x0-cc13x0/module-macros.h diff --git a/examples/mqtt-client/arch/platform/srf06-cc26xx/mqtt-client-extensions.c b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/mqtt-client-extensions.c similarity index 100% rename from examples/mqtt-client/arch/platform/srf06-cc26xx/mqtt-client-extensions.c rename to examples/mqtt-client/arch/platform/cc26x0-cc13x0/mqtt-client-extensions.c diff --git a/examples/mqtt-client/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/examples/mqtt-client/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx deleted file mode 100644 index dcec87bad..000000000 --- a/examples/mqtt-client/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ /dev/null @@ -1 +0,0 @@ -MODULES_REL += arch/cpu/cc26xx-cc13xx diff --git a/examples/mqtt-client/mqtt-client.c b/examples/mqtt-client/mqtt-client.c index be3c97cdb..b71a193ea 100644 --- a/examples/mqtt-client/mqtt-client.c +++ b/examples/mqtt-client/mqtt-client.c @@ -47,7 +47,11 @@ #include /*---------------------------------------------------------------------------*/ #define LOG_MODULE "mqtt-client" +#ifdef MQTT_CLIENT_CONF_LOG_LEVEL +#define LOG_LEVEL MQTT_CLIENT_CONF_LOG_LEVEL +#else #define LOG_LEVEL LOG_LEVEL_NONE +#endif /*---------------------------------------------------------------------------*/ /* Controls whether the example will work in IBM Watson IoT platform mode */ #ifdef MQTT_CLIENT_CONF_WITH_IBM_WATSON @@ -305,6 +309,7 @@ pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk, } if(strncmp(&topic[10], "leds", 4) == 0) { + LOG_DBG("Received MQTT SUB\n"); if(chunk[0] == '1') { leds_on(LEDS_RED); } else if(chunk[0] == '0') { diff --git a/examples/mqtt-client/project-conf.h b/examples/mqtt-client/project-conf.h index 66ba909ce..6b011f7b0 100644 --- a/examples/mqtt-client/project-conf.h +++ b/examples/mqtt-client/project-conf.h @@ -52,7 +52,9 @@ * devices, set your Org ID here and then make sure you set the correct token * through MQTT_CLIENT_CONF_AUTH_TOKEN. */ +#ifndef MQTT_CLIENT_CONF_ORG_ID #define MQTT_CLIENT_CONF_ORG_ID "quickstart" +#endif /* * The MQTT username. diff --git a/examples/multicast/srf06-cc26xx/module-macros.h b/examples/multicast/cc26x0-cc13x0/module-macros.h similarity index 100% rename from examples/multicast/srf06-cc26xx/module-macros.h rename to examples/multicast/cc26x0-cc13x0/module-macros.h diff --git a/examples/multicast/sink.c b/examples/multicast/sink.c index 34ad6009d..49180b69a 100644 --- a/examples/multicast/sink.c +++ b/examples/multicast/sink.c @@ -55,8 +55,6 @@ static struct uip_udp_conn *sink_conn; static uint16_t count; -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - #if !NETSTACK_CONF_WITH_IPV6 || !UIP_CONF_ROUTER || !UIP_IPV6_MULTICAST || !UIP_CONF_IPV6_RPL #error "This example can not work with the current contiki configuration" #error "Check the values of: NETSTACK_CONF_WITH_IPV6, UIP_CONF_ROUTER, UIP_CONF_IPV6_RPL" diff --git a/examples/platform-specific/cc26xx/Makefile b/examples/platform-specific/cc26x0-cc13x0/Makefile similarity index 78% rename from examples/platform-specific/cc26xx/Makefile rename to examples/platform-specific/cc26x0-cc13x0/Makefile index 40e484bcc..9962ab32a 100644 --- a/examples/platform-specific/cc26xx/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = cc26xx-demo -PLATFORMS_ONLY = srf06-cc26xx +PLATFORMS_ONLY = cc26x0-cc13x0 all: $(CONTIKI_PROJECT) diff --git a/examples/platform-specific/cc26xx/Makefile.target b/examples/platform-specific/cc26x0-cc13x0/Makefile.target similarity index 100% rename from examples/platform-specific/cc26xx/Makefile.target rename to examples/platform-specific/cc26x0-cc13x0/Makefile.target diff --git a/examples/platform-specific/cc26xx/README.md b/examples/platform-specific/cc26x0-cc13x0/README.md similarity index 100% rename from examples/platform-specific/cc26xx/README.md rename to examples/platform-specific/cc26x0-cc13x0/README.md diff --git a/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile new file mode 100644 index 000000000..052927896 --- /dev/null +++ b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile @@ -0,0 +1,11 @@ +CONTIKI_PROJECT=client + +all: $(CONTIKI_PROJECT) + +PLATFORMS_ONLY = cc26x0-cc13x0 +BOARDS_ONLY = launchpad/cc2650 sensortag/cc2650 srf06/cc26x0 + +MAKE_MAC = MAKE_MAC_BLE +MAKE_NET = MAKE_NET_IPV6 +CONTIKI = ../../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/cc26xx/ble-ipv6/README.md b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md similarity index 95% rename from examples/platform-specific/cc26xx/ble-ipv6/README.md rename to examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md index d33c7329f..078667264 100644 --- a/examples/platform-specific/cc26xx/ble-ipv6/README.md +++ b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md @@ -28,12 +28,12 @@ It has been tested on the TI CC2650 SensorTag and the TI CC2650 LaunchPad hardwa The IPv6-over-BLE stack comes with the following modules: ### BLE radio -The implementation of the BLE radio for the TI CC26xx platform is implemented in `arch/cpu/cc26xx-cc13xx/rf-core/ble-cc2650.c` -and `arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/*.[ch]`. +The implementation of the BLE radio for the TI CC26xx platform is implemented in `arch/cpu/cc26x0-cc13x0/rf-core/ble-cc2650.c` +and `arch/cpu/cc26x0-cc13x0/rf-core/ble-hal/*.[ch]`. These files contain all the hardware specific code for supporting BLE as a link layer. ### BLE L2CAP layer -The L2CAP LE credit-based flow control support is implemented in `arch/cpu/cc26xx-cc13xx/rf-core/ble-l2cap.c`. +The L2CAP LE credit-based flow control support is implemented in `arch/cpu/cc26x0-cc13x0/rf-core/ble-l2cap.c`. Besides implementing rudimentary L2CAP support, this module handles fragmentation of large IPv6 packets. ## Using BLEach diff --git a/examples/platform-specific/cc26xx/ble-ipv6/client.c b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/client.c similarity index 100% rename from examples/platform-specific/cc26xx/ble-ipv6/client.c rename to examples/platform-specific/cc26x0-cc13x0/ble-ipv6/client.c diff --git a/examples/platform-specific/cc26xx/ble-ipv6/project-conf.h b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/project-conf.h similarity index 100% rename from examples/platform-specific/cc26xx/ble-ipv6/project-conf.h rename to examples/platform-specific/cc26x0-cc13x0/ble-ipv6/project-conf.h diff --git a/examples/platform-specific/cc26xx/cc26xx-demo.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-demo.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-demo.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-demo.c index 81e99f3fa..1b71feeb7 100644 --- a/examples/platform-specific/cc26xx/cc26xx-demo.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-demo.c @@ -42,7 +42,7 @@ * Example project demonstrating the CC13xx/CC26xx platforms * * This example will work for the following boards: - * - srf06-cc26xx: SmartRF06EB + CC13xx/CC26xx EM + * - cc26x0-cc13x0: SmartRF06EB + CC13xx/CC26xx EM * - CC2650 and CC1350 SensorTag * - CC1310, CC1350, CC2650 LaunchPads * diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile similarity index 87% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile index 05dbface1..6d70a3a24 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile @@ -1,7 +1,7 @@ -CONTIKI_PROJECT = cc26xx-web-demo +CONTIKI_PROJECT = cc26x0-web-demo all: $(CONTIKI_PROJECT) -PLATFORMS_ONLY = srf06-cc26xx +PLATFORMS_ONLY = cc26x0-cc13x0 MODULES_REL += ./resources diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile.target b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile.target similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile.target rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile.target diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/README.md similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/README.md rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/README.md index 912fcb72a..6a85ee0b5 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/README.md @@ -180,6 +180,6 @@ parser into the firmware. IBM Watson IoT Platform ---------------------------- -To use IBM Watson IoT Platform, you have to go to SECURITY tab of Device page to select "TLS Optional". This step is critical. If you don't do this, you need to use TLS for connection and default cc26xx-web-demo won't work. +To use IBM Watson IoT Platform, you have to go to SECURITY tab of Device page to select "TLS Optional". This step is critical. If you don't do this, you need to use TLS for connection and default cc26x0-web-demo won't work. ![IBM Watson IoT Platform TLS Optional Configuration](img/ibm-watson-iot-platform-tls-optional.png) diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.c index 3944a58b2..6333d5ad5 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.c @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -48,7 +48,7 @@ #include "dev/button-hal.h" #include "batmon-sensor.h" #include "httpd-simple.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "mqtt-client.h" #include "coap-server.h" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.h similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.h index f59e41bc7..e7252496c 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-web-demo.h @@ -31,7 +31,7 @@ * \addtogroup cc26xx-examples * @{ * - * \defgroup cc26xx-web-demo CC26xx Web Demo + * \defgroup cc26x0-web-demo CC26xx Web Demo * @{ * * An example demonstrating: diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cetic-6lbr-client.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cetic-6lbr-client.c index 569a36a89..fc8044380 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cetic-6lbr-client.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.c index 37b9a295d..bda7eb8ff 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.c @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -40,7 +40,7 @@ #include "coap-engine.h" #include "board-peripherals.h" #include "rf-core/rf-ble.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include #include diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.h similarity index 98% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.h index 7399597c8..0d8c1d40b 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.h +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/coap-server.h @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c index e23e78efe..101b6441b 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c @@ -29,7 +29,7 @@ * */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -38,11 +38,12 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "httpd-simple.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" #include "batmon-sensor.h" #include "lib/sensors.h" #include "lib/list.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "mqtt-client.h" #include "net-uart.h" @@ -436,8 +437,8 @@ PT_THREAD(generate_index(struct httpd_state *s)) PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, SECTION_OPEN "Neighbors" CONTENT_OPEN)); - for(s->nbr = nbr_table_head(ds6_neighbors); s->nbr != NULL; - s->nbr = nbr_table_next(ds6_neighbors, s->nbr)) { + for(s->nbr = uip_ds6_nbr_head(); s->nbr != NULL; + s->nbr = uip_ds6_nbr_next(s->nbr)) { PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "\n")); diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.h similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.h index 25b8db3e5..2b04b264c 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.h +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.h @@ -44,7 +44,7 @@ /*---------------------------------------------------------------------------*/ #include "contiki-net.h" #include "sys/process.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" /*---------------------------------------------------------------------------*/ /* Ideally a multiple of TCP_MSS */ #ifdef HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/6lbr-web.png b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/6lbr-web.png similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/img/6lbr-web.png rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/6lbr-web.png diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/ibm-watson-iot-platform-tls-optional.png similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/ibm-watson-iot-platform-tls-optional.png diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/quickstart-sensortag.png b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/quickstart-sensortag.png similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/img/quickstart-sensortag.png rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/quickstart-sensortag.png diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/sensor-readings-config.png b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/sensor-readings-config.png similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/img/sensor-readings-config.png rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/sensor-readings-config.png diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/well-known-core.png b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/well-known-core.png similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/img/well-known-core.png rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/img/well-known-core.png diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.c index 7562fb89a..0250de322 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.c @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -45,7 +45,7 @@ #include "lib/sensors.h" #include "dev/button-hal.h" #include "board-peripherals.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "dev/leds.h" #include "mqtt-client.h" #include "httpd-simple.h" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.h similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.h index ab7c08227..68b26af6d 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.h +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/mqtt-client.h @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/net-uart.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/net-uart.c index ca3bf8c82..a2ea899da 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/net-uart.c @@ -28,7 +28,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/net-uart.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/net-uart.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/project-conf.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/project-conf.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-ble-advd.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-ble-advd.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-ble-advd.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-ble-advd.c index a94a0b7a0..b32cb82ec 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-ble-advd.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-ble-advd.c @@ -28,7 +28,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-device.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-device.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-device.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-device.c index 46344d1ef..bc61b8510 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-device.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-device.c @@ -29,7 +29,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -41,7 +41,7 @@ #include "coap.h" #include "sys/clock.h" #include "coap-server.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "ti-lib.h" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-leds.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-leds.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-leds.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-leds.c index 6c396145c..538ecc0bd 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-leds.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-leds.c @@ -29,7 +29,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-net.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-net.c similarity index 98% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-net.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-net.c index 81575f345..43a4da354 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-net.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-net.c @@ -29,7 +29,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -41,7 +41,7 @@ #include "coap.h" #include "net/ipv6/uip-ds6.h" #include "coap-server.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "ti-lib.h" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-sensors.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-sensors.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-sensors.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-sensors.c index 9ccc79e97..1852f7cb6 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-sensors.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-sensors.c @@ -29,7 +29,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file @@ -39,7 +39,7 @@ #include "contiki.h" #include "coap-engine.h" #include "coap.h" -#include "cc26xx-web-demo.h" +#include "cc26x0-web-demo.h" #include "coap-server.h" #include diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-toggle-leds.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-toggle-leds.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-toggle-leds.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-toggle-leds.c index 1c708b539..00e632cef 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-toggle-leds.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/resources/res-toggle-leds.c @@ -31,7 +31,7 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-web-demo + * \addtogroup cc26x0-web-demo * @{ * * \file diff --git a/examples/platform-specific/cc26xx/project-conf.h b/examples/platform-specific/cc26x0-cc13x0/project-conf.h similarity index 100% rename from examples/platform-specific/cc26xx/project-conf.h rename to examples/platform-specific/cc26x0-cc13x0/project-conf.h diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/Makefile b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/Makefile similarity index 83% rename from examples/platform-specific/cc26xx/very-sleepy-demo/Makefile rename to examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/Makefile index 46da822d3..d62dff3e3 100644 --- a/examples/platform-specific/cc26xx/very-sleepy-demo/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/Makefile @@ -1,6 +1,6 @@ CONTIKI_PROJECT = very-sleepy-demo -PLATFORMS_ONLY = srf06-cc26xx +PLATFORMS_ONLY = cc26x0-cc13x0 all: $(CONTIKI_PROJECT) diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/Makefile.target b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/Makefile.target similarity index 100% rename from examples/platform-specific/cc26xx/very-sleepy-demo/Makefile.target rename to examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/Makefile.target diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/README.md b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/README.md similarity index 100% rename from examples/platform-specific/cc26xx/very-sleepy-demo/README.md rename to examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/README.md diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/project-conf.h similarity index 100% rename from examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h rename to examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/project-conf.h diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c b/examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/very-sleepy-demo.c similarity index 100% rename from examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c rename to examples/platform-specific/cc26x0-cc13x0/very-sleepy-demo/very-sleepy-demo.c diff --git a/examples/platform-specific/cc26xx/ble-ipv6/Makefile b/examples/platform-specific/cc26xx/ble-ipv6/Makefile deleted file mode 100644 index 4ba928ad3..000000000 --- a/examples/platform-specific/cc26xx/ble-ipv6/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -CONTIKI_PROJECT=client - -all: $(CONTIKI_PROJECT) - -PLATFORMS_ONLY = srf06-cc26xx -BOARDS_ONLY = launchpad/cc2650 sensortag/cc2650 srf06/cc26xx - -MAKE_MAC = MAKE_MAC_BLE -MAKE_NET = MAKE_NET_IPV6 -CONTIKI = ../../../.. -include $(CONTIKI)/Makefile.include \ No newline at end of file diff --git a/examples/platform-specific/jn516x/tsch/common-conf-jn516x.h b/examples/platform-specific/jn516x/tsch/common-conf-jn516x.h index 568fd4b6d..32f7534e7 100644 --- a/examples/platform-specific/jn516x/tsch/common-conf-jn516x.h +++ b/examples/platform-specific/jn516x/tsch/common-conf-jn516x.h @@ -44,7 +44,7 @@ #define REST_MAX_CHUNK_SIZE 256 /* Network config */ -//#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + UIP_LLH_LEN + UIP_IPUDPH_LEN + COAP_MAX_HEADER_SIZE) +//#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + UIP_IPUDPH_LEN + COAP_MAX_HEADER_SIZE) //#define UIP_CONF_BUFFER_SIZE (REST_MAX_CHUNK_SIZE + 0 + 48 + 70) #define UIP_CONF_BUFFER_SIZE 1280 /* ipv6 required minimum */ diff --git a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c index 251b0d135..b3ef311fd 100644 --- a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c +++ b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c @@ -50,8 +50,6 @@ #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - #define INTERVAL (10) #define BLINK_TIME (CLOCK_SECOND/4) diff --git a/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c b/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c index 584f54318..9e38d5d3a 100644 --- a/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c +++ b/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c @@ -97,7 +97,6 @@ PROCESS_THREAD(er_example_server, ev, data) PRINTF("Starting Erbium Example Server\n"); PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); - PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", COAP_MAX_CHUNK_SIZE); diff --git a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c index 5f2a98e24..4b3279e44 100644 --- a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c +++ b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c @@ -45,6 +45,7 @@ #include "contiki-net.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/routing/routing.h" #include "dev/leds.h" #include "ip64/ip64.h" @@ -142,9 +143,9 @@ PT_THREAD(generate_routes(struct httpd_state *s)) #endif ADD("Neighbors
");
 
-  for(nbr = nbr_table_head(ds6_neighbors);
+  for(nbr = uip_ds6_nbr_head();
       nbr != NULL;
-      nbr = nbr_table_next(ds6_neighbors, nbr)) {
+      nbr = uip_ds6_nbr_next(nbr)) {
 
 #if WEBSERVER_CONF_NEIGHBOR_STATUS
 #if BUF_USES_STACK
diff --git a/examples/rpl-border-router/webserver/webserver.c b/examples/rpl-border-router/webserver/webserver.c
index 3658381bf..c4b472837 100644
--- a/examples/rpl-border-router/webserver/webserver.c
+++ b/examples/rpl-border-router/webserver/webserver.c
@@ -32,6 +32,7 @@
 
 #include "contiki.h"
 #include "net/routing/routing.h"
+#include "net/ipv6/uip-ds6-nbr.h"
 #include "net/ipv6/uip-ds6-route.h"
 #include "net/ipv6/uip-sr.h"
 
@@ -90,9 +91,9 @@ PT_THREAD(generate_routes(struct httpd_state *s))
 
   ADD("  Neighbors\n  
    \n"); SEND(&s->sout); - for(nbr = nbr_table_head(ds6_neighbors); + for(nbr = uip_ds6_nbr_head(); nbr != NULL; - nbr = nbr_table_next(ds6_neighbors, nbr)) { + nbr = uip_ds6_nbr_next(nbr)) { ADD("
  • "); ipaddr_add(&nbr->ipaddr); ADD("
  • \n"); diff --git a/examples/sensniff/Makefile b/examples/sensniff/Makefile index 090bc694d..3b7c5116c 100644 --- a/examples/sensniff/Makefile +++ b/examples/sensniff/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = sensniff CONTIKI = ../.. -PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul srf06-cc26xx jn516x simplelink +PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul cc26x0-cc13x0 jn516x simplelink PROJECT_SOURCEFILES += sensniff-mac.c netstack.c MODULES_REL += pool $(TARGET) diff --git a/examples/sensniff/srf06-cc26xx/target-conf.h b/examples/sensniff/cc26x0-cc13x0/target-conf.h similarity index 100% rename from examples/sensniff/srf06-cc26xx/target-conf.h rename to examples/sensniff/cc26x0-cc13x0/target-conf.h diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index a20bd8676..8ef22ff55 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -226,12 +226,11 @@ slip_radio_cmd_handler(const uint8_t *data, int len) static void slip_input_callback(void) { - LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, - uip_buf[UIP_LLH_LEN], uip_buf[UIP_LLH_LEN + 1]); - if(!cmd_input(&uip_buf[UIP_LLH_LEN], uip_len)) { + LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]); + if(!cmd_input(uip_buf, uip_len)) { cmd_send((uint8_t *)"EUnknown command", 16); } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void diff --git a/examples/storage/cfs-coffee/README.md b/examples/storage/cfs-coffee/README.md index 028f518f8..640124d56 100644 --- a/examples/storage/cfs-coffee/README.md +++ b/examples/storage/cfs-coffee/README.md @@ -23,7 +23,7 @@ Supported Hardware (tested or known to work) * cc2538dk * openmote-cc2538 * zoul -* TI srf06-cc26xx +* TI cc26x0-cc13x0 - sensortag - launchpad diff --git a/os/contiki-main.c b/os/contiki-main.c index db8893717..43e301746 100644 --- a/os/contiki-main.c +++ b/os/contiki-main.c @@ -48,6 +48,7 @@ #include "sys/stack-check.h" #include "dev/watchdog.h" +#include "net/queuebuf.h" #include "net/app-layer/coap/coap-engine.h" #include "services/rpl-border-router/rpl-border-router.h" #include "services/orchestra/orchestra.h" @@ -89,6 +90,9 @@ main(void) platform_init_stage_two(); +#if QUEUEBUF_ENABLED + queuebuf_init(); +#endif /* QUEUEBUF_ENABLED */ netstack_init(); node_id_init(); diff --git a/os/contiki-net.h b/os/contiki-net.h index 1eb50dd8d..6384c51ef 100644 --- a/os/contiki-net.h +++ b/os/contiki-net.h @@ -44,10 +44,8 @@ #include "net/ipv6/uip-nameserver.h" #include "net/routing/routing.h" -#if NETSTACK_CONF_WITH_IPV6 #include "net/ipv6/uip-icmp6.h" #include "net/ipv6/uip-ds6.h" -#endif /* NETSTACK_CONF_WITH_IPV6 */ #include "net/ipv6/resolv.h" diff --git a/os/dev/gpio-hal.h b/os/dev/gpio-hal.h index 9fe541772..5ad9f472b 100644 --- a/os/dev/gpio-hal.h +++ b/os/dev/gpio-hal.h @@ -189,7 +189,7 @@ void gpio_hal_event_handler(gpio_hal_pin_mask_t pins); * \param pin The pin * \return The corresponding mask */ -#define gpio_hal_pin_to_mask(pin) (1 << (pin)) +#define gpio_hal_pin_to_mask(pin) ((gpio_hal_pin_mask_t)1 << (pin)) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/os/dev/slip.c b/os/dev/slip.c index 3cfe9ea07..7426151c4 100644 --- a/os/dev/slip.c +++ b/os/dev/slip.c @@ -52,7 +52,7 @@ static uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; #endif /*---------------------------------------------------------------------------*/ /* Must be at least one byte larger than UIP_BUFSIZE! */ -#define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16) +#define RX_BUFSIZE (UIP_BUFSIZE + 16) /*---------------------------------------------------------------------------*/ enum { STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */ @@ -87,7 +87,7 @@ slip_set_input_callback(void (*c)(void)) void slip_send(void) { - slip_write(&uip_buf[UIP_LLH_LEN], uip_len); + slip_write(uip_buf, uip_len); } /*---------------------------------------------------------------------------*/ void @@ -252,8 +252,7 @@ PROCESS_THREAD(slip_process, ev, data) slip_active = 1; /* Move packet from rxbuf to buffer provided by uIP. */ - uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN], - UIP_BUFSIZE - UIP_LLH_LEN); + uip_len = slip_poll_handler(uip_buf, UIP_BUFSIZE); if(uip_len > 0) { if(input_callback) { diff --git a/os/net/app-layer/coap/coap-conf.h b/os/net/app-layer/coap/coap-conf.h index 911017ed8..5b610dca3 100644 --- a/os/net/app-layer/coap/coap-conf.h +++ b/os/net/app-layer/coap/coap-conf.h @@ -99,7 +99,9 @@ #endif /* COAP_MAX_OBSERVERS */ /* Interval in notifies in which NON notifies are changed to CON notifies to check client. */ -#ifndef COAP_OBSERVE_REFRESH_INTERVAL +#ifdef COAP_CONF_OBSERVE_REFRESH_INTERVAL +#define COAP_OBSERVE_REFRESH_INTERVAL COAP_CONF_OBSERVE_REFRESH_INTERVAL +#else #define COAP_OBSERVE_REFRESH_INTERVAL 20 #endif /* COAP_OBSERVE_REFRESH_INTERVAL */ diff --git a/os/net/app-layer/coap/coap-observe.c b/os/net/app-layer/coap/coap-observe.c index d6ef3887e..3574acac4 100644 --- a/os/net/app-layer/coap/coap-observe.c +++ b/os/net/app-layer/coap/coap-observe.c @@ -244,7 +244,9 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath) /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */ if((transaction = coap_new_transaction(coap_get_mid(), &obs->endpoint))) { - if(obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) { + /* if COAP_OBSERVE_REFRESH_INTERVAL is zero, never send observations as confirmable messages */ + if(COAP_OBSERVE_REFRESH_INTERVAL != 0 + && (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0)) { LOG_DBG(" Force Confirmable for\n"); notification->type = COAP_TYPE_CON; } diff --git a/os/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index e2be92326..8109db20e 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -70,21 +70,13 @@ #endif /* WITH_DTLS */ /* sanity check for configured values */ -#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPH_LEN - UIP_UDPH_LEN) +#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_IPH_LEN - UIP_UDPH_LEN) #error "UIP_CONF_BUFFER_SIZE too small for COAP_MAX_CHUNK_SIZE" #endif #define SERVER_LISTEN_PORT UIP_HTONS(COAP_DEFAULT_PORT) #define SERVER_LISTEN_SECURE_PORT UIP_HTONS(COAP_DEFAULT_SECURE_PORT) -/* direct access into the buffer */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#if NETSTACK_CONF_WITH_IPV6 -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#else -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#endif - #ifdef WITH_DTLS static dtls_handler_t cb; static dtls_context_t *dtls_context = NULL; diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index 5b6f1b863..169064b25 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -103,26 +103,18 @@ static struct uip_udp_conn *c; static uip_ipaddr_t src_ip; static uip_ipaddr_t des_ip; /*---------------------------------------------------------------------------*/ -/* uIPv6 Pointers */ -/*---------------------------------------------------------------------------*/ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -/*---------------------------------------------------------------------------*/ /* Local function prototypes */ /*---------------------------------------------------------------------------*/ static void icmp_input(void); static void icmp_output(void); static void mcast_fwd(void *p); -int remove_ext_hdr(void); /*---------------------------------------------------------------------------*/ /* Internal Data Structures */ /*---------------------------------------------------------------------------*/ struct multicast_on_behalf{ /* ICMP message of multicast_on_behalf */ uint16_t mcast_port; uip_ipaddr_t mcast_ip; - uint8_t mcast_payload[UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN]; + uint8_t mcast_payload[UIP_BUFSIZE - UIP_IPUDPH_LEN]; }; #define UIP_ICMP_MOB 18 /* Size of multicast_on_behalf ICMP header */ /*---------------------------------------------------------------------------*/ @@ -143,7 +135,7 @@ icmp_output() struct multicast_on_behalf *mob; mob = (struct multicast_on_behalf *)UIP_ICMP_PAYLOAD; - memcpy(&mob->mcast_payload, &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], uip_slen); + memcpy(&mob->mcast_payload, &uip_buf[UIP_IPUDPH_LEN], uip_slen); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; @@ -164,8 +156,7 @@ icmp_output() PRINT6ADDR(&UIP_IP_BUF->destipaddr); PRINTF("\n"); - UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8; - UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + payload_len); UIP_ICMP_BUF->type = ICMP6_ESMRF; UIP_ICMP_BUF->icode = ESMRF_ICMP_CODE; @@ -199,7 +190,7 @@ icmp_input() } #endif - remove_ext_hdr(); + uip_remove_ext_hdr(); PRINTF("ESMRF: ICMPv6 In from "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); @@ -210,11 +201,11 @@ icmp_input() VERBOSE_PRINTF("ESMRF: ICMPv6 In, parse from %p to %p\n", UIP_ICMP_PAYLOAD, (uint8_t *)UIP_ICMP_PAYLOAD + uip_len - - uip_l2_l3_icmp_hdr_len); + uip_l3_icmp_hdr_len); locmobptr = (struct multicast_on_behalf *) UIP_ICMP_PAYLOAD; - loclen = uip_len - (uip_l2_l3_icmp_hdr_len + UIP_ICMP_MOB); + loclen = uip_len - (uip_l3_icmp_hdr_len + UIP_ICMP_MOB); uip_ipaddr_copy(&src_ip, &UIP_IP_BUF->srcipaddr); uip_ipaddr_copy(&des_ip, &UIP_IP_BUF->destipaddr); @@ -224,13 +215,13 @@ icmp_input() c->rport = locmobptr->mcast_port; uip_slen = loclen; uip_udp_conn=c; - memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], locmobptr->mcast_payload, - loclen > UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN? - UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN: loclen); + memcpy(&uip_buf[UIP_IPUDPH_LEN], locmobptr->mcast_payload, + loclen > UIP_BUFSIZE - UIP_IPUDPH_LEN? + UIP_BUFSIZE - UIP_IPUDPH_LEN: loclen); uip_process(UIP_UDP_SEND_CONN); - memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len); + memcpy(&mcast_buf, uip_buf, uip_len); mcast_len = uip_len; /* pass the packet to our uip_process to check if it is allowed to * accept this packet or not */ @@ -240,7 +231,7 @@ icmp_input() uip_process(UIP_DATA); - memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len); + memcpy(uip_buf, &mcast_buf, mcast_len); uip_len = mcast_len; /* Return the IP of the original Multicast sender */ uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &src_ip); @@ -252,17 +243,17 @@ icmp_input() /* If we enter here, we will definitely forward */ tcpip_ipv6_output(); } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void mcast_fwd(void *p) { - memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len); + memcpy(uip_buf, &mcast_buf, mcast_len); uip_len = mcast_len; UIP_IP_BUF->ttl--; tcpip_output(NULL); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -352,7 +343,7 @@ in() fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread)); } - memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len); + memcpy(&mcast_buf, uip_buf, uip_len); mcast_len = uip_len; ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL); } diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 1d19512d6..909ebbfb6 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -276,7 +276,7 @@ struct mcast_packet { uint16_t seq_val; /* host-byte order */ struct sliding_window *sw; /* Pointer to the SW this packet belongs to */ uint8_t flags; /* Is-Used, Must Send, Is Listed */ - uint8_t buff[UIP_BUFSIZE - UIP_LLH_LEN]; + uint8_t buff[UIP_BUFSIZE]; }; /* Flag bits */ @@ -289,7 +289,7 @@ struct mcast_packet { #define MCAST_PACKET_GET_SEED(p) ((seed_id_t *)&((p)->seed_id)) #else #define MCAST_PACKET_GET_SEED(p) \ - ((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[UIP_LLH_LEN])->srcipaddr) + ((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[0])->srcipaddr) #endif /** @@ -456,14 +456,9 @@ static uint16_t last_seq; /*---------------------------------------------------------------------------*/ /* uIPv6 Pointers */ /*---------------------------------------------------------------------------*/ -#define UIP_DATA_BUF ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#define UIP_EXT_BUF_NEXT ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN]) -#define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2]) -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) +#define UIP_EXT_BUF ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(0)) +#define UIP_EXT_BUF_NEXT ((uint8_t *)(UIP_IP_PAYLOAD(HBHO_TOTAL_LEN))) +#define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)(UIP_IP_PAYLOAD(0) + 2)) extern uint16_t uip_slen; /*---------------------------------------------------------------------------*/ /* Local function prototypes */ @@ -864,8 +859,7 @@ icmp_output() roll_tm_create_dest(&UIP_IP_BUF->destipaddr); uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr); - UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8; - UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + payload_len); UIP_ICMP_BUF->type = ICMP6_ROLL_TM; UIP_ICMP_BUF->icode = ROLL_TM_ICMP_CODE; @@ -1153,10 +1147,10 @@ icmp_input() VERBOSE_PRINTF("ROLL TM: ICMPv6 In, parse from %p to %p\n", UIP_ICMP_PAYLOAD, (uint8_t *)UIP_ICMP_PAYLOAD + uip_len - - uip_l2_l3_icmp_hdr_len); + uip_l3_icmp_hdr_len); while(locslhptr < (struct sequence_list_header *)((uint8_t *)UIP_ICMP_PAYLOAD + - uip_len - uip_l2_l3_icmp_hdr_len)) { + uip_len - uip_l3_icmp_hdr_len)) { VERBOSE_PRINTF("ROLL TM: ICMPv6 In, seq hdr @ %p\n", locslhptr); if((locslhptr->flags & SEQUENCE_LIST_RES) != 0) { @@ -1321,7 +1315,7 @@ static void out() { - if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { + if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE) { PRINTF("ROLL TM: Multicast Out can not add HBHO. Packet too long\n"); goto drop; } @@ -1355,13 +1349,11 @@ out() HBH_SET_M(lochbhmptr); #endif - uip_ext_len += HBHO_TOTAL_LEN; - uip_len += HBHO_TOTAL_LEN; + uipbuf_add_ext_hdr(HBHO_TOTAL_LEN); /* Update the proto and length field in the v6 header */ UIP_IP_BUF->proto = UIP_PROTO_HBHO; - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); PRINTF("ROLL TM: Multicast Out, HBHO: T=%u, L=%u, M=%u, S=0x%02x%02x\n", lochbhmptr->type, lochbhmptr->len, HBH_GET_M(lochbhmptr), @@ -1383,7 +1375,7 @@ out() drop: uip_slen = 0; - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static uint8_t diff --git a/os/net/ipv6/multicast/smrf.c b/os/net/ipv6/multicast/smrf.c index 86a053648..dd24968ba 100644 --- a/os/net/ipv6/multicast/smrf.c +++ b/os/net/ipv6/multicast/smrf.c @@ -77,18 +77,14 @@ static uip_buf_t mcast_buf; static uint8_t fwd_delay; static uint8_t fwd_spread; /*---------------------------------------------------------------------------*/ -/* uIPv6 Pointers */ -/*---------------------------------------------------------------------------*/ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -/*---------------------------------------------------------------------------*/ static void mcast_fwd(void *p) { - memcpy(&uip_buf[UIP_LLH_LEN], &mcast_buf, mcast_len); + memcpy(uip_buf, &mcast_buf, mcast_len); uip_len = mcast_len; UIP_IP_BUF->ttl--; tcpip_output(NULL); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -178,7 +174,7 @@ in() fwd_delay = fwd_delay * (1 + ((random_rand() >> 11) % fwd_spread)); } - memcpy(&mcast_buf, &uip_buf[UIP_LLH_LEN], uip_len); + memcpy(&mcast_buf, uip_buf, uip_len); mcast_len = uip_len; ctimer_set(&mcast_periodic, fwd_delay, mcast_fwd, NULL); } diff --git a/os/net/ipv6/resolv.c b/os/net/ipv6/resolv.c index 2bcd3983b..29af2b4cf 100644 --- a/os/net/ipv6/resolv.c +++ b/os/net/ipv6/resolv.c @@ -116,8 +116,6 @@ int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t n); #endif /* __SDCC */ -#define UIP_UDP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - /* If RESOLV_CONF_SUPPORTS_MDNS is set, then queries * for domain names in the local TLD will use mDNS as * described by draft-cheshire-dnsext-multicastdns. @@ -837,7 +835,7 @@ newdata(void) } else { uip_udp_packet_sendto(resolv_conn, uip_appdata, mdns_prep_host_announce_packet(), - &UIP_UDP_BUF->srcipaddr, + &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport); } return; diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 90ec7d2d8..e2ffc24fd 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -121,12 +121,8 @@ #define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN]) #define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN]) - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_UDP_BUF(p) ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN + p]) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLIPH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN]) -#define UIP_IPPAYLOAD_BUF(pos) (&uip_buf[UIP_LLIPH_LEN + pos]) +#define UIP_IPPAYLOAD_BUF_POS(pos) (&uip_buf[UIP_IPH_LEN + (pos)]) +#define UIP_UDP_BUF_POS(pos) ((struct uip_udp_hdr *)UIP_IPPAYLOAD_BUF_POS(pos)) /** @} */ @@ -448,9 +444,9 @@ set_packet_attrs(void) /* assign values to the channel attribute (port or type + code) */ if(UIP_IP_BUF->proto == UIP_PROTO_UDP) { - c = UIP_UDP_BUF(0)->srcport; - if(UIP_UDP_BUF(0)->destport < c) { - c = UIP_UDP_BUF(0)->destport; + c = UIP_UDP_BUF_POS(0)->srcport; + if(UIP_UDP_BUF_POS(0)->destport < c) { + c = UIP_UDP_BUF_POS(0)->destport; } } else if(UIP_IP_BUF->proto == UIP_PROTO_TCP) { c = UIP_TCP_BUF->srcport; @@ -901,7 +897,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* Handle the header here! */ { struct uip_ext_hdr *ext_hdr = - (struct uip_ext_hdr *) UIP_IPPAYLOAD_BUF(ext_hdr_len); + (struct uip_ext_hdr *) UIP_IPPAYLOAD_BUF_POS(ext_hdr_len); int len; proto = proto == -1 ? SICSLOWPAN_NHC_ETX_HDR_DESTO : proto; /* Len is defined to be in octets from the length byte */ @@ -940,7 +936,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) case UIP_PROTO_UDP: /* allocate a byte for the next header posision as UDP has no next */ hc06_ptr++; - udp_buf = UIP_UDP_BUF(ext_hdr_len); + udp_buf = UIP_UDP_BUF_POS(ext_hdr_len); LOG_DBG("compression: inlined UDP ports on send side: %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); /* Mask out the last 4 bits can be used as a mask */ @@ -1921,12 +1917,12 @@ input(void) /* Sanity-check size of incoming packet to avoid buffer overflow */ { - int req_size = UIP_LLH_LEN + uncomp_hdr_len + (uint16_t)(frag_offset << 3) + int req_size = uncomp_hdr_len + (uint16_t)(frag_offset << 3) + packetbuf_payload_len; if(req_size > sizeof(uip_buf)) { LOG_ERR( - "input: packet dropped, minimum required IP_BUF size: %d+%d+%d+%d=%d (current size: %u)\n", - UIP_LLH_LEN, uncomp_hdr_len, (uint16_t)(frag_offset << 3), + "input: packet dropped, minimum required IP_BUF size: %d+%d+%d=%d (current size: %u)\n", + uncomp_hdr_len, (uint16_t)(frag_offset << 3), packetbuf_payload_len, req_size, (unsigned)sizeof(uip_buf)); return; } @@ -2059,11 +2055,6 @@ sicslowpan_init(void) #endif /* SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS > 1 */ #endif /* SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_IPHC */ - - /* We use the queuebuf module if fragmentation is enabled */ -#if SICSLOWPAN_CONF_FRAG - queuebuf_init(); -#endif } /*--------------------------------------------------------------------*/ int diff --git a/os/net/ipv6/simple-udp.c b/os/net/ipv6/simple-udp.c index c98107c99..08986d827 100644 --- a/os/net/ipv6/simple-udp.c +++ b/os/net/ipv6/simple-udp.c @@ -52,8 +52,6 @@ PROCESS(simple_udp_process, "Simple UDP process"); static uint8_t started = 0; static uint8_t databuffer[UIP_BUFSIZE]; -#define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - /*---------------------------------------------------------------------------*/ static void init_simple_udp(void) @@ -134,7 +132,7 @@ PROCESS_THREAD(simple_udp_process, ev, data) { struct simple_udp_connection *c; PROCESS_BEGIN(); - + while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { @@ -165,9 +163,9 @@ PROCESS_THREAD(simple_udp_process, ev, data) PROCESS_CONTEXT_BEGIN(c->client_process); c->receive_callback(c, &(UIP_IP_BUF->srcipaddr), - UIP_HTONS(UIP_IP_BUF->srcport), + UIP_HTONS(UIP_UDP_BUF->srcport), &(UIP_IP_BUF->destipaddr), - UIP_HTONS(UIP_IP_BUF->destport), + UIP_HTONS(UIP_UDP_BUF->destport), databuffer, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 8d546c1d7..16176e6e2 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -55,10 +55,6 @@ #define LOG_MODULE "TCP/IP" #define LOG_LEVEL LOG_LEVEL_TCPIP -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len]) -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) - #ifdef UIP_FALLBACK_INTERFACE extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE; #endif @@ -129,7 +125,7 @@ tcpip_output(const uip_lladdr_t *a) return ret; } else { /* Ok, ignore and drop... */ - uip_clear_buf(); + uipbuf_clear(); return 0; } } @@ -452,18 +448,16 @@ tcpip_input(void) NETSTACK_IP_PROCESS) { process_post_synch(&tcpip_process, PACKET_INPUT, NULL); } /* else - do nothing and drop */ - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ -extern void remove_ext_hdr(void); -/*---------------------------------------------------------------------------*/ static void output_fallback(void) { #ifdef UIP_FALLBACK_INTERFACE LOG_INFO("fallback: removing ext hdrs & setting proto %d %d\n", uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40)); - remove_ext_hdr(); + uip_remove_ext_hdr(); /* Inform the other end that the destination is not reachable. If it's * not informed routes might get lost unexpectedly until there's a need * to send a new packet to the peer */ @@ -658,7 +652,7 @@ tcpip_ipv6_output(void) if(!NETSTACK_ROUTING.ext_header_update()) { /* Packet can not be forwarded */ LOG_ERR("output: routing protocol extension header update error\n"); - uip_clear_buf(); + uipbuf_clear(); return; } @@ -746,7 +740,7 @@ send_packet: } exit: - uip_clear_buf(); + uipbuf_clear(); return; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/udp-socket.c b/os/net/ipv6/udp-socket.c index 700306ca1..f104a6b6c 100644 --- a/os/net/ipv6/udp-socket.c +++ b/os/net/ipv6/udp-socket.c @@ -38,9 +38,6 @@ PROCESS(udp_socket_process, "UDP socket process"); static uint8_t buf[UIP_BUFSIZE]; -#define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - - /*---------------------------------------------------------------------------*/ static void init(void) @@ -182,9 +179,9 @@ PROCESS_THREAD(udp_socket_process, ev, data) PROCESS_CONTEXT_BEGIN(c->p); c->input_callback(c, c->ptr, &(UIP_IP_BUF->srcipaddr), - UIP_HTONS(UIP_IP_BUF->srcport), + UIP_HTONS(UIP_UDP_BUF->srcport), &(UIP_IP_BUF->destipaddr), - UIP_HTONS(UIP_IP_BUF->destport), + UIP_HTONS(UIP_UDP_BUF->destport), buf, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index f937986b5..b8f8b63d7 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -55,19 +55,67 @@ #include "net/ipv6/uip-nd6.h" #include "net/routing/routing.h" +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +#include "lib/memb.h" +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 -NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors); +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/** + * Add nbr to the list in nbr_entry. In other words, this function associates an + * IPv6 address in nbr with a link-layer address in nbr_entry. + * \param nbr the neighbor cache entry for an IPv6 address + * \param nbr_entry the nbr_table entry for an link-layer address + */ +static void add_uip_ds6_nbr_to_nbr_entry(uip_ds6_nbr_t *nbr, + uip_ds6_nbr_entry_t *nbr_entry); + +/** + * Remove nbr from the list of the corresponding nbr_entry + * \param nbr a neighbor cache entry (nbr) to be removed + */ +static void remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr); + +/** + * Remove nbr_etnry from nbr_table + * \param nbr_entry a nbr_table entry (nbr_entry) to be removed + */ +static void remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry); + +/** + * Free memory for a specified neighbor cache entry + * \param nbr a neighbor cache entry to be freed + */ +static void free_uip_ds6_nbr(uip_ds6_nbr_t *nbr); + +/** + * Callback function called when a nbr_table entry is removed + * \param nbr_entry a nbr_entry to be removed + */ +static void callback_nbr_entry_removal(uip_ds6_nbr_entry_t *nbr_entry); + +NBR_TABLE(uip_ds6_nbr_entry_t, uip_ds6_nbr_entries); +MEMB(uip_ds6_nbr_memb, uip_ds6_nbr_t, UIP_DS6_NBR_MAX_NEIGHBOR_CACHES); +#else +NBR_TABLE(uip_ds6_nbr_t, ds6_neighbors); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ /*---------------------------------------------------------------------------*/ void uip_ds6_neighbors_init(void) { link_stats_init(); +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + memb_init(&uip_ds6_nbr_memb); + nbr_table_register(uip_ds6_nbr_entries, + (nbr_table_callback *)callback_nbr_entry_removal); +#else nbr_table_register(ds6_neighbors, (nbr_table_callback *)uip_ds6_nbr_rm); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * @@ -75,8 +123,63 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data) { - uip_ds6_nbr_t *nbr = nbr_table_add_lladdr(ds6_neighbors, (linkaddr_t*)lladdr - , reason, data); + uip_ds6_nbr_t *nbr; + +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + + assert(uip_ds6_nbr_lookup(ipaddr) == NULL); + if(uip_ds6_nbr_lookup(ipaddr)) { + LOG_ERR("%s: uip_ds6_nbr for ", __func__); + LOG_ERR_6ADDR(ipaddr); + LOG_ERR_("has already existed\n"); + return NULL; + } + + /* firstly, allocate memory for a new nbr cache entry */ + if((nbr = (uip_ds6_nbr_t *)memb_alloc(&uip_ds6_nbr_memb)) == NULL) { + LOG_ERR("%s: cannot allocate a new uip_ds6_nbr\n", __func__); + return NULL; + } + + /* secondly, get or allocate nbr_entry for the link-layer address */ + nbr_entry = nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t *)lladdr); + if(nbr_entry == NULL) { + if((nbr_entry = + nbr_table_add_lladdr(uip_ds6_nbr_entries, + (linkaddr_t*)lladdr, reason, data)) == NULL) { + LOG_ERR("%s: cannot allocate a new uip_ds6_nbr_entry\n", __func__); + /* return from this function later */ + } else { + LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); + } + } + + /* free nbr and return if nbr_entry is not available */ + if((nbr_entry == NULL) || + (list_length(nbr_entry->uip_ds6_nbrs) == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR)) { + if(list_length(nbr_entry->uip_ds6_nbrs) == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* + * it's already had the maximum number of IPv6 addresses; cannot + * add another. + */ + LOG_ERR("%s: no room in nbr_entry for ", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)lladdr); + LOG_ERR_("\n"); + } + /* free the newly allocated memory in this function call */ + memb_free(&uip_ds6_nbr_memb, nbr); + return NULL; + } else { + /* everything is fine; nbr is ready to be used */ + /* it has room to add another IPv6 address */ + add_uip_ds6_nbr_to_nbr_entry(nbr, nbr_entry); + } +#else + nbr = nbr_table_add_lladdr(ds6_neighbors, (linkaddr_t*)lladdr, reason, data); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + if(nbr) { uip_ipaddr_copy(&nbr->ipaddr, ipaddr); #if UIP_ND6_SEND_RA || !UIP_CONF_ROUTER @@ -113,10 +216,91 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, } } +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/*---------------------------------------------------------------------------*/ +static void +add_uip_ds6_nbr_to_nbr_entry(uip_ds6_nbr_t *nbr, + uip_ds6_nbr_entry_t *nbr_entry) +{ + LOG_DBG("%s: add nbr(%p) to nbr_entry (%p)\n", + __func__, nbr, nbr_entry); + nbr->nbr_entry = nbr_entry; + list_add(nbr_entry->uip_ds6_nbrs, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr) +{ + if(nbr == NULL) { + return; + } + LOG_DBG("%s: remove nbr(%p) from nbr_entry (%p)\n", + __func__, nbr, nbr->nbr_entry); + list_remove(nbr->nbr_entry->uip_ds6_nbrs, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry) +{ + if(nbr_entry == NULL) { + return; + } + LOG_DBG("%s: remove nbr_entry (%p) from nbr_table\n", + __func__, nbr_entry); + (void)nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); +} +/*---------------------------------------------------------------------------*/ +static void +free_uip_ds6_nbr(uip_ds6_nbr_t *nbr) +{ + if(nbr == NULL) { + return; + } +#if UIP_CONF_IPV6_QUEUE_PKT + uip_packetqueue_free(&nbr->packethandle); +#endif /* UIP_CONF_IPV6_QUEUE_PKT */ + NETSTACK_ROUTING.neighbor_state_changed(nbr); + assert(nbr->nbr_entry != NULL); + if(nbr->nbr_entry == NULL) { + LOG_ERR("%s: unexpected error nbr->nbr_entry is NULL\n", __func__); + } else { + remove_uip_ds6_nbr_from_nbr_entry(nbr); + if(list_length(nbr->nbr_entry->uip_ds6_nbrs) == 0) { + remove_nbr_entry(nbr->nbr_entry); + } + } + LOG_DBG("%s: free memory for nbr(%p)\n", __func__, nbr); + memb_free(&uip_ds6_nbr_memb, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +callback_nbr_entry_removal(uip_ds6_nbr_entry_t *nbr_entry) +{ + uip_ds6_nbr_t *nbr; + uip_ds6_nbr_t *next_nbr; + if(nbr_entry == NULL) { + return; + } + for(nbr = (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + nbr != NULL; + nbr = next_nbr) { + next_nbr = (uip_ds6_nbr_t *)list_item_next(nbr); + free_uip_ds6_nbr(nbr); + } +} +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + if(nbr == NULL) { + return 0; + } else { + free_uip_ds6_nbr(nbr); + return 1; + } +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ if(nbr != NULL) { #if UIP_CONF_IPV6_QUEUE_PKT uip_packetqueue_free(&nbr->packethandle); @@ -125,19 +309,52 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) return nbr_table_remove(ds6_neighbors, nbr); } return 0; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + uip_ds6_nbr_t *nbr; +#else uip_ds6_nbr_t nbr_backup; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ if(nbr_pp == NULL || new_ll_addr == NULL) { LOG_ERR("%s: invalid argument\n", __func__); return -1; } +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + + if((nbr_entry = + nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t *)new_ll_addr)) == NULL) { + if((nbr_entry = + nbr_table_add_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t*)new_ll_addr, + NBR_TABLE_REASON_IPV6_ND, NULL)) == NULL) { + LOG_ERR("%s: cannot allocate a nbr_entry for", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)new_ll_addr); + return -1; + } else { + LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); + } + } + + nbr = *nbr_pp; + + remove_uip_ds6_nbr_from_nbr_entry(nbr); + if(list_length(nbr->nbr_entry->uip_ds6_nbrs) == 0) { + remove_nbr_entry(nbr->nbr_entry); + } + add_uip_ds6_nbr_to_nbr_entry(nbr, nbr_entry); + +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /* make sure new_ll_addr is not used in some other nbr */ if(uip_ds6_nbr_ll_lookup(new_ll_addr) != NULL) { LOG_ERR("%s: new_ll_addr, ", __func__); @@ -159,6 +376,7 @@ uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr) return -1; } memcpy(*nbr_pp, &nbr_backup, sizeof(uip_ds6_nbr_t)); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ return 0; } @@ -173,46 +391,88 @@ uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr) const uip_lladdr_t * uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + if(nbr == NULL) { + return NULL; + } + return (const uip_lladdr_t *)nbr_table_get_lladdr(uip_ds6_nbr_entries, + nbr->nbr_entry); +#else return (const uip_lladdr_t *)nbr_table_get_lladdr(ds6_neighbors, nbr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_num(void) { - uip_ds6_nbr_t *nbr; - int num; + int num = 0; - num = 0; +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + for(nbr_entry = nbr_table_head(uip_ds6_nbr_entries); + nbr_entry != NULL; + nbr_entry = nbr_table_next(uip_ds6_nbr_entries, nbr_entry)) { + num += list_length(nbr_entry->uip_ds6_nbrs); + } +#else + uip_ds6_nbr_t *nbr; for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) { num++; } +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ return num; } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_head(void) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if((nbr_entry = nbr_table_head(uip_ds6_nbr_entries)) == NULL) { + return NULL; + } + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); +#else return nbr_table_head(ds6_neighbors); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_next(uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if(nbr == NULL) { + return NULL; + } + if(list_item_next(nbr) != NULL) { + return list_item_next(nbr); + } + nbr_entry = nbr_table_next(uip_ds6_nbr_entries, nbr->nbr_entry); + if(nbr_entry == NULL) { + return NULL; + } else { + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + } +#else return nbr_table_next(ds6_neighbors, nbr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); - if(ipaddr != NULL) { - while(nbr != NULL) { - if(uip_ipaddr_cmp(&nbr->ipaddr, ipaddr)) { - return nbr; - } - nbr = nbr_table_next(ds6_neighbors, nbr); + uip_ds6_nbr_t *nbr; + if(ipaddr == NULL) { + return NULL; + } + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = uip_ds6_nbr_next(nbr)) { + if(uip_ipaddr_cmp(&nbr->ipaddr, ipaddr)) { + return nbr; } } return NULL; @@ -221,7 +481,23 @@ uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t * uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + /* + * we cannot determine which entry should return by lladdr alone; + * return the first entry associated with lladdr. + */ + nbr_entry = + (uip_ds6_nbr_entry_t *)nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (linkaddr_t*)lladdr); + if(nbr_entry == NULL) { + return NULL; + } + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); +#else return nbr_table_get_from_lladdr(ds6_neighbors, (linkaddr_t*)lladdr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ @@ -239,6 +515,20 @@ uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t *nbr = uip_ds6_nbr_lookup(ipaddr); return nbr ? uip_ds6_nbr_get_ll(nbr) : NULL; } +#if UIP_DS6_LL_NUD +/*---------------------------------------------------------------------------*/ +static void +update_nbr_reachable_state_by_ack(uip_ds6_nbr_t *nbr, const linkaddr_t *lladdr) +{ + if(nbr != NULL && nbr->state != NBR_INCOMPLETE) { + nbr->state = NBR_REACHABLE; + stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); + LOG_INFO("received a link layer ACK : "); + LOG_INFO_LLADDR(lladdr); + LOG_INFO_(" is reachable.\n"); + } +} +#endif /* UIP_DS6_LL_NUD */ /*---------------------------------------------------------------------------*/ void uip_ds6_link_callback(int status, int numtx) @@ -266,14 +556,22 @@ uip_ds6_link_callback(int status, int numtx) * acknowledges link packets. */ if(status == MAC_TX_OK) { uip_ds6_nbr_t *nbr; - nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest); - if(nbr != NULL && nbr->state != NBR_INCOMPLETE) { - nbr->state = NBR_REACHABLE; - stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); - LOG_INFO("received a link layer ACK : "); - LOG_INFO_LLADDR((uip_lladdr_t *)dest); - LOG_INFO_(" is reachable.\n"); +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if((nbr_entry = + (uip_ds6_nbr_entry_t *)nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + dest)) == NULL) { + return; } + for(nbr = (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + nbr != NULL; + nbr = (uip_ds6_nbr_t *)list_item_next(nbr)) { + update_nbr_reachable_state_by_ack(nbr, dest); + } +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest); + update_nbr_reachable_state_by_ack(nbr, dest); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } #endif /* UIP_DS6_LL_NUD */ } @@ -283,7 +581,7 @@ uip_ds6_link_callback(int status, int numtx) void uip_ds6_neighbor_periodic(void) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); + uip_ds6_nbr_t *nbr = uip_ds6_nbr_head(); while(nbr != NULL) { switch(nbr->state) { case NBR_REACHABLE: @@ -354,7 +652,7 @@ uip_ds6_neighbor_periodic(void) default: break; } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); } } /*---------------------------------------------------------------------------*/ @@ -373,7 +671,7 @@ uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t * uip_ds6_get_least_lifetime_neighbor(void) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); + uip_ds6_nbr_t *nbr = uip_ds6_nbr_head(); uip_ds6_nbr_t *nbr_expiring = NULL; while(nbr != NULL) { if(nbr_expiring != NULL) { @@ -384,7 +682,7 @@ uip_ds6_get_least_lifetime_neighbor(void) } else { nbr_expiring = nbr; } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); } return nbr_expiring; } diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index d645ac627..6479c972e 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -54,6 +54,10 @@ #if UIP_CONF_IPV6_QUEUE_PKT #include "net/ipv6/uip-packetqueue.h" #endif /*UIP_CONF_QUEUE_PKT */ +#if UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#include "lib/assert.h" +#include "lib/list.h" +#endif /*--------------------------------------------------*/ /** \brief Possible states for the nbr cache entries */ @@ -63,10 +67,46 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 -NBR_TABLE_DECLARE(ds6_neighbors); +/** \brief Set non-zero (1) to enable multiple IPv6 addresses to be + * associated with a link-layer address */ +#ifdef UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#define UIP_DS6_NBR_MULTI_IPV6_ADDRS UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#else +#define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0 +#endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */ -/** \brief An entry in the nbr cache */ +/** \brief Set the maximum number of IPv6 addresses per link-layer + * address */ +#ifdef UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR +#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR +#else +#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR 2 +#endif /* UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR */ + +/** \brief Set the maximum number of neighbor cache entries */ +#ifdef UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES +#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES +#else +#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES \ + (NBR_TABLE_MAX_NEIGHBORS * UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) +#endif /* UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES */ + +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/** \brief nbr_table entry when UIP_DS6_NBR_MULTI_IPV6_ADDRS is + * enabled. uip_ds6_nbrs is a list of uip_ds6_nbr_t objects */ +typedef struct { + LIST_STRUCT(uip_ds6_nbrs); +} uip_ds6_nbr_entry_t; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + +/** \brief The default nbr_table entry (when + * UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr + * cache */ typedef struct uip_ds6_nbr { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + struct uip_ds6_nbr *next; + uip_ds6_nbr_entry_t *nbr_entry; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ uip_ipaddr_t ipaddr; uint8_t isrouter; uint8_t state; @@ -83,25 +123,119 @@ typedef struct uip_ds6_nbr { void uip_ds6_neighbors_init(void); -/** \brief Neighbor Cache basic routines */ +/** + * Add a neighbor cache for a specified IPv6 address, which is + * associated with a specified link-layer address + * \param ipaddr IPv6 address of a neighbor to add + * \param lladdr Link-layer address to associate with ipaddr + * \param isrouter Set 1 if the neighbor is a router + * \param state Set the initial neighbor cache state (e.g., + * NBR_INCOMPLETE) + * \param reason Set a reason of the addition (e.g., + * NBR_TABLE_REASON_RPL_DIO) + * \param data Set data associated with the nbr cache + * \return the address of a newly added nbr cache on success, NULL on + * failure +*/ uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data); + +/** + * Remove a neighbor cache + * \param nbr the address of a neighbor cache to remove + * \return 1 on success, 0 on failure (nothing was removed) + */ int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr); + +/** + * Get the link-layer address associated with a specified nbr cache + * \param nbr the address of a neighbor cache + * \return pointer to the link-layer address on success, NULL on failure + */ const uip_lladdr_t *uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr); -int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr); -const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr); -uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr); -uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr); -uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr); + +/** + * Get the link-layer address associated with a specified IPv6 address + * \param ipaddr an IPv6 address used as a search key + * \return the pointer to the link-layer address on success, NULL on failure + */ const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr); -void uip_ds6_link_callback(int status, int numtx); -void uip_ds6_neighbor_periodic(void); + +/** + * Update the link-layer address associated with an IPv6 address + * \param nbr the double pointer to a neighbor cache which has the + * target IPv6 address + * \param new_ll_addr the new link-layer address of the IPv6 address + * return 0 on success, -1 on failure + */ +int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr); + +/** + * Get an IPv6 address of a neighbor cache + * \param nbr the pointer to a neighbor cache + * \return the pointer to an IPv6 address associated with the neighbor cache + * \note This returns the first IPv6 address found in the neighbor + * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled + */ +const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr); + +/** + * Get an IPv6 address associated with a specified link-layer address + * \param lladdr a link-layer address used as a search key + * \return the pointer to an IPv6 address associated with the neighbor cache + * \note This returns the first IPv6 address found in the neighbor + * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled + */ +uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr); + +/** + * Get the neighbor cache associated with a specified IPv6 address + * \param ipaddr an IPv6 address used as a search key + * \return the pointer to a neighbor cache on success, NULL on failure + */ +uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr); + +/** + * Get the neighbor cache associated with a specified link-layer address + * \param lladdr a link-layer address used as a search key + * \return the pointer to a neighbor cache on success, NULL on failure + */ +uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr); + +/** + * Return the number of neighbor caches + * \return the number of neighbor caches in use + */ int uip_ds6_nbr_num(void); + +/** + * Get the first neighbor cache in nbr_table + * \return the pointer to the first neighbor cache entry + */ uip_ds6_nbr_t *uip_ds6_nbr_head(void); + +/** + * Get the next neighbor cache of a specified one + * \param nbr the pointer to a neighbor cache + * \return the pointer to the next one on success, NULL on failure + */ uip_ds6_nbr_t *uip_ds6_nbr_next(uip_ds6_nbr_t *nbr); +/** + * The callback function to update link-layer stats in a neighbor + * cache + * \param status MAC return value defined in mac.h + * \param numtx the number of transmissions happened for a packet + */ +void uip_ds6_link_callback(int status, int numtx); + +/** + * The housekeeping function called periodically + */ +void uip_ds6_neighbor_periodic(void); + #if UIP_ND6_SEND_NS /** * \brief Refresh the reachable state of a neighbor. This function diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 707a13309..18dcef89c 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -53,11 +53,7 @@ #define LOG_MODULE "ICMPv6" #define LOG_LEVEL LOG_LEVEL_IPV6 -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN]) +#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD) /** \brief temporary IP address */ static uip_ipaddr_t tmp_ipaddr; @@ -134,22 +130,7 @@ echo_request_input(void) uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &tmp_ipaddr); } - if(uip_ext_len > 0) { - /* Remove extension headers if any */ - UIP_IP_BUF->proto = UIP_PROTO_ICMP6; - uip_len -= uip_ext_len; - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); - /* move the echo request payload (starting after the icmp header) - * to the new location in the reply. - * The shift is equal to the length of the extension headers present - * Note: UIP_ICMP_BUF still points to the echo request at this stage - */ - memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len, - (uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN, - (uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN)); - uip_ext_len = 0; - } + uip_remove_ext_hdr(); /* Below is important for the correctness of UIP_ICMP_BUF and the * checksum @@ -173,47 +154,38 @@ echo_request_input(void) void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { /* check if originating packet is not an ICMP error */ - if(uip_ext_len) { - if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { - uip_clear_buf(); - return; - } - } else { - if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { - uip_clear_buf(); - return; - } + uint16_t shift; + if(uip_last_proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { + uipbuf_clear(); + return; } - /* Remove all extension headers related to the routing protocol in place */ + /* Remove all extension headers related to the routing protocol in place. + * Keep all other extension headers, so as to match original packet. */ NETSTACK_ROUTING.ext_header_remove(); /* remember data of original packet before shifting */ uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr); - uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN; - - if(uip_len > UIP_LINK_MTU) { - uip_len = UIP_LINK_MTU; - } - - memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN, - (void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN); + /* The ICMPv6 error message contains as much of possible of the invoking packet + * (see RFC 4443 section 3). Make space for the additional IPv6 and + * ICMPv6 headers here and move payload to the "right". What we move includes + * extension headers */ + shift = UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ICMP6_ERROR_LEN; + uip_len += shift; + uip_len = MIN(uip_len, UIP_LINK_MTU); + memmove(uip_buf + shift, (void *)UIP_IP_BUF, uip_len - shift); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; - if (uip_ext_len) { - UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6; - } else { - UIP_IP_BUF->proto = UIP_PROTO_ICMP6; - } + UIP_IP_BUF->proto = UIP_PROTO_ICMP6; UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit; /* the source should not be unspecified nor multicast, the check for multicast is done in uip_process */ if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)){ - uip_clear_buf(); + uipbuf_clear(); return; } @@ -223,7 +195,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { if(type == ICMP6_PARAM_PROB && code == ICMP6_PARAMPROB_OPTION){ uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr); } else { - uip_clear_buf(); + uipbuf_clear(); return; } } else { @@ -234,8 +206,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { UIP_ICMP_BUF->type = type; UIP_ICMP_BUF->icode = code; UIP_ICMP6_ERROR_BUF->param = uip_htonl(param); - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); @@ -258,8 +229,7 @@ uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len) UIP_IP_BUF->flow = 0; UIP_IP_BUF->proto = UIP_PROTO_ICMP6; UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit; - UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8; - UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + payload_len); memcpy(&UIP_IP_BUF->destipaddr, dest, sizeof(*dest)); uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr); @@ -297,22 +267,7 @@ echo_reply_input(void) uip_ipaddr_copy(&sender, &UIP_IP_BUF->srcipaddr); ttl = UIP_IP_BUF->ttl; - if(uip_ext_len > 0) { - /* Remove extension headers if any */ - UIP_IP_BUF->proto = UIP_PROTO_ICMP6; - uip_len -= uip_ext_len; - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); - /* move the echo reply payload (starting after the icmp header) - * to the new location in the reply. The shift is equal to the - * length of the extension headers present Note: UIP_ICMP_BUF - * still points to the echo request at this stage - */ - memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len, - (uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN, - (uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN)); - uip_ext_len = 0; - } + uip_remove_ext_hdr(); /* Call all registered applications to let them know an echo reply has been received. */ @@ -329,7 +284,7 @@ echo_reply_input(void) } } - uip_clear_buf(); + uipbuf_clear(); return; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/uip-icmp6.h b/os/net/ipv6/uip-icmp6.h index 2808ea7de..5f8caf080 100644 --- a/os/net/ipv6/uip-icmp6.h +++ b/os/net/ipv6/uip-icmp6.h @@ -38,7 +38,7 @@ /** * \file * Header file for ICMPv6 message and error handing (RFC 4443) - * \author Julien Abeille + * \author Julien Abeille * \author Mathilde Durvy */ @@ -52,8 +52,8 @@ /** @{ */ #define ICMP6_DST_UNREACH 1 /**< dest unreachable */ #define ICMP6_PACKET_TOO_BIG 2 /**< packet too big */ -#define ICMP6_TIME_EXCEEDED 3 /**< time exceeded */ -#define ICMP6_PARAM_PROB 4 /**< ip6 header bad */ +#define ICMP6_TIME_EXCEEDED 3 /**< time exceeded */ +#define ICMP6_PARAM_PROB 4 /**< ip6 header bad */ #define ICMP6_ECHO_REQUEST 128 /**< Echo request */ #define ICMP6_ECHO_REPLY 129 /**< Echo reply */ @@ -76,10 +76,10 @@ /** \name ICMPv6 Destination Unreachable message codes*/ /** @{ */ #define ICMP6_DST_UNREACH_NOROUTE 0 /**< no route to destination */ -#define ICMP6_DST_UNREACH_ADMIN 1 /**< administratively prohibited */ +#define ICMP6_DST_UNREACH_ADMIN 1 /**< administratively prohibited */ #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /**< not a neighbor(obsolete) */ #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /**< beyond scope of source address */ -#define ICMP6_DST_UNREACH_ADDR 3 /**< address unreachable */ +#define ICMP6_DST_UNREACH_ADDR 3 /**< address unreachable */ #define ICMP6_DST_UNREACH_NOPORT 4 /**< port unreachable */ /** @} */ @@ -116,7 +116,7 @@ typedef struct uip_icmp6_error{ * \param param 32 bit parameter of the error message, semantic depends on error */ void -uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param); +uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param); /** * \brief Send an icmpv6 message diff --git a/os/net/ipv6/uip-nameserver.c b/os/net/ipv6/uip-nameserver.c index 83a1943b0..755b33992 100644 --- a/os/net/ipv6/uip-nameserver.c +++ b/os/net/ipv6/uip-nameserver.c @@ -108,7 +108,7 @@ uip_nameserver_update(const uip_ipaddr_t *nameserver, uint32_t lifetime) * the the eldest ones */ } } - + if(e == NULL) { if((e = memb_alloc(&dnsmemb)) != NULL) { list_add(dns, e); @@ -221,11 +221,7 @@ uip_nameserver_count(void) } return list_length(dns); #else /* UIP_NAMESERVER_POOL_SIZE > 1 */ -#if NETSTACK_CONF_WITH_IPV6 if(uip_is_addr_unspecified(&serveraddr)) { -#else /* NETSTACK_CONF_WITH_IPV6 */ - if(uip_ipaddr_cmp(&serveraddr, &uip_all_zeroes_addr)) { -#endif /* NETSTACK_CONF_WITH_IPV6 */ return 0; } else { return 1; diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 63ae46b47..f6efc83de 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -84,29 +84,20 @@ /*------------------------------------------------------------------*/ /** @{ */ /** \name Pointers to the header structures. - * All pointers except UIP_IP_BUF depend on uip_ext_len, which at - * packet reception, is the total length of the extension headers. - * - * The pointer to ND6 options header also depends on nd6_opt_offset, - * which we set in each function. - * - * Care should be taken when manipulating these buffers about the - * value of these length variables */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) /**< Pointer to IP header */ -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) /**< Pointer to ICMP header*/ /**@{ Pointers to messages just after icmp header */ -#define UIP_ND6_RS_BUF ((uip_nd6_rs *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_ND6_RA_BUF ((uip_nd6_ra *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_ND6_NS_BUF ((uip_nd6_ns *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_ND6_NA_BUF ((uip_nd6_na *)&uip_buf[uip_l2_l3_icmp_hdr_len]) +#define UIP_ND6_RS_BUF ((uip_nd6_rs *)UIP_ICMP_PAYLOAD) +#define UIP_ND6_RA_BUF ((uip_nd6_ra *)UIP_ICMP_PAYLOAD) +#define UIP_ND6_NS_BUF ((uip_nd6_ns *)UIP_ICMP_PAYLOAD) +#define UIP_ND6_NA_BUF ((uip_nd6_na *)UIP_ICMP_PAYLOAD) /** @} */ /** Pointer to ND option */ -#define UIP_ND6_OPT_HDR_BUF ((uip_nd6_opt_hdr *)&uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset]) -#define UIP_ND6_OPT_PREFIX_BUF ((uip_nd6_opt_prefix_info *)&uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset]) -#define UIP_ND6_OPT_MTU_BUF ((uip_nd6_opt_mtu *)&uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset]) -#define UIP_ND6_OPT_RDNSS_BUF ((uip_nd6_opt_dns *)&uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset]) +#define ND6_OPT(opt) ((unsigned char *)(UIP_ICMP_PAYLOAD + (opt))) +#define ND6_OPT_HDR_BUF(opt) ((uip_nd6_opt_hdr *)ND6_OPT(opt)) +#define ND6_OPT_PREFIX_BUF(opt) ((uip_nd6_opt_prefix_info *)ND6_OPT(opt)) +#define ND6_OPT_MTU_BUF(opt) ((uip_nd6_opt_mtu *)ND6_OPT(opt)) +#define ND6_OPT_RDNSS_BUF(opt) ((uip_nd6_opt_dns *)ND6_OPT(opt)) /** @} */ #if UIP_ND6_SEND_NS || UIP_ND6_SEND_NA || UIP_ND6_SEND_RA || !UIP_CONF_ROUTER @@ -203,14 +194,14 @@ ns_input(void) nd6_opt_offset = UIP_ND6_NS_LEN; while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) { #if UIP_CONF_IPV6_CHECKS - if(UIP_ND6_OPT_HDR_BUF->len == 0) { + if(ND6_OPT_HDR_BUF(nd6_opt_offset)->len == 0) { LOG_ERR("NS received is bad\n"); goto discard; } #endif /* UIP_CONF_IPV6_CHECKS */ - switch (UIP_ND6_OPT_HDR_BUF->type) { + switch (ND6_OPT_HDR_BUF(nd6_opt_offset)->type) { case UIP_ND6_OPT_SLLAO: - nd6_opt_llao = &uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset]; + nd6_opt_llao = &uip_buf[uip_l3_icmp_hdr_len + nd6_opt_offset]; #if UIP_CONF_IPV6_CHECKS /* There must be NO option in a DAD NS */ if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) { @@ -252,7 +243,7 @@ ns_input(void) LOG_WARN("ND option not supported in NS"); break; } - nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3); + nd6_opt_offset += (ND6_OPT_HDR_BUF(nd6_opt_offset)->len << 3); } addr = uip_ds6_addr_lookup(&UIP_ND6_NS_BUF->tgtipaddr); @@ -323,12 +314,11 @@ create_na: #if UIP_CONF_ROUTER flags = flags | UIP_ND6_NA_FLAG_ROUTER; #endif - uip_ext_len = 0; + uipbuf_clear(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; - UIP_IP_BUF->len[0] = 0; /* length will not be more than 255 */ - UIP_IP_BUF->len[1] = UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN); UIP_IP_BUF->proto = UIP_PROTO_ICMP6; UIP_IP_BUF->ttl = UIP_ND6_HOP_LIMIT; @@ -338,14 +328,13 @@ create_na: UIP_ND6_NA_BUF->flagsreserved = flags; memcpy(&UIP_ND6_NA_BUF->tgtipaddr, &addr->ipaddr, sizeof(uip_ipaddr_t)); - create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NA_LEN], + create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_NA_LEN], UIP_ND6_OPT_TLLAO); UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); - uip_len = - UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN; + uipbuf_set_len(UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN); UIP_STAT(++uip_stat.nd6.sent); LOG_INFO("Sending NA to "); @@ -358,7 +347,7 @@ create_na: return; discard: - uip_clear_buf(); + uipbuf_clear(); return; } #endif /* UIP_ND6_SEND_NA */ @@ -369,7 +358,7 @@ discard: void uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) { - uip_ext_len = 0; + uipbuf_clear(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; @@ -385,7 +374,6 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) UIP_ICMP_BUF->icode = 0; UIP_ND6_NS_BUF->reserved = 0; uip_ipaddr_copy((uip_ipaddr_t *) &UIP_ND6_NS_BUF->tgtipaddr, tgt); - UIP_IP_BUF->len[0] = 0; /* length will not be more than 255 */ /* * check if we add a SLLAO option: for DAD, MUST NOT, for NUD, MAY * (here yes), for Address resolution , MUST @@ -398,13 +386,12 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) } if (uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) { LOG_ERR("Dropping NS due to no suitable source address\n"); - uip_clear_buf(); + uipbuf_clear(); return; } - UIP_IP_BUF->len[1] = - UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN); - create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NS_LEN], + create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_NS_LEN], UIP_ND6_OPT_SLLAO); uip_len = @@ -493,20 +480,20 @@ na_input(void) nd6_opt_llao = NULL; while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) { #if UIP_CONF_IPV6_CHECKS - if(UIP_ND6_OPT_HDR_BUF->len == 0) { + if(ND6_OPT_HDR_BUF(nd6_opt_offset)->len == 0) { LOG_ERR("NA received is bad\n"); goto discard; } #endif /*UIP_CONF_IPV6_CHECKS */ - switch (UIP_ND6_OPT_HDR_BUF->type) { + switch (ND6_OPT_HDR_BUF(nd6_opt_offset)->type) { case UIP_ND6_OPT_TLLAO: - nd6_opt_llao = (uint8_t *)UIP_ND6_OPT_HDR_BUF; + nd6_opt_llao = (uint8_t *)ND6_OPT_HDR_BUF(nd6_opt_offset); break; default: LOG_WARN("ND option not supported in NA\n"); break; } - nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3); + nd6_opt_offset += (ND6_OPT_HDR_BUF(nd6_opt_offset)->len << 3); } addr = uip_ds6_addr_lookup(&UIP_ND6_NA_BUF->tgtipaddr); /* Message processing, including TLLAO if any */ @@ -605,7 +592,7 @@ na_input(void) #endif /*UIP_CONF_IPV6_QUEUE_PKT */ discard: - uip_clear_buf(); + uipbuf_clear(); return; } #endif /* UIP_ND6_SEND_NS */ @@ -644,20 +631,20 @@ rs_input(void) while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) { #if UIP_CONF_IPV6_CHECKS - if(UIP_ND6_OPT_HDR_BUF->len == 0) { + if(ND6_OPT_HDR_BUF(nd6_opt_offset)->len == 0) { LOG_ERR("RS received is bad\n"); goto discard; } #endif /*UIP_CONF_IPV6_CHECKS */ - switch (UIP_ND6_OPT_HDR_BUF->type) { + switch (ND6_OPT_HDR_BUF(nd6_opt_offset)->type) { case UIP_ND6_OPT_SLLAO: - nd6_opt_llao = (uint8_t *)UIP_ND6_OPT_HDR_BUF; + nd6_opt_llao = (uint8_t *)ND6_OPT_HDR_BUF(nd6_opt_offset); break; default: LOG_WARN("ND option not supported in RS\n"); break; } - nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3); + nd6_opt_offset += (ND6_OPT_HDR_BUF(nd6_opt_offset)->len << 3); } /* Options processing: only SLLAO */ if(nd6_opt_llao != NULL) { @@ -701,7 +688,7 @@ rs_input(void) uip_ds6_send_ra_sollicited(); discard: - uip_clear_buf(); + uipbuf_clear(); return; } @@ -746,31 +733,31 @@ uip_nd6_ra_output(uip_ipaddr_t * dest) for(prefix = uip_ds6_prefix_list; prefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; prefix++) { if((prefix->isused) && (prefix->advertise)) { - UIP_ND6_OPT_PREFIX_BUF->type = UIP_ND6_OPT_PREFIX_INFO; - UIP_ND6_OPT_PREFIX_BUF->len = UIP_ND6_OPT_PREFIX_INFO_LEN / 8; - UIP_ND6_OPT_PREFIX_BUF->preflen = prefix->length; - UIP_ND6_OPT_PREFIX_BUF->flagsreserved1 = prefix->l_a_reserved; - UIP_ND6_OPT_PREFIX_BUF->validlt = uip_htonl(prefix->vlifetime); - UIP_ND6_OPT_PREFIX_BUF->preferredlt = uip_htonl(prefix->plifetime); - UIP_ND6_OPT_PREFIX_BUF->reserved2 = 0; - uip_ipaddr_copy(&(UIP_ND6_OPT_PREFIX_BUF->prefix), &(prefix->ipaddr)); + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->type = UIP_ND6_OPT_PREFIX_INFO; + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->len = UIP_ND6_OPT_PREFIX_INFO_LEN / 8; + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->preflen = prefix->length; + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->flagsreserved1 = prefix->l_a_reserved; + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->validlt = uip_htonl(prefix->vlifetime); + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->preferredlt = uip_htonl(prefix->plifetime); + ND6_OPT_PREFIX_BUF(nd6_opt_offset)->reserved2 = 0; + uip_ipaddr_copy(&(ND6_OPT_PREFIX_BUF(nd6_opt_offset)->prefix), &(prefix->ipaddr)); nd6_opt_offset += UIP_ND6_OPT_PREFIX_INFO_LEN; uip_len += UIP_ND6_OPT_PREFIX_INFO_LEN; } } /* Source link-layer option */ - create_llao((uint8_t *)UIP_ND6_OPT_HDR_BUF, UIP_ND6_OPT_SLLAO); + create_llao((uint8_t *)ND6_OPT_HDR_BUF(nd6_opt_offset), UIP_ND6_OPT_SLLAO); uip_len += UIP_ND6_OPT_LLAO_LEN; nd6_opt_offset += UIP_ND6_OPT_LLAO_LEN; /* MTU */ - UIP_ND6_OPT_MTU_BUF->type = UIP_ND6_OPT_MTU; - UIP_ND6_OPT_MTU_BUF->len = UIP_ND6_OPT_MTU_LEN >> 3; - UIP_ND6_OPT_MTU_BUF->reserved = 0; - //UIP_ND6_OPT_MTU_BUF->mtu = uip_htonl(uip_ds6_if.link_mtu); - UIP_ND6_OPT_MTU_BUF->mtu = uip_htonl(1500); + ND6_OPT_MTU_BUF(nd6_opt_offset)->type = UIP_ND6_OPT_MTU; + ND6_OPT_MTU_BUF(nd6_opt_offset)->len = UIP_ND6_OPT_MTU_LEN >> 3; + ND6_OPT_MTU_BUF(nd6_opt_offset)->reserved = 0; + //ND6_OPT_MTU_BUF(nd6_opt_offset)->mtu = uip_htonl(uip_ds6_if.link_mtu); + ND6_OPT_MTU_BUF(nd6_opt_offset)->mtu = uip_htonl(1500); uip_len += UIP_ND6_OPT_MTU_LEN; nd6_opt_offset += UIP_ND6_OPT_MTU_LEN; @@ -778,27 +765,26 @@ uip_nd6_ra_output(uip_ipaddr_t * dest) #if UIP_ND6_RA_RDNSS if(uip_nameserver_count() > 0) { uint8_t i = 0; - uip_ipaddr_t *ip = &UIP_ND6_OPT_RDNSS_BUF->ip; + uip_ipaddr_t *ip = &ND6_OPT_RDNSS_BUF(nd6_opt_offset)->ip; uip_ipaddr_t *dns = NULL; - UIP_ND6_OPT_RDNSS_BUF->type = UIP_ND6_OPT_RDNSS; - UIP_ND6_OPT_RDNSS_BUF->reserved = 0; - UIP_ND6_OPT_RDNSS_BUF->lifetime = uip_nameserver_next_expiration(); - if(UIP_ND6_OPT_RDNSS_BUF->lifetime != UIP_NAMESERVER_INFINITE_LIFETIME) { - UIP_ND6_OPT_RDNSS_BUF->lifetime -= clock_seconds(); + ND6_OPT_RDNSS_BUF(nd6_opt_offset)->type = UIP_ND6_OPT_RDNSS; + ND6_OPT_RDNSS_BUF(nd6_opt_offset)->reserved = 0; + ND6_OPT_RDNSS_BUF(nd6_opt_offset)->lifetime = uip_nameserver_next_expiration(); + if(ND6_OPT_RDNSS_BUF(nd6_opt_offset)->lifetime != UIP_NAMESERVER_INFINITE_LIFETIME) { + ND6_OPT_RDNSS_BUF(nd6_opt_offset)->lifetime -= clock_seconds(); } while((dns = uip_nameserver_get(i)) != NULL) { uip_ipaddr_copy(ip++, dns); i++; } - UIP_ND6_OPT_RDNSS_BUF->len = UIP_ND6_OPT_RDNSS_LEN + (i << 1); + ND6_OPT_RDNSS_BUF(nd6_opt_offset)->len = UIP_ND6_OPT_RDNSS_LEN + (i << 1); LOG_INFO("%d nameservers reported\n", i); - uip_len += UIP_ND6_OPT_RDNSS_BUF->len << 3; - nd6_opt_offset += UIP_ND6_OPT_RDNSS_BUF->len << 3; + uip_len += ND6_OPT_RDNSS_BUF(nd6_opt_offset)->len << 3; + nd6_opt_offset += ND6_OPT_RDNSS_BUF(nd6_opt_offset)->len << 3; } #endif /* UIP_ND6_RA_RDNSS */ - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); /*ICMP checksum */ UIP_ICMP_BUF->icmpchksum = 0; @@ -829,17 +815,15 @@ uip_nd6_rs_output(void) uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr); UIP_ICMP_BUF->type = ICMP6_RS; UIP_ICMP_BUF->icode = 0; - UIP_IP_BUF->len[0] = 0; /* length will not be more than 255 */ if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) { UIP_IP_BUF->len[1] = UIP_ICMPH_LEN + UIP_ND6_RS_LEN; uip_len = uip_l3_icmp_hdr_len + UIP_ND6_RS_LEN; } else { uip_len = uip_l3_icmp_hdr_len + UIP_ND6_RS_LEN + UIP_ND6_OPT_LLAO_LEN; - UIP_IP_BUF->len[1] = - UIP_ICMPH_LEN + UIP_ND6_RS_LEN + UIP_ND6_OPT_LLAO_LEN; + uipbuf_set_len_field(UIP_IP_BUF, UIP_ICMPH_LEN + UIP_ND6_RS_LEN + UIP_ND6_OPT_LLAO_LEN); - create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_RS_LEN], + create_llao(&uip_buf[uip_l3_icmp_hdr_len + UIP_ND6_RS_LEN], UIP_ND6_OPT_SLLAO); } @@ -904,14 +888,14 @@ ra_input(void) /* Options processing */ nd6_opt_offset = UIP_ND6_RA_LEN; while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) { - if(UIP_ND6_OPT_HDR_BUF->len == 0) { + if(ND6_OPT_HDR_BUF(nd6_opt_offset)->len == 0) { LOG_ERR("RA received is bad"); goto discard; } - switch (UIP_ND6_OPT_HDR_BUF->type) { + switch (ND6_OPT_HDR_BUF(nd6_opt_offset)->type) { case UIP_ND6_OPT_SLLAO: LOG_DBG("Processing SLLAO option in RA\n"); - nd6_opt_llao = (uint8_t *) UIP_ND6_OPT_HDR_BUF; + nd6_opt_llao = (uint8_t *) ND6_OPT_HDR_BUF(nd6_opt_offset); nbr = uip_ds6_nbr_lookup(&UIP_IP_BUF->srcipaddr); if(!extract_lladdr_from_llao_aligned(&lladdr_aligned)) { /* failed to extract llao - discard packet */ @@ -944,11 +928,11 @@ ra_input(void) case UIP_ND6_OPT_MTU: LOG_DBG("Processing MTU option in RA\n"); uip_ds6_if.link_mtu = - uip_ntohl(((uip_nd6_opt_mtu *) UIP_ND6_OPT_HDR_BUF)->mtu); + uip_ntohl(((uip_nd6_opt_mtu *) ND6_OPT_HDR_BUF(nd6_opt_offset))->mtu); break; case UIP_ND6_OPT_PREFIX_INFO: LOG_DBG("Processing PREFIX option in RA\n"); - nd6_opt_prefix_info = (uip_nd6_opt_prefix_info *) UIP_ND6_OPT_HDR_BUF; + nd6_opt_prefix_info = (uip_nd6_opt_prefix_info *) ND6_OPT_HDR_BUF(nd6_opt_offset); if((uip_ntohl(nd6_opt_prefix_info->validlt) >= uip_ntohl(nd6_opt_prefix_info->preferredlt)) && (!uip_is_addr_linklocal(&nd6_opt_prefix_info->prefix))) { @@ -1035,14 +1019,14 @@ ra_input(void) #if UIP_ND6_RA_RDNSS case UIP_ND6_OPT_RDNSS: LOG_DBG("Processing RDNSS option\n"); - uint8_t naddr = (UIP_ND6_OPT_RDNSS_BUF->len - 1) / 2; - uip_ipaddr_t *ip = (uip_ipaddr_t *)(&UIP_ND6_OPT_RDNSS_BUF->ip); + uint8_t naddr = (ND6_OPT_RDNSS_BUF(nd6_opt_offset)->len - 1) / 2; + uip_ipaddr_t *ip = (uip_ipaddr_t *)(&ND6_OPT_RDNSS_BUF(nd6_opt_offset)->ip); LOG_DBG("got %d nameservers\n", naddr); while(naddr-- > 0) { LOG_DBG("nameserver: "); LOG_DBG_6ADDR(ip); - LOG_DBG_(" lifetime: %"PRIx32"\n", uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime)); - uip_nameserver_update(ip, uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime)); + LOG_DBG_(" lifetime: %"PRIx32"\n", uip_ntohl(ND6_OPT_RDNSS_BUF(nd6_opt_offset)->lifetime)); + uip_nameserver_update(ip, uip_ntohl(ND6_OPT_RDNSS_BUF(nd6_opt_offset)->lifetime)); ip++; } break; @@ -1051,7 +1035,7 @@ ra_input(void) LOG_ERR("ND option not supported in RA\n"); break; } - nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3); + nd6_opt_offset += (ND6_OPT_HDR_BUF(nd6_opt_offset)->len << 3); } defrt = uip_ds6_defrt_lookup(&UIP_IP_BUF->srcipaddr); @@ -1092,7 +1076,7 @@ ra_input(void) #endif /*UIP_CONF_IPV6_QUEUE_PKT */ discard: - uip_clear_buf(); + uipbuf_clear(); return; } #endif /* !UIP_CONF_ROUTER */ diff --git a/os/net/ipv6/uip-packetqueue.h b/os/net/ipv6/uip-packetqueue.h index b265b1ecf..1deacb9ba 100644 --- a/os/net/ipv6/uip-packetqueue.h +++ b/os/net/ipv6/uip-packetqueue.h @@ -7,7 +7,7 @@ struct uip_packetqueue_handle; struct uip_packetqueue_packet { struct uip_ds6_queued_packet *next; - uint8_t queue_buf[UIP_BUFSIZE - UIP_LLH_LEN]; + uint8_t queue_buf[UIP_BUFSIZE]; uint16_t queue_buf_len; struct ctimer lifetimer; struct uip_packetqueue_handle *handle; diff --git a/os/net/ipv6/uip-udp-packet.c b/os/net/ipv6/uip-udp-packet.c index 91ddf598c..c5526b162 100644 --- a/os/net/ipv6/uip-udp-packet.c +++ b/os/net/ipv6/uip-udp-packet.c @@ -51,10 +51,10 @@ void uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len) { #if UIP_UDP - if(data != NULL && len <= (UIP_BUFSIZE - (UIP_LLH_LEN + UIP_IPUDPH_LEN))) { + if(data != NULL && len <= (UIP_BUFSIZE - UIP_IPUDPH_LEN)) { uip_udp_conn = c; uip_slen = len; - memmove(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data, len); + memmove(&uip_buf[UIP_IPUDPH_LEN], data, len); uip_process(UIP_UDP_SEND_CONN); #if UIP_IPV6_MULTICAST diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 9f5eb159d..32ffc6ed4 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -62,22 +62,24 @@ #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + UDP header */ #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + TCP header */ -#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN -#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* Size of ICMP + IP header */ -#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* Size of L2 + IP header */ -#if NETSTACK_CONF_WITH_IPV6 -/** - * The sums below are quite used in ND. When used for uip_buf, we - * include link layer length when used for uip_len, we do not, hence - * we need values with and without LLH_LEN we do not use capital - * letters as these values are variable - */ -#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len) -#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) -#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len) -#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) -#endif /*NETSTACK_CONF_WITH_IPV6*/ +#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) + +/** + * Direct access to IPv6 header + */ +#define UIP_IP_BUF ((struct uip_ip_hdr *)uip_buf) +#define UIP_IP_PAYLOAD(ext) ((unsigned char *)uip_buf + UIP_IPH_LEN + (ext)) + +/** + * Direct access to ICMP, UDP, and TCP headers and payload, with implicit ext header offset (global uip_ext_len) + */ +#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)UIP_IP_PAYLOAD(uip_ext_len)) +#define UIP_ICMP_PAYLOAD ((unsigned char *)UIP_IP_PAYLOAD(uip_ext_len) + UIP_ICMPH_LEN) +#define UIP_UDP_BUF ((struct uip_udp_hdr *)UIP_IP_PAYLOAD(uip_ext_len)) +#define UIP_UDP_PAYLOAD ((unsigned char *)UIP_IP_PAYLOAD(uip_ext_len) + UIP_UDPH_LEN) +#define UIP_TCP_BUF ((struct uip_tcp_hdr *)UIP_IP_PAYLOAD(uip_ext_len)) +#define UIP_TCP_PAYLOAD ((unsigned char *)UIP_IP_PAYLOAD(uip_ext_len) + UIP_TCPH_LEN) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" @@ -100,12 +102,7 @@ typedef union uip_ip6addr_t { uint16_t u16[8]; } uip_ip6addr_t; -#if NETSTACK_CONF_WITH_IPV6 typedef uip_ip6addr_t uip_ipaddr_t; -#else /* NETSTACK_CONF_WITH_IPV6 */ -typedef uip_ip4addr_t uip_ipaddr_t; -#endif /* NETSTACK_CONF_WITH_IPV6 */ - /*---------------------------------------------------------------------------*/ #define UIP_802154_SHORTADDR_LEN 2 @@ -1048,11 +1045,7 @@ struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport); (addr1)->u16[1] == (addr2)->u16[1]) #define uip_ip6addr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) -#if NETSTACK_CONF_WITH_IPV6 #define uip_ipaddr_cmp(addr1, addr2) uip_ip6addr_cmp(addr1, addr2) -#else /* NETSTACK_CONF_WITH_IPV6 */ -#define uip_ipaddr_cmp(addr1, addr2) uip_ip4addr_cmp(addr1, addr2) -#endif /* NETSTACK_CONF_WITH_IPV6 */ /** * Compare two IP addresses with netmasks @@ -1308,31 +1301,16 @@ extern uint16_t uip_len; * The length of the extension headers */ extern uint8_t uip_ext_len; + +/** The final protocol after IPv6 extension headers: + * UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6 */ +extern uint8_t uip_last_proto; /** @} */ #if UIP_URGDATA > 0 extern uint16_t uip_urglen, uip_surglen; #endif /* UIP_URGDATA > 0 */ -/* - * Clear uIP buffer - * - * This function clears the uIP buffer by reseting the uip_len and - * uip_ext_len pointers. - */ -#if NETSTACK_CONF_WITH_IPV6 -#define uip_clear_buf() { \ - uip_len = 0; \ - uip_ext_len = 0; \ - uipbuf_clear_attr();\ -} -#else /*NETSTACK_CONF_WITH_IPV6*/ -#define uip_clear_buf() { \ - uip_len = 0; \ - uipbuf_clear_attr();\ -} -#endif /*NETSTACK_CONF_WITH_IPV6*/ - /** * Representation of a uIP TCP connection. * @@ -1494,13 +1472,11 @@ struct uip_stats { checksum. */ } udp; /**< UDP statistics. */ #endif /* UIP_UDP */ -#if NETSTACK_CONF_WITH_IPV6 struct { uip_stats_t drop; /**< Number of dropped ND6 packets. */ uip_stats_t recv; /**< Number of recived ND6 packets */ uip_stats_t sent; /**< Number of sent ND6 packets */ } nd6; -#endif /*NETSTACK_CONF_WITH_IPV6*/ }; @@ -1619,113 +1595,14 @@ void uip_process(uint8_t flag); #define UIP_STOPPED 16 -/* The TCP and IP headers. */ -struct uip_tcpip_hdr { -#if NETSTACK_CONF_WITH_IPV6 - /* IPv6 header. */ - uint8_t vtc, - tcflow; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; -#else /* NETSTACK_CONF_WITH_IPV6 */ - /* IPv4 header. */ - uint8_t vhl, - tos, - len[2], - ipid[2], - ipoffset[2], - ttl, - proto; - uint16_t ipchksum; - uip_ipaddr_t srcipaddr, destipaddr; -#endif /* NETSTACK_CONF_WITH_IPV6 */ - - /* TCP header. */ - uint16_t srcport, - destport; - uint8_t seqno[4], - ackno[4], - tcpoffset, - flags, - wnd[2]; - uint16_t tcpchksum; - uint8_t urgp[2]; - uint8_t optdata[4]; -}; - -/* The ICMP and IP headers. */ -struct uip_icmpip_hdr { -#if NETSTACK_CONF_WITH_IPV6 - /* IPv6 header. */ - uint8_t vtc, - tcf; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; -#else /* NETSTACK_CONF_WITH_IPV6 */ - /* IPv4 header. */ - uint8_t vhl, - tos, - len[2], - ipid[2], - ipoffset[2], - ttl, - proto; - uint16_t ipchksum; - uip_ipaddr_t srcipaddr, destipaddr; -#endif /* NETSTACK_CONF_WITH_IPV6 */ - - /* ICMP header. */ - uint8_t type, icode; - uint16_t icmpchksum; -#if !NETSTACK_CONF_WITH_IPV6 - uint16_t id, seqno; - uint8_t payload[1]; -#endif /* !NETSTACK_CONF_WITH_IPV6 */ -}; - - -/* The UDP and IP headers. */ -struct uip_udpip_hdr { -#if NETSTACK_CONF_WITH_IPV6 - /* IPv6 header. */ - uint8_t vtc, - tcf; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; -#else /* NETSTACK_CONF_WITH_IPV6 */ - /* IP header. */ - uint8_t vhl, - tos, - len[2], - ipid[2], - ipoffset[2], - ttl, - proto; - uint16_t ipchksum; - uip_ipaddr_t srcipaddr, destipaddr; -#endif /* NETSTACK_CONF_WITH_IPV6 */ - - /* UDP header. */ - uint16_t srcport, - destport; - uint16_t udplen; - uint16_t udpchksum; -}; - /* * In IPv6 the length of the L3 headers before the transport header is * not fixed, due to the possibility to include extension option headers * after the IP header. hence we split here L3 and L4 headers */ /* The IP header */ + struct uip_ip_hdr { -#if NETSTACK_CONF_WITH_IPV6 /* IPV6 header */ uint8_t vtc; uint8_t tcflow; @@ -1733,18 +1610,6 @@ struct uip_ip_hdr { uint8_t len[2]; uint8_t proto, ttl; uip_ip6addr_t srcipaddr, destipaddr; -#else /* NETSTACK_CONF_WITH_IPV6 */ - /* IPV4 header */ - uint8_t vhl, - tos, - len[2], - ipid[2], - ipoffset[2], - ttl, - proto; - uint16_t ipchksum; - uip_ipaddr_t srcipaddr, destipaddr; -#endif /* NETSTACK_CONF_WITH_IPV6 */ }; @@ -1860,9 +1725,6 @@ struct uip_tcp_hdr { struct uip_icmp_hdr { uint8_t type, icode; uint16_t icmpchksum; -#if !NETSTACK_CONF_WITH_IPV6 - uint16_t id, seqno; -#endif /* !NETSTACK_CONF_WITH_IPV6 */ }; @@ -1889,8 +1751,7 @@ struct uip_udp_hdr { * * \hideinitializer */ -#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) -#define UIP_APPDATA_PTR (void *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN] +#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_IPTCPH_LEN) #define UIP_PROTO_ICMP 1 #define UIP_PROTO_TCP 6 @@ -1898,7 +1759,6 @@ struct uip_udp_hdr { #define UIP_PROTO_ICMP6 58 -#if NETSTACK_CONF_WITH_IPV6 /** @{ */ /** \brief extension headers types */ #define UIP_PROTO_HBHO 0 @@ -1908,7 +1768,7 @@ struct uip_udp_hdr { #define UIP_PROTO_NONE 59 /** @} */ -#define uip_is_proto_ext_hdr(proto) (proto == UIP_PROTO_HBHO || proto == UIP_PROTO_DESTO || proto == UIP_PROTO_ROUTING || proto == UIP_PROTO_FRAG || proto == UIP_PROTO_NONE) +#define uip_is_proto_ext_hdr(proto) ((proto) != UIP_PROTO_TCP && (proto) != UIP_PROTO_UDP && (proto) != UIP_PROTO_ICMP6) /** @{ */ /** \brief Destination and Hop By Hop extension headers option types */ @@ -1937,9 +1797,6 @@ struct uip_udp_hdr { /** @} */ -#endif /* NETSTACK_CONF_WITH_IPV6 */ - - #if UIP_FIXEDADDR extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; #else /* UIP_FIXEDADDR */ @@ -1954,10 +1811,6 @@ extern const uip_lladdr_t uip_lladdr; extern uip_lladdr_t uip_lladdr; #endif - - - -#if NETSTACK_CONF_WITH_IPV6 /** Length of the link local prefix */ #define UIP_LLPREF_LEN 10 @@ -2174,8 +2027,6 @@ extern uip_lladdr_t uip_lladdr; (((a)->u8[14]) == ((b)->u8[14])) && \ (((a)->u8[15]) == ((b)->u8[15]))) -#endif /*NETSTACK_CONF_WITH_IPV6*/ - /** * A non-error message that indicates that a packet should be * processed locally. @@ -2288,6 +2139,11 @@ uint16_t uip_udpchksum(void); */ uint16_t uip_icmp6chksum(void); +/** + * Removes all IPv6 extension headers from uip_buf, updates length fields + * (uip_len and uip_ext_len) + */ +void uip_remove_ext_hdr(void); #endif /* UIP_H_ */ diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 82d7900db..8a1c27682 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -114,46 +114,26 @@ uip_lladdr_t uip_lladdr = {{0x00,0x06,0x98,0x00,0x02,0x32}}; * @{ */ /*---------------------------------------------------------------------------*/ -/** - * \brief Type of the next header in IPv6 header or extension headers - * - * Can be the next header field in the IPv6 header or in an extension header. - * When doing fragment reassembly, we must change the value of the next header - * field in the header before the fragmentation header, hence we need a pointer - * to this field. - */ -uint8_t *uip_next_hdr; /** \brief bitmap we use to record which IPv6 headers we have already seen */ uint8_t uip_ext_bitmap = 0; /** - * \brief length of the extension headers read. updated each time we process - * a header + * \brief Total length of all IPv6 extension headers */ uint8_t uip_ext_len = 0; -/** \brief length of the header options read */ -uint8_t uip_ext_opt_offset = 0; +/** \brief The final protocol after IPv6 extension headers: + * UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6 */ +uint8_t uip_last_proto = 0; /** @} */ /*---------------------------------------------------------------------------*/ /* Buffers */ /*---------------------------------------------------------------------------*/ /** - * \name Buffer defines + * \name Reassembly buffer definition * @{ */ -#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]) +#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0]) + /** @} */ /** * \name Buffer variables @@ -341,7 +321,7 @@ uip_ipchksum(void) { uint16_t sum; - sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN); + sum = chksum(0, uip_buf, UIP_IPH_LEN); LOG_DBG("uip_ipchksum: sum 0x%04x\n", sum); return (sum == 0) ? 0xffff : uip_htons(sum); } @@ -362,10 +342,10 @@ upper_layer_chksum(uint8_t proto) volatile uint16_t upper_layer_len; uint16_t sum; - upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1] - uip_ext_len); + upper_layer_len = uipbuf_get_len_field(UIP_IP_BUF) - uip_ext_len; LOG_DBG("Upper layer checksum len: %d from: %d\n", upper_layer_len, - UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len); + (int)(UIP_IP_PAYLOAD(uip_ext_len) - uip_buf)); /* First sum pseudoheader. */ /* IP protocol and length fields. This addition cannot carry. */ @@ -373,9 +353,8 @@ upper_layer_chksum(uint8_t proto) /* Sum IP source and destination addresses. */ sum = chksum(sum, (uint8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t)); - /* Sum TCP header and data. */ - sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN + uip_ext_len], - upper_layer_len); + /* Sum upper-layer header and data. */ + sum = chksum(sum, UIP_IP_PAYLOAD(uip_ext_len), upper_layer_len); return (sum == 0) ? 0xffff : uip_htons(sum); } @@ -511,29 +490,27 @@ uip_connect(const uip_ipaddr_t *ripaddr, uint16_t rport) #endif /* UIP_TCP && UIP_ACTIVE_OPEN */ /*---------------------------------------------------------------------------*/ void -remove_ext_hdr(void) +uip_remove_ext_hdr(void) { - int last_uip_ext_len; /* Remove ext header before TCP/UDP processing. */ if(uip_ext_len > 0) { - LOG_DBG("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n", + LOG_DBG("Removing IPv6 extension headers (extlen: %d, uiplen: %d)\n", uip_ext_len, uip_len); if(uip_len < UIP_IPH_LEN + uip_ext_len) { - LOG_ERR("ERROR: uip_len too short compared to ext len\n"); - uip_clear_buf(); + LOG_ERR("uip_len too short compared to ext len\n"); + uipbuf_clear(); return; } - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - UIP_IP_BUF->proto = UIP_EXT_BUF->next; - memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + last_uip_ext_len, - uip_len - UIP_IPH_LEN - last_uip_ext_len); - uip_len -= last_uip_ext_len; + /* Set proto */ + UIP_IP_BUF->proto = uip_last_proto; + /* Move IP payload to the "left"*/ + memmove(UIP_IP_PAYLOAD(0), UIP_IP_PAYLOAD(uip_ext_len), + uip_len - UIP_IPH_LEN - uip_ext_len); /* Update the IP length. */ - UIP_IP_BUF->len[0] = (uip_len - UIP_IPH_LEN) >> 8; - UIP_IP_BUF->len[1] = (uip_len - UIP_IPH_LEN) & 0xff; + uipbuf_add_ext_hdr(-uip_ext_len); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); } } /*---------------------------------------------------------------------------*/ @@ -611,7 +588,7 @@ uip_listen(uint16_t port) /*---------------------------------------------------------------------------*/ #if UIP_CONF_IPV6_REASSEMBLY -#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN) +#define UIP_REASS_BUFSIZE (UIP_BUFSIZE) static uint8_t uip_reassbuf[UIP_REASS_BUFSIZE]; @@ -647,11 +624,12 @@ static uint32_t uip_id; /* For every packet that is to be fragmented, the source #define IP_MF 0x0001 static uint16_t -uip_reass(void) +uip_reass(uint8_t *prev_proto_ptr) { uint16_t offset=0; uint16_t len; uint16_t i; + struct uip_frag_hdr *frag_buf = (struct uip_frag_hdr *)UIP_IP_PAYLOAD(uip_ext_len); /* If ip_reasstmr is zero, no packet is present in the buffer */ /* We first write the unfragmentable part of IP header into the reassembly @@ -663,7 +641,7 @@ uip_reass(void) etimer_set(&uip_reass_timer, UIP_REASS_MAXAGE*CLOCK_SECOND); uip_reass_on = 1; uip_reassflags = 0; - uip_id = UIP_FRAG_BUF->id; + uip_id = frag_buf->id; /* Clear the bitmap. */ memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap)); } @@ -674,9 +652,9 @@ uip_reass(void) */ if(uip_ipaddr_cmp(&FBUF->srcipaddr, &UIP_IP_BUF->srcipaddr) && uip_ipaddr_cmp(&FBUF->destipaddr, &UIP_IP_BUF->destipaddr) && - UIP_FRAG_BUF->id == uip_id) { + frag_buf->id == uip_id) { len = uip_len - uip_ext_len - UIP_IPH_LEN - UIP_FRAGH_LEN; - offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8); + offset = (uip_ntohs(frag_buf->offsetresmore) & 0xfff8); /* in byte, originaly in multiple of 8 bytes*/ LOG_INFO("len %d\n", len); LOG_INFO("offset %d\n", offset); @@ -687,7 +665,7 @@ uip_reass(void) * Part is obtained from the Next Header field of the first * fragment's Fragment header. */ - *uip_next_hdr = UIP_FRAG_BUF->next; + *prev_proto_ptr = frag_buf->next; memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN); LOG_INFO("src "); LOG_INFO_6ADDR(&FBUF->srcipaddr); @@ -708,7 +686,7 @@ uip_reass(void) /* If this fragment has the More Fragments flag set to zero, it is the last fragment*/ - if((uip_ntohs(UIP_FRAG_BUF->offsetresmore) & IP_MF) == 0) { + if((uip_ntohs(frag_buf->offsetresmore) & IP_MF) == 0) { uip_reassflags |= UIP_REASS_FLAG_LASTFRAG; /*calculate the size of the entire packet*/ uip_reasslen = offset + len; @@ -732,7 +710,7 @@ uip_reass(void) /* Copy the fragment into the reassembly buffer, at the right offset. */ memcpy((uint8_t *)FBUF + UIP_IPH_LEN + uip_ext_len + offset, - (uint8_t *)UIP_FRAG_BUF + UIP_FRAGH_LEN, len); + (uint8_t *)frag_buf + UIP_FRAGH_LEN, len); /* Update the bitmap. */ if(offset >> 6 == (offset + len) >> 6) { @@ -778,10 +756,8 @@ uip_reass(void) uip_reasslen += UIP_IPH_LEN + uip_ext_len; memcpy(UIP_IP_BUF, FBUF, uip_reasslen); - UIP_IP_BUF->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff); - LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen, - (UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]); + uipbuf_set_len_field(UIP_IP_BUF, uip_reasslen - UIP_IPH_LEN); + LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen, uipbuf_get_len_field(UIP_IP_BUF)); return uip_reasslen; @@ -811,7 +787,7 @@ uip_reass_over(void) * any RFC, we decided not to include it as it reduces the size of * the packet. */ - uip_clear_buf(); + uipbuf_clear(); memcpy(UIP_IP_BUF, FBUF, UIP_IPH_LEN); /* copy the header for src and dest address*/ uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_REASSEMBLY, 0); @@ -841,16 +817,29 @@ uip_add_rcv_nxt(uint16_t n) * \brief Process the options in Destination and Hop By Hop extension headers */ static uint8_t -ext_hdr_options_process(void) +ext_hdr_options_process(uint8_t *ext_buf) { /* * Length field in the extension header: length of the header in units of * 8 bytes, excluding the first 8 bytes * length field in an option : the length of data in the option */ - uip_ext_opt_offset = 2; - while(uip_ext_opt_offset < ((UIP_EXT_BUF->len << 3) + 8)) { - switch(UIP_EXT_HDR_OPT_BUF->type) { + uint8_t opt_offset = 2; /* 2 first bytes in ext header */ + struct uip_hbho_hdr *ext_hdr = (struct uip_hbho_hdr *)ext_buf; + uint8_t ext_hdr_len = (ext_hdr->len << 3) + 8; + + while(opt_offset + 2 <= ext_hdr_len) { /* + 2 for opt header */ + struct uip_ext_hdr_opt *opt_hdr = (struct uip_ext_hdr_opt *)(ext_buf + opt_offset); + uint8_t opt_len = opt_hdr->len + 2; + + if(opt_offset + opt_len > ext_hdr_len) { + LOG_ERR("RPL Option too long: Dropping Packet\n"); + uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, + (ext_buf + opt_offset) - uip_buf); + return 2; + } + + switch(opt_hdr->type) { /* * for now we do not support any options except padding ones * PAD1 does not make sense as the header must be 8bytes aligned, @@ -858,11 +847,11 @@ ext_hdr_options_process(void) */ case UIP_EXT_HDR_OPT_PAD1: LOG_DBG("Processing PAD1 option\n"); - uip_ext_opt_offset += 1; + opt_offset += 1; break; case UIP_EXT_HDR_OPT_PADN: LOG_DBG("Processing PADN option\n"); - uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2; + opt_offset += opt_len; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -873,12 +862,13 @@ ext_hdr_options_process(void) * Using this fix, the header is ignored, and the next header (if * present) is processed. */ - if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_opt_offset)) { + LOG_DBG("Processing RPL option\n"); + if(!NETSTACK_ROUTING.ext_header_hbh_update(ext_buf, opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF->len) + 2; - return 0; + opt_offset += opt_len; + break; default: /* * check the two highest order bits of the option @@ -893,8 +883,8 @@ ext_hdr_options_process(void) * Problem, Code 2, message to the packet's Source Address, * pointing to the unrecognized Option Type. */ - LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF->type); - switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) { + LOG_DBG("Unrecognized option, MSB 0x%x\n", opt_hdr->type); + switch(opt_hdr->type & 0xC0) { case 0: break; case 0x40: @@ -905,22 +895,49 @@ ext_hdr_options_process(void) } case 0x80: uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, - (uint32_t)UIP_IPH_LEN + uip_ext_len + uip_ext_opt_offset); + (ext_buf + opt_offset) - uip_buf); return 2; } /* in the cases were we did not discard, update ext_opt* */ - uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF->len + 2; + opt_offset += opt_len; break; } } return 0; } - - +/*---------------------------------------------------------------------------*/ +static bool +uip_check_mtu(void) +{ + if(uip_len > UIP_LINK_MTU) { + uip_icmp6_error_output(ICMP6_PACKET_TOO_BIG, 0, UIP_LINK_MTU); + UIP_STAT(++uip_stat.ip.drop); + return false; + } else { + return true; + } +} +/*---------------------------------------------------------------------------*/ +static bool +uip_update_ttl(void) +{ + if(UIP_IP_BUF->ttl <= 1) { + uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_TRANSIT, 0); + UIP_STAT(++uip_stat.ip.drop); + return false; + } else { + UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1; + return true; + } +} /*---------------------------------------------------------------------------*/ void uip_process(uint8_t flag) { + uint8_t *last_header; + uint8_t protocol; + uint8_t *next_header; + struct uip_ext_hdr *ext_ptr; #if UIP_TCP int c; uint16_t tmp16; @@ -932,7 +949,7 @@ uip_process(uint8_t flag) goto udp_send; } #endif /* UIP_UDP */ - uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; + uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN]; /* Check if we were invoked because of a poll request for a particular connection. */ @@ -956,7 +973,7 @@ uip_process(uint8_t flag) } else if(flag == UIP_TIMER) { /* Reset the length variables. */ #if UIP_TCP - uip_clear_buf(); + uipbuf_clear(); uip_slen = 0; /* Increase the initial sequence number. */ @@ -1069,7 +1086,7 @@ uip_process(uint8_t flag) if(flag == UIP_UDP_TIMER) { if(uip_udp_conn->lport != 0) { uip_conn = NULL; - uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN]; + uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN]; uip_len = uip_slen = 0; uip_flags = UIP_POLL; UIP_UDP_APPCALL(); @@ -1102,8 +1119,8 @@ uip_process(uint8_t flag) * value.. */ - if((UIP_IP_BUF->len[0] << 8) + UIP_IP_BUF->len[1] <= uip_len) { - uip_len = (UIP_IP_BUF->len[0] << 8) + UIP_IP_BUF->len[1] + UIP_IPH_LEN; + if(uipbuf_get_len_field(UIP_IP_BUF) <= uip_len) { + uip_len = uipbuf_get_len_field(UIP_IP_BUF) + UIP_IPH_LEN; /* * The length reported in the IPv6 header is the * length of the payload that follows the @@ -1116,10 +1133,21 @@ uip_process(uint8_t flag) * header (40 bytes). */ } else { - LOG_ERR("packet shorter than reported in IP header."); + LOG_ERR("packet shorter than reported in IP header\n"); goto drop; } + /* Check sanity of extension headers, and compute the total extension header + * length (uip_ext_len) as well as the final protocol (uip_last_proto) */ + uip_last_proto = 0; + last_header = uipbuf_get_last_header(uip_buf, uip_len, &uip_last_proto); + if(last_header == NULL) { + LOG_ERR("invalid extension header chain\n"); + goto drop; + } + /* Set uip_ext_len */ + uip_ext_len = last_header - UIP_IP_PAYLOAD(0); + LOG_INFO("packet received from "); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); LOG_INFO_(" to "); @@ -1141,32 +1169,20 @@ uip_process(uint8_t flag) #if UIP_CONF_ROUTER /* - * Next header field processing. In IPv6, we can have extension headers, - * if present, the Hop-by-Hop Option must be processed before forwarding + * If present, the Hop-by-Hop Option must be processed before forwarding * the packet. */ - uip_next_hdr = &UIP_IP_BUF->proto; - uip_ext_len = 0; - uip_ext_bitmap = 0; - if(*uip_next_hdr == UIP_PROTO_HBHO) { -#if UIP_CONF_IPV6_CHECKS - uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO; -#endif /* UIP_CONF_IPV6_CHECKS */ - switch(ext_hdr_options_process()) { + + next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); + if(next_header != NULL && protocol == UIP_PROTO_HBHO) { + switch(ext_hdr_options_process(next_header)) { case 0: - /* continue */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; + break; /* done */ case 1: - LOG_ERR("Dropping packet after extension header processing\n"); - /* silently discard */ - goto drop; + goto drop; /* silently discard */ case 2: - LOG_ERR("Sending error message after extension header processing\n"); - /* send icmp error message (created in ext_hdr_options_process) - * and discard*/ - goto send; + goto send; /* send icmp error message (created in + ext_hdr_options_process) and discard */ } } @@ -1202,23 +1218,12 @@ uip_process(uint8_t flag) !uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr) && !uip_is_addr_loopback(&UIP_IP_BUF->destipaddr)) { - - /* Check MTU */ - if(uip_len > UIP_LINK_MTU) { - uip_icmp6_error_output(ICMP6_PACKET_TOO_BIG, 0, UIP_LINK_MTU); - UIP_STAT(++uip_stat.ip.drop); - goto send; - } - /* Check Hop Limit */ - if(UIP_IP_BUF->ttl <= 1) { - uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, - ICMP6_TIME_EXCEED_TRANSIT, 0); - UIP_STAT(++uip_stat.ip.drop); + if(!uip_check_mtu() || !uip_update_ttl()) { + /* Send ICMPv6 error, prepared by the function that just returned false */ goto send; } - UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1; - LOG_INFO("Forwarding packet towards "); + LOG_INFO("Forwarding packet to next hop "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_("\n"); UIP_STAT(++uip_stat.ip.forwarded); @@ -1247,35 +1252,20 @@ uip_process(uint8_t flag) UIP_STAT(++uip_stat.ip.drop); goto drop; } - - /* - * Next header field processing. In IPv6, we can have extension headers, - * they are processed here - */ - uip_next_hdr = &UIP_IP_BUF->proto; - uip_ext_len = 0; - uip_ext_bitmap = 0; #endif /* UIP_CONF_ROUTER */ #if UIP_IPV6_MULTICAST && UIP_CONF_ROUTER process: #endif /* UIP_IPV6_MULTICAST && UIP_CONF_ROUTER */ - while(1) { - switch(*uip_next_hdr){ -#if UIP_TCP - case UIP_PROTO_TCP: - /* TCP, for both IPv4 and IPv6 */ - goto tcp_input; -#endif /* UIP_TCP */ -#if UIP_UDP - case UIP_PROTO_UDP: - /* UDP, for both IPv4 and IPv6 */ - goto udp_input; -#endif /* UIP_UDP */ - case UIP_PROTO_ICMP6: - /* ICMPv6 */ - goto icmp6_input; + /* IPv6 extension header processing: loop until reaching upper-layer protocol */ + uip_ext_bitmap = 0; + for(next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); + next_header != NULL && uip_is_proto_ext_hdr(protocol); + next_header = uipbuf_get_next_header(next_header, uip_len - (next_header - uip_buf), &protocol, false)) { + + ext_ptr = (struct uip_ext_hdr *)next_header; + switch(protocol) { case UIP_PROTO_HBHO: LOG_DBG("Processing hbh header\n"); /* Hop by hop option header */ @@ -1287,145 +1277,140 @@ uip_process(uint8_t flag) uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO; } #endif /*UIP_CONF_IPV6_CHECKS*/ - switch(ext_hdr_options_process()) { + switch(ext_hdr_options_process(next_header)) { case 0: - /*continue*/ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; + break; /* done */ case 1: - /*silently discard*/ - goto drop; + goto drop; /* silently discard */ case 2: - /* send icmp error message (created in ext_hdr_options_process) - * and discard*/ - goto send; + goto send; /* send icmp error message (created in + ext_hdr_options_process) and discard */ } break; - case UIP_PROTO_DESTO: + case UIP_PROTO_DESTO: #if UIP_CONF_IPV6_CHECKS - /* Destination option header. if we saw two already, drop */ - LOG_DBG("Processing desto header\n"); - if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO1) { - if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO2) { - goto bad_hdr; - } else{ - uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO2; - } - } else { - uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO1; - } -#endif /*UIP_CONF_IPV6_CHECKS*/ - switch(ext_hdr_options_process()) { - case 0: - /*continue*/ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - case 1: - /*silently discard*/ - goto drop; - case 2: - /* send icmp error message (created in ext_hdr_options_process) - * and discard*/ - goto send; - } - break; - case UIP_PROTO_ROUTING: -#if UIP_CONF_IPV6_CHECKS - /* Routing header. If we saw one already, drop */ - if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_ROUTING) { - goto bad_hdr; - } else { - uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_ROUTING; - } -#endif /*UIP_CONF_IPV6_CHECKS*/ - /* - * Routing Header length field is in units of 8 bytes, excluding - * As per RFC2460 section 4.4, if routing type is unrecognized: - * if segments left = 0, ignore the header - * if segments left > 0, discard packet and send icmp error pointing - * to the routing type - */ - - LOG_DBG("Processing Routing header\n"); - if(UIP_ROUTING_BUF->seg_left > 0) { - if(NETSTACK_ROUTING.ext_header_srh_update()) { - - /* With routing header, the detination address is us and will - * be swapped later to the next hop. Because of this, the MTU - * and TTL were not checked and updated yet. Do this now. */ - - /* Check MTU */ - if(uip_len > UIP_LINK_MTU) { - uip_icmp6_error_output(ICMP6_PACKET_TOO_BIG, 0, UIP_LINK_MTU); - UIP_STAT(++uip_stat.ip.drop); - goto send; - } - /* Check Hop Limit */ - if(UIP_IP_BUF->ttl <= 1) { - uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, - ICMP6_TIME_EXCEED_TRANSIT, 0); - UIP_STAT(++uip_stat.ip.drop); - goto send; - } - UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1; - - LOG_INFO("Forwarding packet to next hop "); - LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); - LOG_INFO_("\n"); - UIP_STAT(++uip_stat.ip.forwarded); - - goto send; /* Proceed to forwarding */ - } - uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, UIP_IPH_LEN + uip_ext_len + 2); - UIP_STAT(++uip_stat.ip.drop); - LOG_ERR("unrecognized routing type"); - goto send; - } - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - case UIP_PROTO_FRAG: - /* Fragmentation header:call the reassembly function, then leave */ -#if UIP_CONF_IPV6_REASSEMBLY - LOG_INFO("Processing fragmentation header\n"); - uip_len = uip_reass(); - if(uip_len == 0) { - goto drop; - } - if(uip_reassflags & UIP_REASS_FLAG_ERROR_MSG){ - /* we are not done with reassembly, this is an error message */ - goto send; - } - /*packet is reassembled, reset the next hdr to the beginning - of the IP header and restart the parsing of the reassembled pkt*/ - LOG_INFO("Processing reassembled packet\n"); - uip_ext_len = 0; - uip_ext_bitmap = 0; - uip_next_hdr = &UIP_IP_BUF->proto; - break; -#else /* UIP_CONF_IPV6_REASSEMBLY */ - UIP_STAT(++uip_stat.ip.drop); - UIP_STAT(++uip_stat.ip.fragerr); - LOG_ERR("fragment dropped."); - goto drop; -#endif /* UIP_CONF_IPV6_REASSEMBLY */ - case UIP_PROTO_NONE: - goto drop; - default: + /* Destination option header. if we saw two already, drop */ + LOG_DBG("Processing desto header\n"); + if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO1) { + if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_DESTO2) { goto bad_hdr; + } else{ + uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO2; + } + } else { + uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO1; + } +#endif /*UIP_CONF_IPV6_CHECKS*/ + switch(ext_hdr_options_process(next_header)) { + case 0: + break; /* done */ + case 1: + goto drop; /* silently discard */ + case 2: + goto send; /* send icmp error message (created in + ext_hdr_options_process) and discard */ + } + break; + case UIP_PROTO_ROUTING: +#if UIP_CONF_IPV6_CHECKS + /* Routing header. If we saw one already, drop */ + if(uip_ext_bitmap & UIP_EXT_HDR_BITMAP_ROUTING) { + goto bad_hdr; + } else { + uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_ROUTING; + } +#endif /*UIP_CONF_IPV6_CHECKS*/ + /* + * Routing Header length field is in units of 8 bytes, excluding + * As per RFC2460 section 4.4, if routing type is unrecognized: + * if segments left = 0, ignore the header + * if segments left > 0, discard packet and send icmp error pointing + * to the routing type + */ + + LOG_DBG("Processing Routing header\n"); + if(((struct uip_routing_hdr *)ext_ptr)->seg_left > 0) { + /* Process source routing header */ + if(NETSTACK_ROUTING.ext_header_srh_update()) { + + /* The MTU and TTL were not checked and updated yet, because with + * a routing header, the IPv6 destination address was set to us + * even though we act only as forwarder. Check MTU and TTL now */ + if(!uip_check_mtu() || !uip_update_ttl()) { + /* Send ICMPv6 error, prepared by the function that just returned false */ + goto send; + } + + LOG_INFO("Forwarding packet to next hop "); + LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); + LOG_INFO_("\n"); + UIP_STAT(++uip_stat.ip.forwarded); + + goto send; /* Proceed to forwarding */ + } else { + LOG_ERR("Unrecognized routing type\n"); + goto bad_hdr; + } + } + break; + case UIP_PROTO_FRAG: + /* Fragmentation header:call the reassembly function, then leave */ +#if UIP_CONF_IPV6_REASSEMBLY + LOG_INFO("Processing fragmentation header\n"); + uip_len = uip_reass(&ext_ptr->next); + if(uip_len == 0) { + goto drop; + } + if(uip_reassflags & UIP_REASS_FLAG_ERROR_MSG) { + /* we are not done with reassembly, this is an error message */ + goto send; + } + /* packet is reassembled. Restart the parsing of the reassembled pkt */ + LOG_INFO("Processing reassembled packet\n"); + uip_ext_bitmap = 0; + next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); + break; +#else /* UIP_CONF_IPV6_REASSEMBLY */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.fragerr); + LOG_ERR("fragment dropped."); + goto drop; +#endif /* UIP_CONF_IPV6_REASSEMBLY */ + case UIP_PROTO_NONE: + goto drop; + default: + goto bad_hdr; } } + + /* Process upper-layer input */ + if(next_header != NULL) { + switch(protocol) { +#if UIP_TCP + case UIP_PROTO_TCP: + /* TCP, for both IPv4 and IPv6 */ + goto tcp_input; +#endif +#if UIP_UDP + case UIP_PROTO_UDP: + /* UDP, for both IPv4 and IPv6 */ + goto udp_input; +#endif + case UIP_PROTO_ICMP6: + /* ICMPv6 */ + goto icmp6_input; + } + } + bad_hdr: /* * RFC 2460 send error message parameterr problem, code unrecognized * next header, pointing to the next header field */ - uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER, (uint32_t)(uip_next_hdr - (uint8_t *)UIP_IP_BUF)); + uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER, (uint32_t)(next_header - uip_buf)); UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.protoerr); - LOG_ERR("unrecognized header"); + LOG_ERR("unrecognized header\n"); goto send; /* End of headers processing */ @@ -1466,7 +1451,7 @@ uip_process(uint8_t flag) LOG_ERR("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF->type); UIP_STAT(++uip_stat.icmp.drop); UIP_STAT(++uip_stat.icmp.typeerr); - uip_clear_buf(); + uipbuf_clear(); } if(uip_len > 0) { @@ -1481,7 +1466,7 @@ uip_process(uint8_t flag) /* UDP input processing. */ udp_input: - remove_ext_hdr(); + uip_remove_ext_hdr(); LOG_INFO("Receiving UDP packet\n"); @@ -1541,10 +1526,10 @@ uip_process(uint8_t flag) UIP_STAT(++uip_stat.udp.recv); uip_len = uip_len - UIP_IPUDPH_LEN; - uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN]; + uip_appdata = &uip_buf[UIP_IPUDPH_LEN]; uip_conn = NULL; uip_flags = UIP_NEWDATA; - uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN]; + uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN]; uip_slen = 0; UIP_UDP_APPCALL(); @@ -1558,8 +1543,7 @@ uip_process(uint8_t flag) /* For IPv6, the IP length field does not include the IPv6 IP header length. */ - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0x00; @@ -1575,7 +1559,7 @@ uip_process(uint8_t flag) uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &uip_udp_conn->ripaddr); uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr); - uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; + uip_appdata = &uip_buf[UIP_IPTCPH_LEN]; #if UIP_UDP_CHECKSUMS /* Calculate UDP checksum. */ @@ -1593,7 +1577,7 @@ uip_process(uint8_t flag) /* TCP input processing. */ tcp_input: - remove_ext_hdr(); + uip_remove_ext_hdr(); UIP_STAT(++uip_stat.tcp.recv); LOG_INFO("Receiving TCP packet\n"); @@ -1610,7 +1594,7 @@ uip_process(uint8_t flag) /* Make sure that the TCP port number is not zero. */ if(UIP_TCP_BUF->destport == 0 || UIP_TCP_BUF->srcport == 0) { - LOG_ERR("tcp: zero port."); + LOG_ERR("tcp: zero port\n"); goto drop; } @@ -1727,7 +1711,7 @@ uip_process(uint8_t flag) the remote end will retransmit the packet at a time when we have more spare connections. */ UIP_STAT(++uip_stat.tcp.syndrop); - LOG_ERR("tcp: found no unused connections."); + LOG_ERR("tcp: found no unused connections\n"); goto drop; } uip_conn = uip_connr; @@ -1758,7 +1742,7 @@ uip_process(uint8_t flag) /* Parse the TCP MSS option, if present. */ if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) { for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) { - opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c]; + opt = uip_buf[UIP_IPTCPH_LEN + c]; if(opt == TCP_OPT_END) { /* End of options. */ break; @@ -1766,10 +1750,10 @@ uip_process(uint8_t flag) ++c; /* NOP option. */ } else if(opt == TCP_OPT_MSS && - uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { + uip_buf[UIP_IPTCPH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { /* An MSS option with the right option length. */ - tmp16 = ((uint16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | - (uint16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c]; + tmp16 = ((uint16_t)uip_buf[UIP_IPTCPH_LEN + 2 + c] << 8) | + (uint16_t)uip_buf[UIP_IPTCPH_LEN + 3 + c]; uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16; @@ -1778,12 +1762,12 @@ uip_process(uint8_t flag) } else { /* All other options have a length field, so that we easily can skip past them. */ - if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { + if(uip_buf[UIP_IPTCPH_LEN + 1 + c] == 0) { /* If the length field is zero, the options are malformed and we don't process them further. */ break; } - c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c]; + c += uip_buf[UIP_IPTCPH_LEN + 1 + c]; } } } @@ -1945,7 +1929,7 @@ uip_process(uint8_t flag) /* Parse the TCP MSS option, if present. */ if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) { for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) { - opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c]; + opt = uip_buf[UIP_IPTCPH_LEN + c]; if(opt == TCP_OPT_END) { /* End of options. */ break; @@ -1953,10 +1937,10 @@ uip_process(uint8_t flag) ++c; /* NOP option. */ } else if(opt == TCP_OPT_MSS && - uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { + uip_buf[UIP_IPTCPH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { /* An MSS option with the right option length. */ - tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | - uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c]; + tmp16 = (uip_buf[UIP_IPTCPH_LEN + 2 + c] << 8) | + uip_buf[UIP_IPTCPH_LEN + 3 + c]; uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16; @@ -1965,12 +1949,12 @@ uip_process(uint8_t flag) } else { /* All other options have a length field, so that we easily can skip past them. */ - if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { + if(uip_buf[UIP_IPTCPH_LEN + 1 + c] == 0) { /* If the length field is zero, the options are malformed and we don't process them further. */ break; } - c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c]; + c += uip_buf[UIP_IPTCPH_LEN + 1 + c]; } } } @@ -1982,7 +1966,7 @@ uip_process(uint8_t flag) uip_add_rcv_nxt(1); uip_flags = UIP_CONNECTED | UIP_NEWDATA; uip_connr->len = 0; - uip_clear_buf(); + uipbuf_clear(); uip_slen = 0; UIP_APPCALL(); goto appsend; @@ -2084,7 +2068,7 @@ uip_process(uint8_t flag) When the application is called, the global variable uip_len contains the length of the incoming data. The application can access the incoming data through the global pointer - uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN + uip_appdata, which usually points UIP_IPTCPH_LEN bytes into the uip_buf array. If the application wishes to send any data, this data should be @@ -2153,7 +2137,7 @@ uip_process(uint8_t flag) packet had new data in it, we must send out a packet. */ if(uip_slen > 0 && uip_connr->len > 0) { /* Add the length of the IP and TCP headers. */ - uip_len = uip_connr->len + UIP_TCPIP_HLEN; + uip_len = uip_connr->len + UIP_IPTCPH_LEN; /* We always set the ACK flag in response packets. */ UIP_TCP_BUF->flags = TCP_ACK | TCP_PSH; /* Send the packet. */ @@ -2162,7 +2146,7 @@ uip_process(uint8_t flag) /* If there is no data to send, just send out a pure ACK if there is newdata. */ if(uip_flags & UIP_NEWDATA) { - uip_len = UIP_TCPIP_HLEN; + uip_len = UIP_IPTCPH_LEN; UIP_TCP_BUF->flags = TCP_ACK; goto tcp_send_noopts; } @@ -2290,8 +2274,7 @@ uip_process(uint8_t flag) UIP_IP_BUF->proto = UIP_PROTO_TCP; UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit; - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); UIP_TCP_BUF->urgp[0] = UIP_TCP_BUF->urgp[1] = 0; @@ -2306,8 +2289,7 @@ uip_process(uint8_t flag) #endif UIP_IP_BUF->flow = 0x00; send: - LOG_INFO("Sending packet with length %d (%d)\n", uip_len, - (UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]); + LOG_INFO("Sending packet with length %d (%d)\n", uip_len, uipbuf_get_len_field(UIP_IP_BUF)); UIP_STAT(++uip_stat.ip.sent); /* Return and let the caller do the actual transmission. */ @@ -2315,7 +2297,7 @@ uip_process(uint8_t flag) return; drop: - uip_clear_buf(); + uipbuf_clear(); uip_ext_bitmap = 0; uip_flags = 0; return; @@ -2339,18 +2321,16 @@ uip_send(const void *data, int len) int copylen; if(uip_sappdata != NULL) { - copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN - - (int)((char *)uip_sappdata - - (char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN])); + copylen = MIN(len, UIP_BUFSIZE - UIP_IPTCPH_LEN - + (int)((char *)uip_sappdata - (char *)UIP_TCP_PAYLOAD)); } else { - copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN); + copylen = MIN(len, UIP_BUFSIZE - UIP_IPTCPH_LEN); } if(copylen > 0) { uip_slen = copylen; if(data != uip_sappdata) { if(uip_sappdata == NULL) { - memcpy((char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN], - (data), uip_slen); + memcpy(UIP_TCP_PAYLOAD, (data), uip_slen); } else { memcpy(uip_sappdata, (data), uip_slen); } diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index c25e4523f..f7e8f4b06 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -30,7 +30,7 @@ * */ #include "contiki.h" -#include "uip.h" +#include "net/ipv6/uip.h" #include "net/ipv6/uipbuf.h" #include @@ -39,45 +39,141 @@ static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX]; static uint16_t uipbuf_default_attrs[UIPBUF_ATTR_MAX]; +/*---------------------------------------------------------------------------*/ +void +uipbuf_clear(void) +{ + uip_len = 0; + uip_ext_len = 0; + uip_last_proto = 0; + uipbuf_clear_attr(); +} +/*---------------------------------------------------------------------------*/ +bool +uipbuf_add_ext_hdr(int16_t len) +{ + if(len + uip_len <= UIP_LINK_MTU && len + uip_len >= 0) { + uip_ext_len += len; + uip_len += len; + return true; + } else { + return false; + } +} +/*---------------------------------------------------------------------------*/ +bool +uipbuf_set_len(uint16_t len) +{ + if(len <= UIP_LINK_MTU) { + uip_len = len; + return true; + } else { + return false; + } +} +/*---------------------------------------------------------------------------*/ +void +uipbuf_set_len_field(struct uip_ip_hdr *hdr, uint16_t len) +{ + hdr->len[0] = (len >> 8); + hdr->len[1] = (len & 0xff); +} +/*---------------------------------------------------------------------------*/ +uint16_t +uipbuf_get_len_field(struct uip_ip_hdr *hdr) +{ + return ((uint16_t)(hdr->len[0]) << 8) + hdr->len[1]; +} /*---------------------------------------------------------------------------*/ /* Get the next header given the buffer - start indicates that this is start of the IPv6 header - needs to be set to 0 when in an ext hdr */ -uint8_t* -uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_t start) +uint8_t * +uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, bool start) { - int ext_len = 0; - struct uip_ip_hdr *ipbuf = (struct uip_ip_hdr *) buffer; - struct uip_ext_hdr *ext = NULL; + int curr_hdr_len = 0; + int next_hdr_len = 0; + uint8_t *next_header = NULL; + struct uip_ip_hdr *ipbuf = NULL; + struct uip_ext_hdr *curr_ext = NULL; + struct uip_ext_hdr *next_ext = NULL; if(start) { /* protocol in the IP buffer */ + ipbuf = (struct uip_ip_hdr *)buffer; *protocol = ipbuf->proto; - return buffer + UIP_IPH_LEN; + curr_hdr_len = UIP_IPH_LEN; } else { /* protocol in the Ext hdr */ - ext = (struct uip_ext_hdr *) buffer; - *protocol = ext->next; + curr_ext = (struct uip_ext_hdr *)buffer; + *protocol = curr_ext->next; /* This is just an ext header */ - ext_len = (ext->len << 3) + 8; - return buffer + ext_len; + curr_hdr_len = (curr_ext->len << 3) + 8; } + + /* Check first if enough space for current header */ + if(curr_hdr_len > size) { + return NULL; + } + next_header = buffer + curr_hdr_len; + + /* Check if the buffer is large enough for the next header */ + if(uip_is_proto_ext_hdr(*protocol)) { + next_ext = (struct uip_ext_hdr *)next_header; + next_hdr_len = (next_ext->len << 3) + 8; + } else { + if(*protocol == UIP_PROTO_TCP) { + next_hdr_len = UIP_TCPH_LEN; + } else if(*protocol == UIP_PROTO_UDP) { + next_hdr_len = UIP_UDPH_LEN; + } else if(*protocol == UIP_PROTO_ICMP6) { + next_hdr_len = UIP_ICMPH_LEN; + } + } + + /* Size must be enough to hold both the current and next header */ + if(next_hdr_len == 0 || curr_hdr_len + next_hdr_len > size) { + return NULL; + } + + return next_header; } /*---------------------------------------------------------------------------*/ /* Get the final header given the buffer - that is assumed to be at start of an IPv6 header */ -uint8_t* +uint8_t * uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol) { uint8_t *nbuf; - nbuf = uipbuf_get_next_header(buffer, size, protocol, 1); - while(uip_is_proto_ext_hdr(*protocol)) { - /* send in and move beyond the ext hdr */ - nbuf = uipbuf_get_next_header(nbuf, size - (nbuf - buffer), protocol, 0); + nbuf = uipbuf_get_next_header(buffer, size, protocol, true); + while(nbuf != NULL && uip_is_proto_ext_hdr(*protocol)) { + /* move to the ext hdr */ + nbuf = uipbuf_get_next_header(nbuf, size - (nbuf - buffer), protocol, false); } + + /* In case the buffer wasn't large enough for all headers, return NULL */ return nbuf; } /*---------------------------------------------------------------------------*/ +uint8_t * +uipbuf_search_header(uint8_t *buffer, uint16_t size, uint8_t protocol) +{ + uint8_t *nbuf; + uint8_t next_proto; + + nbuf = uipbuf_get_next_header(buffer, size, &next_proto, true); + while(nbuf != NULL && next_proto != protocol && uip_is_proto_ext_hdr(next_proto)) { + /* move to the ext hdr */ + nbuf = uipbuf_get_next_header(nbuf, size - (nbuf - buffer), &next_proto, false); + } + + if(next_proto == protocol) { + return nbuf; + } else { + return NULL; + } +} +/*---------------------------------------------------------------------------*/ /** * Common functions for uipbuf (attributes, etc). * diff --git a/os/net/ipv6/uipbuf.h b/os/net/ipv6/uipbuf.h index 6af4e590b..fdea60b28 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -34,6 +34,40 @@ #define UIPBUF_H_ #include "contiki.h" +struct uip_ip_hdr; + +/** + * \brief Resets uIP buffer + */ +void uipbuf_clear(void); + +/** + * \brief Update uip buffer length for addition of an extension header + * \param len The length of the new extension header + * \retval true if the length fields were successfully set, false otherwise + */ +bool uipbuf_add_ext_hdr(int16_t len); + +/** + * \brief Set the length of the uIP buffer + * \param len The new length + * \retval true if the len was successfully set, false otherwise + */ +bool uipbuf_set_len(uint16_t len); + +/** + * \brief Updates the length field in the uIP buffer + * \param buffer The IPv6 header + * \param len The new length value + */ +void uipbuf_set_len_field(struct uip_ip_hdr *hdr, uint16_t len); + +/** + * \brief Returns the value of the length field in the uIP buffer + * \param buffer The IPv6 header + * \retvel The length value + */ +uint16_t uipbuf_get_len_field(struct uip_ip_hdr *hdr); /** * \brief Get the next IPv6 header. @@ -41,11 +75,11 @@ * \param size The size of the data in the buffer * \param protocol A pointer to a variable where the protocol of the header will be stored * \param start A flag that indicates if this is expected to be the IPv6 packet header or a later header (Extension header) - * \retval returns address of the starting position of the next header + * \retval returns address of the next header, or NULL in case of insufficient buffer space * * This function moves to the next header in a IPv6 packet. */ -uint8_t* uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_t start); +uint8_t *uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, bool start); /** @@ -53,12 +87,22 @@ uint8_t* uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protoco * \param buffer A pointer to the buffer holding the IPv6 packet * \param size The size of the data in the buffer * \param protocol A pointer to a variable where the protocol of the header will be stored - * \retval returns address of the starting position of the next header + * \retval returns address of the last header, or NULL in case of insufficient buffer space * * This function moves to the last header of the IPv6 packet. */ -uint8_t* uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol); +uint8_t *uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol); +/** + * \brief Get an IPv6 header with a given protocol field. + * \param buffer A pointer to the buffer holding the IPv6 packet + * \param size The size of the data in the buffer + * \param protocol The protocol we are looking for + * \retval returns address of the header if found, else NULL + * + * This function moves to the last header of the IPv6 packet. + */ +uint8_t *uipbuf_search_header(uint8_t *buffer, uint16_t size, uint8_t protocol); /** * \brief Get the value of the attribute diff --git a/os/net/ipv6/uiplib.c b/os/net/ipv6/uiplib.c index a6d8b4f0c..e4a7a49b7 100644 --- a/os/net/ipv6/uiplib.c +++ b/os/net/ipv6/uiplib.c @@ -56,7 +56,6 @@ #define LOG_LEVEL LOG_LEVEL_NONE /*---------------------------------------------------------------------------*/ -#if NETSTACK_CONF_WITH_IPV6 int uiplib_ip6addrconv(const char *addrstr, uip_ip6addr_t *ipaddr) { @@ -118,7 +117,6 @@ uiplib_ip6addrconv(const char *addrstr, uip_ip6addr_t *ipaddr) return 1; } -#endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ /* Parse a IPv4-address from a string. Returns the number of characters read * for the address. */ diff --git a/os/net/ipv6/uiplib.h b/os/net/ipv6/uiplib.h index b30a1bcb5..aaf91282f 100644 --- a/os/net/ipv6/uiplib.h +++ b/os/net/ipv6/uiplib.h @@ -68,11 +68,7 @@ * \retval 0 If the IP address could not be parsed. * \retval Non-zero If the IP address was parsed. */ -#if NETSTACK_CONF_WITH_IPV6 #define uiplib_ipaddrconv uiplib_ip6addrconv -#else /* NETSTACK_CONF_WITH_IPV6 */ -#define uiplib_ipaddrconv uiplib_ip4addrconv -#endif /* NETSTACK_CONF_WITH_IPV6 */ int uiplib_ip4addrconv(const char *addrstr, uip_ip4addr_t *addr); int uiplib_ip6addrconv(const char *addrstr, uip_ip6addr_t *addr); diff --git a/os/net/ipv6/uipopt.h b/os/net/ipv6/uipopt.h index 15c79e20a..a75c59ea0 100644 --- a/os/net/ipv6/uipopt.h +++ b/os/net/ipv6/uipopt.h @@ -121,26 +121,6 @@ * @{ */ -/** - * The link level header length. - * - * This is the offset into the uip_buf where the IP header can be - * found. For Ethernet, this should be set to 14. For SLIP, this - * should be set to 0. - * - * \note we probably won't use this constant for other link layers than - * ethernet as they have variable header length (this is due to variable - * number and type of address fields and to optional security features) - * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14 - * 802.11 -> 4 + (6*3/4) + 2 - * \hideinitializer - */ -#ifdef UIP_CONF_LLH_LEN -#define UIP_LLH_LEN (UIP_CONF_LLH_LEN) -#else /* UIP_LLH_LEN */ -#define UIP_LLH_LEN 0 -#endif /* UIP_CONF_LLH_LEN */ - /** * The size of the uIP packet buffer. * @@ -151,12 +131,11 @@ * \hideinitializer */ #ifndef UIP_CONF_BUFFER_SIZE -#define UIP_BUFSIZE (UIP_LINK_MTU + UIP_LLH_LEN) +#define UIP_BUFSIZE (UIP_LINK_MTU) #else /* UIP_CONF_BUFFER_SIZE */ #define UIP_BUFSIZE (UIP_CONF_BUFFER_SIZE) #endif /* UIP_CONF_BUFFER_SIZE */ - /** * Determines if statistics support should be compiled in. * @@ -248,11 +227,6 @@ void uip_log(char *msg); /** The maximum transmission unit at the IP Layer*/ #define UIP_LINK_MTU 1280 -#ifndef NETSTACK_CONF_WITH_IPV6 -/** Do we use IPv6 or not (default: no) */ -#define NETSTACK_CONF_WITH_IPV6 0 -#endif - #ifndef UIP_CONF_IPV6_QUEUE_PKT /** Do we do per %neighbor queuing during address resolution (default: no) */ #define UIP_CONF_IPV6_QUEUE_PKT 0 @@ -440,15 +414,15 @@ void uip_log(char *msg); * The TCP maximum segment size. * * This is should not be to set to more than - * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. + * UIP_BUFSIZE - UIP_IPTCPH_LEN. */ #ifdef UIP_CONF_TCP_MSS -#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_IPTCPH_LEN) #error UIP_CONF_TCP_MSS is too large for the current UIP_BUFSIZE -#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) */ +#endif /* UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_IPTCPH_LEN) */ #define UIP_TCP_MSS (UIP_CONF_TCP_MSS) #else /* UIP_CONF_TCP_MSS */ -#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_IPTCPH_LEN) #endif /* UIP_CONF_TCP_MSS */ /** diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index fcc548f89..ebea0fd8a 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -547,5 +547,4 @@ csma_output_init(void) memb_init(&packet_memb); memb_init(&metadata_memb); memb_init(&neighbor_memb); - queuebuf_init(); } diff --git a/os/net/mac/tsch/tsch-const.h b/os/net/mac/tsch/tsch-const.h index f78b9883d..c4712ce2d 100644 --- a/os/net/mac/tsch/tsch-const.h +++ b/os/net/mac/tsch/tsch-const.h @@ -77,9 +77,7 @@ /* The approximate number of slots per second */ #define TSCH_SLOTS_PER_SECOND (1000000 / tsch_timing_us[tsch_ts_timeslot_length]) -/* Calculate packet tx/rx duration in rtimer ticks based on sent - * packet len in bytes with 802.15.4 250kbps data rate. - * One byte = 32us. Add two bytes for CRC and one for len field */ +/* Calculate packet tx/rx duration in rtimer ticks based on packet length in bytes. */ #define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(RADIO_BYTE_AIR_TIME * ((len) + RADIO_PHY_OVERHEAD)) /* Convert rtimer ticks to clock and vice versa */ diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 841dee07f..a801bc92e 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -643,6 +643,8 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) mac_tx_status = MAC_TX_ERR; } } + } else { + mac_tx_status = MAC_TX_ERR; } } diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 8c79c299c..a33feeef1 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -243,11 +243,49 @@ tsch_reset(void) } /* TSCH keep-alive functions */ +/*---------------------------------------------------------------------------*/ +/* Resynchronize to last_eb_nbr. + * Return non-zero if this function schedules the next keepalive. + * Return zero otherwise. + */ +static int +resynchronize(const linkaddr_t *original_time_source_addr) +{ + const struct tsch_neighbor *current_time_source = tsch_queue_get_time_source(); + if(current_time_source && !linkaddr_cmp(¤t_time_source->addr, original_time_source_addr)) { + /* Time source has already been changed (e.g. by RPL). Let's see if it works. */ + LOG_INFO("time source has been changed to "); + LOG_INFO_LLADDR(¤t_time_source->addr); + LOG_INFO_("\n"); + return 0; + } + /* Switch time source to the last neighbor we received an EB from */ + if(linkaddr_cmp(&last_eb_nbr_addr, &linkaddr_null)) { + LOG_WARN("not able to re-synchronize, received no EB from other neighbors\n"); + if(sync_count == 0) { + /* We got no synchronization at all in this session, leave the network */ + tsch_disassociate(); + } + return 0; + } else { + LOG_WARN("re-synchronizing on "); + LOG_WARN_LLADDR(&last_eb_nbr_addr); + LOG_WARN_("\n"); + /* We simply pick the last neighbor we receiver sync information from */ + tsch_queue_update_time_source(&last_eb_nbr_addr); + tsch_join_priority = last_eb_nbr_jp + 1; + /* Try to get in sync ASAP */ + tsch_schedule_keepalive_immediately(); + return 1; + } +} + /*---------------------------------------------------------------------------*/ /* Tx callback for keepalive messages */ static void keepalive_packet_sent(void *ptr, int status, int transmissions) { + int schedule_next_keepalive = 1; /* Update neighbor link statistics */ link_stats_packet_sent(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), status, transmissions); /* Call RPL callback if RPL is enabled */ @@ -258,28 +296,14 @@ keepalive_packet_sent(void *ptr, int status, int transmissions) LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); LOG_INFO_(", st %d-%d\n", status, transmissions); - /* We got no ack, try to recover by switching to the last neighbor we received an EB from */ + /* We got no ack, try to resynchronize */ if(status == MAC_TX_NOACK) { - if(linkaddr_cmp(&last_eb_nbr_addr, &linkaddr_null)) { - LOG_WARN("not able to re-synchronize, received no EB from other neighbors\n"); - if(sync_count == 0) { - /* We got no synchronization at all in this session, leave the network */ - tsch_disassociate(); - } - } else { - LOG_WARN("re-synchronizing on "); - LOG_WARN_LLADDR(&last_eb_nbr_addr); - LOG_WARN_("\n"); - /* We simply pick the last neighbor we receiver sync information from */ - tsch_queue_update_time_source(&last_eb_nbr_addr); - tsch_join_priority = last_eb_nbr_jp + 1; - /* Try to get in sync ASAP */ - tsch_schedule_keepalive_immediately(); - return; - } + schedule_next_keepalive = !resynchronize(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); } - tsch_schedule_keepalive(); + if(schedule_next_keepalive) { + tsch_schedule_keepalive(); + } } /*---------------------------------------------------------------------------*/ /* Prepare and send a keepalive message */ @@ -948,8 +972,7 @@ tsch_init(void) return; } - /* Init the queuebuf and TSCH sub-modules */ - queuebuf_init(); + /* Init TSCH sub-modules */ tsch_reset(); tsch_queue_init(); tsch_schedule_init(); diff --git a/os/net/queuebuf.h b/os/net/queuebuf.h index 60216465d..ef66da780 100644 --- a/os/net/queuebuf.h +++ b/os/net/queuebuf.h @@ -55,6 +55,12 @@ #include "net/packetbuf.h" +#ifdef QUEUEBUF_CONF_ENABLED +#define QUEUEBUF_ENABLED QUEUEBUF_CONF_ENABLED +#else /* QUEUEBUF_CONF_ENABLED */ +#define QUEUEBUF_ENABLED 1 +#endif /* QUEUEBUF_CONF_ENABLED */ + /* QUEUEBUF_NUM is the total number of queuebuf */ #ifdef QUEUEBUF_CONF_NUM #define QUEUEBUF_NUM QUEUEBUF_CONF_NUM diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index bb1399fbb..318cd1baa 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -107,7 +107,7 @@ static void ext_header_remove(void) { #if NETSTACK_CONF_WITH_IPV6 - uip_ext_len = 0; + uip_remove_ext_hdr(); #endif /* NETSTACK_CONF_WITH_IPV6 */ } /*---------------------------------------------------------------------------*/ @@ -118,7 +118,7 @@ ext_header_update(void) } /*---------------------------------------------------------------------------*/ static int -ext_header_hbh_update(int uip_ext_opt_offset) +ext_header_hbh_update(uint8_t *ext_buf, int opt_offset) { return 1; } diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h index 7fe6e7ca8..4508f0c4e 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -131,12 +131,13 @@ struct routing_driver { * Process and update the routing protocol hob-by-hop * extention headers of the current uIP packet. * - * \param uip_ext_opt_offset The offset within the uIP packet where - * extension headers start + * \param ext_buf A pointer to the ext header buffer + * \param opt_offset The offset within the extension header where + * the option starts * \return 1 in case the packet is valid and to be processed further, * 0 in case the packet must be dropped. */ - int (* ext_header_hbh_update)(int uip_ext_opt_offset); + int (* ext_header_hbh_update)(uint8_t *ext_buf, int opt_offset); /** * Process and update SRH in-place, * i.e. internal address swapping as per RFC6554 diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index cbaee6959..58f758048 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -126,7 +126,7 @@ rpl_get_nbr(rpl_parent_t *parent) { const linkaddr_t *lladdr = rpl_get_parent_lladdr(parent); if(lladdr != NULL) { - return nbr_table_get_from_lladdr(ds6_neighbors, lladdr); + return uip_ds6_nbr_ll_lookup((const uip_lladdr_t *)lladdr); } else { return NULL; } @@ -145,9 +145,9 @@ rpl_dag_init(void) } /*---------------------------------------------------------------------------*/ rpl_parent_t * -rpl_get_parent(uip_lladdr_t *addr) +rpl_get_parent(const uip_lladdr_t *addr) { - rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (linkaddr_t *)addr); + rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (const linkaddr_t *)addr); return p; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 8488d5ac6..34d9b4907 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -60,46 +60,35 @@ #include #include -/*---------------------------------------------------------------------------*/ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN]) -#define UIP_RH_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_RPL_SRH_BUF ((struct uip_rpl_srh_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_RH_LEN]) -#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int uip_ext_opt_offset) +rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset) { rpl_instance_t *instance; int down; uint16_t sender_rank; uint8_t sender_closer; uip_ds6_route_t *route; - rpl_parent_t *sender = NULL; + rpl_parent_t *sender; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)ext_buf; + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(ext_buf + opt_offset); - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL - || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { + if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || rpl_opt->opt_type != UIP_EXT_HDR_OPT_RPL + || rpl_opt->opt_len != RPL_HDR_OPT_LEN) { LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n", - UIP_HBHO_BUF->len, - UIP_EXT_HDR_OPT_RPL_BUF->opt_type, - UIP_EXT_HDR_OPT_RPL_BUF->opt_len); + hbh_hdr->len, rpl_opt->opt_type, rpl_opt->opt_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); + instance = rpl_get_instance(rpl_opt->instance); if(instance == NULL) { - LOG_ERR("Unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF->instance); + LOG_ERR("Unknown instance: %u\n", rpl_opt->instance); return 0; } - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) { + if(rpl_opt->flags & RPL_HDR_OPT_FWD_ERR) { LOG_ERR("Forward error!\n"); /* We should try to repair it by removing the neighbor that caused the packet to be forwareded in the first place. We drop any @@ -123,14 +112,14 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) return 0; } down = 0; - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) { + if(rpl_opt->flags & RPL_HDR_OPT_DOWN) { down = 1; } - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank); + sender_rank = UIP_HTONS(rpl_opt->senderrank); sender = nbr_table_get_from_lladdr(rpl_parents, packetbuf_addr(PACKETBUF_ADDR_SENDER)); - if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR)) { + if(sender != NULL && (rpl_opt->flags & RPL_HDR_OPT_RANK_ERR)) { /* A rank error was signalled, attempt to repair it by updating * the sender's rank from ext header */ sender->rank = sender_rank; @@ -160,7 +149,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) instance->unicast_dio_target = sender; rpl_schedule_unicast_dio_immediately(instance); } - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) { + if(rpl_opt->flags & RPL_HDR_OPT_RANK_ERR) { RPL_STAT(rpl_stats.loop_errors++); LOG_ERR(" Rank error signalled in RPL option!\n"); /* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */ @@ -169,7 +158,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) } LOG_WARN("Single error tolerated\n"); RPL_STAT(rpl_stats.loop_warnings++); - UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR; + rpl_opt->flags |= RPL_HDR_OPT_RANK_ERR; return 1; } @@ -181,41 +170,19 @@ int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) { #if RPL_WITH_NON_STORING - uint8_t *uip_next_hdr; - int last_uip_ext_len = uip_ext_len; + struct uip_routing_hdr *rh_header; rpl_dag_t *dag; uip_sr_node_t *dest_node; uip_sr_node_t *root_node; - uip_ext_len = 0; - uip_next_hdr = &UIP_IP_BUF->proto; - - /* Look for routing header */ - while(uip_next_hdr != NULL && *uip_next_hdr != UIP_PROTO_ROUTING) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, only the Hop-by-Hop Options header and - * Destination Options header can appear before the Routing - * header. - */ - /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } + /* Look for routing ext header */ + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); dag = rpl_get_dag(&UIP_IP_BUF->destipaddr); root_node = uip_sr_get_node(dag, &dag->dag_id); dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr); - if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING - && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) || + if((rh_header != NULL && rh_header->routing_type == RPL_RH_TYPE_SRH) || (dest_node != NULL && root_node != NULL && dest_node->parent == root_node)) { /* Routing header found or the packet destined for a direct child of the root. @@ -224,11 +191,9 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) * forwarding to next hop */ uip_ipaddr_copy(ipaddr, &UIP_IP_BUF->destipaddr); uip_create_linklocal_prefix(ipaddr); - uip_ext_len = last_uip_ext_len; return 1; } - uip_ext_len = last_uip_ext_len; return 0; #else /* RPL_WITH_NON_STORING */ return 0; /* SRH not found */ @@ -239,34 +204,13 @@ int rpl_ext_header_srh_update(void) { #if RPL_WITH_NON_STORING - uint8_t *uip_next_hdr; - int last_uip_ext_len = uip_ext_len; + struct uip_routing_hdr *rh_header; + struct uip_rpl_srh_hdr *srh_header; - uip_ext_len = 0; - uip_next_hdr = &UIP_IP_BUF->proto; + /* Look for routing ext header */ + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); - /* Look for routing header */ - while(uip_next_hdr != NULL && *uip_next_hdr != UIP_PROTO_ROUTING) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, only the Hop-by-Hop Options header and - * Destination Options header can appear before the Routing - * header. - */ - /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } - - if(uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING - && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) { + if(rh_header != NULL && rh_header->routing_type == RPL_RH_TYPE_SRH) { /* SRH found, now look for next hop */ uint8_t cmpri, cmpre; uint8_t ext_len; @@ -275,11 +219,12 @@ rpl_ext_header_srh_update(void) uint8_t segments_left; uip_ipaddr_t current_dest_addr; - segments_left = UIP_RH_BUF->seg_left; - ext_len = (UIP_RH_BUF->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF->pad >> 4; + srh_header = (struct uip_rpl_srh_hdr *)(((uint8_t *)rh_header) + RPL_RH_LEN); + segments_left = rh_header->seg_left; + ext_len = rh_header->len * 8 + 8; + cmpri = srh_header->cmpr >> 4; + cmpre = srh_header->cmpr & 0x0f; + padding = srh_header->pad >> 4; path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1; (void)path_len; @@ -290,7 +235,7 @@ rpl_ext_header_srh_update(void) /* We are the final destination, do nothing */ } else { uint8_t i = path_len - segments_left; /* The index of the next address to be visited */ - uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri)); + uint8_t *addr_ptr = ((uint8_t *)rh_header) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri)); uint8_t cmpr = segments_left == 1 ? cmpre : cmpri; /* As per RFC6554: swap the IPv6 destination address and address[i] */ @@ -303,17 +248,15 @@ rpl_ext_header_srh_update(void) memcpy(addr_ptr, ((uint8_t *)¤t_dest_addr) + cmpr, 16 - cmpr); /* Update segments left field */ - UIP_RH_BUF->seg_left--; + rh_header->seg_left--; LOG_INFO("SRH next hop "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_("\n"); } - uip_ext_len = last_uip_ext_len; return 1; } - uip_ext_len = last_uip_ext_len; return 0; #else /* RPL_WITH_NON_STORING */ return 0; /* SRH not found */ @@ -336,7 +279,6 @@ static int insert_srh_header(void) { /* Implementation of RFC6554 */ - uint8_t temp_len; uint8_t path_len; uint8_t ext_len; uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ @@ -348,6 +290,10 @@ insert_srh_header(void) rpl_dag_t *dag; uip_ipaddr_t node_addr; + /* Always insest SRH as first extension header */ + struct uip_routing_hdr *rh_hdr = (struct uip_routing_hdr *)UIP_IP_PAYLOAD(0); + struct uip_rpl_srh_hdr *srh_hdr = (struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(0) + RPL_RH_LEN); + LOG_INFO("SRH creating source routing header with destination "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_("\n"); @@ -418,33 +364,33 @@ insert_srh_header(void) path_len, cmpri, cmpre, ext_len, padding); /* Check if there is enough space to store the extension header */ - if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) { + if(uip_len + ext_len > UIP_LINK_MTU) { LOG_ERR("Packet too long: impossible to add source routing header (%u bytes)\n", ext_len); return 0; } - /* Move existing ext headers and payload uip_ext_len further */ - memmove(uip_buf + uip_l2_l3_hdr_len + ext_len, - uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN); - memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); + /* Move existing ext headers and payload ext_len further */ + memmove(uip_buf + UIP_IPH_LEN + uip_ext_len + ext_len, + uip_buf + UIP_IPH_LEN + uip_ext_len, uip_len - UIP_IPH_LEN); + memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len); - /* Insert source routing header */ - UIP_RH_BUF->next = UIP_IP_BUF->proto; + /* Insert source routing header (as first ext header) */ + rh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF->len = (ext_len - 8) / 8; - UIP_RH_BUF->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF->seg_left = path_len; + rh_hdr->len = (ext_len - 8) / 8; + rh_hdr->routing_type = RPL_RH_TYPE_SRH; + rh_hdr->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF->pad = padding << 4; + srh_hdr->cmpr = (cmpri << 4) + cmpre; + srh_hdr->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ node = dest_node; - hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */ + hop_ptr = ((uint8_t *)rh_hdr) + ext_len - padding; /* Pointer where to write the next hop compressed address */ while(node != NULL && node->parent != root_node) { NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); @@ -459,15 +405,9 @@ insert_srh_header(void) NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr); - /* In-place update of IPv6 length field */ - temp_len = UIP_IP_BUF->len[1]; - UIP_IP_BUF->len[1] += ext_len; - if(UIP_IP_BUF->len[1] < temp_len) { - UIP_IP_BUF->len[0]++; - } - - uip_ext_len += ext_len; - uip_len += ext_len; + /* Update the IPv6 length field */ + uipbuf_add_ext_hdr(ext_len); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); return 1; } @@ -476,44 +416,37 @@ static int update_hbh_header(void) { rpl_instance_t *instance; - int uip_ext_opt_offset; - int last_uip_ext_len; rpl_parent_t *parent; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0); + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(0) + 2); - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - uip_ext_opt_offset = 2; + if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && rpl_opt->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || rpl_opt->opt_len != RPL_HDR_OPT_LEN) { - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { - - LOG_ERR("Hop-by-hop extension header has wrong size (%u %u)\n", - UIP_EXT_HDR_OPT_RPL_BUF->opt_len, - uip_ext_len); + LOG_ERR("Hop-by-hop extension header has wrong size (%u)\n", rpl_opt->opt_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); + instance = rpl_get_instance(rpl_opt->instance); if(instance == NULL || !instance->used || !instance->current_dag->joined) { LOG_ERR("Unable to add/update hop-by-hop extension header: incorrect instance\n"); - uip_ext_len = last_uip_ext_len; return 0; /* Drop */ } LOG_INFO("Updating RPL option\n"); /* Update sender rank and instance, will update flags next */ - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id; + rpl_opt->senderrank = UIP_HTONS(instance->current_dag->rank); + rpl_opt->instance = instance->instance_id; if(RPL_IS_STORING(instance)) { /* In non-storing mode, downwards traffic does not have the HBH option */ /* Check the direction of the down flag, as per Section 11.2.2.3, which states that if a packet is going down it should in general not go back up again. If this happens, a RPL_HDR_OPT_FWD_ERR should be flagged. */ - if((UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN)) { + if((rpl_opt->flags & RPL_HDR_OPT_DOWN)) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { - UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR; + rpl_opt->flags |= RPL_HDR_OPT_FWD_ERR; LOG_WARN("RPL forwarding error\n"); /* We should send back the packet to the originating parent, but it is not feasible yet, so we send a No-Path DAO instead */ @@ -532,63 +465,51 @@ update_hbh_header(void) if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { /* No route was found, so this packet will go towards the RPL root. If so, we should not set the down flag. */ - UIP_EXT_HDR_OPT_RPL_BUF->flags &= ~RPL_HDR_OPT_DOWN; + rpl_opt->flags &= ~RPL_HDR_OPT_DOWN; LOG_DBG("RPL option going up\n"); } else { /* A DAO route was found so we set the down flag. */ - UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_DOWN; + rpl_opt->flags |= RPL_HDR_OPT_DOWN; LOG_DBG("RPL option going down\n"); } } } } - uip_ext_len = last_uip_ext_len; return 1; } /*---------------------------------------------------------------------------*/ static int insert_hbh_header(const rpl_instance_t *instance) { - int uip_ext_opt_offset; - int last_uip_ext_len; - uint8_t temp_len; - - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - uip_ext_opt_offset = 2; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0); + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2)); /* Insert hop-by-hop header */ LOG_DBG("Creating hop-by-hop option\n"); - if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { + if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_LINK_MTU) { LOG_ERR("Packet too long: impossible to add hop-by-hop option\n"); - uip_ext_len = last_uip_ext_len; return 0; } - /* Move existing ext headers and payload UIP_EXT_BUF further */ - memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN); - memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN); + /* Move existing ext headers and payload RPL_HOP_BY_HOP_LEN further */ + memmove(UIP_IP_PAYLOAD(RPL_HOP_BY_HOP_LEN), UIP_IP_PAYLOAD(0), uip_len - UIP_IPH_LEN); + memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); - /* Update IP and HBH protocol and fields */ - UIP_HBHO_BUF->next = UIP_IP_BUF->proto; + /* Insert HBH header (as first ext header) */ + hbh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id; - uip_len += RPL_HOP_BY_HOP_LEN; - temp_len = UIP_IP_BUF->len[1]; - UIP_IP_BUF->len[1] += RPL_HOP_BY_HOP_LEN; - if(UIP_IP_BUF->len[1] < temp_len) { - UIP_IP_BUF->len[0]++; - } + hbh_hdr->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; + rpl_opt->opt_type = UIP_EXT_HDR_OPT_RPL; + rpl_opt->opt_len = RPL_HDR_OPT_LEN; + rpl_opt->flags = 0; + rpl_opt->senderrank = UIP_HTONS(instance->current_dag->rank); + rpl_opt->instance = instance->instance_id; - uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; + uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); /* Update header before returning */ return update_hbh_header(); @@ -597,52 +518,33 @@ insert_hbh_header(const rpl_instance_t *instance) void rpl_ext_header_remove(void) { - uint8_t temp_len; - uint8_t rpl_ext_hdr_len; - int uip_ext_opt_offset; - uint8_t *uip_next_hdr; + uint8_t *prev_proto_ptr; + uint8_t protocol; + uint8_t ext_len; + uint8_t *next_header; + struct uip_ext_hdr *ext_ptr; + struct uip_ext_hdr_opt *opt_ptr; - uip_ext_len = 0; - uip_ext_opt_offset = 2; - uip_next_hdr = &UIP_IP_BUF->proto; - - /* Look for hop-by-hop and routing headers */ - while(uip_next_hdr != NULL) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_ROUTING: - if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) { - /* Remove hop-by-hop and routing headers */ - *uip_next_hdr = UIP_EXT_BUF->next; - rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8; - temp_len = UIP_IP_BUF->len[1]; - uip_len -= rpl_ext_hdr_len; - UIP_IP_BUF->len[1] -= rpl_ext_hdr_len; - if(UIP_IP_BUF->len[1] > temp_len) { - UIP_IP_BUF->len[0]--; - } - LOG_DBG("Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len); - memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN); - } else { - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - } - break; - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, any header other than the Destination - * Options header does not appear between the Hop-by-Hop - * Options header and the Routing header. - * - * We're moving to the next header only if uip_next_hdr has - * UIP_PROTO_DESTO. Otherwise, we'll return. - */ - /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - return; + next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); + ext_ptr = (struct uip_ext_hdr *)next_header; + prev_proto_ptr = &UIP_IP_BUF->proto; + while(next_header != NULL && uip_is_proto_ext_hdr(protocol)) { + opt_ptr = (struct uip_ext_hdr_opt *)(next_header + 2); + if(protocol == UIP_PROTO_ROUTING || (protocol == UIP_PROTO_HBHO && opt_ptr->type == UIP_EXT_HDR_OPT_RPL)) { + /* Remove ext header */ + *prev_proto_ptr = ext_ptr->next; + ext_len = ext_ptr->len * 8 + 8; + uipbuf_add_ext_hdr(-ext_len); + /* Update length field and rest of packer to the "left" */ + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); + memmove(next_header, next_header + ext_len, uip_len - (next_header - uip_buf)); + /* Update loop variables */ + protocol = *prev_proto_ptr; + } else { + /* move to the ext hdr */ + next_header = uipbuf_get_next_header(next_header, uip_len - (next_header - uip_buf), &protocol, false); + ext_ptr = (struct uip_ext_hdr *)next_header; + prev_proto_ptr = &ext_ptr->next; } } } diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index a246e576e..baa6b08a7 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -70,9 +70,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) /*---------------------------------------------------------------------------*/ static void dis_input(void); static void dio_input(void); @@ -251,7 +248,7 @@ dis_input(void) } } } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -471,7 +468,7 @@ dio_input(void) rpl_process_dio(&from, &dio); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -810,7 +807,7 @@ dao_input_storing(void) /* independent if we remove or not - ACK the request */ if(flags & RPL_DAO_K_FLAG) { /* indicate that we accepted the no-path DAO */ - uip_clear_buf(); + uipbuf_clear(); dao_ack_output(instance, &dao_sender_addr, sequence, RPL_DAO_ACK_UNCONDITIONAL_ACCEPT); } @@ -900,7 +897,7 @@ fwd_dao: } if(should_ack) { LOG_DBG("Sending DAO ACK\n"); - uip_clear_buf(); + uipbuf_clear(); dao_ack_output(instance, &dao_sender_addr, sequence, RPL_DAO_ACK_UNCONDITIONAL_ACCEPT); } @@ -1014,7 +1011,7 @@ dao_input_nonstoring(void) if(flags & RPL_DAO_K_FLAG) { LOG_DBG("Sending DAO ACK\n"); - uip_clear_buf(); + uipbuf_clear(); dao_ack_output(instance, &dao_sender_addr, sequence, RPL_DAO_ACK_UNCONDITIONAL_ACCEPT); } @@ -1047,7 +1044,7 @@ dao_input(void) } discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ #if RPL_WITH_DAO_ACK @@ -1286,7 +1283,7 @@ dao_ack_input(void) instance = rpl_get_instance(instance_id); if(instance == NULL) { - uip_clear_buf(); + uipbuf_clear(); return; } @@ -1294,7 +1291,7 @@ dao_ack_input(void) parent = rpl_find_parent(instance->current_dag, &UIP_IP_BUF->srcipaddr); if(parent == NULL) { /* not a known instance - drop the packet and ignore */ - uip_clear_buf(); + uipbuf_clear(); return; } } else { @@ -1303,7 +1300,7 @@ dao_ack_input(void) if(instance->current_dag->rank == ROOT_RANK(instance)) { LOG_DBG("DODAG root received a DAO ACK, ignoring it\n"); - uip_clear_buf(); + uipbuf_clear(); return; } @@ -1363,7 +1360,7 @@ dao_ack_input(void) } } #endif /* RPL_WITH_DAO_ACK */ - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void diff --git a/os/net/routing/rpl-classic/rpl-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c index 344840d0e..d23111e46 100644 --- a/os/net/routing/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -65,12 +65,11 @@ * neighbors and are not only MAC neighbors. */ #define MAX_CHILDREN (NBR_TABLE_MAX_NEIGHBORS - 2) -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) static int num_parents; /* any node that are possible parents */ static int num_children; /* all children that we have as nexthop */ static int num_free; -static linkaddr_t *worst_rank_nbr; /* the parent that has the worst rank */ +static const linkaddr_t *worst_rank_nbr; /* the parent that has the worst rank */ static rpl_rank_t worst_rank; /*---------------------------------------------------------------------------*/ #if LOG_DBG_ENABLED @@ -112,9 +111,9 @@ update_nbr(void) num_parents = 0; num_children = 0; - nbr = nbr_table_head(ds6_neighbors); + nbr = uip_ds6_nbr_head(); while(nbr != NULL) { - linkaddr_t *lladdr = nbr_table_get_lladdr(ds6_neighbors, nbr); + const linkaddr_t *lladdr = (const linkaddr_t *)uip_ds6_nbr_get_ll(nbr); is_used = 0; /* @@ -127,7 +126,7 @@ update_nbr(void) num_children++; } - parent = rpl_get_parent((uip_lladdr_t *)lladdr); + parent = rpl_get_parent((const uip_lladdr_t *)lladdr); if(parent != NULL) { num_parents++; @@ -159,7 +158,7 @@ update_nbr(void) LOG_DBG_("\n"); } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); num_used++; } /* how many more IP neighbors can be have? */ diff --git a/os/net/routing/rpl-classic/rpl.h b/os/net/routing/rpl-classic/rpl.h index db87cc824..e690abeae 100644 --- a/os/net/routing/rpl-classic/rpl.h +++ b/os/net/routing/rpl-classic/rpl.h @@ -275,7 +275,7 @@ rpl_dag_t *rpl_get_dag(const uip_ipaddr_t *addr); rpl_dag_t *rpl_get_any_dag(void); rpl_instance_t *rpl_get_instance(uint8_t instance_id); int rpl_ext_header_update(void); -int rpl_ext_header_hbh_update(int); +int rpl_ext_header_hbh_update(uint8_t *, int); void rpl_insert_header(void); void rpl_ext_header_remove(void); const struct link_stats *rpl_get_parent_link_stats(rpl_parent_t *p); @@ -285,7 +285,7 @@ uint16_t rpl_get_parent_link_metric(rpl_parent_t *p); rpl_rank_t rpl_rank_via_parent(rpl_parent_t *p); const linkaddr_t *rpl_get_parent_lladdr(rpl_parent_t *p); uip_ipaddr_t *rpl_parent_get_ipaddr(rpl_parent_t *nbr); -rpl_parent_t *rpl_get_parent(uip_lladdr_t *addr); +rpl_parent_t *rpl_get_parent(const uip_lladdr_t *addr); rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr); void rpl_dag_init(void); uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent); diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index af67cdaff..cb8dcc190 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -53,46 +53,16 @@ #define LOG_MODULE "RPL" #define LOG_LEVEL LOG_LEVEL_RPL -/*---------------------------------------------------------------------------*/ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN]) -#define UIP_RH_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_RPL_SRH_BUF ((struct uip_rpl_srh_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_RH_LEN]) -#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) -#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset]) - /*---------------------------------------------------------------------------*/ int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) { - uint8_t *uip_next_hdr; - int last_uip_ext_len = uip_ext_len; + struct uip_routing_hdr *rh_header; uip_sr_node_t *dest_node; uip_sr_node_t *root_node; - uip_ext_len = 0; - uip_next_hdr = &UIP_IP_BUF->proto; - - /* Look for routing header */ - while(uip_next_hdr != NULL && *uip_next_hdr != UIP_PROTO_ROUTING) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, only the Hop-by-Hop Options header and - * Destination Options header can appear before the Routing header. - */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } + /* Look for routing ext header */ + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); if(!rpl_is_addr_in_our_dag(&UIP_IP_BUF->destipaddr)) { return 0; @@ -101,8 +71,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) root_node = uip_sr_get_node(NULL, &curr_instance.dag.dag_id); dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr); - if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING - && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) || + if((rh_header != NULL && rh_header->routing_type == RPL_RH_TYPE_SRH) || (dest_node != NULL && root_node != NULL && dest_node->parent == root_node)) { /* Routing header found or the packet destined for a direct child of the root. @@ -111,20 +80,18 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) * forwarding to next hop */ uip_ipaddr_copy(ipaddr, &UIP_IP_BUF->destipaddr); uip_create_linklocal_prefix(ipaddr); - uip_ext_len = last_uip_ext_len; return 1; } LOG_DBG("no SRH found\n"); - uip_ext_len = last_uip_ext_len; return 0; } /*---------------------------------------------------------------------------*/ int rpl_ext_header_srh_update(void) { - uint8_t *uip_next_hdr; - int last_uip_ext_len = uip_ext_len; + struct uip_routing_hdr *rh_header; + struct uip_rpl_srh_hdr *srh_header; uint8_t cmpri, cmpre; uint8_t ext_len; uint8_t padding; @@ -132,40 +99,21 @@ rpl_ext_header_srh_update(void) uint8_t segments_left; uip_ipaddr_t current_dest_addr; - uip_ext_len = 0; - uip_next_hdr = &UIP_IP_BUF->proto; + /* Look for routing ext header */ + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); - /* Look for routing header */ - while(uip_next_hdr != NULL && *uip_next_hdr != UIP_PROTO_ROUTING) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, only the Hop-by-Hop Options header and - * Destination Options header can appear before the Routing header. - */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } - - if(uip_next_hdr == NULL || *uip_next_hdr != UIP_PROTO_ROUTING - || UIP_RH_BUF->routing_type != RPL_RH_TYPE_SRH) { + if(rh_header == NULL || rh_header->routing_type != RPL_RH_TYPE_SRH) { LOG_INFO("SRH not found\n"); - uip_ext_len = last_uip_ext_len; return 0; } /* Parse SRH */ - segments_left = UIP_RH_BUF->seg_left; - ext_len = (UIP_RH_BUF->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF->pad >> 4; + srh_header = (struct uip_rpl_srh_hdr *)(((uint8_t *)rh_header) + RPL_RH_LEN); + segments_left = rh_header->seg_left; + ext_len = rh_header->len * 8 + 8; + cmpri = srh_header->cmpr >> 4; + cmpre = srh_header->cmpr & 0x0f; + padding = srh_header->pad >> 4; path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1; (void)path_len; @@ -177,7 +125,7 @@ rpl_ext_header_srh_update(void) /* We are the final destination, do nothing */ } else { uint8_t i = path_len - segments_left; /* The index of the next address to be visited */ - uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri)); + uint8_t *addr_ptr = ((uint8_t *)rh_header) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri)); uint8_t cmpr = segments_left == 1 ? cmpre : cmpri; /* As per RFC6554: swap the IPv6 destination address with address[i] */ @@ -190,14 +138,13 @@ rpl_ext_header_srh_update(void) memcpy(addr_ptr, ((uint8_t *)¤t_dest_addr) + cmpr, 16 - cmpr); /* Update segments left field */ - UIP_RH_BUF->seg_left--; + rh_header->seg_left--; LOG_INFO("SRH next hop "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_("\n"); } - uip_ext_len = last_uip_ext_len; return 1; } /*---------------------------------------------------------------------------*/ @@ -223,7 +170,6 @@ static int insert_srh_header(void) { /* Implementation of RFC6554 */ - uint8_t temp_len; uint8_t path_len; uint8_t ext_len; uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ @@ -234,6 +180,10 @@ insert_srh_header(void) uip_sr_node_t *node; uip_ipaddr_t node_addr; + /* Always insest SRH as first extension header */ + struct uip_routing_hdr *rh_hdr = (struct uip_routing_hdr *)UIP_IP_PAYLOAD(0); + struct uip_rpl_srh_hdr *srh_hdr = (struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(0) + RPL_RH_LEN); + LOG_INFO("SRH creating source routing header with destination "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); LOG_INFO_(" \n"); @@ -304,33 +254,33 @@ insert_srh_header(void) path_len, cmpri, cmpre, ext_len, padding); /* Check if there is enough space to store the extension header */ - if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) { + if(uip_len + ext_len > UIP_LINK_MTU) { LOG_ERR("packet too long: impossible to add source routing header (%u bytes)\n", ext_len); return 0; } - /* Move existing ext headers and payload uip_ext_len further */ - memmove(uip_buf + uip_l2_l3_hdr_len + ext_len, - uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN); - memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); + /* Move existing ext headers and payload ext_len further */ + memmove(uip_buf + UIP_IPH_LEN + uip_ext_len + ext_len, + uip_buf + UIP_IPH_LEN + uip_ext_len, uip_len - UIP_IPH_LEN); + memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len); - /* Insert source routing header */ - UIP_RH_BUF->next = UIP_IP_BUF->proto; + /* Insert source routing header (as first ext header) */ + rh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF->len = (ext_len - 8) / 8; - UIP_RH_BUF->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF->seg_left = path_len; + rh_hdr->len = (ext_len - 8) / 8; + rh_hdr->routing_type = RPL_RH_TYPE_SRH; + rh_hdr->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF->pad = padding << 4; + srh_hdr->cmpr = (cmpri << 4) + cmpre; + srh_hdr->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ node = dest_node; - hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */ + hop_ptr = ((uint8_t *)rh_hdr) + ext_len - padding; /* Pointer where to write the next hop compressed address */ while(node != NULL && node->parent != root_node) { NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); @@ -345,21 +295,15 @@ insert_srh_header(void) NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node); uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &node_addr); - /* In-place update of IPv6 length field */ - temp_len = UIP_IP_BUF->len[1]; - UIP_IP_BUF->len[1] += ext_len; - if(UIP_IP_BUF->len[1] < temp_len) { - UIP_IP_BUF->len[0]++; - } - - uip_ext_len += ext_len; - uip_len += ext_len; + /* Update the IPv6 length field */ + uipbuf_add_ext_hdr(ext_len); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); return 1; } /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int uip_ext_opt_offset) +rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset) { int down; int rank_error_signaled; @@ -367,32 +311,31 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) uint16_t sender_rank; uint8_t sender_closer; rpl_nbr_t *sender; - uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF->opt_type; - uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF->opt_len; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)ext_buf; + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(ext_buf + opt_offset); - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || opt_type != UIP_EXT_HDR_OPT_RPL - || opt_len != RPL_HDR_OPT_LEN) { + if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || rpl_opt->opt_type != UIP_EXT_HDR_OPT_RPL + || rpl_opt->opt_len != RPL_HDR_OPT_LEN) { LOG_ERR("hop-by-hop extension header has wrong size or type (%u %u %u)\n", - UIP_HBHO_BUF->len, opt_type, opt_len); + hbh_hdr->len, rpl_opt->opt_type, rpl_opt->opt_len); return 0; /* Drop */ } - if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF->instance) { - LOG_ERR("unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF->instance); + if(!curr_instance.used || curr_instance.instance_id != rpl_opt->instance) { + LOG_ERR("unknown instance: %u\n", rpl_opt->instance); return 0; /* Drop */ } - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) { + if(rpl_opt->flags & RPL_HDR_OPT_FWD_ERR) { LOG_ERR("forward error!\n"); return 0; /* Drop */ } - down = (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank); + down = (rpl_opt->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; + sender_rank = UIP_HTONS(rpl_opt->senderrank); sender = nbr_table_get_from_lladdr(rpl_neighbors, packetbuf_addr(PACKETBUF_ADDR_SENDER)); - rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; + rank_error_signaled = (rpl_opt->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; sender_closer = sender_rank < curr_instance.dag.rank; loop_detected = (down && !sender_closer) || (!down && sender_closer); @@ -406,7 +349,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) if(loop_detected) { /* Set forward error flag */ - UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR; + rpl_opt->flags |= RPL_HDR_OPT_RANK_ERR; } return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled); @@ -418,34 +361,27 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) static int update_hbh_header(void) { - int uip_ext_opt_offset; - int last_uip_ext_len; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0); + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2)); - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - uip_ext_opt_offset = 2; + if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && rpl_opt->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || rpl_opt->opt_len != RPL_HDR_OPT_LEN) { - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { - - LOG_ERR("hop-by-hop extension header has wrong size (%u %u)\n", - UIP_EXT_HDR_OPT_RPL_BUF->opt_len, uip_ext_len); + LOG_ERR("hop-by-hop extension header has wrong size (%u)\n", rpl_opt->opt_len); return 0; /* Drop */ } - if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF->instance) { + if(!curr_instance.used || curr_instance.instance_id != rpl_opt->instance) { LOG_ERR("unable to add/update hop-by-hop extension header: incorrect instance\n"); - uip_ext_len = last_uip_ext_len; return 0; /* Drop */ } /* Update sender rank and instance, will update flags next */ - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF->instance = curr_instance.instance_id; + rpl_opt->senderrank = UIP_HTONS(curr_instance.dag.rank); + rpl_opt->instance = curr_instance.instance_id; } - uip_ext_len = last_uip_ext_len; return 1; } /*---------------------------------------------------------------------------*/ @@ -456,45 +392,34 @@ update_hbh_header(void) static int insert_hbh_header(void) { - int uip_ext_opt_offset; - int last_uip_ext_len; - uint8_t temp_len; - - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - uip_ext_opt_offset = 2; + struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0); + struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2)); /* Insert hop-by-hop header */ LOG_INFO("creating hop-by-hop option\n"); - if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { + if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_LINK_MTU) { LOG_ERR("packet too long: impossible to add hop-by-hop option\n"); - uip_ext_len = last_uip_ext_len; return 0; } - /* Move existing ext headers and payload UIP_EXT_BUF further */ - memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN); - memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN); + /* Move existing ext headers and payload RPL_HOP_BY_HOP_LEN further */ + memmove(UIP_IP_PAYLOAD(RPL_HOP_BY_HOP_LEN), UIP_IP_PAYLOAD(0), uip_len - UIP_IPH_LEN); + memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); - /* Update IP and HBH protocol and fields */ - UIP_HBHO_BUF->next = UIP_IP_BUF->proto; + /* Insert HBH header (as first ext header) */ + hbh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF->instance = curr_instance.instance_id; - uip_len += RPL_HOP_BY_HOP_LEN; - temp_len = UIP_IP_BUF->len[1]; - UIP_IP_BUF->len[1] += RPL_HOP_BY_HOP_LEN; - if(UIP_IP_BUF->len[1] < temp_len) { - UIP_IP_BUF->len[0]++; - } + hbh_hdr->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; + rpl_opt->opt_type = UIP_EXT_HDR_OPT_RPL; + rpl_opt->opt_len = RPL_HDR_OPT_LEN; + rpl_opt->flags = 0; + rpl_opt->senderrank = UIP_HTONS(curr_instance.dag.rank); + rpl_opt->instance = curr_instance.instance_id; - uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; + uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); /* Update header before returning */ return update_hbh_header(); @@ -531,54 +456,34 @@ rpl_ext_header_update(void) void rpl_ext_header_remove(void) { - uint8_t temp_len; - uint8_t rpl_ext_hdr_len; - int uip_ext_opt_offset; - uint8_t *uip_next_hdr; + uint8_t *prev_proto_ptr; + uint8_t protocol; + uint8_t ext_len; + uint8_t *next_header; + struct uip_ext_hdr *ext_ptr; + struct uip_ext_hdr_opt *opt_ptr; - uip_ext_len = 0; - uip_ext_opt_offset = 2; - uip_next_hdr = &UIP_IP_BUF->proto; - - /* Look for hop-by-hop and routing headers */ - while(uip_next_hdr != NULL) { - switch(*uip_next_hdr) { - case UIP_PROTO_HBHO: - case UIP_PROTO_ROUTING: - if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) { - /* Remove hop-by-hop and routing headers */ - *uip_next_hdr = UIP_EXT_BUF->next; - rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8; - temp_len = UIP_IP_BUF->len[1]; - uip_len -= rpl_ext_hdr_len; - UIP_IP_BUF->len[1] -= rpl_ext_hdr_len; - if(UIP_IP_BUF->len[1] > temp_len) { - UIP_IP_BUF->len[0]--; - } - LOG_INFO("removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len); - memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN); - } else { - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - } - break; - case UIP_PROTO_DESTO: - /* - * As per RFC 2460, any header other than the Destination - * Options header does not appear between the Hop-by-Hop - * Options header and the Routing header. - * - * We're moving to the next header only if uip_next_hdr has - * UIP_PROTO_DESTO. Otherwise, we'll return. - */ - /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; - break; - default: - return; + next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); + ext_ptr = (struct uip_ext_hdr *)next_header; + prev_proto_ptr = &UIP_IP_BUF->proto; + while(next_header != NULL && uip_is_proto_ext_hdr(protocol)) { + opt_ptr = (struct uip_ext_hdr_opt *)(next_header + 2); + if(protocol == UIP_PROTO_ROUTING || (protocol == UIP_PROTO_HBHO && opt_ptr->type == UIP_EXT_HDR_OPT_RPL)) { + /* Remove ext header */ + *prev_proto_ptr = ext_ptr->next; + ext_len = ext_ptr->len * 8 + 8; + uipbuf_add_ext_hdr(-ext_len); + /* Update length field and move rest of packet to the "left" */ + uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); + memmove(next_header, next_header + ext_len, uip_len - (next_header - uip_buf)); + /* Update loop variables */ + protocol = *prev_proto_ptr; + } else { + /* move to the ext hdr */ + next_header = uipbuf_get_next_header(next_header, uip_len - (next_header - uip_buf), &protocol, false); + ext_ptr = (struct uip_ext_hdr *)next_header; + prev_proto_ptr = &ext_ptr->next; } } } - /** @}*/ diff --git a/os/net/routing/rpl-lite/rpl-ext-header.h b/os/net/routing/rpl-lite/rpl-ext-header.h index df61bc325..c2d0db5bc 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.h +++ b/os/net/routing/rpl-lite/rpl-ext-header.h @@ -63,12 +63,13 @@ int rpl_ext_header_srh_update(void); * Process and update the RPL hop-by-hop extension headers of * the current uIP packet. * -* \param uip_ext_opt_offset The offset within the uIP packet where -* extension headers start +* \param ext_buf A pointer to the ext header buffer +* \param opt_offset The offset within the extension header where +* the option starts * \return 1 in case the packet is valid and to be processed further, * 0 in case the packet must be dropped. */ -int rpl_ext_header_hbh_update(int uip_ext_opt_offset); +int rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset); /** * Adds/updates all RPL extension headers to current uIP packet. diff --git a/os/net/routing/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index be5ea2948..d376ff5e8 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -62,10 +62,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) - /*---------------------------------------------------------------------------*/ static void dis_input(void); static void dio_input(void); @@ -147,7 +143,7 @@ dis_input(void) rpl_process_dis(&UIP_IP_BUF->srcipaddr, uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -329,7 +325,7 @@ dio_input(void) rpl_process_dio(&from, &dio); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -540,7 +536,7 @@ dao_input(void) rpl_process_dao(&from, &dao); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -651,7 +647,7 @@ dao_ack_input(void) rpl_process_dao_ack(sequence, status); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void diff --git a/os/net/routing/rpl-lite/rpl-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c index 9752b1446..188ceb648 100644 --- a/os/net/routing/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -59,11 +59,10 @@ * NOTE: this policy assumes that all neighbors end up being IPv6 * neighbors and are not only MAC neighbors. */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) static int num_parents; /* all nodes that are possible parents */ static int num_free; -static linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */ +static const linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */ static rpl_rank_t worst_rank; /*---------------------------------------------------------------------------*/ @@ -79,10 +78,10 @@ update_state(void) worst_rank_nbr_lladdr = NULL; num_parents = 0; - ds6_nbr = nbr_table_head(ds6_neighbors); + ds6_nbr = uip_ds6_nbr_head(); while(ds6_nbr != NULL) { - linkaddr_t *nbr_lladdr = nbr_table_get_lladdr(ds6_neighbors, ds6_nbr); + const linkaddr_t *nbr_lladdr = (const linkaddr_t *)uip_ds6_nbr_get_ll(ds6_nbr); rpl_nbr = rpl_neighbor_get_from_lladdr((uip_lladdr_t *)nbr_lladdr); if(rpl_nbr != NULL && rpl_neighbor_is_parent(rpl_nbr)) { @@ -98,7 +97,7 @@ update_state(void) worst_rank_nbr_lladdr = nbr_lladdr; } - ds6_nbr = nbr_table_next(ds6_neighbors, ds6_nbr); + ds6_nbr = uip_ds6_nbr_next(ds6_nbr); num_used++; } /* how many more IP neighbors can be have? */ diff --git a/os/net/routing/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c index a0f5d95b0..94a26fe75 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -181,9 +181,9 @@ rpl_neighbor_count(void) static uip_ds6_nbr_t * rpl_get_ds6_nbr(rpl_nbr_t *nbr) { - const linkaddr_t *lladdr = rpl_neighbor_get_lladdr(nbr); + const uip_lladdr_t *lladdr = (const uip_lladdr_t *)rpl_neighbor_get_lladdr(nbr); if(lladdr != NULL) { - return nbr_table_get_from_lladdr(ds6_neighbors, lladdr); + return uip_ds6_nbr_ll_lookup(lladdr); } else { return NULL; } diff --git a/os/services/ip64/ip64-arp.c b/os/services/ip64/ip64-arp.c index 75197558d..6fd996920 100644 --- a/os/services/ip64/ip64-arp.c +++ b/os/services/ip64/ip64-arp.c @@ -139,7 +139,7 @@ ip64_arp_timer(void) { struct arp_entry *tabptr; int i; - + ++arptime; for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { tabptr = &arp_table[i]; @@ -157,7 +157,7 @@ arp_update(uip_ip4addr_t *ipaddr, struct uip_eth_addr *ethaddr) { register struct arp_entry *tabptr = arp_table; int i, c; - + /* Walk through the ARP mapping table and try to find an entry to update. If none is found, the IP -> MAC address mapping is inserted in the ARP table. */ @@ -170,7 +170,7 @@ arp_update(uip_ip4addr_t *ipaddr, struct uip_eth_addr *ethaddr) /* Check if the source IP address of the incoming packet matches the IP address in this ARP table entry. */ if(uip_ip4addr_cmp(ipaddr, &tabptr->ipaddr)) { - + /* An old entry found, update this and return. */ memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6); tabptr->time = arptime; @@ -239,7 +239,7 @@ ip64_arp_arp_input(const uint8_t *packet, uint16_t packet_len) table, since it is likely that we will do more communication with this host in the future. */ arp_update(&arphdr->sipaddr, &arphdr->shwaddr); - + arphdr->opcode = UIP_HTONS(ARP_REPLY); memcpy(arphdr->dhwaddr.addr, arphdr->shwaddr.addr, 6); @@ -275,7 +275,7 @@ ip64_arp_check_cache(const uint8_t *nlhdr) printf("check cache %d.%d.%d.%d\n", uip_ipaddr_to_quad(&ipv4_hdr->destipaddr)); - + /* First check if destination is a local broadcast. */ uip_ipaddr(&broadcast_addr, 255,255,255,255); if(uip_ip4addr_cmp(&ipv4_hdr->destipaddr, &broadcast_addr)) { @@ -321,7 +321,7 @@ ip64_arp_create_ethhdr(uint8_t *llhdr, const uint8_t *nlhdr) struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)nlhdr; struct ip64_eth_hdr *ethhdr = (struct ip64_eth_hdr *)llhdr; uip_ip4addr_t broadcast_addr; - + /* Find the destination IP address in the ARP table and construct the Ethernet header. If the destination IP addres isn't on the local network, we use the default router's IP address instead. @@ -371,7 +371,7 @@ ip64_arp_create_ethhdr(uint8_t *llhdr, const uint8_t *nlhdr) } memcpy(ethhdr->src.addr, ip64_eth_addr.addr, 6); - + ethhdr->type = UIP_HTONS(IP64_ETH_TYPE_IP); return sizeof(struct ip64_eth_hdr); } @@ -382,7 +382,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr) struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)nlhdr; struct arp_hdr *arp_hdr = (struct arp_hdr *)llhdr; uip_ip4addr_t ipaddr; - + if(!uip_ipaddr_maskcmp(&ipv4_hdr->destipaddr, ip64_get_hostaddr(), ip64_get_netmask())) { @@ -394,7 +394,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr) /* Else, we use the destination IP address. */ uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr); } - + memset(arp_hdr->ethhdr.dest.addr, 0xff, 6); memset(arp_hdr->dhwaddr.addr, 0x00, 6); memcpy(arp_hdr->ethhdr.src.addr, ip64_eth_addr.addr, 6); @@ -408,8 +408,8 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr) arp_hdr->hwlen = 6; arp_hdr->protolen = 4; arp_hdr->ethhdr.type = UIP_HTONS(IP64_ETH_TYPE_ARP); - - uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; + + uip_appdata = &uip_buf[UIP_IPTCPH_LEN]; return sizeof(struct arp_hdr); } diff --git a/os/services/ip64/ip64-dhcpc.c b/os/services/ip64/ip64-dhcpc.c index 8e8e286f8..10a5184e3 100644 --- a/os/services/ip64/ip64-dhcpc.c +++ b/os/services/ip64/ip64-dhcpc.c @@ -61,7 +61,7 @@ struct dhcp_msg { uint8_t options[312]; }; -#if (UIP_BUFSIZE - UIP_LLH_LEN - UIP_UDPIP_HLEN) < 548 +#if (UIP_BUFSIZE - UIP_UDPIP_HLEN) < 548 #error UIP_CONF_BUFFER_SIZE may be too small to accomodate DHCPv4 packets #error Increase UIP_CONF_BUFFER_SIZE in your project-conf.h, or contiki-conf.h #error A good size is 600 bytes @@ -191,12 +191,12 @@ send_request(void) struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; create_msg(m); - + end = add_msg_type(&m->options[4], DHCPREQUEST); end = add_server_id(end); end = add_req_ipaddr(end); end = add_end(end); - + uip_send(uip_appdata, (int)(end - (uint8_t *)uip_appdata)); } /*---------------------------------------------------------------------------*/ @@ -239,7 +239,7 @@ static uint8_t parse_msg(void) { struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; - + if(m->op == DHCP_REPLY && memcmp(m->xid, &xid, sizeof(xid)) == 0 && memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) { @@ -258,7 +258,7 @@ msg_for_me(void) struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; uint8_t *optptr = &m->options[4]; uint8_t *end = (uint8_t*)uip_appdata + uip_datalen(); - + if(m->op == DHCP_REPLY && memcmp(m->xid, &xid, sizeof(xid)) == 0 && memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) { @@ -280,7 +280,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) clock_time_t ticks; PT_BEGIN(&s.pt); - + init: xid++; s.state = STATE_SENDING; @@ -305,7 +305,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) s.ticks *= 2; } } - + selecting: s.ticks = CLOCK_SECOND; do { @@ -330,7 +330,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) goto init; } } while(s.state != STATE_CONFIG_RECEIVED); - + bound: #if 0 printf("Got IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&s.ipaddr)); @@ -343,7 +343,7 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) #endif ip64_dhcpc_configured(&s); - + #define MAX_TICKS (~((clock_time_t)0) / 2) #define MAX_TICKS32 (~((uint32_t)0)) #define IMIN(a, b) ((a) < (b) ? (a) : (b)) @@ -407,12 +407,12 @@ ip64_dhcpc_init(const void *mac_addr, int mac_len) uip_ip6addr_t v6addr; uip_ip4addr_t v4addr; struct uip_udp_conn *conn2; - + s.mac_addr = mac_addr; s.mac_len = mac_len; s.state = STATE_INITIAL; - uip_ipaddr(&v4addr, 255,255,255,255); + uip_ipaddr(&v4addr, 255,255,255,255); ip64_addr_4to6(&v4addr, &v6addr); s.conn = udp_new(&v6addr, UIP_HTONS(IP64_DHCPC_SERVER_PORT), NULL); conn2 = udp_new(NULL, UIP_HTONS(IP64_DHCPC_SERVER_PORT), NULL); @@ -437,7 +437,7 @@ void ip64_dhcpc_request(void) { uip_ipaddr_t ipaddr; - + if(s.state == STATE_INITIAL) { uip_ipaddr(&ipaddr, 0,0,0,0); uip_sethostaddr(&ipaddr); diff --git a/os/services/ip64/ip64-eth-interface.c b/os/services/ip64/ip64-eth-interface.c index 1dcaeb5ad..dc89610e5 100644 --- a/os/services/ip64/ip64-eth-interface.c +++ b/os/services/ip64/ip64-eth-interface.c @@ -39,8 +39,6 @@ #include -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" #define printf(...) @@ -62,7 +60,7 @@ ip64_eth_interface_input(uint8_t *packet, uint16_t len) printf("-------------->\n"); uip_len = ip64_4to6(&packet[sizeof(struct ip64_eth_hdr)], len - sizeof(struct ip64_eth_hdr), - &uip_buf[UIP_LLH_LEN]); + uip_buf); if(uip_len > 0) { printf("ip64_interface_process: converted %d bytes\n", uip_len); @@ -96,7 +94,7 @@ output(void) PRINTF("\n"); printf("<--------------\n"); - len = ip64_6to4(&uip_buf[UIP_LLH_LEN], uip_len, + len = ip64_6to4(uip_buf, uip_len, &ip64_packet_buffer[sizeof(struct ip64_eth_hdr)]); printf("ip64-interface: output len %d\n", len); diff --git a/os/services/ip64/ip64-slip-interface.c b/os/services/ip64/ip64-slip-interface.c index 10422f2c7..fb4f69627 100644 --- a/os/services/ip64/ip64-slip-interface.c +++ b/os/services/ip64/ip64-slip-interface.c @@ -38,8 +38,6 @@ #include #include -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" @@ -57,24 +55,24 @@ static void input_callback(void) { /*PRINTF("SIN: %u\n", uip_len);*/ - if(uip_buf[UIP_LLH_LEN] == '!') { - PRINTF("Got configuration message of type %c\n", uip_buf[UIP_LLH_LEN + 1]); - uip_clear_buf(); + if(uip_buf[0] == '!') { + PRINTF("Got configuration message of type %c\n", uip_buf[1]); + uipbuf_clear(); #if 0 - if(uip_buf[UIP_LLH_LEN + 1] == 'P') { + if(uip_buf[1] == 'P') { uip_ipaddr_t prefix; /* Here we set a prefix !!! */ memset(&prefix, 0, 16); - memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 2], 8); + memcpy(&prefix, &uip_buf[2], 8); PRINTF("Setting prefix "); PRINT6ADDR(&prefix); PRINTF("\n"); set_prefix_64(&prefix); } #endif - } else if(uip_buf[UIP_LLH_LEN] == '?') { - PRINTF("Got request message of type %c\n", uip_buf[UIP_LLH_LEN + 1]); - if(uip_buf[UIP_LLH_LEN + 1] == 'M') { + } else if(uip_buf[0] == '?') { + PRINTF("Got request message of type %c\n", uip_buf[1]); + if(uip_buf[1] == 'M') { const char *hexchar = "0123456789abcdef"; int j; /* this is just a test so far... just to see if it works */ @@ -86,21 +84,21 @@ input_callback(void) uip_len = 18; slip_write(uip_buf, uip_len); } - uip_clear_buf(); + uipbuf_clear(); } else { - + /* Save the last sender received over SLIP to avoid bouncing the packet back if no route is found */ uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr); - - uint16_t len = ip64_4to6(&uip_buf[UIP_LLH_LEN], uip_len, + + uint16_t len = ip64_4to6(uip_buf, uip_len, ip64_packet_buffer); if(len > 0) { - memcpy(&uip_buf[UIP_LLH_LEN], ip64_packet_buffer, len); + memcpy(uip_buf, ip64_packet_buffer, len); uip_len = len; /* PRINTF("send len %d\n", len); */ } else { - uip_clear_buf(); + uipbuf_clear(); } } } @@ -129,11 +127,11 @@ output(void) if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) { PRINTF("ip64-interface: output, not sending bounced message\n"); } else { - len = ip64_6to4(&uip_buf[UIP_LLH_LEN], uip_len, + len = ip64_6to4(uip_buf, uip_len, ip64_packet_buffer); PRINTF("ip64-interface: output len %d\n", len); if(len > 0) { - memcpy(&uip_buf[UIP_LLH_LEN], ip64_packet_buffer, len); + memcpy(uip_buf, ip64_packet_buffer, len); uip_len = len; slip_send(); return len; diff --git a/os/services/rpl-border-router/embedded/slip-bridge.c b/os/services/rpl-border-router/embedded/slip-bridge.c index d1f97339d..b1349ac0a 100644 --- a/os/services/rpl-border-router/embedded/slip-bridge.c +++ b/os/services/rpl-border-router/embedded/slip-bridge.c @@ -43,8 +43,6 @@ #include "dev/slip.h" #include /*---------------------------------------------------------------------------*/ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -/*---------------------------------------------------------------------------*/ /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "SLIP" @@ -63,34 +61,34 @@ request_prefix(void) uip_buf[1] = 'P'; uip_len = 2; slip_write(uip_buf, uip_len); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void slip_input_callback(void) { LOG_DBG("SIN: %u\n", uip_len); - if(uip_buf[UIP_LLH_LEN] == '!') { + if(uip_buf[0] == '!') { LOG_INFO("Got configuration message of type %c\n", - uip_buf[UIP_LLH_LEN + 1]); - if(uip_buf[UIP_LLH_LEN + 1] == 'P') { + uip_buf[1]); + if(uip_buf[1] == 'P') { uip_ipaddr_t prefix; /* Here we set a prefix !!! */ memset(&prefix, 0, 16); - memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 2], 8); + memcpy(&prefix, &uip_buf[2], 8); - uip_clear_buf(); + uipbuf_clear(); LOG_INFO("Setting prefix "); LOG_INFO_6ADDR(&prefix); LOG_INFO_("\n"); set_prefix_64(&prefix); } - uip_clear_buf(); + uipbuf_clear(); - } else if(uip_buf[UIP_LLH_LEN] == '?') { - LOG_INFO("Got request message of type %c\n", uip_buf[UIP_LLH_LEN + 1]); - if(uip_buf[UIP_LLH_LEN + 1] == 'M') { + } else if(uip_buf[0] == '?') { + LOG_INFO("Got request message of type %c\n", uip_buf[1]); + if(uip_buf[1] == 'M') { char *hexchar = "0123456789abcdef"; int j; /* this is just a test so far... just to see if it works */ @@ -102,7 +100,7 @@ slip_input_callback(void) uip_len = 18; slip_write(uip_buf, uip_len); } - uip_clear_buf(); + uipbuf_clear(); } else { /* Save the last sender received over SLIP to avoid bouncing the packet back if no route is found */ diff --git a/os/services/rpl-border-router/native/tun-bridge.c b/os/services/rpl-border-router/native/tun-bridge.c index f321577b3..b358bf2f9 100644 --- a/os/services/rpl-border-router/native/tun-bridge.c +++ b/os/services/rpl-border-router/native/tun-bridge.c @@ -256,7 +256,7 @@ output(void) { LOG_DBG("SUT: %u\n", uip_len); if(uip_len > 0) { - return tun_output(&uip_buf[UIP_LLH_LEN], uip_len); + return tun_output(uip_buf, uip_len); } return 0; } @@ -298,7 +298,7 @@ handle_fd(fd_set *rset, fd_set *wset) int size; if(FD_ISSET(tunfd, rset)) { - size = tun_input(&uip_buf[UIP_LLH_LEN], sizeof(uip_buf)); + size = tun_input(uip_buf, sizeof(uip_buf)); /* printf("TUN data incoming read:%d\n", size); */ uip_len = size; tcpip_input(); diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index aaebab164..43e008c8e 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -2,41 +2,41 @@ EXAMPLESDIR=../../examples TOOLSDIR=../../tools EXAMPLES = \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ -platform-specific/cc26xx/very-sleepy-demo/srf06-cc26xx:BOARD=sensortag/cc2650 \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=sensortag/cc2650 \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=sensortag/cc1350 \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=srf06/cc13xx \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=launchpad/cc2650 \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=launchpad/cc1310 \ -platform-specific/cc26xx/cc26xx-web-demo/srf06-cc26xx:BOARD=launchpad/cc1350 \ -platform-specific/cc26xx/very-sleepy-demo/srf06-cc26xx \ -platform-specific/cc26xx/ble-ipv6/srf06-cc26xx:BOARD=sensortag/cc2650 \ -nullnet/srf06-cc26xx:BOARD=sensortag/cc2650 \ -rpl-border-router/srf06-cc26xx:BOARD=launchpad/cc2650 \ -sensniff/srf06-cc26xx \ -sensniff/srf06-cc26xx:BOARD=launchpad/cc1310 \ -dev/gpio-hal/srf06-cc26xx:BOARD=srf06/cc13xx \ -dev/gpio-hal/srf06-cc26xx:BOARD=srf06/cc26xx \ -dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc1350 \ -dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc2650 \ -dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1310 \ -dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1350 \ -dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2650 \ -dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2640r2 \ -dev/leds/srf06-cc26xx:BOARD=srf06/cc13xx \ -dev/leds/srf06-cc26xx:BOARD=srf06/cc26xx \ -dev/leds/srf06-cc26xx:BOARD=sensortag/cc1350 \ -dev/leds/srf06-cc26xx:BOARD=sensortag/cc2650 \ -dev/leds/srf06-cc26xx:BOARD=launchpad/cc1310 \ -dev/leds/srf06-cc26xx:BOARD=launchpad/cc1350 \ -dev/leds/srf06-cc26xx:BOARD=launchpad/cc2650 \ -dev/leds/srf06-cc26xx:BOARD=launchpad/cc2640r2 \ -6tisch/etsi-plugtest-2017/srf06-cc26xx:BOARD=launchpad/cc2650 \ -mqtt-client/srf06-cc26xx:BOARD=srf06/cc26xx \ -mqtt-client/srf06-cc26xx:BOARD=launchpad/cc2650 \ -mqtt-client/srf06-cc26xx:BOARD=sensortag/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +platform-specific/cc26x0-cc13x0/very-sleepy-demo/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc1350 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=srf06/cc13x0 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ +platform-specific/cc26x0-cc13x0/cc26x0-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc1350 \ +platform-specific/cc26x0-cc13x0/very-sleepy-demo/cc26x0-cc13x0 \ +platform-specific/cc26x0-cc13x0/ble-ipv6/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +nullnet/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +rpl-border-router/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +sensniff/cc26x0-cc13x0 \ +sensniff/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=srf06/cc13x0 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=srf06/cc26x0 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=sensortag/cc1350 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=launchpad/cc1350 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=launchpad/cc2640r2 \ +dev/leds/cc26x0-cc13x0:BOARD=srf06/cc13x0 \ +dev/leds/cc26x0-cc13x0:BOARD=srf06/cc26x0 \ +dev/leds/cc26x0-cc13x0:BOARD=sensortag/cc1350 \ +dev/leds/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +dev/leds/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ +dev/leds/cc26x0-cc13x0:BOARD=launchpad/cc1350 \ +dev/leds/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +dev/leds/cc26x0-cc13x0:BOARD=launchpad/cc2640r2 \ +6tisch/etsi-plugtest-2017/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +mqtt-client/cc26x0-cc13x0:BOARD=srf06/cc26x0 \ +mqtt-client/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +mqtt-client/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ hello-world/simplelink:BOARD=launchpad/cc26x2r1 \ hello-world/simplelink:BOARD=sensortag/cc2650 \ nullnet/simplelink:BOARD=sensortag/cc2650 \ diff --git a/tests/08-native-runs/02-mqtt-client.sh b/tests/08-native-runs/02-mqtt-client.sh new file mode 100755 index 000000000..cb1ee937a --- /dev/null +++ b/tests/08-native-runs/02-mqtt-client.sh @@ -0,0 +1,79 @@ +#!/bin/bash +source ../utils.sh + +# Contiki directory +CONTIKI=$1 + +# Example code directory +CODE_DIR=$CONTIKI/examples/mqtt-client/ +CODE=mqtt-client + +CLIENT_LOG=$CODE.log +CLIENT_TESTLOG=$CODE.testlog +CLIENT_ERR=$CODE.err +MOSQ_SUB_LOG=mosquitto_sub.log +MOSQ_SUB_ERR=mosquitto_sub.err + +# Start mosquitto server +echo "Starting mosquitto daemon" +mosquitto &> /dev/null & +MOSQID=$! +sleep 2 + +# Start mosquitto_sub client. Subscribe +echo "Starting mosquitto subscriber" +mosquitto_sub -t iot-2/evt/status/fmt/json > $MOSQ_SUB_LOG 2> $MOSQ_SUB_ERR & +MSUBID=$! +sleep 2 + +# Starting Contiki-NG native node +echo "Starting native node" +make -C $CODE_DIR TARGET=native \ + DEFINES=MQTT_CLIENT_CONF_ORG_ID=\\\"travis-test\\\",MQTT_CLIENT_CONF_LOG_LEVEL=LOG_LEVEL_DBG \ + > make.log 2> make.err +sudo $CODE_DIR/$CODE.native > $CLIENT_LOG 2> $CLIENT_ERR & +CPID=$! + +# The mqtt-client will publish every 30 secs. Wait for 45 +sleep 45 + +# Send a publish to the mqtt client +mosquitto_pub -m "1" -t iot-2/cmd/leds/fmt/json + +echo "Closing native node" +sleep 2 +kill_bg $CPID + +echo "Stopping mosquitto daemon" +kill_bg $MOSQID + +echo "Stopping mosquitto subscriber" +kill_bg $MSUBID + +# Success criteria: +# * mosquitto_sub output not empty +# * mqtt-client.native output contains "MQTT SUB" +SUB_RCV=`grep "MQTT SUB" $CLIENT_LOG` +if [ -s "$MOSQ_SUB_LOG" -a -n "$SUB_RCV" ] +then + cp $CLIENT_LOG $CODE.testlog + printf "%-32s TEST OK\n" "$CODE" | tee $CODE.testlog; +else + echo "==== make.log ====" ; cat make.log; + echo "==== make.err ====" ; cat make.err; + echo "==== $CLIENT_LOG ====" ; cat $CLIENT_LOG; + echo "==== $CLIENT_ERR ====" ; cat $CLIENT_ERR; + echo "==== $MOSQ_SUB_LOG ====" ; cat $MOSQ_SUB_LOG; + echo "==== $MOSQ_SUB_ERR ====" ; cat $MOSQ_SUB_ERR; + + printf "%-32s TEST FAIL\n" "$CODE" | tee $CODE.testlog; +fi + +rm make.log +rm make.err +rm $CLIENT_LOG $CLIENT_ERR +rm $MOSQ_SUB_LOG $MOSQ_SUB_ERR + +# We do not want Make to stop -> Return 0 +# The Makefile will check if a log contains FAIL at the end +exit 0 diff --git a/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc b/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc new file mode 100644 index 000000000..66e2a8c9a --- /dev/null +++ b/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_CSMA=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc b/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc new file mode 100644 index 000000000..e6957af28 --- /dev/null +++ b/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_TSCH=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc b/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc new file mode 100644 index 000000000..b95a1ff4b --- /dev/null +++ b/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_NBR_MULTI_IPV6_ADDRS=1 WITH_ULA=1 WITH_CSMA=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc b/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc new file mode 100644 index 000000000..20f8a12ae --- /dev/null +++ b/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_NBR_MULTI_IPV6_ADDRS=1 WITH_ULA=1 WITH_TSCH=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/code/Makefile b/tests/09-ipv6/code/Makefile index 2c910f1cd..d8f4cab55 100644 --- a/tests/09-ipv6/code/Makefile +++ b/tests/09-ipv6/code/Makefile @@ -28,6 +28,10 @@ ifeq ($(WITH_TSCH),1) CFLAGS += -DTSCH_CONF_DEFAULT_HOPPING_SEQUENCE=TSCH_HOPPING_SEQUENCE_1_1 endif +ifeq ($(WITH_NBR_MULTI_IPV6_ADDRS),1) + CFLAGS += -DUIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS=1 +endif + PLATFORM_ONLY = cooja TARGET = cooja diff --git a/tests/09-ipv6/js/ping-test-lla-ula.js b/tests/09-ipv6/js/ping-test-lla-ula.js new file mode 100644 index 000000000..c15dcbf15 --- /dev/null +++ b/tests/09-ipv6/js/ping-test-lla-ula.js @@ -0,0 +1,72 @@ +TIMEOUT(20000, log.testFailed()); + +dst_lla = "fe80::202:2:2:2"; +dst_ula = "fd00::202:2:2:2"; +dst_mac = "0002.0002.0002.0002"; +step = 0; +rpl_is_enabled = false; + +while(1) { + YIELD(); + log.log(time + " " + id + " "+ msg + "\n"); + + if(msg.contains("Node ID: ")) { + if(id == 1) { + write(sim.getMoteWithID(1), "rpl-set-root 1"); + } + step += 1; + } + + if(msg.contains("Setting as DAG root")) { + rpl_is_enabled = true; + } + + if(step == 2 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_lla); + step += 1; + } + + if(step == 4 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_ula); + step += 1; + } + + if(msg.contains("Received ping reply")) { + if(step == 3) { + step += 1; + } else { + step += 1; + write(sim.getMoteWithID(1), "ip-nbr"); + } + } + + if(step == 6 && rpl_is_enabled) { + /* when RPL is enabled, we skip examining ip-nbr results */ + log.testOK(); + } + + if(msg.contains("<->")) { + re = /-- | <-> |, router|, state /; + nc = msg.split(re); + ip_addr = nc[1]; + ll_addr = nc[2]; + is_router = nc[3]; + state = nc[4].trim(); + if(ll_addr == dst_mac && + state == "Reachable") { + if(step == 6 && ip_addr == dst_lla) { + step += 1; + } else if(step == 7 && ip_addr == dst_ula) { + log.testOK(); + } else { + /* unexpected case */ + log.testFailed(); + } + } else { + log.log(ip_addr + "\n"); + log.log(ll_addr + "\n"); + log.log(state + "\n"); + log.testFailed(); + } + } +} diff --git a/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh b/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh new file mode 100755 index 000000000..8f73ee237 --- /dev/null +++ b/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +TEST_NAME=01-test-nbr-multi-addrs + +if [ $# -eq 1 ]; then + # a (relative) path to CONTIKI_DIR is supposed to be given as $1 + TEST_DIR=$1/tests/10-ipv6-nbr +else + TEST_DIR=.//tests/10-ipv6-nbr +fi +SRC_DIR=${TEST_DIR}/nbr-multi-addrs +EXEC_FILE_NAME=test.native + +make -C ${SRC_DIR} clean + +echo "build the test program"... +make -C ${SRC_DIR} > ${TEST_NAME}.log + +echo "run the test..." +${TEST_DIR}/${SRC_DIR}/${EXEC_FILE_NAME} | tee ${TEST_NAME}.log | \ + grep -vE '^\[' >> ${TEST_NAME}.testlog diff --git a/tests/10-ipv6-nbr/Makefile b/tests/10-ipv6-nbr/Makefile new file mode 100644 index 000000000..c46e5271d --- /dev/null +++ b/tests/10-ipv6-nbr/Makefile @@ -0,0 +1 @@ +include ../Makefile.script-test diff --git a/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile b/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile new file mode 100644 index 000000000..711bf0987 --- /dev/null +++ b/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = test +all: $(CONTIKI_PROJECT) + +CFLAGS += -DUNIT_TEST_PRINT_FUNCTION=my_test_print +CFLAGS += -DLOG_CONF_LEVEL_IPV6=LOG_LEVEL_DBG +CFLAGS += -DNBR_TABLE_FIND_REMOVABLE=my_always_return_null +CFLAGS += -DUIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS=1 + +PLATFORM_ONLY = native +TARGET = native +MODULES += os/sys/log os/services/unit-test + +CONTIKI = ../../../ +include $(CONTIKI)/Makefile.include diff --git a/tests/10-ipv6-nbr/nbr-multi-addrs/test.c b/tests/10-ipv6-nbr/nbr-multi-addrs/test.c new file mode 100644 index 000000000..2cefd7cca --- /dev/null +++ b/tests/10-ipv6-nbr/nbr-multi-addrs/test.c @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018, Yasuyuki Tanaka + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. 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. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#define LOG_MODULE "test" +#define LOG_LEVEL LOG_LEVEL_DBG + +/* report function defined in unit-test.c */ +void unit_test_print_report(const unit_test_t *utp); + +static const uint8_t is_router = 1; +static const uint8_t state = NBR_INCOMPLETE; +static const nbr_table_reason_t reason = NBR_TABLE_REASON_UNDEFINED; + +static void remove_all_entries_in_neighbor_cache(void); + +PROCESS(node_process, "Node"); +AUTOSTART_PROCESSES(&node_process); + +void +my_test_print(const unit_test_t *utp) +{ + unit_test_print_report(utp); + if(utp->result == unit_test_failure) { + printf("\nTEST FAILED\n"); + exit(1); /* exit by failure */ + } +} + +/* my_always_return_null() is set to NBR_TABLE_FIND_REMOVABLE */ +const linkaddr_t * +my_always_return_null(nbr_table_reason_t reason, void *data) +{ + return NULL; +} + +void +remove_all_entries_in_neighbor_cache(void) +{ + uip_ds6_nbr_t *nbr, *next_nbr; + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = next_nbr) { + next_nbr = uip_ds6_nbr_next(nbr); + uip_ds6_nbr_rm(nbr); + } + /* + * uip_ds6_nbr_rm() cannot free the memory for an entry in nbr-table. There is + * no API to free or deallocate unused nbr-table entry. Because of that, + * nbr-table has some link-layer addresses even though this function removes + * all the neighbor cache entries. + */ +} + +UNIT_TEST_REGISTER(add_v6addrs_to_neighbor, + "add IPv6 addresses to a single neighbor"); +UNIT_TEST(add_v6addrs_to_neighbor) +{ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr; + const uip_lladdr_t *ret_lladdr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + /* prepare a link-layer address */ + LOG_DBG("link-layer addr: "); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_("\n"); + + for(int i = 0; i <= UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; i++) { + ipaddr.u8[0] = i; + LOG_DBG("adding ipv6 addr ("); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_("[i=%u])\n", i); + + /* add a binding of the IPv6 address and the MAC address */ + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + if(i < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + UNIT_TEST_ASSERT(nbr != NULL); + UNIT_TEST_ASSERT(memcmp(&nbr->ipaddr, &ipaddr, sizeof(ipaddr)) == 0); + UNIT_TEST_ASSERT(nbr->state == state); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == (i + 1)); + /* + * for some reason, nbr->isrouter is not set if both UIP_ND6_SEND_RA and + * !UIP_CONF_ROUTER is 0 (see uip-ds6-nbr.c) + */ + // UNIT_TEST_ASSERT(nbr->isrouter == is_router); + ret_lladdr = uip_ds6_nbr_lladdr_from_ipaddr((const uip_ipaddr_t *)&ipaddr); + UNIT_TEST_ASSERT(ret_lladdr != NULL); + UNIT_TEST_ASSERT(memcmp(ret_lladdr, &lladdr, sizeof(lladdr)) == 0); + + } else { + /* i == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; the address shouldn't be added */ + UNIT_TEST_ASSERT(nbr == NULL); + } + } + + UNIT_TEST_END(); +} + +UNIT_TEST_REGISTER(remove_v6addrs_of_neighbor, + "remove IPv6 addresses associated with a single neighbor"); +UNIT_TEST(remove_v6addrs_of_neighbor) +{ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr, *next_nbr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + /* prepare a link-layer address */ + LOG_DBG("link-layer addr: "); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_("\n"); + + /* fill the neighbor entry associated with the link-layer address */ + for(int i = 0; i < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; i++) { + ipaddr.u8[0] = i; + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + UNIT_TEST_ASSERT(nbr != NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == (i + 1)); + } + + /* remove IPv6 addresses for the link-layer address one by one */ + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = next_nbr) { + LOG_DBG("removing nbr:%p\n", nbr); + next_nbr = uip_ds6_nbr_next(nbr); + UNIT_TEST_ASSERT(uip_ds6_nbr_rm(nbr) == 1); + } + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + + UNIT_TEST_END(); + +} + +UNIT_TEST_REGISTER(fill_neighbor_cache_table, + "fill the neighbor cache table"); +UNIT_TEST(fill_neighbor_cache_table) +{ + /* + * We should be able to add the same number of link-layer addresses as + * NBR_TABLE_MAX_NEIGHBORS. In addition, we should be add the same number of + * IPv6 addresses per link-layer address as + * UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR. + */ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + for(int i = 0; i <= NBR_TABLE_MAX_NEIGHBORS; i++) { + lladdr.addr[0] = i & 0xFF; + lladdr.addr[1] = i >> 8; + for(int j = 0; j <= UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; j++) { + ipaddr.u8[0] = i & 0xFF; + ipaddr.u8[1] = i >> 8; + ipaddr.u8[2] = j; + LOG_DBG("adding ipv6 addr ("); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_(") to link-layer addr ("); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_(") [i=%u,j=%u]\n", i, j); + + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + if((i < NBR_TABLE_MAX_NEIGHBORS) && + (j < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR)) { + UNIT_TEST_ASSERT(nbr != NULL); + } else if(i == NBR_TABLE_MAX_NEIGHBORS) { + /* we should not be able to add a link-layer address any more */ + UNIT_TEST_ASSERT(j == 0); + UNIT_TEST_ASSERT(nbr == NULL); + break; + } else if(j == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* we should not be able to add an IPv6 address any more */ + UNIT_TEST_ASSERT(i < NBR_TABLE_MAX_NEIGHBORS); + UNIT_TEST_ASSERT(nbr == NULL); + break; + } else { + /* shouldn't come here */ + UNIT_TEST_ASSERT(false); + } + } + } + + UNIT_TEST_END(); +} + +PROCESS_THREAD(node_process, ev, data) +{ + PROCESS_BEGIN(); + + UNIT_TEST_RUN(add_v6addrs_to_neighbor); + UNIT_TEST_RUN(remove_v6addrs_of_neighbor); + UNIT_TEST_RUN(fill_neighbor_cache_table); + + printf("\nTEST SUCCEEDED\n"); + exit(0); /* success: all the test passed */ + + PROCESS_END(); +} diff --git a/tests/Makefile.script-test b/tests/Makefile.script-test index e4dd0da6a..e58acec80 100644 --- a/tests/Makefile.script-test +++ b/tests/Makefile.script-test @@ -5,18 +5,14 @@ CONTIKI=../.. all: clean summary -summary: cooja $(TESTLOGS) +summary: $(TESTLOGS) @cat *.testlog > summary @echo "========== Summary ==========" @cat summary -%.testlog: %.sh cooja +%.testlog: %.sh @echo "========== Running script test $(basename $@).sh ==========" @bash "$(basename $@).sh" "$(CONTIKI)" clean: @rm -f *.*log report summary - -cooja: $(CONTIKI)/tools/cooja/dist/cooja.jar -$(CONTIKI)/tools/cooja/dist/cooja.jar: - (cd $(CONTIKI)/tools/cooja; ant jar) diff --git a/tools/doxygen/Doxyfile b/tools/doxygen/Doxyfile index dab2c18e3..2cd7dba72 100644 --- a/tools/doxygen/Doxyfile +++ b/tools/doxygen/Doxyfile @@ -807,8 +807,8 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = */cpu/cc26xx-cc13xx/lib/* \ - */cpu/cc26xx-cc13xx/rf-core/api/* \ +EXCLUDE_PATTERNS = */cpu/cc26x0-cc13x0/lib/* \ + */cpu/cc26x0-cc13x0/rf-core/api/* \ */cpu/simplelink-cc13xx-cc26xx/lib/* \ */cpu/simplelink-cc13xx-cc26xx/rf-settings/* \ */cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/* \ diff --git a/tools/sky/uip6-bridge/Makefile b/tools/sky/uip6-bridge/Makefile deleted file mode 100644 index 55da6798e..000000000 --- a/tools/sky/uip6-bridge/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -ifdef CONTIKI_HOME -CONTIKI = $(CONTIKI_HOME) -else -ifndef CONTIKI -CONTIKI=../../.. -endif -endif - -DEFINES=WITH_SLIP=1 - -ifndef TARGET -TARGET=sky -endif - -MODULES_REL += dev -PROJECT_SOURCEFILES = fakeuip.c sicslow_ethernet.c - -all: uip6-bridge-tap.sky - -upload: uip6-bridge-tap.ihex - cp $< $(IHEXFILE) - $(MAKE) sky-u.$(subst /,-,$(word $(MOTE), $(MOTES))) - -include $(CONTIKI)/Makefile.include - -../../tapslip6: ../../tapslip6.c - (cd ../../; $(MAKE) tapslip6) - -ifndef MOTE -MOTE=1 -endif - -connect: ../../tapslip6 - sudo ../../tapslip6 -t tap0 -s $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) 127.0.0.1 255.0.0.0 - -bridge: - @sudo service radvd restart || echo radvd could not be restarted - sudo route add -6 fd00::/64 tap0 - sudo ip -6 address add fd00::1/64 dev tap0 diff --git a/tools/sky/uip6-bridge/dev/slip.c b/tools/sky/uip6-bridge/dev/slip.c deleted file mode 100644 index e8062e515..000000000 --- a/tools/sky/uip6-bridge/dev/slip.c +++ /dev/null @@ -1,323 +0,0 @@ -/* -*- C -*- */ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - - -#include -#include -#include "dev/ds2411/ds2411.h" -#include "contiki.h" - -#include "net/ipv6/uip.h" -#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) - -#include "dev/slip.h" - -#define SLIP_END 0300 -#define SLIP_ESC 0333 -#define SLIP_ESC_END 0334 -#define SLIP_ESC_ESC 0335 - -PROCESS(slip_process, "SLIP driver"); - -uint8_t slip_active; - -#if 1 -#define SLIP_STATISTICS(statement) -#else -uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; -#define SLIP_STATISTICS(statement) statement -#endif - -/* Must be at least one byte larger than UIP_BUFSIZE! */ -#define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16) - -enum { - STATE_TWOPACKETS = 0, /* We have 2 packets and drop incoming data. */ - STATE_OK = 1, - STATE_ESC = 2, - STATE_RUBBISH = 3, -}; - -/* - * Variables begin and end manage the buffer space in a cyclic - * fashion. The first used byte is at begin and end is one byte past - * the last. I.e. [begin, end) is the actively used space. - * - * If begin != pkt_end we have a packet at [begin, pkt_end), - * furthermore, if state == STATE_TWOPACKETS we have one more packet at - * [pkt_end, end). If more bytes arrive in state STATE_TWOPACKETS - * they are discarded. - */ - -static uint8_t state = STATE_TWOPACKETS; -static uint16_t begin, end; -static uint8_t rxbuf[RX_BUFSIZE]; -static uint16_t pkt_end; /* SLIP_END tracker. */ - -static void (* input_callback)(void) = NULL; -static void (* tcpip_input_callback)(void) = NULL; -/*---------------------------------------------------------------------------*/ -void -slip_set_input_callback(void (*c)(void)) -{ - input_callback = c; -} -/*---------------------------------------------------------------------------*/ -void -slip_set_tcpip_input_callback(void (*c)(void)) -{ - tcpip_input_callback = c; -} -/*---------------------------------------------------------------------------*/ -uint8_t -slip_write(const void *_ptr, int len) -{ - const uint8_t *ptr = _ptr; - uint16_t i; - uint8_t c; - - slip_arch_writeb(SLIP_END); - - for(i = 0; i < len; ++i) { - c = *ptr++; - if(c == SLIP_END) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_END; - } else if(c == SLIP_ESC) { - slip_arch_writeb(SLIP_ESC); - c = SLIP_ESC_ESC; - } - slip_arch_writeb(c); - } - slip_arch_writeb(SLIP_END); - - return len; -} -/*---------------------------------------------------------------------------*/ -static void -rxbuf_init(void) -{ - begin = end = pkt_end = 0; - state = STATE_OK; -} -/*---------------------------------------------------------------------------*/ -/* Upper half does the polling. */ -static uint16_t -slip_poll_handler(uint8_t *outbuf, uint16_t blen) -{ - /* This is a hack and won't work across buffer edge! */ - if(rxbuf[begin] == 'C') { - int i; - if(begin < end && (end - begin) >= 6 - && memcmp(&rxbuf[begin], "CLIENT", 6) == 0) { - state = STATE_TWOPACKETS; /* Interrupts do nothing. */ - memset(&rxbuf[begin], 0x0, 6); - - rxbuf_init(); - - for(i = 0; i < 13; i++) { - slip_arch_writeb("CLIENTSERVER\300"[i]); - } - return 0; - } - } else if(rxbuf[begin] == '?') { - int i, j; - char* hexchar = "0123456789abcdef"; - if(begin < end && (end - begin) >= 2 - && rxbuf[begin + 1] == 'M') { - state = STATE_TWOPACKETS; /* Interrupts do nothing. */ - rxbuf[begin] = 0; - rxbuf[begin + 1] = 0; - - rxbuf_init(); - - /* this is just a test so far... just to see if it works */ - slip_arch_writeb('!'); - slip_arch_writeb('M'); - for(j = 0; j < 8; j++) { - slip_arch_writeb(hexchar[ds2411_id[j] >> 4]); - slip_arch_writeb(hexchar[ds2411_id[j] & 15]); - } - slip_arch_writeb(SLIP_END); - return 0; - } - } - - /* - * Interrupt can not change begin but may change pkt_end. - * If pkt_end != begin it will not change again. - */ - if(begin != pkt_end) { - uint16_t len; - - if(begin < pkt_end) { - len = pkt_end - begin; - if(len > blen) { - len = 0; - } else { - memcpy(outbuf, &rxbuf[begin], len); - } - } else { - len = (RX_BUFSIZE - begin) + (pkt_end - 0); - if(len > blen) { - len = 0; - } else { - unsigned i; - for(i = begin; i < RX_BUFSIZE; i++) { - *outbuf++ = rxbuf[i]; - } - for(i = 0; i < pkt_end; i++) { - *outbuf++ = rxbuf[i]; - } - } - } - - /* Remove data from buffer together with the copied packet. */ - begin = pkt_end; - if(state == STATE_TWOPACKETS) { - pkt_end = end; - state = STATE_OK; /* Assume no bytes where lost! */ - - /* One more packet is buffered, need to be polled again! */ - process_poll(&slip_process); - } - return len; - } - - return 0; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(slip_process, ev, data) -{ - PROCESS_BEGIN(); - - rxbuf_init(); - - while(1) { - PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); - - slip_active = 1; - - /* Move packet from rxbuf to buffer provided by uIP. */ - uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN], - UIP_BUFSIZE - UIP_LLH_LEN); - if(uip_len > 0) { - if(tcpip_input_callback) { - tcpip_input_callback(); - } else { - tcpip_input(); - } - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -int -slip_input_byte(unsigned char c) -{ - switch(state) { - case STATE_RUBBISH: - if(c == SLIP_END) { - state = STATE_OK; - } - return 0; - - case STATE_TWOPACKETS: /* Two packets are already buffered! */ - return 0; - - case STATE_ESC: - if(c == SLIP_ESC_END) { - c = SLIP_END; - } else if(c == SLIP_ESC_ESC) { - c = SLIP_ESC; - } else { - state = STATE_RUBBISH; - SLIP_STATISTICS(slip_rubbish++); - end = pkt_end; /* remove rubbish */ - return 0; - } - state = STATE_OK; - break; - - case STATE_OK: - if(c == SLIP_ESC) { - state = STATE_ESC; - return 0; - } else if(c == SLIP_END) { - /* - * We have a new packet, possibly of zero length. - * - * There may already be one packet buffered. - */ - if(end != pkt_end) { /* Non zero length. */ - if(begin == pkt_end) { /* None buffered. */ - pkt_end = end; - } else { - state = STATE_TWOPACKETS; - SLIP_STATISTICS(slip_twopackets++); - } - process_poll(&slip_process); - return 1; - } - return 0; - } - break; - } - - /* add_char: */ - { - unsigned next; - next = end + 1; - if(next == RX_BUFSIZE) { - next = 0; - } - if(next == begin) { /* rxbuf is full */ - state = STATE_RUBBISH; - SLIP_STATISTICS(slip_overflow++); - end = pkt_end; /* remove rubbish */ - return 0; - } - rxbuf[end] = c; - end = next; - } - - /* There could be a separate poll routine for this. */ - if(c == 'T' && rxbuf[begin] == 'C') { - process_poll(&slip_process); - return 1; - } - - return 0; -} -/*---------------------------------------------------------------------------*/ diff --git a/tools/sky/uip6-bridge/dev/slip.h b/tools/sky/uip6-bridge/dev/slip.h deleted file mode 100644 index d164ee97c..000000000 --- a/tools/sky/uip6-bridge/dev/slip.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- C -*- */ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -#ifndef SLIP_H_ -#define SLIP_H_ - -#include "contiki.h" - -PROCESS_NAME(slip_process); - -/** - * Send an IP packet from the uIP buffer with SLIP. - */ -uint8_t slip_send(void); - -/** - * Input a SLIP byte. - * - * This function is called by the RS232/SIO device driver to pass - * incoming bytes to the SLIP driver. The function can be called from - * an interrupt context. - * - * For systems using low-power CPU modes, the return value of the - * function can be used to determine if the CPU should be woken up or - * not. If the function returns non-zero, the CPU should be powered - * up. If the function returns zero, the CPU can continue to be - * powered down. - * - * \param c The data that is to be passed to the SLIP driver - * - * \return Non-zero if the CPU should be powered up, zero otherwise. - */ -int slip_input_byte(unsigned char c); - -uint8_t slip_write(const void *ptr, int len); - -/* Did we receive any bytes lately? */ -extern uint8_t slip_active; - -/* Statistics. */ -extern uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop; - -/** - * Set a function to be called when there is activity on the SLIP - * interface; used for detecting if a node is a gateway node. - */ -void slip_set_input_callback(void (*callback)(void)); - -/** - * Set a function to be called when a packet has been received. - * Default is tcpip_input(). - */ -void slip_set_tcpip_input_callback(void (*callback)(void)); - -/* - * These machine dependent functions and an interrupt service routine - * must be provided externally (slip_arch.c). - */ -void slip_arch_init(void); -void slip_arch_writeb(unsigned char c); - -#endif /* SLIP_H_ */ diff --git a/tools/sky/uip6-bridge/fakeuip.c b/tools/sky/uip6-bridge/fakeuip.c deleted file mode 100644 index 84f6440ce..000000000 --- a/tools/sky/uip6-bridge/fakeuip.c +++ /dev/null @@ -1,136 +0,0 @@ - -/* Various stub functions and uIP variables other code might need to - * compile. Allows you to save needing to compile all of uIP in just - * to get a few things */ - - -#include "net/ipv6/uip.h" -#include "net/ipv6/uip-ds6.h" -#include - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - -uip_buf_t uip_aligned_buf; - -uint16_t uip_len; - -struct uip_stats uip_stat; - -uip_lladdr_t uip_lladdr; - -uint16_t uip_htons(uint16_t val) { return UIP_HTONS(val);} - -uip_ds6_netif_t uip_ds6_if; - -/********** UIP_DS6.c **********/ - -void -uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr) -{ - /* We consider only links with IEEE EUI-64 identifier or - IEEE 48-bit MAC addresses */ -#if (UIP_LLADDR_LEN == 8) - memcpy(ipaddr->u8 + 8, lladdr, UIP_LLADDR_LEN); - ipaddr->u8[8] ^= 0x02; -#elif (UIP_LLADDR_LEN == 6) - memcpy(ipaddr->u8 + 8, lladdr, 3); - ipaddr->u8[11] = 0xff; - ipaddr->u8[12] = 0xfe; - memcpy(ipaddr->u8 + 13, lladdr + 3, 3); - ipaddr->u8[8] ^= 0x02; -#else -#error fakeuip.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8 -#endif -} - -/*---------------------------------------------------------------------------*/ -/* - * get a link local address - - * state = -1 => any address is ok. Otherwise state = desired state of addr. - * (TENTATIVE, PREFERRED, DEPRECATED) - */ -uip_ds6_addr_t * -uip_ds6_get_link_local(int8_t state) { - uip_ds6_addr_t *locaddr; - for(locaddr = uip_ds6_if.addr_list; - locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { - if((locaddr->isused) && (state == - 1 || locaddr->state == state) - && (uip_is_addr_linklocal(&locaddr->ipaddr))) { - return locaddr; - } - } - return NULL; -} - -uip_ds6_addr_t * -uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type) -{ - return NULL; -} -/********** UIP.c ****************/ - -static uint16_t -chksum(uint16_t sum, const uint8_t *data, uint16_t len) -{ - uint16_t t; - const uint8_t *dataptr; - const uint8_t *last_byte; - - dataptr = data; - last_byte = data + len - 1; - - while(dataptr < last_byte) { /* At least two more bytes */ - t = (dataptr[0] << 8) + dataptr[1]; - sum += t; - if(sum < t) { - sum++; /* carry */ - } - dataptr += 2; - } - - if(dataptr == last_byte) { - t = (dataptr[0] << 8) + 0; - sum += t; - if(sum < t) { - sum++; /* carry */ - } - } - - /* Return sum in host byte order. */ - return sum; -} - -static uint16_t -upper_layer_chksum(uint8_t proto) -{ - uint16_t upper_layer_len; - uint16_t sum; - - upper_layer_len = (((uint16_t)(UIP_IP_BUF->len[0]) << 8) + UIP_IP_BUF->len[1]) ; - - /* First sum pseudoheader. */ - /* IP protocol and length fields. This addition cannot carry. */ - sum = upper_layer_len + proto; - /* Sum IP source and destination addresses. */ - sum = chksum(sum, (uint8_t *)&UIP_IP_BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t)); - - /* Sum TCP header and data. */ - sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], - upper_layer_len); - - return (sum == 0) ? 0xffff : uip_htons(sum); -} - -/*---------------------------------------------------------------------------*/ -uint16_t -uip_icmp6chksum(void) -{ - return upper_layer_chksum(UIP_PROTO_ICMP6); -} - -/*---------------------------------------------------------------------------*/ -void -uip_ds6_link_callback(int status, int numtx) -{ - -} diff --git a/tools/sky/uip6-bridge/radvd.conf b/tools/sky/uip6-bridge/radvd.conf deleted file mode 100644 index d6dd41e2b..000000000 --- a/tools/sky/uip6-bridge/radvd.conf +++ /dev/null @@ -1,16 +0,0 @@ -interface tap0 { - AdvSendAdvert on; - AdvLinkMTU 1280; - AdvCurHopLimit 128; - AdvReachableTime 360000; - MinRtrAdvInterval 100; - MaxRtrAdvInterval 150; - AdvDefaultLifetime 200; - prefix AAAA::/64 - { - AdvOnLink on; - AdvAutonomous on; - AdvPreferredLifetime 4294967295; - AdvValidLifetime 4294967295; - }; -}; diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c deleted file mode 100644 index 7217e3229..000000000 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ /dev/null @@ -1,882 +0,0 @@ -/** - * \file sicslow_ethernet.c - * Routines to interface between Ethernet and 6LowPan - * - * \author - * Colin O'Flynn - * - * \addtogroup usbstick - */ - -/* Copyright (c) 2008 by: - * Colin O'Flynn coflynn@newae.com - * Eric Gnoske egnoske@gmail.com - * Blake Leverett bleverett@gmail.com - * Mike Vidales mavida404@gmail.com - * Kevin Brown kbrown3@uccs.edu - * Nate Bohlmann nate@elfwerks.com - * - * 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 holders nor the names of - * 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 OWNER 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. - */ - -/** - \ingroup usbstick - \defgroup sicslowinterop 6LowPan Ethernet Interop - @{ -*/ - - -/** - \par Ethernet to 6LowPan Address Translation - - It should be obvious that since 802.15.4 addresses are 8 - bytes, and 802.3 addresses are 6 bytes, some form of - address translation is needed. These routines provide this - - \par 802.3 Address Formats - - 802.3 MAC addresses used here have this form: - - \verbatim - +----+----+----+----+----+----+----+----+ - + + + + + + TR + GL + MU + - +----+----+----+----+----+----+----+----+ - \endverbatim - - - It can be seen this is like a normal ethernet MAC address, - with GL being the Global/Local bit, and MU being the - Multicast/Unicast bit. - - The addition is the 'TR' bit, which if set indicates that - the address must be translated when going between 802.15.4 - and 802.3. - - \par Address Translation - - If the TRANSLATE (TR) bit is CLEAR, this means the 5th and - 4th LSBytes of the 802.15.4 address are fffe, aka the address - has the hexidecial form: - - xxxxxxfffexxxxxx - - \note - You should always aim to set the 802.15.4 addresses - of the devices on your network to ones that will - satisfy this requirement. Some examples are: - \note - 0x02 23 42 ff fe 73 92 28 - \note - 0x82 00 82 ff fe cd ee 22 - - \note - So the most significant octets MUST - have bit 0 CLEAR, bit 1 SET, and bit 2 CLEAR. The remaining - bits in this octet can be anything. - - If the TRANSLATE bit is SET, this means the address on the - 802.3 side does not directly convert to an 802.15.4 address. - To translate it, the remainder of the octet is used as an - index in a look-up table. This look-up table simply stores - the 4th, 5th, and 8th octet of the 802.15.4 address, and attaches - them to the remaining 5 bytes of the 802.3 address. - - In this way there can be 32 different 802.15.4 'prefixes', - requiring only 96 bytes of RAM in a storage table on the - 802.3 to 802.15.4 bridge. - - Mulitcast addresses on 802.3 are mapped to broadcast addresses on - 802.15.4 and vis-versa. Since IPv6 does not use 802.3 broadcast, - this code will drop all 802.3 broadcast packets. They are most - likely something unwanted, such as IPv4 packets that snuck in. - - \par Notes on how addresses are stored - - An 802.15.4 address will be reported for example as: - - 0x8877665544332211 - - Stored in the array as passed to these functions, it will be: - \verbatim - array[0] = 0x88; - array[1] = 0x77; - array[2] = 0x66; - etc. - \endverbatim - - An 802.3 address will be reported for example as: - 02:43:53:35:45:45 - - Stored in the array as passed to these functions, it will be: - \verbatim - array[0] = 0x02; - array[1] = 0x43; - array[2] = 0x53; - array[3] = 0x35 - etc. - \endverbatim -*/ - -#include "uip.h" -#include "uip_arp.h" /* For ethernet header structure */ -#include "net/ipv6/sicslowpan.h" -#include "sicslow_ethernet.h" - -#include -#include -#include - -//#define PRINTF printf -#define PRINTF(...) - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define ETHBUF(x) ((struct uip_eth_hdr *)x) - -//For little endian, such as our friend mr. AVR -#ifndef LSB -#define LSB(u16) (((uint8_t *)&(u16))[0]) //!< Least significant byte of \a u16. -#define MSB(u16) (((uint8_t *)&(u16))[1]) //!< Most significant byte of \a u16. -#endif - -usbstick_mode_t usbstick_mode; - -uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan); -uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan); -/* uint8_t memcmp_reverse(uint8_t * a, uint8_t * b, uint8_t num); */ -/* void mac_ethhijack_nondata(const struct mac_driver *r); */ -/* void mac_ethhijack(const struct mac_driver *r); */ - -/* extern void (*sicslowmac_snifferhook)(const struct mac_driver *r); */ - - -//! Location of TRANSLATE (TR) bit in Ethernet address -#define TRANSLATE_BIT_MASK (1<<2) -//! Location of LOCAL (GL) bit in Ethernet address -#define LOCAL_BIT_MASK (1<<1) -//! Location of MULTICAST (MU) bit in Ethernet address -#define MULTICAST_BIT_MASK (1<<0) - -#define PREFIX_BUFFER_SIZE 32 - -uint8_t prefixCounter; -uint8_t prefixBuffer[PREFIX_BUFFER_SIZE][3]; - -/* 6lowpan max size + ethernet header size + 1 */ -uint8_t raw_buf[127+ UIP_LLH_LEN +1]; - - -/* void tcpip_input( void ) */ -/* { */ -/* mac_LowpanToEthernet(); */ -/* } */ - -/** - * \brief Perform any setup needed - */ -/* struct mac_driver * pmac; */ -void mac_ethernetSetup(void) -{ - usbstick_mode.sicslowpan = 1; - usbstick_mode.sendToRf = 1; - usbstick_mode.translate = 1; - usbstick_mode.raw = 1; - -/* sicslowinput = pinput; */ - - -/* pmac = sicslowmac_get_driver(); */ -/* pmac->set_receive_function(mac_ethhijack); */ -/* sicslowmac_snifferhook = mac_ethhijack_nondata; */ -} - - -/** - * \brief Take a packet received over the ethernet link, and send it - * out over 802.15.4 - */ -void mac_ethernetToLowpan(uint8_t * ethHeader) -{ - //Dest address - uip_lladdr_t destAddr; - uip_lladdr_t *destAddrPtr = NULL; - - PRINTF("Packet type: %x\n", ((struct uip_eth_hdr *) ethHeader)->type); - - //RUM doesn't support sending data - #if UIP_CONF_USE_RUM - return; - #endif - - //If not IPv6 we don't do anything - if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) { - PRINTF("eth2low: Packet is not IPv6, dropping\n"); -/* rndis_stat.txbad++; */ - uip_clear_buf(); - return; - } - - // In sniffer mode we don't ever send anything - if (usbstick_mode.sendToRf == 0) { - uip_clear_buf(); - return; - } - - /* IPv6 uses 33-33-xx-xx-xx-xx prefix for multicast ND stuff */ - if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0x33) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0x33) ) - { - PRINTF("eth2low: Ethernet multicast packet received\n"); - ;//Do Nothing - } else if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0xFF) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0xFF) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[2] == 0xFF) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[3] == 0xFF) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[4] == 0xFF) && - (((struct uip_eth_hdr *) ethHeader)->dest.addr[5] == 0xFF) ) { - /* IPv6 does not use broadcast addresses, hence this should not happen */ - PRINTF("eth2low: Ethernet broadcast address received, should not happen?\n"); -/* rndis_stat.txbad++; */ - uip_clear_buf(); - return; - } else { - PRINTF("eth2low: Addressed packet received... "); - //Check this returns OK - if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) { - PRINTF(" translation failed\n"); -/* rndis_stat.txbad++; */ - uip_clear_buf(); - return; - } - PRINTF(" translated OK\n"); - destAddrPtr = &destAddr; - } - - //Remove header from length before passing onward - if(uip_len > UIP_LLH_LEN) { - uip_len -= UIP_LLH_LEN; - - //Some IP packets have link layer in them, need to change them around! - if (usbstick_mode.translate) { - /* uint8_t transReturn = */ - mac_translateIPLinkLayer(ll_802154_type); - PRINTF("IPTranslation: returns %d\n", transReturn); - } - - if (usbstick_mode.sendToRf){ - tcpip_output(destAddrPtr); - /* rndis_stat.txok++; */ - } - } - - uip_clear_buf(); - -} - - -/** - * \brief Take a packet received over the 802.15.4 link, and send it - * out over ethernet, performing any translations needed. - */ -void mac_LowpanToEthernet(void) -{ -/* parsed_frame = sicslowmac_get_frame(); */ - - //Setup generic ethernet stuff - ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6); - - //Check for broadcast message - if(packetbuf_holds_broadcast()) { -/* if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && */ -/* ( parsed_frame->dest_addr->addr16 == 0xffff) ) { */ - ETHBUF(uip_buf)->dest.addr[0] = 0x33; - ETHBUF(uip_buf)->dest.addr[1] = 0x33; - ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12]; - ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13]; - ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14]; - ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15]; - } else { - //Otherwise we have a real address - mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->dest.addr[0]), - (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); - } - - - mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]), - (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); - - //We only do address translation in network mode! - if (usbstick_mode.translate) { - //Some IP packets have link layer in them, need to change them around! - mac_translateIPLinkLayer(ll_8023_type); - } - - PRINTF("Low2Eth: Sending packet to ethernet\n"); - - uip_len += UIP_LLH_LEN; - -/* rndis_send(uip_buf, uip_len, 1); */ -/* rndis_stat.rxok++; */ -/* uip_clear_buf(); */ -} - -/** - * \brief Translate IP packet's possible link-layer addresses, passing - * the message to the appropriate higher level function for this - * packet (aka: ICMP) - * \param target The target we want to end up with - either ll_8023_type - * for ethernet, or ll_802154_type for 802.15.4 - * \return Returns how successful the translation was - * \retval 0 Addresses, if present, were translated. - * \retval <0 Negative return values indicate various errors, as defined - * by the higher level function. - */ -int8_t mac_translateIPLinkLayer(lltype_t target) -{ - -#if UIP_LLADDR_LEN == 8 - if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) { - PRINTF("eth2low: ICMP Message detected\n"); - return mac_translateIcmpLinkLayer(target); - } - return 0; -#else - return 1; -#endif - -} - -#include "net/ipv6/uip-icmp6.h" -#include "net/ipv6/uip-nd6.h" - -typedef struct { - uint8_t type; - uint8_t length; - uint8_t data[16]; -} icmp_opts_t; - -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) -#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x]) - -void slide(uint8_t * data, uint8_t length, int16_t slide); - -/** - * \brief Translate the link-layer (L2) addresses in an ICMP packet. - * This will just be NA/NS/RA/RS packets currently. - * \param target The target we want to end up with - either ll_8023_type - * for ethernet, or ll_802154_type for 802.15.4 - * \return Returns how successful the translation was - * \retval 0 Addresses, if present, were translated. - * \retval -1 ICMP message was unknown type, nothing done. - * \retval -2 ICMP Length does not make sense? - * \retval -3 Unknown 'target' type - */ -int8_t mac_translateIcmpLinkLayer(lltype_t target) -{ - uint16_t icmp_opt_offset = 0; - int16_t len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8); - - uint16_t iplen; - - uint8_t i; - - int16_t sizechange; - - uint8_t llbuf[16]; - - //Figure out offset to start of options - switch(UIP_ICMP_BUF->type) { - case ICMP6_NS: - case ICMP6_NA: - icmp_opt_offset = 24; - break; - - case ICMP6_RS: - icmp_opt_offset = 8; - break; - - case ICMP6_RA: - icmp_opt_offset = 16; - break; - - case ICMP6_REDIRECT: - icmp_opt_offset = 40; - break; - - /** Things without link-layer */ - case ICMP6_DST_UNREACH: - case ICMP6_PACKET_TOO_BIG: - case ICMP6_TIME_EXCEEDED: - case ICMP6_PARAM_PROB: - case ICMP6_ECHO_REQUEST: - case ICMP6_ECHO_REPLY: - return 0; - break; - - default: - return -1; - } - - //Figure out length of options - len -= icmp_opt_offset; - - //Sanity check - if (len < 8) return -2; - - //While we have options to do... - while (len >= 8){ - - //If we have one of these, we have something useful! - if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) || - ((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) ) { - - /* Shrinking the buffer may thrash things, so we store the old - link-layer address */ - for(i = 0; i < (UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++) { - llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i]; - } - - //Shrink/grow buffer as needed - if (target == ll_802154_type) { - //Current is 802.3, Hence current link-layer option is 6 extra bytes - sizechange = 8; - slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange); - } else if (target == ll_8023_type) { - /* Current is 802.15.4, Hence current link-layer option is 14 extra - * bytes. - * (Actual LL is 8 bytes, but total option length is in multiples of - * 8 Bytes, hence 8 + 2 = 10. Closest is 16 bytes, then 16 bytes for - * total optional length - 2 bytes for type + length leaves 14 ) - */ - sizechange = -8; - slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange); - } else { - return -3; //Uh-oh! - } - - //Translate addresses - if (target == ll_802154_type) { - mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data); - } else { - mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf); - } - - //Adjust the length - if (target == ll_802154_type) { - UIP_ICMP_OPTS(icmp_opt_offset)->length = 2; - } else { - UIP_ICMP_OPTS(icmp_opt_offset)->length = 1; - } - - //Adjust the IP header length, as well as uIP length - iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8); - iplen += sizechange; - len += sizechange; - - UIP_IP_BUF->len[1] = (uint8_t)iplen; - UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8); - - uip_len += sizechange; - - //We broke ICMP checksum, be sure to fix that - UIP_ICMP_BUF->icmpchksum = 0; - UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); - - //Finally set up next run in while loop - len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length; - icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length; - } else { - - //Not an option we care about, ignore it - len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length; - - //This shouldn't happen! - if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0) { - PRINTF("Option in ND packet has length zero, error?\n"); - len = 0; - } - - icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length; - - } //If ICMP_OPT is one we care about - - } //while(len >= 8) - - return 0; - -} - - -/** - * \brief Create a 802.15.4 long address from a 802.3 address - * \param ethernet Pointer to ethernet address - * \param lowpan Pointer to 802.15.4 address - */ -uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan) -{ - uint8_t index; - -#if UIP_LLADDR_LEN == 8 - //Special case - if the address is our address, we just copy over what we know to be - //our 802.15.4 address - -/* if (memcmp_reverse((uint8_t *)&rndis_ethernet_addr, ethernet, 6) == 0) { */ - if (memcmp((uint8_t *)&uip_lladdr.addr[2], ethernet, 6) == 0) { - memcpy((uint8_t *)lowpan, uip_lladdr.addr, 8); -/* byte_reverse((uint8_t *)lowpan, 8); */ - - return 1; - } - - //Check if translate bit is set, hence we have to look up the prefix - if (ethernet[0] & TRANSLATE_BIT_MASK) { - - //Get top bits - index = ethernet[0] >> 3; - - //Check this is plausible... - if (index >= prefixCounter) { - return 0; - } - - //Copy over prefix - lowpan->addr[0] = prefixBuffer[index][0]; - lowpan->addr[3] = prefixBuffer[index][1]; - lowpan->addr[4] = prefixBuffer[index][2]; - - //Bit is clear - //so we copy all six - } else { - lowpan->addr[0] = ethernet[0]; - lowpan->addr[3] = 0xff; - lowpan->addr[4] = 0xfe; - } - - //Copy over reamining five bytes - lowpan->addr[1] = ethernet[1]; - lowpan->addr[2] = ethernet[2]; - lowpan->addr[5] = ethernet[3]; - lowpan->addr[6] = ethernet[4]; - lowpan->addr[7] = ethernet[5]; - -#else - uint8_t i; - - for(i = 0; i < UIP_LLADDR_LEN; i++) { - lowpan->addr[i] = ethernet[i]; - } -#endif - - return 1; -} - - -/** - * \brief Create a 802.3 address from a 802.15.4 long address - * \param ethernet Pointer to ethernet address - * \param lowpan Pointer to 802.15.4 address - */ -uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan) -{ - uint8_t index = 0; - uint8_t i; -/* uint8_t j, match; */ - -#if UIP_LLADDR_LEN == 8 - - //Special case - if the address is our address, we just copy over what we know to be - //our 802.3 address -/* if (memcmp_reverse(uip_lladdr.addr, (uint8_t *)lowpan, 8) == 0) { */ - if (memcmp(uip_lladdr.addr, (uint8_t *)lowpan, 8) == 0) { - memcpy(ethernet, &uip_lladdr.addr[2], 6); -/* byte_reverse(ethernet, 6); */ - - return 1; - } - - - //Check if we need to do anything: - if ((lowpan->addr[3] == 0xff) && (lowpan->addr[4] == 0xfe) && - ((lowpan->addr[0] & TRANSLATE_BIT_MASK) == 0) && - ((lowpan->addr[0] & MULTICAST_BIT_MASK) == 0) && - (lowpan->addr[0] & LOCAL_BIT_MASK)) { - - /** Nope: just copy over 6 bytes **/ - ethernet[0] = lowpan->addr[0]; - ethernet[1] = lowpan->addr[1]; - ethernet[2] = lowpan->addr[2]; - ethernet[3] = lowpan->addr[5]; - ethernet[4] = lowpan->addr[6]; - ethernet[5] = lowpan->addr[7]; - - - } else { - - /** Yes: need to store prefix **/ - for (i = 0; i < prefixCounter; i++) { - //Check the current prefix - if it fails, check next one - - - if ((lowpan->addr[0] == prefixBuffer[i][0]) && - (lowpan->addr[3] == prefixBuffer[i][1]) && - (lowpan->addr[4] == prefixBuffer[i][2])) { - break; - } - - } - - index = i; - - //Deal with overflow, iron-fist style - if (index >= PREFIX_BUFFER_SIZE) { - index = 0; - prefixCounter = PREFIX_BUFFER_SIZE; - } else { - //Are we making a new one? - if (index == prefixCounter) { - prefixCounter++; - } - } - - //Copy the prefix over, no matter if we have a new or old one - prefixBuffer[index][0] = lowpan->addr[0]; - prefixBuffer[index][1] = lowpan->addr[3]; - prefixBuffer[index][2] = lowpan->addr[4]; - - //Create ethernet MAC address now - ethernet[1] = lowpan->addr[1]; - ethernet[2] = lowpan->addr[2]; - ethernet[3] = lowpan->addr[5]; - ethernet[4] = lowpan->addr[6]; - ethernet[5] = lowpan->addr[7]; - - - ethernet[0] = TRANSLATE_BIT_MASK | LOCAL_BIT_MASK | (index << 3); - } - -#else - - //Create ethernet MAC address now - for(i = 0; i < UIP_LLADDR_LEN; i++) { - ethernet[i] = lowpan->addr[i]; - } -#endif - - return 1; -} - - -/** - * \brief Slide the pointed to memory up a certain amount, - * growing/shrinking a buffer - * \param data Pointer to start of data buffer - * \param length Length of the data buffer - * \param slide How many bytes to slide the buffer up in memory (if +) or - * down in memory (if -) - */ -void slide(uint8_t * data, uint8_t length, int16_t slide) -{ - //Sanity checks - if (!length) return; - if (!slide) return; - - uint8_t i = 0; - - while(length) { - length--; - - //If we are sliding up, we do from the top of the buffer down - if (slide > 0) { - *(data + length + slide) = *(data + length); - - //If we are sliding down, we do from the bottom of the buffer up - } else { - *(data + slide + i) = *(data + i); - } - - i++; - } -} - -/*--------------------------------------------------------------------*/ -/** \brief Process a received 6lowpan packet. Hijack function. - * \param r The MAC layer - * - * The 6lowpan packet is put in packetbuf by the MAC. This routine calls - * any other needed layers (either 6lowpan, or just raw ethernet dump) - */ -#if 0 -void mac_ethhijack(const struct mac_driver *r) -{ - if (usbstick_mode.raw) { - mac_802154raw(r); - } - - if (usbstick_mode.sicslowpan) { - -#if UIP_CONF_USE_RUM - if (parsed_frame->payload[4]) { /* RUM 6lowpan frame type */ -#endif - sicslowinput(r); -#if UIP_CONF_USE_RUM - } -#endif - - - } - -} -#endif - -#if 0 -void mac_ethhijack_nondata(const struct mac_driver *r) -{ - if (usbstick_mode.raw) - mac_802154raw(r); -} -#endif - -/*--------------------------------------------------------------------*/ -/*--------------------------------------------------------------------*/ -/** \brief Logs a sent 6lowpan frame - * - * This routine passes a frame - * directly to the ethernet layer without decompressing. - */ -#if 0 -void mac_logTXtoEthernet(frame_create_params_t *p,frame_result_t *frame_result) -{ - uint8_t sendlen; - - /* Make sure we are supposed to do this */ - if (usbstick_mode.raw == 0) return; - -/* Get the raw frame */ - memcpy(&raw_buf[UIP_LLH_LEN], frame_result->frame, frame_result->length); - sendlen = frame_result->length; - - //Setup generic ethernet stuff - ETHBUF(raw_buf)->type = uip_htons(UIP_ETHTYPE_802154); - - uint64_t tempaddr; - - - //Check for broadcast message - //if(linkaddr_cmp((const linkaddr_t *)destAddr, &linkaddr_null)) { - if( ( p->fcf.destAddrMode == SHORTADDRMODE) && - ( p->dest_addr.addr16 == 0xffff) ) { - ETHBUF(raw_buf)->dest.addr[0] = 0x33; - ETHBUF(raw_buf)->dest.addr[1] = 0x33; - ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12]; - ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13]; - ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14]; - ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15]; - } else { - - tempaddr = p->dest_addr.addr64; - - byte_reverse((uint8_t *)&tempaddr, 8); - - //Otherwise we have a real address - mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]), - (uip_lladdr_t *)&tempaddr); - - } - - tempaddr = p->src_addr.addr64; - - byte_reverse((uint8_t *)&tempaddr, 8); - - mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]), - (uip_lladdr_t *)&tempaddr); - - PRINTF("Low2Eth: Sending 802.15.4 packet to ethernet\n"); - - sendlen += UIP_LLH_LEN; - - rndis_send(raw_buf, sendlen, 0); - rndis_stat.rxok++; - return; -} -#endif - -/*--------------------------------------------------------------------*/ -/** \brief Process a received 6lowpan packet. - * \param r The MAC layer - * - * The 6lowpan packet is put in packetbuf by the MAC. This routine passes - * it directly to the ethernet layer without decompressing. - */ -#if 0 -void mac_802154raw(const struct mac_driver *r) -{ - uint8_t sendlen; - - parsed_frame = sicslowmac_get_frame(); - - /* Get the raw frame */ - memcpy(&raw_buf[UIP_LLH_LEN], radio_frame_data(), radio_frame_length()); - sendlen = radio_frame_length(); - - //Setup generic ethernet stuff - ETHBUF(raw_buf)->type = uip_htons(UIP_ETHTYPE_802154); - - - //Check for broadcast message - //if(linkaddr_cmp((const linkaddr_t *)destAddr, &linkaddr_null)) { - if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) && - ( parsed_frame->dest_addr->addr16 == 0xffff) ) { - ETHBUF(raw_buf)->dest.addr[0] = 0x33; - ETHBUF(raw_buf)->dest.addr[1] = 0x33; - ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12]; - ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13]; - ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14]; - ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15]; - } else { - - //Otherwise we have a real address - mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]), - (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); - - } - - mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]), - (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); - - PRINTF("Low2Eth: Sending 802.15.4 packet to ethernet\n"); - - sendlen += UIP_LLH_LEN; - - rndis_send(raw_buf, sendlen, 1); - rndis_stat.rxok++; - - return; -} -#endif -/** @} */ -/** @} */ diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.h b/tools/sky/uip6-bridge/sicslow_ethernet.h deleted file mode 100644 index 2e48c188e..000000000 --- a/tools/sky/uip6-bridge/sicslow_ethernet.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * \file sicslow_ethernet.c - * Routines to interface between Ethernet and 6LowPan - * - * \author - * Colin O'Flynn - * - * \addtogroup usbstick - */ - -/* Copyright (c) 2008 by: - - Colin O'Flynn coflynn@newae.com - Eric Gnoske egnoske@gmail.com - Blake Leverett bleverett@gmail.com - Mike Vidales mavida404@gmail.com - Kevin Brown kbrown3@uccs.edu - Nate Bohlmann nate@elfwerks.com - - 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 holders nor the names of - 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 OWNER 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. -*/ - -#ifndef SICSLOW_ETHERNET_H -#define SICSLOW_ETHERNET_H - -typedef enum { - ll_802154_type, - ll_8023_type -} lltype_t; - - -typedef struct { - uint8_t sicslowpan :1; - uint8_t sendToRf :1; - uint8_t translate :1; - uint8_t raw :1; -} usbstick_mode_t; - - -#define UIP_ETHTYPE_802154 0x809A - -extern usbstick_mode_t usbstick_mode; - - -int8_t mac_translateIcmpLinkLayer(lltype_t target); -int8_t mac_translateIPLinkLayer(lltype_t target); -void mac_LowpanToEthernet(void); -void mac_ethernetToLowpan(uint8_t * ethHeader); -void mac_ethernetSetup(void); -/* void mac_802154raw(const struct mac_driver *r); */ -/* void mac_logTXtoEthernet(frame_create_params_t *p,frame_result_t *frame_result); */ - -#endif diff --git a/tools/sky/uip6-bridge/uip6-bridge-tap.c b/tools/sky/uip6-bridge/uip6-bridge-tap.c deleted file mode 100644 index 694499b6d..000000000 --- a/tools/sky/uip6-bridge/uip6-bridge-tap.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2009, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * - */ - -/** - * \file - * A brief description of what this file is - * \author - * Niclas Finne - * Joakim Eriksson - */ - -#include "contiki.h" -#include "net/ipv6/uip.h" -#include "dev/slip.h" -#include "dev/leds.h" -#include "sicslow_ethernet.h" - -#include "net/packetbuf.h" - -#include -#include - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - -PROCESS(uip6_bridge, "IPv6/6lowpan TAP bridge"); -PROCESS(tcpip_process, "tcpip dummy"); -AUTOSTART_PROCESSES(&uip6_bridge); - -/*---------------------------------------------------------------------------*/ -static uint8_t (* outputfunc)(const uip_lladdr_t *a); -uint8_t -tcpip_output(const uip_lladdr_t *a) -{ - if(outputfunc != NULL) { - outputfunc(a); - leds_toggle(LEDS_GREEN); - } - return 0; -} -void -tcpip_ipv6_output(void) -{ -} -void -tcpip_set_outputfunc(uint8_t (*f)(const uip_lladdr_t *)) -{ - outputfunc = f; -} -PROCESS_THREAD(tcpip_process, ev, data) -{ - PROCESS_BEGIN(); - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/* Packet from SICSLoWPAN */ -void -tcpip_input(void) -{ - if(uip_len > 0) { - mac_LowpanToEthernet(); - if(uip_len > 0) { - slip_write(uip_buf, uip_len); - leds_toggle(LEDS_RED); - uip_clear_buf(); - } - } -} -/*---------------------------------------------------------------------------*/ -/* Packet from SLIP */ -static void -slip_tcpip_input(void) -{ - /* TODO Should fix this in slip configuration */ - memmove(uip_buf, &uip_buf[UIP_LLH_LEN], uip_len); - mac_ethernetToLowpan(uip_buf); -} -/*---------------------------------------------------------------------------*/ -static void -slip_activity(void) -{ - leds_toggle(LEDS_BLUE); -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(uip6_bridge, ev, data) -{ - PROCESS_BEGIN(); - - printf("Setting up SLIP\n"); - - mac_ethernetSetup(); - - slip_arch_init(); - slip_set_input_callback(slip_activity); - slip_set_tcpip_input_callback(slip_tcpip_input); - process_start(&slip_process, NULL); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -int -putchar(int c) -{ -#define SLIP_END 0300 - static char debug_frame = 0; - - if(!debug_frame) { /* Start of debug output */ - slip_arch_writeb(SLIP_END); - slip_arch_writeb('\r'); /* Type debug line == '\r' */ - debug_frame = 1; - } - - slip_arch_writeb((char)c); - - /* - * Line buffered output, a newline marks the end of debug output and - * implicitly flushes debug output. - */ - if(c == '\n') { - slip_arch_writeb(SLIP_END); - debug_frame = 0; - } - return c; -} -/*---------------------------------------------------------------------------*/ diff --git a/tools/wpcapslip/wpcap.c b/tools/wpcapslip/wpcap.c index 54fc4e873..0d667d617 100644 --- a/tools/wpcapslip/wpcap.c +++ b/tools/wpcapslip/wpcap.c @@ -451,7 +451,7 @@ arp_out(struct ethip_hdr *iphdr, int len) arphdr->protolen = 4; arphdr->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP); - /* uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];*/ + /* uip_appdata = &uip_buf[UIP_IPTCPH_LEN];*/ return sizeof(struct arp_hdr); } diff --git a/tools/zolertia/license-bsl.txt b/tools/zolertia/license-bsl.txt deleted file mode 100644 index e6775e9d7..000000000 --- a/tools/zolertia/license-bsl.txt +++ /dev/null @@ -1,62 +0,0 @@ -Copyright (c) 2001-2003 Chris Liechti - -All Rights Reserved. - -This is the Python license. In short, you can use this product in -commercial and non-commercial applications, modify it, redistribute it. -A notification to the author when you use and/or modify it is welcome. - -TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE -============================================ - -LICENSE AGREEMENT ------------------ - -1. This LICENSE AGREEMENT is between the copyright holder of this -product, and the Individual or Organization ("Licensee") accessing -and otherwise using this product in source or binary form and its -associated documentation. - -2. Subject to the terms and conditions of this License Agreement, -the copyright holder hereby grants Licensee a nonexclusive, -royalty-free, world-wide license to reproduce, analyze, test, -perform and/or display publicly, prepare derivative works, distribute, -and otherwise use this product alone or in any derivative version, -provided, however, that copyright holders License Agreement and -copyright holders notice of copyright are retained in this product -alone or in any derivative version prepared by Licensee. - -3. In the event Licensee prepares a derivative work that is based on -or incorporates this product or any part thereof, and wants to make -the derivative work available to others as provided herein, then -Licensee hereby agrees to include in any such work a brief summary of -the changes made to this product. - -4. The copyright holder is making this product available to Licensee -on an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS -OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT -LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY -REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR -ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS PRODUCT WILL -NOT INFRINGE ANY THIRD PARTY RIGHTS. - -5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY -OTHER USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR -CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, -DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY -DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY -THEREOF. - -6. This License Agreement will automatically terminate upon a -material breach of its terms and conditions. - -7. Nothing in this License Agreement shall be deemed to create any -relationship of agency, partnership, or joint venture between the -copyright holder and Licensee. This License Agreement does not grant -permission to use trademarks or trade names from the copyright holder -in a trademark sense to endorse or promote products or services of -Licensee, or any third party. - -8. By copying, installing or otherwise using this product, Licensee -agrees to be bound by the terms and conditions of this License -Agreement. diff --git a/tools/zolertia/motelist-zolertia b/tools/zolertia/motelist-zolertia deleted file mode 100755 index e5f7da99e..000000000 --- a/tools/zolertia/motelist-zolertia +++ /dev/null @@ -1,295 +0,0 @@ -#!/usr/bin/perl -w -use strict; -# $Id: motelist-z1,v 1.1 2010/08/24 15:48:20 joxe Exp $ -# @author Cory Sharp -# @author Joe Polastre - -my $help = <<'EOF'; -usage: motelist [options] - - $Revision: 1.1 $ - -options: - -h display this help - -c compact format, not pretty but easier for parsing - -f specify the usb-serial file (for smote.cs) - -k kernel version: 2.4, 2.6, auto (default) - -m method to scan usb: procfs, sysfs, auto (default) - -dev_prefix force the device prefix for the serial device - -usb display extra usb information - -b specify which Zolertia board to list (z1, remote, etc) -EOF - -my %Opt = ( - compact => 0, - usb => 0, - board => "", - method => "auto", - kernel => "auto", - dev_prefix => [ "/dev/usb/tts/", "/dev/ttyUSB", "/dev/tts/USB" ], - usbserial => "sudo cat /proc/tty/driver/usbserial |", -); - -while (@ARGV) { - last unless $ARGV[0] =~ /^-/; - my $opt = shift @ARGV; - if( $opt eq "-h" ) { print "$help\n"; exit 0; } - elsif( $opt eq "-c" ) { $Opt{compact} = 1; } - elsif( $opt eq "-f" ) { $Opt{usbserial} = shift @ARGV; } - elsif( $opt eq "-k" ) { $Opt{kernel} = shift @ARGV; } - elsif( $opt eq "-m" ) { $Opt{method} = shift @ARGV; } - elsif( $opt eq "-dev_prefix" ) { $Opt{dev_prefix} = shift @ARGV; } - elsif( $opt eq "-usb" ) { $Opt{usb} = 1; } - elsif( $opt eq "-b" ) { $Opt{board} = shift @ARGV; } - else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; } -} - -if( $Opt{kernel} eq "auto" ) { - $Opt{kernel} = "unknown"; - $Opt{kernel} = $1 if snarf("/proc/version") =~ /\bLinux version (\d+\.\d+)/; -} - -if( $Opt{method} eq "auto" ) { - $Opt{method} = ($Opt{kernel} eq "2.4") ? "procfs" : "sysfs"; -} - -if( $Opt{board} eq "z1" ) { - $Opt{board} = "Zolertia Z1"; -} elsif( $Opt{board} eq "remote" ) { - $Opt{board} = "Zolertia RE-Mote platform"; -} elsif( $Opt{board} eq "firefly" ) { - $Opt{board} = "Zolertia Firefly platform"; -} elsif( $Opt{board} eq "orion" ) { - $Opt{board} = "Zolertia Orion Ethernet router"; -} - -my @devs = $Opt{method} eq "procfs" ? scan_procfs() : scan_sysfs(); -print_motelist( sort { cmp_usbdev($a,$b) } @devs ); - - -# -# SysFS -# -sub scan_sysfs { - - my $tmp = '($_->{UsbVendor}||"") eq "10c4" && ($_->{UsbProduct}||"") eq "ea60"'; - - if($Opt{board}) { - $tmp = '($_->{ProductString}||"") eq $Opt{board} && ' . $tmp - } - - # Scan /sys/bus/usb/drivers/usb for CP210x devices - my @cpdevs = - grep { eval "$tmp" } - map { { - SysPath => $_, - UsbVendor => snarf("$_/idVendor",1), - UsbProduct => snarf("$_/idProduct",1), - ProductString => snarf("$_/product",1), - } } - glob("/sys/bus/usb/drivers/usb/*"); - - # Gather information about each CP210x device - for my $f (@cpdevs) { - my $syspath = $f->{SysPath}; - $f->{InfoSerial} = snarf("$syspath/serial",1); - $f->{InfoManufacturer} = snarf("$syspath/manufacturer",1); - $f->{InfoProduct} = snarf("$syspath/product",1); - $f->{UsbDevNum} = snarf("$syspath/devnum",1); - - my $devstr = readlink($syspath); - if( $devstr =~ m{([^/]+)/usb(\d+)/.*-([^/]+)$} ) { - $f->{UsbPath} = "usb-$1-$3"; - $f->{UsbBusNum} = $2; - } - ($f->{SysDev} = $syspath) =~ s{^.*/}{}; - - my $port = "$syspath/$f->{SysDev}:1.0"; - ($f->{DriverName} = readlink("$port/driver")) =~ s{^.*/}{} if -l "$port/driver"; - ($f->{SerialDevName} = (glob("$port/tty*"),undef)[0]) =~ s{^.*/}{}; - $f->{SerialDevNum} = $1 if $f->{SerialDevName} =~ /(\d+)/; - $f->{SerialDevName} = getSerialDevName( $f->{SerialDevNum} ) || " (none)"; - } - return @cpdevs; -} - - -# -# Scan Procfs -# -sub scan_procfs { - - my $text_devs = snarf("< /proc/bus/usb/devices"); - my $text_serial = snarf($Opt{usbserial}); - - my @usbdevs = map { {parse_usb_devices_text($_)} } - grep { !/^\s*$/ } split /\n+(?=T:)/, $text_devs; - my %usbtree = build_usb_tree( @usbdevs ); - my %usbserialtree = build_usbserial_tree( $text_serial ); - for my $tts ( values %usbserialtree ) { - $usbtree{usbkey($tts->{path})}{usbserial} = $tts if defined $tts->{path}; - } - - my @cpdevs = map { { - UsbVendor => $_->{Vendor}, - UsbProduct => $_->{ProdID}, - InfoManufacturer => $_->{Manufacturer}, - InfoProduct => $_->{Product}, - InfoSerial => $_->{SerialNumber}, - UsbBusNum => $_->{nbus}, - UsbDevNum => $_->{ndev}, - UsbPath => (($Opt{kernel} eq "2.4") ? $_->{usbserial}{path} : $_->{usbpath}), - DriverName => $_->{driver}, - SerialDevNum => $_->{usbserial}{tts}, - SerialDevName => getSerialDevName($_->{usbserial}{tts}) || " (none)", - } } - grep { ($_->{Vendor}||"") eq "0403" && ($_->{ProdID}||"") eq "6001" } - values %usbtree; - - return @cpdevs; -} - -sub build_usb_tree { - my @devs = @_; - my %tree = (); - for my $dev (sort { $a->{Lev} <=> $b->{Lev} } @devs) { - my ($bus,$lev,$prnt) = ( $dev->{Bus}+0, $dev->{Lev}+0, $dev->{Prnt}+0 ); - my $devnum = $dev->{"Dev#"}+0; - $dev->{nbus} = $bus; - $dev->{ndev} = $devnum; - $tree{"bus$bus"} = {} unless exists $tree{"bus$bus"}; - $tree{"bus$bus"}{"dev$devnum"} = $dev; - if( $lev == 0 ) { - $dev->{usbpath} = "usb-$dev->{SerialNumber}"; - } else { - my $sep = ($lev==1) ? "-" : "."; - $dev->{parent} = $tree{"bus$bus"}{"dev$prnt"}; - $dev->{usbpath} = $dev->{parent}{usbpath} . $sep . ($dev->{Port}+1); - } - $tree{usbkey($dev->{usbpath})} = $dev; - } - return %tree; -} - -sub parse_usb_devices_text { - my $text = shift; - $text =~ s/^\S+\s*//gm; - return ($text =~ m/([^\s=]+)=\s*(.*?\S)\s*(?=[^\s=]+=|$)/mg); -} - -sub build_usbserial_tree { - my $text = shift; - my %tree = (); - while( $text =~ /^([^:]+):(.*)/mg ) { - my ($tts,$params) = ($1,$2); - $tree{$tts} = { tts => $tts }; - while ($params =~ m/\s+([^:]+):(?:"([^"]*)"|(\S+))/g) { - $tree{$tts}{$1} = $2||$3; - } - } - return %tree; -} - -sub usbkey { - if( $Opt{kernel} eq "2.4" ) { - (my $key = $_[0]) =~ s/^.*-//; - return $key; - } - return $_[0]; -} - - -# -# getSerialDevName -# -# For each device, force to use dev_prefix if it's not an array. Otherwise, -# assume it's a list of candidate prefixes. Check them and commit to the -# first one that actually exists. -# -sub getSerialDevName { - my $devnum = shift; - my $devname = undef; - if( defined $devnum ) { - if( ref($Opt{dev_prefix}) eq "ARRAY" ) { - $devname = $devnum; - for my $prefix (@{$Opt{dev_prefix}}) { - my $file = $prefix . $devnum; - if( -e $file ) { $devname = $file; last; } - } - } else { - $devname = $Opt{dev_prefix} . $devnum; - } - } - return $devname; -} - - -# -# Print motelist -# -sub print_motelist { - my @devs = @_; - - # If none were found, quit - if( @devs == 0 ) { - print "No devices found.\n"; - return; - } - - # Print a header - if( !$Opt{compact} ) { - if( $Opt{usb} ) { - print << "EOF" unless $Opt{compact}; ---- --- ------------------------ -------------- ---------------- ------------------------------------- -Bus Dev USB Path Reference Device Description ---- --- ------------------------ -------------- ---------------- ------------------------------------- -EOF - } else { - print << "EOF" unless $Opt{compact}; --------------- ---------------- --------------------------------------------- -Reference Device Description --------------- ---------------- --------------------------------------------- -EOF - } - } - - # Print the usb information - for my $dev (sort { cmp_usbdev($a,$b) } @devs) { - my $desc = join( " ", $dev->{InfoManufacturer}||"", $dev->{InfoProduct}||"" ) || " (none)"; - my @output = ( $dev->{InfoSerial}||" (none)", $dev->{SerialDevName}, $desc ); - @output = ( $dev->{UsbBusNum}, $dev->{UsbDevNum}, $dev->{UsbPath}, @output ) if $Opt{usb}; - if( $Opt{compact} ) { - print join(",",@output) . "\n"; - } else { - printf( ($Opt{usb}?"%3d %3d %-24s ":"")."%-14s %-16s %s\n", @output ); - } - } -} - - -# -# Cmp Usbdev's -# -sub cmp_usbdev { - my ($a,$b) = @_; - if( defined $a->{SerialDevNum} ) { - if( defined $b->{SerialDevNum} ) { - return $a->{SerialDevNum} <=> $b->{SerialDevNum}; - } - return -1; - } - return 1 if defined $b->{SerialDevNum}; - return ($a->{InfoSerial}||"") cmp ($b->{InfoSerial}||""); -} - -# -# Read a file in -# -sub snarf { - open my $fh, $_[0] or return undef; - my $text = do{local $/;<$fh>}; - close $fh; - $text =~ s/\s+$// if $_[1]; - return $text; -} - diff --git a/tools/zolertia/motelist-zolertia-macos b/tools/zolertia/motelist-zolertia-macos deleted file mode 100755 index 526b4887e..000000000 --- a/tools/zolertia/motelist-zolertia-macos +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -my $help = <<'EOF'; -usage: motelist [options] - -options: - -h display this help - -c compact format, not pretty but easier for parsing -EOF - -my %Opt = ( - compact => 0, - dev_prefix => [ "/dev/tty.SLAB" ], -); - -while (@ARGV) { - last unless $ARGV[0] =~ /^-/; - my $opt = shift @ARGV; - if( $opt eq "-h" ) { print "$help\n"; exit 0; } - elsif( $opt eq "-c" ) { $Opt{compact} = 1; } - else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; } -} - -print_motelist( scan_dev() ); - -# -# Scan /dev for tty.SLAB* -# -sub scan_dev { - my @devs; - foreach (`ls /dev/tty.SLAB* 2>&1`) { - my($dev, $serial) = /(\/dev\/tty.SLAB(\S+))/; - if ($serial ne "*:") { - my $d; - $d->{"InfoSerial"} = $serial; - $d->{"SerialDevName"} = $dev; - push(@devs, $d); - } - } - return @devs; -} - - -# -# Print motelist -# -sub print_motelist { - my @devs = @_; - - # If none were found, quit - if( @devs == 0 ) { - #print "No devices found.\n"; - return; - } - - # Print a header - if( !$Opt{compact} ) { - print << "EOF" unless $Opt{compact}; -Reference Device Description ----------- --------------------------- --------------------------------------- -EOF - } - - # Print the usb information - for my $dev (@devs) { - my $desc = "(none)"; - my @output = ( $dev->{"InfoSerial"}, $dev->{"SerialDevName"}, $desc ); - if( $Opt{compact} ) { - print join(",",@output) . "\n"; - } else { - printf( "%-10s %-27s %s\n", @output ); - } - } -}