From ba73abfeac542541c21f9c861aa35b931cc43e13 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 23 Sep 2018 12:58:31 +0100 Subject: [PATCH 001/184] Provide default board for platform simplelink If BOARD is unspecified, simplelink platform's build system will generate an error instead of choosing a default. This is a) inconsistent with what we do for other platforms and b) problematic because making targets clean, distclean etc will fail. --- arch/platform/simplelink/Makefile.simplelink | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/platform/simplelink/Makefile.simplelink b/arch/platform/simplelink/Makefile.simplelink index d14643c3f..acb613d6e 100644 --- a/arch/platform/simplelink/Makefile.simplelink +++ b/arch/platform/simplelink/Makefile.simplelink @@ -8,9 +8,7 @@ ifndef CONTIKI $(error 'CONTIKI' not defined! You must specify where CONTIKI resides!) endif -ifndef BOARD - $(error 'BOARD' not defined! You must specify which board you are using!) -endif +BOARD ?= srf06/cc26x0 ################################################################################ ### Resolve the SimpleLink Family From e71ef49c047a9be55b4ec15e52f2bed45a12603f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 26 Sep 2018 21:42:06 +0100 Subject: [PATCH 002/184] Create platform-independent SPI select and deselect --- arch/cpu/cc2538/dev/spi-arch.c | 21 ---------------- arch/cpu/cc26xx-cc13xx/dev/spi-arch.c | 19 --------------- .../simplelink-cc13xx-cc26xx/dev/spi-arch.c | 24 ------------------- os/dev/spi.c | 12 ++++++++-- 4 files changed, 10 insertions(+), 66 deletions(-) diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index d8c6437d5..aae0ed797 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -281,27 +281,6 @@ spi_arch_close_and_unlock(const spi_device_t *dev) return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_select(const spi_device_t *dev) -{ - - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - SPIX_CS_CLR(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_deselect(const spi_device_t *dev) -{ - SPIX_CS_SET(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ /* Assumes that checking dev and bus is not NULL before calling this */ spi_status_t spi_arch_transfer(const spi_device_t *dev, diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c index d42c06af9..426e09a1b 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c @@ -230,22 +230,3 @@ spi_arch_transfer(const spi_device_t *dev, return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_select(const spi_device_t *dev) -{ - - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - ti_lib_gpio_clear_dio(dev->pin_spi_cs); - - return SPI_DEV_STATUS_OK; -} -spi_status_t -spi_arch_deselect(const spi_device_t *dev) -{ - ti_lib_gpio_set_dio(dev->pin_spi_cs); - - return SPI_DEV_STATUS_OK; -} diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c index a019a33fb..f4c6114e8 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c @@ -235,30 +235,6 @@ spi_arch_transfer(const spi_device_t *dev, return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_select(const spi_device_t *dev) -{ - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - PINCC26XX_setOutputValue(dev->pin_spi_cs, 0); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_deselect(const spi_device_t *dev) -{ - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - PINCC26XX_setOutputValue(dev->pin_spi_cs, 1); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ /** * @} * @} diff --git a/os/dev/spi.c b/os/dev/spi.c index 145a4f72e..091cf8e51 100644 --- a/os/dev/spi.c +++ b/os/dev/spi.c @@ -67,13 +67,21 @@ spi_release(const spi_device_t *dev) spi_status_t spi_select(const spi_device_t *dev) { - return spi_arch_select(dev); + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + gpio_hal_arch_clear_pin(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ spi_status_t spi_deselect(const spi_device_t *dev) { - return spi_arch_deselect(dev); + gpio_hal_arch_set_pin(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ bool From 3e9d79ca8cf5b4aa372aa1f778814277f883830a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 30 Sep 2018 13:03:50 +0100 Subject: [PATCH 003/184] Fix pin to mask conversion macro for 64-bit masks --- os/dev/gpio-hal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) /** @} */ /*---------------------------------------------------------------------------*/ /** From b4db7aa4e762efa65de62e300140698d1be97408 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 30 Sep 2018 13:21:36 +0100 Subject: [PATCH 004/184] GPIO HAL example fix 64-bit support --- examples/dev/gpio-hal/gpio-hal-example.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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), From b80d11325368c3bbee1961bdef34d1ce9d3a3a56 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 11 Oct 2018 20:23:21 +0200 Subject: [PATCH 005/184] Add a common set of portable RTIMER_BUSY_WAIT functions --- arch/dev/cc1200/cc1200.c | 80 ++++++++--------------- arch/platform/cooja/dev/watchdog.c | 7 +- arch/platform/jn516x/dev/micromac-radio.c | 13 +--- arch/platform/jn516x/dev/uart-driver.c | 10 +-- arch/platform/zoul/dev/cc1200-zoul-arch.c | 15 +---- arch/platform/zoul/dev/dht22.c | 13 +--- os/net/mac/csma/csma-output.c | 15 +---- os/net/mac/tsch/tsch-slot-operation.c | 23 +++---- os/net/mac/tsch/tsch.c | 2 +- os/net/mac/tsch/tsch.h | 18 ----- os/sys/rtimer.h | 19 ++++++ 11 files changed, 70 insertions(+), 145 deletions(-) diff --git a/arch/dev/cc1200/cc1200.c b/arch/dev/cc1200/cc1200.c index 5f76e4817..dd90fdda7 100644 --- a/arch/dev/cc1200/cc1200.c +++ b/arch/dev/cc1200/cc1200.c @@ -310,15 +310,7 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; #define LOCK_SPI() do { spi_locked++; } while(0) #define SPI_IS_LOCKED() (spi_locked != 0) #define RELEASE_SPI() do { spi_locked--; } while(0) -/*---------------------------------------------------------------------------*/ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) { \ - watchdog_periodic(); \ - } \ - } while(0) + /*---------------------------------------------------------------------------*/ #if CC1200_USE_GPIO2 /* Configure GPIO interrupts. GPIO0: falling, GPIO2: rising edge */ @@ -378,29 +370,9 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; #define INFO(...) #endif -#if DEBUG_LEVEL > 0 -/* - * As BUSYWAIT_UNTIL was mainly used to test for a state transition, - * we define a separate macro for this adding the possibility to - * throw an error message when the timeout exceeds - */ -#define BUSYWAIT_UNTIL_STATE(s, t) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while((state() != s) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t))) {} \ - if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t)))) { \ - printf("RF: Timeout exceeded in line %d!\n", __LINE__); \ - } \ - } while(0) -#else -#define BUSYWAIT_UNTIL_STATE(s, t) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while((state() != s) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t))) {} \ - } while(0) -#endif +/* Busy-wait (time-bounded) until the radio reaches a given state */ +#define RTIMER_BUSYWAIT_UNTIL_STATE(s, t) RTIMER_BUSYWAIT_UNTIL(state() == (s), t) + /*---------------------------------------------------------------------------*/ /* Variables */ /*---------------------------------------------------------------------------*/ @@ -604,7 +576,7 @@ PROCESS_THREAD(cc1200_process, ev, data) /* * We are on and not in TX. As every function of this driver * assures that we are in RX mode - * (using BUSYWAIT_UNTIL_STATE(STATE_RX, ...) construct) in + * (using RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, ...) construct) in * either rx_rx(), idle_calibrate_rx() or transmit(), * something probably went wrong in the rx interrupt handler * if we are not in RX at this point. @@ -893,7 +865,7 @@ transmit(unsigned short transmit_len) * again as they were turned off in idle() */ - BUSYWAIT_UNTIL_STATE(STATE_RX, + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, CC1200_RF_CFG.tx_rx_turnaround); ENABLE_GPIO_INTERRUPTS(); @@ -1033,7 +1005,7 @@ channel_clear(void) } /* Wait for CARRIER_SENSE_VALID signal */ - BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) + RTIMER_BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) & CC1200_CARRIER_SENSE_VALID), RTIMER_SECOND / 100); RF_ASSERT(rssi0 & CC1200_CARRIER_SENSE_VALID); @@ -1135,7 +1107,7 @@ on(void) /* Wake-up procedure. Wait for GPIO0 to de-assert (CHIP_RDYn) */ cc1200_arch_spi_select(); - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), RTIMER_SECOND / 100); RF_ASSERT((cc1200_arch_gpio0_read_pin() == 0)); cc1200_arch_spi_deselect(); @@ -1239,7 +1211,7 @@ get_rssi(void) } /* Wait for CARRIER_SENSE_VALID signal */ - BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) + RTIMER_BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) & CC1200_CARRIER_SENSE_VALID), RTIMER_SECOND / 100); RF_ASSERT(rssi0 & CC1200_CARRIER_SENSE_VALID); @@ -1706,20 +1678,20 @@ configure(void) while(1) { #if (CC1200_RF_TESTMODE == 1) watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_YELLOW); leds_on(LEDS_RED); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_RED); leds_on(LEDS_YELLOW); #else watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_GREEN); leds_on(LEDS_RED); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_RED); leds_on(LEDS_GREEN); #endif @@ -1741,11 +1713,11 @@ configure(void) while(1) { watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_GREEN); leds_on(LEDS_YELLOW); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_YELLOW); leds_on(LEDS_GREEN); clock_delay_usec(1000); @@ -1866,8 +1838,8 @@ calibrate(void) INFO("RF: Calibrate\n"); strobe(CC1200_SCAL); - BUSYWAIT_UNTIL_STATE(STATE_CALIBRATE, RTIMER_SECOND / 100); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_CALIBRATE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); #if CC1200_CAL_TIMEOUT_SECONDS cal_timer = clock_seconds(); @@ -1904,7 +1876,7 @@ idle(void) } strobe(CC1200_SIDLE); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); } /* idle(), 21.05.2015 */ /*---------------------------------------------------------------------------*/ @@ -1922,7 +1894,7 @@ idle_calibrate_rx(void) rf_flags &= ~RF_RX_PROCESSING_PKT; strobe(CC1200_SFRX); strobe(CC1200_SRX); - BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); ENABLE_GPIO_INTERRUPTS(); @@ -1947,7 +1919,7 @@ rx_rx(void) strobe(CC1200_SFTX); } else { strobe(CC1200_SIDLE); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); } @@ -1959,7 +1931,7 @@ rx_rx(void) strobe(CC1200_SFRX); strobe(CC1200_SRX); - BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); } /*---------------------------------------------------------------------------*/ @@ -2002,14 +1974,14 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) #if USE_SFSTXON /* Wait for synthesizer to be ready */ - BUSYWAIT_UNTIL_STATE(STATE_FSTXON, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_FSTXON, RTIMER_SECOND / 100); #endif /* Start TX */ strobe(CC1200_STX); /* Wait for TX to start. */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 1), RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 1), RTIMER_SECOND / 100); /* Turned off at the latest in idle() */ TX_LEDS_ON(); @@ -2072,7 +2044,7 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) */ INFO("RF: TX failure!\n"); - BUSYWAIT_UNTIL((state() != STATE_TX), RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL((state() != STATE_TX), RTIMER_SECOND / 100); /* Re-configure GPIO2 */ single_write(CC1200_IOCFG2, GPIO2_IOCFG); idle(); @@ -2086,12 +2058,12 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) } else { /* Wait for TX to complete */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), CC1200_RF_CFG.tx_pkt_lifetime); } #else /* Wait for TX to complete */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), CC1200_RF_CFG.tx_pkt_lifetime); #endif diff --git a/arch/platform/cooja/dev/watchdog.c b/arch/platform/cooja/dev/watchdog.c index a30fc0fc8..347d9a996 100644 --- a/arch/platform/cooja/dev/watchdog.c +++ b/arch/platform/cooja/dev/watchdog.c @@ -30,8 +30,10 @@ * */ - /* Dummy watchdog routines for the Raven 1284p */ + /* Dummy watchdog routines for Cooja motes */ #include "dev/watchdog.h" +#include "lib/simEnvChange.h" +#include "sys/cooja_mt.h" /*---------------------------------------------------------------------------*/ void @@ -47,6 +49,9 @@ watchdog_start(void) void watchdog_periodic(void) { + /* Yield and give control back to the simulator scheduler */ + simProcessRunValue = 1; + cooja_mt_yield(); } /*---------------------------------------------------------------------------*/ void diff --git a/arch/platform/jn516x/dev/micromac-radio.c b/arch/platform/jn516x/dev/micromac-radio.c index 6e2ddb908..bad81f4f0 100644 --- a/arch/platform/jn516x/dev/micromac-radio.c +++ b/arch/platform/jn516x/dev/micromac-radio.c @@ -130,13 +130,6 @@ #define MICROMAC_CONF_ALWAYS_ON 1 #endif /* MICROMAC_CONF_ALWAYS_ON */ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \ - } while(0) - /* Local variables */ static volatile signed char radio_last_rssi; static volatile uint8_t radio_last_correlation; /* LQI */ @@ -377,14 +370,14 @@ transmit(unsigned short payload_len) (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA)); #endif if(poll_mode) { - BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION); + RTIMER_BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION); } else { if(in_ack_transmission) { /* as nested interupts are not possible, the tx flag will never be cleared */ - BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION); + RTIMER_BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION); } else { /* wait until the tx flag is cleared */ - BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION); + RTIMER_BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION); } } diff --git a/arch/platform/jn516x/dev/uart-driver.c b/arch/platform/jn516x/dev/uart-driver.c index 31a4b286c..aeeffeeb4 100644 --- a/arch/platform/jn516x/dev/uart-driver.c +++ b/arch/platform/jn516x/dev/uart-driver.c @@ -66,14 +66,6 @@ extern volatile unsigned char xonxoff_state; #endif /* UART_XONXOFF_FLOW_CTRL */ -/*** Macro Definitions ***/ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \ - } while(0) - #define DEBUG_UART_BUFFERED FALSE #define CHAR_DEADLINE (uart_char_delay * 100) @@ -276,7 +268,7 @@ uart_driver_write_with_deadline(uint8_t uart_dev, uint8_t ch) volatile int16_t write = 0; watchdog_periodic(); /* wait until there is space in tx fifo */ - BUSYWAIT_UNTIL(write = (uart_driver_get_tx_fifo_available_space(uart_dev) > 0), + RTIMER_BUSYWAIT_UNTIL(write = (uart_driver_get_tx_fifo_available_space(uart_dev) > 0), CHAR_DEADLINE); /* write only if there is space so we do not get stuck */ if(write) { diff --git a/arch/platform/zoul/dev/cc1200-zoul-arch.c b/arch/platform/zoul/dev/cc1200-zoul-arch.c index 8c9d8cdd7..b0fd8dd96 100644 --- a/arch/platform/zoul/dev/cc1200-zoul-arch.c +++ b/arch/platform/zoul/dev/cc1200-zoul-arch.c @@ -76,18 +76,8 @@ /*---------------------------------------------------------------------------*/ #if DEBUG_CC1200_ARCH > 0 #define PRINTF(...) printf(__VA_ARGS__) -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) {} \ - if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time)))) { \ - printf("ARCH: Timeout exceeded in line %d!\n", __LINE__); \ - } \ - } while(0) #else #define PRINTF(...) -#define BUSYWAIT_UNTIL(cond, max_time) while(!cond) #endif /*---------------------------------------------------------------------------*/ extern int cc1200_rx_interrupt(void); @@ -105,7 +95,7 @@ cc1200_arch_spi_select(void) /* Set CSn to low (0) */ GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK); /* The MISO pin should go low before chip is fully enabled. */ - BUSYWAIT_UNTIL( + RTIMER_BUSYWAIT_UNTIL( GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK) == 0, RTIMER_SECOND / 100); } @@ -288,7 +278,7 @@ cc1200_arch_init(void) cc1200_arch_spi_deselect(); /* Ensure MISO is high */ - BUSYWAIT_UNTIL( + RTIMER_BUSYWAIT_UNTIL( GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK), RTIMER_SECOND / 10); } @@ -297,4 +287,3 @@ cc1200_arch_init(void) * @} * @} */ - diff --git a/arch/platform/zoul/dev/dht22.c b/arch/platform/zoul/dev/dht22.c index e5d14d53b..23174b2e6 100644 --- a/arch/platform/zoul/dev/dht22.c +++ b/arch/platform/zoul/dev/dht22.c @@ -51,15 +51,6 @@ #define PRINTF(...) #endif /*---------------------------------------------------------------------------*/ -#define BUSYWAIT_UNTIL(max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) { \ - watchdog_periodic(); \ - } \ - } while(0) -/*---------------------------------------------------------------------------*/ #define DHT22_PORT_BASE GPIO_PORT_TO_BASE(DHT22_PORT) #define DHT22_PIN_MASK GPIO_PIN_MASK(DHT22_PIN) /*---------------------------------------------------------------------------*/ @@ -80,12 +71,12 @@ dht22_read(void) /* Exit low power mode and initialize variables */ GPIO_SET_OUTPUT(DHT22_PORT_BASE, DHT22_PIN_MASK); GPIO_SET_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); - BUSYWAIT_UNTIL(DHT22_AWAKE_TIME); + RTIMER_BUSYWAIT(DHT22_AWAKE_TIME); memset(dht22_data, 0, DHT22_BUFFER); /* Initialization sequence */ GPIO_CLR_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); - BUSYWAIT_UNTIL(DHT22_START_TIME); + RTIMER_BUSYWAIT(DHT22_START_TIME); GPIO_SET_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); clock_delay_usec(DHT22_READY_TIME); diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 9c88d569d..20d96b1d1 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -50,11 +50,6 @@ #include "lib/list.h" #include "lib/memb.h" -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ - /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "CSMA" @@ -207,10 +202,7 @@ send_one_packet(void *ptr) wt = RTIMER_NOW(); watchdog_periodic(); while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + CSMA_ACK_WAIT_TIME)) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ + watchdog_periodic(); } ret = MAC_TX_NOACK; @@ -225,10 +217,7 @@ send_one_packet(void *ptr) watchdog_periodic(); while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + CSMA_AFTER_ACK_DETECTED_WAIT_TIME)) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ + watchdog_periodic(); } } diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index b1a3f6ba8..841dee07f 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -52,10 +52,6 @@ #include "net/queuebuf.h" #include "net/mac/framer/framer-802154.h" #include "net/mac/tsch/tsch.h" -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ #include "sys/log.h" /* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH @@ -206,10 +202,7 @@ tsch_get_lock(void) busy_wait = 1; busy_wait_time = RTIMER_NOW(); while(tsch_in_slot_operation) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ + watchdog_periodic(); } busy_wait_time = RTIMER_NOW() - busy_wait_time; } @@ -303,7 +296,7 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ } /* block until the time to schedule comes */ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); + RTIMER_BUSYWAIT_UNTIL_ABS(0, ref_time, offset); return 0; } /*---------------------------------------------------------------------------*/ @@ -314,7 +307,7 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ do { \ if(tsch_schedule_slot_operation(tm, ref_time, offset - RTIMER_GUARD, str)) { \ PT_YIELD(pt); \ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ + RTIMER_BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } \ } while(0); /*---------------------------------------------------------------------------*/ @@ -514,7 +507,7 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_TX_EVENT(); tsch_radio_on(TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT); /* CCA */ - BUSYWAIT_UNTIL_ABS(!(cca_status &= NETSTACK_RADIO.channel_clear()), + RTIMER_BUSYWAIT_UNTIL_ABS(!(cca_status &= NETSTACK_RADIO.channel_clear()), current_slot_start, tsch_timing[tsch_ts_cca_offset] + tsch_timing[tsch_ts_cca]); TSCH_DEBUG_TX_EVENT(); /* there is not enough time to turn radio off */ @@ -561,14 +554,14 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_TX_EVENT(); tsch_radio_on(TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT); /* Wait for ACK to come */ - BUSYWAIT_UNTIL_ABS(NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(NETSTACK_RADIO.receiving_packet(), tx_start_time, tx_duration + tsch_timing[tsch_ts_rx_ack_delay] + tsch_timing[tsch_ts_ack_wait] + RADIO_DELAY_BEFORE_DETECT); TSCH_DEBUG_TX_EVENT(); ack_start_time = RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT; /* Wait for ACK to finish */ - BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), ack_start_time, tsch_timing[tsch_ts_max_ack]); TSCH_DEBUG_TX_EVENT(); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); @@ -748,7 +741,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) packet_seen = NETSTACK_RADIO.receiving_packet() || NETSTACK_RADIO.pending_packet(); if(!packet_seen) { /* Check if receiving within guard time */ - BUSYWAIT_UNTIL_ABS((packet_seen = NETSTACK_RADIO.receiving_packet()), + RTIMER_BUSYWAIT_UNTIL_ABS((packet_seen = NETSTACK_RADIO.receiving_packet()), current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + RADIO_DELAY_BEFORE_DETECT); } if(!packet_seen) { @@ -760,7 +753,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) rx_start_time = RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT; /* Wait until packet is received, turn radio off */ - BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + tsch_timing[tsch_ts_max_tx]); TSCH_DEBUG_RX_EVENT(); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index e78b888d0..25b565809 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -737,7 +737,7 @@ PT_THREAD(tsch_scan(struct pt *pt)) if(!is_packet_pending && NETSTACK_RADIO.receiving_packet()) { /* If we are currently receiving a packet, wait until end of reception */ t0 = RTIMER_NOW(); - BUSYWAIT_UNTIL_ABS((is_packet_pending = NETSTACK_RADIO.pending_packet()), t0, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_ABS((is_packet_pending = NETSTACK_RADIO.pending_packet()), t0, RTIMER_SECOND / 100); } if(is_packet_pending) { diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index 65a46521f..8590dcb38 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -65,30 +65,12 @@ frequency hopping for enhanced reliability. #include "net/mac/tsch/tsch-rpl.h" #endif /* UIP_CONF_IPV6_RPL */ -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ /* Include Arch-Specific conf */ #ifdef TSCH_CONF_ARCH_HDR_PATH #include TSCH_CONF_ARCH_HDR_PATH #endif /* TSCH_CONF_ARCH_HDR_PATH */ -/*********** Macros *********/ - -/* Wait for a condition with timeout t0+offset. */ -#if CONTIKI_TARGET_COOJA -#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) { \ - simProcessRunValue = 1; \ - cooja_mt_yield(); \ - }; -#else -#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ; -#endif /* CONTIKI_TARGET_COOJA */ - /*********** Callbacks *********/ /* Link callbacks to RPL in case RPL is enabled */ diff --git a/os/sys/rtimer.h b/os/sys/rtimer.h index 44ad92a2f..8af9a40f3 100644 --- a/os/sys/rtimer.h +++ b/os/sys/rtimer.h @@ -54,6 +54,7 @@ #define RTIMER_H_ #include "contiki.h" +#include "dev/watchdog.h" /** \brief The rtimer size (in bytes) */ #ifdef RTIMER_CONF_CLOCK_SIZE @@ -186,6 +187,24 @@ void rtimer_arch_schedule(rtimer_clock_t t); #define RTIMER_GUARD_TIME (RTIMER_ARCH_SECOND >> 14) #endif /* RTIMER_CONF_GUARD_TIME */ +/** \brief Busy-wait until a condition. Start time is t0, max wait time is max_time */ +#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ + do { \ + while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ + watchdog_periodic(); \ + } \ + } while(0) + +/** \brief Busy-wait until a condition for at most max_time */ +#define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \ + do { \ + rtimer_clock_t t0 = RTIMER_NOW(); \ + RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time); \ + } while(0) + +/** \brief Busy-wait for a fixed duration */ +#define RTIMER_BUSYWAIT(duration) RTIMER_BUSYWAIT_UNTIL(0, duration) + #endif /* RTIMER_H_ */ /** @} */ From 4097883229ea22c0337dca62f90a978c264e76ad Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 31 May 2018 01:41:24 -0700 Subject: [PATCH 006/184] CSMA: simplify routine that waits for ACK --- os/net/mac/csma/csma-output.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 20d96b1d1..1773e0cb0 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -196,14 +196,10 @@ send_one_packet(void *ptr) if(is_broadcast) { ret = MAC_TX_OK; } else { - rtimer_clock_t wt; - /* Check for ack */ - wt = RTIMER_NOW(); - watchdog_periodic(); - while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + CSMA_ACK_WAIT_TIME)) { - watchdog_periodic(); - } + + /* Wait for max CSMA_ACK_WAIT_TIME */ + RTIMER_BUSYWAIT_UNTIL(NETSTACK_RADIO.pending_packet(), CSMA_ACK_WAIT_TIME); ret = MAC_TX_NOACK; if(NETSTACK_RADIO.receiving_packet() || @@ -212,14 +208,8 @@ send_one_packet(void *ptr) int len; uint8_t ackbuf[CSMA_ACK_LEN]; - if(CSMA_AFTER_ACK_DETECTED_WAIT_TIME > 0) { - wt = RTIMER_NOW(); - watchdog_periodic(); - while(RTIMER_CLOCK_LT(RTIMER_NOW(), - wt + CSMA_AFTER_ACK_DETECTED_WAIT_TIME)) { - watchdog_periodic(); - } - } + /* Wait an additional CSMA_AFTER_ACK_DETECTED_WAIT_TIME to complete reception */ + RTIMER_BUSYWAIT_UNTIL(NETSTACK_RADIO.pending_packet(), CSMA_AFTER_ACK_DETECTED_WAIT_TIME); if(NETSTACK_RADIO.pending_packet()) { len = NETSTACK_RADIO.read(ackbuf, CSMA_ACK_LEN); From d85cecea34d30e560772bfe0f520ee7a9a0a608d Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 23 Sep 2018 15:52:13 +0200 Subject: [PATCH 007/184] rtimer.h: add return value to RTIMER_BUSYWAIT* macros --- os/sys/rtimer.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/os/sys/rtimer.h b/os/sys/rtimer.h index 8af9a40f3..260f08950 100644 --- a/os/sys/rtimer.h +++ b/os/sys/rtimer.h @@ -55,6 +55,7 @@ #include "contiki.h" #include "dev/watchdog.h" +#include /** \brief The rtimer size (in bytes) */ #ifdef RTIMER_CONF_CLOCK_SIZE @@ -189,18 +190,20 @@ void rtimer_arch_schedule(rtimer_clock_t t); /** \brief Busy-wait until a condition. Start time is t0, max wait time is max_time */ #define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ - do { \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ - watchdog_periodic(); \ - } \ - } while(0) + ({ \ + bool c; \ + while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ + watchdog_periodic(); \ + } \ + c; \ + }) /** \brief Busy-wait until a condition for at most max_time */ -#define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0 = RTIMER_NOW(); \ - RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time); \ - } while(0) +#define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \ + ({ \ + rtimer_clock_t t0 = RTIMER_NOW(); \ + RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time); \ + }) /** \brief Busy-wait for a fixed duration */ #define RTIMER_BUSYWAIT(duration) RTIMER_BUSYWAIT_UNTIL(0, duration) From c3ed24d531d70a0b18b95d702dc67ceb342548bd Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 12 Oct 2018 14:14:07 +0200 Subject: [PATCH 008/184] Removing native compilation from ARM compile test suite --- tests/01-compile-base/Makefile | 2 +- tests/02-compile-arm-ports-01/Makefile | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index d9ef0ba58..e51ff523b 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -16,7 +16,7 @@ libs/stack-check/sky \ lwm2m-ipso-objects/native \ lwm2m-ipso-objects/native:MAKE_WITH_DTLS=1 \ lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1 \ -lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1,LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1\ +lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1,LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1 \ rpl-udp/sky \ rpl-border-router/native \ rpl-border-router/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index b3a3abdda..2ec2ce443 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -80,7 +80,6 @@ coap/coap-example-server/cc2538dk \ slip-radio/cc2538dk \ lwm2m-ipso-objects/cc2538dk \ lwm2m-ipso-objects/cc2538dk:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1 \ -lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1,LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1\ multicast/cc2538dk \ dev/gpio-hal/cc2538dk \ dev/leds/cc2538dk \ From 8e990819a81fec50b03aa0ad8db0b54b3e0cbea1 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:07:24 +0100 Subject: [PATCH 009/184] Remove all instances of ti_lib_rom_ macros --- arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c | 10 +----- arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h | 11 +------ arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c | 2 +- arch/cpu/cc26xx-cc13xx/dev/soc-trng.c | 18 +++++------ arch/cpu/cc26xx-cc13xx/dev/spi-arch.c | 31 ++++++------------- .../srf06-cc26xx/launchpad/cc1350/rf-switch.c | 4 +-- arch/platform/srf06-cc26xx/platform.c | 2 +- .../srf06-cc26xx/sensortag/mpu-9250-sensor.c | 4 +-- arch/platform/srf06-cc26xx/srf06/als-sensor.c | 6 ++-- 9 files changed, 30 insertions(+), 58 deletions(-) diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c index 6516c22cd..285652690 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c @@ -53,11 +53,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_pin_cfg_t tmp; /* Clear settings that we are about to change, keep everything else */ -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated config = ti_lib_ioc_port_configure_get(pin); -#else - config = ti_lib_rom_ioc_port_configure_get(pin); -#endif config &= ~CONFIG_MASK; tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH; @@ -87,7 +83,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) config |= IOC_INT_ENABLE; } - ti_lib_rom_ioc_port_configure_set(pin, IOC_PORT_GPIO, config); + ti_lib_ioc_port_configure_set(pin, IOC_PORT_GPIO, config); } /*---------------------------------------------------------------------------*/ gpio_hal_pin_cfg_t @@ -98,11 +94,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) uint32_t config; cfg = 0; -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated config = ti_lib_ioc_port_configure_get(pin); -#else - config = ti_lib_rom_ioc_port_configure_get(pin); -#endif /* Pull */ tmp = config & IOC_IOPULL_M; diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h index 42a912674..ae1b04e26 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h @@ -57,15 +57,10 @@ #define gpio_hal_arch_interrupt_enable(p) interrupt_enable(p) -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated #define gpio_hal_arch_interrupt_disable(p) ti_lib_ioc_int_disable(p) #define gpio_hal_arch_pin_set_input(p) ti_lib_ioc_pin_type_gpio_input(p) #define gpio_hal_arch_pin_set_output(p) ti_lib_ioc_pin_type_gpio_output(p) -#else -#define gpio_hal_arch_interrupt_disable(p) ti_lib_rom_ioc_int_disable(p) -#define gpio_hal_arch_pin_set_input(p) ti_lib_rom_ioc_pin_type_gpio_input(p) -#define gpio_hal_arch_pin_set_output(p) ti_lib_rom_ioc_pin_type_gpio_output(p) -#endif + #define gpio_hal_arch_set_pin(p) ti_lib_gpio_set_dio(p) #define gpio_hal_arch_clear_pin(p) ti_lib_gpio_clear_dio(p) #define gpio_hal_arch_toggle_pin(p) ti_lib_gpio_toggle_dio(p) @@ -80,11 +75,7 @@ static inline void interrupt_enable(gpio_hal_pin_t pin) { ti_lib_gpio_clear_event_dio(pin); -#ifndef ThisLibraryIsFor_CC26x0R2_HaltIfViolated - ti_lib_rom_ioc_int_enable(pin); -#else ti_lib_ioc_int_enable(pin); -#endif } /*---------------------------------------------------------------------------*/ #endif /* GPIO_HAL_ARCH_H_ */ diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c b/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c index 8de930a9c..2309026b6 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c +++ b/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c @@ -99,7 +99,7 @@ soc_rtc_init(void) ti_lib_aon_rtc_channel_enable(AON_RTC_CH1); ti_lib_aon_rtc_enable(); - ti_lib_rom_int_enable(INT_AON_RTC_COMB); + ti_lib_int_enable(INT_AON_RTC_COMB); /* Re-enable interrupts */ if(!interrupts_disabled) { diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c b/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c index 2fea8418d..30a558640 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c +++ b/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c @@ -71,7 +71,7 @@ static void disable_number_ready_interrupt(void) { ti_lib_trng_int_disable(TRNG_NUMBER_READY); - ti_lib_rom_int_disable(INT_TRNG_IRQ); + ti_lib_int_disable(INT_TRNG_IRQ); } /*---------------------------------------------------------------------------*/ static void @@ -79,14 +79,14 @@ enable_number_ready_interrupt(void) { ti_lib_trng_int_clear(TRNG_NUMBER_READY); ti_lib_trng_int_enable(TRNG_NUMBER_READY); - ti_lib_rom_int_enable(INT_TRNG_IRQ); + ti_lib_int_enable(INT_TRNG_IRQ); } /*---------------------------------------------------------------------------*/ static bool accessible(void) { /* First, check the PD */ - if(ti_lib_rom_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) + if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON) { return false; } @@ -104,12 +104,12 @@ static void power_up(void) { /* First, make sure the PERIPH PD is on */ - ti_lib_rom_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); - while((ti_lib_rom_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) + ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); + while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); /* Enable clock in active mode */ - ti_lib_rom_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); } @@ -136,7 +136,7 @@ static uint64_t read_number(void) { uint64_t ran = (uint64_t)HWREG(TRNG_BASE + TRNG_O_OUT1) << 32; - ran += ti_lib_rom_trng_number_get(TRNG_LOW_WORD); + ran += ti_lib_trng_number_get(TRNG_LOW_WORD); return ran; } @@ -237,7 +237,7 @@ soc_trng_rand_asynchronous(uint32_t samples, soc_trng_callback_t cb) ti_lib_trng_int_clear(TRNG_NUMBER_READY); /* Enable clock in sleep mode and register with LPM */ - ti_lib_rom_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); @@ -271,7 +271,7 @@ PROCESS_THREAD(soc_trng_process, ev, data) } /* Disable clock in sleep mode */ - ti_lib_rom_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c index d42c06af9..1f4a1ca32 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c @@ -123,7 +123,7 @@ spi_arch_lock_and_open(const spi_device_t *dev) != PRCM_DOMAIN_POWER_ON)) ; /* Enable clock in active mode */ - ti_lib_rom_prcm_peripheral_run_enable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_peripheral_run_enable(spi_controller[dev->spi_controller].prcm_periph); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()) ; @@ -131,17 +131,14 @@ spi_arch_lock_and_open(const spi_device_t *dev) ti_lib_ssi_int_disable(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXFF | SSI_RXTO | SSI_TXFF); ti_lib_ssi_int_clear(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXTO); -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated - ti_lib_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, ti_lib_sys_ctrl_clock_get(), - get_mode(dev), SSI_MODE_MASTER, dev->spi_bit_rate, 8); - ti_lib_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, dev->pin_spi_miso, - dev->pin_spi_mosi, IOID_UNUSED, dev->pin_spi_sck); -#else - ti_lib_rom_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, ti_lib_sys_ctrl_clock_get(), - get_mode(dev), SSI_MODE_MASTER, dev->spi_bit_rate, 8); - ti_lib_rom_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, dev->pin_spi_miso, - dev->pin_spi_mosi, IOID_UNUSED, dev->pin_spi_sck); -#endif + ti_lib_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, + ti_lib_sys_ctrl_clock_get(), + get_mode(dev), SSI_MODE_MASTER, + dev->spi_bit_rate, 8); + ti_lib_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, + dev->pin_spi_miso, + dev->pin_spi_mosi, IOID_UNUSED, + dev->pin_spi_sck); ti_lib_ssi_enable(spi_controller[dev->spi_controller].ssi_base); @@ -159,7 +156,7 @@ spi_arch_close_and_unlock(const spi_device_t *dev) } /* Power down SSI */ - ti_lib_rom_prcm_peripheral_run_disable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_peripheral_run_disable(spi_controller[dev->spi_controller].prcm_periph); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()) ; @@ -213,20 +210,12 @@ spi_arch_transfer(const spi_device_t *dev, for(i = 0; i < totlen; i++) { c = i < wlen ? write_buf[i] : 0; ti_lib_ssi_data_put(spi_controller[dev->spi_controller].ssi_base, (uint8_t)c); -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated ti_lib_ssi_data_get(spi_controller[dev->spi_controller].ssi_base, &c); -#else - ti_lib_rom_ssi_data_get(spi_controller[dev->spi_controller].ssi_base, &c); -#endif if(i < rlen) { inbuf[i] = (uint8_t)c; } } -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated while(ti_lib_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; -#else - while(ti_lib_rom_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; -#endif return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c b/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c index 42e648a73..639b246cc 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c @@ -63,9 +63,9 @@ LPM_MODULE(rf_switch_module, NULL, shutdown_handler, NULL, LPM_DOMAIN_NONE); void rf_switch_init() { - ti_lib_rom_ioc_pin_type_gpio_output(POWER_PIN); + ti_lib_ioc_pin_type_gpio_output(POWER_PIN); ti_lib_gpio_clear_dio(POWER_PIN); - ti_lib_rom_ioc_pin_type_gpio_output(SELECT_PIN); + ti_lib_ioc_pin_type_gpio_output(SELECT_PIN); ti_lib_gpio_clear_dio(SELECT_PIN); lpm_register_module(&rf_switch_module); diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/srf06-cc26xx/platform.c index 427504ed8..cf72dfae2 100644 --- a/arch/platform/srf06-cc26xx/platform.c +++ b/arch/platform/srf06-cc26xx/platform.c @@ -162,7 +162,7 @@ platform_init_stage_one() ti_lib_pwr_ctrl_io_freeze_disable(); #endif - ti_lib_rom_int_enable(INT_AON_GPIO_EDGE); + ti_lib_int_enable(INT_AON_GPIO_EDGE); ti_lib_int_master_enable(); soc_rtc_init(); diff --git a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c b/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c index a2b3651e5..9e9685cd3 100644 --- a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c +++ b/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c @@ -601,11 +601,11 @@ configure(int type, int enable) { switch(type) { case SENSORS_HW_INIT: - ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); + ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); ti_lib_ioc_io_port_pull_set(BOARD_IOID_MPU_INT, IOC_IOPULL_DOWN); ti_lib_ioc_io_hyst_set(BOARD_IOID_MPU_INT, IOC_HYST_ENABLE); - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); + ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); ti_lib_ioc_io_drv_strength_set(BOARD_IOID_MPU_POWER, IOC_CURRENT_4MA, IOC_STRENGTH_MAX); ti_lib_gpio_clear_dio(BOARD_IOID_MPU_POWER); diff --git a/arch/platform/srf06-cc26xx/srf06/als-sensor.c b/arch/platform/srf06-cc26xx/srf06/als-sensor.c index 3b6fdecb9..74edc06bb 100644 --- a/arch/platform/srf06-cc26xx/srf06/als-sensor.c +++ b/arch/platform/srf06-cc26xx/srf06/als-sensor.c @@ -59,10 +59,10 @@ config(int type, int enable) ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); break; case SENSORS_ACTIVE: - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); - ti_lib_rom_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO, + ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); + ti_lib_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO, IOC_STD_OUTPUT); - ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT); + ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT); if(enable) { ti_lib_gpio_set_dio(BOARD_IOID_ALS_PWR); From 23ab33cc390e0400d53b2fbfd63eda1b883a9f45 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:08:26 +0100 Subject: [PATCH 010/184] Remove ti-lib-rom.h --- arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c | 1 - arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h | 1 - arch/cpu/cc26xx-cc13xx/ti-lib-rom.h | 195 --------------------- arch/cpu/cc26xx-cc13xx/ti-lib.h | 3 - 4 files changed, 200 deletions(-) delete mode 100644 arch/cpu/cc26xx-cc13xx/ti-lib-rom.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c index 285652690..4fd4f7688 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c @@ -39,7 +39,6 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ti-lib.h" -#include "ti-lib-rom.h" #include "dev/gpio-hal.h" #include diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h index ae1b04e26..3997c1062 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h @@ -49,7 +49,6 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ti-lib.h" -#include "ti-lib-rom.h" #include /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h b/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h deleted file mode 100644 index e9fe50111..000000000 --- a/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.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: - * 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. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc26xx-ti-lib - * @{ - * - * \file - * Header file with CC13xxware/CC26xxware ROM API. - */ -/*---------------------------------------------------------------------------*/ -#ifndef TI_LIB_ROM_H_ -#define TI_LIB_ROM_H_ -/*---------------------------------------------------------------------------*/ -/* rom.h */ -#include "driverlib/rom.h" - -/* AON API */ -#define ti_lib_rom_aon_event_mcu_wake_up_set ROM_AONEventMcuWakeUpSet -#define ti_lib_rom_aon_event_mcu_wake_up_get ROM_AONEventMcuWakeUpGet -#define ti_lib_rom_aon_event_aux_wake_up_set ROM_AONEventAuxWakeUpSet -#define ti_lib_rom_aon_event_aux_wake_up_get ROM_AONEventAuxWakeUpGet -#define ti_lib_rom_aon_event_mcu_set ROM_AONEventMcuSet -#define ti_lib_rom_aon_event_mcu_get ROM_AONEventMcuGet - -/* AON_WUC API */ -#define ti_lib_rom_aon_wuc_aux_reset ROM_AONWUCAuxReset -#define ti_lib_rom_aon_wuc_recharge_ctrl_config_set ROM_AONWUCRechargeCtrlConfigSet -#define ti_lib_rom_aon_wuc_osc_config ROM_AONWUCOscConfig - -/* AUX_TDC API */ -#define ti_lib_rom_aux_tdc_config_set ROM_AUXTDCConfigSet -#define ti_lib_rom_aux_tdc_measurement_done ROM_AUXTDCMeasurementDone - -/* AUX_WUC API */ -#define ti_lib_rom_aux_wuc_clock_enable ROM_AUXWUCClockEnable -#define ti_lib_rom_aux_wuc_clock_disable ROM_AUXWUCClockDisable -#define ti_lib_rom_aux_wuc_clock_status ROM_AUXWUCClockStatus -#define ti_lib_rom_aux_wuc_power_ctrl ROM_AUXWUCPowerCtrl - -/* FLASH API */ -#define ti_lib_rom_flash_power_mode_get ROM_FlashPowerModeGet -#define ti_lib_rom_flash_protection_set ROM_FlashProtectionSet -#define ti_lib_rom_flash_protection_get ROM_FlashProtectionGet -#define ti_lib_rom_flash_protection_save ROM_FlashProtectionSave -#define ti_lib_rom_flash_efuse_read_row ROM_FlashEfuseReadRow -#define ti_lib_rom_flash_disable_sectors_for_write ROM_FlashDisableSectorsForWrite - -/* I2C API */ -#define ti_lib_rom_i2c_master_init_exp_clk ROM_I2CMasterInitExpClk -#define ti_lib_rom_i2c_master_err ROM_I2CMasterErr - -/* INTERRUPT API */ -#define ti_lib_rom_int_priority_grouping_set ROM_IntPriorityGroupingSet -#define ti_lib_rom_int_priority_grouping_get ROM_IntPriorityGroupingGet -#define ti_lib_rom_int_priority_set ROM_IntPrioritySet -#define ti_lib_rom_int_priority_get ROM_IntPriorityGet -#define ti_lib_rom_int_enable ROM_IntEnable -#define ti_lib_rom_int_disable ROM_IntDisable -#define ti_lib_rom_int_pend_set ROM_IntPendSet -#define ti_lib_rom_int_pend_get ROM_IntPendGet -#define ti_lib_rom_int_pend_clear ROM_IntPendClear - -/* IOC API */ -#define ti_lib_rom_ioc_port_configure_set ROM_IOCPortConfigureSet -#if !defined(ThisLibraryIsFor_CC26x0R2_HaltIfViolated) -#define ti_lib_rom_ioc_port_configure_get ROM_IOCPortConfigureGet -#define ti_lib_rom_ioc_io_shutdown_set ROM_IOCIOShutdownSet -#define ti_lib_rom_ioc_io_mode_set ROM_IOCIOModeSet -#define ti_lib_rom_ioc_io_int_set ROM_IOCIOIntSet -#define ti_lib_rom_ioc_io_port_pull_set ROM_IOCIOPortPullSet -#define ti_lib_rom_ioc_io_hyst_set ROM_IOCIOHystSet -#define ti_lib_rom_ioc_io_input_set ROM_IOCIOInputSet -#define ti_lib_rom_ioc_io_slew_ctrl_set ROM_IOCIOSlewCtrlSet -#define ti_lib_rom_ioc_io_drv_strength_set ROM_IOCIODrvStrengthSet -#define ti_lib_rom_ioc_io_port_id_set ROM_IOCIOPortIdSet -#define ti_lib_rom_ioc_int_enable ROM_IOCIntEnable -#define ti_lib_rom_ioc_int_disable ROM_IOCIntDisable -#define ti_lib_rom_ioc_pin_type_gpio_input ROM_IOCPinTypeGpioInput -#define ti_lib_rom_ioc_pin_type_gpio_output ROM_IOCPinTypeGpioOutput -#define ti_lib_rom_ioc_pin_type_uart ROM_IOCPinTypeUart -#define ti_lib_rom_ioc_pin_type_ssi_master ROM_IOCPinTypeSsiMaster -#define ti_lib_rom_ioc_pin_type_ssi_slave ROM_IOCPinTypeSsiSlave -#define ti_lib_rom_ioc_pin_type_i2c ROM_IOCPinTypeI2c -#define ti_lib_rom_ioc_pin_type_aux ROM_IOCPinTypeAux -#endif - -/* PRCM API */ -#define ti_lib_rom_prcm_inf_clock_configure_set ROM_PRCMInfClockConfigureSet -#define ti_lib_rom_prcm_inf_clock_configure_get ROM_PRCMInfClockConfigureGet -#define ti_lib_rom_prcm_audio_clock_config_set ROM_PRCMAudioClockConfigSet -#define ti_lib_rom_prcm_power_domain_on ROM_PRCMPowerDomainOn -#define ti_lib_rom_prcm_power_domain_off ROM_PRCMPowerDomainOff -#define ti_lib_rom_prcm_peripheral_run_enable ROM_PRCMPeripheralRunEnable -#define ti_lib_rom_prcm_peripheral_run_disable ROM_PRCMPeripheralRunDisable -#define ti_lib_rom_prcm_peripheral_sleep_enable ROM_PRCMPeripheralSleepEnable -#define ti_lib_rom_prcm_peripheral_sleep_disable ROM_PRCMPeripheralSleepDisable -#define ti_lib_rom_prcm_peripheral_deep_sleep_enable ROM_PRCMPeripheralDeepSleepEnable -#define ti_lib_rom_prcm_peripheral_deep_sleep_disable ROM_PRCMPeripheralDeepSleepDisable -#define ti_lib_rom_prcm_power_domain_status ROM_PRCMPowerDomainStatus -#define ti_lib_rom_prcm_deep_sleep ROM_PRCMDeepSleep - -/* SMPH API */ -#define ti_lib_rom_smph_acquire ROM_SMPHAcquire - -/* SSI API */ -#define ti_lib_rom_ssi_config_set_exp_clk ROM_SSIConfigSetExpClk -#define ti_lib_rom_ssi_data_put ROM_SSIDataPut -#define ti_lib_rom_ssi_data_put_non_blocking ROM_SSIDataPutNonBlocking -#define ti_lib_rom_ssi_data_get ROM_SSIDataGet -#define ti_lib_rom_ssi_data_get_non_blocking ROM_SSIDataGetNonBlocking - -/* TIMER API */ -#define ti_lib_rom_timer_configure ROM_TimerConfigure -#define ti_lib_rom_timer_level_control ROM_TimerLevelControl -#define ti_lib_rom_timer_stall_control ROM_TimerStallControl -#define ti_lib_rom_timer_wait_on_trigger_control ROM_TimerWaitOnTriggerControl - -/* TRNG API */ -#define ti_lib_rom_trng_number_get ROM_TRNGNumberGet - -/* UART API */ -#define ti_lib_rom_uart_fifo_level_get ROM_UARTFIFOLevelGet -#define ti_lib_rom_uart_config_set_exp_clk ROM_UARTConfigSetExpClk -#define ti_lib_rom_uart_config_get_exp_clk ROM_UARTConfigGetExpClk -#define ti_lib_rom_uart_disable ROM_UARTDisable -#define ti_lib_rom_uart_char_get_non_blocking ROM_UARTCharGetNonBlocking -#define ti_lib_rom_uart_char_get ROM_UARTCharGet -#define ti_lib_rom_uart_char_put_non_blocking ROM_UARTCharPutNonBlocking -#define ti_lib_rom_uart_char_put ROM_UARTCharPut - -/* UDMA API */ -#define ti_lib_rom_udma_channel_attribute_enable ROM_uDMAChannelAttributeEnable -#define ti_lib_rom_udma_channel_attribute_disable ROM_uDMAChannelAttributeDisable -#define ti_lib_rom_udma_channel_attribute_get ROM_uDMAChannelAttributeGet -#define ti_lib_rom_udma_channel_control_set ROM_uDMAChannelControlSet -#define ti_lib_rom_udma_channel_transfer_set ROM_uDMAChannelTransferSet -#define ti_lib_rom_udma_channel_scatter_gather_set ROM_uDMAChannelScatterGatherSet -#define ti_lib_rom_udma_channel_size_get ROM_uDMAChannelSizeGet -#define ti_lib_rom_udma_channel_mode_get ROM_uDMAChannelModeGet - -/* VIMS API */ -#define ti_lib_rom_vims_configure ROM_VIMSConfigure -#define ti_lib_rom_vims_mode_set ROM_VIMSModeSet - -/* HAPI */ -#define ti_lib_hapi_crc32(a, b, c) HapiCrc32(a, b, c) -#define ti_lib_hapi_get_flash_size() HapiGetFlashSize() -#define ti_lib_hapi_get_chip_id() HapiGetChipId() -#define ti_lib_hapi_sector_erase(a) HapiSectorErase(a) -#define ti_lib_hapi_program_flash(a, b, c) HapiProgramFlash(a, b, c) -#define ti_lib_hapi_reset_device() HapiResetDevice() -#define ti_lib_hapi_fletcher32(a, b, c) HapiFletcher32(a, b, c) -#define ti_lib_hapi_min_value(a, b) HapiMinValue(a,b) -#define ti_lib_hapi_max_value(a, b) HapiMaxValue(a,b) -#define ti_lib_hapi_mean_value(a, b) HapiMeanValue(a,b) -#define ti_lib_hapi_stand_deviation_value(a, b) HapiStandDeviationValue(a,b) -#define ti_lib_hapi_hf_source_safe_switch() HapiHFSourceSafeSwitch() -#define ti_lib_hapi_select_comp_a_input(a) HapiSelectCompAInput(a) -#define ti_lib_hapi_select_comp_a_ref(a) HapiSelectCompARef(a) -#define ti_lib_hapi_select_adc_comp_b_input(a) HapiSelectADCCompBInput(a) -#define ti_lib_hapi_select_comp_b_ref(a) HapiSelectCompBRef(a) -/*---------------------------------------------------------------------------*/ -#endif /* TI_LIB_ROM_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib.h b/arch/cpu/cc26xx-cc13xx/ti-lib.h index 6e6d78afb..6afcfeb84 100644 --- a/arch/cpu/cc26xx-cc13xx/ti-lib.h +++ b/arch/cpu/cc26xx-cc13xx/ti-lib.h @@ -52,9 +52,6 @@ #ifndef TI_LIB_H_ #define TI_LIB_H_ /*---------------------------------------------------------------------------*/ -/* Include ROM API */ -#include "ti-lib-rom.h" -/*---------------------------------------------------------------------------*/ /* aon_batmon.h */ #include "driverlib/aon_batmon.h" From 3ba8afea79ab49ceeb2f3f25ac67848f78d5790f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:10:06 +0100 Subject: [PATCH 011/184] Harmonize usage across XXwares and CC2640R2-SDK --- arch/cpu/cc26xx-cc13xx/lpm.c | 11 +++-------- arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c | 4 ++-- arch/cpu/cc26xx-cc13xx/ti-lib.h | 21 +++++++++++++-------- arch/platform/srf06-cc26xx/platform.c | 6 +++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/arch/cpu/cc26xx-cc13xx/lpm.c b/arch/cpu/cc26xx-cc13xx/lpm.c index 4c8e0256b..2337fb24f 100644 --- a/arch/cpu/cc26xx-cc13xx/lpm.c +++ b/arch/cpu/cc26xx-cc13xx/lpm.c @@ -162,10 +162,10 @@ lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on) ti_lib_aon_wuc_mcu_power_off_config(MCU_VIRT_PWOFF_DISABLE); /* Latch the IOs in the padring and enable I/O pad sleep mode */ -#if !defined(ThisLibraryIsFor_CC26x0R2_HaltIfViolated) - ti_lib_pwr_ctrl_io_freeze_enable(); + ti_lib_aon_ioc_freeze_enable(); + HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 0; + ti_lib_sys_ctrl_aon_sync(); -#endif /* Turn off VIMS cache, CRAM and TRAM - possibly not required */ ti_lib_prcm_cache_retention_disable(); ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_OFF); @@ -193,12 +193,7 @@ wake_up(void) ti_lib_sys_ctrl_aon_sync(); /* Adjust recharge settings */ -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated - // May need to change to XOSC_IN_LOW_POWER_MODE - ti_lib_sys_ctrl_adjust_recharge_after_power_down(XOSC_IN_HIGH_POWER_MODE); -#else ti_lib_sys_ctrl_adjust_recharge_after_power_down(); -#endif /* * Release the request to the uLDO diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c index 185842b42..faa8f808b 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c @@ -399,8 +399,8 @@ rf_core_set_modesel() } else if(chip_type == CHIP_TYPE_CC1350) { HWREG(PRCM_BASE + PRCM_O_RFCMODESEL) = PRCM_RFCMODESEL_CURR_MODE5; rv = RF_CORE_CMD_OK; -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated - } else if (chip_type == CHIP_TYPE_CC2640R2) { +#if CPU_FAMILY_CC26X0R2 + } else if(chip_type == CHIP_TYPE_CC2640R2) { HWREG(PRCM_BASE + PRCM_O_RFCMODESEL) = PRCM_RFCMODESEL_CURR_MODE1; rv = RF_CORE_CMD_OK; #endif diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib.h b/arch/cpu/cc26xx-cc13xx/ti-lib.h index 6afcfeb84..6bba7c849 100644 --- a/arch/cpu/cc26xx-cc13xx/ti-lib.h +++ b/arch/cpu/cc26xx-cc13xx/ti-lib.h @@ -197,14 +197,16 @@ #define ti_lib_chipinfo_get_device_id_hw_rev_code(...) ChipInfo_GetDeviceIdHwRevCode(__VA_ARGS__) #define ti_lib_chipinfo_get_chip_type(...) ChipInfo_GetChipType(__VA_ARGS__) #define ti_lib_chipinfo_get_chip_family(...) ChipInfo_GetChipFamily(__VA_ARGS__) -#ifdef ThisLibraryIsFor_CC26x0R2_HaltIfViolated + +#if CPU_FAMILY_CC26X0R2 #define ti_lib_chipinfo_chip_family_is_cc26xx(...) ChipInfo_ChipFamilyIs_CC26x0(__VA_ARGS__) #define ti_lib_chipinfo_chip_family_is_cc13xx(...) ChipInfo_ChipFamilyIs_CC13x0(__VA_ARGS__) -#define ti_lib_chipinfo_chip_family_is_cc26x0r2(...) ChipInfo_ChipFamilyIs_CC26x0R2(__VA_ARGS__) +#define ti_lib_chipinfo_chip_family_is_cc26x0r2(...) ChipInfo_ChipFamilyIs_CC26x0R2(__VA_ARGS__) #else #define ti_lib_chipinfo_chip_family_is_cc26xx(...) ChipInfo_ChipFamilyIsCC26xx(__VA_ARGS__) #define ti_lib_chipinfo_chip_family_is_cc13xx(...) ChipInfo_ChipFamilyIsCC13xx(__VA_ARGS__) -#endif +#endif /* CPU_FAMILY_CC26X0R2 */ + #define ti_lib_chipinfo_get_hw_revision(...) ChipInfo_GetHwRevision(__VA_ARGS__) #define ti_lib_chipinfo_hw_revision_is_1_0(...) ChipInfo_HwRevisionIs_1_0(__VA_ARGS__) #define ti_lib_chipinfo_hw_revision_is_gteq_2_0(...) ChipInfo_HwRevisionIs_GTEQ_2_0(__VA_ARGS__) @@ -391,10 +393,6 @@ #define ti_lib_pwr_ctrl_source_get(...) PowerCtrlSourceGet(__VA_ARGS__) #define ti_lib_pwr_ctrl_reset_source_get(...) PowerCtrlResetSourceGet(__VA_ARGS__) #define ti_lib_pwr_ctrl_reset_source_clear(...) PowerCtrlResetSourceClear(__VA_ARGS__) -#if !defined(ThisLibraryIsFor_CC26x0R2_HaltIfViolated) -#define ti_lib_pwr_ctrl_io_freeze_enable(...) PowerCtrlIOFreezeEnable(__VA_ARGS__) -#define ti_lib_pwr_ctrl_io_freeze_disable(...) PowerCtrlIOFreezeDisable(__VA_ARGS__) -#endif /*---------------------------------------------------------------------------*/ /* rfc.h */ #include "driverlib/rfc.h" @@ -413,7 +411,14 @@ #define ti_lib_sys_ctrl_aon_sync(...) SysCtrlAonSync(__VA_ARGS__) #define ti_lib_sys_ctrl_aon_update(...) SysCtrlAonUpdate(__VA_ARGS__) #define ti_lib_sys_ctrl_set_recharge_before_power_down(...) SysCtrlSetRechargeBeforePowerDown(__VA_ARGS__) -#define ti_lib_sys_ctrl_adjust_recharge_after_power_down(...) SysCtrlAdjustRechargeAfterPowerDown(__VA_ARGS__) + +#if CPU_FAMILY_CC26X0R2 +/* May need to change to XOSC_IN_LOW_POWER_MODE */ +#define ti_lib_sys_ctrl_adjust_recharge_after_power_down() SysCtrlAdjustRechargeAfterPowerDown(XOSC_IN_HIGH_POWER_MODE) +#else +#define ti_lib_sys_ctrl_adjust_recharge_after_power_down() SysCtrlAdjustRechargeAfterPowerDown() +#endif /* CPU_FAMILY_CC26X0R2 */ + #define ti_lib_sys_ctrl_dcdc_voltage_conditional_control(...) SysCtrl_DCDC_VoltageConditionalControl(__VA_ARGS__) #define ti_lib_sys_ctrl_reset_source_get(...) SysCtrlResetSourceGet(__VA_ARGS__) #define ti_lib_sys_ctrl_system_reset(...) SysCtrlSystemReset(__VA_ARGS__) diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/srf06-cc26xx/platform.c index cf72dfae2..d160c13e1 100644 --- a/arch/platform/srf06-cc26xx/platform.c +++ b/arch/platform/srf06-cc26xx/platform.c @@ -158,10 +158,10 @@ platform_init_stage_one() * latches in the first place. Before doing these things though, we should * allow software to first regain control of pins */ -#if !defined(ThisLibraryIsFor_CC26x0R2_HaltIfViolated) - ti_lib_pwr_ctrl_io_freeze_disable(); + ti_lib_aon_ioc_freeze_disable(); + HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 1; + ti_lib_sys_ctrl_aon_sync(); -#endif ti_lib_int_enable(INT_AON_GPIO_EDGE); ti_lib_int_master_enable(); From 4a0c9d88944e6525a8556c5beadda01149fd03c5 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:14:26 +0100 Subject: [PATCH 012/184] Change define to reflect current chip family name --- arch/cpu/cc26xx-cc13xx/Makefile.cc13xx | 2 +- arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h | 4 ++-- .../cc26xx/cc26xx-web-demo/cc26xx-web-demo.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx index 093aa1f02..ac050efe8 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx @@ -2,6 +2,6 @@ TI_XXWARE_PATH = lib/cc13xxware CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c -CFLAGS += -DCPU_FAMILY_CC13XX=1 +CFLAGS += -DCPU_FAMILY_CC13X0=1 -DCPU_FAMILY_CC13XX=1 include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h index e7d9dacd7..7400c5ad9 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h @@ -64,11 +64,11 @@ * project has specified otherwise. Depending on the final mode, determine a * default channel (again, if unspecified) and configure RDC params */ -#if CPU_FAMILY_CC13XX +#if CPU_FAMILY_CC13X0 #ifndef CC13XX_CONF_PROP_MODE #define CC13XX_CONF_PROP_MODE 1 #endif /* CC13XX_CONF_PROP_MODE */ -#endif /* CPU_FAMILY_CC13XX */ +#endif /* CPU_FAMILY_CC13X0 */ #if CC13XX_CONF_PROP_MODE #ifndef NETSTACK_CONF_RADIO diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h index 0761725c7..f59e41bc7 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h @@ -119,7 +119,7 @@ /*---------------------------------------------------------------------------*/ /* Default configuration values */ #define CC26XX_WEB_DEMO_DEFAULT_ORG_ID "quickstart" -#if CPU_FAMILY_CC13XX +#if CPU_FAMILY_CC13X0 #define CC26XX_WEB_DEMO_DEFAULT_TYPE_ID "cc13xx" #else #define CC26XX_WEB_DEMO_DEFAULT_TYPE_ID "cc26xx" From bf0e80aae33119c80641a243be52e8a1cc43b934 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:14:53 +0100 Subject: [PATCH 013/184] Always provide -DCPU_FAMILY_xxx --- arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f | 2 ++ arch/cpu/cc26xx-cc13xx/Makefile.cc26xx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f b/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f index decece481..56d041516 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f @@ -1,3 +1,5 @@ TI_XXWARE_PATH = lib/cc2640r2-sdk +CFLAGS += -DCPU_FAMILY_CC26X0R2=1 -DCPU_FAMILY_CC26XXR2=1 + include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx index 4bc2cdcad..34a147f7b 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx @@ -1,3 +1,5 @@ TI_XXWARE_PATH = lib/cc26xxware +CFLAGS += -DCPU_FAMILY_CC26X0=1 -DCPU_FAMILY_CC26XX=1 + include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx From 8ea3e9fb774861210334c9928b9bf6646b88a839 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 2 Oct 2018 23:35:22 +0100 Subject: [PATCH 014/184] Improve code style --- arch/platform/srf06-cc26xx/srf06/als-sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/platform/srf06-cc26xx/srf06/als-sensor.c b/arch/platform/srf06-cc26xx/srf06/als-sensor.c index 74edc06bb..42e714065 100644 --- a/arch/platform/srf06-cc26xx/srf06/als-sensor.c +++ b/arch/platform/srf06-cc26xx/srf06/als-sensor.c @@ -61,7 +61,7 @@ config(int type, int enable) case SENSORS_ACTIVE: ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); ti_lib_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO, - IOC_STD_OUTPUT); + IOC_STD_OUTPUT); ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT); if(enable) { From 163d1241b3bdb5875c9235c0a539b7121fb60177 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 25 May 2018 07:03:22 -0700 Subject: [PATCH 015/184] timer_reset: do not do anything if the timer has not expired --- os/sys/timer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/os/sys/timer.c b/os/sys/timer.c index 1eeae64de..b99aa4127 100644 --- a/os/sys/timer.c +++ b/os/sys/timer.c @@ -74,9 +74,8 @@ timer_set(struct timer *t, clock_time_t interval) * given to the timer_set() function. The start point of the interval * is the exact time that the timer last expired. Therefore, this * function will cause the timer to be stable over time, unlike the - * timer_restart() function. - * - * \note Must not be executed before timer expired + * timer_restart() function. If this is executed before the + * timer expired, this function has no effect. * * \param t A pointer to the timer. * \sa timer_restart() @@ -84,7 +83,9 @@ timer_set(struct timer *t, clock_time_t interval) void timer_reset(struct timer *t) { - t->start += t->interval; + if(timer_expired(t)) { + t->start += t->interval; + } } /*---------------------------------------------------------------------------*/ /** From 8472cf8bbe4d57d18bce7522070aa1cf9be7fabd Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 13 Oct 2018 10:17:30 +0200 Subject: [PATCH 016/184] stimer_reset: do not do anything if the timer has not expired --- os/sys/stimer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/os/sys/stimer.c b/os/sys/stimer.c index 1301dc41e..007587e83 100644 --- a/os/sys/stimer.c +++ b/os/sys/stimer.c @@ -77,7 +77,8 @@ stimer_set(struct stimer *t, unsigned long interval) * given to the stimer_set() function. The start point of the interval * is the exact time that the timer last expired. Therefore, this * function will cause the timer to be stable over time, unlike the - * stimer_restart() function. + * stimer_restart() function. If this is executed before the + * timer expired, this function has no effect. * * \param t A pointer to the timer. * @@ -86,7 +87,9 @@ stimer_set(struct stimer *t, unsigned long interval) void stimer_reset(struct stimer *t) { - t->start += t->interval; + if(stimer_expired(t)) { + t->start += t->interval; + } } /*---------------------------------------------------------------------------*/ /** From 2a66edfd6b3a991744b5558b1c3e3d19e3f56023 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 13 Oct 2018 10:19:18 +0200 Subject: [PATCH 017/184] Doxygen clarification to etimer_reset and ctimer_reset --- os/sys/ctimer.h | 3 ++- os/sys/etimer.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/os/sys/ctimer.h b/os/sys/ctimer.h index 2d391a5e5..e7e463ac4 100644 --- a/os/sys/ctimer.h +++ b/os/sys/ctimer.h @@ -76,7 +76,8 @@ struct ctimer { * is the exact time that the callback timer last * expired. Therefore, this function will cause the timer * to be stable over time, unlike the ctimer_restart() - * function. + * function. If this is executed before the timer expired, + * this function has no effect. * * \sa ctimer_restart() */ diff --git a/os/sys/etimer.h b/os/sys/etimer.h index 02ad5df11..2922b9aa2 100644 --- a/os/sys/etimer.h +++ b/os/sys/etimer.h @@ -107,7 +107,8 @@ void etimer_set(struct etimer *et, clock_time_t interval); * is the exact time that the event timer last * expired. Therefore, this function will cause the timer * to be stable over time, unlike the etimer_restart() - * function. + * function. If this is executed before the timer expired, + * this function has no effect. * * \sa etimer_restart() */ From 87efd3fb45a34d1dbd8428c5ef90da80f641d945 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Sun, 9 Sep 2018 20:34:17 +0100 Subject: [PATCH 018/184] TI lib: add ti_lib_rfc_hw_int_enable/disable/clear functions --- arch/cpu/cc26xx-cc13xx/ti-lib.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib.h b/arch/cpu/cc26xx-cc13xx/ti-lib.h index 6bba7c849..d6c7363ee 100644 --- a/arch/cpu/cc26xx-cc13xx/ti-lib.h +++ b/arch/cpu/cc26xx-cc13xx/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" From cb65f31d48fe5c13b85ced660f3029c382cb23a1 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Sat, 15 Sep 2018 12:16:05 +0100 Subject: [PATCH 019/184] Remove BOARDS_EXCLUDE for TSCH examples: now they can be built for CC13xx boards --- examples/6tisch/6p-packet/Makefile | 1 - examples/6tisch/etsi-plugtest-2017/Makefile | 2 +- examples/6tisch/simple-node/Makefile | 1 - examples/6tisch/sixtop/Makefile | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) 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/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/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=../../.. From 5d041474066155a896de520a273daedc86d1c21b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Sun, 9 Sep 2018 20:32:33 +0100 Subject: [PATCH 020/184] CC26xx/CC13xx: Add support for TSCH API for the prop-mode.c radio driver, and unify the radio timer handling between the IEEE and prop modes --- arch/cpu/cc26xx-cc13xx/Makefile.cc13xx | 2 +- arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h | 42 +- .../rf-core/ble-hal/ble-hal-cc26xx.c | 2 +- .../rf-core/cc13xx-50kbps-tsch.c | 73 ++++ .../rf-core/cc13xx-50kbps-tsch.h | 41 ++ arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c | 334 ++++----------- arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c | 386 +++++++++++++----- arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c | 164 +++++++- arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h | 91 ++++- os/net/mac/tsch/tsch-const.h | 4 +- 10 files changed, 757 insertions(+), 382 deletions(-) create mode 100644 arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c create mode 100644 arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx index ac050efe8..5ea92e30c 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx @@ -1,6 +1,6 @@ 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 diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h index 47dbc4eb5..97b188e15 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26xx-cc13xx/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/rf-core/ble-hal/ble-hal-cc26xx.c b/arch/cpu/cc26xx-cc13xx/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/cc26xx-cc13xx/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/cc13xx-50kbps-tsch.c b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c new file mode 100644 index 000000000..af76d63e3 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/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/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h new file mode 100644 index 000000000..5d4fdb376 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h @@ -0,0 +1,41 @@ +/* + * 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. + * + */ + +#ifndef CC13XX_50KBPS_TSCH_H_ +#define CC13XX_50KBPS_TSCH_H_ + +#include "contiki.h" + +/* TSCH timeslot timing (microseconds) */ +extern const uint16_t tsch_timing_cc13xx_50kbps[]; + +#endif /* CC13XX_50KBPS_TSCH_H_ */ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c b/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c index 3516147b5..9f4021d21 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c +++ b/arch/cpu/cc26xx-cc13xx/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.c b/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c index 66b4a4370..0ce6de5dd 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c +++ b/arch/cpu/cc26xx-cc13xx/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/rf-core.c b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c index faa8f808b..db3c6adb3 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/arch/cpu/cc26xx-cc13xx/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,19 @@ 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; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; 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 +569,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 +724,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/cc26xx-cc13xx/rf-core/rf-core.h index c97ab0f8a..6cb65672d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h +++ b/arch/cpu/cc26xx-cc13xx/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/os/net/mac/tsch/tsch-const.h b/os/net/mac/tsch/tsch-const.h index edc989378..d158c802c 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 */ From ad03d3a05e29de87b2ef1fdf1b4941e63924b22a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 16:02:06 +0100 Subject: [PATCH 021/184] Remove obsolete function prototypes --- os/dev/spi.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/os/dev/spi.h b/os/dev/spi.h index b7114717f..9dda05b8e 100644 --- a/os/dev/spi.h +++ b/os/dev/spi.h @@ -323,25 +323,6 @@ spi_status_t spi_arch_transfer(const spi_device_t *dev, uint8_t *buf, int rlen, int ignore_len); -/** - * \brief Selects an SPI device - * \param dev An SPI device configuration that specifies the CS pin. - * \return SPI return code - * - * Clears the CS pin. It should work only if the device has already - * locked the SPI controller. - */ -spi_status_t spi_arch_select(const spi_device_t *dev); - -/** - * \brief Deselects an SPI device - * \param dev An SPI device configuration that specifies the CS pin. - * \return SPI return code - * - * Set the CS pin. Locking the SPI controller is not needed. - */ -spi_status_t spi_arch_deselect(const spi_device_t *dev); - #endif /* SPI_H_ */ /*---------------------------------------------------------------------------*/ /** From 4b7266247e17726e89b1a71768039bb7bf1137a1 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Wed, 26 Sep 2018 13:41:38 +0100 Subject: [PATCH 022/184] Add optimization flags for native builds --- arch/cpu/native/Makefile.native | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index d7832d358..30883622d 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -20,6 +20,30 @@ endif CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR) CFLAGS += $(CFLAGSNO) +### Are we building with code size optimisations? +SMALL ?= 0 + +# The optimizations on native platform cannot be enabled in GCC (not Clang) versions less than 7.2 +GCC_IS_CLANG := $(shell gcc --version 2> /dev/null | grep clang) +ifneq ($(GCC_IS_CLANG),) + NATIVE_CAN_OPTIIMIZE = 1 +else + GCC_VERSION := $(shell gcc -dumpfullversion -dumpversion | cut -b1-3) + ifeq ($(shell expr $(GCC_VERSION) \>= 7.2), 1) + NATIVE_CAN_OPTIIMIZE = 1 + else + NATIVE_CAN_OPTIIMIZE = 0 + endif +endif + +ifeq ($(NATIVE_CAN_OPTIIMIZE),1) + ifeq ($(SMALL),1) + CFLAGS += -Os + else + CFLAGS += -O2 + endif +endif + ifeq ($(HOST_OS),Darwin) AROPTS = -rc LDFLAGS_WERROR := -Wl,-fatal_warnings From 386e528cc5aad9599ae3b2e5a111d9f4e171da42 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 23 Sep 2018 17:57:47 +0100 Subject: [PATCH 023/184] Harmonise link rule for all cortex CPUs --- arch/cpu/arm/cortex-m/Makefile.cortex-m | 11 +++++++++++ arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 12 ------------ arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 10 ---------- arch/cpu/cc26xx-cc13xx/cc26xx.ld | 2 ++ arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld | 2 ++ arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld | 2 ++ arch/cpu/nrf52832/ld/nrf52.ld | 2 ++ 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/arch/cpu/arm/cortex-m/Makefile.cortex-m b/arch/cpu/arm/cortex-m/Makefile.cortex-m index 444df05cd..aebcf2bdd 100644 --- a/arch/cpu/arm/cortex-m/Makefile.cortex-m +++ b/arch/cpu/arm/cortex-m/Makefile.cortex-m @@ -1,3 +1,14 @@ CONTIKI_ARM_DIRS += cortex-m cortex-m/CMSIS +### Build syscalls for newlib +MODULES += os/lib/newlib + +CUSTOM_RULE_LINK = 1 + +.SECONDEXPANSION: + +%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS) + $(TRACE_LD) + $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ + include $(CONTIKI)/arch/cpu/arm/Makefile.arm diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index 6bd76135c..3cf216bfb 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -9,22 +9,10 @@ LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff -### Build syscalls for newlib -MODULES += os/lib/newlib - CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} -### Compilation rules -CUSTOM_RULE_LINK = 1 - ### Resolve any potential circular dependencies between the linked libraries ### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lm -Wl,--end-group -.SECONDEXPANSION: - -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) - $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ - include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 110e0697b..b0b592e43 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -9,20 +9,10 @@ LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff -### Build syscalls for newlib -MODULES += os/lib/newlib - CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} -### Compilation rules -CUSTOM_RULE_LINK = 1 - ### Resolve any potential circular dependencies between the linked libraries ### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group -%.elf: $(CPU_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TARGET_LIBS) - $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter %.o %.a,$^} $(TARGET_LIBFLAGS) -o $@ - include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/cc26xx-cc13xx/cc26xx.ld b/arch/cpu/cc26xx-cc13xx/cc26xx.ld index 649da32cf..4ea422558 100644 --- a/arch/cpu/cc26xx-cc13xx/cc26xx.ld +++ b/arch/cpu/cc26xx-cc13xx/cc26xx.ld @@ -96,6 +96,8 @@ SECTIONS /* These symbols are used by the stack check library. */ _stack = .; _stack_origin = ORIGIN(SRAM) + LENGTH(SRAM); + _heap = _stack; + _eheap = _stack_origin; .ccfg : { diff --git a/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld b/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld index f3bc5bc43..2afa9e6e2 100644 --- a/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld +++ b/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; diff --git a/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld b/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld index 0bc7349e3..b2c747f0a 100644 --- a/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld +++ b/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; diff --git a/arch/cpu/nrf52832/ld/nrf52.ld b/arch/cpu/nrf52832/ld/nrf52.ld index 87fc9152d..3fead1250 100644 --- a/arch/cpu/nrf52832/ld/nrf52.ld +++ b/arch/cpu/nrf52832/ld/nrf52.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; From db18b43f0fbe401943c0b4131a15e4b7659861de Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 22:07:25 +0100 Subject: [PATCH 024/184] Make sure CONTIKI_BOARD_xyz is defined --- Makefile.include | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile.include b/Makefile.include index 319ae29d7..3578730eb 100644 --- a/Makefile.include +++ b/Makefile.include @@ -46,11 +46,6 @@ UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_ TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1 CFLAGS += -DCONTIKI_TARGET_STRING=\"$(TARGET)\" -ifneq ($(BOARD),) -TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} -CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 -CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\" -endif CFLAGS += -Wno-unused-const-variable @@ -129,6 +124,12 @@ endif # $(BOARD) not empty PLATFORM_ACTION ?= build +ifneq ($(BOARD),) + TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} + CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 + CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\" +endif + # Configure MAC layer # The different options From 6a7deb9fc174e8a6b2b8bd53e91795404195ecf2 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 21:05:52 +0100 Subject: [PATCH 025/184] Detect boards automatically in the build-all script --- tests/compile-all/build.sh | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/compile-all/build.sh b/tests/compile-all/build.sh index fcbbd7bd7..81441816e 100755 --- a/tests/compile-all/build.sh +++ b/tests/compile-all/build.sh @@ -40,17 +40,21 @@ # To invoke the building for a specific platform, run: # $ PLATFORMS=zoul ./build.sh # +CONTIKI_NG_TOP_DIR="../.." +EXAMPLES_DIR=$CONTIKI_NG_TOP_DIR/examples if [[ "$PLATFORMS" == "" ]] then - PLATFORMS=`ls ../../arch/platform` + PLATFORMS=`ls $CONTIKI_NG_TOP_DIR/arch/platform` fi if [[ "$MAKEFILES" == "" ]] then - MAKEFILES=`find ../../examples/ -name Makefile` + MAKEFILES=`find $EXAMPLES_DIR -name Makefile` fi +HELLO_WORLD=$EXAMPLES_DIR/hello-world + # Set the make goal the first argument of the script or to "all" if called w/o arguments if [[ $# -gt 0 ]] then @@ -97,22 +101,14 @@ do continue fi - if [[ "$platform" == "srf06-cc26xx" ]] + # Detect all boards for the current platform by calling + # make TARGET=$platform boards + # in the hello-world dir. + BOARDS=`make -s -C $HELLO_WORLD TARGET=$platform boards \ + | grep -v "no boards" | rev | cut -f3- -d" " | rev` + + if [[ -z $BOARDS ]] then - # srf06-cc26xx has multiple boards - BOARDS="srf06/cc26xx srf06/cc13xx launchpad/cc2650 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350" - elif [[ "$platform" == "simplelink" ]] - then - # SimpleLink has multiple boards - BOARDS="launchpad/cc1310 launchpad/cc1350 launchpad/cc1350-4 launchpad/cc2650 \ - sensortag/cc1350 sensortag/cc2650 srf06/cc13x0 srf06/cc26x0 \ - launchpad/cc1312r1 launchpad/cc1352r1 launchpad/cc1352p1 launchpad/cc1352p-2 launchpad/cc1352p-4 launchpad/cc26x2r1" - elif [[ "$platform" == "zoul" ]] - then - # Zoul has multiple boards - BOARDS="remote-reva remote-revb firefly-reva firefly orion" - else - # Other platforms have just a single board BOARDS="default" fi From 3b5369cf2a1851a062510e21261e0904704aebba Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 15 Oct 2018 14:11:59 +0200 Subject: [PATCH 026/184] MQTT parse_publish_vhdr: added missing initialization of topic_pos --- os/net/app-layer/mqtt/mqtt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/os/net/app-layer/mqtt/mqtt.c b/os/net/app-layer/mqtt/mqtt.c index 46a542c3f..e73ddb425 100644 --- a/os/net/app-layer/mqtt/mqtt.c +++ b/os/net/app-layer/mqtt/mqtt.c @@ -872,6 +872,7 @@ parse_publish_vhdr(struct mqtt_connection *conn, /* Read out topic length */ if(conn->in_packet.topic_len_received == 0) { + conn->in_packet.topic_pos = 0; conn->in_packet.topic_len = (input_data_ptr[(*pos)++] << 8); conn->in_packet.byte_counter++; if(*pos >= input_data_len) { From bcebd3afcfbd472dfc76b5f2d4f599bbc42c97ba Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 15 Oct 2018 14:12:08 +0200 Subject: [PATCH 027/184] MQTT parse_publish_vhdr: added missing check of topic length --- os/net/app-layer/mqtt/mqtt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/os/net/app-layer/mqtt/mqtt.c b/os/net/app-layer/mqtt/mqtt.c index e73ddb425..9571244d8 100644 --- a/os/net/app-layer/mqtt/mqtt.c +++ b/os/net/app-layer/mqtt/mqtt.c @@ -881,7 +881,11 @@ parse_publish_vhdr(struct mqtt_connection *conn, conn->in_packet.topic_len |= input_data_ptr[(*pos)++]; conn->in_packet.byte_counter++; conn->in_packet.topic_len_received = 1; - + /* Abort if topic is longer than our topic buffer */ + if(conn->in_packet.topic_len > MQTT_MAX_TOPIC_LENGTH) { + DBG("MQTT - topic too long %u/%u\n", conn->in_packet.topic_len, MQTT_MAX_TOPIC_LENGTH); + return; + } DBG("MQTT - Read PUBLISH topic len %i\n", conn->in_packet.topic_len); /* WARNING: Check here if TOPIC fits in payload area, otherwise error */ } From 963c2d57aa63fa5421cf30698485bd4ba20e06aa Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 15 Oct 2018 15:54:11 +0200 Subject: [PATCH 028/184] Json library: fix a number of potential buffer overflows --- os/lib/json/jsonparse.c | 98 ++++++++++++++++++++++------------------- os/lib/json/jsontree.c | 10 ++++- 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/os/lib/json/jsonparse.c b/os/lib/json/jsonparse.c index 6277b56c4..941420521 100644 --- a/os/lib/json/jsonparse.c +++ b/os/lib/json/jsonparse.c @@ -32,34 +32,42 @@ #include "jsonparse.h" #include #include +#include /*--------------------------------------------------------------------*/ -static int +static bool push(struct jsonparse_state *state, char c) { - state->stack[state->depth] = c; - state->depth++; - state->vtype = 0; - return state->depth < JSONPARSE_MAX_DEPTH; + if(state->depth < JSONPARSE_MAX_DEPTH) { + state->stack[state->depth] = c; + state->depth++; + state->vtype = 0; + return true; + } else { + return false; + } } /*--------------------------------------------------------------------*/ -static void +static bool modify(struct jsonparse_state *state, char c) { if(state->depth > 0) { state->stack[state->depth - 1] = c; + return true; + } else { + return false; } } /*--------------------------------------------------------------------*/ -static char +static bool pop(struct jsonparse_state *state) { if(state->depth == 0) { - return JSON_TYPE_ERROR; + return false; } state->depth--; state->vtype = state->stack[state->depth]; - return state->stack[state->depth]; + return true; } /*--------------------------------------------------------------------*/ /* will pass by the value and store the start and length of the value for @@ -134,15 +142,11 @@ skip_ws(struct jsonparse_state *state) } } /*--------------------------------------------------------------------*/ -static int +static bool is_atomic(struct jsonparse_state *state) { char v = state->vtype; - if(v == 'N' || v == '"' || v == '0' || v == 'n' || v == 't' || v == 'f') { - return 1; - } else { - return 0; - } + return v == 'N' || v == '"' || v == '0' || v == 'n' || v == 't' || v == 'f'; } /*--------------------------------------------------------------------*/ void @@ -163,6 +167,7 @@ jsonparse_next(struct jsonparse_state *state) char c; char s; char v; + bool ret; skip_ws(state); c = state->json[state->pos]; @@ -173,48 +178,51 @@ jsonparse_next(struct jsonparse_state *state) switch(c) { case '{': if((s == 0 && v == 0) || s == '[' || s == ':') { - push(state, c); - } else { - state->error = JSON_ERROR_UNEXPECTED_OBJECT; - return JSON_TYPE_ERROR; + if(push(state, c)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_OBJECT; + return JSON_TYPE_ERROR; case '}': if((s == ':' && v != ',' && v != 0 ) || (s == '{' && v == 0)) { - pop(state); - } else { - state->error = JSON_ERROR_UNEXPECTED_END_OF_OBJECT; - return JSON_TYPE_ERROR; + if(pop(state)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_END_OF_OBJECT; + return JSON_TYPE_ERROR; case ']': if(s == '[' && v != ',') { - pop(state); - } else { - state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY; - return JSON_TYPE_ERROR; + if(pop(state)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY; + return JSON_TYPE_ERROR; case ':': if(s == '{' && v == 'N') { - modify(state, ':'); + ret = modify(state, ':'); state->vtype = 0; - } else { - state->error = JSON_ERROR_SYNTAX; - return JSON_TYPE_ERROR; + if(ret) { + return jsonparse_next(state); + } } - return jsonparse_next(state); + state->error = JSON_ERROR_SYNTAX; + return JSON_TYPE_ERROR; case ',': if(s == ':' && v != 0) { - modify(state, '{'); + ret = modify(state, '{'); state->vtype = c; + if(ret) { + return c; + } } else if(s == '[') { state->vtype = c; - } else { - state->error = JSON_ERROR_SYNTAX; - return JSON_TYPE_ERROR; + return c; } - return c; + state->error = JSON_ERROR_SYNTAX; + return JSON_TYPE_ERROR; case '"': if((s == 0 && v == 0) || s == '{' || s == '[' || s == ':') { return atomic(state, c = (s == '{' ? JSON_TYPE_PAIR_NAME : c)); @@ -225,12 +233,12 @@ jsonparse_next(struct jsonparse_state *state) return c; case '[': if((s == 0 && v == 0) || s == '[' || s == ':') { - push(state, c); - } else { - state->error = JSON_ERROR_UNEXPECTED_ARRAY; - return JSON_TYPE_ERROR; + if(push(state, c)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_ARRAY; + return JSON_TYPE_ERROR; case 0: if(v == 0 || state->depth > 0) { state->error = JSON_ERROR_SYNTAX; diff --git a/os/lib/json/jsontree.c b/os/lib/json/jsontree.c index 13d7d8604..259525376 100644 --- a/os/lib/json/jsontree.c +++ b/os/lib/json/jsontree.c @@ -198,7 +198,10 @@ jsontree_print_next(struct jsontree_context *js_ctx) } else { ov = o->values[index]; } - /* TODO check max depth */ + if(js_ctx->depth >= JSONTREE_MAX_DEPTH - 1) { + /* Too deep: return 0 */ + return 0; + } js_ctx->depth++; /* step down to value... */ js_ctx->index[js_ctx->depth] = 0; /* and init index */ js_ctx->values[js_ctx->depth] = ov; @@ -299,7 +302,10 @@ find_next(struct jsontree_context *js_ctx) } else { ov = o->values[index]; } - /* TODO check max depth */ + if(js_ctx->depth >= JSONTREE_MAX_DEPTH - 1) { + /* Too deep: return NULL */ + return NULL; + } js_ctx->depth++; /* step down to value... */ js_ctx->index[js_ctx->depth] = 0; /* and init index */ js_ctx->values[js_ctx->depth] = ov; From f9134b11985729a84c2722a2321de3c9479b13b6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 16 Oct 2018 09:23:54 +0200 Subject: [PATCH 029/184] Add mising TSCH constants for platforms openmote-cc2528 and cc2538dk --- arch/cpu/cc2538/cc2538-def.h | 8 +++++--- arch/platform/cc2538dk/dev/board.h | 12 ++++++++++++ arch/platform/openmote-cc2538/board.h | 12 ++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/cpu/cc2538/cc2538-def.h b/arch/cpu/cc2538/cc2538-def.h index 163456a14..defa4ecb0 100644 --- a/arch/cpu/cc2538/cc2538-def.h +++ b/arch/cpu/cc2538/cc2538-def.h @@ -36,11 +36,13 @@ /*---------------------------------------------------------------------------*/ #define RTIMER_ARCH_SECOND 32768 /*---------------------------------------------------------------------------*/ +#define CC2538_PHY_OVERHEAD 3 +#define CC2538_BYTE_AIR_TIME 32 /* 352us from calling transmit() until the SFD byte has been sent */ -#define CC2538_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352)) +#define CC2538_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352)) /* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */ -#define CC2538_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250)) -#define CC2538_DELAY_BEFORE_DETECT 0 +#define CC2538_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250)) +#define CC2538_DELAY_BEFORE_DETECT 0 /* Frame filtering done in software */ #define TSCH_CONF_HW_FRAME_FILTERING 0 diff --git a/arch/platform/cc2538dk/dev/board.h b/arch/platform/cc2538dk/dev/board.h index 80f036fd7..2540b7ce7 100644 --- a/arch/platform/cc2538dk/dev/board.h +++ b/arch/platform/cc2538dk/dev/board.h @@ -220,6 +220,18 @@ #endif /* #if SPI1_IN_USE */ /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name CC2538 TSCH configuration + * + * @{ + */ +#define RADIO_PHY_OVERHEAD CC2538_PHY_OVERHEAD +#define RADIO_BYTE_AIR_TIME CC2538_BYTE_AIR_TIME +#define RADIO_DELAY_BEFORE_TX CC2538_DELAY_BEFORE_TX +#define RADIO_DELAY_BEFORE_RX CC2538_DELAY_BEFORE_RX +#define RADIO_DELAY_BEFORE_DETECT CC2538_DELAY_BEFORE_DETECT +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/openmote-cc2538/board.h b/arch/platform/openmote-cc2538/board.h index abb89b8e2..6e2a15e46 100644 --- a/arch/platform/openmote-cc2538/board.h +++ b/arch/platform/openmote-cc2538/board.h @@ -174,6 +174,18 @@ #define I2C_SDA_PIN 4 /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name CC2538 TSCH configuration + * + * @{ + */ +#define RADIO_PHY_OVERHEAD CC2538_PHY_OVERHEAD +#define RADIO_BYTE_AIR_TIME CC2538_BYTE_AIR_TIME +#define RADIO_DELAY_BEFORE_TX CC2538_DELAY_BEFORE_TX +#define RADIO_DELAY_BEFORE_RX CC2538_DELAY_BEFORE_RX +#define RADIO_DELAY_BEFORE_DETECT CC2538_DELAY_BEFORE_DETECT +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ From 5717fedc13fc0b7fa8d2afdaac736d4a80628c72 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 16 Oct 2018 09:33:50 +0200 Subject: [PATCH 030/184] Add CI compile tests for 6tisch on platforms openmote-cc2538, cc2538dk, and sky --- tests/01-compile-base/Makefile | 2 ++ tests/02-compile-arm-ports-01/Makefile | 2 ++ tests/03-compile-arm-ports-02/Makefile | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index e51ff523b..09f89418d 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -24,6 +24,8 @@ rpl-border-router/sky \ slip-radio/sky \ libs/ipv6-hooks/sky \ nullnet/native \ +nullnet/sky \ +nullnet/sky:MAKE_MAC=MAKE_MAC_TSCH \ mqtt-client/native \ coap/coap-example-client/native \ coap/coap-example-server/native \ diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 2ec2ce443..aaebab164 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -89,6 +89,8 @@ platform-specific/cc2538-common/pka/cc2538dk \ hello-world/cc2538dk \ rpl-border-router/cc2538dk \ rpl-border-router/cc2538dk:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +6tisch/simple-node/cc2538dk \ +6tisch/simple-node/cc2538dk:MAKE_WITH_SECURITY=1,MAKE_WITH_ORCHESTRA=1 \ hello-world/nrf52dk \ platform-specific/nrf52dk/coap-demo/coap-server/nrf52dk \ platform-specific/nrf52dk/coap-demo/coap-client/nrf52dk:SERVER_IPV6_EP=ffff \ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index 190d36e4d..950888f06 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -68,6 +68,8 @@ libs/ipv6-hooks/openmote-cc2538 \ libs/shell/openmote-cc2538 \ libs/simple-energest/openmote-cc2538 \ libs/deployment/openmote-cc2538 \ +6tisch/simple-node/openmote-cc2538 \ +6tisch/simple-node/openmote-cc2538:MAKE_WITH_SECURITY=1,MAKE_WITH_ORCHESTRA=1 \ TOOLS= From 7ab140c55e9c58c487612f2b2f12bd2bd7690208 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 16 Oct 2018 15:17:54 +0200 Subject: [PATCH 031/184] Added missing 'extern' qualifier to tsch_timing_us --- os/net/mac/tsch/tsch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index 8590dcb38..db23b4851 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -158,7 +158,7 @@ extern uint8_t tsch_current_channel; extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN]; extern struct tsch_asn_divisor_t tsch_hopping_sequence_length; /* TSCH timeslot timing (in micro-second) */ -uint16_t tsch_timing_us[tsch_ts_elements_count]; +extern uint16_t tsch_timing_us[tsch_ts_elements_count]; /* TSCH timeslot timing (in rtimer ticks) */ extern rtimer_clock_t tsch_timing[tsch_ts_elements_count]; /* Statistics on the current session */ From d45ee85867c416c3dff3d6462214d4a885d444aa Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 16 Oct 2018 15:19:59 +0200 Subject: [PATCH 032/184] Add CI compile test for TSCH with logging --- tests/03-compile-arm-ports-02/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index 950888f06..655967e1b 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -28,6 +28,7 @@ storage/antelope-shell/zoul \ 6tisch/simple-node/zoul:MAKE_WITH_ORCHESTRA=1 \ 6tisch/simple-node/zoul:MAKE_WITH_SECURITY=1 \ libs/logging/zoul \ +libs/logging/zoul:MAKE_MAC=MAKE_MAC_TSCH \ 6tisch/etsi-plugtest-2017/zoul:BOARD=remote \ 6tisch/6p-packet/zoul \ 6tisch/sixtop/zoul \ From 1cdd4ffb124f936c499a751ffc750790244148fd Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 17:00:40 +0100 Subject: [PATCH 033/184] Move the help and usage targets to a separate Makefile --- Makefile.help | 29 +++++++++++++++++++++++++++++ Makefile.include | 29 +---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 Makefile.help 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) From 882bfd083d1307811fbaaa92eb987aa517eef44a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 17:02:20 +0100 Subject: [PATCH 034/184] Delete the zolertia-specific motelist --- tools/zolertia/license-bsl.txt | 62 ------ tools/zolertia/motelist-zolertia | 295 ------------------------- tools/zolertia/motelist-zolertia-macos | 75 ------- 3 files changed, 432 deletions(-) delete mode 100644 tools/zolertia/license-bsl.txt delete mode 100755 tools/zolertia/motelist-zolertia delete mode 100755 tools/zolertia/motelist-zolertia-macos 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 ); - } - } -} From 5ec90633140e65cc28457995a5947ba7a3e6009f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 17:02:59 +0100 Subject: [PATCH 035/184] Add board search strings for Zolertia devices --- arch/platform/zoul/firefly-reva/Makefile.firefly-reva | 2 +- arch/platform/zoul/firefly/Makefile.firefly | 2 +- arch/platform/zoul/orion/Makefile.orion | 2 +- arch/platform/zoul/remote-reva/Makefile.remote-reva | 2 +- arch/platform/zoul/remote-revb/Makefile.remote-revb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) 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 From 470ac26c4e9e7b3fa5aeed0841dba37092f300e8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 17:03:55 +0100 Subject: [PATCH 036/184] Add the motelist-all target - common for all embedded platforms --- Makefile.embedded | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) From 95cebf10bcad42e1c1b2ff111266966e7f5bfe1b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 17:10:50 +0100 Subject: [PATCH 037/184] Change platform zoul to use the new motelist --- arch/platform/zoul/Makefile.zoul | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) 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) From b56ff259dca10d2f51c8e2dd6016138d87a21d5f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 09:13:42 +0200 Subject: [PATCH 038/184] uIP: remove leftover IPv4 code --- os/contiki-net.h | 2 - os/net/app-layer/coap/coap-uip.c | 4 -- os/net/ipv6/uip-nameserver.c | 6 +-- os/net/ipv6/uip.h | 91 +------------------------------- os/net/ipv6/uiplib.c | 2 - os/net/ipv6/uiplib.h | 4 -- os/net/ipv6/uipopt.h | 5 -- 7 files changed, 2 insertions(+), 112 deletions(-) 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/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index e2be92326..1e817e657 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -79,11 +79,7 @@ /* 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; 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.h b/os/net/ipv6/uip.h index 9f5eb159d..e31e80201 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -65,7 +65,7 @@ #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 @@ -76,8 +76,6 @@ #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*/ - #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" @@ -100,12 +98,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 +1041,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 @@ -1320,18 +1309,11 @@ extern uint16_t uip_urglen, uip_surglen; * 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 +1476,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*/ }; @@ -1621,7 +1601,6 @@ void uip_process(uint8_t flag); /* The TCP and IP headers. */ struct uip_tcpip_hdr { -#if NETSTACK_CONF_WITH_IPV6 /* IPv6 header. */ uint8_t vtc, tcflow; @@ -1629,18 +1608,6 @@ struct uip_tcpip_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 */ /* TCP header. */ uint16_t srcport, @@ -1657,7 +1624,6 @@ struct uip_tcpip_hdr { /* The ICMP and IP headers. */ struct uip_icmpip_hdr { -#if NETSTACK_CONF_WITH_IPV6 /* IPv6 header. */ uint8_t vtc, tcf; @@ -1665,32 +1631,15 @@ struct uip_icmpip_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 */ /* 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; @@ -1698,18 +1647,6 @@ struct uip_udpip_hdr { 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, @@ -1725,7 +1662,6 @@ struct uip_udpip_hdr { */ /* The IP header */ struct uip_ip_hdr { -#if NETSTACK_CONF_WITH_IPV6 /* IPV6 header */ uint8_t vtc; uint8_t tcflow; @@ -1733,18 +1669,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 +1784,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 */ }; @@ -1898,7 +1819,6 @@ struct uip_udp_hdr { #define UIP_PROTO_ICMP6 58 -#if NETSTACK_CONF_WITH_IPV6 /** @{ */ /** \brief extension headers types */ #define UIP_PROTO_HBHO 0 @@ -1937,9 +1857,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 +1871,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 +2087,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. 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..f01689f4f 100644 --- a/os/net/ipv6/uipopt.h +++ b/os/net/ipv6/uipopt.h @@ -248,11 +248,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 From ee5b722c6590c672519a24e152d121cb310e420c Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 09:17:41 +0200 Subject: [PATCH 039/184] uip.h: removed unused define --- os/net/ipv6/uip.h | 1 - 1 file changed, 1 deletion(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index e31e80201..5e72ba844 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -74,7 +74,6 @@ */ #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) #include "net/ipv6/uipopt.h" From caa02ae51e2e81d479f613f6bd5463b51f2a2db2 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 09:24:52 +0200 Subject: [PATCH 040/184] Define UIP_IP_BUF globally in uip.h --- examples/libs/ipv6-hooks/ipv6-hooks.c | 2 -- examples/multicast/sink.c | 2 -- .../jn516x/tsch/simple-sensor-network/node/node.c | 2 -- os/net/app-layer/coap/coap-uip.c | 1 - os/net/ipv6/multicast/esmrf.c | 1 - os/net/ipv6/multicast/roll-tm.c | 1 - os/net/ipv6/multicast/smrf.c | 4 ---- os/net/ipv6/sicslowpan.c | 2 -- os/net/ipv6/simple-udp.c | 12 ++++++------ os/net/ipv6/tcpip.c | 1 - os/net/ipv6/udp-socket.c | 11 +++++------ os/net/ipv6/uip-icmp6.c | 1 - os/net/ipv6/uip-nd6.c | 1 - os/net/ipv6/uip.h | 5 +++++ os/net/ipv6/uip6.c | 1 - os/net/routing/rpl-classic/rpl-ext-header.c | 1 - os/net/routing/rpl-classic/rpl-icmp6.c | 1 - os/net/routing/rpl-classic/rpl-nbr-policy.c | 1 - os/net/routing/rpl-lite/rpl-ext-header.c | 1 - os/net/routing/rpl-lite/rpl-icmp6.c | 1 - os/net/routing/rpl-lite/rpl-nbr-policy.c | 1 - os/services/ip64/ip64-eth-interface.c | 2 -- os/services/ip64/ip64-slip-interface.c | 8 +++----- os/services/rpl-border-router/embedded/slip-bridge.c | 2 -- tools/sky/uip6-bridge/fakeuip.c | 2 -- tools/sky/uip6-bridge/sicslow_ethernet.c | 1 - tools/sky/uip6-bridge/uip6-bridge-tap.c | 2 -- 27 files changed, 19 insertions(+), 51 deletions(-) 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/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/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/os/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index 1e817e657..3c9347bc6 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -78,7 +78,6 @@ #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]) #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #ifdef WITH_DTLS diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index 5b6f1b863..edbc32b16 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -105,7 +105,6 @@ 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]) diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 1d19512d6..20a681fc5 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -461,7 +461,6 @@ static uint16_t last_seq; #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]) extern uint16_t uip_slen; diff --git a/os/net/ipv6/multicast/smrf.c b/os/net/ipv6/multicast/smrf.c index 86a053648..bb23b060b 100644 --- a/os/net/ipv6/multicast/smrf.c +++ b/os/net/ipv6/multicast/smrf.c @@ -77,10 +77,6 @@ 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) { diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 9e4e3a8b4..b5c23a3be 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -121,8 +121,6 @@ #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]) diff --git a/os/net/ipv6/simple-udp.c b/os/net/ipv6/simple-udp.c index c98107c99..49aab96dc 100644 --- a/os/net/ipv6/simple-udp.c +++ b/os/net/ipv6/simple-udp.c @@ -52,7 +52,7 @@ 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]) +#define UIP_UDPIP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) /*---------------------------------------------------------------------------*/ static void @@ -134,7 +134,7 @@ PROCESS_THREAD(simple_udp_process, ev, data) { struct simple_udp_connection *c; PROCESS_BEGIN(); - + while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { @@ -164,10 +164,10 @@ PROCESS_THREAD(simple_udp_process, ev, data) if(c->receive_callback != NULL) { PROCESS_CONTEXT_BEGIN(c->client_process); c->receive_callback(c, - &(UIP_IP_BUF->srcipaddr), - UIP_HTONS(UIP_IP_BUF->srcport), - &(UIP_IP_BUF->destipaddr), - UIP_HTONS(UIP_IP_BUF->destport), + &(UIP_UDPIP_BUF->srcipaddr), + UIP_HTONS(UIP_UDPIP_BUF->srcport), + &(UIP_UDPIP_BUF->destipaddr), + UIP_HTONS(UIP_UDPIP_BUF->destport), databuffer, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 8d546c1d7..740054010 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -56,7 +56,6 @@ #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 diff --git a/os/net/ipv6/udp-socket.c b/os/net/ipv6/udp-socket.c index 700306ca1..11126fedc 100644 --- a/os/net/ipv6/udp-socket.c +++ b/os/net/ipv6/udp-socket.c @@ -38,8 +38,7 @@ 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]) - +#define UIP_UDPIP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) /*---------------------------------------------------------------------------*/ static void @@ -181,10 +180,10 @@ PROCESS_THREAD(udp_socket_process, ev, data) if(c->input_callback != NULL) { PROCESS_CONTEXT_BEGIN(c->p); c->input_callback(c, c->ptr, - &(UIP_IP_BUF->srcipaddr), - UIP_HTONS(UIP_IP_BUF->srcport), - &(UIP_IP_BUF->destipaddr), - UIP_HTONS(UIP_IP_BUF->destport), + &(UIP_UDPIP_BUF->srcipaddr), + UIP_HTONS(UIP_UDPIP_BUF->srcport), + &(UIP_UDPIP_BUF->destipaddr), + UIP_HTONS(UIP_UDPIP_BUF->destport), buf, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 707a13309..13d03a859 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -53,7 +53,6 @@ #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]) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 63ae46b47..d3e50bdcf 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -94,7 +94,6 @@ * 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]) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 5e72ba844..fa3bdbd98 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -76,6 +76,11 @@ #define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) #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[UIP_LLH_LEN]) + #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" #include "net/linkaddr.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index dfbec52b7..5b86de266 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -142,7 +142,6 @@ uint8_t uip_ext_opt_offset = 0; * @{ */ #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]) diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 8488d5ac6..18ebfa3a8 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -61,7 +61,6 @@ #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]) diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index a246e576e..ed0bde02a 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -70,7 +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]) /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/rpl-classic/rpl-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c index 344840d0e..f6b26bae2 100644 --- a/os/net/routing/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -65,7 +65,6 @@ * 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 */ diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index af67cdaff..414a93104 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -54,7 +54,6 @@ #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]) diff --git a/os/net/routing/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index be5ea2948..f369b34c7 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -62,7 +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]) diff --git a/os/net/routing/rpl-lite/rpl-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c index 9752b1446..0c542f780 100644 --- a/os/net/routing/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -59,7 +59,6 @@ * 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; diff --git a/os/services/ip64/ip64-eth-interface.c b/os/services/ip64/ip64-eth-interface.c index 1dcaeb5ad..d70b7576a 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(...) diff --git a/os/services/ip64/ip64-slip-interface.c b/os/services/ip64/ip64-slip-interface.c index 10422f2c7..665a342d9 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" @@ -88,12 +86,12 @@ input_callback(void) } uip_clear_buf(); } 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_LLH_LEN], uip_len, ip64_packet_buffer); if(len > 0) { memcpy(&uip_buf[UIP_LLH_LEN], ip64_packet_buffer, 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..ff980ea69 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" diff --git a/tools/sky/uip6-bridge/fakeuip.c b/tools/sky/uip6-bridge/fakeuip.c index 84f6440ce..86658429a 100644 --- a/tools/sky/uip6-bridge/fakeuip.c +++ b/tools/sky/uip6-bridge/fakeuip.c @@ -8,8 +8,6 @@ #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; diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 7217e3229..317c7abe8 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -155,7 +155,6 @@ //#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 diff --git a/tools/sky/uip6-bridge/uip6-bridge-tap.c b/tools/sky/uip6-bridge/uip6-bridge-tap.c index 694499b6d..19ce22a6f 100644 --- a/tools/sky/uip6-bridge/uip6-bridge-tap.c +++ b/tools/sky/uip6-bridge/uip6-bridge-tap.c @@ -48,8 +48,6 @@ #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); From 1bd9ac781b8e869b5862348583148eb7efaba5a0 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 09:42:24 +0200 Subject: [PATCH 041/184] Define ICMP, UDP, and TCP buffer pointers globally in uip.h --- os/net/ipv6/multicast/esmrf.c | 6 ------ os/net/ipv6/multicast/roll-tm.c | 3 --- os/net/ipv6/resolv.c | 4 +--- os/net/ipv6/sicslowpan.c | 16 +++++++--------- os/net/ipv6/tcpip.c | 3 --- os/net/ipv6/uip-icmp6.c | 1 - os/net/ipv6/uip-nd6.c | 1 - os/net/ipv6/uip.h | 10 +++++++++- os/net/ipv6/uip6.c | 3 --- os/net/routing/rpl-classic/rpl-icmp6.c | 2 -- os/net/routing/rpl-lite/rpl-icmp6.c | 3 --- tools/sky/uip6-bridge/sicslow_ethernet.c | 1 - 12 files changed, 17 insertions(+), 36 deletions(-) diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index edbc32b16..d72d99fad 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -103,12 +103,6 @@ static struct uip_udp_conn *c; static uip_ipaddr_t src_ip; static uip_ipaddr_t des_ip; /*---------------------------------------------------------------------------*/ -/* uIPv6 Pointers */ -/*---------------------------------------------------------------------------*/ -#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); diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 20a681fc5..a8dee46a6 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -457,12 +457,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_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]) extern uint16_t uip_slen; /*---------------------------------------------------------------------------*/ /* Local function prototypes */ 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 b5c23a3be..2a1a9f34f 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -121,10 +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_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_LLIPH_LEN + (pos)]) +#define UIP_UDP_BUF_POS(pos) ((struct uip_udp_hdr *)UIP_IPPAYLOAD_BUF_POS(pos)) /** @} */ @@ -464,9 +462,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; @@ -917,7 +915,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 */ @@ -956,7 +954,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 */ diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 740054010..b7a10de9a 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -55,9 +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_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) - #ifdef UIP_FALLBACK_INTERFACE extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE; #endif diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 13d03a859..193c02aa4 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -53,7 +53,6 @@ #define LOG_MODULE "ICMPv6" #define LOG_LEVEL LOG_LEVEL_IPV6 -#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]) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index d3e50bdcf..b2a17ff1d 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -94,7 +94,6 @@ * value of these length variables */ -#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]) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index fa3bdbd98..556a3e4be 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -79,7 +79,15 @@ /** * Direct access to IPv6 header */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +/** + * Direct access to ICMP, UDP, and TCP headers and payload + */ +#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_l2_l3_hdr_len]) +#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 5b86de266..0a6153a2a 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -142,9 +142,6 @@ uint8_t uip_ext_opt_offset = 0; * @{ */ #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) -#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]) diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index ed0bde02a..5230ab4e4 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -70,8 +70,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#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); diff --git a/os/net/routing/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index f369b34c7..260f9b168 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -62,9 +62,6 @@ #define RPL_DIO_MOP_MASK 0x38 #define RPL_DIO_PREFERENCE_MASK 0x07 -#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); diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 317c7abe8..0b241d71b 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -379,7 +379,6 @@ typedef struct { 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); From 2f9b60215e5b4de40126943acd661ad98ad82610 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 11:22:05 +0200 Subject: [PATCH 042/184] Removing tcpip and udpip data strcutures, unsafe in cases with IPv6 extension headers --- arch/platform/jn516x/slip.c | 1 - os/net/ipv6/simple-udp.c | 10 +++--- os/net/ipv6/udp-socket.c | 10 +++--- os/net/ipv6/uip.h | 56 -------------------------------- os/net/ipv6/uip6.c | 2 +- tools/sky/uip6-bridge/dev/slip.c | 1 - 6 files changed, 9 insertions(+), 71 deletions(-) diff --git a/arch/platform/jn516x/slip.c b/arch/platform/jn516x/slip.c index 173a14d60..572d9f71c 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" diff --git a/os/net/ipv6/simple-udp.c b/os/net/ipv6/simple-udp.c index 49aab96dc..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_UDPIP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - /*---------------------------------------------------------------------------*/ static void init_simple_udp(void) @@ -164,10 +162,10 @@ PROCESS_THREAD(simple_udp_process, ev, data) if(c->receive_callback != NULL) { PROCESS_CONTEXT_BEGIN(c->client_process); c->receive_callback(c, - &(UIP_UDPIP_BUF->srcipaddr), - UIP_HTONS(UIP_UDPIP_BUF->srcport), - &(UIP_UDPIP_BUF->destipaddr), - UIP_HTONS(UIP_UDPIP_BUF->destport), + &(UIP_IP_BUF->srcipaddr), + UIP_HTONS(UIP_UDP_BUF->srcport), + &(UIP_IP_BUF->destipaddr), + UIP_HTONS(UIP_UDP_BUF->destport), databuffer, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/udp-socket.c b/os/net/ipv6/udp-socket.c index 11126fedc..f104a6b6c 100644 --- a/os/net/ipv6/udp-socket.c +++ b/os/net/ipv6/udp-socket.c @@ -38,8 +38,6 @@ PROCESS(udp_socket_process, "UDP socket process"); static uint8_t buf[UIP_BUFSIZE]; -#define UIP_UDPIP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) - /*---------------------------------------------------------------------------*/ static void init(void) @@ -180,10 +178,10 @@ PROCESS_THREAD(udp_socket_process, ev, data) if(c->input_callback != NULL) { PROCESS_CONTEXT_BEGIN(c->p); c->input_callback(c, c->ptr, - &(UIP_UDPIP_BUF->srcipaddr), - UIP_HTONS(UIP_UDPIP_BUF->srcport), - &(UIP_UDPIP_BUF->destipaddr), - UIP_HTONS(UIP_UDPIP_BUF->destport), + &(UIP_IP_BUF->srcipaddr), + UIP_HTONS(UIP_UDP_BUF->srcport), + &(UIP_IP_BUF->destipaddr), + UIP_HTONS(UIP_UDP_BUF->destport), buf, uip_datalen()); PROCESS_CONTEXT_END(); } diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 556a3e4be..255eeb1a5 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -1611,62 +1611,6 @@ void uip_process(uint8_t flag); #define UIP_STOPPED 16 -/* The TCP and IP headers. */ -struct uip_tcpip_hdr { - /* IPv6 header. */ - uint8_t vtc, - tcflow; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - - /* 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 { - /* IPv6 header. */ - uint8_t vtc, - tcf; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - - /* ICMP header. */ - uint8_t type, icode; - uint16_t icmpchksum; -}; - - -/* The UDP and IP headers. */ -struct uip_udpip_hdr { - /* IPv6 header. */ - uint8_t vtc, - tcf; - uint16_t flow; - uint8_t len[2]; - uint8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - - /* 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 diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 0a6153a2a..615a658dc 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -141,7 +141,7 @@ uint8_t uip_ext_opt_offset = 0; * \name Buffer defines * @{ */ -#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) +#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0]) #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]) diff --git a/tools/sky/uip6-bridge/dev/slip.c b/tools/sky/uip6-bridge/dev/slip.c index e8062e515..7cde6437d 100644 --- a/tools/sky/uip6-bridge/dev/slip.c +++ b/tools/sky/uip6-bridge/dev/slip.c @@ -38,7 +38,6 @@ #include "contiki.h" #include "net/ipv6/uip.h" -#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) #include "dev/slip.h" From 86e9790e6e0181e66605deb5f814e9013331af67 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 11:43:34 +0200 Subject: [PATCH 043/184] Minor improvement to uip.h --- os/net/ipv6/uip.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 255eeb1a5..35f0d9cfd 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -84,10 +84,11 @@ /** * Direct access to ICMP, UDP, and TCP headers and payload */ -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) +#define UIP_IP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_hdr_len]) +#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)UIP_IP_PAYLOAD) #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_l2_l3_hdr_len]) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) +#define UIP_UDP_BUF ((struct uip_udp_hdr *)UIP_IP_PAYLOAD) +#define UIP_TCP_BUF ((struct uip_tcp_hdr *)UIP_IP_PAYLOAD) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" From 59852d33f224ba6bd17d0b1a267e0fc90efe4ec7 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 11:57:56 +0200 Subject: [PATCH 044/184] Use global uip.h buffer definitions in a number of other modules --- arch/cpu/msp430/uip-ipchksum.c | 2 +- os/net/app-layer/coap/coap-uip.c | 3 --- os/net/ipv6/uip-icmp6.c | 2 +- os/net/ipv6/uip-nd6.c | 8 ++++---- 4 files changed, 6 insertions(+), 9 deletions(-) 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/os/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index 3c9347bc6..2435b9d2d 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -77,9 +77,6 @@ #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_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) - #ifdef WITH_DTLS static dtls_handler_t cb; static dtls_context_t *dtls_context = NULL; diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 193c02aa4..de9cc2394 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -53,7 +53,7 @@ #define LOG_MODULE "ICMPv6" #define LOG_LEVEL LOG_LEVEL_IPV6 -#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len]) +#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD) #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]) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index b2a17ff1d..446ad8346 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -95,10 +95,10 @@ */ /**@{ 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]) From a528395eb28c90731298f5ddb762f5547b5dfd4b Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 11:58:51 +0200 Subject: [PATCH 045/184] roll-tm.c: removing unused define --- os/net/ipv6/multicast/roll-tm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index a8dee46a6..3e1d14b5b 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -456,7 +456,6 @@ 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_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]) From 4035d840ddab6e44f68d0dd97d6551b50114bce9 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 15:57:39 +0200 Subject: [PATCH 046/184] Rework uip.h buffer definitions --- os/net/ipv6/uip.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 35f0d9cfd..213081a91 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -79,16 +79,19 @@ /** * Direct access to IPv6 header */ -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf + UIP_LLH_LEN) +#define UIP_IP_BUF ((struct uip_ip_hdr *)UIP_IP_BUF_CHAR) +#define UIP_IP_PAYLOAD(ext) ((unsigned char *)UIP_IP_BUF_CHAR + UIP_IPH_LEN + (ext)) /** - * Direct access to ICMP, UDP, and TCP headers and payload + * Direct access to ICMP, UDP, and TCP headers and payload, with implicit ext header offset */ -#define UIP_IP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_hdr_len]) -#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)UIP_IP_PAYLOAD) -#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)UIP_IP_PAYLOAD) -#define UIP_TCP_BUF ((struct uip_tcp_hdr *)UIP_IP_PAYLOAD) +#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" From 8152342c11e2ee3af53633fd8288e5ee8454ac4c Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 16:32:00 +0200 Subject: [PATCH 047/184] Rework uIP6 extension header access --- os/net/ipv6/uip-icmp6.c | 3 +- os/net/ipv6/uip.h | 9 +++ os/net/ipv6/uip6.c | 40 ++++++------- os/net/routing/rpl-classic/rpl-ext-header.c | 63 ++++++++++----------- os/net/routing/rpl-lite/rpl-ext-header.c | 63 ++++++++++----------- 5 files changed, 87 insertions(+), 91 deletions(-) diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index de9cc2394..90a53422d 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -54,7 +54,6 @@ #define LOG_LEVEL LOG_LEVEL_IPV6 #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD) -#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]) /** \brief temporary IP address */ @@ -172,7 +171,7 @@ 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) { + if(UIP_EXT_BUF(uip_ext_len)->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { uip_clear_buf(); return; } diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 213081a91..f4ee4dd2b 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -93,6 +93,15 @@ #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) +/** + * Direct access to extension headers, with explicit ext header offset + */ +#define UIP_EXT_BUF(ext) ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(ext)) +#define UIP_HBHO_BUF(ext) ((struct uip_hbho_hdr *)UIP_IP_PAYLOAD(ext)) +#define UIP_RH_BUF(ext) ((struct uip_routing_hdr *)UIP_IP_PAYLOAD(ext)) +#define UIP_FRAG_BUF(ext) ((struct uip_frag_hdr *)UIP_IP_PAYLOAD(ext)) +#define UIP_DESTO_BUF(ext) ((struct uip_desto_hdr *)UIP_IP_PAYLOAD(ext)) + #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" #include "net/linkaddr.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 615a658dc..943791311 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -142,14 +142,8 @@ uint8_t uip_ext_opt_offset = 0; * @{ */ #define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0]) -#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]) /** @} */ /** * \name Buffer variables @@ -520,7 +514,7 @@ remove_ext_hdr(void) } last_uip_ext_len = uip_ext_len; uip_ext_len = 0; - UIP_IP_BUF->proto = UIP_EXT_BUF->next; + UIP_IP_BUF->proto = UIP_EXT_BUF(uip_ext_len)->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); @@ -658,7 +652,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 = UIP_FRAG_BUF(uip_ext_len)->id; /* Clear the bitmap. */ memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap)); } @@ -669,9 +663,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) { + UIP_FRAG_BUF(uip_ext_len)->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(UIP_FRAG_BUF(uip_ext_len)->offsetresmore) & 0xfff8); /* in byte, originaly in multiple of 8 bytes*/ LOG_INFO("len %d\n", len); LOG_INFO("offset %d\n", offset); @@ -682,7 +676,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; + *uip_next_hdr = UIP_FRAG_BUF(uip_ext_len)->next; memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN); LOG_INFO("src "); LOG_INFO_6ADDR(&FBUF->srcipaddr); @@ -703,7 +697,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(UIP_FRAG_BUF(uip_ext_len)->offsetresmore) & IP_MF) == 0) { uip_reassflags |= UIP_REASS_FLAG_LASTFRAG; /*calculate the size of the entire packet*/ uip_reasslen = offset + len; @@ -727,7 +721,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 *)UIP_FRAG_BUF(uip_ext_len) + UIP_FRAGH_LEN, len); /* Update the bitmap. */ if(offset >> 6 == (offset + len) >> 6) { @@ -844,7 +838,7 @@ ext_hdr_options_process(void) * 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)) { + while(uip_ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) { switch(UIP_EXT_HDR_OPT_BUF->type) { /* * for now we do not support any options except padding ones @@ -1150,8 +1144,8 @@ uip_process(uint8_t flag) switch(ext_hdr_options_process()) { case 0: /* continue */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; case 1: LOG_ERR("Dropping packet after extension header processing\n"); @@ -1285,8 +1279,8 @@ uip_process(uint8_t flag) switch(ext_hdr_options_process()) { case 0: /*continue*/ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; case 1: /*silently discard*/ @@ -1314,8 +1308,8 @@ uip_process(uint8_t flag) switch(ext_hdr_options_process()) { case 0: /*continue*/ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; case 1: /*silently discard*/ @@ -1344,7 +1338,7 @@ uip_process(uint8_t flag) */ LOG_DBG("Processing Routing header\n"); - if(UIP_ROUTING_BUF->seg_left > 0) { + if(UIP_RH_BUF(uip_ext_len)->seg_left > 0) { if(NETSTACK_ROUTING.ext_header_srh_update()) { /* With routing header, the detination address is us and will @@ -1378,8 +1372,8 @@ uip_process(uint8_t flag) LOG_ERR("unrecognized routing type"); goto send; } - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; case UIP_PROTO_FRAG: /* Fragmentation header:call the reassembly function, then leave */ diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 18ebfa3a8..ebaa823aa 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -61,10 +61,7 @@ #include /*---------------------------------------------------------------------------*/ -#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]) @@ -80,12 +77,12 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) uip_ds6_route_t *route; rpl_parent_t *sender = NULL; - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + if(UIP_HBHO_BUF(uip_ext_len)->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) { LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n", - UIP_HBHO_BUF->len, + UIP_HBHO_BUF(uip_ext_len)->len, UIP_EXT_HDR_OPT_RPL_BUF->opt_type, UIP_EXT_HDR_OPT_RPL_BUF->opt_len); return 0; /* Drop */ @@ -200,8 +197,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) * header. */ /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: uip_next_hdr = NULL; @@ -214,7 +211,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) 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) || + && UIP_RH_BUF(uip_ext_len)->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. @@ -255,8 +252,8 @@ rpl_ext_header_srh_update(void) * header. */ /* Move to next header */ - uip_next_hdr = &UIP_EXT_BUF->next; - uip_ext_len += (UIP_EXT_BUF->len << 3) + 8; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: uip_next_hdr = NULL; @@ -265,7 +262,7 @@ rpl_ext_header_srh_update(void) } if(uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING - && UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) { + && UIP_RH_BUF(uip_ext_len)->routing_type == RPL_RH_TYPE_SRH) { /* SRH found, now look for next hop */ uint8_t cmpri, cmpre; uint8_t ext_len; @@ -274,8 +271,8 @@ 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; + segments_left = UIP_RH_BUF(uip_ext_len)->seg_left; + ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; padding = UIP_RPL_SRH_BUF->pad >> 4; @@ -289,7 +286,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 *)UIP_RH_BUF(uip_ext_len)) + 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] */ @@ -302,7 +299,7 @@ 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--; + UIP_RH_BUF(uip_ext_len)->seg_left--; LOG_INFO("SRH next hop "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); @@ -428,13 +425,13 @@ insert_srh_header(void) memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); /* Insert source routing header */ - UIP_RH_BUF->next = UIP_IP_BUF->proto; + UIP_RH_BUF(uip_ext_len)->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; + UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8; + UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH; + UIP_RH_BUF(uip_ext_len)->seg_left = path_len; /* Initialize RPL Source Routing Header */ UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; @@ -443,7 +440,7 @@ insert_srh_header(void) /* 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 *)UIP_RH_BUF(uip_ext_len)) + 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); @@ -484,7 +481,7 @@ update_hbh_header(void) uip_ext_opt_offset = 2; 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) + if(UIP_HBHO_BUF(uip_ext_len)->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", @@ -565,16 +562,16 @@ insert_hbh_header(const rpl_instance_t *instance) 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 UIP_EXT_BUF(uip_ext_len) further */ + memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN); + memset(UIP_HBHO_BUF(uip_ext_len), 0, RPL_HOP_BY_HOP_LEN); /* Update IP and HBH protocol and fields */ - UIP_HBHO_BUF->next = UIP_IP_BUF->proto; + UIP_HBHO_BUF(uip_ext_len)->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_HBHO_BUF(uip_ext_len)->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; @@ -612,8 +609,8 @@ rpl_ext_header_remove(void) 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; + *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; + rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->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; @@ -621,10 +618,10 @@ rpl_ext_header_remove(void) 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); + memmove(UIP_EXT_BUF(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; } break; case UIP_PROTO_DESTO: @@ -637,8 +634,8 @@ rpl_ext_header_remove(void) * 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: return; diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 414a93104..ab9e37188 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -54,10 +54,7 @@ #define LOG_LEVEL LOG_LEVEL_RPL /*---------------------------------------------------------------------------*/ -#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]) @@ -84,8 +81,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) * 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: uip_next_hdr = NULL; @@ -101,7 +98,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) 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) || + && UIP_RH_BUF(uip_ext_len)->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. @@ -143,8 +140,8 @@ rpl_ext_header_srh_update(void) * 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: uip_next_hdr = NULL; @@ -153,15 +150,15 @@ rpl_ext_header_srh_update(void) } if(uip_next_hdr == NULL || *uip_next_hdr != UIP_PROTO_ROUTING - || UIP_RH_BUF->routing_type != RPL_RH_TYPE_SRH) { + || UIP_RH_BUF(uip_ext_len)->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; + segments_left = UIP_RH_BUF(uip_ext_len)->seg_left; + ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; padding = UIP_RPL_SRH_BUF->pad >> 4; @@ -176,7 +173,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 *)UIP_RH_BUF(uip_ext_len)) + 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] */ @@ -189,7 +186,7 @@ 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--; + UIP_RH_BUF(uip_ext_len)->seg_left--; LOG_INFO("SRH next hop "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); @@ -314,13 +311,13 @@ insert_srh_header(void) memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); /* Insert source routing header */ - UIP_RH_BUF->next = UIP_IP_BUF->proto; + UIP_RH_BUF(uip_ext_len)->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; + UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8; + UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH; + UIP_RH_BUF(uip_ext_len)->seg_left = path_len; /* Initialize RPL Source Routing Header */ UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; @@ -329,7 +326,7 @@ insert_srh_header(void) /* 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 *)UIP_RH_BUF(uip_ext_len)) + 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); @@ -369,11 +366,11 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF->opt_type; uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF->opt_len; - if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) || opt_type != UIP_EXT_HDR_OPT_RPL || 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); + UIP_HBHO_BUF(uip_ext_len)->len, opt_type, opt_len); return 0; /* Drop */ } @@ -425,7 +422,7 @@ update_hbh_header(void) uip_ext_opt_offset = 2; 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) + if(UIP_HBHO_BUF(uip_ext_len)->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", @@ -471,16 +468,16 @@ insert_hbh_header(void) 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 UIP_EXT_BUF(uip_ext_len) further */ + memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN); + memset(UIP_HBHO_BUF(uip_ext_len), 0, RPL_HOP_BY_HOP_LEN); /* Update IP and HBH protocol and fields */ - UIP_HBHO_BUF->next = UIP_IP_BUF->proto; + UIP_HBHO_BUF(uip_ext_len)->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_HBHO_BUF(uip_ext_len)->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; @@ -546,8 +543,8 @@ rpl_ext_header_remove(void) 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; + *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; + rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->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; @@ -555,10 +552,10 @@ rpl_ext_header_remove(void) 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); + memmove(UIP_EXT_BUF(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; } break; case UIP_PROTO_DESTO: @@ -571,8 +568,8 @@ rpl_ext_header_remove(void) * 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; + uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; + uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; break; default: return; From 01b795a4c2e2235615c2f1599593f8e9e6f4dc74 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 16:58:51 +0200 Subject: [PATCH 048/184] Rework uIP6 extension header options access --- os/net/ipv6/uip-icmp6.c | 5 +- os/net/ipv6/uip.h | 8 +++ os/net/ipv6/uip6.c | 17 +++-- os/net/routing/rpl-classic/rpl-ext-header.c | 80 ++++++++++----------- os/net/routing/rpl-lite/rpl-ext-header.c | 67 ++++++++--------- tools/sky/uip6-bridge/sicslow_ethernet.c | 2 +- 6 files changed, 86 insertions(+), 93 deletions(-) diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 90a53422d..ca543d68b 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -54,7 +54,6 @@ #define LOG_LEVEL LOG_LEVEL_IPV6 #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD) -#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN]) /** \brief temporary IP address */ static uip_ipaddr_t tmp_ipaddr; @@ -194,14 +193,14 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { uip_len = UIP_LINK_MTU; } - memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN, + memmove(UIP_ICMP_PAYLOAD + uip_ext_len + UIP_ICMP6_ERROR_LEN, (void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN); 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; + UIP_EXT_BUF(0)->next = UIP_PROTO_ICMP6; } else { UIP_IP_BUF->proto = UIP_PROTO_ICMP6; } diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index f4ee4dd2b..e4584de8c 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -101,6 +101,14 @@ #define UIP_RH_BUF(ext) ((struct uip_routing_hdr *)UIP_IP_PAYLOAD(ext)) #define UIP_FRAG_BUF(ext) ((struct uip_frag_hdr *)UIP_IP_PAYLOAD(ext)) #define UIP_DESTO_BUF(ext) ((struct uip_desto_hdr *)UIP_IP_PAYLOAD(ext)) +#define UIP_RPL_SRH_BUF(ext) ((struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(ext) + RPL_RH_LEN)) + +/** + * Direct access to extension header options, with explicit ext header and option offset + */ +#define UIP_EXT_HDR_OPT_BUF(ext, opt) ((struct uip_ext_hdr_opt *)(UIP_IP_PAYLOAD(ext) + (opt))) +#define UIP_EXT_HDR_OPT_PADN_BUF(ext, opt) ((struct uip_ext_hdr_opt_padn *)(UIP_IP_PAYLOAD(ext) + (opt))) +#define UIP_EXT_HDR_OPT_RPL_BUF(ext, opt) ((struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(ext) + (opt))) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 943791311..8b58e53c5 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -138,12 +138,11 @@ uint8_t uip_ext_opt_offset = 0; /* Buffers */ /*---------------------------------------------------------------------------*/ /** - * \name Buffer defines + * \name Reassembly buffer definition * @{ */ #define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0]) -#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]) + /** @} */ /** * \name Buffer variables @@ -839,7 +838,7 @@ ext_hdr_options_process(void) */ uip_ext_opt_offset = 2; while(uip_ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) { - switch(UIP_EXT_HDR_OPT_BUF->type) { + switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type) { /* * for now we do not support any options except padding ones * PAD1 does not make sense as the header must be 8bytes aligned, @@ -851,7 +850,7 @@ ext_hdr_options_process(void) 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; + uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len + 2; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -866,7 +865,7 @@ ext_hdr_options_process(void) LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF->len) + 2; + uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len) + 2; return 0; default: /* @@ -882,8 +881,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("MSB %x\n", UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type); + switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type & 0xC0) { case 0: break; case 0x40: @@ -898,7 +897,7 @@ ext_hdr_options_process(void) return 2; } /* in the cases were we did not discard, update ext_opt* */ - uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF->len + 2; + uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len + 2; break; } } diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index ebaa823aa..6a99b573a 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -60,12 +60,6 @@ #include #include -/*---------------------------------------------------------------------------*/ -#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_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) @@ -78,24 +72,24 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) rpl_parent_t *sender = NULL; if(UIP_HBHO_BUF(uip_ext_len)->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(uip_ext_len, uip_ext_opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL + || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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(uip_ext_len)->len, - UIP_EXT_HDR_OPT_RPL_BUF->opt_type, - UIP_EXT_HDR_OPT_RPL_BUF->opt_len); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type, + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); + instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); if(instance == NULL) { LOG_ERR("Unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF->instance); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); return 0; } - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) { + if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 @@ -119,14 +113,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(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) { down = 1; } - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank); + sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 && (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; @@ -156,7 +150,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(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 */ @@ -165,7 +159,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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; return 1; } @@ -273,9 +267,9 @@ rpl_ext_header_srh_update(void) segments_left = UIP_RH_BUF(uip_ext_len)->seg_left; ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF->pad >> 4; + cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4; + cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f; + padding = UIP_RPL_SRH_BUF(uip_ext_len)->pad >> 4; path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1; (void)path_len; @@ -419,7 +413,7 @@ insert_srh_header(void) return 0; } - /* Move existing ext headers and payload uip_ext_len further */ + /* Move existing ext headers and payload 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); @@ -434,8 +428,8 @@ insert_srh_header(void) UIP_RH_BUF(uip_ext_len)->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF->pad = padding << 4; + UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre; + UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ @@ -480,17 +474,17 @@ update_hbh_header(void) uip_ext_len = 0; uip_ext_opt_offset = 2; - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { + || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len, uip_ext_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); + instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; @@ -499,17 +493,17 @@ update_hbh_header(void) 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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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((UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 */ @@ -528,11 +522,11 @@ 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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_DOWN; LOG_DBG("RPL option going down\n"); } } @@ -562,9 +556,9 @@ insert_hbh_header(const rpl_instance_t *instance) return 0; } - /* Move existing ext headers and payload UIP_EXT_BUF(uip_ext_len) further */ - memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN); - memset(UIP_HBHO_BUF(uip_ext_len), 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(uip_ext_len)->next = UIP_IP_BUF->proto; @@ -572,11 +566,11 @@ insert_hbh_header(const rpl_instance_t *instance) /* Initialize HBH option */ UIP_HBHO_BUF(uip_ext_len)->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_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; @@ -607,7 +601,7 @@ rpl_ext_header_remove(void) 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)) { + if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) { /* Remove hop-by-hop and routing headers */ *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8; diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index ab9e37188..02a681476 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -53,13 +53,6 @@ #define LOG_MODULE "RPL" #define LOG_LEVEL LOG_LEVEL_RPL -/*---------------------------------------------------------------------------*/ -#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_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) @@ -159,9 +152,9 @@ rpl_ext_header_srh_update(void) /* Parse SRH */ segments_left = UIP_RH_BUF(uip_ext_len)->seg_left; ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF->pad >> 4; + cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4; + cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f; + padding = UIP_RPL_SRH_BUF(uip_ext_len)->pad >> 4; path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1; (void)path_len; @@ -305,7 +298,7 @@ insert_srh_header(void) return 0; } - /* Move existing ext headers and payload uip_ext_len further */ + /* Move existing ext headers and payload 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); @@ -320,8 +313,8 @@ insert_srh_header(void) UIP_RH_BUF(uip_ext_len)->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF->pad = padding << 4; + UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre; + UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ @@ -363,8 +356,8 @@ 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; + uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type; + uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len; if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) || opt_type != UIP_EXT_HDR_OPT_RPL @@ -374,21 +367,21 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) 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 != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance) { LOG_ERR("unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF->instance); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); return 0; /* Drop */ } - if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) { + if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; + sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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 = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; sender_closer = sender_rank < curr_instance.dag.rank; loop_detected = (down && !sender_closer) || (!down && sender_closer); @@ -402,7 +395,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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; } return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled); @@ -421,24 +414,24 @@ update_hbh_header(void) uip_ext_len = 0; uip_ext_opt_offset = 2; - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { + || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len, uip_ext_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 != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = curr_instance.instance_id; } uip_ext_len = last_uip_ext_len; @@ -468,9 +461,9 @@ insert_hbh_header(void) return 0; } - /* Move existing ext headers and payload UIP_EXT_BUF(uip_ext_len) further */ - memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN); - memset(UIP_HBHO_BUF(uip_ext_len), 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(uip_ext_len)->next = UIP_IP_BUF->proto; @@ -478,11 +471,11 @@ insert_hbh_header(void) /* Initialize HBH option */ UIP_HBHO_BUF(uip_ext_len)->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_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0; + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); + UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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; @@ -541,7 +534,7 @@ rpl_ext_header_remove(void) 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)) { + if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) { /* Remove hop-by-hop and routing headers */ *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8; diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 0b241d71b..5274a7833 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -379,7 +379,7 @@ typedef struct { uint8_t data[16]; } icmp_opts_t; -#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x]) +#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)UIP_IP_PAYLOAD(x)) void slide(uint8_t * data, uint8_t length, int16_t slide); From bbb641a450e9be4cd6763ba6e328cf51f12408e0 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 17:24:53 +0200 Subject: [PATCH 049/184] Rework uip-nd6 buffer access --- os/net/ipv6/uip-nd6.c | 97 ++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 446ad8346..2dbf95b00 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -101,10 +101,11 @@ #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 @@ -201,12 +202,12 @@ 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]; #if UIP_CONF_IPV6_CHECKS @@ -250,7 +251,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); @@ -491,20 +492,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 */ @@ -642,20 +643,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) { @@ -744,31 +745,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; @@ -776,22 +777,22 @@ 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 */ @@ -902,14 +903,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 */ @@ -942,11 +943,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))) { @@ -1033,14 +1034,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; @@ -1049,7 +1050,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); From 0531c555e87753415c1d9c3c7f48f274637e095e Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 17:25:04 +0200 Subject: [PATCH 050/184] Minor enhancements to uip6.c --- os/net/ipv6/uip.h | 1 - os/net/ipv6/uip6.c | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index e4584de8c..353e28f64 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -1788,7 +1788,6 @@ 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_PROTO_ICMP 1 #define UIP_PROTO_TCP 6 diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 8b58e53c5..d9aec0089 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -2328,8 +2328,7 @@ uip_send(const void *data, int len) 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])); + (int)((char *)uip_sappdata - (char *)UIP_TCP_PAYLOAD)); } else { copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN); } @@ -2337,8 +2336,7 @@ uip_send(const void *data, int len) 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); } From 3384de64b70fc5849d44bac8d585f98292f741d9 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 17:30:12 +0200 Subject: [PATCH 051/184] Rework buffer access in roll-tm.c --- os/net/ipv6/multicast/roll-tm.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 3e1d14b5b..e9214f8d4 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -456,9 +456,8 @@ static uint16_t last_seq; /*---------------------------------------------------------------------------*/ /* uIPv6 Pointers */ /*---------------------------------------------------------------------------*/ -#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_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 */ @@ -1322,11 +1321,11 @@ out() } /* Slide 'right' by HBHO_TOTAL_LEN bytes */ - memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF, uip_len - UIP_IPH_LEN); - memset(UIP_EXT_BUF, 0, HBHO_TOTAL_LEN); + memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF(0), uip_len - UIP_IPH_LEN); + memset(UIP_EXT_BUF(0), 0, HBHO_TOTAL_LEN); - UIP_EXT_BUF->next = UIP_IP_BUF->proto; - UIP_EXT_BUF->len = 0; + UIP_EXT_BUF(0)->next = UIP_IP_BUF->proto; + UIP_EXT_BUF(0)->len = 0; lochbhmptr = UIP_EXT_OPT_FIRST; lochbhmptr->type = HBHO_OPT_TYPE_TRICKLE; From 56b85b6475d9c3bc758359e77002de3877721f81 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 17:47:57 +0200 Subject: [PATCH 052/184] uip.h: clarify comment --- os/net/ipv6/uip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 353e28f64..39714c135 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -84,7 +84,7 @@ #define UIP_IP_PAYLOAD(ext) ((unsigned char *)UIP_IP_BUF_CHAR + UIP_IPH_LEN + (ext)) /** - * Direct access to ICMP, UDP, and TCP headers and payload, with implicit ext header offset + * 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) From fc8ccac5604c6c1e8b4c4079ced2dd9b15d8b7f8 Mon Sep 17 00:00:00 2001 From: Toshio Ito Date: Thu, 18 Oct 2018 16:05:45 +0900 Subject: [PATCH 053/184] tsch: report MAC_TX_ERR if prepare() fails Before this fix, uninitialized mac_tx_status was reported in this case. --- os/net/mac/tsch/tsch-slot-operation.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 841dee07f..5fbf86013 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; } } From c5d59843c4ed9f08e50b811c1191e96d8c2d1788 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 29 May 2018 11:00:13 +0200 Subject: [PATCH 054/184] added linklayer security for CSMA --- os/net/mac/csma/anti-replay.c | 115 ++++++++++++ os/net/mac/csma/anti-replay.h | 80 ++++++++ os/net/mac/csma/ccm-star-packetbuf.c | 80 ++++++++ os/net/mac/csma/ccm-star-packetbuf.h | 39 ++++ os/net/mac/csma/csma-output.c | 10 +- os/net/mac/csma/csma-security.c | 267 +++++++++++++++++++++++++++ os/net/mac/csma/csma-security.h | 74 ++++++++ os/net/mac/csma/csma.c | 8 +- os/net/mac/csma/csma.h | 8 + os/net/packetbuf.h | 5 + 10 files changed, 684 insertions(+), 2 deletions(-) create mode 100644 os/net/mac/csma/anti-replay.c create mode 100644 os/net/mac/csma/anti-replay.h create mode 100644 os/net/mac/csma/ccm-star-packetbuf.c create mode 100644 os/net/mac/csma/ccm-star-packetbuf.h create mode 100644 os/net/mac/csma/csma-security.c create mode 100644 os/net/mac/csma/csma-security.h diff --git a/os/net/mac/csma/anti-replay.c b/os/net/mac/csma/anti-replay.c new file mode 100644 index 000000000..347674184 --- /dev/null +++ b/os/net/mac/csma/anti-replay.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014, Hasso-Plattner-Institut. + * 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 + * Protects against replay attacks by comparing with the last + * unicast or broadcast frame counter of the sender. + * \author + * Konrad Krentz + */ + +/** + * \addtogroup csma + * @{ + */ + +#include "net/mac/csma/anti-replay.h" +#include "net/packetbuf.h" +#include "net/mac/llsec802154.h" + +#if LLSEC802154_USES_FRAME_COUNTER + +/* This node's current frame counter value */ +static uint32_t counter; + +/*---------------------------------------------------------------------------*/ +void +anti_replay_set_counter(void) +{ + frame802154_frame_counter_t reordered_counter; + + ++counter; + reordered_counter.u32 = LLSEC802154_HTONL(counter); + + packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, reordered_counter.u16[0]); + packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, reordered_counter.u16[1]); +} +/*---------------------------------------------------------------------------*/ +uint32_t +anti_replay_get_counter(void) +{ + frame802154_frame_counter_t disordered_counter; + + disordered_counter.u16[0] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1); + disordered_counter.u16[1] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3); + + return LLSEC802154_HTONL(disordered_counter.u32); +} +/*---------------------------------------------------------------------------*/ +void +anti_replay_init_info(struct anti_replay_info *info) +{ + info->last_broadcast_counter + = info->last_unicast_counter + = anti_replay_get_counter(); +} +/*---------------------------------------------------------------------------*/ +int +anti_replay_was_replayed(struct anti_replay_info *info) +{ + uint32_t received_counter; + + received_counter = anti_replay_get_counter(); + + if(packetbuf_holds_broadcast()) { + /* broadcast */ + if(received_counter <= info->last_broadcast_counter) { + return 1; + } else { + info->last_broadcast_counter = received_counter; + return 0; + } + } else { + /* unicast */ + if(received_counter <= info->last_unicast_counter) { + return 1; + } else { + info->last_unicast_counter = received_counter; + return 0; + } + } +} +/*---------------------------------------------------------------------------*/ +#endif /* LLSEC802154_USES_FRAME_COUNTER */ + +/** @} */ diff --git a/os/net/mac/csma/anti-replay.h b/os/net/mac/csma/anti-replay.h new file mode 100644 index 000000000..9211a6e7a --- /dev/null +++ b/os/net/mac/csma/anti-replay.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2014, Hasso-Plattner-Institut. + * 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 + * Interface to anti-replay mechanisms. + * \author + * Konrad Krentz + */ + +/** + * \addtogroup llsec802154 + * @{ + */ + +#ifndef ANTI_REPLAY_H +#define ANTI_REPLAY_H + +#include "contiki.h" + +struct anti_replay_info { + uint32_t last_broadcast_counter; + uint32_t last_unicast_counter; +}; + +/** + * \brief Sets the frame counter packetbuf attributes. + */ +void anti_replay_set_counter(void); + +/** + * \brief Gets the frame counter from packetbuf. + */ +uint32_t anti_replay_get_counter(void); + +/** + * \brief Initializes the anti-replay information about the sender + * \param info Anti-replay information about the sender + */ +void anti_replay_init_info(struct anti_replay_info *info); + +/** + * \brief Checks if received frame was replayed + * \param info Anti-replay information about the sender + * \retval 0 <-> received frame was not replayed + */ +int anti_replay_was_replayed(struct anti_replay_info *info); + +#endif /* ANTI_REPLAY_H */ + +/** @} */ diff --git a/os/net/mac/csma/ccm-star-packetbuf.c b/os/net/mac/csma/ccm-star-packetbuf.c new file mode 100644 index 000000000..17b9befdc --- /dev/null +++ b/os/net/mac/csma/ccm-star-packetbuf.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013, Hasso-Plattner-Institut. + * 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 + * CCM* convenience functions for LLSEC use + * \author + * Justin King-Lacroix + * Konrad Krentz + */ + +#include "net/linkaddr.h" +#include "net/packetbuf.h" +#include "net/mac/llsec802154.h" +#include + +#if LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER + +/*---------------------------------------------------------------------------*/ +static const uint8_t * +get_extended_address(const linkaddr_t *addr) +#if LINKADDR_SIZE == 2 +{ + /* workaround for short addresses: derive EUI64 as in RFC 6282 */ + static linkaddr_extended_t template = { { 0x00 , 0x00 , 0x00 , + 0xFF , 0xFE , 0x00 , 0x00 , 0x00 } }; + template.u16[3] = LLSEC802154_HTONS(addr->u16); + + return template.u8; +} +#else /* LINKADDR_SIZE == 2 */ +{ + return addr->u8; +} +#endif /* LINKADDR_SIZE == 2 */ +/*---------------------------------------------------------------------------*/ +void +ccm_star_packetbuf_set_nonce(uint8_t *nonce, int forward) +{ + const linkaddr_t *source_addr; + + source_addr = forward ? &linkaddr_node_addr : packetbuf_addr(PACKETBUF_ADDR_SENDER); + memcpy(nonce, get_extended_address(source_addr), 8); + nonce[8] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) >> 8; + nonce[9] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3) & 0xff; + nonce[10] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) >> 8; + nonce[11] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1) & 0xff; + nonce[12] = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL); +} +/*---------------------------------------------------------------------------*/ +#endif /* LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER */ diff --git a/os/net/mac/csma/ccm-star-packetbuf.h b/os/net/mac/csma/ccm-star-packetbuf.h new file mode 100644 index 000000000..578bdef96 --- /dev/null +++ b/os/net/mac/csma/ccm-star-packetbuf.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, Hasso-Plattner-Institut. + * 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 CCM_STAR_PACKETBUF_H_ +#define CCM_STAR_PACKETBUF_H_ + +/*---------------------------------------------------------------------------*/ +void ccm_star_packetbuf_set_nonce(uint8_t *nonce, int forward); + +#endif /* CCM_STAR_PACKETBUF_H_ */ diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 1773e0cb0..65505532e 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -40,6 +40,7 @@ */ #include "net/mac/csma/csma.h" +#include "net/mac/csma/csma-security.h" #include "net/packetbuf.h" #include "net/queuebuf.h" #include "dev/watchdog.h" @@ -169,7 +170,14 @@ send_one_packet(void *ptr) packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr); packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1); - if(NETSTACK_FRAMER.create() < 0) { +#if LLSEC802154_ENABLED + /* These should possibly be taken from upper layers in the future */ + packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, CSMA_LLSEC_SECURITY_LEVEL); + packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, CSMA_LLSEC_KEY_ID_MODE); + packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, CSMA_LLSEC_KEY_INDEX); +#endif /* LLSEC802154_ENABLED */ + + if(csma_security_create_frame() < 0) { /* Failed to allocate space for headers */ LOG_ERR("failed to create packet\n"); ret = MAC_TX_ERR_FATAL; diff --git a/os/net/mac/csma/csma-security.c b/os/net/mac/csma/csma-security.c new file mode 100644 index 000000000..ec7f7767a --- /dev/null +++ b/os/net/mac/csma/csma-security.c @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2017, RISE SICS + * 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 + * CSMA security + * \author + * Joakim Eriksson + */ + +/** + * \addtogroup csma + * @{ +*/ + +#include "contiki.h" +#include "net/mac/csma/csma.h" +#include "net/mac/csma/anti-replay.h" +#include "net/mac/csma/csma-security.h" +#include "net/mac/framer/frame802154.h" +#include "net/mac/framer/framer-802154.h" +#include "net/mac/llsec802154.h" +#include "net/netstack.h" +#include "net/packetbuf.h" +#include "lib/ccm-star.h" +#include "lib/aes-128.h" +#include +#include +#include "ccm-star-packetbuf.h" +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "CSMA" +#define LOG_LEVEL LOG_LEVEL_MAC + +#if LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER + +/** + * The keys for LLSEC for CSMA + */ +typedef struct { + uint8_t u8[16]; +} aes_key_t; +static aes_key_t keys[CSMA_LLSEC_MAXKEYS]; + +/* assumed to be 16 bytes */ +void +csma_security_set_key(uint8_t index, uint8_t *key) +{ + if(key != NULL && index < CSMA_LLSEC_MAXKEYS) { + memcpy(keys[index].u8, key, 16); + } +} + +#define N_KEYS (sizeof(keys) / sizeof(aes_key)) +/*---------------------------------------------------------------------------*/ +static int +aead(uint8_t hdrlen, int forward) +{ + uint8_t totlen; + uint8_t nonce[CCM_STAR_NONCE_LENGTH]; + uint8_t *m; + uint8_t m_len; + uint8_t *a; + uint8_t a_len; + uint8_t *result; + uint8_t generated_mic[MIC_LEN]; + uint8_t *mic; + uint8_t key_index; + aes_key_t *key; + uint8_t with_encryption; + + key_index = packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX); + if(key_index > CSMA_LLSEC_MAXKEYS) { + LOG_ERR("Key not available: %u\n", key_index); + return 0; + } + + key = &keys[key_index]; + + ccm_star_packetbuf_set_nonce(nonce, forward); + totlen = packetbuf_totlen(); + a = packetbuf_hdrptr(); + + with_encryption = + (packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x4) ? 1 : 0; + + if(with_encryption) { + a_len = hdrlen; + m = a + a_len; + m_len = totlen - hdrlen; + } else { + a_len = totlen; + m = NULL; + m_len = 0; + } + + mic = a + totlen; + result = forward ? mic : generated_mic; + + CCM_STAR.set_key(key->u8); + CCM_STAR.aead(nonce, + m, m_len, + a, a_len, + result, MIC_LEN, + forward); + + if(forward) { + packetbuf_set_datalen(packetbuf_datalen() + MIC_LEN); + return 1; + } else { + return (memcmp(generated_mic, mic, MIC_LEN) == 0); + } +} + +/*---------------------------------------------------------------------------*/ +int +csma_security_create_frame(void) +{ + int hdr_len; + + packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME); + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0 && + packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX) != 0xffff) { + anti_replay_set_counter(); + } + + hdr_len = NETSTACK_FRAMER.create(); + if(hdr_len < 0) { + return hdr_len; + } + + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0) { + if(!aead(hdr_len, 1)) { + LOG_ERR("failed to encrypt packet to "); + LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); + LOG_ERR_("\n"); + return FRAMER_FAILED; + } + LOG_INFO("LLSEC-OUT:"); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_(" "); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); + LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), + packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)); + } + return hdr_len; +} + +/*---------------------------------------------------------------------------*/ +int +csma_security_frame_len(void) +{ + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0 && + packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX) != 0xffff) { + return NETSTACK_FRAMER.length() + MIC_LEN; + } + return NETSTACK_FRAMER.length(); +} +/*---------------------------------------------------------------------------*/ +int +csma_security_parse_frame(void) +{ + int hdr_len; + + hdr_len = NETSTACK_FRAMER.parse(); + if(hdr_len < 0) { + return hdr_len; + } + + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) == 0) { + /* No security - no more processing required */ + return hdr_len; + } + + LOG_INFO("LLSEC-IN: "); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_(" "); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); + LOG_INFO_(" %d %u (%u) LV:%d KM:%d KEY:0x%02x\n", hdr_len, packetbuf_datalen(), + packetbuf_totlen(), packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL), + packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE), + packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)); + + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) != CSMA_LLSEC_SECURITY_LEVEL) { + LOG_INFO("received frame with wrong security level (%u) from ", + packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_("\n"); + return FRAMER_FAILED; + } + + if(packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE) != CSMA_LLSEC_KEY_ID_MODE) { + LOG_INFO("received frame with wrong key id mode (%u) from ", + packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE)); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO("\n"); + return FRAMER_FAILED; + } + + if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), &linkaddr_node_addr)) { + LOG_INFO("frame from ourselves\n"); + return FRAMER_FAILED; + } + + if(packetbuf_datalen() <= MIC_LEN) { + LOG_ERR("MIC error - too little data in frame!\n"); + return FRAMER_FAILED; + } + + packetbuf_set_datalen(packetbuf_datalen() - MIC_LEN); + if(!aead(hdr_len, 0)) { + LOG_INFO("received unauthentic frame %u from ", + (unsigned int) anti_replay_get_counter()); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_("\n"); + return FRAMER_FAILED; + } + + /* TODO anti-reply protection */ + return hdr_len; +} +/*---------------------------------------------------------------------------*/ +#else +/* The "unsecure" version of the create frame / parse frame */ +int +csma_security_create_frame(void) +{ + packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME); + return NETSTACK_FRAMER.create(); +} +int +csma_security_parse_frame(void) +{ + return NETSTACK_FRAMER.parse(); +} +#endif /* LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER */ + +/** @} */ diff --git a/os/net/mac/csma/csma-security.h b/os/net/mac/csma/csma-security.h new file mode 100644 index 000000000..d99f6292b --- /dev/null +++ b/os/net/mac/csma/csma-security.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018, Tiny Mesh AS + * 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 + * LLSEC802154 Security related configuration + * \author + * Olav Frengstad + */ + +#ifndef CSMA_SECURITY_H_ +#define CSMA_SECURITY_H_ + + +#ifdef CSMA_CONF_LLSEC_DEFAULT_KEY0 +#define CSMA_LLSEC_DEFAULT_KEY0 CSMA_LLSEC_DEFAULT_KEY0 +#else +#define CSMA_LLSEC_DEFAULT_KEY0 {0x10, 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f} +#endif + +#ifdef CSMA_CONF_LLSEC_SECURITY_LEVEL +#define CSMA_LLSEC_SECURITY_LEVEL CSMA_CONF_LLSEC_SECURITY_LEVEL +#else +#define CSMA_LLSEC_SECURITY_LEVEL 5 +#endif /* CSMA_CONF_LLSEC_SECURITY_LEVEL */ + +#ifdef CSMA_CONF_LLSEC_KEY_ID_MODE +#define CSMA_LLSEC_KEY_ID_MODE CSMA_CONF_LLSEC_KEY_ID_MODE +#else +#define CSMA_LLSEC_KEY_ID_MODE FRAME802154_IMPLICIT_KEY +#endif /* CSMA_CONF_LLSEC_KEY_ID_MODE */ + +#ifdef CSMA_CONF_LLSEC_KEY_INDEX +#define CSMA_LLSEC_KEY_INDEX CSMA_CONF_LLSEC_KEY_INDEX +#else +#define CSMA_LLSEC_KEY_INDEX 0 +#endif /* CSMA_CONF_LLSEC_KEY_INDEX */ + +#ifdef CSMA_CONF_LLSEC_MAXKEYS +#define CSMA_LLSEC_MAXKEYS CSMA_CONF_LLSEC_MAXKEYS +#else +#define CSMA_LLSEC_MAXKEYS 1 +#endif + +#endif /* CSMA_SECURITY_H_ */ diff --git a/os/net/mac/csma/csma.c b/os/net/mac/csma/csma.c index 7259e35c8..4db20fa9a 100644 --- a/os/net/mac/csma/csma.c +++ b/os/net/mac/csma/csma.c @@ -70,7 +70,7 @@ input_packet(void) if(packetbuf_datalen() == CSMA_ACK_LEN) { /* Ignore ack packets */ LOG_DBG("ignored ack\n"); - } else if(NETSTACK_FRAMER.parse() < 0) { + } else if(csma_security_parse_frame() < 0) { LOG_ERR("failed to parse %u\n", packetbuf_datalen()); } else if(!linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_node_addr) && @@ -131,6 +131,12 @@ off(void) static void init(void) { + +#ifdef CSMA_LLSEC_DEFAULT_KEY0 + uint8_t key[16] = CSMA_LLSEC_DEFAULT_KEY0; + csma_security_set_key(0, key); +#endif + csma_output_init(); on(); } diff --git a/os/net/mac/csma/csma.h b/os/net/mac/csma/csma.h index 9e0773f28..655e59134 100644 --- a/os/net/mac/csma/csma.h +++ b/os/net/mac/csma/csma.h @@ -67,4 +67,12 @@ extern const struct mac_driver csma_driver; +/* CSMA security framer functions */ +int csma_security_create_frame(void); +int csma_security_parse_frame(void); + +/* key management for CSMA */ +void csma_security_set_key(uint8_t index, uint8_t *key); + + #endif /* CSMA_H_ */ diff --git a/os/net/packetbuf.h b/os/net/packetbuf.h index 20e071474..2429e84b0 100644 --- a/os/net/packetbuf.h +++ b/os/net/packetbuf.h @@ -238,6 +238,11 @@ enum { PACKETBUF_ATTR_KEY_INDEX, #endif /* LLSEC802154_USES_EXPLICIT_KEYS */ +#if LLSEC802154_USES_FRAME_COUNTER + PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, + PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, +#endif /* LLSEC802154_USES_FRAME_COUNTER */ + /* Scope 2 attributes: used between end-to-end nodes. */ /* These must be last */ PACKETBUF_ADDR_SENDER, From df130952c7cab9855f34a51be45915089fad22c3 Mon Sep 17 00:00:00 2001 From: Olav Frengstad Date: Mon, 27 Aug 2018 22:42:46 +0200 Subject: [PATCH 055/184] Ensure correct setup LLSEC for CSMA * Add `LLSEC_KEY_INDEX` for switching between implicit/explicit keys * Add missing `LLSEC_CONF_* * Conditionally include required CSMA setup for IPv6 (enable security when calculating frame length) * Setup default key * Always export `csma_security_set_key/2` --- os/net/ipv6/sicslowpan.c | 9 +++++++++ os/net/mac/csma/csma-output.c | 4 +++- os/net/mac/csma/csma-security.c | 30 +++++++++++++++++++++--------- os/net/mac/csma/csma-security.h | 4 +++- os/net/mac/llsec802154.h | 6 ++++++ 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 9e4e3a8b4..2789e4e7d 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -74,6 +74,10 @@ #include "net/packetbuf.h" #include "net/queuebuf.h" +#if MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED +#include "net/mac/csma/csma-security.h" +#endif /* MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED */ + #include "net/routing/routing.h" /* Log configuration */ @@ -1615,6 +1619,11 @@ output(const linkaddr_t *localdest) } #endif /* SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC */ +#if MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED + packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, + FRAME802154_SECURITY_LEVEL_NONE != CSMA_LLSEC_SECURITY_LEVEL); +#endif /* MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED */ + /* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC. * We calculate it here only to make a better decision of whether the outgoing packet * needs to be fragmented or not. */ diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 65505532e..b7eab163c 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -173,13 +173,15 @@ send_one_packet(void *ptr) #if LLSEC802154_ENABLED /* These should possibly be taken from upper layers in the future */ packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, CSMA_LLSEC_SECURITY_LEVEL); +#if LLSEC802154_USES_EXPLICIT_KEYS packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, CSMA_LLSEC_KEY_ID_MODE); packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, CSMA_LLSEC_KEY_INDEX); +#endif /* LLSEC802154_USES_EXPLICIT_KEYS */ #endif /* LLSEC802154_ENABLED */ if(csma_security_create_frame() < 0) { /* Failed to allocate space for headers */ - LOG_ERR("failed to create packet\n"); + LOG_ERR("failed to create packet, seqno: %d\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)); ret = MAC_TX_ERR_FATAL; } else { int is_broadcast; diff --git a/os/net/mac/csma/csma-security.c b/os/net/mac/csma/csma-security.c index ec7f7767a..50faf2723 100644 --- a/os/net/mac/csma/csma-security.c +++ b/os/net/mac/csma/csma-security.c @@ -63,6 +63,18 @@ #if LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER +#define MIC_LEN LLSEC802154_MIC_LEN(CSMA_LLSEC_SECURITY_LEVEL) + +#if LLSEC802154_USES_EXPLICIT_KEYS +#define LLSEC_KEY_INDEX (FRAME802154_IMPLICIT_KEY == packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE) \ + ? 0 \ + : packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)) +#define LLSEC_KEY_MODE (packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE)) +#else +#define LLSEC_KEY_INDEX (0) +#define LLSEC_KEY_MODE (FRAME802154_IMPLICIT_KEY) +#endif /* LLSEC802154_USES_EXPLICIT_KEYS */ + /** * The keys for LLSEC for CSMA */ @@ -98,7 +110,7 @@ aead(uint8_t hdrlen, int forward) aes_key_t *key; uint8_t with_encryption; - key_index = packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX); + key_index = LLSEC_KEY_INDEX; if(key_index > CSMA_LLSEC_MAXKEYS) { LOG_ERR("Key not available: %u\n", key_index); return 0; @@ -149,7 +161,7 @@ csma_security_create_frame(void) packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME); if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0 && - packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX) != 0xffff) { + LLSEC_KEY_INDEX != 0xffff) { anti_replay_set_counter(); } @@ -170,7 +182,7 @@ csma_security_create_frame(void) LOG_INFO_(" "); LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), - packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)); + LLSEC_KEY_INDEX); } return hdr_len; } @@ -180,7 +192,7 @@ int csma_security_frame_len(void) { if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0 && - packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX) != 0xffff) { + LLSEC_KEY_INDEX != 0xffff) { return NETSTACK_FRAMER.length() + MIC_LEN; } return NETSTACK_FRAMER.length(); @@ -207,8 +219,8 @@ csma_security_parse_frame(void) LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); LOG_INFO_(" %d %u (%u) LV:%d KM:%d KEY:0x%02x\n", hdr_len, packetbuf_datalen(), packetbuf_totlen(), packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL), - packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE), - packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)); + LLSEC_KEY_MODE, + LLSEC_KEY_INDEX); if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) != CSMA_LLSEC_SECURITY_LEVEL) { LOG_INFO("received frame with wrong security level (%u) from ", @@ -218,9 +230,8 @@ csma_security_parse_frame(void) return FRAMER_FAILED; } - if(packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE) != CSMA_LLSEC_KEY_ID_MODE) { - LOG_INFO("received frame with wrong key id mode (%u) from ", - packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE)); + if(LLSEC_KEY_MODE != CSMA_LLSEC_KEY_ID_MODE) { + LOG_INFO("received frame with wrong key id mode (%u) from ", LLSEC_KEY_MODE); LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); LOG_INFO("\n"); return FRAMER_FAILED; @@ -262,6 +273,7 @@ csma_security_parse_frame(void) { return NETSTACK_FRAMER.parse(); } + #endif /* LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER */ /** @} */ diff --git a/os/net/mac/csma/csma-security.h b/os/net/mac/csma/csma-security.h index d99f6292b..d58885f5c 100644 --- a/os/net/mac/csma/csma-security.h +++ b/os/net/mac/csma/csma-security.h @@ -42,7 +42,7 @@ #ifdef CSMA_CONF_LLSEC_DEFAULT_KEY0 -#define CSMA_LLSEC_DEFAULT_KEY0 CSMA_LLSEC_DEFAULT_KEY0 +#define CSMA_LLSEC_DEFAULT_KEY0 CSMA_CONF_LLSEC_DEFAULT_KEY0 #else #define CSMA_LLSEC_DEFAULT_KEY0 {0x10, 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f} #endif @@ -71,4 +71,6 @@ #define CSMA_LLSEC_MAXKEYS 1 #endif +void csma_security_set_key(uint8_t index, uint8_t *key); + #endif /* CSMA_SECURITY_H_ */ diff --git a/os/net/mac/llsec802154.h b/os/net/mac/llsec802154.h index fe1a9d231..e808fef7a 100644 --- a/os/net/mac/llsec802154.h +++ b/os/net/mac/llsec802154.h @@ -74,6 +74,12 @@ #define LLSEC802154_USES_AUX_HEADER LLSEC802154_ENABLED #endif /* LLSEC802154_CONF_USES_AUX_HEADER */ +#ifdef LLSEC802154_CONF_USES_FRAME_COUNTER +#define LLSEC802154_USES_FRAME_COUNTER LLSEC802154_CONF_USES_FRAME_COUNTER +#else +#define LLSEC802154_USES_FRAME_COUNTER LLSEC802154_ENABLED +#endif /* LLSEC802154_CONF_USES_FRAME_COUNTER */ + #if UIP_BYTE_ORDER == UIP_LITTLE_ENDIAN #define LLSEC802154_HTONS(n) (n) #define LLSEC802154_HTONL(n) (n) From 22f4a19994904ffc96cdc907d6d21a15966edb25 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 18:09:40 +0200 Subject: [PATCH 056/184] Clean up usage of uip_ext_len --- os/net/ipv6/multicast/esmrf.c | 3 +- os/net/ipv6/multicast/roll-tm.c | 3 +- os/net/ipv6/tcpip.c | 4 +- os/net/ipv6/uip-icmp6.c | 73 ++---- os/net/ipv6/uip-nd6.c | 7 +- os/net/ipv6/uip.h | 12 +- os/net/ipv6/uip6.c | 33 ++- os/net/ipv6/uipbuf.c | 104 ++++++-- os/net/ipv6/uipbuf.h | 32 ++- os/net/routing/nullrouting/nullrouting.c | 4 +- os/net/routing/routing.h | 6 +- os/net/routing/rpl-classic/rpl-ext-header.c | 267 +++++++------------- os/net/routing/rpl-classic/rpl.h | 2 +- os/net/routing/rpl-lite/rpl-ext-header.c | 249 +++++++----------- os/net/routing/rpl-lite/rpl-ext-header.h | 6 +- 15 files changed, 369 insertions(+), 436 deletions(-) diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index d72d99fad..746f2f03b 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -108,7 +108,6 @@ static uip_ipaddr_t des_ip; static void icmp_input(void); static void icmp_output(void); static void mcast_fwd(void *p); -int remove_ext_hdr(void); /*---------------------------------------------------------------------------*/ /* Internal Data Structures */ /*---------------------------------------------------------------------------*/ @@ -192,7 +191,7 @@ icmp_input() } #endif - remove_ext_hdr(); + uip_remove_ext_hdr(); PRINTF("ESMRF: ICMPv6 In from "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index e9214f8d4..c942dfd46 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -1349,8 +1349,7 @@ 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; diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index b7a10de9a..d78cae510 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -451,15 +451,13 @@ tcpip_input(void) uip_clear_buf(); } /*---------------------------------------------------------------------------*/ -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 */ diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index ca543d68b..c4003352f 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -130,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 @@ -169,41 +154,32 @@ 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(uip_ext_len)->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) { + uip_clear_buf(); + 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(UIP_ICMP_PAYLOAD + 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_IP_BUF_CHAR + 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_EXT_BUF(0)->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 @@ -293,22 +269,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. */ diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 2dbf95b00..9fc7429fe 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -322,7 +322,7 @@ create_na: #if UIP_CONF_ROUTER flags = flags | UIP_ND6_NA_FLAG_ROUTER; #endif - uip_ext_len = 0; + uip_clear_buf(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; @@ -343,8 +343,7 @@ create_na: 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 "); @@ -368,7 +367,7 @@ discard: void uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) { - uip_ext_len = 0; + uip_clear_buf(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 39714c135..49a7a0b21 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -1330,6 +1330,10 @@ 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 @@ -1345,6 +1349,7 @@ extern uint16_t uip_urglen, uip_surglen; #define uip_clear_buf() { \ uip_len = 0; \ uip_ext_len = 0; \ + uip_last_proto = 0; \ uipbuf_clear_attr();\ } @@ -1804,7 +1809,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 */ @@ -2175,6 +2180,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 d9aec0089..4ded21bdc 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -132,6 +132,9 @@ uint8_t uip_ext_bitmap = 0; 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; /** @} */ /*---------------------------------------------------------------------------*/ @@ -499,15 +502,15 @@ 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"); + LOG_ERR("uip_len too short compared to ext len\n"); uip_clear_buf(); return; } @@ -861,7 +864,7 @@ 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)) { + if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_len, uip_ext_opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } @@ -909,6 +912,7 @@ ext_hdr_options_process(void) void uip_process(uint8_t flag) { + uint8_t *last_header; #if UIP_TCP int c; uint16_t tmp16; @@ -1104,10 +1108,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"); 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_IP_BUF_CHAR, uip_len, &uip_last_proto); + if(last_header == NULL) { + LOG_ERR("invalid extension header chain"); + goto drop; + } + /* Set uip_ext_len */ + uip_ext_len = last_header - UIP_IP_BUF_CHAR; + LOG_INFO("packet received from "); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); LOG_INFO_(" to "); @@ -1136,6 +1151,7 @@ uip_process(uint8_t flag) 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; @@ -1254,15 +1270,18 @@ uip_process(uint8_t flag) #if UIP_TCP case UIP_PROTO_TCP: /* TCP, for both IPv4 and IPv6 */ + uip_last_proto = *uip_next_hdr; goto tcp_input; #endif /* UIP_TCP */ #if UIP_UDP case UIP_PROTO_UDP: /* UDP, for both IPv4 and IPv6 */ + uip_last_proto = *uip_next_hdr; goto udp_input; #endif /* UIP_UDP */ case UIP_PROTO_ICMP6: /* ICMPv6 */ + uip_last_proto = *uip_next_hdr; goto icmp6_input; case UIP_PROTO_HBHO: LOG_DBG("Processing hbh header\n"); @@ -1469,7 +1488,7 @@ uip_process(uint8_t flag) /* UDP input processing. */ udp_input: - remove_ext_hdr(); + uip_remove_ext_hdr(); LOG_INFO("Receiving UDP packet\n"); @@ -1581,7 +1600,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"); diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index 6ccbb99aa..efa2413e9 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -38,45 +38,119 @@ static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX]; +/*---------------------------------------------------------------------------*/ +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; + } +} /*---------------------------------------------------------------------------*/ /* 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 337ffe17f..a2e091015 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -35,17 +35,31 @@ #include "contiki.h" +/** + * \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 Get the next IPv6 header. * \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 * \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 +67,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/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index bb1399fbb..3443dbb13 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(int ext_offset, int opt_offset) { return 1; } diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h index 7fe6e7ca8..be1fe0173 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -131,12 +131,14 @@ 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 + * \param ext_offset The offset within the uIP packet where * extension headers start + * \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)(int ext_offset, 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-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 6a99b573a..b175edd38 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -62,7 +62,7 @@ /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int uip_ext_opt_offset) +rpl_ext_header_hbh_update(int ext_offset, int opt_offset) { rpl_instance_t *instance; int down; @@ -71,25 +71,25 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) uip_ds6_route_t *route; rpl_parent_t *sender = NULL; - if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL - || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len != RPL_HDR_OPT_LEN) { + if(UIP_HBHO_BUF(ext_offset)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL + || UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(uip_ext_len)->len, - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type, - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len); + UIP_HBHO_BUF(ext_offset)->len, + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type, + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); + instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance); if(instance == NULL) { LOG_ERR("Unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance); return 0; } - if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) { + if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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 @@ -113,14 +113,14 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) return 0; } down = 0; - if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) { + if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_DOWN) { down = 1; } - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank); + sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->senderrank); sender = nbr_table_get_from_lladdr(rpl_parents, packetbuf_addr(PACKETBUF_ADDR_SENDER)); - if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR)) { + if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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; @@ -150,7 +150,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(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) { + if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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 */ @@ -159,7 +159,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(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; return 1; } @@ -171,41 +171,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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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_IP_BUF_CHAR, 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(uip_ext_len)->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. @@ -214,11 +192,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 */ @@ -229,34 +205,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_IP_BUF_CHAR, 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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } - - if(uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING - && UIP_RH_BUF(uip_ext_len)->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; @@ -265,11 +220,12 @@ rpl_ext_header_srh_update(void) uint8_t segments_left; uip_ipaddr_t current_dest_addr; - segments_left = UIP_RH_BUF(uip_ext_len)->seg_left; - ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF(uip_ext_len)->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; @@ -280,7 +236,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(uip_ext_len)) + 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] */ @@ -293,17 +249,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(uip_ext_len)->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 */ @@ -408,7 +362,7 @@ 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; } @@ -418,23 +372,23 @@ insert_srh_header(void) uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN); memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); - /* Insert source routing header */ - UIP_RH_BUF(uip_ext_len)->next = UIP_IP_BUF->proto; + /* Insert source routing header (as first ext header) */ + UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8; - UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF(uip_ext_len)->seg_left = path_len; + UIP_RH_BUF(0)->len = (ext_len - 8) / 8; + UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH; + UIP_RH_BUF(0)->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4; + UIP_RPL_SRH_BUF(0)->cmpr = (cmpri << 4) + cmpre; + UIP_RPL_SRH_BUF(0)->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ node = dest_node; - hop_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + ext_len - padding; /* Pointer where to write the next hop compressed address */ + hop_ptr = ((uint8_t *)UIP_RH_BUF(0)) + 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); @@ -456,8 +410,7 @@ insert_srh_header(void) UIP_IP_BUF->len[0]++; } - uip_ext_len += ext_len; - uip_len += ext_len; + uipbuf_add_ext_hdr(ext_len); return 1; } @@ -466,44 +419,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; + int opt_offset = 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 && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->opt_len, - uip_ext_len); + LOG_ERR("Hop-by-hop extension header has wrong size (%u)\n", + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len); return 0; /* Drop */ } - instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); + instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = instance->instance_id; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN)) { + if((UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags & RPL_HDR_OPT_DOWN)) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_FWD_ERR; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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 */ @@ -522,37 +468,30 @@ 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(uip_ext_len, uip_ext_opt_offset)->flags &= ~RPL_HDR_OPT_DOWN; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_DOWN; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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; + int opt_offset = 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; } @@ -560,25 +499,25 @@ insert_hbh_header(const rpl_instance_t *instance) 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(uip_ext_len)->next = UIP_IP_BUF->proto; + /* Insert HBH header (as first ext header) */ + UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF(uip_ext_len)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = instance->instance_id; - uip_len += RPL_HOP_BY_HOP_LEN; + UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = instance->instance_id; + 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]++; } - uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; + uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); /* Update header before returning */ return update_hbh_header(); @@ -587,52 +526,34 @@ 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(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) { - /* Remove hop-by-hop and routing headers */ - *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; - rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->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(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN); - } else { - uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; - break; - default: - return; + next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, 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" */ + UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); + UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + memmove(next_header, next_header + ext_len, uip_len - (next_header - UIP_IP_BUF_CHAR)); + /* 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_IP_BUF_CHAR), &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.h b/os/net/routing/rpl-classic/rpl.h index db87cc824..170c97e58 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(int, 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); diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 02a681476..26d13c8ec 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -57,31 +57,12 @@ 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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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_IP_BUF_CHAR, uip_len, UIP_PROTO_ROUTING); if(!rpl_is_addr_in_our_dag(&UIP_IP_BUF->destipaddr)) { return 0; @@ -90,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(uip_ext_len)->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. @@ -100,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; @@ -121,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_IP_BUF_CHAR, 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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; - break; - default: - uip_next_hdr = NULL; - break; - } - } - - if(uip_next_hdr == NULL || *uip_next_hdr != UIP_PROTO_ROUTING - || UIP_RH_BUF(uip_ext_len)->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(uip_ext_len)->seg_left; - ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8; - cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4; - cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f; - padding = UIP_RPL_SRH_BUF(uip_ext_len)->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; @@ -166,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(uip_ext_len)) + 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] */ @@ -179,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(uip_ext_len)->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; } /*---------------------------------------------------------------------------*/ @@ -293,7 +251,7 @@ 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; } @@ -303,23 +261,23 @@ insert_srh_header(void) uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN); memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len); - /* Insert source routing header */ - UIP_RH_BUF(uip_ext_len)->next = UIP_IP_BUF->proto; + /* Insert source routing header (as first ext header) */ + UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8; - UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF(uip_ext_len)->seg_left = path_len; + UIP_RH_BUF(0)->len = (ext_len - 8) / 8; + UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH; + UIP_RH_BUF(0)->seg_left = path_len; /* Initialize RPL Source Routing Header */ - UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4; + UIP_RPL_SRH_BUF(0)->cmpr = (cmpri << 4) + cmpre; + UIP_RPL_SRH_BUF(0)->pad = padding << 4; /* Initialize addresses field (the actual source route). * From last to first. */ node = dest_node; - hop_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + ext_len - padding; /* Pointer where to write the next hop compressed address */ + hop_ptr = ((uint8_t *)UIP_RH_BUF(0)) + 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); @@ -341,14 +299,13 @@ insert_srh_header(void) UIP_IP_BUF->len[0]++; } - uip_ext_len += ext_len; - uip_len += ext_len; + uipbuf_add_ext_hdr(ext_len); return 1; } /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int uip_ext_opt_offset) +rpl_ext_header_hbh_update(int ext_offset, int opt_offset) { int down; int rank_error_signaled; @@ -356,32 +313,32 @@ 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(uip_ext_len, uip_ext_opt_offset)->opt_type; - uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len; + uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type; + uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_len; - if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + if(UIP_HBHO_BUF(ext_offset)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) || opt_type != UIP_EXT_HDR_OPT_RPL || 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(uip_ext_len)->len, opt_type, opt_len); + UIP_HBHO_BUF(ext_offset)->len, opt_type, opt_len); return 0; /* Drop */ } - if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance) { + if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance) { LOG_ERR("unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance); + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance); return 0; /* Drop */ } - if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) { + if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) { LOG_ERR("forward error!\n"); return 0; /* Drop */ } - down = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank); + down = (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; + sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->senderrank); sender = nbr_table_get_from_lladdr(rpl_neighbors, packetbuf_addr(PACKETBUF_ADDR_SENDER)); - rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; + rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; sender_closer = sender_rank < curr_instance.dag.rank; loop_detected = (down && !sender_closer) || (!down && sender_closer); @@ -395,7 +352,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) if(loop_detected) { /* Set forward error flag */ - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; + UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; } return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled); @@ -407,34 +364,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; + int opt_offset = 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 && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { + if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) + || UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->opt_len, uip_ext_len); + LOG_ERR("hop-by-hop extension header has wrong size (%u)\n", + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len); return 0; /* Drop */ } - if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance) { + if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = curr_instance.instance_id; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; } - uip_ext_len = last_uip_ext_len; return 1; } /*---------------------------------------------------------------------------*/ @@ -445,19 +395,13 @@ 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; + int opt_offset = 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; } @@ -465,25 +409,25 @@ insert_hbh_header(void) 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(uip_ext_len)->next = UIP_IP_BUF->proto; + /* Insert HBH header (as first ext header) */ + UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF(uip_ext_len)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = curr_instance.instance_id; - uip_len += RPL_HOP_BY_HOP_LEN; + UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); + UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; + 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]++; } - uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; + uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); /* Update header before returning */ return update_hbh_header(); @@ -520,54 +464,35 @@ 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(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) { - /* Remove hop-by-hop and routing headers */ - *uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next; - rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->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(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN); - } else { - uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8; - break; - default: - return; + next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, 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" */ + UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); + UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + memmove(next_header, next_header + ext_len, uip_len - (next_header - UIP_IP_BUF_CHAR)); + /* 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_IP_BUF_CHAR), &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..7576c6a57 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.h +++ b/os/net/routing/rpl-lite/rpl-ext-header.h @@ -63,12 +63,14 @@ 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 +* \param ext_offset The offset within the uIP packet where * extension headers start +* \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(int ext_offset, int opt_offset); /** * Adds/updates all RPL extension headers to current uIP packet. From b4d45d7f563a1f3a61186995b0dd07ee5d59b5ef Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 23:28:58 +0200 Subject: [PATCH 057/184] Removed comment that was no longer necessary --- os/net/ipv6/uip-nd6.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 9fc7429fe..7728f2fe2 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -84,14 +84,6 @@ /*------------------------------------------------------------------*/ /** @{ */ /** \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 */ /**@{ Pointers to messages just after icmp header */ From d4bc09e0027b30bc398536b6403917e5a1c58d1b Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 23:33:02 +0200 Subject: [PATCH 058/184] Move function for clearing uip_buf to uipbuf module --- examples/slip-radio/slip-radio.c | 2 +- os/net/ipv6/multicast/esmrf.c | 4 ++-- os/net/ipv6/multicast/roll-tm.c | 2 +- os/net/ipv6/multicast/smrf.c | 2 +- os/net/ipv6/tcpip.c | 8 ++++---- os/net/ipv6/uip-icmp6.c | 8 ++++---- os/net/ipv6/uip-nd6.c | 14 ++++++------- os/net/ipv6/uip.h | 13 ------------ os/net/ipv6/uip6.c | 12 +++++------ os/net/ipv6/uipbuf.c | 9 +++++++++ os/net/ipv6/uipbuf.h | 5 +++++ os/net/routing/rpl-classic/rpl-icmp6.c | 20 +++++++++---------- os/net/routing/rpl-lite/rpl-icmp6.c | 8 ++++---- os/services/ip64/ip64-slip-interface.c | 6 +++--- .../rpl-border-router/embedded/slip-bridge.c | 8 ++++---- tools/sky/uip6-bridge/sicslow_ethernet.c | 12 +++++------ tools/sky/uip6-bridge/uip6-bridge-tap.c | 2 +- 17 files changed, 68 insertions(+), 67 deletions(-) diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index a20bd8676..84045e7e1 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -231,7 +231,7 @@ slip_input_callback(void) if(!cmd_input(&uip_buf[UIP_LLH_LEN], uip_len)) { cmd_send((uint8_t *)"EUnknown command", 16); } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index 746f2f03b..b418d5322 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -244,7 +244,7 @@ icmp_input() /* If we enter here, we will definitely forward */ tcpip_ipv6_output(); } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void @@ -254,7 +254,7 @@ mcast_fwd(void *p) uip_len = mcast_len; UIP_IP_BUF->ttl--; tcpip_output(NULL); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static uint8_t diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index c942dfd46..cc0b09ac2 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -1376,7 +1376,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 bb23b060b..c0e3bf0d0 100644 --- a/os/net/ipv6/multicast/smrf.c +++ b/os/net/ipv6/multicast/smrf.c @@ -84,7 +84,7 @@ mcast_fwd(void *p) uip_len = mcast_len; UIP_IP_BUF->ttl--; tcpip_output(NULL); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static uint8_t diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index d78cae510..16176e6e2 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -125,7 +125,7 @@ tcpip_output(const uip_lladdr_t *a) return ret; } else { /* Ok, ignore and drop... */ - uip_clear_buf(); + uipbuf_clear(); return 0; } } @@ -448,7 +448,7 @@ tcpip_input(void) NETSTACK_IP_PROCESS) { process_post_synch(&tcpip_process, PACKET_INPUT, NULL); } /* else - do nothing and drop */ - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void @@ -652,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; } @@ -740,7 +740,7 @@ send_packet: } exit: - uip_clear_buf(); + uipbuf_clear(); return; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index c4003352f..a7e42c55c 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -156,7 +156,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { /* check if originating packet is not an ICMP error */ uint16_t shift; if(uip_last_proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) { - uip_clear_buf(); + uipbuf_clear(); return; } @@ -185,7 +185,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { /* 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; } @@ -195,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 { @@ -286,7 +286,7 @@ echo_reply_input(void) } } - uip_clear_buf(); + uipbuf_clear(); return; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 7728f2fe2..52e19eff5 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -314,7 +314,7 @@ create_na: #if UIP_CONF_ROUTER flags = flags | UIP_ND6_NA_FLAG_ROUTER; #endif - uip_clear_buf(); + uipbuf_clear(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; @@ -348,7 +348,7 @@ create_na: return; discard: - uip_clear_buf(); + uipbuf_clear(); return; } #endif /* UIP_ND6_SEND_NA */ @@ -359,7 +359,7 @@ discard: void uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) { - uip_clear_buf(); + uipbuf_clear(); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; @@ -388,7 +388,7 @@ 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] = @@ -595,7 +595,7 @@ na_input(void) #endif /*UIP_CONF_IPV6_QUEUE_PKT */ discard: - uip_clear_buf(); + uipbuf_clear(); return; } #endif /* UIP_ND6_SEND_NS */ @@ -691,7 +691,7 @@ rs_input(void) uip_ds6_send_ra_sollicited(); discard: - uip_clear_buf(); + uipbuf_clear(); return; } @@ -1082,7 +1082,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.h b/os/net/ipv6/uip.h index 49a7a0b21..9deedb726 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -1340,19 +1340,6 @@ extern uint8_t uip_last_proto; 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. - */ -#define uip_clear_buf() { \ - uip_len = 0; \ - uip_ext_len = 0; \ - uip_last_proto = 0; \ - uipbuf_clear_attr();\ -} - /** * Representation of a uIP TCP connection. * diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 4ded21bdc..dce44552b 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -511,7 +511,7 @@ uip_remove_ext_hdr(void) uip_ext_len, uip_len); if(uip_len < UIP_IPH_LEN + uip_ext_len) { LOG_ERR("uip_len too short compared to ext len\n"); - uip_clear_buf(); + uipbuf_clear(); return; } last_uip_ext_len = uip_ext_len; @@ -802,7 +802,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); @@ -948,7 +948,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. */ @@ -1473,7 +1473,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) { @@ -1989,7 +1989,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; @@ -2322,7 +2322,7 @@ uip_process(uint8_t flag) return; drop: - uip_clear_buf(); + uipbuf_clear(); uip_ext_bitmap = 0; uip_flags = 0; return; diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index efa2413e9..876385890 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -38,6 +38,15 @@ static uint16_t uipbuf_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) diff --git a/os/net/ipv6/uipbuf.h b/os/net/ipv6/uipbuf.h index a2e091015..3ced3cd45 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -35,6 +35,11 @@ #include "contiki.h" +/** + * \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 diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index 5230ab4e4..baa6b08a7 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -248,7 +248,7 @@ dis_input(void) } } } - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -468,7 +468,7 @@ dio_input(void) rpl_process_dio(&from, &dio); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -807,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); } @@ -897,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); } @@ -1011,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); } @@ -1044,7 +1044,7 @@ dao_input(void) } discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ #if RPL_WITH_DAO_ACK @@ -1283,7 +1283,7 @@ dao_ack_input(void) instance = rpl_get_instance(instance_id); if(instance == NULL) { - uip_clear_buf(); + uipbuf_clear(); return; } @@ -1291,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 { @@ -1300,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; } @@ -1360,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-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index 260f9b168..d376ff5e8 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -143,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 @@ -325,7 +325,7 @@ dio_input(void) rpl_process_dio(&from, &dio); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -536,7 +536,7 @@ dao_input(void) rpl_process_dao(&from, &dao); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void @@ -647,7 +647,7 @@ dao_ack_input(void) rpl_process_dao_ack(sequence, status); discard: - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ void diff --git a/os/services/ip64/ip64-slip-interface.c b/os/services/ip64/ip64-slip-interface.c index 665a342d9..209dfcb91 100644 --- a/os/services/ip64/ip64-slip-interface.c +++ b/os/services/ip64/ip64-slip-interface.c @@ -57,7 +57,7 @@ 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(); + uipbuf_clear(); #if 0 if(uip_buf[UIP_LLH_LEN + 1] == 'P') { uip_ipaddr_t prefix; @@ -84,7 +84,7 @@ 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 @@ -98,7 +98,7 @@ input_callback(void) uip_len = len; /* PRINTF("send len %d\n", len); */ } else { - uip_clear_buf(); + uipbuf_clear(); } } } diff --git a/os/services/rpl-border-router/embedded/slip-bridge.c b/os/services/rpl-border-router/embedded/slip-bridge.c index ff980ea69..6ce3f79fd 100644 --- a/os/services/rpl-border-router/embedded/slip-bridge.c +++ b/os/services/rpl-border-router/embedded/slip-bridge.c @@ -61,7 +61,7 @@ request_prefix(void) uip_buf[1] = 'P'; uip_len = 2; slip_write(uip_buf, uip_len); - uip_clear_buf(); + uipbuf_clear(); } /*---------------------------------------------------------------------------*/ static void @@ -77,14 +77,14 @@ slip_input_callback(void) memset(&prefix, 0, 16); memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 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]); @@ -100,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/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 5274a7833..4acd660ff 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -236,13 +236,13 @@ void mac_ethernetToLowpan(uint8_t * ethHeader) 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(); + uipbuf_clear(); return; } // In sniffer mode we don't ever send anything if (usbstick_mode.sendToRf == 0) { - uip_clear_buf(); + uipbuf_clear(); return; } @@ -261,7 +261,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader) /* 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(); + uipbuf_clear(); return; } else { PRINTF("eth2low: Addressed packet received... "); @@ -269,7 +269,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader) if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) { PRINTF(" translation failed\n"); /* rndis_stat.txbad++; */ - uip_clear_buf(); + uipbuf_clear(); return; } PRINTF(" translated OK\n"); @@ -293,7 +293,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader) } } - uip_clear_buf(); + uipbuf_clear(); } @@ -341,7 +341,7 @@ void mac_LowpanToEthernet(void) /* rndis_send(uip_buf, uip_len, 1); */ /* rndis_stat.rxok++; */ -/* uip_clear_buf(); */ +/* uipbuf_clear(); */ } /** diff --git a/tools/sky/uip6-bridge/uip6-bridge-tap.c b/tools/sky/uip6-bridge/uip6-bridge-tap.c index 19ce22a6f..3386c2039 100644 --- a/tools/sky/uip6-bridge/uip6-bridge-tap.c +++ b/tools/sky/uip6-bridge/uip6-bridge-tap.c @@ -87,7 +87,7 @@ tcpip_input(void) if(uip_len > 0) { slip_write(uip_buf, uip_len); leds_toggle(LEDS_RED); - uip_clear_buf(); + uipbuf_clear(); } } } From 4018b31123e0f7681c75a8933cb4ba6f38ea2eaa Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Wed, 17 Oct 2018 23:35:58 +0200 Subject: [PATCH 059/184] Removed need for global uip_ext_opt_offset --- os/net/ipv6/uip6.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index dce44552b..c46ab3968 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -130,8 +130,6 @@ uint8_t uip_ext_bitmap = 0; * a header */ 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; @@ -839,9 +837,9 @@ ext_hdr_options_process(void) * 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(uip_ext_len)->len << 3) + 8)) { - switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type) { + uint8_t ext_opt_offset = 2; + while(ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) { + switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type) { /* * for now we do not support any options except padding ones * PAD1 does not make sense as the header must be 8bytes aligned, @@ -849,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; + ext_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(uip_ext_len, uip_ext_opt_offset)->opt_len + 2; + ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, ext_opt_offset)->opt_len + 2; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -864,11 +862,11 @@ 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_len, uip_ext_opt_offset)) { + if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_len, ext_opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len) + 2; + ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len) + 2; return 0; default: /* @@ -884,8 +882,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(uip_ext_len, uip_ext_opt_offset)->type); - switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type & 0xC0) { + LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type); + switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type & 0xC0) { case 0: break; case 0x40: @@ -896,11 +894,11 @@ 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); + (uint32_t)UIP_IPH_LEN + uip_ext_len + ext_opt_offset); return 2; } /* in the cases were we did not discard, update ext_opt* */ - uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len + 2; + ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len + 2; break; } } From aaf06754eac66057aad4d09e82a98925565c3566 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 11:20:34 +0200 Subject: [PATCH 060/184] uipbuf_set_len_field --- os/net/ipv6/multicast/esmrf.c | 3 +-- os/net/ipv6/multicast/roll-tm.c | 6 ++---- os/net/ipv6/uip-icmp6.c | 3 +-- os/net/ipv6/uip-nd6.c | 14 ++++--------- os/net/ipv6/uip.h | 1 + os/net/ipv6/uip6.c | 12 ++++------- os/net/ipv6/uipbuf.c | 10 ++++++++- os/net/ipv6/uipbuf.h | 8 +++++++ os/net/routing/rpl-classic/rpl-ext-header.c | 22 +++++--------------- os/net/routing/rpl-lite/rpl-ext-header.c | 23 +++++---------------- tools/sky/uip6-bridge/sicslow_ethernet.c | 5 ++--- 11 files changed, 42 insertions(+), 65 deletions(-) diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index b418d5322..dab2c7b31 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -156,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; diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index cc0b09ac2..bd4040b55 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -858,8 +858,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; @@ -1353,8 +1352,7 @@ out() /* 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), diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index a7e42c55c..2f393913f 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -206,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(); diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index 52e19eff5..eceeec961 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -318,8 +318,7 @@ create_na: 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; @@ -375,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 @@ -391,8 +389,7 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) 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], UIP_ND6_OPT_SLLAO); @@ -787,8 +784,7 @@ uip_nd6_ra_output(uip_ipaddr_t * dest) } #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; @@ -819,15 +815,13 @@ 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], UIP_ND6_OPT_SLLAO); diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 9deedb726..a09fb6fb2 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -1630,6 +1630,7 @@ void uip_process(uint8_t flag); * after the IP header. hence we split here L3 and L4 headers */ /* The IP header */ + struct uip_ip_hdr { /* IPV6 header */ uint8_t vtc; diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index c46ab3968..d634e2e7d 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -521,8 +521,7 @@ uip_remove_ext_hdr(void) uip_len -= last_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_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); } } /*---------------------------------------------------------------------------*/ @@ -767,8 +766,7 @@ 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); + uipbuf_set_len_field(UIP_IP_BUF, uip_reasslen - UIP_IPH_LEN); LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen, (UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]); @@ -1563,8 +1561,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; @@ -2295,8 +2292,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; diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index 876385890..cefe118a3 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 @@ -71,6 +71,14 @@ uipbuf_set_len(uint16_t len) } } /*---------------------------------------------------------------------------*/ +void +uipbuf_set_len_field(struct uip_ip_hdr *hdr, uint16_t len) +{ + + hdr->len[0] = (len >> 8); + hdr->len[1] = (len & 0xff); +} +/*---------------------------------------------------------------------------*/ /* 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 * diff --git a/os/net/ipv6/uipbuf.h b/os/net/ipv6/uipbuf.h index 3ced3cd45..655fedee9 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -34,6 +34,7 @@ #define UIPBUF_H_ #include "contiki.h" +struct uip_ip_hdr; /** * \brief Resets uIP buffer @@ -54,6 +55,13 @@ bool uipbuf_add_ext_hdr(int16_t len); */ bool uipbuf_set_len(uint16_t len); +/** + * \brief Updates the length field in the uIP buffer + * \param buffer The new IPv6 header + * \param len The new length value + */ +void uipbuf_set_len_field(struct uip_ip_hdr *hdr, uint16_t len); + /** * \brief Get the next IPv6 header. * \param buffer A pointer to the buffer holding the IPv6 packet diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index b175edd38..77cfd0338 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -279,8 +279,7 @@ count_matching_bytes(const void *p1, const void *p2, size_t n) static int insert_srh_header(void) { - /* Implementation of RFC6554 */ - uint8_t temp_len; + /* Implementation of RFC6554 uint8_t path_len; uint8_t ext_len; uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ @@ -403,14 +402,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]++; - } - + /* 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; } @@ -511,13 +505,8 @@ insert_hbh_header(const rpl_instance_t *instance) UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = instance->instance_id; - 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]++; - } - 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(); @@ -544,8 +533,7 @@ rpl_ext_header_remove(void) ext_len = ext_ptr->len * 8 + 8; uipbuf_add_ext_hdr(-ext_len); /* Update length field and rest of packer to the "left" */ - 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); memmove(next_header, next_header + ext_len, uip_len - (next_header - UIP_IP_BUF_CHAR)); /* Update loop variables */ protocol = *prev_proto_ptr; diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 26d13c8ec..6e6eb6c34 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -170,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 */ @@ -292,14 +291,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]++; - } - + /* 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; } @@ -395,7 +389,6 @@ update_hbh_header(void) static int insert_hbh_header(void) { - uint8_t temp_len; int opt_offset = 2; /* Insert hop-by-hop header */ @@ -421,13 +414,8 @@ insert_hbh_header(void) UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; - 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]++; - } - 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(); @@ -481,9 +469,8 @@ rpl_ext_header_remove(void) *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" */ - UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); - UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); + /* 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_IP_BUF_CHAR)); /* Update loop variables */ protocol = *prev_proto_ptr; diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 4acd660ff..5e532b90c 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -492,12 +492,11 @@ int8_t mac_translateIcmpLinkLayer(lltype_t target) } //Adjust the IP header length, as well as uIP length - iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8); + 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); + uipbuf_set_len_field(UIP_IP_BUF, iplen); uip_len += sizechange; From 1cfe9df73e50a013a0baf9577412be6dc0975392 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 31 Aug 2018 16:45:50 +0100 Subject: [PATCH 061/184] CC26xx RF: in polling mode, disable the CPE0 radio interrupt completely --- arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c index db3c6adb3..7e638509d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c @@ -512,9 +512,13 @@ rf_core_setup_interrupts(void) void rf_core_cmd_done_en(bool fg) { - uint32_t irq = fg ? IRQ_LAST_FG_COMMAND_DONE : IRQ_LAST_COMMAND_DONE; + 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; } From 093caff1d3d69385ff44ef51cd6b185869ef0e8b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Thu, 18 Oct 2018 18:16:54 +0100 Subject: [PATCH 062/184] CC13x0/CC26x0 building: also fail with descriptive error message when cc13xxware/cc26xxware exists, but is empty --- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index 00f9ae232..592ddfbd8 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -1,8 +1,8 @@ CPU_ABS_PATH = arch/cpu/cc26xx-cc13xx 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 From 999e7dc3a7c5e9adad81753dc514fd2a59f65d23 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 11:31:06 +0200 Subject: [PATCH 063/184] Rework uip6.c --- os/net/ipv6/uip-icmp6.c | 3 +- os/net/ipv6/uip-icmp6.h | 12 +- os/net/ipv6/uip6.c | 445 +++++++++----------- os/net/ipv6/uipbuf.c | 7 +- os/net/ipv6/uipbuf.h | 9 +- os/net/routing/rpl-classic/rpl-ext-header.c | 3 +- tools/sky/uip6-bridge/fakeuip.c | 2 +- tools/sky/uip6-bridge/sicslow_ethernet.c | 4 +- 8 files changed, 231 insertions(+), 254 deletions(-) diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index 2f393913f..d9d55a8fb 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -229,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); 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/uip6.c b/os/net/ipv6/uip6.c index d634e2e7d..8b7eea361 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -114,20 +114,10 @@ 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 The final protocol after IPv6 extension headers: @@ -352,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. */ @@ -363,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); } @@ -502,7 +491,6 @@ uip_connect(const uip_ipaddr_t *ripaddr, uint16_t rport) 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("Removing IPv6 extension headers (extlen: %d, uiplen: %d)\n", @@ -512,15 +500,15 @@ uip_remove_ext_hdr(void) uipbuf_clear(); return; } - last_uip_ext_len = uip_ext_len; - uip_ext_len = 0; - UIP_IP_BUF->proto = UIP_EXT_BUF(uip_ext_len)->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. */ + uipbuf_add_ext_hdr(-uip_ext_len); uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); } } @@ -635,11 +623,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 = UIP_FRAG_BUF(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 @@ -651,7 +640,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(uip_ext_len)->id; + uip_id = frag_buf->id; /* Clear the bitmap. */ memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap)); } @@ -662,9 +651,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(uip_ext_len)->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(uip_ext_len)->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); @@ -675,7 +664,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(uip_ext_len)->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); @@ -696,7 +685,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(uip_ext_len)->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; @@ -720,7 +709,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_ext_len) + UIP_FRAGH_LEN, len); + (uint8_t *)frag_buf + UIP_FRAGH_LEN, len); /* Update the bitmap. */ if(offset >> 6 == (offset + len) >> 6) { @@ -767,8 +756,7 @@ uip_reass(void) uip_reasslen += UIP_IPH_LEN + uip_ext_len; memcpy(UIP_IP_BUF, FBUF, uip_reasslen); uipbuf_set_len_field(UIP_IP_BUF, uip_reasslen - UIP_IPH_LEN); - LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen, - (UIP_IP_BUF->len[0] << 8) | UIP_IP_BUF->len[1]); + LOG_INFO("reassembled packet %d (%d)\n", uip_reasslen, uipbuf_get_len_field(UIP_IP_BUF)); return uip_reasslen; @@ -828,16 +816,16 @@ 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(int ext_offset) { /* * 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 */ - uint8_t ext_opt_offset = 2; - while(ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) { - switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type) { + uint8_t opt_offset = 2; + while(opt_offset < ((UIP_EXT_BUF(ext_offset)->len << 3) + 8)) { + switch(UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type) { /* * for now we do not support any options except padding ones * PAD1 does not make sense as the header must be 8bytes aligned, @@ -845,11 +833,11 @@ ext_hdr_options_process(void) */ case UIP_EXT_HDR_OPT_PAD1: LOG_DBG("Processing PAD1 option\n"); - ext_opt_offset += 1; + opt_offset += 1; break; case UIP_EXT_HDR_OPT_PADN: LOG_DBG("Processing PADN option\n"); - ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, ext_opt_offset)->opt_len + 2; + opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(ext_offset, opt_offset)->opt_len + 2; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -860,11 +848,12 @@ 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_len, ext_opt_offset)) { + LOG_DBG("Processing RPL option\n"); + if(!NETSTACK_ROUTING.ext_header_hbh_update(ext_offset, opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len) + 2; + opt_offset += (UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->len) + 2; return 0; default: /* @@ -880,8 +869,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(uip_ext_len, ext_opt_offset)->type); - switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type & 0xC0) { + LOG_DBG("Unrecognized option, MSB 0x%x\n", UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type); + switch(UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type & 0xC0) { case 0: break; case 0x40: @@ -892,23 +881,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 + ext_opt_offset); + (uint32_t)UIP_IPH_LEN + ext_offset + opt_offset); return 2; } /* in the cases were we did not discard, update ext_opt* */ - ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len + 2; + opt_offset += UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->len + 2; 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; @@ -1090,8 +1105,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 @@ -1104,7 +1119,7 @@ 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; } @@ -1113,11 +1128,11 @@ uip_process(uint8_t flag) uip_last_proto = 0; last_header = uipbuf_get_last_header(UIP_IP_BUF_CHAR, uip_len, &uip_last_proto); if(last_header == NULL) { - LOG_ERR("invalid extension header chain"); + LOG_ERR("invalid extension header chain\n"); goto drop; } /* Set uip_ext_len */ - uip_ext_len = last_header - UIP_IP_BUF_CHAR; + uip_ext_len = last_header - UIP_IP_PAYLOAD(0); LOG_INFO("packet received from "); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); @@ -1140,33 +1155,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_IP_BUF_CHAR, uip_len, &protocol, true); + if(next_header != NULL && protocol == UIP_PROTO_HBHO) { + switch(ext_hdr_options_process(next_header - UIP_IP_PAYLOAD(0))) { case 0: - /* continue */ - uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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 +1204,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,38 +1238,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 */ - uip_last_proto = *uip_next_hdr; - goto tcp_input; -#endif /* UIP_TCP */ -#if UIP_UDP - case UIP_PROTO_UDP: - /* UDP, for both IPv4 and IPv6 */ - uip_last_proto = *uip_next_hdr; - goto udp_input; -#endif /* UIP_UDP */ - case UIP_PROTO_ICMP6: - /* ICMPv6 */ - uip_last_proto = *uip_next_hdr; - 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_IP_BUF_CHAR, 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_IP_BUF_CHAR), &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 */ @@ -1290,145 +1263,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 - UIP_IP_PAYLOAD(0))) { case 0: - /*continue*/ - uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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_RH_BUF(uip_ext_len)->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(uip_ext_len)->next; - uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->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 - UIP_IP_PAYLOAD(0))) { + 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_IP_BUF_CHAR, 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_IP_BUF_CHAR)); 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 */ @@ -1612,7 +1580,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; } @@ -1729,7 +1697,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; @@ -2307,8 +2275,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. */ diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index cefe118a3..eaf43e308 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -74,11 +74,16 @@ uipbuf_set_len(uint16_t len) 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 * diff --git a/os/net/ipv6/uipbuf.h b/os/net/ipv6/uipbuf.h index 655fedee9..96b180ee8 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -57,11 +57,18 @@ bool uipbuf_set_len(uint16_t len); /** * \brief Updates the length field in the uIP buffer - * \param buffer The new IPv6 header + * \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. * \param buffer A pointer to the buffer holding the IPv6 packet diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 77cfd0338..91a87079e 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -279,7 +279,7 @@ count_matching_bytes(const void *p1, const void *p2, size_t n) static int insert_srh_header(void) { - /* Implementation of RFC6554 + /* Implementation of RFC6554 */ uint8_t path_len; uint8_t ext_len; uint8_t cmpri, cmpre; /* ComprI and ComprE fields of the RPL Source Routing Header */ @@ -479,7 +479,6 @@ update_hbh_header(void) static int insert_hbh_header(const rpl_instance_t *instance) { - uint8_t temp_len; int opt_offset = 2; /* Insert hop-by-hop header */ diff --git a/tools/sky/uip6-bridge/fakeuip.c b/tools/sky/uip6-bridge/fakeuip.c index 86658429a..6f8d650eb 100644 --- a/tools/sky/uip6-bridge/fakeuip.c +++ b/tools/sky/uip6-bridge/fakeuip.c @@ -104,7 +104,7 @@ 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]) ; + upper_layer_len = uipbuf_get_len_field(UIP_IP_BUF); /* First sum pseudoheader. */ /* IP protocol and length fields. This addition cannot carry. */ diff --git a/tools/sky/uip6-bridge/sicslow_ethernet.c b/tools/sky/uip6-bridge/sicslow_ethernet.c index 5e532b90c..cd60acd57 100644 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ b/tools/sky/uip6-bridge/sicslow_ethernet.c @@ -397,7 +397,7 @@ void slide(uint8_t * data, uint8_t length, int16_t slide); 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); + int16_t len = uipbuf_get_len_field(UIP_IP_BUF); uint16_t iplen; @@ -492,7 +492,7 @@ int8_t mac_translateIcmpLinkLayer(lltype_t target) } //Adjust the IP header length, as well as uIP length - iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8); + iplen = uipbuf_get_len_field(UIP_IP_BUF); iplen += sizechange; len += sizechange; From ea32ab0f12ec1b5dd717d01d6526c49eb4514809 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 17:47:24 +0200 Subject: [PATCH 064/184] Removed UIP_LLH_LEN --- arch/cpu/native/net/tun6-net.c | 4 +- arch/platform/cooja/net/uip-driver.c | 7 +- arch/platform/jn516x/slip.c | 7 +- .../jn516x/tsch/common-conf-jn516x.h | 2 +- .../coap-demo/coap-server/coap-server.c | 1 - examples/slip-radio/slip-radio.c | 5 +- os/dev/slip.c | 7 +- os/net/app-layer/coap/coap-uip.c | 2 +- os/net/ipv6/multicast/esmrf.c | 18 +- os/net/ipv6/multicast/roll-tm.c | 6 +- os/net/ipv6/multicast/smrf.c | 4 +- os/net/ipv6/sicslowpan.c | 6 +- os/net/ipv6/uip-packetqueue.h | 2 +- os/net/ipv6/uip-udp-packet.c | 4 +- os/net/ipv6/uip.h | 10 +- os/net/ipv6/uip6.c | 44 +- os/net/ipv6/uipopt.h | 31 +- os/services/ip64/ip64-arp.c | 22 +- os/services/ip64/ip64-dhcpc.c | 24 +- os/services/ip64/ip64-eth-interface.c | 4 +- os/services/ip64/ip64-slip-interface.c | 22 +- .../rpl-border-router/embedded/slip-bridge.c | 14 +- .../rpl-border-router/native/tun-bridge.c | 4 +- tools/sky/uip6-bridge/Makefile | 39 - tools/sky/uip6-bridge/dev/slip.c | 322 ------- tools/sky/uip6-bridge/dev/slip.h | 92 -- tools/sky/uip6-bridge/fakeuip.c | 134 --- tools/sky/uip6-bridge/project-conf.h | 49 - tools/sky/uip6-bridge/radvd.conf | 16 - tools/sky/uip6-bridge/sicslow_ethernet.c | 879 ------------------ tools/sky/uip6-bridge/sicslow_ethernet.h | 78 -- tools/sky/uip6-bridge/uip6-bridge-tap.c | 150 --- tools/wpcapslip/wpcap.c | 2 +- 33 files changed, 113 insertions(+), 1898 deletions(-) delete mode 100644 tools/sky/uip6-bridge/Makefile delete mode 100644 tools/sky/uip6-bridge/dev/slip.c delete mode 100644 tools/sky/uip6-bridge/dev/slip.h delete mode 100644 tools/sky/uip6-bridge/fakeuip.c delete mode 100644 tools/sky/uip6-bridge/project-conf.h delete mode 100644 tools/sky/uip6-bridge/radvd.conf delete mode 100644 tools/sky/uip6-bridge/sicslow_ethernet.c delete mode 100644 tools/sky/uip6-bridge/sicslow_ethernet.h delete mode 100644 tools/sky/uip6-bridge/uip6-bridge-tap.c 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/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 572d9f71c..41652e181 100644 --- a/arch/platform/jn516x/slip.c +++ b/arch/platform/jn516x/slip.c @@ -116,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 @@ -194,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); @@ -316,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/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/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/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index 84045e7e1..8ef22ff55 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -226,9 +226,8 @@ 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); } uipbuf_clear(); 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-uip.c b/os/net/app-layer/coap/coap-uip.c index 2435b9d2d..8109db20e 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -70,7 +70,7 @@ #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 diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index dab2c7b31..c10ec4d4f 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -114,7 +114,7 @@ static void mcast_fwd(void *p); 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 */ /*---------------------------------------------------------------------------*/ @@ -135,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; @@ -215,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 */ @@ -231,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); @@ -249,7 +249,7 @@ icmp_input() 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); @@ -343,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 bd4040b55..0f865c438 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 /** @@ -1314,7 +1314,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; } diff --git a/os/net/ipv6/multicast/smrf.c b/os/net/ipv6/multicast/smrf.c index c0e3bf0d0..dd24968ba 100644 --- a/os/net/ipv6/multicast/smrf.c +++ b/os/net/ipv6/multicast/smrf.c @@ -80,7 +80,7 @@ static uint8_t fwd_spread; 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); @@ -174,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/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 2a1a9f34f..fa183b686 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -1932,12 +1932,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; } 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 a09fb6fb2..2e83607bd 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -64,7 +64,7 @@ #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 */ +#define UIP_LLIPH_LEN (UIP_IPH_LEN) /* Size of L2 + IP header */ /** * The sums below are quite used in ND. When used for uip_buf, we @@ -72,14 +72,14 @@ * 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_l2_l3_hdr_len (UIP_IPH_LEN + uip_ext_len) +#define uip_l2_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) /** * Direct access to IPv6 header */ -#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf + UIP_LLH_LEN) +#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf) #define UIP_IP_BUF ((struct uip_ip_hdr *)UIP_IP_BUF_CHAR) #define UIP_IP_PAYLOAD(ext) ((unsigned char *)UIP_IP_BUF_CHAR + UIP_IPH_LEN + (ext)) @@ -1780,7 +1780,7 @@ struct uip_udp_hdr { * * \hideinitializer */ -#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_TCPIP_HLEN) #define UIP_PROTO_ICMP 1 #define UIP_PROTO_TCP 6 diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 8b7eea361..19f786d3f 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -321,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); } @@ -587,7 +587,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]; @@ -935,7 +935,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. */ @@ -1072,7 +1072,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(); @@ -1512,10 +1512,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(); @@ -1545,7 +1545,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. */ @@ -1728,7 +1728,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_TCPIP_HLEN + c]; if(opt == TCP_OPT_END) { /* End of options. */ break; @@ -1736,10 +1736,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_TCPIP_HLEN + 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_TCPIP_HLEN + 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; @@ -1748,12 +1748,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_TCPIP_HLEN + 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_TCPIP_HLEN + 1 + c]; } } } @@ -1915,7 +1915,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; @@ -1923,10 +1923,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_TCPIP_HLEN + 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_TCPIP_HLEN + 2 + c] << 8) | + uip_buf[UIP_TCPIP_HLEN + 3 + c]; uip_connr->initialmss = uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16; @@ -1935,12 +1935,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_TCPIP_HLEN + 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_TCPIP_HLEN + 1 + c]; } } } @@ -2054,7 +2054,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 @@ -2307,10 +2307,10 @@ uip_send(const void *data, int len) int copylen; if(uip_sappdata != NULL) { - copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN - + copylen = MIN(len, UIP_BUFSIZE - UIP_TCPIP_HLEN - (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_TCPIP_HLEN); } if(copylen > 0) { uip_slen = copylen; diff --git a/os/net/ipv6/uipopt.h b/os/net/ipv6/uipopt.h index f01689f4f..bd2dcc502 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. * @@ -435,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_TCPIP_HLEN. */ #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_TCPIP_HLEN) #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_TCPIP_HLEN) */ #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_TCPIP_HLEN) #endif /* UIP_CONF_TCP_MSS */ /** diff --git a/os/services/ip64/ip64-arp.c b/os/services/ip64/ip64-arp.c index 75197558d..daf27d959 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_TCPIP_HLEN]; 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 d70b7576a..dc89610e5 100644 --- a/os/services/ip64/ip64-eth-interface.c +++ b/os/services/ip64/ip64-eth-interface.c @@ -60,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); @@ -94,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 209dfcb91..fb4f69627 100644 --- a/os/services/ip64/ip64-slip-interface.c +++ b/os/services/ip64/ip64-slip-interface.c @@ -55,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]); + 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 */ @@ -91,10 +91,10 @@ input_callback(void) 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 { @@ -127,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 6ce3f79fd..b1349ac0a 100644 --- a/os/services/rpl-border-router/embedded/slip-bridge.c +++ b/os/services/rpl-border-router/embedded/slip-bridge.c @@ -68,14 +68,14 @@ 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); uipbuf_clear(); @@ -86,9 +86,9 @@ slip_input_callback(void) } 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 */ 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/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 7cde6437d..000000000 --- a/tools/sky/uip6-bridge/dev/slip.c +++ /dev/null @@ -1,322 +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" - -#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 6f8d650eb..000000000 --- a/tools/sky/uip6-bridge/fakeuip.c +++ /dev/null @@ -1,134 +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 - -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 = uipbuf_get_len_field(UIP_IP_BUF); - - /* 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/project-conf.h b/tools/sky/uip6-bridge/project-conf.h deleted file mode 100644 index 651d45cda..000000000 --- a/tools/sky/uip6-bridge/project-conf.h +++ /dev/null @@ -1,49 +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 - */ - -#ifndef BRIDGE_CONF_H_ -#define BRIDGE_CONF_H_ - -#undef UIP_CONF_ROUTER - -#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_ */ 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 cd60acd57..000000000 --- a/tools/sky/uip6-bridge/sicslow_ethernet.c +++ /dev/null @@ -1,879 +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 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++; */ - uipbuf_clear(); - return; - } - - // In sniffer mode we don't ever send anything - if (usbstick_mode.sendToRf == 0) { - uipbuf_clear(); - 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++; */ - uipbuf_clear(); - 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++; */ - uipbuf_clear(); - 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++; */ - } - } - - uipbuf_clear(); - -} - - -/** - * \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++; */ -/* uipbuf_clear(); */ -} - -/** - * \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_OPTS(x) ((icmp_opts_t *)UIP_IP_PAYLOAD(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 = uipbuf_get_len_field(UIP_IP_BUF); - - 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 = uipbuf_get_len_field(UIP_IP_BUF); - iplen += sizechange; - len += sizechange; - - uipbuf_set_len_field(UIP_IP_BUF, iplen); - - 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 3386c2039..000000000 --- a/tools/sky/uip6-bridge/uip6-bridge-tap.c +++ /dev/null @@ -1,150 +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 - -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); - uipbuf_clear(); - } - } -} -/*---------------------------------------------------------------------------*/ -/* 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..7406d662f 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_TCPIP_HLEN];*/ return sizeof(struct arp_hdr); } From 9b66b6931d7f64a4ac6eb75eb347f84d7263d43a Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 17:48:08 +0200 Subject: [PATCH 065/184] Removed UIP_IP_BUF_CHAR --- os/net/ipv6/uip-icmp6.c | 2 +- os/net/ipv6/uip.h | 5 ++--- os/net/ipv6/uip6.c | 12 ++++++------ os/net/routing/rpl-classic/rpl-ext-header.c | 10 +++++----- os/net/routing/rpl-lite/rpl-ext-header.c | 10 +++++----- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index d9d55a8fb..18dcef89c 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -174,7 +174,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { shift = UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ICMP6_ERROR_LEN; uip_len += shift; uip_len = MIN(uip_len, UIP_LINK_MTU); - memmove(UIP_IP_BUF_CHAR + shift, (void *)UIP_IP_BUF, uip_len - shift); + memmove(uip_buf + shift, (void *)UIP_IP_BUF, uip_len - shift); UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 2e83607bd..78b1fa305 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -79,9 +79,8 @@ /** * Direct access to IPv6 header */ -#define UIP_IP_BUF_CHAR ((unsigned char *)uip_buf) -#define UIP_IP_BUF ((struct uip_ip_hdr *)UIP_IP_BUF_CHAR) -#define UIP_IP_PAYLOAD(ext) ((unsigned char *)UIP_IP_BUF_CHAR + UIP_IPH_LEN + (ext)) +#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) diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 19f786d3f..a6fa4494e 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -1126,7 +1126,7 @@ uip_process(uint8_t flag) /* 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_IP_BUF_CHAR, uip_len, &uip_last_proto); + 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; @@ -1159,7 +1159,7 @@ uip_process(uint8_t flag) * the packet. */ - next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, uip_len, &protocol, true); + 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 - UIP_IP_PAYLOAD(0))) { case 0: @@ -1246,9 +1246,9 @@ uip_process(uint8_t flag) /* IPv6 extension header processing: loop until reaching upper-layer protocol */ uip_ext_bitmap = 0; - for(next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, uip_len, &protocol, true); + 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_IP_BUF_CHAR), &protocol, false)) { + 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) { @@ -1354,7 +1354,7 @@ uip_process(uint8_t flag) /* 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_IP_BUF_CHAR, uip_len, &protocol, true); + next_header = uipbuf_get_next_header(uip_buf, uip_len, &protocol, true); break; #else /* UIP_CONF_IPV6_REASSEMBLY */ UIP_STAT(++uip_stat.ip.drop); @@ -1393,7 +1393,7 @@ uip_process(uint8_t flag) * 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)(next_header - UIP_IP_BUF_CHAR)); + 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\n"); diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 91a87079e..2a77ddbc7 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -177,7 +177,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) uip_sr_node_t *root_node; /* Look for routing ext header */ - rh_header = (struct uip_routing_hdr *)uipbuf_search_header(UIP_IP_BUF_CHAR, uip_len, UIP_PROTO_ROUTING); + 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); @@ -209,7 +209,7 @@ rpl_ext_header_srh_update(void) struct uip_rpl_srh_hdr *srh_header; /* Look for routing ext header */ - rh_header = (struct uip_routing_hdr *)uipbuf_search_header(UIP_IP_BUF_CHAR, uip_len, UIP_PROTO_ROUTING); + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); if(rh_header != NULL && rh_header->routing_type == RPL_RH_TYPE_SRH) { /* SRH found, now look for next hop */ @@ -521,7 +521,7 @@ rpl_ext_header_remove(void) struct uip_ext_hdr *ext_ptr; struct uip_ext_hdr_opt *opt_ptr; - next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, uip_len, &protocol, true); + 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)) { @@ -533,12 +533,12 @@ rpl_ext_header_remove(void) 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_IP_BUF_CHAR)); + 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_IP_BUF_CHAR), &protocol, false); + 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.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 6e6eb6c34..9811771a0 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -62,7 +62,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr) uip_sr_node_t *root_node; /* Look for routing ext header */ - rh_header = (struct uip_routing_hdr *)uipbuf_search_header(UIP_IP_BUF_CHAR, uip_len, UIP_PROTO_ROUTING); + 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; @@ -100,7 +100,7 @@ rpl_ext_header_srh_update(void) uip_ipaddr_t current_dest_addr; /* Look for routing ext header */ - rh_header = (struct uip_routing_hdr *)uipbuf_search_header(UIP_IP_BUF_CHAR, uip_len, UIP_PROTO_ROUTING); + rh_header = (struct uip_routing_hdr *)uipbuf_search_header(uip_buf, uip_len, UIP_PROTO_ROUTING); if(rh_header == NULL || rh_header->routing_type != RPL_RH_TYPE_SRH) { LOG_INFO("SRH not found\n"); @@ -459,7 +459,7 @@ rpl_ext_header_remove(void) struct uip_ext_hdr *ext_ptr; struct uip_ext_hdr_opt *opt_ptr; - next_header = uipbuf_get_next_header(UIP_IP_BUF_CHAR, uip_len, &protocol, true); + 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)) { @@ -471,12 +471,12 @@ rpl_ext_header_remove(void) 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_IP_BUF_CHAR)); + 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_IP_BUF_CHAR), &protocol, false); + 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; } From 8456c544d8a4cf9d1cf78cc7a8757dd35eed314c Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 17:54:34 +0200 Subject: [PATCH 066/184] Simplify uip.h definitions --- os/net/ipv6/multicast/esmrf.c | 4 +-- os/net/ipv6/multicast/roll-tm.c | 4 +-- os/net/ipv6/sicslowpan.c | 2 +- os/net/ipv6/uip-nd6.c | 8 +++--- os/net/ipv6/uip.h | 13 +--------- os/net/ipv6/uip6.c | 28 ++++++++++----------- os/net/ipv6/uipopt.h | 8 +++--- os/net/routing/rpl-classic/rpl-ext-header.c | 6 ++--- os/net/routing/rpl-lite/rpl-ext-header.c | 6 ++--- os/services/ip64/ip64-arp.c | 2 +- tools/wpcapslip/wpcap.c | 2 +- 11 files changed, 36 insertions(+), 47 deletions(-) diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index c10ec4d4f..169064b25 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -201,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); diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 0f865c438..87121fc6d 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -1146,10 +1146,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) { diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index fa183b686..44851e93d 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -121,7 +121,7 @@ #define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN]) #define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN]) -#define UIP_IPPAYLOAD_BUF_POS(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)) /** @} */ diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index eceeec961..f6efc83de 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -201,7 +201,7 @@ ns_input(void) #endif /* UIP_CONF_IPV6_CHECKS */ 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)) { @@ -328,7 +328,7 @@ 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; @@ -391,7 +391,7 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt) } 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 = @@ -823,7 +823,7 @@ uip_nd6_rs_output(void) uip_len = uip_l3_icmp_hdr_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); } diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 78b1fa305..4e915fe90 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -62,18 +62,7 @@ #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_IPH_LEN) /* Size of L2 + IP header */ -/** - * 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_IPH_LEN + uip_ext_len) -#define uip_l2_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) #define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) /** @@ -1779,7 +1768,7 @@ struct uip_udp_hdr { * * \hideinitializer */ -#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_TCPIP_HLEN) +#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_IPTCPH_LEN) #define UIP_PROTO_ICMP 1 #define UIP_PROTO_TCP 6 diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index a6fa4494e..6769561fc 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -1728,7 +1728,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 + c]; + opt = uip_buf[UIP_IPTCPH_LEN + c]; if(opt == TCP_OPT_END) { /* End of options. */ break; @@ -1736,9 +1736,9 @@ uip_process(uint8_t flag) ++c; /* NOP option. */ } else if(opt == TCP_OPT_MSS && - uip_buf[UIP_TCPIP_HLEN + 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 + 2 + c] << 8) | + 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; @@ -1748,12 +1748,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 + 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 + 1 + c]; + c += uip_buf[UIP_IPTCPH_LEN + 1 + c]; } } } @@ -1923,10 +1923,10 @@ uip_process(uint8_t flag) ++c; /* NOP option. */ } else if(opt == TCP_OPT_MSS && - uip_buf[UIP_TCPIP_HLEN + 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 + 2 + c] << 8) | - uip_buf[UIP_TCPIP_HLEN + 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; @@ -1935,12 +1935,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 + 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 + 1 + c]; + c += uip_buf[UIP_IPTCPH_LEN + 1 + c]; } } } @@ -2123,7 +2123,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. */ @@ -2132,7 +2132,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; } @@ -2307,10 +2307,10 @@ uip_send(const void *data, int len) int copylen; if(uip_sappdata != NULL) { - copylen = MIN(len, UIP_BUFSIZE - 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_TCPIP_HLEN); + copylen = MIN(len, UIP_BUFSIZE - UIP_IPTCPH_LEN); } if(copylen > 0) { uip_slen = copylen; diff --git a/os/net/ipv6/uipopt.h b/os/net/ipv6/uipopt.h index bd2dcc502..a75c59ea0 100644 --- a/os/net/ipv6/uipopt.h +++ b/os/net/ipv6/uipopt.h @@ -414,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_TCPIP_HLEN. + * UIP_BUFSIZE - UIP_IPTCPH_LEN. */ #ifdef UIP_CONF_TCP_MSS -#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - 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_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_TCPIP_HLEN) +#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_IPTCPH_LEN) #endif /* UIP_CONF_TCP_MSS */ /** diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 2a77ddbc7..94367483a 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -367,9 +367,9 @@ insert_srh_header(void) } /* Move existing ext headers and payload 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); + 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 (as first ext header) */ UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 9811771a0..e5adad703 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -256,9 +256,9 @@ insert_srh_header(void) } /* Move existing ext headers and payload 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); + 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 (as first ext header) */ UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; diff --git a/os/services/ip64/ip64-arp.c b/os/services/ip64/ip64-arp.c index daf27d959..6fd996920 100644 --- a/os/services/ip64/ip64-arp.c +++ b/os/services/ip64/ip64-arp.c @@ -409,7 +409,7 @@ ip64_arp_create_arp_request(uint8_t *llhdr, const uint8_t *nlhdr) arp_hdr->protolen = 4; arp_hdr->ethhdr.type = UIP_HTONS(IP64_ETH_TYPE_ARP); - uip_appdata = &uip_buf[UIP_TCPIP_HLEN]; + uip_appdata = &uip_buf[UIP_IPTCPH_LEN]; return sizeof(struct arp_hdr); } diff --git a/tools/wpcapslip/wpcap.c b/tools/wpcapslip/wpcap.c index 7406d662f..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_appdata = &uip_buf[UIP_IPTCPH_LEN];*/ return sizeof(struct arp_hdr); } From 6c11da58d84cac02e9380e316edfebc02c23460e Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 18:29:37 +0200 Subject: [PATCH 067/184] Rework rpl-ext-header.c --- os/net/ipv6/uip6.c | 2 +- os/net/routing/nullrouting/nullrouting.c | 2 +- os/net/routing/routing.h | 5 +- os/net/routing/rpl-classic/rpl-ext-header.c | 76 ++++++++++----------- os/net/routing/rpl-classic/rpl.h | 2 +- os/net/routing/rpl-lite/rpl-ext-header.c | 64 ++++++++--------- os/net/routing/rpl-lite/rpl-ext-header.h | 5 +- 7 files changed, 77 insertions(+), 79 deletions(-) diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 6769561fc..0ff2e7fc5 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -849,7 +849,7 @@ ext_hdr_options_process(int ext_offset) * present) is processed. */ LOG_DBG("Processing RPL option\n"); - if(!NETSTACK_ROUTING.ext_header_hbh_update(ext_offset, opt_offset)) { + if(!NETSTACK_ROUTING.ext_header_hbh_update(UIP_IP_PAYLOAD(ext_offset), opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index 3443dbb13..318cd1baa 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -118,7 +118,7 @@ ext_header_update(void) } /*---------------------------------------------------------------------------*/ static int -ext_header_hbh_update(int ext_offset, int 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 be1fe0173..4508f0c4e 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -131,14 +131,13 @@ struct routing_driver { * Process and update the routing protocol hob-by-hop * extention headers of the current uIP packet. * - * \param ext_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 ext_offset, int 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-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 94367483a..7212bd6ba 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -62,34 +62,33 @@ /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int ext_offset, int 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(ext_offset)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL - || UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset)->len, - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type, - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset, opt_offset)->instance); + instance = rpl_get_instance(rpl_opt->instance); if(instance == NULL) { - LOG_ERR("Unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance); + LOG_ERR("Unknown instance: %u\n", rpl_opt->instance); return 0; } - if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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 @@ -113,14 +112,14 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) return 0; } down = 0; - if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset, opt_offset)->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(ext_offset, opt_offset)->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; @@ -150,7 +149,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) instance->unicast_dio_target = sender; rpl_schedule_unicast_dio_immediately(instance); } - if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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 */ @@ -159,7 +158,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) } LOG_WARN("Single error tolerated\n"); RPL_STAT(rpl_stats.loop_warnings++); - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; + rpl_opt->flags |= RPL_HDR_OPT_RANK_ERR; return 1; } @@ -414,18 +413,18 @@ update_hbh_header(void) { rpl_instance_t *instance; rpl_parent_t *parent; - int 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(0) + 2); - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { + 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) { - LOG_ERR("Hop-by-hop extension header has wrong size (%u)\n", - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_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(0, opt_offset)->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"); return 0; /* Drop */ @@ -433,17 +432,17 @@ update_hbh_header(void) LOG_INFO("Updating RPL option\n"); /* Update sender rank and instance, will update flags next */ - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->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(0, opt_offset)->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(0, opt_offset)->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 */ @@ -462,11 +461,11 @@ 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(0, opt_offset)->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(0, opt_offset)->flags |= RPL_HDR_OPT_DOWN; + rpl_opt->flags |= RPL_HDR_OPT_DOWN; LOG_DBG("RPL option going down\n"); } } @@ -479,7 +478,8 @@ update_hbh_header(void) static int insert_hbh_header(const rpl_instance_t *instance) { - int 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"); @@ -493,16 +493,16 @@ insert_hbh_header(const rpl_instance_t *instance) memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); /* Insert HBH header (as first ext header) */ - UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; + hbh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = instance->instance_id; + 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; uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); diff --git a/os/net/routing/rpl-classic/rpl.h b/os/net/routing/rpl-classic/rpl.h index 170c97e58..f0c17cac9 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); +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); diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index e5adad703..8a031c099 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -299,7 +299,7 @@ insert_srh_header(void) } /*---------------------------------------------------------------------------*/ int -rpl_ext_header_hbh_update(int ext_offset, int opt_offset) +rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset) { int down; int rank_error_signaled; @@ -307,32 +307,31 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) uint16_t sender_rank; uint8_t sender_closer; rpl_nbr_t *sender; - uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type; - uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset)->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(ext_offset)->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(ext_offset, opt_offset)->instance) { - LOG_ERR("unknown instance: %u\n", - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset, opt_offset)->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(ext_offset, opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; - sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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(ext_offset, opt_offset)->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); @@ -346,7 +345,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) if(loop_detected) { /* Set forward error flag */ - UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->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); @@ -358,25 +357,25 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset) static int update_hbh_header(void) { - int 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)); - if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { - if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) - || UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { + 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) { - LOG_ERR("hop-by-hop extension header has wrong size (%u)\n", - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_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(0, opt_offset)->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"); return 0; /* Drop */ } /* Update sender rank and instance, will update flags next */ - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; + rpl_opt->senderrank = UIP_HTONS(curr_instance.dag.rank); + rpl_opt->instance = curr_instance.instance_id; } return 1; @@ -389,7 +388,8 @@ update_hbh_header(void) static int insert_hbh_header(void) { - int 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"); @@ -403,16 +403,16 @@ insert_hbh_header(void) memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); /* Insert HBH header (as first ext header) */ - UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; + hbh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_HBHO; /* Initialize HBH option */ - UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); - UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; + 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; uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); diff --git a/os/net/routing/rpl-lite/rpl-ext-header.h b/os/net/routing/rpl-lite/rpl-ext-header.h index 7576c6a57..c2d0db5bc 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.h +++ b/os/net/routing/rpl-lite/rpl-ext-header.h @@ -63,14 +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 ext_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 ext_offset, int 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. From 6c583efa3728b37749f3efebba22f89a9a9bf145 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 18:53:34 +0200 Subject: [PATCH 068/184] Rework ext_hdr_options_process --- os/net/ipv6/uip.h | 2 -- os/net/ipv6/uip6.c | 28 +++++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 4e915fe90..505769727 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -95,8 +95,6 @@ * Direct access to extension header options, with explicit ext header and option offset */ #define UIP_EXT_HDR_OPT_BUF(ext, opt) ((struct uip_ext_hdr_opt *)(UIP_IP_PAYLOAD(ext) + (opt))) -#define UIP_EXT_HDR_OPT_PADN_BUF(ext, opt) ((struct uip_ext_hdr_opt_padn *)(UIP_IP_PAYLOAD(ext) + (opt))) -#define UIP_EXT_HDR_OPT_RPL_BUF(ext, opt) ((struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(ext) + (opt))) #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 0ff2e7fc5..e25a12d1c 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -816,7 +816,7 @@ 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(int ext_offset) +ext_hdr_options_process(uint8_t *ext_buf) { /* * Length field in the extension header: length of the header in units of @@ -824,8 +824,10 @@ ext_hdr_options_process(int ext_offset) * length field in an option : the length of data in the option */ uint8_t opt_offset = 2; - while(opt_offset < ((UIP_EXT_BUF(ext_offset)->len << 3) + 8)) { - switch(UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type) { + struct uip_hbho_hdr *ext_hdr = (struct uip_hbho_hdr *)ext_buf; + while(opt_offset < ((ext_hdr->len << 3) + 8)) { + struct uip_ext_hdr_opt *opt_hdr = (struct uip_ext_hdr_opt *)(ext_buf + opt_offset); + 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, @@ -837,7 +839,7 @@ ext_hdr_options_process(int ext_offset) break; case UIP_EXT_HDR_OPT_PADN: LOG_DBG("Processing PADN option\n"); - opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(ext_offset, opt_offset)->opt_len + 2; + opt_offset += ((struct uip_ext_hdr_opt_padn *)opt_hdr)->opt_len + 2; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -849,11 +851,11 @@ ext_hdr_options_process(int ext_offset) * present) is processed. */ LOG_DBG("Processing RPL option\n"); - if(!NETSTACK_ROUTING.ext_header_hbh_update(UIP_IP_PAYLOAD(ext_offset), opt_offset)) { + if(!NETSTACK_ROUTING.ext_header_hbh_update(ext_buf, opt_offset)) { LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - opt_offset += (UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->len) + 2; + opt_offset += opt_hdr->len + 2; return 0; default: /* @@ -869,8 +871,8 @@ ext_hdr_options_process(int ext_offset) * Problem, Code 2, message to the packet's Source Address, * pointing to the unrecognized Option Type. */ - LOG_DBG("Unrecognized option, MSB 0x%x\n", UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type); - switch(UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->type & 0xC0) { + LOG_DBG("Unrecognized option, MSB 0x%x\n", opt_hdr->type); + switch(opt_hdr->type & 0xC0) { case 0: break; case 0x40: @@ -881,11 +883,11 @@ ext_hdr_options_process(int ext_offset) } case 0x80: uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, - (uint32_t)UIP_IPH_LEN + ext_offset + opt_offset); + (ext_buf + opt_offset) - uip_buf); return 2; } /* in the cases were we did not discard, update ext_opt* */ - opt_offset += UIP_EXT_HDR_OPT_BUF(ext_offset, opt_offset)->len + 2; + opt_offset += opt_hdr->len + 2; break; } } @@ -1161,7 +1163,7 @@ uip_process(uint8_t flag) 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 - UIP_IP_PAYLOAD(0))) { + switch(ext_hdr_options_process(next_header)) { case 0: break; /* done */ case 1: @@ -1263,7 +1265,7 @@ uip_process(uint8_t flag) uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO; } #endif /*UIP_CONF_IPV6_CHECKS*/ - switch(ext_hdr_options_process(next_header - UIP_IP_PAYLOAD(0))) { + switch(ext_hdr_options_process(next_header)) { case 0: break; /* done */ case 1: @@ -1287,7 +1289,7 @@ uip_process(uint8_t flag) uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_DESTO1; } #endif /*UIP_CONF_IPV6_CHECKS*/ - switch(ext_hdr_options_process(next_header - UIP_IP_PAYLOAD(0))) { + switch(ext_hdr_options_process(next_header)) { case 0: break; /* done */ case 1: From 655faf0dca0e4a1482eab5af48aa12f34619607f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 18 Oct 2018 19:11:56 +0200 Subject: [PATCH 069/184] Further simplification of uip.h buffers --- os/net/ipv6/multicast/roll-tm.c | 9 +++++---- os/net/ipv6/uip.h | 15 --------------- os/net/ipv6/uip6.c | 2 +- os/net/routing/rpl-classic/rpl-ext-header.c | 18 +++++++++++------- os/net/routing/rpl-lite/rpl-ext-header.c | 18 +++++++++++------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/os/net/ipv6/multicast/roll-tm.c b/os/net/ipv6/multicast/roll-tm.c index 87121fc6d..909ebbfb6 100644 --- a/os/net/ipv6/multicast/roll-tm.c +++ b/os/net/ipv6/multicast/roll-tm.c @@ -456,6 +456,7 @@ static uint16_t last_seq; /*---------------------------------------------------------------------------*/ /* uIPv6 Pointers */ /*---------------------------------------------------------------------------*/ +#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; @@ -1320,11 +1321,11 @@ out() } /* Slide 'right' by HBHO_TOTAL_LEN bytes */ - memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF(0), uip_len - UIP_IPH_LEN); - memset(UIP_EXT_BUF(0), 0, HBHO_TOTAL_LEN); + memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF, uip_len - UIP_IPH_LEN); + memset(UIP_EXT_BUF, 0, HBHO_TOTAL_LEN); - UIP_EXT_BUF(0)->next = UIP_IP_BUF->proto; - UIP_EXT_BUF(0)->len = 0; + UIP_EXT_BUF->next = UIP_IP_BUF->proto; + UIP_EXT_BUF->len = 0; lochbhmptr = UIP_EXT_OPT_FIRST; lochbhmptr->type = HBHO_OPT_TYPE_TRICKLE; diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 505769727..32ffc6ed4 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -81,21 +81,6 @@ #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) -/** - * Direct access to extension headers, with explicit ext header offset - */ -#define UIP_EXT_BUF(ext) ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(ext)) -#define UIP_HBHO_BUF(ext) ((struct uip_hbho_hdr *)UIP_IP_PAYLOAD(ext)) -#define UIP_RH_BUF(ext) ((struct uip_routing_hdr *)UIP_IP_PAYLOAD(ext)) -#define UIP_FRAG_BUF(ext) ((struct uip_frag_hdr *)UIP_IP_PAYLOAD(ext)) -#define UIP_DESTO_BUF(ext) ((struct uip_desto_hdr *)UIP_IP_PAYLOAD(ext)) -#define UIP_RPL_SRH_BUF(ext) ((struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(ext) + RPL_RH_LEN)) - -/** - * Direct access to extension header options, with explicit ext header and option offset - */ -#define UIP_EXT_HDR_OPT_BUF(ext, opt) ((struct uip_ext_hdr_opt *)(UIP_IP_PAYLOAD(ext) + (opt))) - #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" #include "net/linkaddr.h" diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index e25a12d1c..34404b4b8 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -628,7 +628,7 @@ uip_reass(uint8_t *prev_proto_ptr) uint16_t offset=0; uint16_t len; uint16_t i; - struct uip_frag_hdr *frag_buf = UIP_FRAG_BUF(uip_ext_len); + 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 diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index 7212bd6ba..34d9b4907 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -290,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"); @@ -371,22 +375,22 @@ insert_srh_header(void) memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len); /* Insert source routing header (as first ext header) */ - UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; + rh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF(0)->len = (ext_len - 8) / 8; - UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF(0)->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(0)->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF(0)->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(0)) + 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); diff --git a/os/net/routing/rpl-lite/rpl-ext-header.c b/os/net/routing/rpl-lite/rpl-ext-header.c index 8a031c099..cb8dcc190 100644 --- a/os/net/routing/rpl-lite/rpl-ext-header.c +++ b/os/net/routing/rpl-lite/rpl-ext-header.c @@ -180,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"); @@ -261,22 +265,22 @@ insert_srh_header(void) memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len); /* Insert source routing header (as first ext header) */ - UIP_RH_BUF(0)->next = UIP_IP_BUF->proto; + rh_hdr->next = UIP_IP_BUF->proto; UIP_IP_BUF->proto = UIP_PROTO_ROUTING; /* Initialize IPv6 Routing Header */ - UIP_RH_BUF(0)->len = (ext_len - 8) / 8; - UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH; - UIP_RH_BUF(0)->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(0)->cmpr = (cmpri << 4) + cmpre; - UIP_RPL_SRH_BUF(0)->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(0)) + 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); From 9bb648f92223ed00f70fa297561b2b3befdea612 Mon Sep 17 00:00:00 2001 From: Alex Raimondi Date: Thu, 18 Oct 2018 17:15:27 +0200 Subject: [PATCH 070/184] Fixed all-timers example application --- examples/libs/timers/all-timers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 9faa834f572002241f67ad1a53e47ef6459ced3d Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Wed, 29 Aug 2018 22:28:51 +0100 Subject: [PATCH 071/184] Allow the user to configure COAP_CONF_OBSERVE_REFRESH_INTERVAL and allow it to be zero --- os/net/app-layer/coap/coap-conf.h | 4 +++- os/net/app-layer/coap/coap-observe.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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; } From cb962855a46dba83537a9f89bb960c5bcdb79b88 Mon Sep 17 00:00:00 2001 From: Toshio Ito Date: Fri, 19 Oct 2018 22:32:52 +0900 Subject: [PATCH 072/184] fix code style for else --- os/net/mac/tsch/tsch-slot-operation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 5fbf86013..a801bc92e 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -643,7 +643,7 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) mac_tx_status = MAC_TX_ERR; } } - }else { + } else { mac_tx_status = MAC_TX_ERR; } } From 9194e8216868f8e6de5805b1ad5e2c5c9d0bdf81 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 19 Oct 2018 15:45:16 +0200 Subject: [PATCH 073/184] uip6: sanitize parsing of ext header options --- os/net/ipv6/uip6.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 34404b4b8..25e052f34 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -823,10 +823,21 @@ ext_hdr_options_process(uint8_t *ext_buf) * 8 bytes, excluding the first 8 bytes * length field in an option : the length of data in the option */ - uint8_t opt_offset = 2; + uint8_t opt_offset = 2; /* 2 first bytes in ext header */ struct uip_hbho_hdr *ext_hdr = (struct uip_hbho_hdr *)ext_buf; - while(opt_offset < ((ext_hdr->len << 3) + 8)) { + 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 @@ -839,7 +850,7 @@ ext_hdr_options_process(uint8_t *ext_buf) break; case UIP_EXT_HDR_OPT_PADN: LOG_DBG("Processing PADN option\n"); - opt_offset += ((struct uip_ext_hdr_opt_padn *)opt_hdr)->opt_len + 2; + opt_offset += opt_len; break; case UIP_EXT_HDR_OPT_RPL: /* Fixes situation when a node that is not using RPL @@ -855,8 +866,8 @@ ext_hdr_options_process(uint8_t *ext_buf) LOG_ERR("RPL Option Error: Dropping Packet\n"); return 1; } - opt_offset += opt_hdr->len + 2; - return 0; + opt_offset += opt_len; + break; default: /* * check the two highest order bits of the option @@ -887,7 +898,7 @@ ext_hdr_options_process(uint8_t *ext_buf) return 2; } /* in the cases were we did not discard, update ext_opt* */ - opt_offset += opt_hdr->len + 2; + opt_offset += opt_len; break; } } From 995a076262f924524b7423aa8d32812d968264ec Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:24:16 +0100 Subject: [PATCH 074/184] Explicitly set noninteractive frontent --- tools/docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 9d15704ac..6c84ecabf 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,5 +1,7 @@ FROM 32bit/ubuntu:16.04 +ENV DEBIAN_FRONTEND noninteractive + # Tools RUN apt-get update && \ apt-get install -y --no-install-recommends \ From 20fa52997ca02626019f091608c9a604515be2dd Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:25:02 +0100 Subject: [PATCH 075/184] Quiet wget --- tools/docker/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 6c84ecabf..38c04a90c 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -11,21 +11,21 @@ RUN apt-get update && \ && apt-get clean # Install ARM toolchain -RUN wget https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 && \ +RUN wget -nv https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 && \ tar xjf gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 -C /tmp/ && \ cp -f -r /tmp/gcc-arm-none-eabi-5_2-2015q4/* /usr/local/ && \ rm -rf /tmp/gcc-arm-none-eabi-* gcc-arm-none-eabi-*-linux.tar.bz2 # Install msp430 toolchain -RUN wget http://simonduq.github.io/resources/mspgcc-4.7.2-compiled.tar.bz2 && \ +RUN wget -nv http://simonduq.github.io/resources/mspgcc-4.7.2-compiled.tar.bz2 && \ tar xjf mspgcc*.tar.bz2 -C /tmp/ && \ cp -f -r /tmp/msp430/* /usr/local/ && \ rm -rf /tmp/msp430 mspgcc*.tar.bz2 # Install NXP toolchain (partial, with binaries excluded. Download from nxp.com) -RUN wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ - wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part2.tar.bz2 && \ - wget http://simonduq.github.io/resources/jn516x-sdk-4163-1416.tar.bz2 && \ +RUN wget -nv http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ + wget -nv http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part2.tar.bz2 && \ + wget -nv http://simonduq.github.io/resources/jn516x-sdk-4163-1416.tar.bz2 && \ mkdir /tmp/jn516x-sdk /tmp/ba-elf-gcc && \ tar xjf jn516x-sdk-*.tar.bz2 -C /tmp/jn516x-sdk && \ tar xjf ba-elf-gcc-*part1.tar.bz2 -C /tmp/ba-elf-gcc && \ @@ -37,7 +37,7 @@ RUN wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ ENV PATH="/usr/ba-elf-gcc/bin:${PATH}" ## Install nRF52 SDK -RUN wget https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/nrf5_iot_sdk_3288530.zip && \ +RUN wget -nv https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/nrf5_iot_sdk_3288530.zip && \ mkdir /usr/nrf52-sdk && \ unzip nrf5_iot_sdk_3288530.zip -d /usr/nrf52-sdk && \ rm nrf5_iot_sdk_3288530.zip From d756cb6e48abad103752baf307bbec65b132fb65 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:25:14 +0100 Subject: [PATCH 076/184] Quiet git clone --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 38c04a90c..27e476e61 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -90,7 +90,7 @@ RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E && sudo apt-get clean # Download, build and install Renode -RUN git clone https://github.com/renode/renode.git \ +RUN git clone --quiet https://github.com/renode/renode.git \ && cd ${HOME}/renode \ && git checkout v1.3 \ && ./build.sh From 3c9eafc83b7f53f43002e44647ecf60ed0a84b05 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:25:40 +0100 Subject: [PATCH 077/184] Quiet pip output --- tools/docker/Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 27e476e61..e4cb39037 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -46,9 +46,8 @@ ENV NRF52_SDK_ROOT /usr/nrf52-sdk # Install sphinx and sphinx_rtd_theme, required for building and testing the # readthedocs API documentation -RUN pip install --upgrade pip -RUN pip install setuptools -RUN pip install sphinx_rtd_theme sphinx +RUN pip -q install --upgrade pip +RUN pip -q install setuptools && pip -q install sphinx_rtd_theme sphinx # Create user, enable X forwarding, add to group dialout # -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix From 06ad0f26b3c2680e24683f99894e7c971f4a093e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:25:52 +0100 Subject: [PATCH 078/184] Quiet unzip --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index e4cb39037..bd6dd4821 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -39,7 +39,7 @@ ENV PATH="/usr/ba-elf-gcc/bin:${PATH}" ## Install nRF52 SDK RUN wget -nv https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/nrf5_iot_sdk_3288530.zip && \ mkdir /usr/nrf52-sdk && \ - unzip nrf5_iot_sdk_3288530.zip -d /usr/nrf52-sdk && \ + unzip -q nrf5_iot_sdk_3288530.zip -d /usr/nrf52-sdk && \ rm nrf5_iot_sdk_3288530.zip ENV NRF52_SDK_ROOT /usr/nrf52-sdk From b4684e3d5faec000f46db5e1062f81d565caec01 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:26:37 +0100 Subject: [PATCH 079/184] Single docker RUN for all apt- and npm work. Quiet npm and run all of the above without sudo --- tools/docker/Dockerfile | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index bd6dd4821..8b156efb1 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -3,12 +3,20 @@ FROM 32bit/ubuntu:16.04 ENV DEBIAN_FRONTEND noninteractive # Tools -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential doxygen git wget unzip python-serial python-pip \ - default-jdk ant srecord iputils-tracepath rlwrap \ - mosquitto mosquitto-clients gdb \ - && apt-get clean +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ + echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list && \ + apt-get -qq update && \ + apt-get -qq -y --no-install-recommends install \ + build-essential doxygen git wget unzip python-serial python-pip \ + default-jdk ant srecord iputils-tracepath rlwrap \ + mosquitto mosquitto-clients gdb npm \ + mono-complete gksu libgtk2.0-0 screen uml-utilities gtk-sharp2 \ + libcanberra-gtk-module:i386 \ + && apt-get -qq clean + +# Install coap-cli +RUN npm -q install coap-cli -g \ + && sudo ln -s /usr/bin/nodejs /usr/bin/node # Install ARM toolchain RUN wget -nv https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 && \ @@ -75,19 +83,6 @@ WORKDIR ${HOME} RUN echo "#!/bin/bash\nant -Dbasedir=${COOJA} -f ${COOJA}/build.xml run" > ${HOME}/cooja && \ chmod +x ${HOME}/cooja -# Install coap-cli -RUN sudo apt-get install -y npm \ - && sudo apt-get clean \ - && sudo npm install coap-cli -g \ - && sudo ln -s /usr/bin/nodejs /usr/bin/node - -# Install Mono and libcanberra-gtk:i386 (for Renode) -RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ - && echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list \ - && sudo apt-get update \ - && sudo apt-get install -y mono-complete gksu libgtk2.0-0 screen uml-utilities gtk-sharp2 libcanberra-gtk-module:i386 \ - && sudo apt-get clean - # Download, build and install Renode RUN git clone --quiet https://github.com/renode/renode.git \ && cd ${HOME}/renode \ From b25e7bedf93a54c2a4b30ba328ee1bd81fe08dff Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 20 Oct 2018 15:52:47 +0100 Subject: [PATCH 080/184] Redirect apt-get stdout to /dev/null --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 8b156efb1..634f85ea6 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -11,7 +11,7 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E03280 default-jdk ant srecord iputils-tracepath rlwrap \ mosquitto mosquitto-clients gdb npm \ mono-complete gksu libgtk2.0-0 screen uml-utilities gtk-sharp2 \ - libcanberra-gtk-module:i386 \ + libcanberra-gtk-module:i386 > /dev/null \ && apt-get -qq clean # Install coap-cli From c42fae82daea5a63b2b875e4dcb9ff492b07621b Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Sat, 20 Oct 2018 22:25:55 +0200 Subject: [PATCH 081/184] added uipbuf attributes for llsec level and key and added payloadlen in mac --- arch/cpu/nrf52832/ble/ble-mac.c | 9 ++++- os/net/ipv6/sicslowpan.c | 29 +++++++-------- os/net/ipv6/uip6.c | 1 + os/net/ipv6/uipbuf.c | 31 +++++++++++++--- os/net/ipv6/uipbuf.h | 22 +++++++++++ os/net/mac/ble/ble-l2cap.c | 7 ++++ os/net/mac/csma/csma-security.c | 37 +++++++++++++++---- os/net/mac/csma/csma.c | 35 +++++++++++++++++- os/net/mac/csma/csma.h | 11 ++++++ os/net/mac/mac.h | 3 ++ os/net/mac/nullmac/nullmac.c | 9 ++++- os/net/mac/tsch/tsch.c | 13 ++++++- os/net/packetbuf.h | 3 ++ .../native/border-router-mac.c | 24 +++++++++++- 14 files changed, 200 insertions(+), 34 deletions(-) diff --git a/arch/cpu/nrf52832/ble/ble-mac.c b/arch/cpu/nrf52832/ble/ble-mac.c index 4fe1ef934..d604a911d 100644 --- a/arch/cpu/nrf52832/ble/ble-mac.c +++ b/arch/cpu/nrf52832/ble/ble-mac.c @@ -347,6 +347,12 @@ off(void) return 1; } /*---------------------------------------------------------------------------*/ +static int +max_payload(void) +{ + return PACKETBUF_SIZE; +} +/*---------------------------------------------------------------------------*/ static void init(void) { @@ -371,7 +377,8 @@ const struct mac_driver ble_ipsp_mac_driver = { send_packet, NULL, on, - off + off, + max_payload }; /*---------------------------------------------------------------------------*/ /** diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 2789e4e7d..6f15af4f4 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -74,10 +74,6 @@ #include "net/packetbuf.h" #include "net/queuebuf.h" -#if MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED -#include "net/mac/csma/csma-security.h" -#endif /* MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED */ - #include "net/routing/routing.h" /* Log configuration */ @@ -1618,23 +1614,26 @@ output(const linkaddr_t *localdest) return 0; } #endif /* SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC */ - -#if MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED - packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, - FRAME802154_SECURITY_LEVEL_NONE != CSMA_LLSEC_SECURITY_LEVEL); -#endif /* MAC_CONF_WITH_CSMA && LLSEC802154_CONF_ENABLED */ - +#if LLSEC802154_USES_AUX_HEADER + /* copy LLSEC level */ + packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, + uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL)); +#if LLSEC802154_USES_EXPLICIT_KEYS + packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, + uipbuf_get_attr(UIPBUF_ATTR_LLSEC_KEY_ID)); +#endif /* LLSEC802154_USES_EXPLICIT_KEYS */ +#endif /* LLSEC802154_USES_AUX_HEADER */ /* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC. * We calculate it here only to make a better decision of whether the outgoing packet * needs to be fragmented or not. */ packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest); - framer_hdrlen = NETSTACK_FRAMER.length(); - if(framer_hdrlen < 0) { - /* Framing failed, we assume the maximum header length */ - framer_hdrlen = MAC_MAX_HEADER; + max_payload = NETSTACK_MAC.max_payload(); + if(max_payload <= 0) { + /* Framing failed, drop packet */ + LOG_WARN("output: failed to calculate payload size - dropping packet\n"); + return 0; } - max_payload = MAC_MAX_PAYLOAD - framer_hdrlen; frag_needed = (int)uip_len - (int)uncomp_hdr_len + (int)packetbuf_hdr_len > max_payload; LOG_INFO("output: header len %d -> %d, total len %d -> %d, MAC max payload %d, frag_needed %d\n", uncomp_hdr_len, packetbuf_hdr_len, diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index dfbec52b7..82d7900db 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -409,6 +409,7 @@ uip_init(void) { int c; + uipbuf_init(); uip_ds6_init(); uip_icmp6_init(); uip_nd6_init(); diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index 6ccbb99aa..d2004c727 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -37,6 +37,7 @@ /*---------------------------------------------------------------------------*/ static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX]; +static uint16_t uipbuf_default_attrs[UIPBUF_ATTR_MAX]; /*---------------------------------------------------------------------------*/ /* Get the next header given the buffer - start indicates that this is @@ -101,15 +102,21 @@ uipbuf_set_attr(uint8_t type, uint16_t value) return 0; } /*---------------------------------------------------------------------------*/ +int +uipbuf_set_default_attr(uint8_t type, uint16_t value) +{ + if(type < UIPBUF_ATTR_MAX) { + uipbuf_default_attrs[type] = value; + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ void uipbuf_clear_attr(void) { - /* set everything to "zero" */ - memset(uipbuf_attrs, 0, sizeof(uipbuf_attrs)); - - /* And initialize anything that should be initialized */ - uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, - UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED); + /* set everything to "defaults" */ + memcpy(uipbuf_attrs, uipbuf_default_attrs, sizeof(uipbuf_attrs)); } /*---------------------------------------------------------------------------*/ void @@ -131,3 +138,15 @@ uipbuf_is_attr_flag(uint16_t flag) return (uipbuf_attrs[UIPBUF_ATTR_FLAGS] & flag) == flag; } /*---------------------------------------------------------------------------*/ +void +uipbuf_init(void) +{ + /* And initialize anything that should be initialized */ + uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, + UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED); + /* set the not-set default value - this will cause the MAC layer to + configure its default */ + uipbuf_set_attr(UIPBUF_ATTR_LLSEC_LEVEL, UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT); +} + +/*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/uipbuf.h b/os/net/ipv6/uipbuf.h index 337ffe17f..6af4e590b 100644 --- a/os/net/ipv6/uipbuf.h +++ b/os/net/ipv6/uipbuf.h @@ -81,6 +81,17 @@ uint16_t uipbuf_get_attr(uint8_t type); */ int uipbuf_set_attr(uint8_t type, uint16_t value); +/** + * \brief Set the default value of the attribute + * \param type The attribute to set the default value of + * \param value The value to set + * \retval 0 - indicates failure of setting the value + * \retval 1 - indicates success of setting the value + * + * This function sets the default value of a uipbuf attribute. + */ +int uipbuf_set_default_attr(uint8_t type, uint16_t value); + /** * \brief Set bits in the uipbuf attribute flags. * \param flag_bits The bits to set in the flag. @@ -115,6 +126,14 @@ uint16_t uipbuf_is_attr_flag(uint16_t flag_bits); */ void uipbuf_clear_attr(void); +/** + * \brief Initialize uipbuf attributes. + * + * This function initialize all attributes in the uipbuf + * attributes including all flags. + */ +void uipbuf_init(void); + /** * \brief The bits defined for uipbuf attributes flag. * @@ -124,6 +143,9 @@ void uipbuf_clear_attr(void); /* Avoid using prefix compression on the packet (6LoWPAN) */ #define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_PREFIX_COMPRESSION 0x02 +/* MAC will set the default for this packet */ +#define UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT 0xffff + /** * \brief The attributes defined for uipbuf attributes function. * diff --git a/os/net/mac/ble/ble-l2cap.c b/os/net/mac/ble/ble-l2cap.c index 076d919e8..fb755cc85 100644 --- a/os/net/mac/ble/ble-l2cap.c +++ b/os/net/mac/ble/ble-l2cap.c @@ -505,6 +505,12 @@ off(void) return 0; } /*---------------------------------------------------------------------------*/ +static int +max_payload(void) +{ + return BLE_L2CAP_NODE_MTU; +} +/*---------------------------------------------------------------------------*/ const struct mac_driver ble_l2cap_driver = { "ble-l2cap", init, @@ -512,6 +518,7 @@ const struct mac_driver ble_l2cap_driver = { input, on, off, + max_payload, }; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(ble_l2cap_tx_process, ev, data) diff --git a/os/net/mac/csma/csma-security.c b/os/net/mac/csma/csma-security.c index 50faf2723..83853b81b 100644 --- a/os/net/mac/csma/csma-security.c +++ b/os/net/mac/csma/csma-security.c @@ -61,9 +61,11 @@ #define LOG_MODULE "CSMA" #define LOG_LEVEL LOG_LEVEL_MAC +static const char * HEX = "0123456789ABCDEF"; + #if LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER -#define MIC_LEN LLSEC802154_MIC_LEN(CSMA_LLSEC_SECURITY_LEVEL) +#define MIC_LEN(level) LLSEC802154_MIC_LEN(level) #if LLSEC802154_USES_EXPLICIT_KEYS #define LLSEC_KEY_INDEX (FRAME802154_IMPLICIT_KEY == packetbuf_attr(PACKETBUF_ATTR_KEY_ID_MODE) \ @@ -104,7 +106,8 @@ aead(uint8_t hdrlen, int forward) uint8_t *a; uint8_t a_len; uint8_t *result; - uint8_t generated_mic[MIC_LEN]; + /* Allocate for MAX level */ + uint8_t generated_mic[MIC_LEN(7)]; uint8_t *mic; uint8_t key_index; aes_key_t *key; @@ -142,14 +145,14 @@ aead(uint8_t hdrlen, int forward) CCM_STAR.aead(nonce, m, m_len, a, a_len, - result, MIC_LEN, + result, MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07), forward); if(forward) { - packetbuf_set_datalen(packetbuf_datalen() + MIC_LEN); + packetbuf_set_datalen(packetbuf_datalen() + MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07)); return 1; } else { - return (memcmp(generated_mic, mic, MIC_LEN) == 0); + return (memcmp(generated_mic, mic, MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07)) == 0); } } @@ -171,6 +174,15 @@ csma_security_create_frame(void) } if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0) { + int i = 0; + uint8_t *p; + LOG_DBG(" Payload before (%d):", packetbuf_totlen()); + p = packetbuf_hdrptr(); + for(i = 0; i < packetbuf_totlen(); i++) { + LOG_DBG_("%c%c", HEX[(p[i] >> 4) & 0x0f], HEX[p[i] & 0x0f]); + } + LOG_DBG("\n"); + if(!aead(hdr_len, 1)) { LOG_ERR("failed to encrypt packet to "); LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); @@ -183,6 +195,14 @@ csma_security_create_frame(void) LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), LLSEC_KEY_INDEX); + + LOG_DBG(" Payload after: (%d)", packetbuf_totlen()); + p = packetbuf_hdrptr(); + for(i = 0; i < packetbuf_totlen(); i++) { + LOG_DBG_("%c%c", HEX[(p[i] >> 4) & 0x0f], HEX[p[i] & 0x0f]); + } + LOG_DBG_("\n"); + } return hdr_len; } @@ -193,7 +213,8 @@ csma_security_frame_len(void) { if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0 && LLSEC_KEY_INDEX != 0xffff) { - return NETSTACK_FRAMER.length() + MIC_LEN; + return NETSTACK_FRAMER.length() + + MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07); } return NETSTACK_FRAMER.length(); } @@ -242,12 +263,12 @@ csma_security_parse_frame(void) return FRAMER_FAILED; } - if(packetbuf_datalen() <= MIC_LEN) { + if(packetbuf_datalen() <= MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07)) { LOG_ERR("MIC error - too little data in frame!\n"); return FRAMER_FAILED; } - packetbuf_set_datalen(packetbuf_datalen() - MIC_LEN); + packetbuf_set_datalen(packetbuf_datalen() - MIC_LEN(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & 0x07)); if(!aead(hdr_len, 0)) { LOG_INFO("received unauthentic frame %u from ", (unsigned int) anti_replay_get_counter()); diff --git a/os/net/mac/csma/csma.c b/os/net/mac/csma/csma.c index 4db20fa9a..f9fb6d697 100644 --- a/os/net/mac/csma/csma.c +++ b/os/net/mac/csma/csma.c @@ -49,10 +49,25 @@ #define LOG_MODULE "CSMA" #define LOG_LEVEL LOG_LEVEL_MAC + +static void +init_sec(void) +{ +#if LLSEC802154_USES_AUX_HEADER + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) == + PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT) { + packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, + CSMA_LLSEC_SECURITY_LEVEL); + } +#endif +} /*---------------------------------------------------------------------------*/ static void send_packet(mac_callback_t sent, void *ptr) { + + init_sec(); + csma_output_packet(sent, ptr); } /*---------------------------------------------------------------------------*/ @@ -141,12 +156,30 @@ init(void) on(); } /*---------------------------------------------------------------------------*/ +static int +max_payload(void) +{ + int framer_hdrlen; + + init_sec(); + + framer_hdrlen = NETSTACK_FRAMER.length(); + + if(framer_hdrlen < 0) { + /* Framing failed, we assume the maximum header length */ + framer_hdrlen = CSMA_MAC_MAX_HEADER; + } + + return CSMA_MAC_LEN - framer_hdrlen; +} +/*---------------------------------------------------------------------------*/ const struct mac_driver csma_driver = { "CSMA", init, send_packet, input_packet, on, - off + off, + max_payload, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/csma/csma.h b/os/net/mac/csma/csma.h index 655e59134..96f48e326 100644 --- a/os/net/mac/csma/csma.h +++ b/os/net/mac/csma/csma.h @@ -65,6 +65,17 @@ #define CSMA_ACK_LEN 3 +/* Default MAC len for 802.15.4 classic */ +#ifdef CSMA_MAC_CONF_LEN +#define CSMA_MAC_LEN CSMA_MAC_CONF_LEN +#else +#define CSMA_MAC_LEN 127 +#endif + +/* just a default - with LLSEC, etc */ +#define CSMA_MAC_MAX_HEADER 21 + + extern const struct mac_driver csma_driver; /* CSMA security framer functions */ diff --git a/os/net/mac/mac.h b/os/net/mac/mac.h index 4f2a75b15..f64838b4c 100644 --- a/os/net/mac/mac.h +++ b/os/net/mac/mac.h @@ -76,6 +76,9 @@ struct mac_driver { /** Turn the MAC layer off. */ int (* off)(void); + + /** Read out estimated max payload size based on payload in packetbuf */ + int (* max_payload)(void); }; /* Generic MAC return values. */ diff --git a/os/net/mac/nullmac/nullmac.c b/os/net/mac/nullmac/nullmac.c index a6199a3f9..de92ee5d8 100644 --- a/os/net/mac/nullmac/nullmac.c +++ b/os/net/mac/nullmac/nullmac.c @@ -67,6 +67,12 @@ off(void) return 0; } /*---------------------------------------------------------------------------*/ +static int +max_payload(void) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ static void init(void) { @@ -78,6 +84,7 @@ const struct mac_driver nullmac_driver = { send_packet, packet_input, on, - off + off, + max_payload, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 25b565809..719a09b9f 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -62,6 +62,9 @@ #include "net/mac/tsch/sixtop/sixtop.h" #endif +/* Needed to estimate the MAC lenght */ +#define TSCH_MAC_MAX_LEN 127 + #if FRAME802154_VERSION < FRAME802154_IEEE802154_2015 #error TSCH: FRAME802154_VERSION must be at least FRAME802154_IEEE802154_2015 #endif @@ -1128,13 +1131,21 @@ turn_off(void) return 1; } /*---------------------------------------------------------------------------*/ +static int +max_payload(void) +{ + /* Setup security... before. */ + return TSCH_MAC_MAX_LEN - NETSTACK_FRAMER.length(); +} +/*---------------------------------------------------------------------------*/ const struct mac_driver tschmac_driver = { "TSCH", tsch_init, send_packet, packet_input, turn_on, - turn_off + turn_off, + max_payload, }; /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/packetbuf.h b/os/net/packetbuf.h index 2429e84b0..c077ae940 100644 --- a/os/net/packetbuf.h +++ b/os/net/packetbuf.h @@ -55,6 +55,7 @@ #include "contiki.h" #include "net/linkaddr.h" #include "net/mac/llsec802154.h" +#include "net/mac/csma/csma-security.h" #include "net/mac/tsch/tsch-conf.h" /** @@ -282,6 +283,8 @@ void packetbuf_attr_copyfrom(struct packetbuf_attr *attrs, #define PACKETBUF_ATTR_BYTE 8 #define PACKETBUF_ADDRSIZE (LINKADDR_SIZE * PACKETBUF_ATTR_BYTE) +#define PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT 0xffff + struct packetbuf_attrlist { uint8_t type; uint8_t len; diff --git a/os/services/rpl-border-router/native/border-router-mac.c b/os/services/rpl-border-router/native/border-router-mac.c index fbf8b6496..786a35321 100644 --- a/os/services/rpl-border-router/native/border-router-mac.c +++ b/os/services/rpl-border-router/native/border-router-mac.c @@ -42,6 +42,7 @@ #include "net/netstack.h" #include "packetutils.h" #include "border-router.h" +#include "net/mac/csma-security.h" #include /*---------------------------------------------------------------------------*/ @@ -64,6 +65,19 @@ struct tx_callback { /*---------------------------------------------------------------------------*/ static struct tx_callback callbacks[MAX_CALLBACKS]; /*---------------------------------------------------------------------------*/ +init_sec(void) +{ + /* use the CSMA LLSEC config parameter */ +#if LLSEC802154_USES_AUX_HEADER + if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) == + PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT) { + packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, + CSMA_LLSEC_SECURITY_LEVEL); + } +#endif +} +/*---------------------------------------------------------------------------*/ + void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx) { @@ -164,6 +178,13 @@ off() return 1; } /*---------------------------------------------------------------------------*/ +static int +max_payload() +{ + init_sec(); + return 127 - NETSTACK_FRAMER.length(); +} +/*---------------------------------------------------------------------------*/ static void init(void) { @@ -176,6 +197,7 @@ const struct mac_driver border_router_mac_driver = { send_packet, packet_input, on, - off + off, + max_payload, }; /*---------------------------------------------------------------------------*/ From 3542fa8d85ba9840d017574bdb1305f646c53474 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Sat, 20 Oct 2018 22:27:02 +0200 Subject: [PATCH 082/184] added back more textual representation of messages in rpl-udp example - good for debugging LLSEC encryption --- examples/rpl-udp/udp-client.c | 7 ++++--- examples/rpl-udp/udp-server.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index 1fb030034..fb13a2073 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -32,8 +32,7 @@ udp_rx_callback(struct simple_udp_connection *c, const uint8_t *data, uint16_t datalen) { - unsigned count = *(unsigned *)data; - LOG_INFO("Received response %u from ", count); + LOG_INFO("Received response '%s' from ", (char *) data); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); } @@ -42,6 +41,7 @@ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic_timer; static unsigned count; + static char str[32]; uip_ipaddr_t dest_ipaddr; PROCESS_BEGIN(); @@ -59,7 +59,8 @@ PROCESS_THREAD(udp_client_process, ev, data) LOG_INFO("Sending request %u to ", count); LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_("\n"); - simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); + snprintf(str, sizeof(str), "hello from the client:%d", count); + simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr); count++; } else { LOG_INFO("Not reachable yet\n"); diff --git a/examples/rpl-udp/udp-server.c b/examples/rpl-udp/udp-server.c index 399cabfc4..d69a97c78 100644 --- a/examples/rpl-udp/udp-server.c +++ b/examples/rpl-udp/udp-server.c @@ -54,15 +54,19 @@ udp_rx_callback(struct simple_udp_connection *c, const uint8_t *data, uint16_t datalen) { - unsigned count = *(unsigned *)data; - LOG_INFO("Received request %u from ", count); + char *str = (char *)data; + char outstr[32]; + LOG_INFO("Received request '%s' from ", str); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); #if WITH_SERVER_REPLY - LOG_INFO("Sending response %u to ", count); + /* send the number that came in - and is at the end */ + snprintf(outstr, sizeof(outstr), "hello from the server:%s", + &data[strlen("hello from the client:")]); + LOG_INFO("Sending response '%s' to ", outstr); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); - simple_udp_sendto(&udp_conn, &count, sizeof(count), sender_addr); + simple_udp_sendto(&udp_conn, outstr, strlen(outstr), sender_addr); #endif /* WITH_SERVER_REPLY */ } /*---------------------------------------------------------------------------*/ From d3c95c9a6ead04d42e747a0b179c60cb5d2f54b6 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Sat, 20 Oct 2018 22:27:19 +0200 Subject: [PATCH 083/184] added llsec shell commands --- os/services/shell/shell-commands.c | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index e8bb4b6b2..32ff763f0 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -729,6 +729,75 @@ PT_THREAD(cmd_6top(struct pt *pt, shell_output_func output, char *args)) } #endif /* TSCH_WITH_SIXTOP */ /*---------------------------------------------------------------------------*/ +#if LLSEC802154_ENABLED +static +PT_THREAD(cmd_llsec_setlv(struct pt *pt, shell_output_func output, char *args)) +{ + char *next_args; + + PT_BEGIN(pt); + + SHELL_ARGS_INIT(args, next_args); + + if(args == NULL) { + SHELL_OUTPUT(output, "Default LLSEC level is %d\n", + uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL)); + PT_EXIT(pt); + } else { + int lv = atoi(args); + if(lv < 0 || lv > 7) { + SHELL_OUTPUT(output, "Illegal LLSEC Level %d\n", lv); + PT_EXIT(pt); + } else { + uipbuf_set_default_attr(UIPBUF_ATTR_LLSEC_LEVEL, lv); + uipbuf_clear_attr(); + SHELL_OUTPUT(output, "LLSEC default level set %d\n", lv); + } + } + SHELL_ARGS_NEXT(args, next_args); + + PT_END(pt); +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_llsec_setkey(struct pt *pt, shell_output_func output, char *args)) +{ + char *next_args; + + PT_BEGIN(pt); + + SHELL_ARGS_INIT(args, next_args); + + if(args == NULL) { + SHELL_OUTPUT(output, "Provide an index and a 16-char string for the key\n"); + PT_EXIT(pt); + } else { + int key; + SHELL_ARGS_NEXT(args, next_args); + key = atoi(args); + if(key < 0 || key > 16) { + SHELL_OUTPUT(output, "Illegal LLSEC Key index %d\n", key); + PT_EXIT(pt); + } else { +#if MAC_CONF_WITH_CSMA + /* Get next arg (key-string) */ + SHELL_ARGS_NEXT(args, next_args); + if(args != NULL && strlen(args) == 16) { + csma_security_set_key(key, (uint8_t *) args); + SHELL_OUTPUT(output, "Set key for index %d\n", key); + } else { + SHELL_OUTPUT(output, "Wrong length of key: '%s' (%d)\n", args, strlen(args)); + } +#else + SHELL_OUTPUT(output, "Set key not supported.\n"); + PT_EXIT(pt); +#endif + } + } + PT_END(pt); +} +#endif /* LLSEC802154_ENABLED */ +/*---------------------------------------------------------------------------*/ void shell_commands_init(void) { @@ -801,6 +870,10 @@ const struct shell_command_t builtin_shell_commands[] = { #if TSCH_WITH_SIXTOP { "6top", cmd_6top, "'> 6top help': Shows 6top command usage" }, #endif /* TSCH_WITH_SIXTOP */ +#if LLSEC802154_ENABLED + { "llsec-set-level", cmd_llsec_setlv, "'> llsec-set-level ': Set the level of link layer security (show if no lv argument)"}, + { "llsec-set-key", cmd_llsec_setkey, "'> llsec-set-key ': Set the key of link layer security (show if no id key argument)"}, +#endif /* LLSEC802154_ENABLED */ { NULL, NULL, NULL }, }; From a2eec4c985a22b0015dcac5f78babafad2f6d1d9 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Sat, 20 Oct 2018 22:41:02 +0200 Subject: [PATCH 084/184] fixed csma-security debug output --- os/net/mac/csma/csma-security.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/os/net/mac/csma/csma-security.c b/os/net/mac/csma/csma-security.c index 83853b81b..26caed1d5 100644 --- a/os/net/mac/csma/csma-security.c +++ b/os/net/mac/csma/csma-security.c @@ -61,7 +61,9 @@ #define LOG_MODULE "CSMA" #define LOG_LEVEL LOG_LEVEL_MAC +#if LOG_LEVEL == LOG_LEVEL_DBG static const char * HEX = "0123456789ABCDEF"; +#endif #if LLSEC802154_USES_AUX_HEADER && LLSEC802154_USES_FRAME_COUNTER @@ -174,6 +176,7 @@ csma_security_create_frame(void) } if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) > 0) { +#if LOG_LEVEL == LOG_LEVEL_DBG int i = 0; uint8_t *p; LOG_DBG(" Payload before (%d):", packetbuf_totlen()); @@ -182,6 +185,7 @@ csma_security_create_frame(void) LOG_DBG_("%c%c", HEX[(p[i] >> 4) & 0x0f], HEX[p[i] & 0x0f]); } LOG_DBG("\n"); +#endif if(!aead(hdr_len, 1)) { LOG_ERR("failed to encrypt packet to "); @@ -196,12 +200,14 @@ csma_security_create_frame(void) LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), LLSEC_KEY_INDEX); +#if LOG_LEVEL == LOG_LEVEL_DBG LOG_DBG(" Payload after: (%d)", packetbuf_totlen()); p = packetbuf_hdrptr(); for(i = 0; i < packetbuf_totlen(); i++) { LOG_DBG_("%c%c", HEX[(p[i] >> 4) & 0x0f], HEX[p[i] & 0x0f]); } LOG_DBG_("\n"); +#endif } return hdr_len; From 08141e6b9b74fff6b7528c3180a6681e7b855f18 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 21 Oct 2018 12:33:58 +0100 Subject: [PATCH 085/184] Sort apt-get install packages, one package per line --- tools/docker/Dockerfile | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 634f85ea6..6eb9dbb17 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -7,11 +7,30 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E03280 echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list && \ apt-get -qq update && \ apt-get -qq -y --no-install-recommends install \ - build-essential doxygen git wget unzip python-serial python-pip \ - default-jdk ant srecord iputils-tracepath rlwrap \ - mosquitto mosquitto-clients gdb npm \ - mono-complete gksu libgtk2.0-0 screen uml-utilities gtk-sharp2 \ - libcanberra-gtk-module:i386 > /dev/null \ + ant \ + build-essential \ + default-jdk \ + doxygen \ + gdb \ + git \ + gksu \ + gtk-sharp2 \ + iputils-tracepath \ + libcanberra-gtk-module:i386 \ + libgtk2.0-0 \ + mono-complete \ + mosquitto \ + mosquitto-clients \ + npm \ + python-pip \ + python-serial \ + rlwrap \ + screen \ + srecord \ + uml-utilities \ + unzip \ + wget \ + > /dev/null \ && apt-get -qq clean # Install coap-cli From 6d4cddeec104345206bb7ff18731ad5a78cac34d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 21 Oct 2018 17:13:17 +0100 Subject: [PATCH 086/184] Make the MQTT client example a little more configurable and verbose Suitable for native run testing --- examples/mqtt-client/mqtt-client.c | 5 +++++ examples/mqtt-client/project-conf.h | 2 ++ 2 files changed, 7 insertions(+) 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. From c2ceaab13b5e38cf9660f12ba955b260bae88a99 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 21 Oct 2018 17:14:17 +0100 Subject: [PATCH 087/184] Add MQTT client execution test --- tests/08-native-runs/02-mqtt-client.sh | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 tests/08-native-runs/02-mqtt-client.sh 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 From 7427a861a3d20845681ee2cc4d0545611936fdce Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 21 Oct 2018 19:36:35 +0100 Subject: [PATCH 088/184] Only build cooja for tests that actually use it --- .travis.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index f5a58c609..60d8db747 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,14 @@ 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 From 81d6218ebcd6402bc200846a3e26ab7ac0e93ee2 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 21 Oct 2018 20:32:32 +0100 Subject: [PATCH 089/184] Don't try to build cooja from inside test makefiles --- tests/Makefile.script-test | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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) From e135bf277eaa078824e034f09f3889dfebb39c86 Mon Sep 17 00:00:00 2001 From: Jeppe Odgaard Date: Mon, 22 Oct 2018 10:37:56 +0200 Subject: [PATCH 090/184] Added test to reproduce issue, and proposed fix in rpl-dag, where dag is only freed if dag_id is different. --- examples/multicast/Makefile | 5 + examples/multicast/root.c | 4 +- os/net/routing/rpl-classic/rpl-dag.c | 15 +- tests/15-rpl-classic/02-rpl-root-reboot-2.csc | 336 ++++++++++++++++++ 4 files changed, 351 insertions(+), 9 deletions(-) create mode 100644 tests/15-rpl-classic/02-rpl-root-reboot-2.csc diff --git a/examples/multicast/Makefile b/examples/multicast/Makefile index 86c16e481..be7fb6422 100644 --- a/examples/multicast/Makefile +++ b/examples/multicast/Makefile @@ -12,6 +12,11 @@ include $(CONTIKI)/Makefile.identify-target MODULES_REL += $(TARGET) MODULES += os/net/ipv6/multicast +MODULES += os/services/shell + +ifeq ($(DISABLE_AUTO_ROOT),1) + CFLAGS += -DDISABLE_AUTO_ROOT +endif MAKE_ROUTING = MAKE_ROUTING_RPL_CLASSIC include $(CONTIKI)/Makefile.include diff --git a/examples/multicast/root.c b/examples/multicast/root.c index 59d5d2aa8..a95a25bcf 100644 --- a/examples/multicast/root.c +++ b/examples/multicast/root.c @@ -111,9 +111,9 @@ PROCESS_THREAD(rpl_root_process, ev, data) PROCESS_BEGIN(); PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); - +#ifndef DISABLE_AUTO_ROOT NETSTACK_ROUTING.root_start(); - +#endif prepare_mcast(); etimer_set(&et, START_DELAY * CLOCK_SECOND); diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index cbaee6959..174d3b8fb 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -368,15 +368,16 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id) if(uip_ipaddr_cmp(&dag->dag_id, dag_id)) { version = dag->version; RPL_LOLLIPOP_INCREMENT(version); - } - if(dag == dag->instance->current_dag) { - LOG_INFO("Dropping a joined DAG when setting this node as root\n"); - rpl_set_default_route(instance, NULL); - dag->instance->current_dag = NULL; } else { - LOG_INFO("Dropping a DAG when setting this node as root\n"); + if(dag == dag->instance->current_dag) { + LOG_INFO("Dropping a joined DAG when setting this node as root\n"); + rpl_set_default_route(instance, NULL); + dag->instance->current_dag = NULL; + } else { + LOG_INFO("Dropping a DAG when setting this node as root\n"); + } + rpl_free_dag(dag); } - rpl_free_dag(dag); } } } diff --git a/tests/15-rpl-classic/02-rpl-root-reboot-2.csc b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc new file mode 100644 index 000000000..44f0a3b8a --- /dev/null +++ b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc @@ -0,0 +1,336 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype657 + sink + [CONTIKI_DIR]/examples/multicast/sink.c + make sink.cooja TARGET=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.contikimote.ContikiMoteType + mtype120 + root + [CONTIKI_DIR]/examples/multicast/root.c + make root.cooja TARGET=cooja DISABLE_AUTO_ROOT=1 + 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 + 50.0 + 0.0 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype657 + + + + org.contikios.cooja.interfaces.Position + 100.0 + 0.0 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype657 + + + + org.contikios.cooja.interfaces.Position + 150.0 + 0.0 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-addr~;routes~;routing~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype657 + + + + org.contikios.cooja.interfaces.Position + 0.0 + 0.0 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype120 + + + + org.contikios.cooja.plugins.SimControl + 280 + 1 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.TrafficVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin + 0.9090909090909091 0.0 0.0 0.9090909090909091 125.81818181818181 173.0 + + 400 + 2 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + + + + + 1320 + 3 + 240 + 400 + 160 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + + + + 500.0 + + 1720 + 5 + 166 + 0 + 948 + + + org.contikios.cooja.plugins.Notes + + Enter notes here + true + + 1040 + 4 + 160 + 680 + 0 + + + org.contikios.cooja.plugins.ScriptRunner + + + false + + 1011 + 0 + 700 + 259 + 140 + + + From 0a3b89008040225101336076a496d6f77677445f Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 23 Oct 2018 07:50:15 +0200 Subject: [PATCH 091/184] fixed rpl-udp example --- examples/rpl-udp/udp-client.c | 4 ++-- examples/rpl-udp/udp-server.c | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index fb13a2073..8628e834c 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -32,7 +32,7 @@ udp_rx_callback(struct simple_udp_connection *c, const uint8_t *data, uint16_t datalen) { - LOG_INFO("Received response '%s' from ", (char *) data); + LOG_INFO("Received response '%.*s' from ", datalen, (char *) data); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); } @@ -59,7 +59,7 @@ PROCESS_THREAD(udp_client_process, ev, data) LOG_INFO("Sending request %u to ", count); LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_("\n"); - snprintf(str, sizeof(str), "hello from the client:%d", count); + snprintf(str, sizeof(str), "hello %d", count); simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr); count++; } else { diff --git a/examples/rpl-udp/udp-server.c b/examples/rpl-udp/udp-server.c index d69a97c78..072eb8ae8 100644 --- a/examples/rpl-udp/udp-server.c +++ b/examples/rpl-udp/udp-server.c @@ -54,19 +54,13 @@ udp_rx_callback(struct simple_udp_connection *c, const uint8_t *data, uint16_t datalen) { - char *str = (char *)data; - char outstr[32]; - LOG_INFO("Received request '%s' from ", str); + LOG_INFO("Received request '%.*s' from ", datalen, (char *) data); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); #if WITH_SERVER_REPLY - /* send the number that came in - and is at the end */ - snprintf(outstr, sizeof(outstr), "hello from the server:%s", - &data[strlen("hello from the client:")]); - LOG_INFO("Sending response '%s' to ", outstr); - LOG_INFO_6ADDR(sender_addr); - LOG_INFO_("\n"); - simple_udp_sendto(&udp_conn, outstr, strlen(outstr), sender_addr); + /* send back the same string to the client as an echo reply */ + LOG_INFO("Sending response.\n"); + simple_udp_sendto(&udp_conn, data, datalen, sender_addr); #endif /* WITH_SERVER_REPLY */ } /*---------------------------------------------------------------------------*/ From 008cffe81a24760e2fa005eacd9cc94d1f3d82ee Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 23 Oct 2018 07:51:46 +0200 Subject: [PATCH 092/184] fixed compilation issues --- os/net/ipv6/uipbuf.c | 8 +++++--- os/net/mac/csma/csma-security.h | 2 +- os/net/mac/csma/csma.c | 3 ++- os/services/rpl-border-router/native/border-router-mac.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/os/net/ipv6/uipbuf.c b/os/net/ipv6/uipbuf.c index d2004c727..c25e4523f 100644 --- a/os/net/ipv6/uipbuf.c +++ b/os/net/ipv6/uipbuf.c @@ -141,12 +141,14 @@ uipbuf_is_attr_flag(uint16_t flag) void uipbuf_init(void) { + memset(uipbuf_default_attrs, 0, sizeof(uipbuf_default_attrs)); /* And initialize anything that should be initialized */ - uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, - UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED); + uipbuf_set_default_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, + UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED); /* set the not-set default value - this will cause the MAC layer to configure its default */ - uipbuf_set_attr(UIPBUF_ATTR_LLSEC_LEVEL, UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT); + uipbuf_set_default_attr(UIPBUF_ATTR_LLSEC_LEVEL, + UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT); } /*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/csma/csma-security.h b/os/net/mac/csma/csma-security.h index d58885f5c..4e9f9b391 100644 --- a/os/net/mac/csma/csma-security.h +++ b/os/net/mac/csma/csma-security.h @@ -44,7 +44,7 @@ #ifdef CSMA_CONF_LLSEC_DEFAULT_KEY0 #define CSMA_LLSEC_DEFAULT_KEY0 CSMA_CONF_LLSEC_DEFAULT_KEY0 #else -#define CSMA_LLSEC_DEFAULT_KEY0 {0x10, 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f} +#define CSMA_LLSEC_DEFAULT_KEY0 {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f} #endif #ifdef CSMA_CONF_LLSEC_SECURITY_LEVEL diff --git a/os/net/mac/csma/csma.c b/os/net/mac/csma/csma.c index f9fb6d697..63808192f 100644 --- a/os/net/mac/csma/csma.c +++ b/os/net/mac/csma/csma.c @@ -147,11 +147,12 @@ static void init(void) { +#if LLSEC802154_USES_AUX_HEADER #ifdef CSMA_LLSEC_DEFAULT_KEY0 uint8_t key[16] = CSMA_LLSEC_DEFAULT_KEY0; csma_security_set_key(0, key); #endif - +#endif /* LLSEC802154_USES_AUX_HEADER */ csma_output_init(); on(); } diff --git a/os/services/rpl-border-router/native/border-router-mac.c b/os/services/rpl-border-router/native/border-router-mac.c index 786a35321..7fe4fc6ed 100644 --- a/os/services/rpl-border-router/native/border-router-mac.c +++ b/os/services/rpl-border-router/native/border-router-mac.c @@ -42,7 +42,6 @@ #include "net/netstack.h" #include "packetutils.h" #include "border-router.h" -#include "net/mac/csma-security.h" #include /*---------------------------------------------------------------------------*/ @@ -65,6 +64,7 @@ struct tx_callback { /*---------------------------------------------------------------------------*/ static struct tx_callback callbacks[MAX_CALLBACKS]; /*---------------------------------------------------------------------------*/ +void init_sec(void) { /* use the CSMA LLSEC config parameter */ From 0997932bcb357c80336e0294ca38568c5ce2d514 Mon Sep 17 00:00:00 2001 From: Toshio Ito Date: Tue, 23 Oct 2018 16:31:34 +0900 Subject: [PATCH 093/184] tsch: skip resynchronization when time source has been already changed. See #712 Plus, now `resynchronize` is a separate function. --- os/net/mac/tsch/tsch.c | 62 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 25b565809..60638eaaf 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 */ From a2c9f75e468174075102b1e9dff95b507d9e77b4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 19 Oct 2018 14:17:25 +0100 Subject: [PATCH 094/184] Add out of tree build tests --- .travis.yml | 17 +++++++++++++++-- tests/19-out-of-tree-build/Makefile | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/19-out-of-tree-build/Makefile diff --git a/.travis.yml b/.travis.yml index 60d8db747..ca4dbf8d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,12 +34,22 @@ before_install: - if [ ${BUILD_COOJA:-false} = true ] ; then ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar ; fi + + # Create a directory for out of tree tests and clone the test repo therein + # The directory will need created unconditionally so we can always chgrp and + # mount it, even if empty. Checkout a pre-defined version. + - mkdir -p $OUT_OF_TREE_TEST_PATH + - if [ ${TEST_NAME} = "out-of-tree-build" ] ; then + git clone --depth 1 https://github.com/contiki-ng/out-of-tree-tests $OUT_OF_TREE_TEST_PATH && + cd $OUT_OF_TREE_TEST_PATH && + git checkout $OUT_OF_TREE_TEST_VER ; + fi # Set permissions for Docker mount - - sudo chgrp -hR 1000 $CNG_HOST_PATH + - sudo chgrp -hR 1000 $CNG_HOST_PATH $OUT_OF_TREE_TEST_PATH # The test script for each build script: - - docker run --privileged -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME"; + - docker run --privileged -v $OUT_OF_TREE_TEST_PATH:/home/user/out-of-tree-tests -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME"; # Check outcome of the test - $CNG_HOST_PATH/tests/check-test.sh $CNG_HOST_PATH/tests/??-$TEST_NAME; exit $?; @@ -49,6 +59,8 @@ env: global: - DOCKER_IMG='contiker/contiki-ng' - CNG_HOST_PATH=`pwd` + - OUT_OF_TREE_TEST_PATH=$HOME/out-of-tree-tests + - OUT_OF_TREE_TEST_VER=2869ae7 # Encrypted environment variables. # Only available on builds of contiki-ng/contiki-ng branches, not PRs or forks. - secure: 0nrV5yjpT2kE19Hlm7t619Qbmyjx/G7bSUI1c+U3kZbyuxnRlASjVcDN5uPBoimIfGiBRI0nRq690BogAJt4EKwbC1Dy8kC1XD8mRtQ2AIZ6PHaUoG9iS5sBhFBQK0XkB83bwh6omRn/04O0uuX74ooSWT7fDrWxi/y5+0ysXK6gRtOhdrJ3FU5OkNVewX8NeCdx3pOWhMOtXWdFkMIi1XRdDnvMM5/hHlHMkdXXtaZQX9UsK3Q3DSjPRLZjKRiOlcx9MIg2ebh9ITmd2Du2p2q/LKtoutJckvhbKQPWcZi/B+1ZTSff0FHBIg+EYxf6TeFuia7XSTWH7sr2CDCCtcvSR9bB5yW6jdmGfa8Af8I1TCBuqoSUo0Re50BZBZF7COleEh+IojbjXn2CIDMg5rT4Sh3qcMGvFn9OW1cz5h5UNSOk7EIAXXPcI7Aloxh2sBo4/DrvvbfIsKrvxV9Fx4bdyNtR7dZ7xsoOw6L0zttC3K9naf3VAOeBAyjBiRwm0tWxJC/buhTsKlYrthhyUrwLtYAFL4UHcazvz57hY/cEzR2X6F//9Hp7HFoNtn1E36doX3ZfeI22yxHMo9SYW7O69C45wbhJ29lAA9XXbYVyGBKFkY8C1NCZ0Xckt9H8/Ow5Sz8HmW/NNBJCn0Fsx+jezdGc4ED5naugNbLAyNg= @@ -68,3 +80,4 @@ env: - TEST_NAME='compile-tools' - TEST_NAME='native-runs' - TEST_NAME='ipv6' BUILD_COOJA=true + - TEST_NAME='out-of-tree-build' diff --git a/tests/19-out-of-tree-build/Makefile b/tests/19-out-of-tree-build/Makefile new file mode 100644 index 000000000..759027062 --- /dev/null +++ b/tests/19-out-of-tree-build/Makefile @@ -0,0 +1,20 @@ +EXAMPLESDIR=$(HOME)/out-of-tree-tests +TOOLSDIR=$(HOME)/contiki-ng/tools + +EXAMPLES = \ +hello-world/native \ +hello-world/native:MAKE_NET=MAKE_NET_NULLNET \ +hello-world/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +hello-world/sky \ +hello-world/nrf52dk \ +hello-world/cc2538dk \ +hello-world/zoul \ +hello-world/openmote-cc2538 \ +hello-world/srf06-cc26xx \ +hello-world/jn516x \ +hello-world/simplelink:BOARD=launchpad/cc26x2r1 \ +hello-world/simplelink:BOARD=sensortag/cc2650 \ + +TOOLS= + +include ../Makefile.compile-test From 1841aadf6a20ef00a155f72b5b9fb24965a441ae Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 19:59:01 +0100 Subject: [PATCH 095/184] Reduce makefile code duplication --- arch/cpu/arm/cortex-m/Makefile.cortex-m | 12 ++++++++++++ arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 11 +---------- arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 11 ----------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/arch/cpu/arm/cortex-m/Makefile.cortex-m b/arch/cpu/arm/cortex-m/Makefile.cortex-m index aebcf2bdd..36487ef8a 100644 --- a/arch/cpu/arm/cortex-m/Makefile.cortex-m +++ b/arch/cpu/arm/cortex-m/Makefile.cortex-m @@ -3,6 +3,18 @@ CONTIKI_ARM_DIRS += cortex-m cortex-m/CMSIS ### Build syscalls for newlib MODULES += os/lib/newlib +LDFLAGS += -T $(LDSCRIPT) +LDFLAGS += -Wl,--gc-sections,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch + +OBJCOPY_FLAGS += --gap-fill 0xff + +CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} + +### Resolve any potential circular dependencies between the linked libraries +### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 +TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group + CUSTOM_RULE_LINK = 1 .SECONDEXPANSION: diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index 3cf216bfb..b4bf612da 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -3,16 +3,7 @@ CONTIKI_ARM_DIRS += cortex-m/cm3 CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles -LDFLAGS += -T $(LDSCRIPT) -LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch -OBJCOPY_FLAGS += --gap-fill 0xff - -CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} - -### Resolve any potential circular dependencies between the linked libraries -### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 -TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lm -Wl,--end-group +TARGET_LIBFILES += -lm include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index b0b592e43..7443681ea 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -3,16 +3,5 @@ CONTIKI_ARM_DIRS += cortex-m/cm4 CFLAGS += -mcpu=cortex-m4 LDFLAGS += -mcpu=cortex-m4 -LDFLAGS += -T $(LDSCRIPT) -LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch - -OBJCOPY_FLAGS += --gap-fill 0xff - -CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} - -### Resolve any potential circular dependencies between the linked libraries -### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 -TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m From ab5d5ba33cac0f4c7c5fd2b928b7c611f66fbf7f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 22:26:22 +0100 Subject: [PATCH 096/184] Extend build verbosity control Apply verbosity control for mkdir, cp, srec_cat, objcopy, objdump --- Makefile.include | 11 ++++++++++- arch/cpu/arm/Makefile.arm | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Makefile.include b/Makefile.include index a194274bd..7d7bef70e 100644 --- a/Makefile.include +++ b/Makefile.include @@ -77,7 +77,8 @@ PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFI # Provide way to create $(OBJECTDIR) if it has been removed by make clean $(OBJECTDIR): - mkdir $@ + $(TRACE_MKDIR) + $(Q)mkdir $@ uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) @@ -241,12 +242,20 @@ ifeq ($(V),1) TRACE_LD = TRACE_AR = TRACE_AS = + TRACE_OBJCOPY = + TRACE_OBJDUMP = + TRACE_MKDIR = + TRACE_CP = Q= else TRACE_CC = @echo " CC " $< TRACE_LD = @echo " LD " $@ TRACE_AR = @echo " AR " $@ TRACE_AS = @echo " AS " $< + TRACE_OBJCOPY = @echo " OBJCOPY " $< "-->" $@ + TRACE_OBJDUMP = @echo " OBJDUMP " $< "-->" $@ + TRACE_MKDIR = @echo " MKDIR " $@ + TRACE_CP = @echo " CP " $< "-->" $@ Q=@ endif diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index 83f9b8a36..e24385f4b 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -1,3 +1,11 @@ +### Verbosity control. Use make V=1 to get verbose builds. +### Extends what we already have in the top-level Makefile +ifeq ($(V),1) + TRACE_SREC_CAT = +else + TRACE_SREC_CAT = @echo " SREC_CAT " $< "-->" $@ +endif + CC = arm-none-eabi-gcc CPP = arm-none-eabi-cpp LD = arm-none-eabi-gcc @@ -47,18 +55,23 @@ CLEAN += *.elf *.bin *.lst *.hex *.i16hex .PRECIOUS: %.elf %.hex %.bin %.i16hex: %.elf - $(OBJCOPY) -O ihex $< $@ + $(TRACE_OBJCOPY) + $(Q)$(OBJCOPY) -O ihex $< $@ %.hex: %.i16hex - $(SREC_CAT) $< -intel -o $@ -intel + $(TRACE_SREC_CAT) + $(Q)$(SREC_CAT) $< -intel -o $@ -intel %.bin: %.elf - $(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@ + $(TRACE_OBJCOPY) + $(Q)$(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@ %.lst: %.elf - $(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@ + $(TRACE_OBJDUMP) + $(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@ ### We don't really need the .hex and .bin for the .$(TARGET) but let's make ### sure they get built %.$(TARGET): %.elf %.hex %.bin - cp $< $@ + $(TRACE_CP) + $(Q)cp $< $@ From f8ea68c3eb39d7de1c28d3ceaa7a2c6896e91b42 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 23:14:51 +0100 Subject: [PATCH 097/184] Change build output dir structure and filenames --- Makefile.include | 27 ++++++++++++++----------- arch/cpu/arm/Makefile.arm | 19 ++++++++++------- arch/cpu/arm/cortex-m/Makefile.cortex-m | 4 +++- arch/cpu/nrf52832/Makefile.nrf52832 | 6 +++--- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Makefile.include b/Makefile.include index 7d7bef70e..7d26da821 100644 --- a/Makefile.include +++ b/Makefile.include @@ -13,8 +13,6 @@ include $(CONTIKI)/Makefile.identify-target ### Include Makefile.tools to pull in targets that allow us to build tools dir include $(CONTIKI)/Makefile.tools -CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a - ifeq ($(DEFINES),) -include Makefile.$(TARGET).defines ifneq ($(DEFINES),) @@ -39,7 +37,12 @@ ifdef CI endif endif -OBJECTDIR = obj_$(TARGET) +BUILD_DIR = build +BUILD_DIR_TARGET = $(BUILD_DIR)/$(TARGET) +BUILD_DIR_BOARD = $(BUILD_DIR_TARGET)/$(BOARD) +OBJECTDIR = $(BUILD_DIR_BOARD)/obj + +CONTIKI_NG_TARGET_LIB = $(BUILD_DIR_BOARD)/contiki-ng-$(TARGET).a LOWERCASE = -abcdefghijklmnopqrstuvwxyz/ UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_ @@ -75,11 +78,6 @@ endef CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}} PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}} -# Provide way to create $(OBJECTDIR) if it has been removed by make clean -$(OBJECTDIR): - $(TRACE_MKDIR) - $(Q)mkdir $@ - uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) ### Include target makefile (TODO Unsafe?) @@ -125,6 +123,11 @@ endif # $(BOARD) not empty PLATFORM_ACTION ?= build +# Provide way to create $(OBJECTDIR) if it has been removed by make clean +$(OBJECTDIR): + $(TRACE_MKDIR) + $(Q)mkdir -p $@ + ifneq ($(BOARD),) TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 @@ -312,14 +315,13 @@ endef ### Harmonize filename of a .map file, if the platform's build system wants ### to create one -CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) +CONTIKI_NG_PROJECT_MAP = $(BUILD_DIR_BOARD)/$(basename $(notdir $@)).map .PHONY: clean distclean usage help targets boards savetarget savedefines viewconf clean: - -$(Q)rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) - -$(Q)rm -rf $(OBJECTDIR) - -$(Q)rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) + -$(Q)rm -f *.d *.e *.o $(CLEAN) + -$(Q)rm -rf $(BUILD_DIR_TARGET) -$(Q)rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) @echo Target $(TARGET) cleaned @@ -328,6 +330,7 @@ distclean: echo Running: $(MAKE) TARGET=$$TARG clean; \ $(MAKE) TARGET=$$TARG clean; \ done + rmdir $(BUILD_DIR) -include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index e24385f4b..d378d1132 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -51,27 +51,32 @@ endif ### CPU-dependent cleanup files CLEAN += *.elf *.bin *.lst *.hex *.i16hex -### Don't treat the following files as intermediate -.PRECIOUS: %.elf %.hex %.bin +OUT_HEX = $(BUILD_DIR_BOARD)/%.hex +OUT_I16HEX = $(BUILD_DIR_BOARD)/%.i16hex +OUT_BIN = $(BUILD_DIR_BOARD)/%.bin +OUT_LST = $(BUILD_DIR_BOARD)/%.lst -%.i16hex: %.elf +### Don't treat the following files as intermediate +.PRECIOUS: $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) + +$(OUT_I16HEX): $(OUT_ELF) $(TRACE_OBJCOPY) $(Q)$(OBJCOPY) -O ihex $< $@ -%.hex: %.i16hex +$(OUT_HEX): $(OUT_I16HEX) $(TRACE_SREC_CAT) $(Q)$(SREC_CAT) $< -intel -o $@ -intel -%.bin: %.elf +$(OUT_BIN): $(OUT_ELF) $(TRACE_OBJCOPY) $(Q)$(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@ -%.lst: %.elf +$(OUT_LST): $(OUT_ELF) $(TRACE_OBJDUMP) $(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@ ### We don't really need the .hex and .bin for the .$(TARGET) but let's make ### sure they get built -%.$(TARGET): %.elf %.hex %.bin +%.$(TARGET): $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) $(TRACE_CP) $(Q)cp $< $@ diff --git a/arch/cpu/arm/cortex-m/Makefile.cortex-m b/arch/cpu/arm/cortex-m/Makefile.cortex-m index 36487ef8a..0ca1d54ff 100644 --- a/arch/cpu/arm/cortex-m/Makefile.cortex-m +++ b/arch/cpu/arm/cortex-m/Makefile.cortex-m @@ -17,9 +17,11 @@ TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group CUSTOM_RULE_LINK = 1 +OUT_ELF = $(BUILD_DIR_BOARD)/%.elf + .SECONDEXPANSION: -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS) +$(OUT_ELF): $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index c97c728e5..098033ce4 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -172,11 +172,11 @@ vpath %.s $(ASM_PATHS) OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) -CLEAN += nrf52832.a +NRFLIB = $(BUILD_DIR_BOARD)/nrf52832.a -TARGET_LIBS = nrf52832.a $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a +TARGET_LIBS = $(NRFLIB) $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a -nrf52832.a: $(OBJECTS) +$(NRFLIB): $(OBJECTS) $(TRACE_AR) $(Q)$(AR) $(AROPTS) $@ $^ From 1b85bc61242f2e793c8c41a17f4f7c3015616037 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 13 Oct 2018 23:15:06 +0100 Subject: [PATCH 098/184] Ignore the new build output dir --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0ff1ebfa2..c80b86fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ *.ihex *.pyc *~ -obj_* +build/* Makefile.target Makefile.*.defines tools/doxygen/html From 6f2f4b4b2371b6027c71860b7a3773a069c34cf4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 00:23:43 +0100 Subject: [PATCH 099/184] Fix the .upload target --- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 6 +++--- arch/platform/cc2538dk/Makefile.cc2538dk | 5 +++-- arch/platform/openmote-cc2538/Makefile.openmote-cc2538 | 5 +++-- arch/platform/zoul/Makefile.zoul | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index 592ddfbd8..94f4e5111 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -81,8 +81,10 @@ STACK_SIZE = 0 @$(SIZE) -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}' @$(SIZE) -A $< | egrep "text|isr_vector" | awk '{s+=$$2} END {f=$(FLASH_SIZE)-s; printf "[Flash] used %6d, free %6d\n",s,f;}' +include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 + ifeq ($(BOARD_SUPPORTS_BSL),1) -%.upload: %.bin +%.upload: $(OUT_BIN) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else @@ -95,5 +97,3 @@ endif ### For the login etc targets BAUDRATE = 115200 - -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index d80fd8d5f..148c6e837 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -28,11 +28,12 @@ endif BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin %.elf +%.upload: $(OUT_BIN) $(OUT_ELF) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h $*.elf | grep -B1 LOAD | \ + $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h \ + $(BUILD_DIR_BOARD)/$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$5}' | \ sort -g | head -1)) $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< diff --git a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 index d3863fdbc..8b25b0bfe 100644 --- a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -35,11 +35,12 @@ endif BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin %.elf +%.upload: $(OUT_BIN) $(OUT_ELF) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h $*.elf | grep -B1 LOAD | \ + $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h \ + $(BUILD_DIR_BOARD)/$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$5}' | \ sort -g | head -1)) $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 938abe035..e43f84744 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -69,9 +69,9 @@ endif ### $$$$ 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 +%.$(MOTE): $(OUT_BIN) $(OUT_ELF) @echo "Flashing $(MOTE)" - @BSL_ADDRESS=`$(OBJDUMP) -h $$*.elf | grep -B1 LOAD | \ + @BSL_ADDRESS=`$(OBJDUMP) -h $(BUILD_DIR_BOARD)/$$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$$$5}' | \ sort -g | head -1`; \ $(PYTHON) $(BSL) $(BSL_FLAGS) -b $(BSL_SPEED) -a $$$${BSL_ADDRESS} -p $(MOTE) $$< From 8121383950402e614f33dbb667e67cefc9069185 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 17 Oct 2018 12:36:52 +0100 Subject: [PATCH 100/184] Update the Cooja submodule to the latest version --- tools/cooja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cooja b/tools/cooja index a5904b983..63538bbb8 160000 --- a/tools/cooja +++ b/tools/cooja @@ -1 +1 @@ -Subproject commit a5904b98366478bb9e7f7fe9f0bb78fc064914c5 +Subproject commit 63538bbb882ba06a7b8cf97c11ce2fe4d22e4f88 From 44d3f78b9c77fe2872e4d10feba39e3e6afbbbb8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 14 Oct 2018 00:29:47 +0100 Subject: [PATCH 101/184] Adjust the Cooja build system to the new build output dir structure --- arch/platform/cooja/Makefile.cooja | 8 ++++---- arch/platform/cooja/Makefile.customrules-cooja | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index d06aa08d5..6a6a9d49e 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -34,10 +34,10 @@ endif endif ## QUICKSTART -#MAIN_SRC = $(OBJECTDIR)/$(LIBNAME).c -MAIN_OBJ = $(OBJECTDIR)/$(LIBNAME).o -ARCHIVE = $(OBJECTDIR)/$(LIBNAME).a -JNILIB = $(OBJECTDIR)/$(LIBNAME).$(TARGET) +#MAIN_SRC = $(BUILD_DIR_BOARD)/$(LIBNAME).c +MAIN_OBJ = $(BUILD_DIR_BOARD)/$(LIBNAME).o +ARCHIVE = $(BUILD_DIR_BOARD)/$(LIBNAME).a +JNILIB = $(BUILD_DIR_BOARD)/$(LIBNAME).$(TARGET) CONTIKI_APP_OBJ = $(CONTIKI_APP).o ### COOJA platform sources diff --git a/arch/platform/cooja/Makefile.customrules-cooja b/arch/platform/cooja/Makefile.customrules-cooja index 42d6e125e..60d6240f1 100644 --- a/arch/platform/cooja/Makefile.customrules-cooja +++ b/arch/platform/cooja/Makefile.customrules-cooja @@ -10,11 +10,11 @@ CUSTOM_RULE_LINK=1 REDEF_PRINTF=1 # Redefine functions to enable printf()s inside Cooja -# NB: Assumes ARCHIVE was not overridden and is in $(OBJECTDIR) +# NB: Assumes ARCHIVE was not overridden and is in $(BUILD_DIR_BOARD) $(ARCHIVE): $(CONTIKI_OBJECTFILES) | $(OBJECTDIR) $(AR_COMMAND_1) $^ $(AR_COMMAND_2) -# NB: Assumes JNILIB was not overridden and is in $(OBJECTDIR) +# NB: Assumes JNILIB was not overridden and is in $(BUILD_DIR_BOARD) $(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR) ifdef REDEF_PRINTF From 0622889add62f0a230db1ecd6f1b1ce68d556e5b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 18 Oct 2018 20:14:48 +0100 Subject: [PATCH 102/184] Allow users to specify build configurations --- Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index 7d26da821..1ebe8f582 100644 --- a/Makefile.include +++ b/Makefile.include @@ -39,7 +39,7 @@ endif BUILD_DIR = build BUILD_DIR_TARGET = $(BUILD_DIR)/$(TARGET) -BUILD_DIR_BOARD = $(BUILD_DIR_TARGET)/$(BOARD) +BUILD_DIR_BOARD = $(BUILD_DIR_TARGET)/$(BOARD)/$(BUILD_DIR_CONFIG) OBJECTDIR = $(BUILD_DIR_BOARD)/obj CONTIKI_NG_TARGET_LIB = $(BUILD_DIR_BOARD)/contiki-ng-$(TARGET).a From d89cca83acded3ce51045efd0eb8c550ac2a48a7 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 23 Oct 2018 16:49:54 +0100 Subject: [PATCH 103/184] Don't generate an error if build/ does not exist --- Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index 1ebe8f582..3c9058c9e 100644 --- a/Makefile.include +++ b/Makefile.include @@ -330,7 +330,7 @@ distclean: echo Running: $(MAKE) TARGET=$$TARG clean; \ $(MAKE) TARGET=$$TARG clean; \ done - rmdir $(BUILD_DIR) + -$(Q)rm -rf $(BUILD_DIR) -include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) From 14eeeccebca59bb9ce2f892bc927c90ca5e8b4af Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 23 Oct 2018 17:45:43 +0100 Subject: [PATCH 104/184] Always create example.$(TARGET) under build/ and then copy to . --- Makefile.include | 12 ++++++++---- arch/cpu/arm/Makefile.arm | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile.include b/Makefile.include index 3c9058c9e..672c7f4c1 100644 --- a/Makefile.include +++ b/Makefile.include @@ -395,12 +395,16 @@ ifndef LD endif ifndef CUSTOM_RULE_LINK -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \ ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ endif +%.$(TARGET): $(BUILD_DIR_BOARD)/%.$(TARGET) + $(TRACE_CP) + $(Q)cp $< $@ + %.ramprof: %.$(TARGET) $(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4 @@ -458,9 +462,9 @@ ifeq ($(findstring $(TARGET),native cooja),) include $(CONTIKI)/Makefile.embedded endif -# Don't treat %.$(TARGET) as an intermediate file because it is -# in fact the primary target. -.PRECIOUS: %.$(TARGET) +# Don't treat $(BUILD_DIR_BOARD)/%.$(TARGET) and $(TARGET) as intermediate +# files because for many platforms they are in fact the primary target. +.PRECIOUS: $(BUILD_DIR_BOARD)/%.$(TARGET) %.$(TARGET) # Cancel the predefined implict rule for compiling and linking # a single C source into a binary to force GNU make to consider diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index d378d1132..e8befdb86 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -77,6 +77,6 @@ $(OUT_LST): $(OUT_ELF) ### We don't really need the .hex and .bin for the .$(TARGET) but let's make ### sure they get built -%.$(TARGET): $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) +$(BUILD_DIR_BOARD)/%.$(TARGET): $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) $(TRACE_CP) $(Q)cp $< $@ From 1dc02498369470c810ed0cef110ccb399c562014 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 23 Oct 2018 17:45:59 +0100 Subject: [PATCH 105/184] Adjust the jn516x build system to the new build output dir structure --- arch/platform/jn516x/Makefile.jn516x | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index 9ad9488d5..051c336fb 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -229,30 +229,34 @@ ALLLIBS = $(addprefix -l,$(LDLIBS)) $(addprefix -l,$(LDSTACKLIBS)) $(addprefix - ABS_APPLIBS = $(addsuffix _$(JENNIC_CHIP_FAMILY).a,$(addprefix $(COMPONENTS_BASE_DIR)/Library/lib,$(APPLIBS))) ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) -# The SDK is fully installed, proceed to linking and objcopy to ready-to-upload .jn516x.bin file -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) - echo ${filter %.a,$^} +# The SDK is fully installed, proceed to linking +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) + @echo ${filter %.a,$^} $(Q)$(CC) -Wl,--gc-sections $(LDFLAGS) -T$(LINKCMD) -o $@ -Wl,--start-group \ $(patsubst /cygdrive/c/%,c:/%,${filter-out %.a,$^}) \ $(patsubst /cygdrive/c/%,c:/%,${filter %.a,$^}) \ $(ALLLIBS) -Wl,--end-group -Wl,-Map,$(CONTIKI_NG_PROJECT_MAP) - $(OBJCOPY) -S -O binary $@ $@.bin else # The SDK does not include libraries, only build objects and libraries, skip linking -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) - echo Creating empty $@ +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) + @echo Creating empty $@ touch $@ endif -%.$(TARGET).bin: %.$(TARGET) +$(BUILD_DIR_BOARD)/%.$(TARGET).bin: $(BUILD_DIR_BOARD)/%.$(TARGET) + $(TRACE_OBJCOPY) $(Q)$(OBJCOPY) -S -O binary $< $@ +%.$(TARGET).bin: $(BUILD_DIR_BOARD)/%.$(TARGET).bin + $(TRACE_CP) + $(Q)$(CP) $< $@ + ### Upload target to one jn516x mote specified by MOTE=portNumber ifeq ($(HOST_OS),Windows) -%.upload: %.$(TARGET).bin +%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin ${FLASH_PROGRAMMER} -a -c $(DEV_PORT) -B 1000000 -s -w -f $< else -%.upload: %.$(TARGET).bin +%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin ${FLASH_PROGRAMMER} -V 10 -v -s $(DEV_PORT) -I 38400 -P 1000000 -f $< endif @@ -276,7 +280,7 @@ motelistinfo: $(Q)$(MOTELIST) ${FLASH_PROGRAMMER} \? ### Upload target to all connected jn516x motes -%.uploadall: %.$(TARGET).bin +%.uploadall: $(BUILD_DIR_BOARD)/%.$(TARGET).bin $(Q)$(MOTELIST) ${FLASH_PROGRAMMER} $< ### Flash the given file to all connected jn516x motes From 61fba4dcdec1e2fbf53a94ae73c7a997c5015b33 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 12 Oct 2018 15:13:29 +0200 Subject: [PATCH 106/184] Rename srf06-cc26xx to cc26x0-cc13x0 --- .gitignore | 4 +- .../Makefile.cc26x0-cc13x0} | 2 +- .../cfs-coffee-arch.h | 0 .../common/xmem.c | 0 .../contiki-conf.h | 2 +- .../launchpad/Makefile.launchpad | 0 .../launchpad/board-buttons.c | 0 .../launchpad/board-peripherals.h | 0 .../launchpad/board.c | 0 .../launchpad/cc1310/Makefile.cc1310 | 0 .../launchpad/cc1310/board.h | 0 .../launchpad/cc1350/Makefile.cc1350 | 0 .../launchpad/cc1350/board.h | 0 .../launchpad/cc1350/rf-switch.c | 0 .../launchpad/cc1350/tx-power-driver.c | 0 .../launchpad/cc2640r2/Makefile.cc2640r2 | 0 .../launchpad/cc2640r2/board.h | 0 .../launchpad/cc2650/Makefile.cc2650 | 0 .../launchpad/cc2650/board.h | 0 .../launchpad/leds-arch.c | 0 .../platform.c | 0 .../sensortag/Makefile.sensortag | 0 .../sensortag/bmp-280-sensor.c | 0 .../sensortag/bmp-280-sensor.h | 0 .../sensortag/board-buttons.c | 0 .../sensortag/board-i2c.c | 0 .../sensortag/board-i2c.h | 0 .../sensortag/board-peripherals.h | 0 .../sensortag/board.c | 0 .../sensortag/buzzer.c | 0 .../sensortag/buzzer.h | 0 .../sensortag/cc1350/Makefile.cc1350 | 0 .../sensortag/cc1350/board.h | 0 .../sensortag/cc1350/leds-arch.c | 0 .../sensortag/cc2650/Makefile.cc2650 | 0 .../sensortag/cc2650/board.h | 0 .../sensortag/cc2650/leds-arch.c | 0 .../sensortag/hdc-1000-sensor.c | 0 .../sensortag/hdc-1000-sensor.h | 0 .../sensortag/mpu-9250-sensor.c | 0 .../sensortag/mpu-9250-sensor.h | 0 .../sensortag/opt-3001-sensor.c | 0 .../sensortag/opt-3001-sensor.h | 0 .../sensortag/sensor-common.c | 0 .../sensortag/sensor-common.h | 0 .../sensortag/sensortag-sensors.c | 0 .../sensortag/tmp-007-sensor.c | 0 .../sensortag/tmp-007-sensor.h | 0 .../srf06/Makefile.srf06 | 0 .../srf06/als-sensor.c | 0 .../srf06/als-sensor.h | 0 .../srf06/board-buttons.c | 0 .../srf06/board-peripherals.h | 0 .../srf06/board.c | 0 .../srf06/cc13xx/Makefile.cc13xx | 0 .../srf06/cc13xx/board.h | 0 .../srf06/cc26xx/Makefile.cc26xx | 0 .../srf06/cc26xx/board.h | 2 +- .../srf06/leds-arch.c | 0 .../srf06/srf06-sensors.c | 0 examples/6tisch/etsi-plugtest-2017/README.md | 2 +- examples/dev/button-hal/Makefile | 2 +- examples/dev/gpio-hal/Makefile | 2 +- .../{srf06-cc26xx => cc26x0-cc13x0}/pins.c | 0 examples/mqtt-client/Makefile | 2 +- .../Makefile.cc26x0-cc13x0} | 0 .../module-macros.h | 0 .../mqtt-client-extensions.c | 0 .../module-macros.h | 0 .../{cc26xx => cc26x0-cc13x0}/Makefile | 2 +- .../{cc26xx => cc26x0-cc13x0}/Makefile.target | 0 .../{cc26xx => cc26x0-cc13x0}/README.md | 0 .../ble-ipv6/Makefile | 4 +- .../ble-ipv6/README.md | 0 .../ble-ipv6/client.c | 0 .../ble-ipv6/project-conf.h | 0 .../{cc26xx => cc26x0-cc13x0}/cc26xx-demo.c | 2 +- .../cc26xx-web-demo/Makefile | 2 +- .../cc26xx-web-demo/Makefile.target | 0 .../cc26xx-web-demo/README.md | 0 .../cc26xx-web-demo/cc26xx-web-demo.c | 0 .../cc26xx-web-demo/cc26xx-web-demo.h | 0 .../cc26xx-web-demo/cetic-6lbr-client.c | 0 .../cc26xx-web-demo/coap-server.c | 0 .../cc26xx-web-demo/coap-server.h | 0 .../cc26xx-web-demo/httpd-simple.c | 0 .../cc26xx-web-demo/httpd-simple.h | 0 .../cc26xx-web-demo/img/6lbr-web.png | Bin .../ibm-watson-iot-platform-tls-optional.png | Bin .../img/quickstart-sensortag.png | Bin .../img/sensor-readings-config.png | Bin .../cc26xx-web-demo/img/well-known-core.png | Bin .../cc26xx-web-demo/mqtt-client.c | 0 .../cc26xx-web-demo/mqtt-client.h | 0 .../cc26xx-web-demo/net-uart.c | 0 .../cc26xx-web-demo/net-uart.h | 0 .../cc26xx-web-demo/project-conf.h | 0 .../cc26xx-web-demo/resources/res-ble-advd.c | 0 .../cc26xx-web-demo/resources/res-device.c | 0 .../cc26xx-web-demo/resources/res-leds.c | 0 .../cc26xx-web-demo/resources/res-net.c | 0 .../cc26xx-web-demo/resources/res-sensors.c | 0 .../resources/res-toggle-leds.c | 0 .../{cc26xx => cc26x0-cc13x0}/project-conf.h | 0 .../very-sleepy-demo/Makefile | 2 +- .../very-sleepy-demo/Makefile.target | 0 .../very-sleepy-demo/README.md | 0 .../very-sleepy-demo/project-conf.h | 0 .../very-sleepy-demo/very-sleepy-demo.c | 0 examples/sensniff/Makefile | 2 +- .../target-conf.h | 0 examples/storage/cfs-coffee/README.md | 2 +- tests/02-compile-arm-ports-01/Makefile | 70 +++++++++--------- 113 files changed, 52 insertions(+), 52 deletions(-) rename arch/platform/{srf06-cc26xx/Makefile.srf06-cc26xx => cc26x0-cc13x0/Makefile.cc26x0-cc13x0} (96%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/cfs-coffee-arch.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/common/xmem.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/contiki-conf.h (98%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/Makefile.launchpad (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/board-buttons.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/board-peripherals.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/board.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1310/Makefile.cc1310 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1310/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1350/Makefile.cc1350 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1350/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1350/rf-switch.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc1350/tx-power-driver.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc2640r2/Makefile.cc2640r2 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc2640r2/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc2650/Makefile.cc2650 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/cc2650/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/launchpad/leds-arch.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/platform.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/Makefile.sensortag (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/bmp-280-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/bmp-280-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/board-buttons.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/board-i2c.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/board-i2c.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/board-peripherals.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/board.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/buzzer.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/buzzer.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc1350/Makefile.cc1350 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc1350/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc1350/leds-arch.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc2650/Makefile.cc2650 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc2650/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/cc2650/leds-arch.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/hdc-1000-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/hdc-1000-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/mpu-9250-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/mpu-9250-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/opt-3001-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/opt-3001-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/sensor-common.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/sensor-common.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/sensortag-sensors.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/tmp-007-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/sensortag/tmp-007-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/Makefile.srf06 (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/als-sensor.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/als-sensor.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/board-buttons.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/board-peripherals.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/board.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/cc13xx/Makefile.cc13xx (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/cc13xx/board.h (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/cc26xx/Makefile.cc26xx (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/cc26xx/board.h (99%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/leds-arch.c (100%) rename arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/srf06/srf06-sensors.c (100%) rename examples/dev/gpio-hal/{srf06-cc26xx => cc26x0-cc13x0}/pins.c (100%) rename examples/mqtt-client/arch/platform/{srf06-cc26xx/Makefile.srf06-cc26xx => cc26x0-cc13x0/Makefile.cc26x0-cc13x0} (100%) rename examples/mqtt-client/arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/module-macros.h (100%) rename examples/mqtt-client/arch/platform/{srf06-cc26xx => cc26x0-cc13x0}/mqtt-client-extensions.c (100%) rename examples/multicast/{srf06-cc26xx => cc26x0-cc13x0}/module-macros.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/Makefile (78%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/Makefile.target (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/README.md (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/ble-ipv6/Makefile (73%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/ble-ipv6/README.md (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/ble-ipv6/client.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/ble-ipv6/project-conf.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-demo.c (99%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/Makefile (94%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/Makefile.target (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/README.md (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/cc26xx-web-demo.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/cc26xx-web-demo.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/cetic-6lbr-client.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/coap-server.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/coap-server.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/httpd-simple.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/httpd-simple.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/img/6lbr-web.png (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/img/quickstart-sensortag.png (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/img/sensor-readings-config.png (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/img/well-known-core.png (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/mqtt-client.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/mqtt-client.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/net-uart.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/net-uart.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/project-conf.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-ble-advd.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-device.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-leds.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-net.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-sensors.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/cc26xx-web-demo/resources/res-toggle-leds.c (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/project-conf.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/very-sleepy-demo/Makefile (83%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/very-sleepy-demo/Makefile.target (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/very-sleepy-demo/README.md (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/very-sleepy-demo/project-conf.h (100%) rename examples/platform-specific/{cc26xx => cc26x0-cc13x0}/very-sleepy-demo/very-sleepy-demo.c (100%) rename examples/sensniff/{srf06-cc26xx => cc26x0-cc13x0}/target-conf.h (100%) 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/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 similarity index 96% rename from arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx rename to arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 03eefcf8b..6ff30afc8 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -1,4 +1,4 @@ -# srf06-cc26xx platform makefile +# cc26x0-cc13x0 platform makefile ifndef CONTIKI $(error CONTIKI not defined! You must specify where CONTIKI resides!) 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 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1310/Makefile.cc1310 rename to arch/platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.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 100% rename from arch/platform/srf06-cc26xx/launchpad/cc1350/Makefile.cc1350 rename to arch/platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.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 100% rename from arch/platform/srf06-cc26xx/launchpad/cc2650/Makefile.cc2650 rename to arch/platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.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 100% rename from arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 rename to arch/platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.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 100% rename from arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 rename to arch/platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.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/cc13xx/Makefile.cc13xx similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/cc13xx/Makefile.cc13xx rename to arch/platform/cc26x0-cc13x0/srf06/cc13xx/Makefile.cc13xx diff --git a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc13xx/board.h similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/cc13xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc13xx/board.h diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/Makefile.cc26xx b/arch/platform/cc26x0-cc13x0/srf06/cc26xx/Makefile.cc26xx similarity index 100% rename from arch/platform/srf06-cc26xx/srf06/cc26xx/Makefile.cc26xx rename to arch/platform/cc26x0-cc13x0/srf06/cc26xx/Makefile.cc26xx diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc26xx/board.h similarity index 99% rename from arch/platform/srf06-cc26xx/srf06/cc26xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc26xx/board.h index f31a94fb3..cd6d2b1e4 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h +++ b/arch/platform/cc26x0-cc13x0/srf06/cc26xx/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/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/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/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/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 similarity index 100% rename from examples/mqtt-client/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx rename to examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.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/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/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/cc26xx/ble-ipv6/Makefile b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile similarity index 73% rename from examples/platform-specific/cc26xx/ble-ipv6/Makefile rename to examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile index 4ba928ad3..027c851e9 100644 --- a/examples/platform-specific/cc26xx/ble-ipv6/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile @@ -2,10 +2,10 @@ CONTIKI_PROJECT=client all: $(CONTIKI_PROJECT) -PLATFORMS_ONLY = srf06-cc26xx +PLATFORMS_ONLY = cc26x0-cc13x0 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 +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 100% rename from examples/platform-specific/cc26xx/ble-ipv6/README.md rename to examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md 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/cc26xx-demo.c similarity index 99% rename from examples/platform-specific/cc26xx/cc26xx-demo.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-demo.c index 81e99f3fa..1b71feeb7 100644 --- a/examples/platform-specific/cc26xx/cc26xx-demo.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26xx-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/cc26xx-web-demo/Makefile similarity index 94% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile index 05dbface1..74246220c 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = cc26xx-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/cc26xx-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/cc26xx-web-demo/Makefile.target diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/README.md similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/README.md rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/README.md diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26xx-web-demo.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26xx-web-demo.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26xx-web-demo.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26xx-web-demo.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cetic-6lbr-client.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/cetic-6lbr-client.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cetic-6lbr-client.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/coap-server.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/coap-server.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/coap-server.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.h rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/coap-server.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/httpd-simple.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/httpd-simple.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/httpd-simple.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/httpd-simple.h rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/httpd-simple.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/6lbr-web.png b/examples/platform-specific/cc26x0-cc13x0/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-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/cc26xx-web-demo/mqtt-client.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/mqtt-client.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/mqtt-client.h similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/mqtt-client.h rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/mqtt-client.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/net-uart.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/net-uart.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/net-uart.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-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/cc26xx-web-demo/net-uart.h diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h b/examples/platform-specific/cc26x0-cc13x0/cc26xx-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/cc26xx-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/cc26xx-web-demo/resources/res-ble-advd.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-ble-advd.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-ble-advd.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-device.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-device.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-device.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-device.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-leds.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-leds.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-leds.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-leds.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-net.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-net.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-net.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-net.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-sensors.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-sensors.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-sensors.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-sensors.c diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-toggle-leds.c b/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-toggle-leds.c similarity index 100% rename from examples/platform-specific/cc26xx/cc26xx-web-demo/resources/res-toggle-leds.c rename to examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/resources/res-toggle-leds.c 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/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/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/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index aaebab164..e5b403882 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/cc26xx-web-demo/cc26x0-cc13x0 \ +platform-specific/cc26x0-cc13x0/cc26xx-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/cc26xx-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc1350 \ +platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=srf06/cc13xx \ +platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ +platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ +platform-specific/cc26x0-cc13x0/cc26xx-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/cc13xx \ +dev/gpio-hal/cc26x0-cc13x0:BOARD=srf06/cc26xx \ +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/cc13xx \ +dev/leds/cc26x0-cc13x0:BOARD=srf06/cc26xx \ +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/cc26xx \ +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 \ From 7a6cbff5f6012894aee7d57f6032fe622ce20e72 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 12 Oct 2018 16:37:55 +0200 Subject: [PATCH 107/184] Rename srf06/{cc26xx,cc13xx} to srf06/{cc26x0,cc13x0} --- .../cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 4 +-- .../Makefile.cc13x0} | 2 +- .../srf06/{cc13xx => cc13x0}/board.h | 0 .../Makefile.cc26x0} | 2 +- .../srf06/{cc26xx => cc26x0}/board.h | 0 .../6tisch/channel-selection-demo/Makefile | 2 +- examples/6tisch/tsch-stats/Makefile | 2 +- examples/benchmarks/rpl-req-resp/Makefile | 2 +- .../cc26x0-cc13x0/ble-ipv6/Makefile | 2 +- .../{cc26xx-demo.c => cc26x0-demo.c} | 0 .../Makefile | 2 +- .../Makefile.target | 0 .../README.md | 2 +- .../cc26x0-web-demo.c} | 4 +-- .../cc26x0-web-demo.h} | 2 +- .../cetic-6lbr-client.c | 2 +- .../coap-server.c | 4 +-- .../coap-server.h | 2 +- .../httpd-simple.c | 4 +-- .../httpd-simple.h | 2 +- .../img/6lbr-web.png | Bin .../ibm-watson-iot-platform-tls-optional.png | Bin .../img/quickstart-sensortag.png | Bin .../img/sensor-readings-config.png | Bin .../img/well-known-core.png | Bin .../mqtt-client.c | 4 +-- .../mqtt-client.h | 2 +- .../net-uart.c | 2 +- .../net-uart.h | 0 .../project-conf.h | 0 .../resources/res-ble-advd.c | 2 +- .../resources/res-device.c | 4 +-- .../resources/res-leds.c | 2 +- .../resources/res-net.c | 4 +-- .../resources/res-sensors.c | 4 +-- .../resources/res-toggle-leds.c | 2 +- tests/02-compile-arm-ports-01/Makefile | 26 +++++++++--------- 37 files changed, 46 insertions(+), 46 deletions(-) rename arch/platform/cc26x0-cc13x0/srf06/{cc13xx/Makefile.cc13xx => cc13x0/Makefile.cc13x0} (82%) rename arch/platform/cc26x0-cc13x0/srf06/{cc13xx => cc13x0}/board.h (100%) rename arch/platform/cc26x0-cc13x0/srf06/{cc26xx/Makefile.cc26xx => cc26x0/Makefile.cc26x0} (81%) rename arch/platform/cc26x0-cc13x0/srf06/{cc26xx => cc26x0}/board.h (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-demo.c => cc26x0-demo.c} (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/Makefile (93%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/Makefile.target (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/README.md (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo/cc26xx-web-demo.c => cc26x0-web-demo/cc26x0-web-demo.c} (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo/cc26xx-web-demo.h => cc26x0-web-demo/cc26x0-web-demo.h} (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/cetic-6lbr-client.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/coap-server.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/coap-server.h (98%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/httpd-simple.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/httpd-simple.h (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/img/6lbr-web.png (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/img/ibm-watson-iot-platform-tls-optional.png (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/img/quickstart-sensortag.png (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/img/sensor-readings-config.png (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/img/well-known-core.png (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/mqtt-client.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/mqtt-client.h (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/net-uart.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/net-uart.h (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/project-conf.h (100%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-ble-advd.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-device.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-leds.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-net.c (98%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-sensors.c (99%) rename examples/platform-specific/cc26x0-cc13x0/{cc26xx-web-demo => cc26x0-web-demo}/resources/res-toggle-leds.c (99%) diff --git a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 6ff30afc8..0c7557ab1 100644 --- a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -5,8 +5,8 @@ ifndef CONTIKI 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 += . diff --git a/arch/platform/cc26x0-cc13x0/srf06/cc13xx/Makefile.cc13xx b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 similarity index 82% rename from arch/platform/cc26x0-cc13x0/srf06/cc13xx/Makefile.cc13xx rename to arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 index b83084651..2d92d9113 100644 --- a/arch/platform/cc26x0-cc13x0/srf06/cc13xx/Makefile.cc13xx +++ b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 @@ -4,4 +4,4 @@ CPU_FAMILY = cc13xx ### 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/cc26x0-cc13x0/srf06/cc13xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/board.h similarity index 100% rename from arch/platform/cc26x0-cc13x0/srf06/cc13xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc13x0/board.h diff --git a/arch/platform/cc26x0-cc13x0/srf06/cc26xx/Makefile.cc26xx b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 similarity index 81% rename from arch/platform/cc26x0-cc13x0/srf06/cc26xx/Makefile.cc26xx rename to arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 index 841442a5c..6e4a09629 100644 --- a/arch/platform/cc26x0-cc13x0/srf06/cc26xx/Makefile.cc26xx +++ b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 @@ -4,4 +4,4 @@ CPU_FAMILY = cc26xx ### 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/cc26x0-cc13x0/srf06/cc26xx/board.h b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/board.h similarity index 100% rename from arch/platform/cc26x0-cc13x0/srf06/cc26xx/board.h rename to arch/platform/cc26x0-cc13x0/srf06/cc26x0/board.h 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/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/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile index 027c851e9..052927896 100644 --- a/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/Makefile @@ -3,7 +3,7 @@ CONTIKI_PROJECT=client all: $(CONTIKI_PROJECT) PLATFORMS_ONLY = cc26x0-cc13x0 -BOARDS_ONLY = launchpad/cc2650 sensortag/cc2650 srf06/cc26xx +BOARDS_ONLY = launchpad/cc2650 sensortag/cc2650 srf06/cc26x0 MAKE_MAC = MAKE_MAC_BLE MAKE_NET = MAKE_NET_IPV6 diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26xx-demo.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-demo.c similarity index 100% rename from examples/platform-specific/cc26x0-cc13x0/cc26xx-demo.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-demo.c diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile similarity index 93% rename from examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile index 74246220c..6d70a3a24 100644 --- a/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile @@ -1,4 +1,4 @@ -CONTIKI_PROJECT = cc26xx-web-demo +CONTIKI_PROJECT = cc26x0-web-demo all: $(CONTIKI_PROJECT) PLATFORMS_ONLY = cc26x0-cc13x0 diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile.target b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile.target similarity index 100% rename from examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/Makefile.target rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/Makefile.target diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26xx-web-demo/README.md b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/README.md similarity index 99% rename from examples/platform-specific/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/cc26xx-web-demo/httpd-simple.c rename to examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c index e23e78efe..287452bb3 100644 --- a/examples/platform-specific/cc26x0-cc13x0/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 @@ -42,7 +42,7 @@ #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" diff --git a/examples/platform-specific/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/cc26x0-cc13x0/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/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index e5b403882..43e008c8e 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -2,31 +2,31 @@ EXAMPLESDIR=../../examples TOOLSDIR=../../tools EXAMPLES = \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0 \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +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/cc26xx-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc2650 \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=sensortag/cc1350 \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=srf06/cc13xx \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc2650 \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc1310 \ -platform-specific/cc26x0-cc13x0/cc26xx-web-demo/cc26x0-cc13x0:BOARD=launchpad/cc1350 \ +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/cc13xx \ -dev/gpio-hal/cc26x0-cc13x0:BOARD=srf06/cc26xx \ +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/cc13xx \ -dev/leds/cc26x0-cc13x0:BOARD=srf06/cc26xx \ +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 \ @@ -34,7 +34,7 @@ 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/cc26xx \ +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 \ From 0bcdd39cc60b81a7c3390a40e54f7b7cbfb08532 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 12 Oct 2018 19:38:18 +0200 Subject: [PATCH 108/184] Rename 'arch/cpu/cc26xx-cc13xx' to 'arch/cpu/cc26x0-cc13x0' --- .gitmodules | 6 +++--- .../Makefile.cc13xx => cc26x0-cc13x0/Makefile.cc13x0} | 2 +- .../Makefile.cc26xx => cc26x0-cc13x0/Makefile.cc26x0} | 2 +- .../Makefile.cc26x0-cc13x0} | 2 +- .../cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/Makefile.cc26x0r2f | 2 +- arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ble-addr.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ble-addr.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/cc13x0-cc26x0-cm3.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/cc13xx-cc26xx-conf.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/cc13xx-cc26xx-def.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/cc26xx.ld | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ccxxware-conf.h | 2 +- arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/clock.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dbg.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/adc-sensor.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/adc-sensor.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/aux-ctrl.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/aux-ctrl.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/batmon-sensor.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/batmon-sensor.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/cc26xx-uart.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/cc26xx-uart.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/contiki-watchdog.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-hal-arch.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-hal-arch.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-interrupt.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/oscillators.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/oscillators.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-rtc.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-rtc.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-trng.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-trng.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/spi-arch.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/doxygen-group.txt | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/fault-handlers.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ieee-addr.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ieee-addr.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/int-master.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc13xxware | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc2640r2-sdk | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc26xxware | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lpm.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lpm.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/random.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/api/ieee_cmd.h | 0 .../rf-core/api/ieee_mailbox.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-cc2650.c | 0 .../rf-core/ble-hal/ble-hal-cc26xx.c | 0 .../rf-core/ble-hal/ble-hal-cc26xx.h | 0 .../rf-core/ble-hal/rf-ble-cmd.c | 0 .../rf-core/ble-hal/rf-ble-cmd.h | 0 .../rf-core/cc13xx-50kbps-tsch.c | 0 .../rf-core/cc13xx-50kbps-tsch.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/dot-15-4g.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ieee-mode.c | 0 .../rf-core/prop-mode-tx-power.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/prop-mode.c | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/prop-mode.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-ble.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-ble.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-core.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-core.h | 0 .../{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-switch.h | 0 .../rf-core/smartrf-settings.c | 0 .../rf-core/smartrf-settings.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rtimer-arch.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rtimer-arch.h | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/slip-arch.c | 0 arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ti-lib.h | 0 arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 2 +- .../platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 | 2 +- .../platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 | 2 +- .../platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 | 2 +- .../platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 | 2 +- .../platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 | 2 +- arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 | 2 +- arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 | 2 +- .../cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/builtin-sensors.c | 0 .../cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/builtin-sensors.h | 0 .../arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 2 +- examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md | 6 +++--- tools/doxygen/Doxyfile | 4 ++-- 82 files changed, 22 insertions(+), 22 deletions(-) rename arch/cpu/{cc26xx-cc13xx/Makefile.cc13xx => cc26x0-cc13x0/Makefile.cc13x0} (80%) rename arch/cpu/{cc26xx-cc13xx/Makefile.cc26xx => cc26x0-cc13x0/Makefile.cc26x0} (65%) rename arch/cpu/{cc26xx-cc13xx/Makefile.cc26xx-cc13xx => cc26x0-cc13x0/Makefile.cc26x0-cc13x0} (98%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/Makefile.cc26x0r2f (67%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ble-addr.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ble-addr.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/cc13x0-cc26x0-cm3.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/cc13xx-cc26xx-conf.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/cc13xx-cc26xx-def.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/cc26xx.ld (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ccxxware-conf.h (98%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/clock.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dbg.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/adc-sensor.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/adc-sensor.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/aux-ctrl.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/aux-ctrl.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/batmon-sensor.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/batmon-sensor.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/cc26xx-uart.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/cc26xx-uart.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/contiki-watchdog.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-hal-arch.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-hal-arch.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/gpio-interrupt.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/oscillators.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/oscillators.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-rtc.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-rtc.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-trng.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/soc-trng.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/dev/spi-arch.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/doxygen-group.txt (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/fault-handlers.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ieee-addr.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ieee-addr.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/int-master.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc13xxware (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc2640r2-sdk (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lib/cc26xxware (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lpm.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/lpm.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/random.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/api/ieee_cmd.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/api/ieee_mailbox.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-cc2650.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-hal/ble-hal-cc26xx.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-hal/ble-hal-cc26xx.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-hal/rf-ble-cmd.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ble-hal/rf-ble-cmd.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/cc13xx-50kbps-tsch.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/cc13xx-50kbps-tsch.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/dot-15-4g.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/ieee-mode.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/prop-mode-tx-power.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/prop-mode.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/prop-mode.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-ble.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-ble.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-core.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-core.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/rf-switch.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/smartrf-settings.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rf-core/smartrf-settings.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rtimer-arch.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/rtimer-arch.h (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/slip-arch.c (100%) rename arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/ti-lib.h (100%) rename examples/mqtt-client/arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/builtin-sensors.c (100%) rename examples/mqtt-client/arch/cpu/{cc26xx-cc13xx => cc26x0-cc13x0}/builtin-sensors.h (100%) 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/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx b/arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 similarity index 80% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc13xx rename to arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 index 5ea92e30c..c29ee7270 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc13x0 @@ -4,4 +4,4 @@ CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c 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 98% rename from arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx rename to arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 592ddfbd8..e62b8be05 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -1,4 +1,4 @@ -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)/*)) 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 100% rename from arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h rename to arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-def.h 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 100% 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 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/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c rename to arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h rename to arch/cpu/cc26x0-cc13x0/rf-core/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 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c rename to arch/cpu/cc26x0-cc13x0/rf-core/ieee-mode.c 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 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c rename to arch/cpu/cc26x0-cc13x0/rf-core/prop-mode.c 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 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c rename to arch/cpu/cc26x0-cc13x0/rf-core/rf-core.c diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h b/arch/cpu/cc26x0-cc13x0/rf-core/rf-core.h similarity index 100% rename from arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h rename to arch/cpu/cc26x0-cc13x0/rf-core/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 100% rename from arch/cpu/cc26xx-cc13xx/ti-lib.h rename to arch/cpu/cc26x0-cc13x0/ti-lib.h diff --git a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 0c7557ab1..43cc7ea3f 100644 --- a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -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/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 b/arch/platform/cc26x0-cc13x0/launchpad/cc1310/Makefile.cc1310 index 8d3d2abd4..e9f7bab91 100644 --- a/arch/platform/cc26x0-cc13x0/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/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 b/arch/platform/cc26x0-cc13x0/launchpad/cc1350/Makefile.cc1350 index 0d1f65359..811a3f61b 100644 --- a/arch/platform/cc26x0-cc13x0/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/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 b/arch/platform/cc26x0-cc13x0/launchpad/cc2650/Makefile.cc2650 index 72e50de3a..399cd79e5 100644 --- a/arch/platform/cc26x0-cc13x0/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/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 b/arch/platform/cc26x0-cc13x0/sensortag/cc1350/Makefile.cc1350 index cdae4c2b1..f0f924e97 100644 --- a/arch/platform/cc26x0-cc13x0/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/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 b/arch/platform/cc26x0-cc13x0/sensortag/cc2650/Makefile.cc2650 index e91cabda4..4aa83e352 100644 --- a/arch/platform/cc26x0-cc13x0/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/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 index 2d92d9113..ec20fcb63 100644 --- a/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 +++ b/arch/platform/cc26x0-cc13x0/srf06/cc13x0/Makefile.cc13x0 @@ -1,5 +1,5 @@ ### 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 diff --git a/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 index 6e4a09629..84ef217a8 100644 --- a/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 +++ b/arch/platform/cc26x0-cc13x0/srf06/cc26x0/Makefile.cc26x0 @@ -1,5 +1,5 @@ ### 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 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 index dcec87bad..7c74123c6 100644 --- a/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/examples/mqtt-client/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -1 +1 @@ -MODULES_REL += arch/cpu/cc26xx-cc13xx +MODULES_REL += arch/cpu/cc26x0-cc13x0 diff --git a/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md b/examples/platform-specific/cc26x0-cc13x0/ble-ipv6/README.md index d33c7329f..078667264 100644 --- a/examples/platform-specific/cc26x0-cc13x0/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/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/* \ From 2af3665b04e0451922ea54d8cfffceaffb939bb8 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 12 Oct 2018 19:39:10 +0200 Subject: [PATCH 109/184] simplelink: correct a comment in Makefile.cc13xx-cc26xx --- arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From feb1513b4699ea915c0024c0860c019c112c42b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Wed, 24 Oct 2018 15:26:40 +0200 Subject: [PATCH 110/184] Unmodulated carrier transmission for cc2420 Modified the cc2420 driver to enable the radio test mode to emit unmodulated carriers (tones). A carrier can be enabled using the normal radio driver API: NETSTACK_CONF_RADIO.set_value( RADIO_PARAM_POWER_MODE, RADIO_POWER_MODE_CARRIER_ON); Once enabled, the carrier can be disabled like this: NETSTACK_CONF_RADIO.set_value( RADIO_PARAM_POWER_MODE, RADIO_POWER_MODE_CARRIER_OFF); --- arch/dev/cc2420/cc2420.c | 41 +++++++++++++++++++++++++++++++++++++++- os/dev/radio.h | 4 +++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index a1572b0ef..7dfa1900b 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -114,6 +114,7 @@ PROCESS(cc2420_process, "CC2420 driver"); #define CORR_THR(n) (((n) & 0x1f) << 6) #define FIFOP_THR(n) ((n) & 0x7f) #define RXBPF_LOCUR (1 << 13); +#define TX_MODE (3 << 2) int cc2420_on(void); int cc2420_off(void); @@ -135,6 +136,8 @@ static void set_poll_mode(uint8_t enable); static void set_send_on_cca(uint8_t enable); static void set_auto_ack(uint8_t enable); +static void set_test_mode(uint8_t enable, uint8_t modulated); + signed char cc2420_last_rssi; uint8_t cc2420_last_correlation; @@ -156,7 +159,11 @@ get_value(radio_param_t param, radio_value_t *value) } switch(param) { case RADIO_PARAM_POWER_MODE: - *value = receive_on ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF; + if ((getreg(CC2420_MDMCTRL1) & TX_MODE) & 0x08) { + *value = RADIO_POWER_MODE_CARRIER_ON; + } else { + *value = receive_on ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF; + } return RADIO_RESULT_OK; case RADIO_PARAM_CHANNEL: *value = cc2420_get_channel(); @@ -237,6 +244,11 @@ set_value(radio_param_t param, radio_value_t value) cc2420_off(); return RADIO_RESULT_OK; } + if(value == RADIO_POWER_MODE_CARRIER_ON || + value == RADIO_POWER_MODE_CARRIER_OFF) { + set_test_mode((value == RADIO_POWER_MODE_CARRIER_ON), 0); + return RADIO_RESULT_OK; + } return RADIO_RESULT_INVALID_VALUE; case RADIO_PARAM_CHANNEL: if(value < 11 || value > 26) { @@ -1120,3 +1132,30 @@ set_send_on_cca(uint8_t enable) send_on_cca = enable; } /*---------------------------------------------------------------------------*/ +/* Enable or disable radio test mode emmiting modulated or unmodulated + * (carrier) signal. See datasheet page 55. +*/ +static uint16_t prev_MDMCTRL1, prev_DACTST; + +static void +set_test_mode(uint8_t enable, uint8_t modulated) +{ + if (enable) { + prev_MDMCTRL1 = getreg(CC2420_MDMCTRL1); + setreg(CC2420_MDMCTRL1, 0x050C); + if (!modulated) { + prev_DACTST = getreg(CC2420_DACTST); + setreg(CC2420_DACTST, 0x1800); + } + /* actually starts the test mode */ + strobe(CC2420_STXON); + } else { + if (!modulated) { + setreg(CC2420_DACTST, prev_DACTST); + } + setreg(CC2420_MDMCTRL1, prev_MDMCTRL1); + /* actually stops the carrier */ + strobe(CC2420_SRFOFF); + } +} +/*---------------------------------------------------------------------------*/ diff --git a/os/dev/radio.h b/os/dev/radio.h index e6ca64f3d..e279e9efe 100644 --- a/os/dev/radio.h +++ b/os/dev/radio.h @@ -196,7 +196,9 @@ enum { /* Radio power modes */ enum { RADIO_POWER_MODE_OFF, - RADIO_POWER_MODE_ON + RADIO_POWER_MODE_ON, + RADIO_POWER_MODE_CARRIER_ON, + RADIO_POWER_MODE_CARRIER_OFF }; /** From e29093efecdfb1af06e450f8b567c107dcf9372d Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 30 Mar 2018 00:14:22 +0200 Subject: [PATCH 111/184] tests/09-ipv6: add tests for UIP_DS6_NBR_MULTI_IPV6_ADDRS feature --- tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/code/Makefile | 4 + tests/09-ipv6/js/ping-test-lla-ula.js | 72 ++++++++++++ 6 files changed, 508 insertions(+) create mode 100644 tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc create mode 100644 tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc create mode 100644 tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc create mode 100644 tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc create mode 100644 tests/09-ipv6/js/ping-test-lla-ula.js 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(); + } + } +} From 8ef5c8b8c68619f89ee14e7fae1f4ddb354c8863 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Sat, 31 Mar 2018 18:35:25 +0200 Subject: [PATCH 112/184] uip-ds6-nbr: make ds6_neighbors a local variable All the nbr_table API calls with ds6_neighbors are replaced with uip_ds6_nbr APIs accordingly. --- .../cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c | 5 +++-- .../zoul/orion/ip64-router/ip64-router.c | 5 +++-- examples/rpl-border-router/webserver/webserver.c | 5 +++-- os/net/ipv6/uip-ds6-nbr.c | 2 +- os/net/ipv6/uip-ds6-nbr.h | 2 -- os/net/routing/rpl-classic/rpl-dag.c | 6 +++--- os/net/routing/rpl-classic/rpl-nbr-policy.c | 10 +++++----- os/net/routing/rpl-classic/rpl.h | 2 +- os/net/routing/rpl-lite/rpl-nbr-policy.c | 8 ++++---- os/net/routing/rpl-lite/rpl-neighbor.c | 4 ++-- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c index 287452bb3..101b6441b 100644 --- a/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c @@ -38,6 +38,7 @@ /*---------------------------------------------------------------------------*/ #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" @@ -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/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/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index f937986b5..619e9c347 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -60,7 +60,7 @@ #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 -NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors); +NBR_TABLE(uip_ds6_nbr_t, ds6_neighbors); /*---------------------------------------------------------------------------*/ void diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index d645ac627..4de17249c 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -63,8 +63,6 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 -NBR_TABLE_DECLARE(ds6_neighbors); - /** \brief An entry in the nbr cache */ typedef struct uip_ds6_nbr { uip_ipaddr_t ipaddr; 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-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c index 344840d0e..fc77ba5ed 100644 --- a/os/net/routing/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -70,7 +70,7 @@ 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 +112,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 +127,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 +159,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..9777be6de 100644 --- a/os/net/routing/rpl-classic/rpl.h +++ b/os/net/routing/rpl-classic/rpl.h @@ -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-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c index 9752b1446..e9d256eee 100644 --- a/os/net/routing/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -63,7 +63,7 @@ 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 +79,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 +98,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; } From ee452b528753c5426355721e001510f4421696eb Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Sun, 1 Apr 2018 12:50:31 +0200 Subject: [PATCH 113/184] uip-ds6-nbr: introduce UIP_DS6_NBR_MULTI_IPV6_ADDRS This feature, which is disabled by default, extends the neighbor cache management in order to have multiple IPv6 address associated with a single link-layer address as neighbor caches. To use this feature, set 1 to UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES. --- os/net/ipv6/uip-ds6-nbr.c | 298 +++++++++++++++++++++++++++++++++++--- os/net/ipv6/uip-ds6-nbr.h | 28 ++++ 2 files changed, 303 insertions(+), 23 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index 619e9c347..f4404e8c8 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -55,19 +55,40 @@ #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 +#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); +static void remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr); +static void remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry); +static void free_uip_ds6_nbr(uip_ds6_nbr_t *nbr); +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 +96,44 @@ 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; + } + + 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 NULL; + } else { + LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); + } + } + + 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__); + if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { + nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); + } + } else { + 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 +170,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 +263,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 +330,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 +345,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 +435,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 +469,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 +510,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 +535,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 +606,7 @@ uip_ds6_neighbor_periodic(void) default: break; } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); } } /*---------------------------------------------------------------------------*/ @@ -373,7 +625,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 +636,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 4de17249c..b6b228d2d 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,8 +67,32 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 +#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 */ + +#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 +#endif /* UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES */ + + +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/** \brief An nbr_table entry for neighbor caches */ +typedef struct { + LIST_STRUCT(uip_ds6_nbrs); +} uip_ds6_nbr_entry_t; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /** \brief An entry in the 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; From 17aa75f0cf6ee00535f3d84e93863b418645c23c Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Mon, 20 Aug 2018 19:26:27 +0200 Subject: [PATCH 114/184] uip-ds6-nbr: add doxygen comments (and re-order some functions) --- os/net/ipv6/uip-ds6-nbr.c | 27 +++++++++ os/net/ipv6/uip-ds6-nbr.h | 124 ++++++++++++++++++++++++++++++++++---- 2 files changed, 139 insertions(+), 12 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index f4404e8c8..c83fa7674 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -65,12 +65,39 @@ #define LOG_LEVEL LOG_LEVEL_IPV6 #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 diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index b6b228d2d..809f01d2b 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -67,27 +67,33 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 +/** \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 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 +#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 An nbr_table entry for neighbor caches */ +/** \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 An entry in the nbr cache */ +/** \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; @@ -109,25 +115,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 From 319b70345ab54bf89139190c85c169761f5094a4 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 17:28:13 +0200 Subject: [PATCH 115/184] uip-ds6-nbr: introduce UIP_DS6_NBR_MAX_6ADDRS_PER_NBR --- os/net/ipv6/uip-ds6-nbr.c | 13 +++++++++++++ os/net/ipv6/uip-ds6-nbr.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index c83fa7674..0db8a0f45 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -149,6 +149,19 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, } } + if(list_length(nbr_entry->uip_ds6_nbrs) < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* it has room to add another IPv6 address */ + } else { + /* + * 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"); + return NULL; + } + 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__); if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index 809f01d2b..6479c972e 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -75,6 +75,14 @@ #define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0 #endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */ +/** \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 From 54a2889614bc2f5121cf506a95e6c6f66e6f51a4 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 14:20:08 +0200 Subject: [PATCH 116/184] test/10-ipv6-nbr: add 01-test-nbr-multi-addrs --- .travis.yml | 1 + tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh | 21 ++ tests/10-ipv6-nbr/Makefile | 1 + tests/10-ipv6-nbr/nbr-multi-addrs/Makefile | 14 + tests/10-ipv6-nbr/nbr-multi-addrs/test.c | 260 +++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100755 tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh create mode 100644 tests/10-ipv6-nbr/Makefile create mode 100644 tests/10-ipv6-nbr/nbr-multi-addrs/Makefile create mode 100644 tests/10-ipv6-nbr/nbr-multi-addrs/test.c diff --git a/.travis.yml b/.travis.yml index 60d8db747..d9c98d75d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,3 +68,4 @@ env: - TEST_NAME='compile-tools' - TEST_NAME='native-runs' - TEST_NAME='ipv6' BUILD_COOJA=true + - TEST_NAME='ipv6-nbr' BUILD_COOJA=true 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(); +} From 4d8bb2f55093eda519e27d2c90d018d29cf1b3f9 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 18:27:40 +0200 Subject: [PATCH 117/184] uip-ds6-nbr: check memb availability before adding an nbr_table entry --- os/net/ipv6/uip-ds6-nbr.c | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index 0db8a0f45..b8f8b63d7 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -136,6 +136,13 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, 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) { @@ -143,31 +150,30 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, 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 NULL; + /* return from this function later */ } else { LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); } } - if(list_length(nbr_entry->uip_ds6_nbrs) < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { - /* it has room to add another IPv6 address */ - } else { - /* - * 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"); - return NULL; - } - - 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__); - if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { - nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); + /* 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 From 79a4fe33a6d33a34a986dc18a6e3fbeba388a0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Thu, 25 Oct 2018 11:24:44 +0200 Subject: [PATCH 118/184] Unmodulated carrier transmission for cc2538 Modified the cc2538 driver to enable the radio test mode to emit unmodulated carriers (tones). A carrier can be enabled using the normal radio driver API: NETSTACK_CONF_RADIO.set_value( RADIO_PARAM_POWER_MODE, RADIO_POWER_MODE_CARRIER_ON); Once enabled, the carrier can be disabled like this: NETSTACK_CONF_RADIO.set_value( RADIO_PARAM_POWER_MODE, RADIO_POWER_MODE_CARRIER_OFF); --- arch/cpu/cc2538/dev/cc2538-rf.c | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index bddfcc942..32a8eef81 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -140,6 +140,8 @@ static const output_config_t output_power[] = { {-24, 0x00 }, }; +static radio_result_t get_value(radio_param_t param, radio_value_t *value); + #define OUTPUT_CONFIG_COUNT (sizeof(output_power) / sizeof(output_config_t)) /* Max and Min Output Power in dBm */ @@ -394,6 +396,50 @@ get_sfd_timestamp(void) return RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd); } /*---------------------------------------------------------------------------*/ +/* Enable or disable radio test mode emmiting modulated or unmodulated + * (carrier) signal. See datasheet page XX +*/ +static uint32_t prev_FRMCTRL0, prev_MDMTEST1; +static uint8_t was_on; + +static void +set_test_mode(uint8_t enable, uint8_t modulated) +{ + radio_value_t mode; + get_value(RADIO_PARAM_POWER_MODE, &mode); + + if (enable) { + if (mode == RADIO_POWER_MODE_CARRIER_ON) { + return; + } + was_on = (mode == RADIO_POWER_MODE_ON); + off(); + prev_FRMCTRL0 = REG(RFCORE_XREG_FRMCTRL0); + // This constantly transmits random data + printf("FRMCTRL0: %08X\n", (unsigned int)prev_FRMCTRL0); + REG(RFCORE_XREG_FRMCTRL0) = 0x00000042; + if (!modulated) { + prev_MDMTEST1 = REG(RFCORE_XREG_MDMTEST1); + printf("MDMTEST1: %08X\n", (unsigned int)prev_MDMTEST1); + // ...adding this we send an unmodulated carrier instead + REG(RFCORE_XREG_MDMTEST1) = 0x00000018; + } + CC2538_RF_CSP_ISTXON(); + } else { + if (mode != RADIO_POWER_MODE_CARRIER_ON) { + return; + } + CC2538_RF_CSP_ISRFOFF(); + REG(RFCORE_XREG_FRMCTRL0) = prev_FRMCTRL0; + if (!modulated) { + REG(RFCORE_XREG_MDMTEST1) = prev_MDMTEST1; + } + if (was_on) { + on(); + } + } +} +/*---------------------------------------------------------------------------*/ /* Netstack API radio driver functions */ /*---------------------------------------------------------------------------*/ static int @@ -806,8 +852,12 @@ get_value(radio_param_t param, radio_value_t *value) switch(param) { case RADIO_PARAM_POWER_MODE: - *value = (REG(RFCORE_XREG_RXENABLE) && RFCORE_XREG_RXENABLE_RXENMASK) == 0 - ? RADIO_POWER_MODE_OFF : RADIO_POWER_MODE_ON; + if ((REG(RFCORE_XREG_RXENABLE) & RFCORE_XREG_RXENABLE_RXENMASK) == 0) { + *value = RADIO_POWER_MODE_OFF; + } else { + *value = (REG(RFCORE_XREG_FRMCTRL0) & RFCORE_XREG_FRMCTRL0_TX_MODE) == 0 + ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_CARRIER_ON; + } return RADIO_RESULT_OK; case RADIO_PARAM_CHANNEL: *value = (radio_value_t)get_channel(); @@ -895,6 +945,11 @@ set_value(radio_param_t param, radio_value_t value) if(value == RADIO_POWER_MODE_OFF) { off(); return RADIO_RESULT_OK; + } + if(value == RADIO_POWER_MODE_CARRIER_ON || + value == RADIO_POWER_MODE_CARRIER_OFF) { + set_test_mode((value == RADIO_POWER_MODE_CARRIER_ON), 0); + return RADIO_RESULT_OK; } return RADIO_RESULT_INVALID_VALUE; case RADIO_PARAM_CHANNEL: From c6770112af8663761d1f2a260224eda7c0818456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Thu, 25 Oct 2018 11:49:20 +0200 Subject: [PATCH 119/184] Fixed code style and removed forgotten pritf's --- arch/cpu/cc2538/dev/cc2538-rf.c | 18 ++++++++---------- arch/dev/cc2420/cc2420.c | 8 ++++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index 32a8eef81..23e3e11e0 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -408,33 +408,31 @@ set_test_mode(uint8_t enable, uint8_t modulated) radio_value_t mode; get_value(RADIO_PARAM_POWER_MODE, &mode); - if (enable) { - if (mode == RADIO_POWER_MODE_CARRIER_ON) { + if(enable) { + if(mode == RADIO_POWER_MODE_CARRIER_ON) { return; } was_on = (mode == RADIO_POWER_MODE_ON); off(); prev_FRMCTRL0 = REG(RFCORE_XREG_FRMCTRL0); - // This constantly transmits random data - printf("FRMCTRL0: %08X\n", (unsigned int)prev_FRMCTRL0); + /* This constantly transmits random data */ REG(RFCORE_XREG_FRMCTRL0) = 0x00000042; - if (!modulated) { + if(!modulated) { prev_MDMTEST1 = REG(RFCORE_XREG_MDMTEST1); - printf("MDMTEST1: %08X\n", (unsigned int)prev_MDMTEST1); - // ...adding this we send an unmodulated carrier instead + /* ...adding this we send an unmodulated carrier instead */ REG(RFCORE_XREG_MDMTEST1) = 0x00000018; } CC2538_RF_CSP_ISTXON(); } else { - if (mode != RADIO_POWER_MODE_CARRIER_ON) { + if(mode != RADIO_POWER_MODE_CARRIER_ON) { return; } CC2538_RF_CSP_ISRFOFF(); REG(RFCORE_XREG_FRMCTRL0) = prev_FRMCTRL0; - if (!modulated) { + if(!modulated) { REG(RFCORE_XREG_MDMTEST1) = prev_MDMTEST1; } - if (was_on) { + if(was_on) { on(); } } diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 7dfa1900b..58c77e140 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -159,7 +159,7 @@ get_value(radio_param_t param, radio_value_t *value) } switch(param) { case RADIO_PARAM_POWER_MODE: - if ((getreg(CC2420_MDMCTRL1) & TX_MODE) & 0x08) { + if((getreg(CC2420_MDMCTRL1) & TX_MODE) & 0x08) { *value = RADIO_POWER_MODE_CARRIER_ON; } else { *value = receive_on ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF; @@ -1140,17 +1140,17 @@ static uint16_t prev_MDMCTRL1, prev_DACTST; static void set_test_mode(uint8_t enable, uint8_t modulated) { - if (enable) { + if(enable) { prev_MDMCTRL1 = getreg(CC2420_MDMCTRL1); setreg(CC2420_MDMCTRL1, 0x050C); - if (!modulated) { + if(!modulated) { prev_DACTST = getreg(CC2420_DACTST); setreg(CC2420_DACTST, 0x1800); } /* actually starts the test mode */ strobe(CC2420_STXON); } else { - if (!modulated) { + if(!modulated) { setreg(CC2420_DACTST, prev_DACTST); } setreg(CC2420_MDMCTRL1, prev_MDMCTRL1); From a906f03a253e906c9c9a8f37188db868a85a9b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Fri, 26 Oct 2018 16:28:20 +0200 Subject: [PATCH 120/184] cc2420 return to last state when disabling carrier Made cc2420 follow the same logic as cc2538 when disabling the unmodulated carrier. Now they both return to the state they were in before the carrier was enabled. --- arch/cpu/cc2538/dev/cc2538-rf.c | 2 +- arch/dev/cc2420/cc2420.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index 23e3e11e0..cee2197e7 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -397,7 +397,7 @@ get_sfd_timestamp(void) } /*---------------------------------------------------------------------------*/ /* Enable or disable radio test mode emmiting modulated or unmodulated - * (carrier) signal. See datasheet page XX + * (carrier) signal. See User's Guide pages 719 and 741. */ static uint32_t prev_FRMCTRL0, prev_MDMTEST1; static uint8_t was_on; diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 58c77e140..18b289c1d 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -1136,11 +1136,20 @@ set_send_on_cca(uint8_t enable) * (carrier) signal. See datasheet page 55. */ static uint16_t prev_MDMCTRL1, prev_DACTST; +static uint8_t was_on; static void set_test_mode(uint8_t enable, uint8_t modulated) { + radio_value_t mode; + get_value(RADIO_PARAM_POWER_MODE, &mode); + if(enable) { + if(mode == RADIO_POWER_MODE_CARRIER_ON) { + return; + } + was_on = (mode == RADIO_POWER_MODE_ON); + off(); prev_MDMCTRL1 = getreg(CC2420_MDMCTRL1); setreg(CC2420_MDMCTRL1, 0x050C); if(!modulated) { @@ -1150,12 +1159,18 @@ set_test_mode(uint8_t enable, uint8_t modulated) /* actually starts the test mode */ strobe(CC2420_STXON); } else { + if(mode != RADIO_POWER_MODE_CARRIER_ON) { + return; + } + strobe(CC2420_SRFOFF); if(!modulated) { setreg(CC2420_DACTST, prev_DACTST); } setreg(CC2420_MDMCTRL1, prev_MDMCTRL1); /* actually stops the carrier */ - strobe(CC2420_SRFOFF); + if(was_on) { + on(); + } } } /*---------------------------------------------------------------------------*/ From 468a14b528794121077af1cb113720fb8290cef5 Mon Sep 17 00:00:00 2001 From: kkrentz Date: Sat, 27 Oct 2018 02:31:28 -0700 Subject: [PATCH 121/184] moved initialization of queuebuf to contikimac-main.c --- arch/platform/nrf52dk/contiki-conf.h | 4 ++++ os/contiki-main.c | 4 ++++ os/net/ipv6/sicslowpan.c | 5 ----- os/net/mac/csma/csma-output.c | 1 - os/net/mac/tsch/tsch.c | 3 +-- os/net/queuebuf.h | 6 ++++++ 6 files changed, 15 insertions(+), 8 deletions(-) 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/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/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 9e4e3a8b4..034045e7d 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -2061,11 +2061,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/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 1773e0cb0..0436bacea 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -539,5 +539,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.c b/os/net/mac/tsch/tsch.c index 60638eaaf..8a5218355 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -972,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 From 2d2d6b3ad6d9b02f228a7c95ff8fdfe164222135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Mon, 29 Oct 2018 11:15:40 +0100 Subject: [PATCH 122/184] Fixed code style issues --- arch/cpu/cc2538/dev/cc2538-rf.c | 12 ++++++------ arch/dev/cc2420/cc2420.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index cee2197e7..e3a548067 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -396,9 +396,9 @@ get_sfd_timestamp(void) return RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd); } /*---------------------------------------------------------------------------*/ -/* Enable or disable radio test mode emmiting modulated or unmodulated +/* Enable or disable radio test mode emmiting modulated or unmodulated * (carrier) signal. See User's Guide pages 719 and 741. -*/ + */ static uint32_t prev_FRMCTRL0, prev_MDMTEST1; static uint8_t was_on; @@ -407,7 +407,7 @@ set_test_mode(uint8_t enable, uint8_t modulated) { radio_value_t mode; get_value(RADIO_PARAM_POWER_MODE, &mode); - + if(enable) { if(mode == RADIO_POWER_MODE_CARRIER_ON) { return; @@ -416,7 +416,7 @@ set_test_mode(uint8_t enable, uint8_t modulated) off(); prev_FRMCTRL0 = REG(RFCORE_XREG_FRMCTRL0); /* This constantly transmits random data */ - REG(RFCORE_XREG_FRMCTRL0) = 0x00000042; + REG(RFCORE_XREG_FRMCTRL0) = 0x00000042; if(!modulated) { prev_MDMTEST1 = REG(RFCORE_XREG_MDMTEST1); /* ...adding this we send an unmodulated carrier instead */ @@ -850,7 +850,7 @@ get_value(radio_param_t param, radio_value_t *value) switch(param) { case RADIO_PARAM_POWER_MODE: - if ((REG(RFCORE_XREG_RXENABLE) & RFCORE_XREG_RXENABLE_RXENMASK) == 0) { + if((REG(RFCORE_XREG_RXENABLE) & RFCORE_XREG_RXENABLE_RXENMASK) == 0) { *value = RADIO_POWER_MODE_OFF; } else { *value = (REG(RFCORE_XREG_FRMCTRL0) & RFCORE_XREG_FRMCTRL0_TX_MODE) == 0 @@ -943,7 +943,7 @@ set_value(radio_param_t param, radio_value_t value) if(value == RADIO_POWER_MODE_OFF) { off(); return RADIO_RESULT_OK; - } + } if(value == RADIO_POWER_MODE_CARRIER_ON || value == RADIO_POWER_MODE_CARRIER_OFF) { set_test_mode((value == RADIO_POWER_MODE_CARRIER_ON), 0); diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 18b289c1d..545f917ac 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -1132,9 +1132,9 @@ set_send_on_cca(uint8_t enable) send_on_cca = enable; } /*---------------------------------------------------------------------------*/ -/* Enable or disable radio test mode emmiting modulated or unmodulated +/* Enable or disable radio test mode emmiting modulated or unmodulated * (carrier) signal. See datasheet page 55. -*/ + */ static uint16_t prev_MDMCTRL1, prev_DACTST; static uint8_t was_on; @@ -1151,12 +1151,12 @@ set_test_mode(uint8_t enable, uint8_t modulated) was_on = (mode == RADIO_POWER_MODE_ON); off(); prev_MDMCTRL1 = getreg(CC2420_MDMCTRL1); - setreg(CC2420_MDMCTRL1, 0x050C); + setreg(CC2420_MDMCTRL1, 0x050C); if(!modulated) { prev_DACTST = getreg(CC2420_DACTST); setreg(CC2420_DACTST, 0x1800); } - /* actually starts the test mode */ + /* actually starts the test mode */ strobe(CC2420_STXON); } else { if(mode != RADIO_POWER_MODE_CARRIER_ON) { From 42dfc81af265a29547ae7a2fbfc5025486ee527d Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 30 Oct 2018 13:38:16 +0100 Subject: [PATCH 123/184] added LLSEC attributes form packetbuf to uipbuf when receiving IP packet, and a few other minor fixes --- examples/rpl-udp/udp-client.c | 3 ++- os/net/ipv6/sicslowpan.c | 13 +++++++++++++ os/net/mac/csma/csma-output.c | 4 +--- os/net/mac/csma/csma-security.c | 12 +++++++----- os/net/mac/csma/csma-security.h | 2 -- os/net/mac/csma/csma.h | 2 +- os/services/shell/shell-commands.c | 15 +++++++-------- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index 8628e834c..4c27cf1db 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -59,7 +59,8 @@ PROCESS_THREAD(udp_client_process, ev, data) LOG_INFO("Sending request %u to ", count); LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_("\n"); - snprintf(str, sizeof(str), "hello %d", count); + /* avoid the risk of not fitting the '\0' in the string */ + snprintf(str, sizeof(str) - 1, "hello %d", count); simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr); count++; } else { diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 6f15af4f4..e61cb3731 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -2012,6 +2012,19 @@ input(void) callback->input_callback(); } +#if LLSEC802154_USES_AUX_HEADER + /* + * Assuming that the last packet in packetbuf is containing + * the LLSEC state so that it can be copied to uipbuf. + */ + uipbuf_set_attr(UIPBUF_ATTR_LLSEC_LEVEL, + packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)); +#if LLSEC802154_USES_EXPLICIT_KEYS + uipbuf_set_attr(UIPBUF_ATTR_LLSEC_KEY_ID, + packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX)); +#endif /* LLSEC802154_USES_EXPLICIT_KEYS */ +#endif /* LLSEC802154_USES_AUX_HEADER */ + tcpip_input(); #if SICSLOWPAN_CONF_FRAG } diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index b7eab163c..fcc548f89 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -171,11 +171,9 @@ send_one_packet(void *ptr) packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1); #if LLSEC802154_ENABLED - /* These should possibly be taken from upper layers in the future */ - packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, CSMA_LLSEC_SECURITY_LEVEL); #if LLSEC802154_USES_EXPLICIT_KEYS + /* This should possibly be taken from upper layers in the future */ packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, CSMA_LLSEC_KEY_ID_MODE); - packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, CSMA_LLSEC_KEY_INDEX); #endif /* LLSEC802154_USES_EXPLICIT_KEYS */ #endif /* LLSEC802154_ENABLED */ diff --git a/os/net/mac/csma/csma-security.c b/os/net/mac/csma/csma-security.c index 26caed1d5..0b44fa348 100644 --- a/os/net/mac/csma/csma-security.c +++ b/os/net/mac/csma/csma-security.c @@ -88,12 +88,14 @@ typedef struct { static aes_key_t keys[CSMA_LLSEC_MAXKEYS]; /* assumed to be 16 bytes */ -void -csma_security_set_key(uint8_t index, uint8_t *key) +int +csma_security_set_key(uint8_t index, const uint8_t *key) { if(key != NULL && index < CSMA_LLSEC_MAXKEYS) { memcpy(keys[index].u8, key, 16); + return 1; } + return 0; } #define N_KEYS (sizeof(keys) / sizeof(aes_key)) @@ -116,7 +118,7 @@ aead(uint8_t hdrlen, int forward) uint8_t with_encryption; key_index = LLSEC_KEY_INDEX; - if(key_index > CSMA_LLSEC_MAXKEYS) { + if(key_index >= CSMA_LLSEC_MAXKEYS) { LOG_ERR("Key not available: %u\n", key_index); return 0; } @@ -197,8 +199,8 @@ csma_security_create_frame(void) LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); LOG_INFO_(" "); LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); - LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), - LLSEC_KEY_INDEX); + LOG_INFO_(" %u (%u) LV:%d, KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(), + packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL), LLSEC_KEY_INDEX); #if LOG_LEVEL == LOG_LEVEL_DBG LOG_DBG(" Payload after: (%d)", packetbuf_totlen()); diff --git a/os/net/mac/csma/csma-security.h b/os/net/mac/csma/csma-security.h index 4e9f9b391..97092b84d 100644 --- a/os/net/mac/csma/csma-security.h +++ b/os/net/mac/csma/csma-security.h @@ -71,6 +71,4 @@ #define CSMA_LLSEC_MAXKEYS 1 #endif -void csma_security_set_key(uint8_t index, uint8_t *key); - #endif /* CSMA_SECURITY_H_ */ diff --git a/os/net/mac/csma/csma.h b/os/net/mac/csma/csma.h index 96f48e326..dd5688666 100644 --- a/os/net/mac/csma/csma.h +++ b/os/net/mac/csma/csma.h @@ -83,7 +83,7 @@ int csma_security_create_frame(void); int csma_security_parse_frame(void); /* key management for CSMA */ -void csma_security_set_key(uint8_t index, uint8_t *key); +int csma_security_set_key(uint8_t index, const uint8_t *key); #endif /* CSMA_H_ */ diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 32ff763f0..0ec04c7c4 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -55,6 +55,9 @@ #if MAC_CONF_WITH_TSCH #include "net/mac/tsch/tsch.h" #endif /* MAC_CONF_WITH_TSCH */ +#if MAC_CONF_WITH_CSMA +#include "net/mac/csma/csma.h" +#endif #include "net/routing/routing.h" #include "net/mac/llsec802154.h" @@ -424,7 +427,7 @@ PT_THREAD(cmd_rpl_global_repair(struct pt *pt, shell_output_func output, char *a { PT_BEGIN(pt); - SHELL_OUTPUT(output, "Triggering routing global repair\n") + SHELL_OUTPUT(output, "Triggering routing global repair\n"); NETSTACK_ROUTING.global_repair("Shell"); PT_END(pt); @@ -447,7 +450,7 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char * { PT_BEGIN(pt); - SHELL_OUTPUT(output, "Triggering routes refresh\n") + SHELL_OUTPUT(output, "Triggering routes refresh\n"); rpl_refresh_routes("Shell"); PT_END(pt); @@ -733,12 +736,9 @@ PT_THREAD(cmd_6top(struct pt *pt, shell_output_func output, char *args)) static PT_THREAD(cmd_llsec_setlv(struct pt *pt, shell_output_func output, char *args)) { - char *next_args; PT_BEGIN(pt); - SHELL_ARGS_INIT(args, next_args); - if(args == NULL) { SHELL_OUTPUT(output, "Default LLSEC level is %d\n", uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL)); @@ -754,7 +754,6 @@ PT_THREAD(cmd_llsec_setlv(struct pt *pt, shell_output_func output, char *args)) SHELL_OUTPUT(output, "LLSEC default level set %d\n", lv); } } - SHELL_ARGS_NEXT(args, next_args); PT_END(pt); } @@ -775,7 +774,7 @@ PT_THREAD(cmd_llsec_setkey(struct pt *pt, shell_output_func output, char *args)) int key; SHELL_ARGS_NEXT(args, next_args); key = atoi(args); - if(key < 0 || key > 16) { + if(key < 0) { SHELL_OUTPUT(output, "Illegal LLSEC Key index %d\n", key); PT_EXIT(pt); } else { @@ -783,7 +782,7 @@ PT_THREAD(cmd_llsec_setkey(struct pt *pt, shell_output_func output, char *args)) /* Get next arg (key-string) */ SHELL_ARGS_NEXT(args, next_args); if(args != NULL && strlen(args) == 16) { - csma_security_set_key(key, (uint8_t *) args); + csma_security_set_key(key, (const uint8_t *) args); SHELL_OUTPUT(output, "Set key for index %d\n", key); } else { SHELL_OUTPUT(output, "Wrong length of key: '%s' (%d)\n", args, strlen(args)); From 35123e9dd8b5f0920469015d03bfb7793bf2ccc3 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Tue, 30 Oct 2018 16:22:18 +0100 Subject: [PATCH 124/184] fixed better packet size assumptions --- os/net/mac/csma/csma.h | 2 +- os/net/mac/tsch/tsch-const.h | 4 ++-- os/net/mac/tsch/tsch.c | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/os/net/mac/csma/csma.h b/os/net/mac/csma/csma.h index dd5688666..88396db0b 100644 --- a/os/net/mac/csma/csma.h +++ b/os/net/mac/csma/csma.h @@ -69,7 +69,7 @@ #ifdef CSMA_MAC_CONF_LEN #define CSMA_MAC_LEN CSMA_MAC_CONF_LEN #else -#define CSMA_MAC_LEN 127 +#define CSMA_MAC_LEN 127 - 2 #endif /* just a default - with LLSEC, etc */ diff --git a/os/net/mac/tsch/tsch-const.h b/os/net/mac/tsch/tsch-const.h index edc989378..f78b9883d 100644 --- a/os/net/mac/tsch/tsch-const.h +++ b/os/net/mac/tsch/tsch-const.h @@ -66,8 +66,8 @@ /* 1 channel, sequence length 1 */ #define TSCH_HOPPING_SEQUENCE_1_1 (uint8_t[]){ 20 } -/* Max TSCH packet lenght */ -#define TSCH_PACKET_MAX_LEN MIN(127, PACKETBUF_SIZE) +/* Max TSCH packet lenght - last bytes are CRC in default 802.15.4 packets */ +#define TSCH_PACKET_MAX_LEN MIN(127 - 2, PACKETBUF_SIZE) /* The jitter to remove in ticks. * This should be the sum of measurement errors on Tx and Rx nodes. diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index 719a09b9f..8c79c299c 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -62,9 +62,6 @@ #include "net/mac/tsch/sixtop/sixtop.h" #endif -/* Needed to estimate the MAC lenght */ -#define TSCH_MAC_MAX_LEN 127 - #if FRAME802154_VERSION < FRAME802154_IEEE802154_2015 #error TSCH: FRAME802154_VERSION must be at least FRAME802154_IEEE802154_2015 #endif @@ -1135,7 +1132,7 @@ static int max_payload(void) { /* Setup security... before. */ - return TSCH_MAC_MAX_LEN - NETSTACK_FRAMER.length(); + return TSCH_PACKET_MAX_LEN - NETSTACK_FRAMER.length(); } /*---------------------------------------------------------------------------*/ const struct mac_driver tschmac_driver = { From 693e6fdb30a05950a69fee1b1e69558a316b91e7 Mon Sep 17 00:00:00 2001 From: Jeppe Odgaard Date: Tue, 30 Oct 2018 17:05:49 +0100 Subject: [PATCH 125/184] Increased rpl_done, because time to build rpl seems to be faster in Cooja with graphical interface. --- tests/15-rpl-classic/02-rpl-root-reboot-2.csc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/15-rpl-classic/02-rpl-root-reboot-2.csc b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc index 44f0a3b8a..cdfdf7a8d 100644 --- a/tests/15-rpl-classic/02-rpl-root-reboot-2.csc +++ b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc @@ -232,7 +232,7 @@ + true + + 617 + 2 + 785 + 1007 + 160 + + + diff --git a/tests/15-rpl-classic/02-rpl-root-reboot-2.csc b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc index cdfdf7a8d..6de8e9583 100644 --- a/tests/15-rpl-classic/02-rpl-root-reboot-2.csc +++ b/tests/15-rpl-classic/02-rpl-root-reboot-2.csc @@ -7,6 +7,7 @@ [APPS_DIR]/powertracker My simulation + 10.0 123456 1000000 @@ -21,35 +22,10 @@ org.contikios.cooja.contikimote.ContikiMoteType - mtype657 - sink - [CONTIKI_DIR]/examples/multicast/sink.c - make sink.cooja TARGET=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.contikimote.ContikiMoteType - mtype120 - root - [CONTIKI_DIR]/examples/multicast/root.c - make root.cooja TARGET=cooja DISABLE_AUTO_ROOT=1 + mtype512 + mote + [CONTIKI_DIR]/examples/libs/shell/example.c + make example.cooja TARGET=cooja MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC -j org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.Battery org.contikios.cooja.contikimote.interfaces.ContikiVib @@ -88,7 +64,7 @@ org.contikios.cooja.contikimote.interfaces.ContikiEEPROM AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== - mtype657 + mtype512 @@ -109,7 +85,7 @@ org.contikios.cooja.contikimote.interfaces.ContikiEEPROM AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== - mtype657 + mtype512 @@ -134,7 +110,7 @@ org.contikios.cooja.contikimote.interfaces.ContikiEEPROM AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== - mtype657 + mtype512 @@ -155,13 +131,13 @@ org.contikios.cooja.contikimote.interfaces.ContikiEEPROM AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== - mtype120 + mtype512 org.contikios.cooja.plugins.SimControl 280 - 1 + 0 160 400 0 @@ -178,7 +154,7 @@ 0.9090909090909091 0.0 0.0 0.9090909090909091 125.81818181818181 173.0 400 - 2 + 4 400 1 1 @@ -190,38 +166,20 @@ - 1320 + 604 3 - 240 + 784 400 160 - - org.contikios.cooja.plugins.TimeLine - - 0 - 1 - 2 - 3 - - - - 500.0 - - 1720 - 5 - 166 - 0 - 948 - org.contikios.cooja.plugins.Notes Enter notes here true - 1040 - 4 + 944 + 1 160 680 0 @@ -314,7 +272,7 @@ while(true) { } else if(msg.startsWith("add root")) { //TODO: Use id from generated msg //TODO: Use saved type and position - m = sim.getMoteTypes()[1].generateMote(sim); + m = sim.getMoteTypes()[0].generateMote(sim); m.getInterfaces().getMoteID().setMoteID(root_id); sim.addMote(m); log.log("root added\n"); @@ -324,13 +282,13 @@ while(true) { } log.testOK(); /* Report test success and quit */ - false + true - 1011 - 0 - 700 - 259 - 140 + 617 + 2 + 785 + 1007 + 160 From be52ee76a00e867ea9039a65c08dca4555490725 Mon Sep 17 00:00:00 2001 From: "Jeppe N. Odgaard" Date: Thu, 15 Nov 2018 16:40:30 +0100 Subject: [PATCH 144/184] Reverted changes to examples/multicast --- examples/multicast/Makefile | 5 ----- examples/multicast/root.c | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/multicast/Makefile b/examples/multicast/Makefile index be7fb6422..86c16e481 100644 --- a/examples/multicast/Makefile +++ b/examples/multicast/Makefile @@ -12,11 +12,6 @@ include $(CONTIKI)/Makefile.identify-target MODULES_REL += $(TARGET) MODULES += os/net/ipv6/multicast -MODULES += os/services/shell - -ifeq ($(DISABLE_AUTO_ROOT),1) - CFLAGS += -DDISABLE_AUTO_ROOT -endif MAKE_ROUTING = MAKE_ROUTING_RPL_CLASSIC include $(CONTIKI)/Makefile.include diff --git a/examples/multicast/root.c b/examples/multicast/root.c index a95a25bcf..59d5d2aa8 100644 --- a/examples/multicast/root.c +++ b/examples/multicast/root.c @@ -111,9 +111,9 @@ PROCESS_THREAD(rpl_root_process, ev, data) PROCESS_BEGIN(); PRINTF("Multicast Engine: '%s'\n", UIP_MCAST6.name); -#ifndef DISABLE_AUTO_ROOT + NETSTACK_ROUTING.root_start(); -#endif + prepare_mcast(); etimer_set(&et, START_DELAY * CLOCK_SECOND); From be71b5fc1d43863a5feb85162fb2f6ad39f2a659 Mon Sep 17 00:00:00 2001 From: "carlosgp143@gmail.com" Date: Mon, 30 Apr 2018 13:04:23 +0200 Subject: [PATCH 145/184] Added support for multiple server session in LwM2M --- .../lwm2m-ipso-objects/example-ipso-objects.c | 37 +- os/services/lwm2m/lwm2m-rd-client.c | 809 ++++++++++-------- os/services/lwm2m/lwm2m-rd-client.h | 88 +- os/services/lwm2m/lwm2m-server.c | 2 +- 4 files changed, 537 insertions(+), 399 deletions(-) diff --git a/examples/lwm2m-ipso-objects/example-ipso-objects.c b/examples/lwm2m-ipso-objects/example-ipso-objects.c index 51bd84040..98e065f2f 100644 --- a/examples/lwm2m-ipso-objects/example-ipso-objects.c +++ b/examples/lwm2m-ipso-objects/example-ipso-objects.c @@ -34,6 +34,7 @@ * \author * Joakim Eriksson, joakime@sics.se * Niclas Finne, nfi@sics.se + * Carlos Gonzalo Peces, carlosgp143@gmail.com */ #include "contiki.h" @@ -63,6 +64,20 @@ #define LWM2M_SERVER_ADDRESS "coap://[fd00::1]" #endif +#ifndef LWM2M_SERVER_ADDRESS_SECOND +#define LWM2M_SERVER_ADDRESS_SECOND "coap://[fd00::1]:5686" +#endif + +#ifndef LWM2M_SESSIONS +#define LWM2M_SESSIONS 2 +#endif + + static lwm2m_session_info_t session_info; + +#if LWM2M_SESSIONS == 2 +static lwm2m_session_info_t session_info_second; +#endif + #if BOARD_SENSORTAG #include "board-peripherals.h" @@ -148,13 +163,27 @@ setup_lwm2m_servers(void) coap_endpoint_t server_ep; if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS, strlen(LWM2M_SERVER_ADDRESS), &server_ep) != 0) { - lwm2m_rd_client_register_with_bootstrap_server(&server_ep); - lwm2m_rd_client_register_with_server(&server_ep); +#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER + lwm2m_rd_client_register_with_bootstrap_server(&session_info, &server_ep); +#else + lwm2m_rd_client_register_with_server(&session_info, &server_ep); +#endif } #endif /* LWM2M_SERVER_ADDRESS */ - lwm2m_rd_client_use_bootstrap_server(REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER); - lwm2m_rd_client_use_registration_server(REGISTER_WITH_LWM2M_SERVER); +#if LWM2M_SESSIONS == 2 +#ifdef LWM2M_SERVER_ADDRESS_SECOND + coap_endpoint_t server_ep_second; + if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS_SECOND, strlen(LWM2M_SERVER_ADDRESS_SECOND), + &server_ep_second) != 0) { +#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER + lwm2m_rd_client_register_with_bootstrap_server(&session_info_second, &server_ep_second); +#else + lwm2m_rd_client_register_with_server(&session_info_second, &server_ep_second); +#endif + } +#endif /* LWM2M_SERVER_ADDRESS_SECOND */ +#endif /* LWM2M_SESSIONS == 2 */ } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_ipso_objects, ev, data) diff --git a/os/services/lwm2m/lwm2m-rd-client.c b/os/services/lwm2m/lwm2m-rd-client.c index 4b4b11528..995ab6c69 100644 --- a/os/services/lwm2m/lwm2m-rd-client.c +++ b/os/services/lwm2m/lwm2m-rd-client.c @@ -54,6 +54,7 @@ #include "coap-endpoint.h" #include "coap-callback-api.h" #include "lwm2m-security.h" +#include "lib/list.h" #include #include #include @@ -76,18 +77,11 @@ #define LWM2M_DEFAULT_CLIENT_LIFETIME 30 /* sec */ #endif -#define MAX_RD_UPDATE_WAIT 5000 - #define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT) #define BS_REMOTE_PORT UIP_HTONS(5685) #define STATE_MACHINE_UPDATE_INTERVAL 500 -static struct lwm2m_session_info session_info; -static coap_callback_request_state_t rd_request_state; - -static coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */ - /* The states for the RD client state machine */ /* When node is unregistered it ends up in UNREGISTERED and this is going to be there until use X or Y kicks it @@ -114,38 +108,36 @@ static coap_message_t request[1]; /* This way the message can be treated as #define FLAG_RD_DATA_UPDATE_TRIGGERED 0x02 #define FLAG_RD_DATA_UPDATE_ON_DIRTY 0x10 -static uint8_t rd_state = 0; -static uint8_t rd_flags = FLAG_RD_DATA_UPDATE_ON_DIRTY; -static uint64_t wait_until_network_check = 0; -static uint64_t last_update; +/* The type of server to use: bootstrap or registration */ +#define USE_BOOTSTRAP_SERVER 0 +#define USE_REGISTRATION_SERVER 1 +LIST(session_info_list); + +/* Shared by all sessions, used by only one at a time in the FSM */ static char query_data[64]; /* allocate some data for queries and updates */ static uint8_t rd_data[128]; /* allocate some data for the RD */ -static uint32_t rd_block1; -static uint8_t rd_more; -static coap_timer_t rd_timer; -static void (*rd_callback)(coap_callback_request_state_t *callback_state); - -static coap_timer_t block1_timer; +static coap_timer_t rd_timer; /* Timer to tick the FSM periodically */ +static char default_ep [20]; #if LWM2M_QUEUE_MODE_ENABLED -static coap_timer_t queue_mode_client_awake_timer; /* Timer to control the client's - * awake time - */ -static uint8_t queue_mode_client_awake; /* 1 - client is awake, - * 0 - client is sleeping - */ +static coap_timer_t queue_mode_client_awake_timer; /* Timer to control the client's + * awake time + */ +static uint8_t queue_mode_client_awake; /* 1 - client is awake, + * 0 - client is sleeping + */ static uint16_t queue_mode_client_awake_time; /* The time to be awake */ /* Callback for the client awake timer */ -static void queue_mode_awake_timer_callback(coap_timer_t *timer); +static void queue_mode_awake_timer_callback(coap_timer_t *timer); #endif static void check_periodic_observations(); static void update_callback(coap_callback_request_state_t *callback_state); static int -set_rd_data(coap_message_t *request) +set_rd_data(lwm2m_session_info_t *session_info) { lwm2m_buffer_t outbuf; @@ -155,31 +147,31 @@ set_rd_data(coap_message_t *request) outbuf.len = 0; /* this will also set the request payload */ - rd_more = lwm2m_engine_set_rd_data(&outbuf, 0); - coap_set_payload(request, rd_data, outbuf.len); + session_info->rd_more = lwm2m_engine_set_rd_data(&outbuf, 0); + coap_set_payload(session_info->request, rd_data, outbuf.len); - if(rd_more) { + if(session_info->rd_more) { /* set the first block here */ LOG_DBG("Setting block1 in request\n"); - coap_set_header_block1(request, 0, 1, sizeof(rd_data)); + coap_set_header_block1(session_info->request, 0, 1, sizeof(rd_data)); } return outbuf.len; } /*---------------------------------------------------------------------------*/ static void -prepare_update(coap_message_t *request, int triggered) +prepare_update(lwm2m_session_info_t *session_info, int triggered) { - coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0); - coap_set_header_uri_path(request, session_info.assigned_ep); + coap_init_message(session_info->request, COAP_TYPE_CON, COAP_POST, 0); + coap_set_header_uri_path(session_info->request, session_info->assigned_ep); - snprintf(query_data, sizeof(query_data) - 1, "?lt=%d&b=%s", session_info.lifetime, session_info.binding); - LOG_DBG("UPDATE:%s %s\n", session_info.assigned_ep, query_data); - coap_set_header_uri_query(request, query_data); + snprintf(query_data, sizeof(query_data) - 1, "?lt=%d&b=%s", session_info->lifetime, session_info->binding); + LOG_DBG("UPDATE:%s %s\n", session_info->assigned_ep, query_data); + coap_set_header_uri_query(session_info->request, query_data); - if((triggered || rd_flags & FLAG_RD_DATA_UPDATE_ON_DIRTY) && (rd_flags & FLAG_RD_DATA_DIRTY)) { - rd_flags &= ~FLAG_RD_DATA_DIRTY; - set_rd_data(request); - rd_callback = update_callback; + if((triggered || session_info->rd_flags & FLAG_RD_DATA_UPDATE_ON_DIRTY) && (session_info->rd_flags & FLAG_RD_DATA_DIRTY)) { + session_info->rd_flags &= ~FLAG_RD_DATA_DIRTY; + set_rd_data(session_info); + session_info->rd_callback = update_callback; } } /*---------------------------------------------------------------------------*/ @@ -198,90 +190,119 @@ has_network_access(void) } /*---------------------------------------------------------------------------*/ int -lwm2m_rd_client_is_registered(void) +lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info) { - return rd_state == REGISTRATION_DONE || rd_state == UPDATE_SENT; -} -/*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_use_bootstrap_server(int use) -{ - session_info.use_bootstrap = use != 0; - if(session_info.use_bootstrap) { - rd_state = INIT; - } + return session_info->rd_state == REGISTRATION_DONE || session_info->rd_state == UPDATE_SENT; } /*---------------------------------------------------------------------------*/ /* will take another argument when we support multiple sessions */ void -lwm2m_rd_client_set_session_callback(session_callback_t cb) +lwm2m_rd_client_set_session_callback(lwm2m_session_info_t *session_info, session_callback_t cb) { - session_info.callback = cb; + session_info->callback = cb; } /*---------------------------------------------------------------------------*/ static void -perform_session_callback(int state) +perform_session_callback(lwm2m_session_info_t *session_info, int state) { - if(session_info.callback != NULL) { + if(session_info->callback != NULL) { LOG_DBG("Performing session callback: %d cb:%p\n", - state, session_info.callback); - session_info.callback(&session_info, state); - } -} -/*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_use_registration_server(int use) -{ - session_info.use_registration = use != 0; - if(session_info.use_registration) { - rd_state = INIT; + state, session_info->callback); + session_info->callback(session_info, state); } } /*---------------------------------------------------------------------------*/ uint16_t -lwm2m_rd_client_get_lifetime(void) +lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info) { - return session_info.lifetime; + return session_info->lifetime; } /*---------------------------------------------------------------------------*/ void -lwm2m_rd_client_set_lifetime(uint16_t lifetime) +lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime) { if(lifetime > 0) { - session_info.lifetime = lifetime; + session_info->lifetime = lifetime; } else { - session_info.lifetime = LWM2M_DEFAULT_CLIENT_LIFETIME; + session_info->lifetime = LWM2M_DEFAULT_CLIENT_LIFETIME; + } +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint) +{ + if(endpoint != NULL) { + session_info->ep = endpoint; + } +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_set_default_endpoint_name(const char *endpoint) +{ + if(default_ep != NULL) { + strcpy(default_ep, endpoint); } } /*---------------------------------------------------------------------------*/ void lwm2m_rd_client_set_update_rd(void) { - rd_flags |= FLAG_RD_DATA_DIRTY; -} -/*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_set_automatic_update(int update) -{ - rd_flags = (rd_flags & ~FLAG_RD_DATA_UPDATE_ON_DIRTY) | - (update != 0 ? FLAG_RD_DATA_UPDATE_ON_DIRTY : 0); -} -/*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_register_with_server(const coap_endpoint_t *server) -{ - coap_endpoint_copy(&session_info.server_ep, server); - session_info.has_registration_server_info = 1; - session_info.registered = 0; - if(session_info.use_registration) { - rd_state = INIT; + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { + session_info->rd_flags |= FLAG_RD_DATA_DIRTY; + session_info = session_info->next; } } /*---------------------------------------------------------------------------*/ -static int -update_registration_server(void) +void +lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int update) { - if(session_info.has_registration_server_info) { + session_info->rd_flags = (session_info->rd_flags & ~FLAG_RD_DATA_UPDATE_ON_DIRTY) | + (update != 0 ? FLAG_RD_DATA_UPDATE_ON_DIRTY : 0); +} +/*---------------------------------------------------------------------------*/ +static void +setup_session_default_values(lwm2m_session_info_t *session_info) +{ + if(session_info->ep == NULL) { + session_info->ep = default_ep; + } + /* default binding U = UDP, UQ = UDP Q-mode*/ +#if LWM2M_QUEUE_MODE_CONF_ENABLED + session_info->binding = "UQ"; + /* Enough margin to ensure that the client is not unregistered (we + * do not know the time it can stay awake) + */ + session_info->lifetime = (LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME / 1000) * 2; +#else + session_info->binding = "U"; + if(session_info->lifetime == 0) { + session_info->lifetime = LWM2M_DEFAULT_CLIENT_LIFETIME; + } +#endif /* LWM2M_QUEUE_MODE_CONF_ENABLED */ + + session_info->rd_flags = FLAG_RD_DATA_UPDATE_ON_DIRTY; + session_info->wait_until_network_check = 0; + session_info->last_update = 0; + session_info->last_rd_progress = 0; + session_info->rd_state = INIT; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server) +{ + list_add(session_info_list, session_info); /* Add to the list of sessions */ + setup_session_default_values(session_info); + coap_endpoint_copy(&session_info->server_ep, server); + session_info->has_registration_server_info = 1; + session_info->use_server_type = USE_REGISTRATION_SERVER; + session_info->rd_state = INIT; +} +/*---------------------------------------------------------------------------*/ +static int +update_registration_server(lwm2m_session_info_t *session_info) +{ + if(session_info->has_registration_server_info) { return 1; } @@ -304,39 +325,54 @@ update_registration_server(void) } /*---------------------------------------------------------------------------*/ void -lwm2m_rd_client_register_with_bootstrap_server(const coap_endpoint_t *server) +lwm2m_rd_client_register_with_bootstrap_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server) { - coap_endpoint_copy(&session_info.bs_server_ep, server); - session_info.has_bs_server_info = 1; - session_info.bootstrapped = 0; - session_info.registered = 0; - if(session_info.use_bootstrap) { - rd_state = INIT; - } + list_add(session_info_list, session_info); /* Add to the list of sessions */ + setup_session_default_values(session_info); + coap_endpoint_copy(&session_info->bs_server_ep, server); + session_info->has_bs_server_info = 1; + session_info->use_server_type = USE_BOOTSTRAP_SERVER; + session_info->bootstrapped = 0; + session_info->rd_state = INIT; } /*---------------------------------------------------------------------------*/ int -lwm2m_rd_client_deregister(void) +lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info) { - if(lwm2m_rd_client_is_registered()) { - rd_state = DEREGISTER; + if(lwm2m_rd_client_is_registered(session_info)) { + session_info->rd_state = DEREGISTER; return 1; } /* Not registered */ return 0; } /*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_update_triggered(void) +static lwm2m_session_info_t * +get_sessio_info_from_server_ep(const coap_endpoint_t *server_ep) { - rd_flags |= FLAG_RD_DATA_UPDATE_TRIGGERED; + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { + if(coap_endpoint_cmp(&session_info->server_ep, server_ep)) { + return session_info; + } + session_info = session_info->next; + } + return NULL; +} +void +lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep) +{ + lwm2m_session_info_t *session_info = get_sessio_info_from_server_ep(server_ep); + if(session_info) { + session_info->rd_flags |= FLAG_RD_DATA_UPDATE_TRIGGERED; + } /* Here we need to do an CoAP timer poll - to get a quick request transmission! */ } /*---------------------------------------------------------------------------*/ static int -update_bootstrap_server(void) +update_bootstrap_server(lwm2m_session_info_t *session_info) { - if(session_info.has_bs_server_info) { + if(session_info->has_bs_server_info) { return 1; } @@ -373,29 +409,32 @@ bootstrap_callback(coap_callback_request_state_t *callback_state) { coap_request_state_t *state = &callback_state->state; LOG_DBG("Bootstrap callback Response: %d, ", state->response != NULL); + + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)state->user_data; + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { if(CHANGED_2_04 == state->response->code) { LOG_DBG_("Considered done!\n"); - rd_state = BOOTSTRAP_DONE; + session_info->rd_state = BOOTSTRAP_DONE; return; } /* Possible error response codes are 4.00 Bad request & 4.15 Unsupported content format */ LOG_DBG_("Failed with code %d. Retrying\n", state->response->code); /* TODO Application callback? */ - rd_state = INIT; - } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { + session_info->rd_state = INIT; + } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { LOG_DBG_("Server not responding! Retry?"); - rd_state = DO_BOOTSTRAP; + session_info->rd_state = DO_BOOTSTRAP; } else if(state->status == COAP_REQUEST_STATUS_FINISHED) { LOG_DBG_("Request finished. Ignore\n"); } else { LOG_DBG_("Unexpected error! Retry?"); - rd_state = DO_BOOTSTRAP; + session_info->rd_state = DO_BOOTSTRAP; } } /*---------------------------------------------------------------------------*/ static void -produce_more_rd(void) +produce_more_rd(lwm2m_session_info_t *session_info) { lwm2m_buffer_t outbuf; @@ -406,23 +445,23 @@ produce_more_rd(void) outbuf.size = sizeof(rd_data); outbuf.len = 0; - rd_block1++; + session_info->rd_block1++; /* this will also set the request payload */ - rd_more = lwm2m_engine_set_rd_data(&outbuf, rd_block1); - coap_set_payload(request, rd_data, outbuf.len); + session_info->rd_more = lwm2m_engine_set_rd_data(&outbuf, session_info->rd_block1); + coap_set_payload(session_info->request, rd_data, outbuf.len); LOG_DBG("Setting block1 in request - block: %d more: %d\n", - (int)rd_block1, (int)rd_more); - coap_set_header_block1(request, rd_block1, rd_more, sizeof(rd_data)); + (int)session_info->rd_block1, (int)session_info->rd_more); + coap_set_header_block1(session_info->request, session_info->rd_block1, session_info->rd_more, sizeof(rd_data)); - coap_send_request(&rd_request_state, &session_info.server_ep, request, rd_callback); + coap_send_request(&session_info->rd_request_state, &session_info->server_ep, session_info->request, session_info->rd_callback); } /*---------------------------------------------------------------------------*/ static void block1_rd_callback(coap_timer_t *timer) { - produce_more_rd(); + produce_more_rd((lwm2m_session_info_t *)timer->user_data); } /*---------------------------------------------------------------------------*/ /* @@ -433,20 +472,24 @@ registration_callback(coap_callback_request_state_t *callback_state) { coap_request_state_t *state = &callback_state->state; LOG_DBG("Registration callback. Status: %d. Response: %d, ", state->status, state->response != NULL); + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)state->user_data; + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { /* check state and possibly set registration to done */ /* If we get a continue - we need to call the rd generator one more time */ + if(CONTINUE_2_31 == state->response->code) { /* We assume that size never change?! */ - coap_get_header_block1(state->response, &rd_block1, NULL, NULL, NULL); - coap_timer_set_callback(&block1_timer, block1_rd_callback); - coap_timer_set(&block1_timer, 1); /* delay 1 ms */ + coap_get_header_block1(state->response, &session_info->rd_block1, NULL, NULL, NULL); + coap_timer_set_user_data(&session_info->block1_timer, (void *)session_info); + coap_timer_set_callback(&session_info->block1_timer, block1_rd_callback); + coap_timer_set(&session_info->block1_timer, 1); /* delay 1 ms */ LOG_DBG_("Continue\n"); } else if(CREATED_2_01 == state->response->code) { if(state->response->location_path_len < LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN) { - memcpy(session_info.assigned_ep, state->response->location_path, + memcpy(session_info->assigned_ep, state->response->location_path, state->response->location_path_len); - session_info.assigned_ep[state->response->location_path_len] = 0; + session_info->assigned_ep[state->response->location_path_len] = 0; /* if we decide to not pass the lt-argument on registration, we should force an initial "update" to register lifetime with server */ #if LWM2M_QUEUE_MODE_ENABLED #if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION @@ -454,14 +497,14 @@ registration_callback(coap_callback_request_state_t *callback_state) lwm2m_queue_mode_set_first_request(); } #endif - lwm2m_rd_client_fsm_execute_queue_mode_awake(); /* Avoid 500 ms delay and move directly to the state*/ + lwm2m_rd_client_fsm_execute_queue_mode_awake(session_info); /* Avoid 500 ms delay and move directly to the state*/ #else - rd_state = REGISTRATION_DONE; + session_info->rd_state = REGISTRATION_DONE; #endif /* remember the last reg time */ - last_update = coap_timer_uptime(); - LOG_DBG_("Done (assigned EP='%s')!\n", session_info.assigned_ep); - perform_session_callback(LWM2M_RD_CLIENT_REGISTERED); + session_info->last_update = coap_timer_uptime(); + LOG_DBG_("Done (assigned EP='%s')!\n", session_info->assigned_ep); + perform_session_callback(session_info, LWM2M_RD_CLIENT_REGISTERED); return; } @@ -474,15 +517,15 @@ registration_callback(coap_callback_request_state_t *callback_state) LOG_DBG_("failed with code %d. Re-init network\n", state->response->code); } /* TODO Application callback? */ - rd_state = INIT; + session_info->rd_state = INIT; } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { LOG_DBG_("Server not responding, trying to reconnect\n"); - rd_state = INIT; - } else if(state->status == COAP_REQUEST_STATUS_FINISHED){ + session_info->rd_state = INIT; + } else if(state->status == COAP_REQUEST_STATUS_FINISHED) { LOG_DBG_("Request finished. Ignore\n"); } else { LOG_DBG_("Unexpected error, trying to reconnect\n"); - rd_state = INIT; + session_info->rd_state = INIT; } } /*---------------------------------------------------------------------------*/ @@ -495,18 +538,20 @@ update_callback(coap_callback_request_state_t *callback_state) coap_request_state_t *state = &callback_state->state; LOG_DBG("Update callback. Status: %d. Response: %d, ", state->status, state->response != NULL); + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)state->user_data; + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { /* If we get a continue - we need to call the rd generator one more time */ if(CONTINUE_2_31 == state->response->code) { /* We assume that size never change?! */ LOG_DBG_("Continue\n"); - coap_get_header_block1(state->response, &rd_block1, NULL, NULL, NULL); - coap_timer_set_callback(&block1_timer, block1_rd_callback); - coap_timer_set(&block1_timer, 1); /* delay 1 ms */ + coap_get_header_block1(state->response, &session_info->rd_block1, NULL, NULL, NULL); + coap_timer_set_callback(&session_info->block1_timer, block1_rd_callback); + coap_timer_set(&session_info->block1_timer, 1); /* delay 1 ms */ } else if(CHANGED_2_04 == state->response->code) { LOG_DBG_("Done!\n"); /* remember the last reg time */ - last_update = coap_timer_uptime(); + session_info->last_update = coap_timer_uptime(); #if LWM2M_QUEUE_MODE_ENABLED /* If it has been waked up by a notification, send the stored notifications in queue */ if(lwm2m_queue_mode_is_waked_up_by_notification()) { @@ -519,25 +564,26 @@ update_callback(coap_callback_request_state_t *callback_state) lwm2m_queue_mode_set_first_request(); } #endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ - lwm2m_rd_client_fsm_execute_queue_mode_awake(); /* Avoid 500 ms delay and move directly to the state*/ + lwm2m_rd_client_fsm_execute_queue_mode_awake(session_info); /* Avoid 500 ms delay and move directly to the state*/ #else - rd_state = REGISTRATION_DONE; - rd_flags &= ~FLAG_RD_DATA_UPDATE_TRIGGERED; -#endif /* LWM2M_QUEUE_MODE_ENABLED */ + + session_info->rd_state = REGISTRATION_DONE; + session_info->rd_flags &= ~FLAG_RD_DATA_UPDATE_TRIGGERED; +#endif /* LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME */ } else { /* Possible error response codes are 4.00 Bad request & 4.04 Not Found */ LOG_DBG_("Failed with code %d. Retrying registration\n", state->response->code); - rd_state = DO_REGISTRATION; + session_info->rd_state = DO_REGISTRATION; } } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { LOG_DBG_("Server not responding, trying to reconnect\n"); - rd_state = INIT; - } else if(state->status == COAP_REQUEST_STATUS_FINISHED){ + session_info->rd_state = INIT; + } else if(state->status == COAP_REQUEST_STATUS_FINISHED) { LOG_DBG_("Request finished. Ignore\n"); } else { LOG_DBG_("Unexpected error, trying to reconnect\n"); - rd_state = INIT; + session_info->rd_state = INIT; } } /*---------------------------------------------------------------------------*/ @@ -549,19 +595,49 @@ deregister_callback(coap_callback_request_state_t *callback_state) state->status, state->response != NULL ? state->response->code : 0); + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)state->user_data; + if(state->status == COAP_REQUEST_STATUS_RESPONSE && (DELETED_2_02 == state->response->code)) { LOG_DBG("Deregistration success\n"); - rd_state = DEREGISTERED; - perform_session_callback(LWM2M_RD_CLIENT_DEREGISTERED); + session_info->rd_state = DEREGISTERED; + perform_session_callback(session_info, LWM2M_RD_CLIENT_DEREGISTERED); } else { LOG_DBG("Deregistration failed\n"); - if(rd_state == DEREGISTER_SENT) { - rd_state = DEREGISTER_FAILED; - perform_session_callback(LWM2M_RD_CLIENT_DEREGISTER_FAILED); + if(session_info->rd_state == DEREGISTER_SENT) { + session_info->rd_state = DEREGISTER_FAILED; + perform_session_callback(session_info, LWM2M_RD_CLIENT_DEREGISTER_FAILED); } } } /*---------------------------------------------------------------------------*/ +#if LWM2M_QUEUE_MODE_ENABLED +static int +all_sessions_in_queue_mode_state(void) +{ + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { + if(((session_info->rd_state & 0xF) != 0xE)) { + return 0; + } + session_info = session_info->next; + } + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +all_sessions_in_queue_mode_awake(void) +{ + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { + if(session_info->rd_state != QUEUE_MODE_AWAKE) { + return 0; + } + session_info = session_info->next; + } + return 1; +} +#endif /* LWM2M_QUEUE_MODE_ENABLED */ +/*---------------------------------------------------------------------------*/ /* CoAP timer callback */ static void periodic_process(coap_timer_t *timer) @@ -571,7 +647,7 @@ periodic_process(coap_timer_t *timer) /* reschedule the CoAP timer */ #if LWM2M_QUEUE_MODE_ENABLED /* In Queue Mode, the machine is not executed periodically, but with the awake/sleeping times */ - if(!((rd_state & 0xF) == 0xE)) { + if(!all_sessions_in_queue_mode_state()) { coap_timer_reset(&rd_timer, STATE_MACHINE_UPDATE_INTERVAL); } #else @@ -580,233 +656,242 @@ periodic_process(coap_timer_t *timer) now = coap_timer_uptime(); - LOG_DBG("RD Client - state: %d, ms: %lu\n", rd_state, - (unsigned long)coap_timer_uptime()); + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { - switch(rd_state) { - case INIT: - LOG_DBG("RD Client started with endpoint '%s' and client lifetime %d\n", session_info.ep, session_info.lifetime); - rd_state = WAIT_NETWORK; - break; - case WAIT_NETWORK: - if(now > wait_until_network_check) { - /* check each 10 seconds before next check */ - LOG_DBG("Checking for network... %lu\n", - (unsigned long)wait_until_network_check); - wait_until_network_check = now + 10000; - if(has_network_access()) { - /* Either do bootstrap then registration */ - if(session_info.use_bootstrap) { - rd_state = DO_BOOTSTRAP; - } else { - rd_state = DO_REGISTRATION; - } - } - /* Otherwise wait until for a network to join */ - } - break; - case DO_BOOTSTRAP: - if(session_info.use_bootstrap && session_info.bootstrapped == 0) { - if(update_bootstrap_server()) { - /* prepare request, TID is set by COAP_BLOCKING_REQUEST() */ - coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0); - coap_set_header_uri_path(request, "/bs"); + LOG_DBG("RD Client with assigned ep: %s - state: %d, ms: %lu\n", session_info->assigned_ep, session_info->rd_state, + (unsigned long)coap_timer_uptime()); - snprintf(query_data, sizeof(query_data) - 1, "?ep=%s", session_info.ep); - coap_set_header_uri_query(request, query_data); - LOG_INFO("Registering ID with bootstrap server ["); - LOG_INFO_COAP_EP(&session_info.bs_server_ep); - LOG_INFO_("] as '%s'\n", query_data); - - if(coap_send_request(&rd_request_state, &session_info.bs_server_ep, - request, bootstrap_callback)) { - rd_state = BOOTSTRAP_SENT; - } - } - } - break; - case BOOTSTRAP_SENT: - /* Just wait for bootstrap to be done... */ - break; - case BOOTSTRAP_DONE: - /* check that we should still use bootstrap */ - if(session_info.use_bootstrap) { - lwm2m_security_server_t *security; - LOG_DBG("*** Bootstrap - checking for server info...\n"); - /* get the security object - ignore bootstrap servers */ - for(security = lwm2m_security_get_first(); - security != NULL; - security = lwm2m_security_get_next(security)) { - if(security->bootstrap == 0) { - break; - } - } - - if(security != NULL) { - /* get the server URI */ - if(security->server_uri_len > 0) { - uint8_t secure = 0; - - LOG_DBG("**** Found security instance using: "); - LOG_DBG_COAP_STRING((const char *)security->server_uri, - security->server_uri_len); - LOG_DBG_(" (len %d) \n", security->server_uri_len); - /* TODO Should verify it is a URI */ - /* Check if secure */ - secure = strncmp((const char *)security->server_uri, - "coaps:", 6) == 0; - - if(!coap_endpoint_parse((const char *)security->server_uri, - security->server_uri_len, - &session_info.server_ep)) { - LOG_DBG("Failed to parse server URI!\n"); + switch(session_info->rd_state) { + case INIT: + LOG_DBG("RD Client started with endpoint '%s' and client lifetime %d\n", session_info->ep, session_info->lifetime); + session_info->rd_state = WAIT_NETWORK; + break; + case WAIT_NETWORK: + if(now > session_info->wait_until_network_check) { + /* check each 10 seconds before next check */ + LOG_DBG("Checking for network... %lu\n", + (unsigned long)session_info->wait_until_network_check); + session_info->wait_until_network_check = now + 10000; + if(has_network_access()) { + /* Either do bootstrap then registration */ + if(session_info->use_server_type == USE_BOOTSTRAP_SERVER) { + session_info->rd_state = DO_BOOTSTRAP; } else { - LOG_DBG("Server address:"); - LOG_DBG_COAP_EP(&session_info.server_ep); - LOG_DBG_("\n"); - if(secure) { - LOG_DBG("Secure CoAP requested but not supported - can not bootstrap\n"); - } else { - lwm2m_rd_client_register_with_server(&session_info.server_ep); - session_info.bootstrapped++; - } + session_info->rd_state = DO_REGISTRATION; + } + } + /* Otherwise wait until for a network to join */ + } + break; + case DO_BOOTSTRAP: + if(session_info->use_server_type == USE_BOOTSTRAP_SERVER && session_info->bootstrapped == 0) { + if(update_bootstrap_server(session_info)) { + + /* prepare request, TID is set by COAP_BLOCKING_REQUEST() */ + coap_init_message(session_info->request, COAP_TYPE_CON, COAP_POST, 0); + coap_set_header_uri_path(session_info->request, "/bs"); + + snprintf(query_data, sizeof(query_data) - 1, "?ep=%s", session_info->ep); + coap_set_header_uri_query(session_info->request, query_data); + LOG_INFO("Registering ID with bootstrap server ["); + LOG_INFO_COAP_EP(&session_info->bs_server_ep); + LOG_INFO_("] as '%s'\n", query_data); + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->bs_server_ep, + session_info->request, bootstrap_callback)) { + session_info->rd_state = BOOTSTRAP_SENT; } - } else { - LOG_DBG("** failed to parse URI "); - LOG_DBG_COAP_STRING((const char *)security->server_uri, - security->server_uri_len); - LOG_DBG_("\n"); } } + break; + case BOOTSTRAP_SENT: + /* Just wait for bootstrap to be done... */ + break; + case BOOTSTRAP_DONE: + /* check that we should still use bootstrap */ + if(session_info->use_server_type == USE_BOOTSTRAP_SERVER) { + lwm2m_security_server_t *security; + LOG_DBG("*** Bootstrap - checking for server info...\n"); + /* get the security object - ignore bootstrap servers */ + for(security = lwm2m_security_get_first(); + security != NULL; + security = lwm2m_security_get_next(security)) { + if(security->bootstrap == 0) { + break; + } + } - /* if we did not register above - then fail this and restart... */ - if(session_info.bootstrapped == 0) { - /* Not ready. Lets retry with the bootstrap server again */ - rd_state = DO_BOOTSTRAP; - } else { - rd_state = DO_REGISTRATION; + if(security != NULL) { + /* get the server URI */ + if(security->server_uri_len > 0) { + uint8_t secure = 0; + + LOG_DBG("**** Found security instance using: "); + LOG_DBG_COAP_STRING((const char *)security->server_uri, + security->server_uri_len); + LOG_DBG_(" (len %d) \n", security->server_uri_len); + /* TODO Should verify it is a URI */ + /* Check if secure */ + secure = strncmp((const char *)security->server_uri, + "coaps:", 6) == 0; + + if(!coap_endpoint_parse((const char *)security->server_uri, + security->server_uri_len, + &session_info->server_ep)) { + LOG_DBG("Failed to parse server URI!\n"); + } else { + LOG_DBG("Server address:"); + LOG_DBG_COAP_EP(&session_info->server_ep); + LOG_DBG_("\n"); + if(secure) { + LOG_DBG("Secure CoAP requested but not supported - can not bootstrap\n"); + } else { + lwm2m_rd_client_register_with_server(session_info, &session_info->server_ep); + session_info->bootstrapped++; + } + } + } else { + LOG_DBG("** failed to parse URI "); + LOG_DBG_COAP_STRING((const char *)security->server_uri, + security->server_uri_len); + LOG_DBG_("\n"); + } + } + + /* if we did not register above - then fail this and restart... */ + if(session_info->bootstrapped == 0) { + /* Not ready. Lets retry with the bootstrap server again */ + session_info->rd_state = DO_BOOTSTRAP; + } else { + session_info->rd_state = DO_REGISTRATION; + } } - } - break; - case DO_REGISTRATION: - if(!coap_endpoint_is_connected(&session_info.server_ep)) { - /* Not connected... wait a bit... and retry connection */ - coap_endpoint_connect(&session_info.server_ep); - LOG_DBG("Wait until connected... \n"); - return; - } - if(session_info.use_registration && !session_info.registered && - update_registration_server()) { - int len; - - /* prepare request, TID was set by COAP_BLOCKING_REQUEST() */ - coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0); - coap_set_header_uri_path(request, "/rd"); - - snprintf(query_data, sizeof(query_data) - 1, "?ep=%s<=%d&b=%s", session_info.ep, session_info.lifetime, session_info.binding); - coap_set_header_uri_query(request, query_data); - - len = set_rd_data(request); - rd_callback = registration_callback; - - LOG_INFO("Registering with ["); - LOG_INFO_COAP_EP(&session_info.server_ep); - LOG_INFO_("] lwm2m endpoint '%s': '", query_data); - if(len) { - LOG_INFO_COAP_STRING((const char *)rd_data, len); + break; + case DO_REGISTRATION: + if(!coap_endpoint_is_connected(&session_info->server_ep)) { + /* Not connected... wait a bit... and retry connection */ + coap_endpoint_connect(&session_info->server_ep); + LOG_DBG("Wait until connected... \n"); + return; } - LOG_INFO_("' More:%d\n", rd_more); - if(coap_send_request(&rd_request_state, &session_info.server_ep, - request, registration_callback)){ - rd_state = REGISTRATION_SENT; + if(session_info->use_server_type == USE_REGISTRATION_SERVER && !lwm2m_rd_client_is_registered(session_info) && + update_registration_server(session_info)) { + int len; + + /* prepare request, TID was set by COAP_BLOCKING_REQUEST() */ + coap_init_message(session_info->request, COAP_TYPE_CON, COAP_POST, 0); + coap_set_header_uri_path(session_info->request, "/rd"); + + snprintf(query_data, sizeof(query_data) - 1, "?ep=%s<=%d&b=%s", session_info->ep, session_info->lifetime, session_info->binding); + coap_set_header_uri_query(session_info->request, query_data); + + len = set_rd_data(session_info); + session_info->rd_callback = registration_callback; + + LOG_INFO("Registering with ["); + LOG_INFO_COAP_EP(&session_info->server_ep); + LOG_INFO_("] lwm2m endpoint '%s': '", query_data); + if(len) { + LOG_INFO_COAP_STRING((const char *)rd_data, len); + } + LOG_INFO_("' More:%d\n", session_info->rd_more); + + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->server_ep, + session_info->request, registration_callback)) { + + session_info->rd_state = REGISTRATION_SENT; + } + session_info->last_rd_progress = coap_timer_uptime(); } - } - break; - case REGISTRATION_SENT: - /* just wait until the callback kicks us to the next state... */ - break; - case REGISTRATION_DONE: - /* All is done! */ + break; + case REGISTRATION_SENT: + /* just wait until the callback kicks us to the next state... */ + break; + case REGISTRATION_DONE: + /* All is done! */ - check_periodic_observations(); /* TODO: manage periodic observations */ + check_periodic_observations(); /* TODO: manage periodic observations */ - /* check if it is time for the next update */ - if((rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED) || - ((uint32_t)session_info.lifetime * 500) <= now - last_update) { - /* triggered or time to send an update to the server, at half-time! sec vs ms */ - prepare_update(request, rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); - if(coap_send_request(&rd_request_state, &session_info.server_ep, request, - update_callback)) { - rd_state = UPDATE_SENT; + /* check if it is time for the next update */ + if((session_info->rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED) || + ((uint32_t)session_info->lifetime * 500) <= now - session_info->last_update) { + /* triggered or time to send an update to the server, at half-time! sec vs ms */ + prepare_update(session_info, session_info->rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); + + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->server_ep, session_info->request, + update_callback)) { + session_info->rd_state = UPDATE_SENT; + } + session_info->last_rd_progress = coap_timer_uptime(); } - } - break; + break; + #if LWM2M_QUEUE_MODE_ENABLED - case QUEUE_MODE_AWAKE: - LOG_DBG("Queue Mode: Client is AWAKE at %lu\n", (unsigned long)coap_timer_uptime()); - queue_mode_client_awake = 1; - queue_mode_client_awake_time = lwm2m_queue_mode_get_awake_time(); - coap_timer_set(&queue_mode_client_awake_timer, queue_mode_client_awake_time); - break; - case QUEUE_MODE_SEND_UPDATE: -/* Define this macro to make the necessary actions for waking up, - * depending on the platform - */ + case QUEUE_MODE_AWAKE: + LOG_DBG("Queue Mode: Client is AWAKE at %lu\n", (unsigned long)coap_timer_uptime()); + if((queue_mode_client_awake = all_sessions_in_queue_mode_awake())) { + queue_mode_client_awake_time = lwm2m_queue_mode_get_awake_time(); + coap_timer_set(&queue_mode_client_awake_timer, queue_mode_client_awake_time); + } + break; + case QUEUE_MODE_SEND_UPDATE: + /* Define this macro to make the necessary actions for waking up, + * depending on the platform + */ #ifdef LWM2M_QUEUE_MODE_WAKE_UP - LWM2M_QUEUE_MODE_WAKE_UP(); + LWM2M_QUEUE_MODE_WAKE_UP(); #endif /* LWM2M_QUEUE_MODE_WAKE_UP */ - prepare_update(request, rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); - if(coap_send_request(&rd_request_state, &session_info.server_ep, request, - update_callback)) { - rd_state = UPDATE_SENT; - } - break; + prepare_update(session_info, session_info->rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->server_ep, session_info->request, + update_callback)) { + session_info->rd_state = UPDATE_SENT; + } + session_info->last_rd_progress = coap_timer_uptime(); + break; #endif /* LWM2M_QUEUE_MODE_ENABLED */ - case UPDATE_SENT: - /* just wait until the callback kicks us to the next state... */ - break; - case DEREGISTER: - LOG_INFO("DEREGISTER %s\n", session_info.assigned_ep); - coap_init_message(request, COAP_TYPE_CON, COAP_DELETE, 0); - coap_set_header_uri_path(request, session_info.assigned_ep); - if(coap_send_request(&rd_request_state, &session_info.server_ep, request, - deregister_callback)) { - rd_state = DEREGISTER_SENT; - } - break; - case DEREGISTER_SENT: - break; - case DEREGISTER_FAILED: - break; - case DEREGISTERED: - break; + case UPDATE_SENT: + /* just wait until the callback kicks us to the next state... */ + break; + case DEREGISTER: + LOG_INFO("DEREGISTER %s\n", session_info->assigned_ep); + coap_init_message(session_info->request, COAP_TYPE_CON, COAP_DELETE, 0); + coap_set_header_uri_path(session_info->request, session_info->assigned_ep); - default: - LOG_WARN("Unhandled state: %d\n", rd_state); + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->server_ep, session_info->request, + deregister_callback)) { + session_info->rd_state = DEREGISTER_SENT; + } + break; + case DEREGISTER_SENT: + break; + case DEREGISTER_FAILED: + break; + case DEREGISTERED: + break; + + default: + LOG_WARN("Unhandled state: %d\n", session_info->rd_state); + } + session_info = session_info->next; } } /*---------------------------------------------------------------------------*/ void lwm2m_rd_client_init(const char *ep) { - session_info.ep = ep; - /* default binding U = UDP, UQ = UDP Q-mode*/ -#if LWM2M_QUEUE_MODE_ENABLED - session_info.binding = "UQ"; - /* Enough margin to ensure that the client is not unregistered (we - * do not know the time it can stay awake) - */ - session_info.lifetime = (LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME / 1000) * 2; -#else - session_info.binding = "U"; - if(session_info.lifetime == 0) { - session_info.lifetime = LWM2M_DEFAULT_CLIENT_LIFETIME; - } -#endif - - rd_state = INIT; + strcpy(default_ep, ep); /* call the RD client periodically */ coap_timer_set_callback(&rd_timer, periodic_process); @@ -846,27 +931,31 @@ queue_mode_awake_timer_callback(coap_timer_t *timer) LOG_DBG("Queue Mode: Client is SLEEPING at %lu\n", (unsigned long)coap_timer_uptime()); queue_mode_client_awake = 0; -/* Define this macro to enter sleep mode depending on the platform */ + lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); + while(session_info != NULL) { + session_info->rd_state = QUEUE_MODE_SEND_UPDATE; + session_info = session_info->next; + } + coap_timer_set(&rd_timer, lwm2m_queue_mode_get_sleep_time()); + /* Define this macro to enter sleep mode depending on the platform */ #ifdef LWM2M_QUEUE_MODE_SLEEP_MS LWM2M_QUEUE_MODE_SLEEP_MS(lwm2m_queue_mode_get_sleep_time()); #endif /* LWM2M_QUEUE_MODE_SLEEP_MS */ - rd_state = QUEUE_MODE_SEND_UPDATE; - coap_timer_set(&rd_timer, lwm2m_queue_mode_get_sleep_time()); } /*---------------------------------------------------------------------------*/ void -lwm2m_rd_client_fsm_execute_queue_mode_awake() +lwm2m_rd_client_fsm_execute_queue_mode_awake(lwm2m_session_info_t *session_info) { coap_timer_stop(&rd_timer); - rd_state = QUEUE_MODE_AWAKE; + session_info->rd_state = QUEUE_MODE_AWAKE; periodic_process(&rd_timer); } /*---------------------------------------------------------------------------*/ void -lwm2m_rd_client_fsm_execute_queue_mode_update() +lwm2m_rd_client_fsm_execute_queue_mode_update(lwm2m_session_info_t *session_info) { coap_timer_stop(&rd_timer); - rd_state = QUEUE_MODE_SEND_UPDATE; + session_info->rd_state = QUEUE_MODE_SEND_UPDATE; periodic_process(&rd_timer); } /*---------------------------------------------------------------------------*/ diff --git a/os/services/lwm2m/lwm2m-rd-client.h b/os/services/lwm2m/lwm2m-rd-client.h index cfc5c549d..7c1c66bd8 100644 --- a/os/services/lwm2m/lwm2m-rd-client.h +++ b/os/services/lwm2m/lwm2m-rd-client.h @@ -54,28 +54,71 @@ #include "lwm2m-object.h" #include "lwm2m-queue-mode-conf.h" +#include "coap-endpoint.h" +#include "coap-callback-api.h" struct lwm2m_session_info; typedef void (*session_callback_t)(struct lwm2m_session_info *session, int status); -int lwm2m_rd_client_is_registered(void); -void lwm2m_rd_client_use_bootstrap_server(int use); -void lwm2m_rd_client_use_registration_server(int use); -void lwm2m_rd_client_register_with_server(const coap_endpoint_t *server); -void lwm2m_rd_client_register_with_bootstrap_server(const coap_endpoint_t *server); -uint16_t lwm2m_rd_client_get_lifetime(void); -void lwm2m_rd_client_set_lifetime(uint16_t lifetime); +#ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN +#define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15 +#endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */ +/*---------------------------------------------------------------------------*/ +/*- Server session----------------------------*/ +/*---------------------------------------------------------------------------*/ +typedef struct lwm2m_session_info { + + struct lwm2m_session_info *next; + /* Information */ + const char *ep; + const char *binding; + char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN]; + uint16_t lifetime; + coap_endpoint_t bs_server_ep; + coap_endpoint_t server_ep; + uint8_t use_server_type; + uint8_t has_bs_server_info; + uint8_t has_registration_server_info; + uint8_t bootstrapped; /* bootstrap done */ + session_callback_t callback; + + /* CoAP Request */ + coap_callback_request_state_t rd_request_state; + coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */ + + /* RD parameters */ + uint8_t rd_state; + uint8_t rd_flags; + uint64_t wait_until_network_check; + uint64_t last_update; + uint64_t last_rd_progress; + + /* Blosk Transfer */ + uint32_t rd_block1; + uint8_t rd_more; + void (*rd_callback)(coap_callback_request_state_t *state); + coap_timer_t block1_timer; +} lwm2m_session_info_t; + +int lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info); +void lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server); +void lwm2m_rd_client_register_with_bootstrap_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server); +uint16_t lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info); +void lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime); +void lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint); +void lwm2m_rd_client_set_default_endpoint_name(const char *endpoint); + /* Indicate that something in the object list have changed */ void lwm2m_rd_client_set_update_rd(void); /* Control if the object list should be automatically updated at updates of lifetime */ -void lwm2m_rd_client_set_automatic_update(int update); +void lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int update); /* trigger an immediate update */ -void lwm2m_rd_client_update_triggered(void); +void lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep); -int lwm2m_rd_client_deregister(void); +int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info); void lwm2m_rd_client_init(const char *ep); -void lwm2m_rd_client_set_session_callback(session_callback_t cb); +void lwm2m_rd_client_set_session_callback(lwm2m_session_info_t *session_info, session_callback_t cb); #if LWM2M_QUEUE_MODE_ENABLED uint8_t lwm2m_rd_client_is_client_awake(void); @@ -84,28 +127,5 @@ void lwm2m_rd_client_fsm_execute_queue_mode_awake(); void lwm2m_rd_client_fsm_execute_queue_mode_update(); #endif -#ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN -#define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15 -#endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */ - -/*---------------------------------------------------------------------------*/ -/*- Server session-*Currently single session only*---------------------------*/ -/*---------------------------------------------------------------------------*/ -struct lwm2m_session_info { - const char *ep; - const char *binding; - char assigned_ep[LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN]; - uint16_t lifetime; - coap_endpoint_t bs_server_ep; - coap_endpoint_t server_ep; - uint8_t use_bootstrap; - uint8_t has_bs_server_info; - uint8_t use_registration; - uint8_t has_registration_server_info; - uint8_t registered; - uint8_t bootstrapped; /* bootstrap done */ - session_callback_t callback; -}; - #endif /* LWM2M_RD_CLIENT_H_ */ /** @} */ diff --git a/os/services/lwm2m/lwm2m-server.c b/os/services/lwm2m/lwm2m-server.c index bf0398b4f..b777d72d6 100644 --- a/os/services/lwm2m/lwm2m-server.c +++ b/os/services/lwm2m/lwm2m-server.c @@ -221,7 +221,7 @@ lwm2m_callback(lwm2m_object_instance_t *object, } else if(ctx->operation == LWM2M_OP_EXECUTE) { switch(ctx->resource_id) { case LWM2M_SERVER_REG_UPDATE_TRIGGER_ID: - lwm2m_rd_client_update_triggered(); + lwm2m_rd_client_update_triggered(ctx->request->src_ep); break; } } else { From 962aa01d30dffb9442177c967254854e5caccc21 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 4 Sep 2018 10:58:31 +0200 Subject: [PATCH 146/184] Combined the functions for registering LWM2M server and bootstrap server into a single function for simpler API. Updated the LWM2M example to register to a single server by default but with a configuration option to use multiple servers. --- .../lwm2m-ipso-objects/example-ipso-objects.c | 34 +++------ os/services/lwm2m/lwm2m-rd-client.c | 76 +++++++++---------- os/services/lwm2m/lwm2m-rd-client.h | 12 ++- 3 files changed, 53 insertions(+), 69 deletions(-) diff --git a/examples/lwm2m-ipso-objects/example-ipso-objects.c b/examples/lwm2m-ipso-objects/example-ipso-objects.c index 98e065f2f..60ca4bdb9 100644 --- a/examples/lwm2m-ipso-objects/example-ipso-objects.c +++ b/examples/lwm2m-ipso-objects/example-ipso-objects.c @@ -52,29 +52,25 @@ #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" +/* Define this macro to non-zero to register via a bootstrap server */ #ifndef REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER #define REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER 0 #endif -#ifndef REGISTER_WITH_LWM2M_SERVER -#define REGISTER_WITH_LWM2M_SERVER 1 +#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER +#define SERVER_TYPE LWM2M_RD_CLIENT_BOOTSTRAP_SERVER +#else +#define SERVER_TYPE LWM2M_RD_CLIENT_LWM2M_SERVER #endif #ifndef LWM2M_SERVER_ADDRESS #define LWM2M_SERVER_ADDRESS "coap://[fd00::1]" #endif -#ifndef LWM2M_SERVER_ADDRESS_SECOND -#define LWM2M_SERVER_ADDRESS_SECOND "coap://[fd00::1]:5686" -#endif +static lwm2m_session_info_t session_info; -#ifndef LWM2M_SESSIONS -#define LWM2M_SESSIONS 2 -#endif - - static lwm2m_session_info_t session_info; - -#if LWM2M_SESSIONS == 2 +/* Define this macro to register with a second LWM2M server */ +#ifdef LWM2M_SERVER_ADDRESS_SECOND static lwm2m_session_info_t session_info_second; #endif @@ -163,27 +159,17 @@ setup_lwm2m_servers(void) coap_endpoint_t server_ep; if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS, strlen(LWM2M_SERVER_ADDRESS), &server_ep) != 0) { -#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER - lwm2m_rd_client_register_with_bootstrap_server(&session_info, &server_ep); -#else - lwm2m_rd_client_register_with_server(&session_info, &server_ep); -#endif + lwm2m_rd_client_register_with_server(&session_info, &server_ep, SERVER_TYPE); } #endif /* LWM2M_SERVER_ADDRESS */ -#if LWM2M_SESSIONS == 2 #ifdef LWM2M_SERVER_ADDRESS_SECOND coap_endpoint_t server_ep_second; if(coap_endpoint_parse(LWM2M_SERVER_ADDRESS_SECOND, strlen(LWM2M_SERVER_ADDRESS_SECOND), &server_ep_second) != 0) { -#if REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER - lwm2m_rd_client_register_with_bootstrap_server(&session_info_second, &server_ep_second); -#else - lwm2m_rd_client_register_with_server(&session_info_second, &server_ep_second); -#endif + lwm2m_rd_client_register_with_server(&session_info_second, &server_ep_second, SERVER_TYPE); } #endif /* LWM2M_SERVER_ADDRESS_SECOND */ -#endif /* LWM2M_SESSIONS == 2 */ } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_ipso_objects, ev, data) diff --git a/os/services/lwm2m/lwm2m-rd-client.c b/os/services/lwm2m/lwm2m-rd-client.c index 995ab6c69..d0759f222 100644 --- a/os/services/lwm2m/lwm2m-rd-client.c +++ b/os/services/lwm2m/lwm2m-rd-client.c @@ -108,10 +108,6 @@ #define FLAG_RD_DATA_UPDATE_TRIGGERED 0x02 #define FLAG_RD_DATA_UPDATE_ON_DIRTY 0x10 -/* The type of server to use: bootstrap or registration */ -#define USE_BOOTSTRAP_SERVER 0 -#define USE_REGISTRATION_SERVER 1 - LIST(session_info_list); /* Shared by all sessions, used by only one at a time in the FSM */ @@ -119,7 +115,7 @@ static char query_data[64]; /* allocate some data for queries and updates */ static uint8_t rd_data[128]; /* allocate some data for the RD */ static coap_timer_t rd_timer; /* Timer to tick the FSM periodically */ -static char default_ep [20]; +static char default_ep[20]; #if LWM2M_QUEUE_MODE_ENABLED static coap_timer_t queue_mode_client_awake_timer; /* Timer to control the client's @@ -135,7 +131,7 @@ static void queue_mode_awake_timer_callback(coap_timer_t *timer); static void check_periodic_observations(); static void update_callback(coap_callback_request_state_t *callback_state); - +/*---------------------------------------------------------------------------*/ static int set_rd_data(lwm2m_session_info_t *session_info) { @@ -239,9 +235,8 @@ lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char void lwm2m_rd_client_set_default_endpoint_name(const char *endpoint) { - if(default_ep != NULL) { - strcpy(default_ep, endpoint); - } + strncpy(default_ep, endpoint, sizeof(default_ep) - 1); + default_ep[sizeof(default_ep) - 1] = '\0'; } /*---------------------------------------------------------------------------*/ void @@ -261,8 +256,10 @@ lwm2m_rd_client_set_automatic_update(lwm2m_session_info_t *session_info, int upd (update != 0 ? FLAG_RD_DATA_UPDATE_ON_DIRTY : 0); } /*---------------------------------------------------------------------------*/ -static void -setup_session_default_values(lwm2m_session_info_t *session_info) +void +lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, + const coap_endpoint_t *server, + lwm2m_rd_client_server_type_t server_type) { if(session_info->ep == NULL) { session_info->ep = default_ep; @@ -282,21 +279,25 @@ setup_session_default_values(lwm2m_session_info_t *session_info) #endif /* LWM2M_QUEUE_MODE_CONF_ENABLED */ session_info->rd_flags = FLAG_RD_DATA_UPDATE_ON_DIRTY; + session_info->has_bs_server_info = 0; + session_info->has_registration_server_info = 0; session_info->wait_until_network_check = 0; session_info->last_update = 0; session_info->last_rd_progress = 0; + session_info->bootstrapped = 0; session_info->rd_state = INIT; -} -/*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server) -{ + + if(server_type == LWM2M_RD_CLIENT_BOOTSTRAP_SERVER) { + coap_endpoint_copy(&session_info->bs_server_ep, server); + session_info->has_bs_server_info = 1; + session_info->use_server_type = LWM2M_RD_CLIENT_BOOTSTRAP_SERVER; + } else { + coap_endpoint_copy(&session_info->server_ep, server); + session_info->use_server_type = LWM2M_RD_CLIENT_LWM2M_SERVER; + session_info->has_registration_server_info = 1; + } + list_add(session_info_list, session_info); /* Add to the list of sessions */ - setup_session_default_values(session_info); - coap_endpoint_copy(&session_info->server_ep, server); - session_info->has_registration_server_info = 1; - session_info->use_server_type = USE_REGISTRATION_SERVER; - session_info->rd_state = INIT; } /*---------------------------------------------------------------------------*/ static int @@ -324,18 +325,6 @@ update_registration_server(lwm2m_session_info_t *session_info) return 0; } /*---------------------------------------------------------------------------*/ -void -lwm2m_rd_client_register_with_bootstrap_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server) -{ - list_add(session_info_list, session_info); /* Add to the list of sessions */ - setup_session_default_values(session_info); - coap_endpoint_copy(&session_info->bs_server_ep, server); - session_info->has_bs_server_info = 1; - session_info->use_server_type = USE_BOOTSTRAP_SERVER; - session_info->bootstrapped = 0; - session_info->rd_state = INIT; -} -/*---------------------------------------------------------------------------*/ int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info) { @@ -348,7 +337,7 @@ lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info) } /*---------------------------------------------------------------------------*/ static lwm2m_session_info_t * -get_sessio_info_from_server_ep(const coap_endpoint_t *server_ep) +get_session_info_from_server_ep(const coap_endpoint_t *server_ep) { lwm2m_session_info_t *session_info = (lwm2m_session_info_t *)list_head(session_info_list); while(session_info != NULL) { @@ -359,10 +348,11 @@ get_sessio_info_from_server_ep(const coap_endpoint_t *server_ep) } return NULL; } +/*---------------------------------------------------------------------------*/ void lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep) { - lwm2m_session_info_t *session_info = get_sessio_info_from_server_ep(server_ep); + lwm2m_session_info_t *session_info = get_session_info_from_server_ep(server_ep); if(session_info) { session_info->rd_flags |= FLAG_RD_DATA_UPDATE_TRIGGERED; } @@ -675,7 +665,7 @@ periodic_process(coap_timer_t *timer) session_info->wait_until_network_check = now + 10000; if(has_network_access()) { /* Either do bootstrap then registration */ - if(session_info->use_server_type == USE_BOOTSTRAP_SERVER) { + if(session_info->use_server_type == LWM2M_RD_CLIENT_BOOTSTRAP_SERVER) { session_info->rd_state = DO_BOOTSTRAP; } else { session_info->rd_state = DO_REGISTRATION; @@ -685,7 +675,8 @@ periodic_process(coap_timer_t *timer) } break; case DO_BOOTSTRAP: - if(session_info->use_server_type == USE_BOOTSTRAP_SERVER && session_info->bootstrapped == 0) { + if(session_info->use_server_type == LWM2M_RD_CLIENT_BOOTSTRAP_SERVER && + session_info->bootstrapped == 0) { if(update_bootstrap_server(session_info)) { /* prepare request, TID is set by COAP_BLOCKING_REQUEST() */ @@ -711,7 +702,7 @@ periodic_process(coap_timer_t *timer) break; case BOOTSTRAP_DONE: /* check that we should still use bootstrap */ - if(session_info->use_server_type == USE_BOOTSTRAP_SERVER) { + if(session_info->use_server_type == LWM2M_RD_CLIENT_BOOTSTRAP_SERVER) { lwm2m_security_server_t *security; LOG_DBG("*** Bootstrap - checking for server info...\n"); /* get the security object - ignore bootstrap servers */ @@ -748,7 +739,7 @@ periodic_process(coap_timer_t *timer) if(secure) { LOG_DBG("Secure CoAP requested but not supported - can not bootstrap\n"); } else { - lwm2m_rd_client_register_with_server(session_info, &session_info->server_ep); + lwm2m_rd_client_register_with_server(session_info, &session_info->server_ep, LWM2M_RD_CLIENT_LWM2M_SERVER); session_info->bootstrapped++; } } @@ -777,7 +768,8 @@ periodic_process(coap_timer_t *timer) return; } - if(session_info->use_server_type == USE_REGISTRATION_SERVER && !lwm2m_rd_client_is_registered(session_info) && + if(session_info->use_server_type == LWM2M_RD_CLIENT_LWM2M_SERVER && + !lwm2m_rd_client_is_registered(session_info) && update_registration_server(session_info)) { int len; @@ -891,7 +883,7 @@ periodic_process(coap_timer_t *timer) void lwm2m_rd_client_init(const char *ep) { - strcpy(default_ep, ep); + lwm2m_rd_client_set_default_endpoint_name(ep); /* call the RD client periodically */ coap_timer_set_callback(&rd_timer, periodic_process); @@ -908,7 +900,7 @@ check_periodic_observations(void) } /*---------------------------------------------------------------------------*/ /* - *Queue Mode Support + * Queue Mode Support */ #if LWM2M_QUEUE_MODE_ENABLED /*---------------------------------------------------------------------------*/ diff --git a/os/services/lwm2m/lwm2m-rd-client.h b/os/services/lwm2m/lwm2m-rd-client.h index 7c1c66bd8..58fa0a8c2 100644 --- a/os/services/lwm2m/lwm2m-rd-client.h +++ b/os/services/lwm2m/lwm2m-rd-client.h @@ -46,6 +46,13 @@ #ifndef LWM2M_RD_CLIENT_H_ #define LWM2M_RD_CLIENT_H_ +/* The type of server to use for registration: bootstrap or LWM2M */ +typedef enum { + LWM2M_RD_CLIENT_BOOTSTRAP_SERVER, + LWM2M_RD_CLIENT_LWM2M_SERVER +} lwm2m_rd_client_server_type_t; + +/* Session callback states */ #define LWM2M_RD_CLIENT_BOOTSTRAPPED 1 #define LWM2M_RD_CLIENT_REGISTERED 2 #define LWM2M_RD_CLIENT_DEREGISTERED 3 @@ -76,7 +83,7 @@ typedef struct lwm2m_session_info { uint16_t lifetime; coap_endpoint_t bs_server_ep; coap_endpoint_t server_ep; - uint8_t use_server_type; + lwm2m_rd_client_server_type_t use_server_type; uint8_t has_bs_server_info; uint8_t has_registration_server_info; uint8_t bootstrapped; /* bootstrap done */ @@ -101,8 +108,7 @@ typedef struct lwm2m_session_info { } lwm2m_session_info_t; int lwm2m_rd_client_is_registered(lwm2m_session_info_t *session_info); -void lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server); -void lwm2m_rd_client_register_with_bootstrap_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server); +void lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, const coap_endpoint_t *server, lwm2m_rd_client_server_type_t server_type); uint16_t lwm2m_rd_client_get_lifetime(lwm2m_session_info_t *session_info); void lwm2m_rd_client_set_lifetime(lwm2m_session_info_t *session_info, uint16_t lifetime); void lwm2m_rd_client_set_endpoint_name(lwm2m_session_info_t *session_info, const char *endpoint); From 82b7b74165c2defceb1ad2fc149445f46e020878 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 4 Sep 2018 11:45:49 +0200 Subject: [PATCH 147/184] Removed the incomplete feature in LWM2M RD client to "guess" a LWM2M server if none has been specified. This does not belong in the LWM2M RD client and does not work well with multiple server support. --- os/services/lwm2m/lwm2m-rd-client.c | 83 ++++++----------------------- 1 file changed, 16 insertions(+), 67 deletions(-) diff --git a/os/services/lwm2m/lwm2m-rd-client.c b/os/services/lwm2m/lwm2m-rd-client.c index d0759f222..6bb58f91a 100644 --- a/os/services/lwm2m/lwm2m-rd-client.c +++ b/os/services/lwm2m/lwm2m-rd-client.c @@ -300,31 +300,6 @@ lwm2m_rd_client_register_with_server(lwm2m_session_info_t *session_info, list_add(session_info_list, session_info); /* Add to the list of sessions */ } /*---------------------------------------------------------------------------*/ -static int -update_registration_server(lwm2m_session_info_t *session_info) -{ - if(session_info->has_registration_server_info) { - return 1; - } - -#if UIP_CONF_IPV6_RPL - { - rpl_dag_t *dag; - - /* Use the DAG id as server address if no other has been specified */ - dag = rpl_get_any_dag(); - if(dag != NULL) { - /* create coap-endpoint? */ - /* uip_ipaddr_copy(&server_ipaddr, &dag->dag_id); */ - /* server_port = REMOTE_PORT; */ - return 1; - } - } -#endif /* UIP_CONF_IPV6_RPL */ - - return 0; -} -/*---------------------------------------------------------------------------*/ int lwm2m_rd_client_deregister(lwm2m_session_info_t *session_info) { @@ -359,31 +334,6 @@ lwm2m_rd_client_update_triggered(const coap_endpoint_t *server_ep) /* Here we need to do an CoAP timer poll - to get a quick request transmission! */ } /*---------------------------------------------------------------------------*/ -static int -update_bootstrap_server(lwm2m_session_info_t *session_info) -{ - if(session_info->has_bs_server_info) { - return 1; - } - -#if UIP_CONF_IPV6_RPL - { - rpl_dag_t *dag; - - /* Use the DAG id as server address if no other has been specified */ - dag = rpl_get_any_dag(); - if(dag != NULL) { - /* create coap endpoint */ - /* uip_ipaddr_copy(&bs_server_ipaddr, &dag->dag_id); */ - /* bs_server_port = REMOTE_PORT; */ - return 1; - } - } -#endif /* UIP_CONF_IPV6_RPL */ - - return 0; -} -/*---------------------------------------------------------------------------*/ /* * A client initiated bootstrap starts with a POST to /bs?ep={session_info.ep}, * on the bootstrap server. The server should reply with 2.04. @@ -676,24 +626,23 @@ periodic_process(coap_timer_t *timer) break; case DO_BOOTSTRAP: if(session_info->use_server_type == LWM2M_RD_CLIENT_BOOTSTRAP_SERVER && - session_info->bootstrapped == 0) { - if(update_bootstrap_server(session_info)) { + session_info->bootstrapped == 0 && + session_info->has_bs_server_info) { - /* prepare request, TID is set by COAP_BLOCKING_REQUEST() */ - coap_init_message(session_info->request, COAP_TYPE_CON, COAP_POST, 0); - coap_set_header_uri_path(session_info->request, "/bs"); + /* prepare request, TID is set by COAP_BLOCKING_REQUEST() */ + coap_init_message(session_info->request, COAP_TYPE_CON, COAP_POST, 0); + coap_set_header_uri_path(session_info->request, "/bs"); - snprintf(query_data, sizeof(query_data) - 1, "?ep=%s", session_info->ep); - coap_set_header_uri_query(session_info->request, query_data); - LOG_INFO("Registering ID with bootstrap server ["); - LOG_INFO_COAP_EP(&session_info->bs_server_ep); - LOG_INFO_("] as '%s'\n", query_data); - /* Add session info as user data to use it in the callbacks */ - session_info->rd_request_state.state.user_data = (void *)session_info; - if(coap_send_request(&session_info->rd_request_state, &session_info->bs_server_ep, - session_info->request, bootstrap_callback)) { - session_info->rd_state = BOOTSTRAP_SENT; - } + snprintf(query_data, sizeof(query_data) - 1, "?ep=%s", session_info->ep); + coap_set_header_uri_query(session_info->request, query_data); + LOG_INFO("Registering ID with bootstrap server ["); + LOG_INFO_COAP_EP(&session_info->bs_server_ep); + LOG_INFO_("] as '%s'\n", query_data); + /* Add session info as user data to use it in the callbacks */ + session_info->rd_request_state.state.user_data = (void *)session_info; + if(coap_send_request(&session_info->rd_request_state, &session_info->bs_server_ep, + session_info->request, bootstrap_callback)) { + session_info->rd_state = BOOTSTRAP_SENT; } } break; @@ -770,7 +719,7 @@ periodic_process(coap_timer_t *timer) if(session_info->use_server_type == LWM2M_RD_CLIENT_LWM2M_SERVER && !lwm2m_rd_client_is_registered(session_info) && - update_registration_server(session_info)) { + session_info->has_registration_server_info) { int len; /* prepare request, TID was set by COAP_BLOCKING_REQUEST() */ From 416b38861f20c7da6a768c47740117c4cd2674e0 Mon Sep 17 00:00:00 2001 From: Carlos Gonzalo Date: Thu, 6 Sep 2018 13:49:42 +0200 Subject: [PATCH 148/184] Updated lwm2m-standalone submodule --- tests/18-coap-lwm2m/example-lwm2m-standalone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/18-coap-lwm2m/example-lwm2m-standalone b/tests/18-coap-lwm2m/example-lwm2m-standalone index 67b858437..3b23ca8d6 160000 --- a/tests/18-coap-lwm2m/example-lwm2m-standalone +++ b/tests/18-coap-lwm2m/example-lwm2m-standalone @@ -1 +1 @@ -Subproject commit 67b858437f7cf1e4e027d821c4c2ac15fdf2ab44 +Subproject commit 3b23ca8d6a19d281b6330d3f24afc2e1bb14ddb7 From 666e4263cdc74aa95ac4029358acd2053150c91b Mon Sep 17 00:00:00 2001 From: Takeshi Sakoda Date: Wed, 21 Nov 2018 17:27:20 +0900 Subject: [PATCH 149/184] tsch-rpl: add tsch_rpl_check_dodag_joined function in tsch-rpl. --- os/net/mac/tsch/tsch-rpl.c | 8 ++++++++ os/net/mac/tsch/tsch-rpl.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/os/net/mac/tsch/tsch-rpl.c b/os/net/mac/tsch/tsch-rpl.c index 951648d91..e8db94b57 100644 --- a/os/net/mac/tsch/tsch-rpl.c +++ b/os/net/mac/tsch/tsch-rpl.c @@ -136,5 +136,13 @@ tsch_rpl_callback_parent_switch(rpl_parent_t *old, rpl_parent_t *new) rpl_parent_get_ipaddr(new))); } } +/*---------------------------------------------------------------------------*/ +/* Check RPL has joined DODAG. + * To use, set #define TSCH_RPL_CHECK_DODAG_JOINED tsch_rpl_check_dodag_joined */ +int +tsch_rpl_check_dodag_joined(void) +{ + return NETSTACK_ROUTING.node_has_joined(); +} #endif /* UIP_CONF_IPV6_RPL */ /** @} */ diff --git a/os/net/mac/tsch/tsch-rpl.h b/os/net/mac/tsch/tsch-rpl.h index 23a148db8..95412e3d2 100644 --- a/os/net/mac/tsch/tsch-rpl.h +++ b/os/net/mac/tsch/tsch-rpl.h @@ -79,6 +79,12 @@ void tsch_rpl_callback_new_dio_interval(clock_time_t dio_interval); * \param new The new RPL parent */ void tsch_rpl_callback_parent_switch(rpl_parent_t *old, rpl_parent_t *new); +/** + * \brief Check RPL has joined DODAG. + * To use, set TSCH_RPL_CHECK_DODAG_JOINED tsch_rpl_check_dodag_joined + * \return 1 if joined, 0 otherwise + */ +int tsch_rpl_check_dodag_joined(void); #endif /* __TSCH_RPL_H__ */ /** @} */ From 3a1d604418e2a4efe88ad68bf68d893b881d6ee8 Mon Sep 17 00:00:00 2001 From: Takeshi Sakoda Date: Wed, 21 Nov 2018 17:27:35 +0900 Subject: [PATCH 150/184] tsch: add start sending EB when a node joins RPL newwork in tsch. --- os/net/mac/tsch/tsch.c | 9 +++++++++ os/net/mac/tsch/tsch.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index a33feeef1..bb1018677 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -862,6 +862,12 @@ PROCESS_THREAD(tsch_send_eb_process, ev, data) unsigned long delay; if(tsch_is_associated && tsch_current_eb_period > 0) { +#ifdef TSCH_RPL_CHECK_DODAG_JOINED + /* Implementation section 6.3 of RFC 8180 */ + if(!TSCH_RPL_CHECK_DODAG_JOINED()) { + goto tsch_send_eb_skipped; + } +#endif /* TSCH_RPL_CHECK_DODAG_JOINED */ /* Enqueue EB only if there isn't already one in queue */ if(tsch_queue_packet_count(&tsch_eb_address) == 0) { uint8_t hdr_len = 0; @@ -881,6 +887,9 @@ PROCESS_THREAD(tsch_send_eb_process, ev, data) } } } +#ifdef TSCH_RPL_CHECK_DODAG_JOINED +tsch_send_eb_skipped: +#endif /* TSCH_RPL_CHECK_DODAG_JOINED */ if(tsch_current_eb_period > 0) { /* Next EB transmission with a random delay * within [tsch_current_eb_period*0.75, tsch_current_eb_period[ */ diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index db23b4851..2683d24b1 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -88,6 +88,10 @@ frequency hopping for enhanced reliability. #define TSCH_CALLBACK_KA_SENT tsch_rpl_callback_ka_sent #endif /* TSCH_CALLBACK_KA_SENT */ +#ifndef TSCH_RPL_CHECK_DODAG_JOINED +#define TSCH_RPL_CHECK_DODAG_JOINED tsch_rpl_check_dodag_joined +#endif /* TSCH_RPL_CHECK_DODAG_JOINED */ + #endif /* UIP_CONF_IPV6_RPL */ #if BUILD_WITH_ORCHESTRA @@ -117,6 +121,11 @@ void TSCH_CALLBACK_LEAVING_NETWORK(); void TSCH_CALLBACK_KA_SENT(); #endif +/* Called by TSCH before sending a EB */ +#ifdef TSCH_RPL_CHECK_DODAG_JOINED +int TSCH_RPL_CHECK_DODAG_JOINED(); +#endif + /* Called by TSCH form interrupt after receiving a frame, enabled upper-layer to decide * whether to ACK or NACK */ #ifdef TSCH_CALLBACK_DO_NACK From a9aad296177ba1e1fb6826ce82108b41be6bdce9 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 22 Nov 2018 15:01:08 +0100 Subject: [PATCH 151/184] Add missing inclusions of --- examples/benchmarks/rpl-req-resp/node.c | 2 ++ os/net/mac/tsch/tsch-adaptive-timesync.c | 1 + 2 files changed, 3 insertions(+) diff --git a/examples/benchmarks/rpl-req-resp/node.c b/examples/benchmarks/rpl-req-resp/node.c index 4b92415f9..bc7552797 100644 --- a/examples/benchmarks/rpl-req-resp/node.c +++ b/examples/benchmarks/rpl-req-resp/node.c @@ -42,6 +42,8 @@ #include "contiki-net.h" #include "services/deployment/deployment.h" +#include + /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "App" diff --git a/os/net/mac/tsch/tsch-adaptive-timesync.c b/os/net/mac/tsch/tsch-adaptive-timesync.c index cf10e9cf1..2745abca2 100644 --- a/os/net/mac/tsch/tsch-adaptive-timesync.c +++ b/os/net/mac/tsch/tsch-adaptive-timesync.c @@ -45,6 +45,7 @@ #include "net/mac/tsch/tsch.h" #include +#include #if TSCH_ADAPTIVE_TIMESYNC From f1bbc421217f7a2ddc61f0454defbebc25cc9284 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Nov 2018 10:35:41 +0100 Subject: [PATCH 152/184] Build system: enable compiling with arch directory at arbitrary paths --- Makefile.include | 11 +++++++---- arch/cpu/arm/cortex-m/Makefile.cortex-m | 2 +- arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 2 +- arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 2 +- arch/cpu/cc2538/Makefile.cc2538 | 2 +- arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 2 +- arch/cpu/msp430/Makefile.msp430 | 2 +- arch/cpu/nrf52832/Makefile.nrf52832 | 2 +- .../cc13x0-cc26x0/Makefile.cc13x0-cc26x0 | 2 +- .../cc13x2-cc26x2/Makefile.cc13x2-cc26x2 | 2 +- arch/platform/cc2538dk/Makefile.cc2538dk | 2 +- arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 4 ++-- arch/platform/cooja/Makefile.cooja | 4 ++-- arch/platform/native/Makefile.native | 4 ++-- arch/platform/nrf52dk/Makefile.nrf52dk | 4 ++-- .../platform/openmote-cc2538/Makefile.openmote-cc2538 | 4 ++-- .../simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx | 2 +- arch/platform/sky/Makefile.common | 2 +- arch/platform/sky/Makefile.sky | 2 +- arch/platform/zoul/Makefile.zoul | 4 ++-- 20 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Makefile.include b/Makefile.include index 672c7f4c1..2e5a31d1a 100644 --- a/Makefile.include +++ b/Makefile.include @@ -82,7 +82,10 @@ uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) ### Include target makefile (TODO Unsafe?) -target_makefile := $(wildcard $(CONTIKI)/arch/platform/$(TARGET)/Makefile.$(TARGET) ${foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)}) +# Configurable arch path +ARCH_PATH ?= $(CONTIKI)/arch + +target_makefile := $(wildcard $(ARCH_PATH)/platform/$(TARGET)/Makefile.$(TARGET) ${foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)}) # Check if the target makefile exists, and create the object directory if necessary. ifeq ($(strip $(target_makefile)),) @@ -326,13 +329,13 @@ clean: @echo Target $(TARGET) cleaned distclean: - @for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \ + @for TARG in `ls $(ARCH_PATH)/platform $(TARGETDIRS)`; do \ echo Running: $(MAKE) TARGET=$$TARG clean; \ $(MAKE) TARGET=$$TARG clean; \ done -$(Q)rm -rf $(BUILD_DIR) --include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) +-include $(ARCH_PATH)/platform/$(TARGET)/Makefile.customrules-$(TARGET) ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR) @@ -414,7 +417,7 @@ endif include $(CONTIKI)/Makefile.help targets: - @ls $(CONTIKI)/arch/platform $(TARGETDIRS) + @ls $(ARCH_PATH)/platform $(TARGETDIRS) boards: ifdef BOARD diff --git a/arch/cpu/arm/cortex-m/Makefile.cortex-m b/arch/cpu/arm/cortex-m/Makefile.cortex-m index 0ca1d54ff..3f14ead41 100644 --- a/arch/cpu/arm/cortex-m/Makefile.cortex-m +++ b/arch/cpu/arm/cortex-m/Makefile.cortex-m @@ -25,4 +25,4 @@ $(OUT_ELF): $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ -include $(CONTIKI)/arch/cpu/arm/Makefile.arm +include $(ARCH_PATH)/cpu/arm/Makefile.arm diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index b4bf612da..35051a0f7 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -6,4 +6,4 @@ LDFLAGS += -mcpu=cortex-m3 -nostartfiles TARGET_LIBFILES += -lm -include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m +include $(ARCH_PATH)/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 7443681ea..dc470601f 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -4,4 +4,4 @@ CFLAGS += -mcpu=cortex-m4 LDFLAGS += -mcpu=cortex-m4 -include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m +include $(ARCH_PATH)/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index 51a5c40c7..85f435320 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -52,4 +52,4 @@ $(LDSCRIPT): $(SOURCE_LDSCRIPT) FORCE | $(OBJECTDIR) $(TRACE_CC) $(Q)$(CC) $(LDGENFLAGS) $< | grep -v '^\s*#\s*pragma\>' > $@ -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +include $(ARCH_PATH)/cpu/arm/cortex-m/cm3/Makefile.cm3 diff --git a/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index a4f5ed1a9..c0fb8eeed 100644 --- a/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -81,7 +81,7 @@ STACK_SIZE = 0 @$(SIZE) -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}' @$(SIZE) -A $< | egrep "text|isr_vector" | awk '{s+=$$2} END {f=$(FLASH_SIZE)-s; printf "[Flash] used %6d, free %6d\n",s,f;}' -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +include $(ARCH_PATH)/cpu/arm/cortex-m/cm3/Makefile.cm3 ifeq ($(BOARD_SUPPORTS_BSL),1) %.upload: $(OUT_BIN) diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index 841e11285..7927002b6 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -11,7 +11,7 @@ CFLAGS += -gstabs+ .SUFFIXES: ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/msp430 +CONTIKI_CPU=$(ARCH_PATH)/cpu/msp430 ### Define the source files we have in the MSP430 port diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index c78838fd1..c72fa6f5f 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -204,4 +204,4 @@ erase: .PHONY: softdevice.jlink -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +include $(ARCH_PATH)/cpu/arm/cortex-m/cm4/Makefile.cm4 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 index 9aa7c5be2..9be4ad6ab 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 @@ -8,4 +8,4 @@ TARGET_LIBFILES += $(SDK_DRIVERS)/lib/drivers_$(SDK_LIB_NAME).am3g TARGET_LIBFILES += $(SDK_DEVICES)/driverlib/bin/gcc/driverlib.lib # CC13x0/CC26x0 is a Cortex-M3 architecture -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +include $(ARCH_PATH)/cpu/arm/cortex-m/cm3/Makefile.cm3 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 index 52333f47d..afe0ae429 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 @@ -8,4 +8,4 @@ TARGET_LIBFILES += $(SDK_DRIVERS)/lib/drivers_$(SDK_LIB_NAME).am4fg TARGET_LIBFILES += $(SDK_DEVICES)/driverlib/bin/gcc/driverlib.lib # CC13x2/CC26x2 is a Cortex-M4 architecture -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +include $(ARCH_PATH)/cpu/arm/cortex-m/cm4/Makefile.cm4 diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index 148c6e837..bdbc7598f 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -14,7 +14,7 @@ CONTIKI_TARGET_SOURCEFILES += board-buttons.c als-sensor.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 +CONTIKI_CPU=$(ARCH_PATH)/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 MODULES += os/storage/cfs diff --git a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index 43cc7ea3f..622445dd4 100644 --- a/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/arch/platform/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -11,7 +11,7 @@ BOARDS = srf06/cc26x0 srf06/cc13x0 launchpad/cc2640r2 launchpad/cc2650 launchpad CONTIKI_TARGET_DIRS += . ### Include the board-specific makefile -PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) +PLATFORM_ROOT_DIR = $(ARCH_PATH)/platform/$(TARGET) -include $(PLATFORM_ROOT_DIR)/$(BOARD)/Makefile.$(notdir $(BOARD)) CONTIKI_TARGET_SOURCEFILES += platform.c leds-arch.c @@ -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/cc26x0-cc13x0 +CONTIKI_CPU=$(ARCH_PATH)/cpu/cc26x0-cc13x0 include $(CONTIKI_CPU)/Makefile.$(CPU_FAMILY) diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index 6a6a9d49e..6fdb6f0ca 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -41,7 +41,7 @@ JNILIB = $(BUILD_DIR_BOARD)/$(LIBNAME).$(TARGET) CONTIKI_APP_OBJ = $(CONTIKI_APP).o ### COOJA platform sources -COOJA = $(CONTIKI)/arch/platform/$(TARGET) +COOJA = $(ARCH_PATH)/platform/$(TARGET) CONTIKI_TARGET_DIRS = . dev lib sys cfs net # (COOJA_SOURCEDIRS contains additional sources dirs set from simulator) @@ -67,7 +67,7 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) CLEAN += COOJA.log ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/x86 +CONTIKI_CPU=$(ARCH_PATH)/cpu/x86 ### Compiler arguments #CC = gcc diff --git a/arch/platform/native/Makefile.native b/arch/platform/native/Makefile.native index afeddd22f..51681284e 100644 --- a/arch/platform/native/Makefile.native +++ b/arch/platform/native/Makefile.native @@ -28,5 +28,5 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) MAKE_MAC ?= MAKE_MAC_NULLMAC ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/native -include $(CONTIKI)/arch/cpu/native/Makefile.native +CONTIKI_CPU=$(ARCH_PATH)/cpu/native +include $(ARCH_PATH)/cpu/native/Makefile.native diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index e1d56c090..ff554b35c 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -3,7 +3,7 @@ ifndef CONTIKI endif ### Include the board-specific makefile -PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) +PLATFORM_ROOT_DIR = $(ARCH_PATH)/platform/$(TARGET) CONTIKI_TARGET_DIRS += . dev config CONTIKI_SOURCEFILES += platform.c leds-arch.c nrf52dk-sensors.c button-sensor.c temperature-sensor.c @@ -21,5 +21,5 @@ endif SMALL ?= 0 ### Define the CPU directory and pull in the correct CPU makefile. -CONTIKI_CPU=$(CONTIKI)/arch/cpu/nrf52832 +CONTIKI_CPU=$(ARCH_PATH)/cpu/nrf52832 include $(CONTIKI_CPU)/Makefile.nrf52832 diff --git a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 index 8b25b0bfe..f720a9ae8 100644 --- a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -11,7 +11,7 @@ endif ### Configure the build for the board and pull in board-specific sources CONTIKI_TARGET_DIRS += . dev -PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) +PLATFORM_ROOT_DIR = $(ARCH_PATH)/platform/$(TARGET) ### Include CONTIKI_TARGET_SOURCEFILES += platform.c board.c @@ -21,7 +21,7 @@ CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 +CONTIKI_CPU=$(ARCH_PATH)/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 MODULES += os/storage/cfs diff --git a/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx b/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx index 9f2dbe45b..39a3fc504 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx +++ b/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx @@ -51,7 +51,7 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) CPU_FAMILY = cc13xx-cc26xx # Define the CPU directory and pull in the correct CPU Makefile -CONTIKI_CPU := $(realpath $(CONTIKI)/arch/cpu/simplelink-$(CPU_FAMILY)) +CONTIKI_CPU := $(realpath $(ARCH_PATH)/cpu/simplelink-$(CPU_FAMILY)) include $(CONTIKI_CPU)/Makefile.$(CPU_FAMILY) MODULES += os/net os/net/mac os/net/mac/framer diff --git a/arch/platform/sky/Makefile.common b/arch/platform/sky/Makefile.common index 5018da3da..b72f92ed8 100644 --- a/arch/platform/sky/Makefile.common +++ b/arch/platform/sky/Makefile.common @@ -18,7 +18,7 @@ endif CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS) MCU=msp430f1611 -include $(CONTIKI)/arch/cpu/msp430/Makefile.msp430 +include $(ARCH_PATH)/cpu/msp430/Makefile.msp430 ifdef IAR diff --git a/arch/platform/sky/Makefile.sky b/arch/platform/sky/Makefile.sky index 0398486b0..ec2324085 100644 --- a/arch/platform/sky/Makefile.sky +++ b/arch/platform/sky/Makefile.sky @@ -4,6 +4,6 @@ CONTIKI_TARGET_SOURCEFILES += contiki-sky-platform.c \ sht11.c sht11-sensor.c light-sensor.c battery-sensor.c \ button-sensor.c -include $(CONTIKI)/arch/platform/sky/Makefile.common +include $(ARCH_PATH)/platform/sky/Makefile.common MODULES += arch/dev/cc2420 arch/dev/sht11 arch/dev/ds2411 os/storage/cfs diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index e43f84744..e65290b42 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -25,7 +25,7 @@ CFLAGS += -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\"" ### Configure the build for the board and pull in board-specific sources CONTIKI_TARGET_DIRS += . dev CONTIKI_TARGET_DIRS += . $(BOARD) -PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) +PLATFORM_ROOT_DIR = $(ARCH_PATH)/platform/$(TARGET) ### Include the board dir if one exists -include $(PLATFORM_ROOT_DIR)/$(BOARD)/Makefile.$(BOARD) @@ -39,7 +39,7 @@ CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) ### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 +CONTIKI_CPU=$(ARCH_PATH)/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 MODULES += arch/dev/cc1200 arch/dev/rgb-led os/storage/cfs From 081a8cd516beb87ac0bdbbcc841a06be86cf6e9b Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Mon, 26 Nov 2018 10:55:19 +0100 Subject: [PATCH 153/184] Fixed wrong PIN configuration for UART0_RX on LaunchPads All LaunchPads drives the UART0_RX pin up, but is configured in the Board file to be pull-down. This alignes the UART0_RX pin configuration with the development board HW. --- .../simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c | 2 +- .../simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c | 2 +- .../simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c | 2 +- .../cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c index b33dab9ad..b5db4e61d 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c @@ -498,7 +498,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1310_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1310_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1310_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1310_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1310_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1310_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1310_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1310_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c index 44fd41035..a51bba632 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c @@ -619,7 +619,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1312R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1312R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1312R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1312R1_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1312R1_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1312R1_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1312R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1312R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c index b4d34a54b..aa690dff4 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c @@ -493,7 +493,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1350_LAUNCHXL_433_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1350_LAUNCHXL_433_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1350_LAUNCHXL_433_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1350_LAUNCHXL_433_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1350_LAUNCHXL_433_UART_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1350_LAUNCHXL_433_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1350_LAUNCHXL_433_DIO1_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4 GHz path*/ CC1350_LAUNCHXL_433_DIO30_RF_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* External RF Switch is powered off by default */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c index 1277fc66a..ff7f47351 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c @@ -498,7 +498,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1350_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1350_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1350_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1350_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1350_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1350_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4 GHz path*/ CC1350_LAUNCHXL_DIO30_RF_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* External RF Switch is powered off by default */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c index a1b74bce4..c2717cc70 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c @@ -585,7 +585,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1352P_2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P_2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P_2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1352P_2_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P_2_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1352P_2_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1352P_2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1352P_2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c index 63a41d64b..bd4f43032 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c @@ -585,7 +585,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1352P_4_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P_4_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P_4_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1352P_4_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P_4_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1352P_4_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1352P_4_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1352P_4_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c index d4f953fba..cff74bc03 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c @@ -585,7 +585,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1352P1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352P1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1352P1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1352P1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1352P1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1352P1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c index a9197a4f5..d2b3eeee3 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c @@ -609,7 +609,7 @@ const PIN_Config BoardGpioInitTable[] = { CC1352R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC1352R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1352R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC1352R1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC1352R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC1352R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c index ed0a4796e..02fd96471 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c @@ -497,7 +497,7 @@ const PIN_Config BoardGpioInitTable[] = { CC2650_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC2650_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC2650_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC2650_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC2650_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC2650_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC2650_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC2650_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c index db47744de..a66a6ef00 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c @@ -619,7 +619,7 @@ const PIN_Config BoardGpioInitTable[] = { CC26X2R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC26X2R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ CC26X2R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC26X2R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC26X2R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLUP, /* UART RX via debugger back channel */ CC26X2R1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ CC26X2R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ CC26X2R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ From dff3e760b81259629ca126c537949a7552a72a71 Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Thu, 29 Nov 2018 16:42:45 +0100 Subject: [PATCH 154/184] Fix correct LOG_INFO in platform.c When logging info about channel and PANID a newline is added for each logging statement. It should only add a newline for the first LOG_INFO. --- arch/platform/simplelink/cc13xx-cc26xx/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/platform/simplelink/cc13xx-cc26xx/platform.c b/arch/platform/simplelink/cc13xx-cc26xx/platform.c index c78fe1946..56030445a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/platform.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/platform.c @@ -250,9 +250,9 @@ platform_init_stage_three(void) LOG_INFO("RF: Channel %d", chan); if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &pan) == RADIO_RESULT_OK) { - LOG_INFO(", PANID 0x%04X", pan); + LOG_INFO_(", PANID 0x%04X", pan); } - LOG_INFO("\n"); + LOG_INFO_("\n"); LOG_INFO("Node ID: %d\n", node_id); From 944d8da2559b54e05b5feb114b9d22a8175398c4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 1 Dec 2018 20:37:25 +0000 Subject: [PATCH 155/184] Fix the nrf52dk .jlink and .flash make targets Fixes #782 --- arch/cpu/nrf52832/Makefile.nrf52832 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index c72fa6f5f..102e74486 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -185,10 +185,12 @@ $(OBJECT_DIRECTORY)/%.o: %.s $(TRACE_CC) $(Q)$(CC) $(ASMFLAGS) $(addprefix -I$(NRF52_SDK_ROOT)/, $(INC_PATHS)) -c -o $@ $< -%.jlink: - sed -e 's/#OUTPUT_FILENAME#/$*.hex/' $(CONTIKI_CPU)/flash.jlink > $@ +include $(ARCH_PATH)/cpu/arm/cortex-m/cm4/Makefile.cm4 -%.flash: %.hex %.jlink +%.jlink: $(OUT_HEX) + sed -e 's,#OUTPUT_FILENAME#,$<,' $(CONTIKI_CPU)/flash.jlink > $@ + +%.flash: %.jlink @echo Flashing: $^ $(JLINK) $(JLINK_OPTS) -CommanderScript $*.jlink @@ -203,5 +205,3 @@ erase: $(JLINK) $(JLINK_OPTS) -CommanderScript $(CONTIKI_CPU)/erase.jlink .PHONY: softdevice.jlink - -include $(ARCH_PATH)/cpu/arm/cortex-m/cm4/Makefile.cm4 From e7a86cf16b2aff9a44b690228e669b580531d929 Mon Sep 17 00:00:00 2001 From: Toshio Ito Date: Thu, 6 Dec 2018 11:30:54 +0900 Subject: [PATCH 156/184] cooja: add int-master implementation. It's copied from arch/cpu/native/int-master.c, which is just a no-op stub. See #790 --- arch/platform/cooja/Makefile.cooja | 2 +- arch/platform/cooja/int-master.c | 67 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 arch/platform/cooja/int-master.c diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index 6fdb6f0ca..023fe3d9a 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -47,7 +47,7 @@ CONTIKI_TARGET_DIRS = . dev lib sys cfs net # (COOJA_SOURCEDIRS contains additional sources dirs set from simulator) vpath %.c $(COOJA_SOURCEDIRS) -COOJA_BASE = simEnvChange.c cooja_mt.c cooja_mtarch.c rtimer-arch.c slip.c watchdog.c +COOJA_BASE = simEnvChange.c cooja_mt.c cooja_mtarch.c rtimer-arch.c slip.c watchdog.c int-master.c COOJA_INTFS = beep.c button-sensor.c ip.c leds-arch.c moteid.c \ pir-sensor.c rs232.c vib-sensor.c \ diff --git a/arch/platform/cooja/int-master.c b/arch/platform/cooja/int-master.c new file mode 100644 index 000000000..177dbd442 --- /dev/null +++ b/arch/platform/cooja/int-master.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * 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 "contiki.h" +#include "sys/int-master.h" + +#include +/*---------------------------------------------------------------------------*/ +#define DISABLED 0 +#define ENABLED 1 +/*---------------------------------------------------------------------------*/ +static int_master_status_t stat = DISABLED; +/*---------------------------------------------------------------------------*/ +void +int_master_enable(void) +{ + stat = ENABLED; +} +/*---------------------------------------------------------------------------*/ +int_master_status_t +int_master_read_and_disable(void) +{ + int_master_status_t rv = stat; + stat = DISABLED; + return rv; +} +/*---------------------------------------------------------------------------*/ +void +int_master_status_set(int_master_status_t status) +{ + stat = status; +} +/*---------------------------------------------------------------------------*/ +bool +int_master_is_enabled(void) +{ + return stat == DISABLED ? false : true; +} +/*---------------------------------------------------------------------------*/ From 8863fcab0ef83c503a1410d1bd47a6bb30b2cb33 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 17 Dec 2018 15:34:27 +0000 Subject: [PATCH 157/184] typo fix in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9a1005ef..03a980a0d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Contiki-NG is an open-source, cross-platform operating system for Next-Generation IoT devices. It focuses on dependable (secure and reliable) low-power communication and standard protocols, such as IPv6/6LoWPAN, 6TiSCH, RPL, and CoAP. Contiki-NG comes with extensive documentation, tutorials, a roadmap, release cycle, and well-defined development flow for smooth integration of community contributions. -Unless excplicitly stated otherwise, Contiki-NG sources are distributed under +Unless explicitly stated otherwise, Contiki-NG sources are distributed under the terms of the [3-clause BSD license](LICENSE.md). This license gives everyone the right to use and distribute the code, either in binary or source code format, as long as the copyright license is retained in From f9cd3449f374ab7f3f492607aa9b51a0de15098f Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 18 Dec 2018 16:21:15 +0000 Subject: [PATCH 158/184] add tsch_get_network_uptime_ticks() function --- os/net/mac/tsch/tsch-slot-operation.c | 48 ++++++++++++++++++++++++--- os/net/mac/tsch/tsch-slot-operation.h | 2 +- os/net/mac/tsch/tsch.h | 6 ++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index a801bc92e..4397a4805 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -52,6 +52,7 @@ #include "net/queuebuf.h" #include "net/mac/framer/framer-802154.h" #include "net/mac/tsch/tsch.h" +#include "sys/critical.h" #include "sys/log.h" /* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH @@ -126,9 +127,10 @@ struct tsch_packet *dequeued_array[TSCH_DEQUEUED_ARRAY_SIZE]; struct ringbufindex input_ringbuf; struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS]; +/* Updates and reads of the next two variables must be atomic (i.e. both together) */ /* Last time we received Sync-IE (ACK or data packet from a time source) */ static struct tsch_asn_t last_sync_asn; -clock_time_t last_sync_time; /* Same info, in clock_time_t units */ +clock_time_t tsch_last_sync_time; /* Same info, in clock_time_t units */ /* A global lock for manipulating data structures safely from outside of interrupt */ static volatile int tsch_locked = 0; @@ -347,6 +349,33 @@ get_packet_and_neighbor_for_link(struct tsch_link *link, struct tsch_neighbor ** return p; } /*---------------------------------------------------------------------------*/ +uint64_t +tsch_get_network_uptime_ticks(void) +{ + uint64_t uptime_asn; + uint64_t uptime_ticks; + int_master_status_t status; + + if(!tsch_is_associated) { + /* not associated, network uptime is not known */ + return (uint64_t)-1; + } + + status = critical_enter(); + + uptime_asn = last_sync_asn.ls4b + ((uint64_t)last_sync_asn.ms1b << 32); + /* first calculate the at the uptime at the last sync in rtimer ticks */ + uptime_ticks = uptime_asn * tsch_timing[tsch_ts_timeslot_length]; + /* then convert to clock ticks (assume that CLOCK_SECOND divides RTIMER_ARCH_SECOND) */ + uptime_ticks /= (RTIMER_ARCH_SECOND / CLOCK_SECOND); + /* then add the ticks passed since the last timesync */ + uptime_ticks += (clock_time() - tsch_last_sync_time); + + critical_exit(status); + + return uptime_ticks; +} +/*---------------------------------------------------------------------------*/ /** * This function turns on the radio. Its semantics is dependent on * the value of TSCH_RADIO_ON_DURING_TIMESLOT constant: @@ -623,7 +652,7 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) tsch_timesync_update(current_neighbor, since_last_timesync, drift_correction); /* Keep track of sync time */ last_sync_asn = tsch_current_asn; - last_sync_time = clock_time(); + tsch_last_sync_time = clock_time(); tsch_schedule_keepalive(); } mac_tx_status = MAC_TX_OK; @@ -882,7 +911,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) int32_t since_last_timesync = TSCH_ASN_DIFF(tsch_current_asn, last_sync_asn); /* Keep track of last sync time */ last_sync_asn = tsch_current_asn; - last_sync_time = clock_time(); + tsch_last_sync_time = clock_time(); /* Save estimated drift */ drift_correction = -estimated_drift; is_drift_correction_used = 1; @@ -1014,6 +1043,13 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) /* End of slot operation, schedule next slot or resynchronize */ + if(tsch_is_coordinator) { + /* Update the `last_sync_*` variables to avoid large errors + * in the application-level time synchronization */ + last_sync_asn = tsch_current_asn; + tsch_last_sync_time = clock_time(); + } + /* Do we need to resynchronize? i.e., wait for EB again */ if(!tsch_is_coordinator && (TSCH_ASN_DIFF(tsch_current_asn, last_sync_asn) > (100 * TSCH_CLOCK_TO_SLOTS(TSCH_DESYNC_THRESHOLD / 100, tsch_timing[tsch_ts_timeslot_length])))) { @@ -1115,10 +1151,14 @@ void tsch_slot_operation_sync(rtimer_clock_t next_slot_start, struct tsch_asn_t *next_slot_asn) { + int_master_status_t status; + current_slot_start = next_slot_start; tsch_current_asn = *next_slot_asn; + status = critical_enter(); last_sync_asn = tsch_current_asn; - last_sync_time = clock_time(); + tsch_last_sync_time = clock_time(); + critical_exit(status); current_link = NULL; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/tsch/tsch-slot-operation.h b/os/net/mac/tsch/tsch-slot-operation.h index b1c05697b..22547a2c9 100644 --- a/os/net/mac/tsch/tsch-slot-operation.h +++ b/os/net/mac/tsch/tsch-slot-operation.h @@ -56,7 +56,7 @@ extern struct tsch_packet *dequeued_array[TSCH_DEQUEUED_ARRAY_SIZE]; extern struct ringbufindex input_ringbuf; extern struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS]; /* Last clock_time_t where synchronization happened */ -extern clock_time_t last_sync_time; +extern clock_time_t tsch_last_sync_time; /* Counts the length of the current burst */ extern int tsch_current_burst_count; diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index db23b4851..8674ee31a 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -226,6 +226,12 @@ void tsch_schedule_keepalive(void); * Schedule a keep-alive immediately */ void tsch_schedule_keepalive_immediately(void); +/** + * Get the time, in clock ticks, since the TSCH network was started. + * + * \return The network uptime, or -1 if the node is not part of a TSCH network. + */ +uint64_t tsch_get_network_uptime_ticks(void); /** * Leave the TSCH network we are currently in */ From 08cbbe224b7ec3148f4d55ea3afe95f66717b38f Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 18 Dec 2018 16:21:43 +0000 Subject: [PATCH 159/184] minor shell update: extend the tsch-status command --- os/services/shell/shell-commands.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index c8b7d862e..2d0bdfed0 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -584,8 +584,12 @@ PT_THREAD(cmd_tsch_status(struct pt *pt, shell_output_func output, char *args)) } else { SHELL_OUTPUT(output, "none\n"); } - SHELL_OUTPUT(output, "-- Last synchronized: %lu seconds ago\n", (clock_time() - last_sync_time) / CLOCK_SECOND); - SHELL_OUTPUT(output, "-- Drift w.r.t. coordinator: %ld ppm\n", tsch_adaptive_timesync_get_drift_ppm()); + SHELL_OUTPUT(output, "-- Last synchronized: %lu seconds ago\n", + (clock_time() - tsch_last_sync_time) / CLOCK_SECOND); + SHELL_OUTPUT(output, "-- Drift w.r.t. coordinator: %ld ppm\n", + tsch_adaptive_timesync_get_drift_ppm()); + SHELL_OUTPUT(output, "-- Network uptime: %lu seconds\n", + (unsigned long)(tsch_get_network_uptime_ticks() / CLOCK_SECOND)); } PT_END(pt); From 99a68e84f193ac6a70d13c12234dda793e0c698e Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 18 Dec 2018 16:22:37 +0000 Subject: [PATCH 160/184] add the TSCH application-level timesync example --- examples/6tisch/timesync-demo/Makefile | 24 ++++ examples/6tisch/timesync-demo/README.md | 18 +++ examples/6tisch/timesync-demo/node.c | 139 +++++++++++++++++++ examples/6tisch/timesync-demo/project-conf.h | 83 +++++++++++ 4 files changed, 264 insertions(+) create mode 100644 examples/6tisch/timesync-demo/Makefile create mode 100644 examples/6tisch/timesync-demo/README.md create mode 100644 examples/6tisch/timesync-demo/node.c create mode 100644 examples/6tisch/timesync-demo/project-conf.h diff --git a/examples/6tisch/timesync-demo/Makefile b/examples/6tisch/timesync-demo/Makefile new file mode 100644 index 000000000..cd18192d0 --- /dev/null +++ b/examples/6tisch/timesync-demo/Makefile @@ -0,0 +1,24 @@ +CONTIKI_PROJECT = node +all: $(CONTIKI_PROJECT) + +CONTIKI=../../.. + +PLATFORMS_EXCLUDE = sky nrf52dk native + +# force Orchestra from command line +MAKE_WITH_ORCHESTRA ?= 0 +# force Security from command line +MAKE_WITH_SECURITY ?= 0 + +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/shell + +ifeq ($(MAKE_WITH_ORCHESTRA),1) +MODULES += os/services/orchestra +endif + +ifeq ($(MAKE_WITH_SECURITY),1) +CFLAGS += -DWITH_SECURITY=1 +endif + +include $(CONTIKI)/Makefile.include diff --git a/examples/6tisch/timesync-demo/README.md b/examples/6tisch/timesync-demo/README.md new file mode 100644 index 000000000..cf130ee73 --- /dev/null +++ b/examples/6tisch/timesync-demo/README.md @@ -0,0 +1,18 @@ +This is a demonstration of application-level time synchronization using TSCH. + +In a TSCH network, all nodes are synchronized to a global time counter maintained +by the coordinator. This fact can be exploited to measure properties such as latency. + +The modes periodically send their detected network uptime to the coordinator. +The coordinator receives these packets, prints its local network uptime +and the time difference. This time difference is equal to the end-to-end latency, +which includes both the time to prepare the packet, the time until an appropriate +slot in the TSCH schedule, the over-the-air time (negligible). If the packet +does not arrive with the first attempt, it also includes the retransmission time. + +The nodes in this example do not have any notion of the wall-clock time. +That would need additional synchronization between the TSCH network and an external clock source. +For example, one can periodically distribute UNIX timestamps over the UART interface +on the border router to implement this feature. Alternatively, the data collected from +the TSCH network can be timestamped with just TSCH timestamps, and them on the external gateway +these timestamps could be converted to wall-clock time. \ No newline at end of file diff --git a/examples/6tisch/timesync-demo/node.c b/examples/6tisch/timesync-demo/node.c new file mode 100644 index 000000000..408421cec --- /dev/null +++ b/examples/6tisch/timesync-demo/node.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * 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. + * + */ +/** + * \file + * A RPL+TSCH node demonstrating application-level time syncrhonization. + * + * \author Atis Elsts + * Simon Duquennoy + */ + +#include "contiki.h" +#include "net/routing/routing.h" +#include "net/netstack.h" +#include "net/ipv6/simple-udp.h" +#include "net/mac/tsch/tsch.h" +#include "lib/random.h" +#include "sys/node-id.h" + +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +#define SEND_INTERVAL (60 * CLOCK_SECOND) +/*---------------------------------------------------------------------------*/ +static struct simple_udp_connection client_conn, server_conn; + +PROCESS(node_process, "RPL Node"); +AUTOSTART_PROCESSES(&node_process); +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + uint64_t local_time_clock_ticks = tsch_get_network_uptime_ticks(); + uint64_t remote_time_clock_ticks; + + if(datalen >= sizeof(remote_time_clock_ticks)) { + memcpy(&remote_time_clock_ticks, data, sizeof(remote_time_clock_ticks)); + + LOG_INFO("Received from "); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_(", created at %lu, now %lu, latency %lu clock ticks\n", + (unsigned long)remote_time_clock_ticks, + (unsigned long)local_time_clock_ticks, + (unsigned long)(local_time_clock_ticks - remote_time_clock_ticks)); + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(node_process, ev, data) +{ + static struct etimer periodic_timer; + int is_coordinator; + uip_ipaddr_t dest_ipaddr; + + PROCESS_BEGIN(); + + is_coordinator = 0; + +#if CONTIKI_TARGET_COOJA + is_coordinator = (node_id == 1); +#endif + + if(is_coordinator) { + NETSTACK_ROUTING.root_start(); + } + + /* Initialize UDP connections */ + simple_udp_register(&server_conn, UDP_SERVER_PORT, NULL, + UDP_CLIENT_PORT, udp_rx_callback); + simple_udp_register(&client_conn, UDP_CLIENT_PORT, NULL, + UDP_SERVER_PORT, NULL); + + NETSTACK_MAC.on(); + + etimer_set(&periodic_timer, random_rand() % SEND_INTERVAL); + + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + + if(tsch_is_coordinator) { + break; + } + + if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) { + /* Send network uptime timestamp to the DAG root */ + uint64_t network_uptime; + network_uptime = tsch_get_network_uptime_ticks(); + simple_udp_sendto(&client_conn, &network_uptime, sizeof(network_uptime), &dest_ipaddr); + LOG_INFO("Sent network uptime timestamp %lu to ", (unsigned long)network_uptime); + LOG_INFO_6ADDR(&dest_ipaddr); + LOG_INFO_("\n"); + } else { + LOG_INFO("Not reachable yet\n"); + } + + /* Add some jitter */ + etimer_set(&periodic_timer, SEND_INTERVAL + - CLOCK_SECOND + (random_rand() % (2 * CLOCK_SECOND))); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/6tisch/timesync-demo/project-conf.h b/examples/6tisch/timesync-demo/project-conf.h new file mode 100644 index 000000000..f787b8dfe --- /dev/null +++ b/examples/6tisch/timesync-demo/project-conf.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * 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. + * + */ + +/** + * \author Simon Duquennoy + * Atis Elsts + */ + +#ifndef __PROJECT_CONF_H__ +#define __PROJECT_CONF_H__ + +/* Set to enable TSCH security */ +#ifndef WITH_SECURITY +#define WITH_SECURITY 0 +#endif /* WITH_SECURITY */ + +/* USB serial takes space, free more space elsewhere */ +#define SICSLOWPAN_CONF_FRAG 0 +#define UIP_CONF_BUFFER_SIZE 160 + +/*******************************************************/ +/******************* Configure TSCH ********************/ +/*******************************************************/ + +/* IEEE802.15.4 PANID */ +#define IEEE802154_CONF_PANID 0x81a5 + +/* Do not start TSCH at init, wait for NETSTACK_MAC.on() */ +#define TSCH_CONF_AUTOSTART 0 + +/* 6TiSCH minimal schedule length. + * Larger values result in less frequent active slots: reduces capacity and saves energy. */ +#define TSCH_SCHEDULE_CONF_DEFAULT_LENGTH 3 + +#if WITH_SECURITY + +/* Enable security */ +#define LLSEC802154_CONF_ENABLED 1 + +#endif /* WITH_SECURITY */ + +/*******************************************************/ +/************* Other system configuration **************/ +/*******************************************************/ + +/* Logging */ +#define LOG_CONF_LEVEL_RPL LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_TCPIP LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_IPV6 LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_6LOWPAN LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_MAC LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_WARN +#define TSCH_LOG_CONF_PER_SLOT 0 + +#endif /* __PROJECT_CONF_H__ */ From de3c154f485d19611fc83bd64e08a567b8559516 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 18 Dec 2018 16:52:40 +0000 Subject: [PATCH 161/184] UDP example code cleanup --- examples/libs/ipv6-uipbuf/udp-client.c | 3 --- examples/rpl-udp/udp-client.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/examples/libs/ipv6-uipbuf/udp-client.c b/examples/libs/ipv6-uipbuf/udp-client.c index bee1cda83..5616874b5 100644 --- a/examples/libs/ipv6-uipbuf/udp-client.c +++ b/examples/libs/ipv6-uipbuf/udp-client.c @@ -12,9 +12,6 @@ #define UDP_CLIENT_PORT 8765 #define UDP_SERVER_PORT 5678 -static struct simple_udp_connection udp_conn; - -#define START_INTERVAL (15 * CLOCK_SECOND) #define SEND_INTERVAL (60 * CLOCK_SECOND) static struct simple_udp_connection udp_conn; diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index 7f24c8bac..5dc7a0763 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -12,9 +12,6 @@ #define UDP_CLIENT_PORT 8765 #define UDP_SERVER_PORT 5678 -static struct simple_udp_connection udp_conn; - -#define START_INTERVAL (15 * CLOCK_SECOND) #define SEND_INTERVAL (60 * CLOCK_SECOND) static struct simple_udp_connection udp_conn; From c01d3d7d227845721d66b9ec157acf68a41bcf1b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 18 Dec 2018 17:14:18 +0000 Subject: [PATCH 162/184] Do not allow to 'trick' the platform and board exclude checks --- Makefile.include | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.include b/Makefile.include index 2e5a31d1a..930378c01 100644 --- a/Makefile.include +++ b/Makefile.include @@ -478,6 +478,8 @@ ifeq ($(PLATFORM_ACTION),skip) # Skip this target. $(CONTIKI_PROJECT): @echo "Skipping $@: not for the '$(TARGET)/$(BOARD)' platform!" +%.$(TARGET): + @echo "Skipping $@: not for the '$(TARGET)/$(BOARD)' platform!" else # Build this target. # Match-anything pattern rule to allow the project makefiles to From cd1b23ff38ee3117268ded59ed5b6f1575786911 Mon Sep 17 00:00:00 2001 From: Zhitao He Date: Wed, 9 Jan 2019 14:02:01 +0100 Subject: [PATCH 163/184] fix temperature sensor reading in nrf52dk platform, which was stuck at zero --- arch/platform/nrf52dk/dev/temperature-sensor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/platform/nrf52dk/dev/temperature-sensor.c b/arch/platform/nrf52dk/dev/temperature-sensor.c index 5aac8b3ef..3af30c4af 100644 --- a/arch/platform/nrf52dk/dev/temperature-sensor.c +++ b/arch/platform/nrf52dk/dev/temperature-sensor.c @@ -64,7 +64,15 @@ static int value(int type) { #ifndef SOFTDEVICE_PRESENT - return nrf_temp_read(); + int32_t volatile temp; + + NRF_TEMP->TASKS_START = 1; + while(NRF_TEMP->EVENTS_DATARDY == 0); + NRF_TEMP->EVENTS_DATARDY = 0; + temp = nrf_temp_read(); + NRF_TEMP->TASKS_STOP = 1; + + return temp; #else int32_t temp; sd_temp_get(&temp); From 0b31b090aa425c9b5d4967f0a3b1c8fbe32c35e2 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Wed, 9 Jan 2019 16:53:26 +0200 Subject: [PATCH 164/184] Add AES-128 driver for CC26x0/CC13x0 --- arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 | 1 + arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h | 5 + arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.c | 127 ++++++++++++++++++ arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.h | 80 +++++++++++ arch/cpu/cc26x0-cc13x0/ti-lib.h | 8 ++ 5 files changed, 221 insertions(+) create mode 100755 arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.c create mode 100755 arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.h diff --git a/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 index c0fb8eeed..d3900b9fb 100644 --- a/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 +++ b/arch/cpu/cc26x0-cc13x0/Makefile.cc26x0-cc13x0 @@ -44,6 +44,7 @@ CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c CONTIKI_CPU_SOURCEFILES += spi-arch.c +CONTIKI_CPU_SOURCEFILES += cc26xx-aes.c CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) diff --git a/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h b/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h index 7400c5ad9..0b553fb90 100644 --- a/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h +++ b/arch/cpu/cc26x0-cc13x0/cc13xx-cc26xx-conf.h @@ -102,6 +102,11 @@ #define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125 +/* Platform-specific (H/W) AES implementation */ +#ifndef AES_128_CONF +#define AES_128_CONF cc26xx_aes_128_driver +#endif /* AES_128_CONF */ + /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.c b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.c new file mode 100755 index 000000000..cacdfc61f --- /dev/null +++ b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2016, 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. + */ +/** + * \addtogroup cc26xx-aes + * @{ + * + * \file + * Implementation of the AES driver for the CC26x0/CC13x0 SoC + * \author + * Atis Elsts + */ +#include "contiki.h" +#include "dev/cc26xx-aes.h" +#include "ti-lib.h" +/*---------------------------------------------------------------------------*/ +#include "sys/log.h" +#define LOG_MODULE "cc26xx-aes" +#define LOG_LEVEL LOG_LEVEL_MAIN +/*---------------------------------------------------------------------------*/ +static uint32_t skey[AES_128_KEY_LENGTH / sizeof(uint32_t)]; + +/*---------------------------------------------------------------------------*/ +void +cc26xx_aes_set_key(const uint8_t *key) +{ + memcpy(skey, key, AES_128_KEY_LENGTH); +} +/*---------------------------------------------------------------------------*/ +static void +encrypt_decrypt(uint8_t *plaintext_and_result, bool do_encrypt) +{ + uint32_t result[AES_128_BLOCK_SIZE / sizeof(uint32_t)]; + unsigned status; + int i; + + /* First, make sure the PERIPH PD is on */ + ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); + while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) + != PRCM_DOMAIN_POWER_ON)); + + /* Enable CRYPTO peripheral */ + ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_CRYPTO); + ti_lib_prcm_load_set(); + while(!ti_lib_prcm_load_get()); + + status = ti_lib_crypto_aes_load_key(skey, CRYPTO_KEY_AREA_0); + if(status != AES_SUCCESS) { + LOG_WARN("load key failed: %u\n", status); + } else { + + status = ti_lib_crypto_aes_ecb((uint32_t *)plaintext_and_result, result, CRYPTO_KEY_AREA_0, do_encrypt, false); + if(status != AES_SUCCESS) { + LOG_WARN("ecb failed: %u\n", status); + } else { + + for(i = 0; i < 100; ++i) { + ti_lib_cpu_delay(10); + status = ti_lib_crypto_aes_ecb_status(); + if(status != AES_DMA_BSY) { + break; + } + } + + ti_lib_crypto_aes_ecb_finish(); + + if(status != AES_SUCCESS) { + LOG_WARN("ecb get result failed: %u\n", status); + } + } + } + + ti_lib_prcm_peripheral_run_disable(PRCM_PERIPH_CRYPTO); + ti_lib_prcm_load_set(); + while(!ti_lib_prcm_load_get()); + + if(status == AES_SUCCESS) { + memcpy(plaintext_and_result, result, AES_128_BLOCK_SIZE); + } else { + /* corrupt the result */ + plaintext_and_result[0] ^= 1; + } +} +/*---------------------------------------------------------------------------*/ +void +cc26xx_aes_encrypt(uint8_t *plaintext_and_result) +{ + encrypt_decrypt(plaintext_and_result, true); +} +/*---------------------------------------------------------------------------*/ +void +cc26xx_aes_decrypt(uint8_t *cyphertext_and_result) +{ + encrypt_decrypt(cyphertext_and_result, false); +} +/*---------------------------------------------------------------------------*/ +const struct aes_128_driver cc26xx_aes_128_driver = { + cc26xx_aes_set_key, + cc26xx_aes_encrypt +}; + +/** @} */ diff --git a/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.h b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.h new file mode 100755 index 000000000..a979cc562 --- /dev/null +++ b/arch/cpu/cc26x0-cc13x0/dev/cc26xx-aes.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016, 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. + */ +/** + * \addtogroup cc26xx + * @{ + * + * \defgroup cc26xx-aes CC26x0/CC13x0 AES-128 + * + * AES-128 driver for the CC26x0/CC13x0 SoC + * @{ + * + * \file + * Header file of the AES-128 driver for the CC26xx SoC + * \author + * Atis Elsts + */ +#ifndef CC2538_AES_H_ +#define CC2538_AES_H_ + +#include "lib/aes-128.h" + +/** + * \brief Set a key to use in subsequent encryption & decryption operations. + * \param key The key to use + * + * The size of the key must be AES_128_KEY_LENGTH. + */ +void cc26xx_aes_set_key(const uint8_t *key); + +/** + * \brief Encrypt a message using the SoC AES-128 hardware implementation + * \param plaintext_and_result In: message to encrypt, out: the encrypted message. + * + * The size of the message must be AES_128_BLOCK_SIZE. + * The key to use in the encryption must be set before calling this function. + */ +void cc26xx_aes_encrypt(uint8_t *plaintext_and_result); + +/** + * \brief Decrypt a message using the SoC AES-128 hardware implementation + * \param cyphertext_and_result In: message to decrypt, out: the decrypted message. + * + * The size of the message must be AES_128_BLOCK_SIZE. + * The key to use in the decryption must be set before calling this function. + */ +void cc26xx_aes_decrypt(uint8_t *cyphertext_and_result); + +extern const struct aes_128_driver cc26xx_aes_128_driver; + +#endif /* CC2538_AES_H_ */ +/** + * @} + * @} + */ diff --git a/arch/cpu/cc26x0-cc13x0/ti-lib.h b/arch/cpu/cc26x0-cc13x0/ti-lib.h index d6c7363ee..0d8400813 100644 --- a/arch/cpu/cc26x0-cc13x0/ti-lib.h +++ b/arch/cpu/cc26x0-cc13x0/ti-lib.h @@ -572,6 +572,14 @@ #define ti_lib_watchdog_stall_enable(...) WatchdogStallEnable(__VA_ARGS__) #define ti_lib_watchdog_stall_disable(...) WatchdogStallDisable(__VA_ARGS__) /*---------------------------------------------------------------------------*/ +/* crypto.h */ +#include "driverlib/crypto.h" + +#define ti_lib_crypto_aes_load_key(...) CRYPTOAesLoadKey(__VA_ARGS__) +#define ti_lib_crypto_aes_ecb(...) CRYPTOAesEcb(__VA_ARGS__) +#define ti_lib_crypto_aes_ecb_status(...) CRYPTOAesEcbStatus(__VA_ARGS__) +#define ti_lib_crypto_aes_ecb_finish(...) CRYPTOAesEcbFinish(__VA_ARGS__) +/*---------------------------------------------------------------------------*/ #endif /* TI_LIB_H_ */ /*---------------------------------------------------------------------------*/ /** From f1b2d35a8c297489bb44489baeb6ada976dd916d Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Tue, 8 Jan 2019 10:19:08 +0100 Subject: [PATCH 165/184] Extend 8-bit variables to 16 bits to avoid integer overflows when processing IPv6 extension header options. --- os/net/ipv6/uip6.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 8a1c27682..24274a306 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -824,13 +824,13 @@ ext_hdr_options_process(uint8_t *ext_buf) * 8 bytes, excluding the first 8 bytes * length field in an option : the length of data in the option */ - uint8_t opt_offset = 2; /* 2 first bytes in ext header */ + uint16_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; + uint16_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; + uint16_t opt_len = opt_hdr->len + 2; if(opt_offset + opt_len > ext_hdr_len) { LOG_ERR("RPL Option too long: Dropping Packet\n"); From d0a0a2a568eff152ed1f3b964d53f8b3eee12434 Mon Sep 17 00:00:00 2001 From: Zhitao He Date: Thu, 10 Jan 2019 18:56:27 +0100 Subject: [PATCH 166/184] busy wait maximum 72 us (typically 36 us) for taking a measurement from the on-chip temperature sensor --- arch/platform/nrf52dk/dev/temperature-sensor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/platform/nrf52dk/dev/temperature-sensor.c b/arch/platform/nrf52dk/dev/temperature-sensor.c index 3af30c4af..f42fd3fe3 100644 --- a/arch/platform/nrf52dk/dev/temperature-sensor.c +++ b/arch/platform/nrf52dk/dev/temperature-sensor.c @@ -67,7 +67,8 @@ value(int type) int32_t volatile temp; NRF_TEMP->TASKS_START = 1; - while(NRF_TEMP->EVENTS_DATARDY == 0); + /* nRF52832 datasheet: one temperature measurement takes typically 36 us */ + RTIMER_BUSYWAIT_UNTIL(NRF_TEMP->EVENTS_DATARDY, RTIMER_SECOND * 72 / 1000000); NRF_TEMP->EVENTS_DATARDY = 0; temp = nrf_temp_read(); NRF_TEMP->TASKS_STOP = 1; From d850fff673f0a1a2b9c2c91d8330bdbb4c32ea90 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Nov 2018 09:55:52 +0100 Subject: [PATCH 167/184] Make it possible to use shell without IPv6 --- os/services/shell/shell-commands.c | 19 +++++++++++++++++-- os/services/shell/shell.c | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index c8b7d862e..331d674de 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -72,16 +72,19 @@ #define PING_TIMEOUT (5 * CLOCK_SECOND) +#if NETSTACK_CONF_WITH_IPV6 static struct uip_icmp6_echo_reply_notification echo_reply_notification; static shell_output_func *curr_ping_output_func = NULL; static struct process *curr_ping_process; static uint8_t curr_ping_ttl; static uint16_t curr_ping_datalen; +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if TSCH_WITH_SIXTOP static shell_command_6top_sub_cmd_t sixtop_sub_cmd = NULL; #endif /* TSCH_WITH_SIXTOP */ static struct shell_command_set_t builtin_shell_command_set; LIST(shell_command_sets); +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static const char * ds6_nbr_state_to_str(uint8_t state) @@ -101,6 +104,7 @@ ds6_nbr_state_to_str(uint8_t state) return "Unknown"; } } +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if ROUTING_CONF_RPL_LITE /*---------------------------------------------------------------------------*/ static const char * @@ -219,6 +223,7 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } #endif /* ROUTING_CONF_RPL_LITE */ +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static void echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) @@ -275,6 +280,7 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } +#endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ static void shell_output_log_levels(shell_output_func output) @@ -457,6 +463,7 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char * } #endif /* ROUTING_CONF_RPL_LITE */ #endif /* UIP_CONF_IPV6_RPL */ +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args)) @@ -478,7 +485,6 @@ PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args)) } PT_END(pt); - } /*---------------------------------------------------------------------------*/ static @@ -509,6 +515,7 @@ PT_THREAD(cmd_ip_neighbors(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if MAC_CONF_WITH_TSCH /*---------------------------------------------------------------------------*/ static @@ -591,6 +598,7 @@ PT_THREAD(cmd_tsch_status(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } #endif /* MAC_CONF_WITH_TSCH */ +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) @@ -656,6 +664,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } +#endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ static PT_THREAD(cmd_reboot(struct pt *pt, shell_output_func output, char *args)) @@ -804,9 +813,11 @@ shell_commands_init(void) { list_init(shell_command_sets); list_add(shell_command_sets, &builtin_shell_command_set); +#if NETSTACK_CONF_WITH_IPV6 /* Set up Ping Reply callback */ uip_icmp6_echo_reply_callback_add(&echo_reply_notification, echo_reply_handler); +#endif /* NETSTACK_CONF_WITH_IPV6 */ } /*---------------------------------------------------------------------------*/ void @@ -846,10 +857,12 @@ shell_command_lookup(const char *name) const struct shell_command_t builtin_shell_commands[] = { { "help", cmd_help, "'> help': Shows this help" }, { "reboot", cmd_reboot, "'> reboot': Reboot the board by watchdog_reboot()" }, + { "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." }, +#if NETSTACK_CONF_WITH_IPV6 { "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" }, { "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" }, - { "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." }, { "ping", cmd_ping, "'> ping addr': Pings the IPv6 address 'addr'" }, +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if UIP_CONF_IPV6_RPL { "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix can be optionally specified." }, { "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" }, @@ -862,7 +875,9 @@ const struct shell_command_t builtin_shell_commands[] = { { "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" }, { "rpl-nbr", cmd_rpl_nbr, "'> rpl-nbr': Shows the RPL neighbor table" }, #endif /* ROUTING_CONF_RPL_LITE */ +#if NETSTACK_CONF_WITH_IPV6 { "routes", cmd_routes, "'> routes': Shows the route entries" }, +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if MAC_CONF_WITH_TSCH { "tsch-set-coordinator", cmd_tsch_set_coordinator, "'> tsch-set-coordinator 0/1 [0/1]': Sets node as coordinator (1) or not (0). Second, optional parameter: enable (1) or disable (0) security." }, { "tsch-schedule", cmd_tsch_schedule, "'> tsch-schedule': Shows the current TSCH schedule" }, diff --git a/os/services/shell/shell.c b/os/services/shell/shell.c index 5347080a8..f5383ee5f 100644 --- a/os/services/shell/shell.c +++ b/os/services/shell/shell.c @@ -52,6 +52,7 @@ #include "net/ipv6/ip64-addr.h" #include "net/ipv6/uiplib.h" +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ void shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr) @@ -60,6 +61,7 @@ shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr) uiplib_ipaddr_snprint(buf, sizeof(buf), ipaddr); SHELL_OUTPUT(output, "%s", buf); } +#endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ void shell_output_lladdr(shell_output_func output, const linkaddr_t *lladdr) From 36ee548b51b9606041d5b7416a54b9ca3f560cfe Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Nov 2018 09:56:02 +0100 Subject: [PATCH 168/184] Shell: add mac-addr command --- os/services/shell/shell-commands.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 331d674de..512c60b6f 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -463,6 +463,18 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char * } #endif /* ROUTING_CONF_RPL_LITE */ #endif /* UIP_CONF_IPV6_RPL */ +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_macaddr(struct pt *pt, shell_output_func output, char *args)) +{ + PT_BEGIN(pt); + + SHELL_OUTPUT(output, "Node MAC address: "); + shell_output_lladdr(output, &linkaddr_node_addr); + SHELL_OUTPUT(output, "\n"); + + PT_END(pt); +} #if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static @@ -858,6 +870,7 @@ const struct shell_command_t builtin_shell_commands[] = { { "help", cmd_help, "'> help': Shows this help" }, { "reboot", cmd_reboot, "'> reboot': Reboot the board by watchdog_reboot()" }, { "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." }, + { "mac-addr", cmd_macaddr, "'> mac-addr': Shows the node's MAC address" }, #if NETSTACK_CONF_WITH_IPV6 { "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" }, { "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" }, From 5c206691a3e3967721def08e9b6a23eb27f1188b Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 11 Jan 2019 21:22:16 +0100 Subject: [PATCH 169/184] Shell: group IPv6 and RPL-Lite commands --- os/services/shell/shell-commands.c | 135 ++++++++++++++--------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 512c60b6f..c5bffe619 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -104,7 +104,64 @@ ds6_nbr_state_to_str(uint8_t state) return "Unknown"; } } +/*---------------------------------------------------------------------------*/ +static void +echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) +{ + if(curr_ping_output_func != NULL) { + curr_ping_output_func = NULL; + curr_ping_ttl = ttl; + curr_ping_datalen = datalen; + process_poll(curr_ping_process); + } +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args)) +{ + static uip_ipaddr_t remote_addr; + static struct etimer timeout_timer; + char *next_args; + + PT_BEGIN(pt); + + SHELL_ARGS_INIT(args, next_args); + + /* Get argument (remote IPv6) */ + SHELL_ARGS_NEXT(args, next_args); + if(args == NULL) { + SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n"); + PT_EXIT(pt); + } else if(uiplib_ipaddrconv(args, &remote_addr) == 0) { + SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args); + PT_EXIT(pt); + } + + SHELL_OUTPUT(output, "Pinging "); + shell_output_6addr(output, &remote_addr); + SHELL_OUTPUT(output, "\n"); + + /* Send ping request */ + curr_ping_process = PROCESS_CURRENT(); + curr_ping_output_func = output; + etimer_set(&timeout_timer, PING_TIMEOUT); + uip_icmp6_send(&remote_addr, ICMP6_ECHO_REQUEST, 0, 4); + PT_WAIT_UNTIL(pt, curr_ping_output_func == NULL || etimer_expired(&timeout_timer)); + + if(curr_ping_output_func != NULL) { + SHELL_OUTPUT(output, "Timeout\n"); + curr_ping_output_func = NULL; + } else { + SHELL_OUTPUT(output, "Received ping reply from "); + shell_output_6addr(output, &remote_addr); + SHELL_OUTPUT(output, ", len %u, ttl %u, delay %lu ms\n", + curr_ping_datalen, curr_ping_ttl, (1000*(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND); + } + + PT_END(pt); +} #endif /* NETSTACK_CONF_WITH_IPV6 */ + #if ROUTING_CONF_RPL_LITE /*---------------------------------------------------------------------------*/ static const char * @@ -222,65 +279,18 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } -#endif /* ROUTING_CONF_RPL_LITE */ -#if NETSTACK_CONF_WITH_IPV6 -/*---------------------------------------------------------------------------*/ -static void -echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) -{ - if(curr_ping_output_func != NULL) { - curr_ping_output_func = NULL; - curr_ping_ttl = ttl; - curr_ping_datalen = datalen; - process_poll(curr_ping_process); - } -} /*---------------------------------------------------------------------------*/ static -PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args)) +PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args)) { - static uip_ipaddr_t remote_addr; - static struct etimer timeout_timer; - char *next_args; - PT_BEGIN(pt); - SHELL_ARGS_INIT(args, next_args); - - /* Get argument (remote IPv6) */ - SHELL_ARGS_NEXT(args, next_args); - if(args == NULL) { - SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n"); - PT_EXIT(pt); - } else if(uiplib_ipaddrconv(args, &remote_addr) == 0) { - SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args); - PT_EXIT(pt); - } - - SHELL_OUTPUT(output, "Pinging "); - shell_output_6addr(output, &remote_addr); - SHELL_OUTPUT(output, "\n"); - - /* Send ping request */ - curr_ping_process = PROCESS_CURRENT(); - curr_ping_output_func = output; - etimer_set(&timeout_timer, PING_TIMEOUT); - uip_icmp6_send(&remote_addr, ICMP6_ECHO_REQUEST, 0, 4); - PT_WAIT_UNTIL(pt, curr_ping_output_func == NULL || etimer_expired(&timeout_timer)); - - if(curr_ping_output_func != NULL) { - SHELL_OUTPUT(output, "Timeout\n"); - curr_ping_output_func = NULL; - } else { - SHELL_OUTPUT(output, "Received ping reply from "); - shell_output_6addr(output, &remote_addr); - SHELL_OUTPUT(output, ", len %u, ttl %u, delay %lu ms\n", - curr_ping_datalen, curr_ping_ttl, (1000*(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND); - } + SHELL_OUTPUT(output, "Triggering routes refresh\n"); + rpl_refresh_routes("Shell"); PT_END(pt); } -#endif /* NETSTACK_CONF_WITH_IPV6 */ +#endif /* ROUTING_CONF_RPL_LITE */ /*---------------------------------------------------------------------------*/ static void shell_output_log_levels(shell_output_func output) @@ -449,19 +459,6 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar PT_END(pt); } -/*---------------------------------------------------------------------------*/ -#if ROUTING_CONF_RPL_LITE -static -PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args)) -{ - PT_BEGIN(pt); - - SHELL_OUTPUT(output, "Triggering routes refresh\n"); - rpl_refresh_routes("Shell"); - - PT_END(pt); -} -#endif /* ROUTING_CONF_RPL_LITE */ #endif /* UIP_CONF_IPV6_RPL */ /*---------------------------------------------------------------------------*/ static @@ -875,22 +872,18 @@ const struct shell_command_t builtin_shell_commands[] = { { "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" }, { "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" }, { "ping", cmd_ping, "'> ping addr': Pings the IPv6 address 'addr'" }, + { "routes", cmd_routes, "'> routes': Shows the route entries" }, #endif /* NETSTACK_CONF_WITH_IPV6 */ #if UIP_CONF_IPV6_RPL { "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix can be optionally specified." }, { "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" }, #if ROUTING_CONF_RPL_LITE { "rpl-refresh-routes", cmd_rpl_refresh_routes, "'> rpl-refresh-routes': Refreshes all routes through a DTSN increment" }, -#endif /* ROUTING_CONF_RPL_LITE */ - { "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" }, -#endif /* UIP_CONF_IPV6_RPL */ -#if ROUTING_CONF_RPL_LITE { "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" }, { "rpl-nbr", cmd_rpl_nbr, "'> rpl-nbr': Shows the RPL neighbor table" }, #endif /* ROUTING_CONF_RPL_LITE */ -#if NETSTACK_CONF_WITH_IPV6 - { "routes", cmd_routes, "'> routes': Shows the route entries" }, -#endif /* NETSTACK_CONF_WITH_IPV6 */ + { "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" }, +#endif /* UIP_CONF_IPV6_RPL */ #if MAC_CONF_WITH_TSCH { "tsch-set-coordinator", cmd_tsch_set_coordinator, "'> tsch-set-coordinator 0/1 [0/1]': Sets node as coordinator (1) or not (0). Second, optional parameter: enable (1) or disable (0) security." }, { "tsch-schedule", cmd_tsch_schedule, "'> tsch-schedule': Shows the current TSCH schedule" }, From 67e3b455cd9a023b09acd9da6bab15ca85116a63 Mon Sep 17 00:00:00 2001 From: Zhitao He Date: Mon, 14 Jan 2019 15:27:43 +0100 Subject: [PATCH 170/184] correct time intervals of example CoAP periodic resources: one second = 1000 x 1 ms coap timer ticks, not CLOCK_SECOND ticks --- examples/coap/coap-example-server/resources/res-push.c | 2 +- examples/coap/coap-example-server/resources/res-temperature.c | 2 +- examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c | 2 +- .../coap/coap-plugtest-server/resources/res-plugtest-separate.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/coap/coap-example-server/resources/res-push.c b/examples/coap/coap-example-server/resources/res-push.c index ffc8c9c07..3056f3a0d 100644 --- a/examples/coap/coap-example-server/resources/res-push.c +++ b/examples/coap/coap-example-server/resources/res-push.c @@ -50,7 +50,7 @@ PERIODIC_RESOURCE(res_push, NULL, NULL, NULL, - 5 * CLOCK_SECOND, + 5000, res_periodic_handler); /* diff --git a/examples/coap/coap-example-server/resources/res-temperature.c b/examples/coap/coap-example-server/resources/res-temperature.c index ac34dbe33..5616924a6 100644 --- a/examples/coap/coap-example-server/resources/res-temperature.c +++ b/examples/coap/coap-example-server/resources/res-temperature.c @@ -66,7 +66,7 @@ PERIODIC_RESOURCE(res_temperature, NULL, NULL, NULL, - CLOCK_SECOND, + 1000, res_periodic_handler); static void diff --git a/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c index 7d191e751..3200d1d88 100644 --- a/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-obs.c @@ -58,7 +58,7 @@ PERIODIC_RESOURCE(res_plugtest_obs, NULL, res_put_handler, res_delete_handler, - 5 * CLOCK_SECOND, + 5000, res_periodic_handler); static int32_t obs_counter = 0; diff --git a/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c b/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c index c0ae81d11..bbcfc9d77 100644 --- a/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c +++ b/examples/coap/coap-plugtest-server/resources/res-plugtest-separate.c @@ -57,7 +57,7 @@ PERIODIC_RESOURCE(res_plugtest_separate, NULL, NULL, NULL, - 3 * CLOCK_SECOND, + 3000, res_resume_handler); /* A structure to store the required information */ From f35a7a2f36bc73a0170b66b3b70b1d8c1d3f35f8 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 11 Jan 2019 15:38:43 +0000 Subject: [PATCH 171/184] add back z1 platform --- arch/platform/z1/Makefile.common | 145 +++++++ arch/platform/z1/Makefile.z1 | 11 + arch/platform/z1/Makefile.z1sp | 6 + arch/platform/z1/README.z1sp | 9 + arch/platform/z1/apps/burn-nodeid.c | 83 ++++ arch/platform/z1/cfs-coffee-arch.h | 86 ++++ arch/platform/z1/contiki-conf.h | 72 ++++ arch/platform/z1/contiki-z1-platform.c | 41 ++ arch/platform/z1/dev/adxl345.c | 411 ++++++++++++++++++++ arch/platform/z1/dev/adxl345.h | 246 ++++++++++++ arch/platform/z1/dev/battery-sensor.c | 67 ++++ arch/platform/z1/dev/button-sensor.c | 101 +++++ arch/platform/z1/dev/cc2420-arch.c | 76 ++++ arch/platform/z1/dev/i2cmaster.c | 228 +++++++++++ arch/platform/z1/dev/i2cmaster.h | 65 ++++ arch/platform/z1/dev/light-sensor.c | 89 +++++ arch/platform/z1/dev/light-sensor.h | 50 +++ arch/platform/z1/dev/light-ziglet.c | 219 +++++++++++ arch/platform/z1/dev/light-ziglet.h | 123 ++++++ arch/platform/z1/dev/potentiometer-sensor.c | 67 ++++ arch/platform/z1/dev/potentiometer-sensor.h | 46 +++ arch/platform/z1/dev/reed-sensor.c | 122 ++++++ arch/platform/z1/dev/reed-sensor.h | 76 ++++ arch/platform/z1/dev/relay-phidget.c | 105 +++++ arch/platform/z1/dev/relay-phidget.h | 49 +++ arch/platform/z1/dev/sht11-arch.h | 63 +++ arch/platform/z1/dev/sht25.c | 134 +++++++ arch/platform/z1/dev/sht25.h | 71 ++++ arch/platform/z1/dev/sky-sensors.c | 152 ++++++++ arch/platform/z1/dev/sky-sensors.h | 46 +++ arch/platform/z1/dev/temperature-sensor.c | 70 ++++ arch/platform/z1/dev/temperature-sensor.h | 49 +++ arch/platform/z1/dev/tlc59116.c | 185 +++++++++ arch/platform/z1/dev/tlc59116.h | 142 +++++++ arch/platform/z1/dev/tmp102.c | 193 +++++++++ arch/platform/z1/dev/tmp102.h | 79 ++++ arch/platform/z1/dev/xmem.c | 256 ++++++++++++ arch/platform/z1/dev/z1-phidgets.c | 153 ++++++++ arch/platform/z1/dev/z1-phidgets.h | 49 +++ arch/platform/z1/dev/z1-sensors.c | 47 +++ arch/platform/z1/node-id-z1.c | 74 ++++ arch/platform/z1/node-id-z1.h | 43 ++ arch/platform/z1/platform.c | 292 ++++++++++++++ arch/platform/z1/z1-def.h | 287 ++++++++++++++ 44 files changed, 4978 insertions(+) create mode 100644 arch/platform/z1/Makefile.common create mode 100644 arch/platform/z1/Makefile.z1 create mode 100644 arch/platform/z1/Makefile.z1sp create mode 100644 arch/platform/z1/README.z1sp create mode 100644 arch/platform/z1/apps/burn-nodeid.c create mode 100644 arch/platform/z1/cfs-coffee-arch.h create mode 100644 arch/platform/z1/contiki-conf.h create mode 100644 arch/platform/z1/contiki-z1-platform.c create mode 100644 arch/platform/z1/dev/adxl345.c create mode 100644 arch/platform/z1/dev/adxl345.h create mode 100644 arch/platform/z1/dev/battery-sensor.c create mode 100644 arch/platform/z1/dev/button-sensor.c create mode 100644 arch/platform/z1/dev/cc2420-arch.c create mode 100644 arch/platform/z1/dev/i2cmaster.c create mode 100644 arch/platform/z1/dev/i2cmaster.h create mode 100644 arch/platform/z1/dev/light-sensor.c create mode 100644 arch/platform/z1/dev/light-sensor.h create mode 100644 arch/platform/z1/dev/light-ziglet.c create mode 100644 arch/platform/z1/dev/light-ziglet.h create mode 100644 arch/platform/z1/dev/potentiometer-sensor.c create mode 100644 arch/platform/z1/dev/potentiometer-sensor.h create mode 100644 arch/platform/z1/dev/reed-sensor.c create mode 100644 arch/platform/z1/dev/reed-sensor.h create mode 100644 arch/platform/z1/dev/relay-phidget.c create mode 100644 arch/platform/z1/dev/relay-phidget.h create mode 100644 arch/platform/z1/dev/sht11-arch.h create mode 100644 arch/platform/z1/dev/sht25.c create mode 100644 arch/platform/z1/dev/sht25.h create mode 100644 arch/platform/z1/dev/sky-sensors.c create mode 100644 arch/platform/z1/dev/sky-sensors.h create mode 100644 arch/platform/z1/dev/temperature-sensor.c create mode 100644 arch/platform/z1/dev/temperature-sensor.h create mode 100644 arch/platform/z1/dev/tlc59116.c create mode 100644 arch/platform/z1/dev/tlc59116.h create mode 100644 arch/platform/z1/dev/tmp102.c create mode 100644 arch/platform/z1/dev/tmp102.h create mode 100644 arch/platform/z1/dev/xmem.c create mode 100644 arch/platform/z1/dev/z1-phidgets.c create mode 100644 arch/platform/z1/dev/z1-phidgets.h create mode 100644 arch/platform/z1/dev/z1-sensors.c create mode 100644 arch/platform/z1/node-id-z1.c create mode 100644 arch/platform/z1/node-id-z1.h create mode 100644 arch/platform/z1/platform.c create mode 100644 arch/platform/z1/z1-def.h diff --git a/arch/platform/z1/Makefile.common b/arch/platform/z1/Makefile.common new file mode 100644 index 000000000..42172022b --- /dev/null +++ b/arch/platform/z1/Makefile.common @@ -0,0 +1,145 @@ + +# +# Currently enabling SMALL breaks the build on this platform. +# No large effect is expected anyway: unused sections are discarded even if SMALL is not set. +# +SMALL=0 + +ARCH = leds.c xmem.c i2cmaster.c \ + spi-legacy.c cc2420.c cc2420-arch.c cc2420-arch-sfd.c\ + node-id-z1.c sensors.c button-sensor.c cfs-coffee.c \ + uart0.c uart0-putchar.c uip-ipchksum.c \ + slip.c slip_uart0.c z1-sensors.c adxl345.c temperature-sensor.c \ + z1-phidgets.c light-sensor.c battery-sensor.c sky-sensors.c tmp102.c \ + platform.c + +CONTIKI_TARGET_DIRS = . dev apps +ifndef CONTIKI_TARGET_MAIN +CONTIKI_TARGET_MAIN = contiki-main.c +endif + +CONTIKI_TARGET_SOURCEFILES += $(ARCH) + +MCU=msp430f2617 +CPU_HAS_MSP430X=1 + +LDFLAGS += -Wl,--defsym -Wl,__P1SEL2=0x0041 -Wl,--defsym -Wl,__P5SEL2=0x0045 + +ifdef nodemac +CFLAGS += -DMACID=$(nodemac) +endif + +CFLAGS += -g + +include $(ARCH_PATH)/cpu/msp430/Makefile.msp430 + + +NUMPAR=20 +IHEXFILE=tmpimage.ihex + +ifeq ($(HOST_OS),Darwin) + ifndef MOTELIST + USBDEVPREFIX= + SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux + MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia-macos + BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1 + BSL_FILETYPE = -I + MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \ + cut -f 2 -d ,) + REFNUM = $(shell $(MOTELIST) -c 2>&- | \ + cut -f 1 -d , | tail -c5 | sed 's/^0*//') + ifneq (,$(REFNUM)) + # No device fo-und + ifeq (,$(findstring und, $(REFNUM))) + CFLAGS += -DSERIALNUM=$(REFNUM:0%=%) + endif + endif + endif +else + # If we are not running under Mac, we assume Linux + ifndef MOTELIST + USBDEVPREFIX= + SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux + MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia + BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1 + BSL_FILETYPE = -I + MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \ + cut -f 2 -d , | \ + perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') + CMOTES=$(MOTES) + REFNUM = $(shell $(MOTELIST) -c 2>&- | \ + cut -f 1 -d , | tail -c5 | sed 's/^0*//') + ifneq (,$(REFNUM)) + # No device fo-und + ifeq (,$(findstring und, $(REFNUM))) + CFLAGS += -DSERIALNUM=$(REFNUM) + endif + endif + endif +endif + +motelist: + $(MOTELIST) +z1-motelist: + $(MOTELIST) -b z1 +z1-motes: + @echo $(MOTES) + +ifdef MOTE +%.upload: %.ihex + cp $< $(IHEXFILE) + $(MAKE) z1-u.$(subst /,-,$(word $(MOTE), $(MOTES))) +else # MOTE +%.upload: %.ihex + cp $< $(IHEXFILE) + @echo $(MOTES) + $(MAKE) z1-reset z1-upload +endif # MOTE + +z1-upload: z1-reset + $(MAKE) -j $(NUMPAR) z1-upload-sequence + +z1-upload-sequence: $(foreach PORT, $(MOTES), z1-u.$(subst /,-,$(PORT))) + @echo Done + +z1-reset: + $(MAKE) -k -j $(NUMPAR) z1-reset-sequence + +z1-reset-sequence: $(foreach PORT, $(MOTES), z1-r.$(subst /,-,$(PORT))) + @echo Done + +z1-u.%: + @echo +++++ Erasing $(subst -,/,$*); \ + $(BSL) -c $(subst -,/,$*) -e && sleep 2 ; \ + echo +++++ Programming $(subst -,/,$*) ; \ + $(BSL) -c $(subst -,/,$*) $(BSL_FILETYPE) -p $(IHEXFILE) && sleep 2 ; \ + echo +++++ Resetting $(subst -,/,$*) ; \ + $(BSL) -c $(subst -,/,$*) -r + +z1-r.%: + $(BSL) -c $(subst -,/,$*) -r + +sizeplot: + msp430-size $(OBJECTDIR)/*.o | $(CONTIKI)/tools/sky/check-size > size-data + gnuplot $(CONTIKI)/tools/sky/plot-size + gv size.pdf + +winslip: +ifdef INTERFACE + $(CONTIKI)/tools/wpcapslip/wpcapslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) $(INTERFACE) 172.16.0.0 255.255.0.0 +else + @echo "Usage: \"$(MAKE) $@ INTERFACE=\"" + @echo "Use the \"ipconfig\" command to find out the IP addresses of the local interfaces" +endif + +linslip: $(CONTIKI)/tools/tunslip + $(CONTIKI)/tools/tunslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) 172.16.0.0 255.255.0.0 + +$(CONTIKI)/tools/tunslip: + (cd $(CONTIKI)/tools; $(MAKE) tunslip) + +ifdef MOTE + PORT = $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) +else + PORT = $(USBDEVPREFIX)$(firstword $(CMOTES)) +endif diff --git a/arch/platform/z1/Makefile.z1 b/arch/platform/z1/Makefile.z1 new file mode 100644 index 000000000..aeff61bf2 --- /dev/null +++ b/arch/platform/z1/Makefile.z1 @@ -0,0 +1,11 @@ +# Common Makefile between Z1 and Z1SP + +CONTIKI_TARGET_SOURCEFILES += contiki-z1-platform.c + +include $(ARCH_PATH)/platform/z1/Makefile.common + +ifeq ($(ZOLERTIA_Z1SP),1) +include $(ARCH_PATH)/platform/z1/Makefile.z1sp +endif + +MODULES += arch/dev/cc2420 os/storage/cfs diff --git a/arch/platform/z1/Makefile.z1sp b/arch/platform/z1/Makefile.z1sp new file mode 100644 index 000000000..29b8fcbd1 --- /dev/null +++ b/arch/platform/z1/Makefile.z1sp @@ -0,0 +1,6 @@ +# Makefile for Z1 Starter Platform + +# This is the actual flag we need to include specific Z1SP components +CFLAGS += -DZ1_IS_Z1SP + +CONTIKI_TARGET_SOURCEFILES += potentiometer-sensor.c diff --git a/arch/platform/z1/README.z1sp b/arch/platform/z1/README.z1sp new file mode 100644 index 000000000..8db1e48da --- /dev/null +++ b/arch/platform/z1/README.z1sp @@ -0,0 +1,9 @@ +Using the Z1 starter platform (Z1SP) +============================================ + +To enable the Z1SP components, you should include in your application Makefile +the ZOLERTIA_Z1SP flag set to 1, see "examples/z1/Makefile". + +For Z1SP specific information please go to: + +http://zolertia.sourceforge.net/wiki/index.php/Mainpage:z1sp diff --git a/arch/platform/z1/apps/burn-nodeid.c b/arch/platform/z1/apps/burn-nodeid.c new file mode 100644 index 000000000..0f469cac4 --- /dev/null +++ b/arch/platform/z1/apps/burn-nodeid.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2006, 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. + * + */ + +/** + * \file + * A program for burning a node ID into the flash ROM of a Tmote Sky node. + * \author + * Adam Dunkels + */ + +#include "dev/leds.h" +#include "dev/watchdog.h" +#include "sys/node-id.h" +#include "contiki.h" +#include "sys/etimer.h" + +#include "node-id-z1.h" + +#include + +static struct etimer etimer; + +PROCESS(burn_process, "Burn node id"); +AUTOSTART_PROCESSES(&burn_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(burn_process, ev, data) +{ + PROCESS_BEGIN(); + + etimer_set(&etimer, 5*CLOCK_SECOND); + PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); + + watchdog_stop(); + leds_on(LEDS_RED); +#if NODEID + #warning "***** BURNING NODE ID" + printf("Burning node id %d\n", NODEID); + node_id_burn(NODEID); + leds_on(LEDS_BLUE); + node_id_restore(); + printf("Restored node id %d\n", node_id); +#else +#error "burn-nodeid must be compiled with nodeid=" + node_id_restore(); + printf("Restored node id %d\n", node_id); +#endif + leds_off(LEDS_RED + LEDS_BLUE); + watchdog_start(); + while(1) { + PROCESS_WAIT_EVENT(); + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/cfs-coffee-arch.h b/arch/platform/z1/cfs-coffee-arch.h new file mode 100644 index 000000000..3225e2f32 --- /dev/null +++ b/arch/platform/z1/cfs-coffee-arch.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008, 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. + * + */ + +/** + * \file + * Coffee architecture-dependent header for the Zolertia Z1 platform. + * \author + * Nicolas Tsiftes + * Enric M. Calvo + */ + +#ifndef CFS_COFFEE_ARCH_H +#define CFS_COFFEE_ARCH_H + +#include "contiki-conf.h" +#include "dev/xmem.h" + +/*** M25P16 Memory Organization +The memory is organized as: +16Mbit = 2 097 152 bytes (8 bits each) +32 sectors (512 Kbits, 65536 bytes each) +8192 pages (256 bytes each). +Each page can be individually programmed (bits are programmed from 1 to 0). The device is +sector or bulk erasable (bits are erased from 0 to 1) but not page erasable +*/ + +/* Total size of the External Flash Memory in the Z1 */ +#define COFFEE_XMEM_TOTAL_SIZE_KB 2048UL + +/* Coffee configuration parameters. */ +#define COFFEE_SECTOR_SIZE 65536UL +#define COFFEE_PAGE_SIZE 256UL +#define COFFEE_START COFFEE_SECTOR_SIZE +#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START) +#define COFFEE_NAME_LENGTH 16 +#define COFFEE_MAX_OPEN_FILES 6 +#define COFFEE_FD_SET_SIZE 8 +#define COFFEE_LOG_TABLE_LIMIT 256 +#define COFFEE_DYN_SIZE 4*1024 +#define COFFEE_LOG_SIZE 1024 + +#define COFFEE_MICRO_LOGS 1 + +/* Flash operations. */ +#define COFFEE_WRITE(buf, size, offset) \ + xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) + +#define COFFEE_READ(buf, size, offset) \ + xmem_pread((char *)(buf), (size), COFFEE_START + (offset)) + +#define COFFEE_ERASE(sector) \ + xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) + +/* Coffee types. */ +typedef int16_t coffee_page_t; + +#endif /* !CFS_COFFEE_ARCH_H */ diff --git a/arch/platform/z1/contiki-conf.h b/arch/platform/z1/contiki-conf.h new file mode 100644 index 000000000..e31a9fbcd --- /dev/null +++ b/arch/platform/z1/contiki-conf.h @@ -0,0 +1,72 @@ +#ifndef CONTIKI_CONF_H +#define CONTIKI_CONF_H + +/* include the project config */ +#ifdef PROJECT_CONF_PATH +#include PROJECT_CONF_PATH +#endif /* PROJECT_CONF_PATH */ +/*---------------------------------------------------------------------------*/ +#include "z1-def.h" +#include "msp430-def.h" +/*---------------------------------------------------------------------------*/ + +/* Configure radio driver */ +#ifndef NETSTACK_CONF_RADIO +#define NETSTACK_CONF_RADIO cc2420_driver +#endif /* NETSTACK_CONF_RADIO */ + +/* Symbol for the TSCH 15ms timeslot timing template */ +#define TSCH_CONF_ARCH_HDR_PATH "dev/cc2420/cc2420-tsch-15ms.h" + +/* The TSCH default slot length of 10ms is a bit too short for this platform, + * use 15ms instead. */ +#ifndef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_15000 +#endif /* TSCH_CONF_DEFAULT_TIMESLOT_TIMING */ + +/* Save RAM through a smaller uIP buffer */ +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 140 +#endif + +#define PROCESS_CONF_NUMEVENTS 8 +#define PROCESS_CONF_STATS 1 +/*#define PROCESS_CONF_FASTPOLL 4*/ + +/* So far, printfs without interrupt. */ +#define UART0_CONF_TX_WITH_INTERRUPT 0 +/* This does not work in Cooja. */ +#define UART0_CONF_RX_WITH_DMA 0 + +/* Handle 10 neighbors */ +#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS +#define NBR_TABLE_CONF_MAX_NEIGHBORS 10 +#endif + +/* Handle 10 routes */ +#ifndef NETSTACK_MAX_ROUTE_ENTRIES +#define NETSTACK_MAX_ROUTE_ENTRIES 10 +#endif + +/* Handle 10 links */ +#ifndef TSCH_SCHEDULE_CONF_MAX_LINKS +#define TSCH_SCHEDULE_CONF_MAX_LINKS 10 +#endif + +#ifndef TSCH_CONF_MAX_INCOMING_PACKETS +#define TSCH_CONF_MAX_INCOMING_PACKETS 2 +#endif + +#ifndef TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR +#define TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR 4 +#endif + +/* Platform-specific (H/W) AES implementation */ +#ifndef AES_128_CONF +#define AES_128_CONF cc2420_aes_128_driver +#endif /* AES_128_CONF */ + +/*---------------------------------------------------------------------------*/ +#include "msp430-conf.h" +/*---------------------------------------------------------------------------*/ +#endif /* CONTIKI_CONF_H */ diff --git a/arch/platform/z1/contiki-z1-platform.c b/arch/platform/z1/contiki-z1-platform.c new file mode 100644 index 000000000..60272bb00 --- /dev/null +++ b/arch/platform/z1/contiki-z1-platform.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL + * 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. + * + * + * Author: Enric M. Calvo based on previous work by + * Niclas Finne , Joakim Eriksson + * + */ + +#include "dev/button-sensor.h" + +void +init_platform(void) +{ + process_start(&sensors_process, NULL); +} diff --git a/arch/platform/z1/dev/adxl345.c b/arch/platform/z1/dev/adxl345.c new file mode 100644 index 000000000..08e170432 --- /dev/null +++ b/arch/platform/z1/dev/adxl345.c @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * Copyright (c) 2016, Zolertia + * 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 + * Device drivers for adxl345 accelerometer in Zolertia Z1. + * \author + * Marcus Lundén, SICS + * Enric M. Calvo, Zolertia + * Antonio Lignan, Zolertia + */ +/*---------------------------------------------------------------------------*/ +#include +#include "contiki.h" +#include "adxl345.h" +#include "cc2420.h" +#include "i2cmaster.h" +#include "isr_compat.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +static uint8_t enabled; +/*---------------------------------------------------------------------------*/ +/* Callback pointers when interrupt occurs */ +void (*accm_int1_cb)(uint8_t reg); +void (*accm_int2_cb)(uint8_t reg); +/*---------------------------------------------------------------------------*/ +/* Bitmasks for the interrupts */ +static uint16_t int1_mask = 0, int2_mask = 0; + +/* Default values for adxl345 at startup. + * This will be sent to the adxl345 in a + * stream at init to set it up in a default state + */ + +static uint8_t adxl345_default_settings[] = { + /* Note, as the two first two bulks are to be written in a stream, they contain + * the register address as first byte in that section. + * 0--14 are in one stream, start at ADXL345_THRESH_TAP + */ + /* XXX NB Register address, not register value!! */ + ADXL345_THRESH_TAP, + ADXL345_THRESH_TAP_DEFAULT, + ADXL345_OFSX_DEFAULT, + ADXL345_OFSY_DEFAULT, + ADXL345_OFSZ_DEFAULT, + ADXL345_DUR_DEFAULT, + ADXL345_LATENT_DEFAULT, + ADXL345_WINDOW_DEFAULT, + ADXL345_THRESH_ACT_DEFAULT, + ADXL345_THRESH_INACT_DEFAULT, + ADXL345_TIME_INACT_DEFAULT, + ADXL345_ACT_INACT_CTL_DEFAULT, + ADXL345_THRESH_FF_DEFAULT, + ADXL345_TIME_FF_DEFAULT, + ADXL345_TAP_AXES_DEFAULT, + + /* 15--19 start at ADXL345_BW_RATE */ + /* XXX NB Register address, not register value!! */ + ADXL345_BW_RATE, + ADXL345_BW_RATE_DEFAULT, + ADXL345_POWER_CTL_DEFAULT, + ADXL345_INT_ENABLE_DEFAULT, + ADXL345_INT_MAP_DEFAULT, + + /* These two: 20, 21 write separately */ + ADXL345_DATA_FORMAT_DEFAULT, + ADXL345_FIFO_CTL_DEFAULT +}; +/*---------------------------------------------------------------------------*/ +PROCESS(accmeter_process, "Accelerometer process"); +/*---------------------------------------------------------------------------*/ +static void +accm_write_reg(uint8_t reg, uint8_t val) +{ + uint8_t tx_buf[] = {reg, val}; + + i2c_transmitinit(ADXL345_ADDR); + while (i2c_busy()); + PRINTF("ADXL345: I2C Ready to TX\n"); + + i2c_transmit_n(2, tx_buf); + while (i2c_busy()); + PRINTF("ADXL345: WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg); +} +/*---------------------------------------------------------------------------*/ +/* First byte in stream must be the register address to begin writing to. + * The data is then written from second byte and increasing. + */ +static void +accm_write_stream(uint8_t len, uint8_t *data) +{ + i2c_transmitinit(ADXL345_ADDR); + while (i2c_busy()); + PRINTF("ADXL345: I2C Ready to TX(stream)\n"); + + i2c_transmit_n(len, data); // start tx and send conf reg + while (i2c_busy()); + PRINTF("ADXL345: WRITE_STR %u B to 0x%02X\n", len, data[0]); +} + +/*---------------------------------------------------------------------------*/ +static uint8_t +accm_read_reg(uint8_t reg) +{ + uint8_t retVal = 0; + uint8_t rtx = reg; + PRINTF("ADXL345: READ_REG 0x%02X\n", reg); + + /* transmit the register to read */ + i2c_transmitinit(ADXL345_ADDR); + while (i2c_busy()); + i2c_transmit_n(1, &rtx); + while (i2c_busy()); + + /* receive the data */ + i2c_receiveinit(ADXL345_ADDR); + while (i2c_busy()); + i2c_receive_n(1, &retVal); + while (i2c_busy()); + + return retVal; +} +/*---------------------------------------------------------------------------*/ +static void +accm_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto) +{ + uint8_t rtx = reg; + PRINTF("ADXL345: READ_STR %u B from 0x%02X\n", len, reg); + + /* transmit the register to start reading from */ + i2c_transmitinit(ADXL345_ADDR); + while (i2c_busy()); + i2c_transmit_n(1, &rtx); + while (i2c_busy()); + + /* receive the data */ + i2c_receiveinit(ADXL345_ADDR); + while (i2c_busy()); + i2c_receive_n(len, whereto); + while (i2c_busy()); +} + +/*---------------------------------------------------------------------------*/ +/* Read an axis of the accelerometer (x, y or z). Return value is a signed + * 10 bit int. + * The resolution of the acceleration measurement can be increased up to 13 bit, + * but will change the data format of this read out. Refer to the data sheet if + * so is wanted/needed. + */ +int16_t +accm_read_axis(enum ADXL345_AXIS axis) +{ + int16_t rd = 0; + uint8_t tmp[2]; + if(axis > Z_AXIS){ + return 0; + } + accm_read_stream(ADXL345_DATAX0 + axis, 2, &tmp[0]); + rd = (int16_t)(tmp[0] | (tmp[1]<<8)); + return rd; +} +/*---------------------------------------------------------------------------*/ +int +accm_set_grange(uint8_t grange) +{ + uint8_t tempreg = 0; + + if(grange > ADXL345_RANGE_16G) { + PRINTF("ADXL345: grange invalid: %u\n", grange); + return ADXL345_ERROR; + } + + if(!enabled) { + return ADXL345_ERROR; + } + + /* Keep the previous contents of the register, zero out the last two bits */ + tempreg = (accm_read_reg(ADXL345_DATA_FORMAT) & 0xFC); + tempreg |= grange; + accm_write_reg(ADXL345_DATA_FORMAT, tempreg); + return ADXL345_SUCCESS; +} + +/*---------------------------------------------------------------------------*/ +void +accm_init(void) +{ + PRINTF("ADXL345: init\n"); + accm_int1_cb = NULL; + accm_int2_cb = NULL; + + /* Set up ports and pins for interrups. */ + ADXL345_DIR &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN); + ADXL345_SEL &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN); + ADXL345_SEL2 &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN); + + /* Set up ports and pins for I2C communication */ + i2c_enable(); + + /* set default register values. */ + accm_write_stream(15, &adxl345_default_settings[0]); + accm_write_stream(5, &adxl345_default_settings[15]); + accm_write_reg(ADXL345_DATA_FORMAT, adxl345_default_settings[20]); + accm_write_reg(ADXL345_FIFO_CTL, adxl345_default_settings[21]); + + process_start(&accmeter_process, NULL); + + /* Enable msp430 interrupts on the two interrupt pins. */ + dint(); + /* low to high transition interrupts */ + ADXL345_IES &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN); + /* enable interrupts */ + ADXL345_IE |= (ADXL345_INT1_PIN | ADXL345_INT2_PIN); + eint(); + + enabled = 1; +} +/*---------------------------------------------------------------------------*/ +void +accm_stop(void) +{ + dint(); + ADXL345_IE &= ~(ADXL345_INT1_PIN | ADXL345_INT2_PIN); + accm_write_reg(ADXL345_INT_ENABLE, ~(int1_mask | int2_mask)); + accm_write_reg(ADXL345_INT_MAP, ~int2_mask); + eint(); + enabled = 0; +} +/*---------------------------------------------------------------------------*/ +int +accm_set_irq(uint8_t int1, uint8_t int2) +{ + if(!enabled) { + return ADXL345_ERROR; + } + + /* Set the corresponding interrupt mapping to INT1 or INT2 */ + PRINTF("ADXL345: IRQs set to INT1: 0x%02X IRQ2: 0x%02X\n", int1, int2); + + int1_mask = int1; + int2_mask = int2; + + accm_write_reg(ADXL345_INT_ENABLE, (int1 | int2)); + /* int1 bits are zeroes in the map register so this is for both ints */ + accm_write_reg(ADXL345_INT_MAP, int2); + return ADXL345_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +/* Invoked after an interrupt happened. Reads the interrupt source reg at the + * accelerometer, which resets the interrupts, and invokes the corresponding + * callback. It passes the source register value so the callback can determine + * what interrupt happened, if several interrupts are mapped to the same pin. + */ +static void +poll_handler(void) +{ + uint8_t ireg = 0; + ireg = accm_read_reg(ADXL345_INT_SOURCE); + + /* Invoke callbacks for the corresponding interrupts */ + if(ireg & int1_mask){ + if(accm_int1_cb != NULL){ + PRINTF("ADXL345: INT1 cb invoked\n"); + accm_int1_cb(ireg); + } + } else if(ireg & int2_mask){ + if(accm_int2_cb != NULL){ + PRINTF("ADXL345: INT2 cb invoked\n"); + accm_int2_cb(ireg); + } + } +} +/*---------------------------------------------------------------------------*/ +/* This process is sleeping until an interrupt from the accelerometer occurs, + * which polls this process from the interrupt service routine. */ +PROCESS_THREAD(accmeter_process, ev, data) +{ + PROCESS_POLLHANDLER(poll_handler()); + PROCESS_EXITHANDLER(); + PROCESS_BEGIN(); + while(1){ + PROCESS_WAIT_EVENT_UNTIL(0); + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/* This interrupt vector is shared with the interrupts from CC2420, so that + * was moved here + */ +static struct timer suppressTimer1, suppressTimer2; + +ISR(PORT1, port1_isr) +{ + /* ADXL345_IFG.x goes high when interrupt occurs, use to check what + * interrupted + */ + if((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){ + /* Check if this should be suppressed or not */ + if(timer_expired(&suppressTimer1)) { + timer_set(&suppressTimer1, SUPPRESS_TIME_INT1); + ADXL345_IFG &= ~ADXL345_INT1_PIN; // clear interrupt flag + process_poll(&accmeter_process); + LPM4_EXIT; + } + } else if((ADXL345_IFG & ADXL345_INT2_PIN) && + !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){ + /* Check if this should be suppressed or not */ + if(timer_expired(&suppressTimer2)) { + timer_set(&suppressTimer2, SUPPRESS_TIME_INT2); + /* clear interrupt flag */ + ADXL345_IFG &= ~ADXL345_INT2_PIN; + process_poll(&accmeter_process); + LPM4_EXIT; + } + } else { + /* CC2420 interrupt */ + if(cc2420_interrupt()) { + LPM4_EXIT; + } + } +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int value) +{ + if(type != SENSORS_ACTIVE) { + return ADXL345_ERROR; + } + + if(value) { + accm_init(); + } else { + accm_stop(); + } + enabled = value; + return ADXL345_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return enabled; + } + return ADXL345_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + if(!enabled) { + return ADXL345_ERROR; + } + + if((type != X_AXIS) && (type != Y_AXIS) && (type != Z_AXIS)) { + return ADXL345_ERROR; + } + + switch(type) { + case X_AXIS: + return accm_read_axis(X_AXIS); + case Y_AXIS: + return accm_read_axis(Y_AXIS); + case Z_AXIS: + return accm_read_axis(Z_AXIS); + default: + return ADXL345_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(adxl345, ADXL345_SENSOR, value, configure, status); +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/adxl345.h b/arch/platform/z1/dev/adxl345.h new file mode 100644 index 000000000..a8d4789d8 --- /dev/null +++ b/arch/platform/z1/dev/adxl345.h @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * Copyright (c) 2016, Zolertia + * 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 + * Device drivers header file for adxl345 accelerometer in Zolertia Z1. + * \author + * Marcus Lundén, SICS + * Enric Calvo, Zolertia + * Antonio Lignan, Zolertia + */ +/*---------------------------------------------------------------------------*/ +#ifndef ADXL345_H_ +#define ADXL345_H_ +#include +#include "dev/i2cmaster.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +/* Used in accm_read_axis(), eg accm_read_axis(X_AXIS) */ +enum ADXL345_AXIS { + X_AXIS = 0, + Y_AXIS = 2, + Z_AXIS = 4, +}; +/* -------------------------------------------------------------------------- */ +/* Init the accelerometer: ports, pins, registers, interrupts (none enabled), + * I2C, default threshold values etc. + */ +void accm_init(void); + +/* Read an axis of the accelerometer (x, y or z). Return value is a signed 10 + * bit int. + * The resolution of the acceleration measurement can be increased up to 13 bit, + * but will change the data format of this read out. Refer to the data sheet if + * so is wanted/needed. + */ +int16_t accm_read_axis(enum ADXL345_AXIS axis); + +/* Sets the g-range, ie the range the accelerometer measures (ie 2g means -2 to + * +2 g on every axis). Possible values: + * - ADXL345_RANGE_2G + * - ADXL345_RANGE_4G + * - ADXL345_RANGE_8G + * - ADXL345_RANGE_16G + */ +int accm_set_grange(uint8_t grange); + +/* Map interrupt (FF, tap, dbltap etc) to interrupt pin (IRQ_INT1, IRQ_INT2). + * This must come after accm_init() as the registers will otherwise be + * overwritten. + */ +int accm_set_irq(uint8_t int1, uint8_t int2); + +/* Macros for setting the pointers to callback functions from the interrupts. + * The function will be called with an uint8_t as parameter, containing the + * interrupt flag register from the ADXL345. That way, several interrupts can be + * mapped to the same pin and be read + */ +#define ACCM_REGISTER_INT1_CB(ptr) accm_int1_cb = ptr; +#define ACCM_REGISTER_INT2_CB(ptr) accm_int2_cb = ptr; +/* -------------------------------------------------------------------------- */ +/* Application definitions, change if required by application. */ + +/* Time after an interrupt that subsequent interrupts are suppressed. Should + * later be turned into one specific time per type of interrupt (tap, freefall. + * etc) + */ +#define SUPPRESS_TIME_INT1 CLOCK_SECOND/4 +#define SUPPRESS_TIME_INT2 CLOCK_SECOND/4 + +/* Suggested defaults according to the data sheet etc */ +#define ADXL345_THRESH_TAP_DEFAULT 0x48 /* 4.5g (0x30 == 3.0g) */ +#define ADXL345_OFSX_DEFAULT 0x00 /* for calibration only */ +#define ADXL345_OFSY_DEFAULT 0x00 +#define ADXL345_OFSZ_DEFAULT 0x00 +#define ADXL345_DUR_DEFAULT 0x20 /* 20 ms (datasheet: 10ms++) */ +#define ADXL345_LATENT_DEFAULT 0x50 /* 100 ms (datasheet: 20ms++) */ +#define ADXL345_WINDOW_DEFAULT 0xFF /* 320 ms (datasheet: 80ms++) */ +#define ADXL345_THRESH_ACT_DEFAULT 0x15 /* 1.3g (62.5 mg/LSB) */ +#define ADXL345_THRESH_INACT_DEFAULT 0x08 /* 0.5g (62.5 mg/LSB) */ +#define ADXL345_TIME_INACT_DEFAULT 0x02 /* 2 s (1 s/LSB) */ +#define ADXL345_ACT_INACT_CTL_DEFAULT 0xFF /* all axis, ac-coupled */ +#define ADXL345_THRESH_FF_DEFAULT 0x09 /* 563 mg */ +#define ADXL345_TIME_FF_DEFAULT 0x20 /* 60 ms */ +#define ADXL345_TAP_AXES_DEFAULT 0x07 /* all axis, no suppression */ + +#define ADXL345_BW_RATE_DEFAULT (0x00 | ADXL345_SRATE_100) /* 100 Hz */ +/* link bit set, no autosleep, start normal measuring */ +#define ADXL345_POWER_CTL_DEFAULT 0x28 +#define ADXL345_INT_ENABLE_DEFAULT 0x00 /* no interrupts enabled */ +#define ADXL345_INT_MAP_DEFAULT 0x00 /* all mapped to int_1 */ + +/* XXX NB: In the data format register, data format of axis readings is chosen + * between left or right justify. This affects the position of the MSB/LSB and is + * different depending on g-range and resolution. If changed, make sure this is + * reflected in the _read_axis() function. Also, the resolution can be increased + * from 10 bit to at most 13 bit, but this also changes position of MSB etc on data + * format so check this in read_axis() too. + */ +/* right-justify, 2g, 10-bit mode, int is active high */ +#define ADXL345_DATA_FORMAT_DEFAULT (0x00 | ADXL345_RANGE_2G) +#define ADXL345_FIFO_CTL_DEFAULT 0x00 /* FIFO bypass mode */ + +/* -------------------------------------------------------------------------- */ +/* Reference definitions, should not be changed */ +/* adxl345 slave address */ +#define ADXL345_ADDR 0x53 + +/* ADXL345 registers */ +#define ADXL345_DEVID 0x00 +/* registers 0x01 to 0x1C are reserved, do not access */ +#define ADXL345_THRESH_TAP 0x1D +#define ADXL345_OFSX 0x1E +#define ADXL345_OFSY 0x1F +#define ADXL345_OFSZ 0x20 +#define ADXL345_DUR 0x21 +#define ADXL345_LATENT 0x22 +#define ADXL345_WINDOW 0x23 +#define ADXL345_THRESH_ACT 0x24 +#define ADXL345_THRESH_INACT 0x25 +#define ADXL345_TIME_INACT 0x26 +#define ADXL345_ACT_INACT_CTL 0x27 +#define ADXL345_THRESH_FF 0x28 +#define ADXL345_TIME_FF 0x29 +#define ADXL345_TAP_AXES 0x2A +#define ADXL345_ACT_TAP_STATUS 0x2B +#define ADXL345_BW_RATE 0x2C +#define ADXL345_POWER_CTL 0x2D +#define ADXL345_INT_ENABLE 0x2E +#define ADXL345_INT_MAP 0x2F +#define ADXL345_INT_SOURCE 0x30 +#define ADXL345_DATA_FORMAT 0x31 +#define ADXL345_DATAX0 0x32 /* read only, LSByte X, two's complement */ +#define ADXL345_DATAX1 0x33 /* read only, MSByte X */ +#define ADXL345_DATAY0 0x34 /* read only, LSByte Y */ +#define ADXL345_DATAY1 0x35 /* read only, MSByte X */ +#define ADXL345_DATAZ0 0x36 /* read only, LSByte Z */ +#define ADXL345_DATAZ1 0x37 /* read only, MSByte X */ +#define ADXL345_FIFO_CTL 0x38 +#define ADXL345_FIFO_STATUS 0x39 /* read only */ + +/* ADXL345 interrupts */ +#define ADXL345_INT_DISABLE 0X00 /* used for disabling interrupts */ +#define ADXL345_INT_OVERRUN 0X01 +#define ADXL345_INT_WATERMARK 0X02 +#define ADXL345_INT_FREEFALL 0X04 +#define ADXL345_INT_INACTIVITY 0X08 +#define ADXL345_INT_ACTIVITY 0X10 +#define ADXL345_INT_DOUBLETAP 0X20 +#define ADXL345_INT_TAP 0X40 +#define ADXL345_INT_DATAREADY 0X80 + +/* Accelerometer hardware ports, pins and registers on the msp430 µC */ +#define ADXL345_DIR P1DIR +#define ADXL345_PIN P1PIN +#define ADXL345_REN P1REN +#define ADXL345_SEL P1SEL +#define ADXL345_SEL2 P1SEL2 +#define ADXL345_INT1_PIN (1<<6) /* P1.6 */ +#define ADXL345_INT2_PIN (1<<7) /* P1.7 */ +#define ADXL345_IES P1IES +#define ADXL345_IE P1IE +#define ADXL345_IFG P1IFG +#define ADXL345_VECTOR PORT1_VECTOR + +/* g-range for DATA_FORMAT register */ +#define ADXL345_RANGE_2G 0x00 +#define ADXL345_RANGE_4G 0x01 +#define ADXL345_RANGE_8G 0x02 +#define ADXL345_RANGE_16G 0x03 + + +/* The adxl345 has programmable sample rates, but unexpected results may occur + * if the wrong rate and I2C bus speed is used (see datasheet p 17). Sample + * rates in Hz. This setting does not change the internal sampling rate, just + * how often it is piped to the output registers (ie the interrupt features use + * the full sample rate internally). + * Example use: + * adxl345_set_reg(ADXL345_BW_RATE, ((_ADXL345_STATUS & LOW_POWER) + * | ADXL345_SRATE_50)); + */ + +/* XXX NB don't use at all as I2C data rate<= 400kHz */ +#define ADXL345_SRATE_3200 0x0F +/* XXX NB don't use at all as I2C data rate<= 400kHz */ +#define ADXL345_SRATE_1600 0x0E +#define ADXL345_SRATE_800 0x0D /* when I2C data rate == 400 kHz */ +#define ADXL345_SRATE_400 0x0C /* when I2C data rate == 400 kHz */ +#define ADXL345_SRATE_200 0x0B /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_100 0x0A /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_50 0x09 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_25 0x08 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_12_5 0x07 /* 12.5 Hz, when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_6_25 0x06 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_3_13 0x05 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_1_56 0x04 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_0_78 0x03 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_0_39 0x02 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_0_20 0x01 /* when I2C data rate >= 100 kHz */ +#define ADXL345_SRATE_0_10 0x00 /* 0.10 Hz, when I2C data rate >= 100 kHz */ +/* -------------------------------------------------------------------------- */ +/* Callback pointers for the interrupts */ +extern void (*accm_int1_cb)(uint8_t reg); +extern void (*accm_int2_cb)(uint8_t reg); +/* -------------------------------------------------------------------------- */ +#define ACCM_INT1 0x01 +#define ACCM_INT2 0x02 +#define ADXL345_SUCCESS 0x00 +#define ADXL345_ERROR (-1) +/* -------------------------------------------------------------------------- */ +#define ADXL345_SENSOR "ADXL345 sensor" +/* -------------------------------------------------------------------------- */ +extern const struct sensors_sensor adxl345; +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +#endif /* ifndef ADXL345_H_ */ diff --git a/arch/platform/z1/dev/battery-sensor.c b/arch/platform/z1/dev/battery-sensor.c new file mode 100644 index 000000000..dd787ccae --- /dev/null +++ b/arch/platform/z1/dev/battery-sensor.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2006, 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2005-11-01 + * Updated : $Date: 2010/08/25 19:30:52 $ + * $Revision: 1.11 $ + */ +#include "contiki.h" +#include "dev/battery-sensor.h" +#include "dev/sky-sensors.h" + +/* Configure ADC12_2 to sample channel 11 (voltage) and use */ +/* the Vref+ as reference (SREF_1) since it is a stable reference */ +#define INPUT_CHANNEL (1 << INCH_11) +#define INPUT_REFERENCE SREF_1 +#define BATTERY_MEM ADC12MEM11 + +const struct sensors_sensor battery_sensor; +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return BATTERY_MEM; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c); +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return sky_sensors_status(INPUT_CHANNEL, type); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status); diff --git a/arch/platform/z1/dev/button-sensor.c b/arch/platform/z1/dev/button-sensor.c new file mode 100644 index 000000000..58479bf3b --- /dev/null +++ b/arch/platform/z1/dev/button-sensor.c @@ -0,0 +1,101 @@ +/* + * 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 "contiki.h" +#include "lib/sensors.h" +#include "dev/hwconf.h" +#include "dev/button-sensor.h" +#include "isr_compat.h" + +const struct sensors_sensor button_sensor; + +static struct timer debouncetimer; +static int status(int type); + +HWCONF_PIN(BUTTON, 2, 5); +HWCONF_IRQ(BUTTON, 2, 5); + +/*---------------------------------------------------------------------------*/ +ISR(PORT2, irq_p2) +{ + if(BUTTON_CHECK_IRQ()) { + if(timer_expired(&debouncetimer)) { + timer_set(&debouncetimer, CLOCK_SECOND / 4); + sensors_changed(&button_sensor); + LPM4_EXIT; + } + } + P2IFG = 0x00; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return BUTTON_READ() || !timer_expired(&debouncetimer); +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch (type) { + case SENSORS_ACTIVE: + if (c) { + if(!status(SENSORS_ACTIVE)) { + timer_set(&debouncetimer, 0); + BUTTON_IRQ_EDGE_SELECTD(); + + BUTTON_SELECT(); + BUTTON_MAKE_INPUT(); + + BUTTON_ENABLE_IRQ(); + } + } else { + BUTTON_DISABLE_IRQ(); + } + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch (type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return BUTTON_IRQ_ENABLED(); + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, + value, configure, status); diff --git a/arch/platform/z1/dev/cc2420-arch.c b/arch/platform/z1/dev/cc2420-arch.c new file mode 100644 index 000000000..394c5c569 --- /dev/null +++ b/arch/platform/z1/dev/cc2420-arch.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2006, 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. + * + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "dev/spi-legacy.h" +#include "cc2420.h" +#include "isr_compat.h" + +#ifdef CC2420_CONF_SFD_TIMESTAMPS +#define CONF_SFD_TIMESTAMPS CC2420_CONF_SFD_TIMESTAMPS +#endif /* CC2420_CONF_SFD_TIMESTAMPS */ + +#ifndef CONF_SFD_TIMESTAMPS +#define CONF_SFD_TIMESTAMPS 0 +#endif /* CONF_SFD_TIMESTAMPS */ + +#ifdef CONF_SFD_TIMESTAMPS +#include "cc2420-arch-sfd.h" +#endif /* CONF_SFD_TIMESTAMPS */ + +/*---------------------------------------------------------------------------*/ +#if 0 +/* this is now handled in the ADXL345 accelerometer code as it uses irq on port1 too. */ +ISR(CC2420_IRQ, cc24240_port1_interrupt) +{ + if(cc2420_interrupt()) { + LPM4_EXIT; + } +} +#endif +/*---------------------------------------------------------------------------*/ +void +cc2420_arch_init(void) +{ + spi_init(); + + /* all input by default, set these as output */ + CC2420_CSN_PORT(DIR) |= BV(CC2420_CSN_PIN); + CC2420_VREG_PORT(DIR) |= BV(CC2420_VREG_PIN); + CC2420_RESET_PORT(DIR) |= BV(CC2420_RESET_PIN); + +#if CONF_SFD_TIMESTAMPS + cc2420_arch_sfd_init(); +#endif /* CONF_SFD_TIMESTAMPS */ + + CC2420_SPI_DISABLE(); /* Unselect radio. */ +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/i2cmaster.c b/arch/platform/z1/dev/i2cmaster.c new file mode 100644 index 000000000..59437b904 --- /dev/null +++ b/arch/platform/z1/dev/i2cmaster.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2010, 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. + * + */ + +/** + * \file + * I2C communication device drivers for Zolertia Z1 sensor node. + * \author + * Enric M. Calvo, Zolertia + * Marcus Lundén, SICS + */ + +#include "i2cmaster.h" +#include "isr_compat.h" + +signed char tx_byte_ctr, rx_byte_ctr; +unsigned char rx_buf[2]; +unsigned char *tx_buf_ptr; +unsigned char *rx_buf_ptr; +unsigned char receive_data; +unsigned char transmit_data1; +unsigned char transmit_data2; +unsigned char prescale_lsb = I2C_PRESC_Z1_LSB; +unsigned char prescale_msb = I2C_PRESC_Z1_MSB; +volatile unsigned int i; /* volatile to prevent optimization */ + +/* ------------------------------------------------------------------------------ + * Change the data rate prior initializing transmission or reception + * ----------------------------------------------------------------------------- */ +void +i2c_setrate(uint8_t p_lsb, uint8_t p_msb) +{ + prescale_lsb = p_lsb; + prescale_lsb = p_msb; +} +/* ------------------------------------------------------------------------------ + * This function initializes the USCI module for master-receive operation. + * ----------------------------------------------------------------------------- */ +void +i2c_receiveinit(uint8_t slave_address) +{ + UCB1CTL1 = UCSWRST; /* Enable SW reset */ + UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; /* I2C Master, synchronous mode */ + UCB1CTL1 = UCSSEL_2 | UCSWRST; /* Use SMCLK, keep SW reset */ + UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */ + UCB1BR1 = prescale_msb; + UCB1I2CSA = slave_address; /* set slave address */ + UCB1CTL1 &= ~UCTR; /* I2C Receiver */ + UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */ + UCB1I2CIE = UCNACKIE; +#if I2C_RX_WITH_INTERRUPT + UC1IE = UCB1RXIE; /* Enable RX interrupt if desired */ +#endif +} +/* ------------------------------------------------------------------------------ + * Initializes USCI for master-transmit operation. + * ------------------------------------------------------------------------------ */ +void +i2c_transmitinit(uint8_t slave_address) +{ + UCB1CTL1 |= UCSWRST; /* Enable SW reset */ + UCB1CTL0 |= (UCMST | UCMODE_3 | UCSYNC); /* I2C Master, synchronous mode */ + UCB1CTL1 = UCSSEL_2 + UCSWRST; /* Use SMCLK, keep SW reset */ + UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */ + UCB1BR1 = prescale_msb; + UCB1I2CSA = slave_address; /* Set slave address */ + UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */ + UCB1I2CIE = UCNACKIE; + UC1IE = UCB1TXIE; /* Enable TX ready interrupt */ +} +/* ------------------------------------------------------------------------------ + * This function is used to start an I2C communication in master-receiver mode WITHOUT INTERRUPTS + * for more than 1 byte + * ------------------------------------------------------------------------------ */ +static volatile uint8_t rx_byte_tot = 0; +uint8_t +i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf) +{ + + rx_byte_tot = byte_ctr; + rx_byte_ctr = byte_ctr; + rx_buf_ptr = rx_buf; + + while((UCB1CTL1 & UCTXSTT) || (UCB1STAT & UCNACKIFG)) /* Slave acks address or not? */ + PRINTFDEBUG("____ UCTXSTT not clear OR NACK received\n"); + +#if I2C_RX_WITH_INTERRUPT + PRINTFDEBUG(" RX Interrupts: YES \n"); + + /* SPECIAL-CASE: Stop condition must be sent while receiving the 1st byte for 1-byte only read operations */ + if(rx_byte_tot == 1) { /* See page 537 of slau144e.pdf */ + dint(); + UCB1CTL1 |= UCTXSTT; /* I2C start condition */ + while(UCB1CTL1 & UCTXSTT) /* Waiting for Start bit to clear */ + PRINTFDEBUG("____ STT clear wait\n"); + UCB1CTL1 |= UCTXSTP; /* I2C stop condition */ + eint(); + } else { /* all other cases */ + UCB1CTL1 |= UCTXSTT; /* I2C start condition */ + } + return 0; + +#else + uint8_t n_received = 0; + + PRINTFDEBUG(" RX Interrupts: NO \n"); + + UCB1CTL1 |= UCTXSTT; /* I2C start condition */ + + while(rx_byte_ctr > 0) { + if(UC1IFG & UCB1RXIFG) { /* Waiting for Data */ + rx_buf[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF; + rx_byte_ctr--; + UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag */ + n_received++; + } + } + UCB1CTL1 |= UCTXSTP; /* I2C stop condition */ + return n_received; +#endif +} +/* ------------------------------------------------------------------------------ + * This function is used to check if there is communication in progress. + * ------------------------------------------------------------------------------ */ +uint8_t +i2c_busy(void) +{ + return UCB1STAT & UCBBUSY; +} +/*---------------------------------------------------------------------------- + * Setup ports and pins for I2C use. + * ------------------------------------------------------------------------------ */ + +void +i2c_enable(void) +{ + I2C_PxSEL |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */ + I2C_PxSEL2 |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */ + I2C_PxDIR |= I2C_SCL; /* SCL is output (not needed?) */ + I2C_PxDIR &= ~I2C_SDA; /* SDA is input (not needed?) */ + I2C_PxREN |= (I2C_SDA | I2C_SCL); /* Activate internal pull-up/-down resistors */ + I2C_PxOUT |= (I2C_SDA | I2C_SCL); /* Select pull-up resistors */ +} +void +i2c_disable(void) +{ + I2C_PxSEL &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */ + I2C_PxSEL2 &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */ + I2C_PxREN &= ~(I2C_SDA | I2C_SCL); /* Deactivate internal pull-up/-down resistors */ + I2C_PxOUT &= ~(I2C_SDA | I2C_SCL); /* Select pull-up resistors */ +} +/* ------------------------------------------------------------------------------ + * This function is used to start an I2C communication in master-transmit mode. + * ------------------------------------------------------------------------------ */ +static volatile uint8_t tx_byte_tot = 0; +void +i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf) +{ + tx_byte_tot = byte_ctr; + tx_byte_ctr = byte_ctr; + tx_buf_ptr = tx_buf; + UCB1CTL1 |= UCTR + UCTXSTT; /* I2C TX, start condition */ +} +/*----------------------------------------------------------------------------*/ +ISR(USCIAB1TX, i2c_tx_interrupt) +{ + /* TX Part */ + if(UC1IFG & UCB1TXIFG) { /* TX int. condition */ + if(tx_byte_ctr == 0) { + UCB1CTL1 |= UCTXSTP; /* I2C stop condition */ + UC1IFG &= ~UCB1TXIFG; /* Clear USCI_B1 TX int flag */ + } else { + UCB1TXBUF = tx_buf_ptr[tx_byte_tot - tx_byte_ctr]; + tx_byte_ctr--; + } + } + /* RX Part */ +#if I2C_RX_WITH_INTERRUPT + else if(UC1IFG & UCB1RXIFG) { /* RX int. condition */ + rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF; + rx_byte_ctr--; + if(rx_byte_ctr == 1) { /* stop condition should be set before receiving last byte */ + /* Only for 1-byte transmissions, STOP is handled in receive_n_int */ + if(rx_byte_tot != 1) { + UCB1CTL1 |= UCTXSTP; /* I2C stop condition */ + } + UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag. XXX Just in case, check if necessary */ + } + } +#endif +} + +ISR(USCIAB1RX, i2c_rx_interrupt) +{ + if(UCB1STAT & UCNACKIFG) { + PRINTFDEBUG("!!! NACK received in RX\n"); + UCB1CTL1 |= UCTXSTP; + UCB1STAT &= ~UCNACKIFG; + } +} diff --git a/arch/platform/z1/dev/i2cmaster.h b/arch/platform/z1/dev/i2cmaster.h new file mode 100644 index 000000000..cf9d96e6d --- /dev/null +++ b/arch/platform/z1/dev/i2cmaster.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, 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. + * + */ + +/** + * \file + * I2C communication device driver header file for Zolertia Z1 sensor node. + * \author + * Enric Calvo, Zolertia + * Marcus Lundén, SICS + */ + +#ifndef I2CMASTER_H_ +#define I2CMASTER_H_ + +#include "contiki.h" + +void i2c_enable(void); +void i2c_disable(void); + +void i2c_receiveinit(uint8_t slave_address); +uint8_t i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf); + +void i2c_transmitinit(uint8_t slave_address); +void i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf); + +uint8_t i2c_busy(void); +void i2c_setrate(uint8_t p_lsb, uint8_t p_msb); + +#if 0 +#include +#define PRINTFDEBUG(...) printf(__VA_ARGS__) +#else +#define PRINTFDEBUG(...) +#endif + +#endif /* #ifdef I2CMASTER_H_ */ diff --git a/arch/platform/z1/dev/light-sensor.c b/arch/platform/z1/dev/light-sensor.c new file mode 100644 index 000000000..ebc52d4db --- /dev/null +++ b/arch/platform/z1/dev/light-sensor.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2005-2010, 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 "contiki.h" +#include "lib/sensors.h" +#include "dev/sky-sensors.h" +#include "dev/light-sensor.h" +#include "dev/potentiometer-sensor.h" + +/* Photodiode 1 (P64) on INCH_4 */ +/* Photodiode 2 (P65) on INCH_5 */ +/* Enric#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5)) */ +#ifndef INPUT_CHANNEL +#define INPUT_CHANNEL (1 << INCH_4) +#endif + +#ifndef INPUT_REFERENCE +#define INPUT_REFERENCE SREF_0 +#endif + +#ifdef POTENTIOMETER_MEM +#define PHOTOSYNTHETIC_MEM POTENTIOMETER_MEM +#define TOTAL_SOLAR_MEM POTENTIOMETER_MEM +#else +#define PHOTOSYNTHETIC_MEM ADC12MEM4 +#define TOTAL_SOLAR_MEM ADC12MEM4 +#endif + + +const struct sensors_sensor light_sensor; + +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + switch(type) { + /* Photosynthetically Active Radiation. */ + case LIGHT_SENSOR_PHOTOSYNTHETIC: + return PHOTOSYNTHETIC_MEM; + + /* Total Solar Radiation. */ + case LIGHT_SENSOR_TOTAL_SOLAR: + return TOTAL_SOLAR_MEM; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return sky_sensors_status(INPUT_CHANNEL, type); +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(light_sensor, "Light", value, configure, status); diff --git a/arch/platform/z1/dev/light-sensor.h b/arch/platform/z1/dev/light-sensor.h new file mode 100644 index 000000000..411c6fa33 --- /dev/null +++ b/arch/platform/z1/dev/light-sensor.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, 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. + * + * + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2010-01-08 + * Updated : $Date: 2010/01/14 20:23:02 $ + * $Revision: 1.2 $ + */ + +#ifndef LIGHT_SENSOR_H_ +#define LIGHT_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor light_sensor; + +#define LIGHT_SENSOR_PHOTOSYNTHETIC 0 +#define LIGHT_SENSOR_TOTAL_SOLAR 1 + + +#endif /* LIGHT-SENSOR_H_ */ diff --git a/arch/platform/z1/dev/light-ziglet.c b/arch/platform/z1/dev/light-ziglet.c new file mode 100644 index 000000000..3f322e30a --- /dev/null +++ b/arch/platform/z1/dev/light-ziglet.c @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2010, 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. + * + */ + +/** + * \file + * Device drivers for light ziglet sensor in Zolertia Z1. + * It is recommended to use with a 100KHz data rate + * \author + * Antonio Lignan, Zolertia + * Marcus Lundén, SICS + */ + +#include +#include "contiki.h" +#include "i2cmaster.h" +#include "light-ziglet.h" + +#if 0 +#define PRINTFDEBUG(...) printf(__VA_ARGS__) +#else +#define PRINTFDEBUG(...) +#endif + +/* Bitmasks and bit flag variable for keeping track of tmp102 status. */ +enum TSL2563_STATUSTYPES { + /* must be a bit and not more, not using 0x00. */ + INITED = 0x01, + RUNNING = 0x02, + STOPPED = 0x04, +}; + +static enum TSL2563_STATUSTYPES _TSL2563_STATUS = 0x00; + +uint16_t +calculateLux(uint16_t *buffer) +{ + uint32_t ch0, ch1 = 0; + uint32_t aux = (1 << 14); + uint32_t ratio, lratio, tmp = 0; + + ch0 = (buffer[0] * aux) >> 10; + ch1 = (buffer[1] * aux) >> 10; + + PRINTFDEBUG("B0 %u, B1 %u\n", buffer[0], buffer[1]); + PRINTFDEBUG("ch0 %lu, ch1 %lu\n", ch0, ch1); + + ratio = (ch1 << 10); + ratio = ratio / ch0; + lratio = (ratio + 1) >> 1; + + PRINTFDEBUG("ratio %lu, lratio %lu\n", ratio, lratio); + + if((lratio >= 0) && (lratio <= K1T)) { + tmp = (ch0 * B1T) - (ch1 * M1T); + } else if(lratio <= K2T) { + tmp = (ch0 * B2T) - (ch1 * M2T); + } else if(lratio <= K3T) { + tmp = (ch0 * B3T) - (ch1 * M3T); + } else if(lratio <= K4T) { + tmp = (ch0 * B4T) - (ch1 * M4T); + } else if(lratio <= K5T) { + tmp = (ch0 * B5T) - (ch1 * M5T); + } else if(lratio <= K6T) { + tmp = (ch0 * B6T) - (ch1 * M6T); + } else if(lratio <= K7T) { + tmp = (ch0 * B7T) - (ch1 * M7T); + } else if(lratio > K8T) { + tmp = (ch0 * B8T) - (ch1 * M8T); + } + + if(tmp < 0) { + tmp = 0; + } + + tmp += (1 << 13); + + PRINTFDEBUG("tmp %lu\n", tmp); + + return tmp >> 14; +} +/*---------------------------------------------------------------------------*/ +/* Init the light ziglet sensor: ports, pins, registers, interrupts (none enabled), I2C, + default threshold values etc. */ + +void +light_ziglet_init(void) +{ + if(!(_TSL2563_STATUS & INITED)) { + PRINTFDEBUG("light ziglet init\n"); + _TSL2563_STATUS |= INITED; + + /* Set up ports and pins for I2C communication */ + i2c_enable(); + return; + } +} +/*---------------------------------------------------------------------------*/ +/* Write to a 16-bit register. + args: + reg register to write to + val value to write + */ + +void +tsl2563_write_reg(uint8_t reg, uint16_t val) +{ + uint8_t tx_buf[] = { reg, 0x00, 0x00 }; + + tx_buf[1] = (uint8_t)(val >> 8); + tx_buf[2] = (uint8_t)(val & 0x00FF); + + i2c_transmitinit(TSL2563_ADDR); + while(i2c_busy()); + PRINTFDEBUG("I2C Ready to TX\n"); + + i2c_transmit_n(3, tx_buf); + while(i2c_busy()); + PRINTFDEBUG("WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg); +} +/*---------------------------------------------------------------------------*/ +/* Read register. + args: + reg what register to read + returns the value of the read register type uint16_t + */ + +uint16_t +tsl2563_read_reg(uint8_t reg) +{ + uint16_t readBuf[] = { 0x00, 0x00 }; + uint8_t buf[] = { 0x00, 0x00, 0x00, 0x00 }; + uint16_t retVal = 0; + uint8_t rtx = reg; + + /* Transmit the register to read */ + i2c_transmitinit(TSL2563_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, &rtx); + while(i2c_busy()); + + /* Receive the data */ + i2c_receiveinit(TSL2563_ADDR); + while(i2c_busy()); + i2c_receive_n(4, buf); + while(i2c_busy()); + + PRINTFDEBUG("\nb0 %u, b1 %u, b2 %u, b3 %u\n", buf[0], buf[1], buf[2], buf[3]); + + readBuf[0] = (buf[1] << 8 | (buf[0])); + readBuf[1] = (buf[3] << 8 | (buf[2])); + + retVal = calculateLux(readBuf); + return retVal; +} +uint16_t +light_ziglet_on(void) +{ + uint16_t data; + uint8_t regon = TSL2563_PWRN; + /* Turn on the sensor */ + i2c_transmitinit(TSL2563_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, ®on); + while(i2c_busy()); + data = (uint16_t)tsl2563_read_reg(TSL2563_READ); + return data; +} +void +light_ziglet_off(void) +{ + uint8_t regoff = 0x00; + /* Turn off the sensor */ + i2c_transmitinit(TSL2563_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, ®off); + while(i2c_busy()); + return; +} +/*---------------------------------------------------------------------------*/ +/* Read light ziglet sensor + */ + +uint16_t +light_ziglet_read(void) +{ + uint16_t lux = 0; + lux = light_ziglet_on(); + light_ziglet_off(); + return lux; +} diff --git a/arch/platform/z1/dev/light-ziglet.h b/arch/platform/z1/dev/light-ziglet.h new file mode 100644 index 000000000..4db18e24e --- /dev/null +++ b/arch/platform/z1/dev/light-ziglet.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2010, 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. + * + */ + +/** + * \file + * Device drivers header file for light ziglet sensor in Zolertia Z1 WSN Platform. + * \author + * Antonio Lignan, Zolertia + * Marcus Lundén, SICS + */ + +#ifndef LIGHT_ZIGLET_H_ +#define LIGHT_ZIGLET_H_ +#include +#include "i2cmaster.h" + +/* Init the light ziglet sensor: ports, pins, I2C, interrupts */ +void light_ziglet_init(void); + +/* Write to a register. + args: + reg register to write to + val value to write + */ +void tsl2563_write_reg(uint8_t reg, uint16_t val); + +/* Read one register. + args: + reg what register to read + returns the value of the read register + */ +uint16_t tsl2563_read_reg(uint8_t reg); + +/* Takes a single light reading + args: none + returns a lux value + */ +uint16_t light_ziglet_read(); + +/* Calculates the lux values from the calibration table + args: raw values from sensor + returns a lux value + */ +uint16_t calculateLux(uint16_t *readRaw); + +/* Turns the light ziglet ON and polls the sensor for a light reading */ +uint16_t light_ziglet_on(void); + +/* -------------------------------------------------------------------------- */ +/* Reference definitions */ + +/* TSL2563 slave address */ +#define TSL2563_ADDR 0x39 + +/* Registers */ +#define TSL2563_READ 0xAC +#define TSL2563_PWRN 0x03 + +/* Calibration settings */ +#define K1T 0X0040 +#define B1T 0x01f2 +#define M1T 0x01b2 + +#define K2T 0x0080 +#define B2T 0x0214 +#define M2T 0x02d1 + +#define K3T 0x00c0 +#define B3T 0x023f +#define M3T 0x037b + +#define K4T 0x0100 +#define B4T 0x0270 +#define M4T 0x03fe + +#define K5T 0x0138 +#define B5T 0x016f +#define M5T 0x01fc + +#define K6T 0x019a +#define B6T 0x00d2 +#define M6T 0x00fb + +#define K7T 0x029a +#define B7T 0x0018 +#define M7T 0x0012 + +#define K8T 0x029a +#define B8T 0x0000 +#define M8T 0x0000 + +/* -------------------------------------------------------------------------- */ +#endif /* ifndef LIGHT_ZIGLET_H_ */ + diff --git a/arch/platform/z1/dev/potentiometer-sensor.c b/arch/platform/z1/dev/potentiometer-sensor.c new file mode 100644 index 000000000..12597bd0e --- /dev/null +++ b/arch/platform/z1/dev/potentiometer-sensor.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL + * 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne) + * Created : 2011-02-22 + * $Revision: 1.0 $ + */ + +#include "dev/potentiometer-sensor.h" +#include "dev/sky-sensors.h" +#include "contiki.h" + +/* Configure ADC12_2 to sample channel 11 (voltage) and use */ +/* the Vref+ as reference (SREF_1) since it is a stable reference */ +#define INPUT_CHANNEL (1 << INCH_4) +#define INPUT_REFERENCE SREF_0 +#define POTENTIOMETER_MEM ADC12MEM4 + +const struct sensors_sensor potentiometer_sensor; +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return POTENTIOMETER_MEM; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c); +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return sky_sensors_status(INPUT_CHANNEL, type); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(potentiometer_sensor, POTENTIOMETER_SENSOR, value, configure, status); diff --git a/arch/platform/z1/dev/potentiometer-sensor.h b/arch/platform/z1/dev/potentiometer-sensor.h new file mode 100644 index 000000000..d9d8b983d --- /dev/null +++ b/arch/platform/z1/dev/potentiometer-sensor.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL + * 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne) + * Created : 2011-02-22 + * $Revision: 1.0 $ + */ + +#ifndef POTENTIOMETER_SENSOR_H_ +#define POTENTIOMETER_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor potentiometer_sensor; + +#define POTENTIOMETER_SENSOR "Potentiometer" + +#endif /* POTENTIOMETER_SENSOR_H_ */ diff --git a/arch/platform/z1/dev/reed-sensor.c b/arch/platform/z1/dev/reed-sensor.c new file mode 100644 index 000000000..7e7a0df6d --- /dev/null +++ b/arch/platform/z1/dev/reed-sensor.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2015, Zolertia + * 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 + * Reed sensor driver file + * \author + * Antonio Lignan + */ + +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/reed-sensor.h" +#include "sys/process.h" +#include "sys/ctimer.h" +/*---------------------------------------------------------------------------*/ +#ifndef REED_CHECK_PERIOD +#define REED_CHECK_PERIOD CLOCK_SECOND +#endif +/*---------------------------------------------------------------------------*/ +static int current_status = -1; +static struct ctimer change_timer; +process_event_t reed_sensor_event_changed; +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return ~(REED_PORT_DIR & REED_READ_PIN); + } + return REED_SENSOR_ERROR; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + if((!status(SENSORS_ACTIVE)) || (type != REED_SENSOR_VAL)) { + return REED_SENSOR_ERROR; + } + return (REED_PORT_READ & REED_READ_PIN) ? REED_CLOSED : REED_OPEN; +} +/*---------------------------------------------------------------------------*/ +static void +check_callback(void *data) +{ + static int new_status; + if(current_status == -1) { + ctimer_stop(&change_timer); + return; + } + + new_status = value(REED_SENSOR_VAL); + if(new_status != current_status) { + current_status = new_status; + process_post(PROCESS_BROADCAST, reed_sensor_event_changed, ¤t_status); + } + ctimer_reset(&change_timer); +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + if(!status(SENSORS_ACTIVE)) { + REED_PORT_SEL |= REED_READ_PIN; + REED_PORT_DIR &= ~REED_READ_PIN; + REED_PORT_REN |= REED_READ_PIN; + REED_PORT_PRES |= REED_READ_PIN; + } + } else { + REED_PORT_DIR |= REED_READ_PIN; + REED_PORT_REN &= ~REED_READ_PIN; + } + return REED_SENSOR_SUCCESS; + case REED_SENSOR_MODE: + if(c == REED_SENSOR_EVENT_MODE) { + current_status = value(REED_SENSOR_VAL); + ctimer_set(&change_timer, REED_CHECK_PERIOD, check_callback, NULL); + } else if(c == REED_SENSOR_EVENT_POLL) { + current_status = -1; + ctimer_stop(&change_timer); + } else { + return REED_SENSOR_ERROR; + } + return REED_SENSOR_SUCCESS; + } + return REED_SENSOR_ERROR; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(reed_sensor, REED_SENSOR, value, configure, status); diff --git a/arch/platform/z1/dev/reed-sensor.h b/arch/platform/z1/dev/reed-sensor.h new file mode 100644 index 000000000..7e86716f5 --- /dev/null +++ b/arch/platform/z1/dev/reed-sensor.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, Zolertia + * 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. + * + */ +/** + * Header file for the reed sensor + * + * The Reed sensor allows to be used either by polling the sensor status or by + * setting up a timer on the background ticking every REED_CHECK_PERIOD, posting + * a reed_sensor_event_changed event, informing the application about a change + * in the sensor status (basically open or closed). To enable each mode + * (default is polling) call the configure() function with REED_SENSOR_MODE + * using REED_SENSOR_EVENT_MODE or REED_SENSOR_POLL_MODE, after having + * initialized the device using SENSORS_ACTIVATE(reed_sensor). + * + * \file + * Reed sensor header file + * \author + * Antonio Lignan + */ +#include "lib/sensors.h" + +#ifndef REED_SENSOR_H_ +#define REED_SENSOR_H_ +/* -------------------------------------------------------------------------- */ +#define REED_SENSOR_ERROR -1 +#define REED_SENSOR_SUCCESS 0x00 +#define REED_SENSOR_VAL 0x01 +/* -------------------------------------------------------------------------- */ +#define REED_OPEN 0x00 +#define REED_CLOSED 0x01 +/* -------------------------------------------------------------------------- */ +#define REED_SENSOR_MODE 0x01 +#define REED_SENSOR_EVENT_MODE 0x0A +#define REED_SENSOR_EVENT_POLL 0x0B +/* -------------------------------------------------------------------------- */ +#define REED_PORT_DIR P4DIR +#define REED_PORT_SEL P4SEL +#define REED_PORT_REN P4REN +#define REED_PORT_READ P4IN +#define REED_PORT_PRES P4OUT +#define REED_READ_PIN (1 << 2) +/* -------------------------------------------------------------------------- */ +#define REED_SENSOR "Reed Sensor" +/* -------------------------------------------------------------------------- */ +extern const struct sensors_sensor reed_sensor; +extern process_event_t reed_sensor_event_changed; +/* -------------------------------------------------------------------------- */ +#endif /* ifndef REED_SENSOR_H_ */ diff --git a/arch/platform/z1/dev/relay-phidget.c b/arch/platform/z1/dev/relay-phidget.c new file mode 100644 index 000000000..d78734b21 --- /dev/null +++ b/arch/platform/z1/dev/relay-phidget.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 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. + * + * + * ----------------------------------------------------------------- + * + * \file + * Device simple driver for generic relay in phidget port of Zolertia Z1 + * \author + * Antonio Lignan, Zolertia + * + */ + +#include "contiki.h" +#include "relay-phidget.h" + +static uint8_t controlPin; + +enum PHIDGET_RELAY_STATUSTYPES { + /* must be a bit and not more, not using 0x00. */ + INITED = 0x01, + RUNNING = 0x02, + STOPPED = 0x04, +}; + +static enum PHIDGET_RELAY_STATUSTYPES _RELAY_STATUS = 0x00; + +/*---------------------------------------------------------------------------*/ + +void +relay_enable(uint8_t pin) +{ + + if(!(_RELAY_STATUS & INITED)) { + + _RELAY_STATUS |= INITED; + + /* Selects the pin to be configure as the control pin of the relay module */ + controlPin = (1 << pin); + + /* Configures the control pin */ + P6SEL &= ~controlPin; + P6DIR |= controlPin; + } +} +/*---------------------------------------------------------------------------*/ + +void +relay_on() +{ + if((_RELAY_STATUS & INITED)) { + P6OUT |= controlPin; + } +} +/*---------------------------------------------------------------------------*/ +void +relay_off() +{ + if((_RELAY_STATUS & INITED)) { + P6OUT &= ~controlPin; + } +} +/*---------------------------------------------------------------------------*/ + +int8_t +relay_toggle() +{ + if((_RELAY_STATUS & INITED)) { + P6OUT ^= controlPin; + if((P6OUT & controlPin)) { + return 1; + } + return 0; + } + return -1; +} +/*---------------------------------------------------------------------------*/ + diff --git a/arch/platform/z1/dev/relay-phidget.h b/arch/platform/z1/dev/relay-phidget.h new file mode 100644 index 000000000..580151f58 --- /dev/null +++ b/arch/platform/z1/dev/relay-phidget.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 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. + * + * ----------------------------------------------------------------- + * + * \file + * Device simple driver for generic relay in phidget port of Zolertia Z1 + * \author + * Antonio Lignan, Zolertia + * + */ + +#ifndef RELAY_PHIDGET_H_ +#define RELAY_PHIDGETS_H_ + +void relay_enable(uint8_t pin); + +void relay_on(); +void relay_off(); +int8_t relay_toggle(); + +#endif /* RELAY_PHIDGET_H_ */ diff --git a/arch/platform/z1/dev/sht11-arch.h b/arch/platform/z1/dev/sht11-arch.h new file mode 100644 index 000000000..1cd1bc8e6 --- /dev/null +++ b/arch/platform/z1/dev/sht11-arch.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL + * 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 + * Architecture-specific definitions for the SHT11 sensor on Zolertia Z1 + * when connected to the Ziglet port. + * \author + * Enric M. Calvo , adapted from work by + * Nicolas Tsiftes + */ + +#ifndef SHT11_ARCH_H +#define SHT11_ARCH_H + +/* Architecture-specific definitions for the SHT11 sensor on Zolertia Z1 + * when connected to the Ziglet port. + * CAUTION: I2C needs to be disabled to use the bitbang protocol of SHT11 + */ + +#define SHT11_ARCH_SDA 1 /* P5.1 */ +#define SHT11_ARCH_SCL 2 /* P5.2 */ +/* SHT11_ARCH_PWR is not needed, but until and *-arch abstraction exists, this + * should fix it + */ +#define SHT11_ARCH_PWR 3 /* P5.3 -- unused pin */ + +#define SHT11_PxDIR P5DIR +#define SHT11_PxIN P5IN +#define SHT11_PxOUT P5OUT +#define SHT11_PxSEL P5SEL +#define SHT11_PxREN P5REN + +#endif diff --git a/arch/platform/z1/dev/sht25.c b/arch/platform/z1/dev/sht25.c new file mode 100644 index 000000000..b8356087b --- /dev/null +++ b/arch/platform/z1/dev/sht25.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2015, Zolertia + * 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 + * SHT25 temperature and humidity sensor driver + * \author + * Antonio Lignan + */ +#include +#include "contiki.h" +#include "i2cmaster.h" +#include "dev/sht25.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +static uint8_t enabled; +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int value) +{ + if(type != SENSORS_ACTIVE) { + return SHT25_ERROR; + } + if(value) { + i2c_enable(); + } else { + i2c_disable(); + } + enabled = value; + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return enabled; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static uint16_t +sht25_read_reg(uint8_t reg) +{ + uint8_t buf[] = { 0x00, 0x00 }; + uint16_t retval; + uint8_t rtx = reg; + + /* transmit the register to read */ + i2c_transmitinit(SHT25_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, &rtx); + while(i2c_busy()); + /* receive the data */ + i2c_receiveinit(SHT25_ADDR); + while(i2c_busy()); + i2c_receive_n(2, &buf[0]); + while(i2c_busy()); + + retval = (uint16_t)(buf[0] << 8 | (buf[1])); + return retval; +} +/*---------------------------------------------------------------------------*/ +static int16_t +sht25_convert(uint8_t variable, uint16_t value) +{ + int16_t rd; + uint32_t buff; + buff = (uint32_t)value; + if(variable == SHT25_VAL_TEMP) { + buff *= 17572; + buff = buff >> 16; + rd = (int16_t)buff - 4685; + } else { + buff *= 12500; + buff = buff >> 16; + rd = (int16_t)buff - 600; + rd = (rd > 10000) ? 10000 : rd; + } + return rd; +} +/*---------------------------------------------------------------------------*/ +static int16_t +sht25_read(uint8_t variable) +{ + int16_t rd; + uint16_t raw; + + if((variable != SHT25_VAL_TEMP) && (variable != SHT25_VAL_HUM)) { + return SHT25_ERROR; + } + raw = sht25_read_reg(variable); + rd = sht25_convert(variable, raw); + return rd; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return sht25_read(type); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(sht25, SHT25_SENSOR, value, configure, status); +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/sht25.h b/arch/platform/z1/dev/sht25.h new file mode 100644 index 000000000..65d9399d3 --- /dev/null +++ b/arch/platform/z1/dev/sht25.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Zolertia + * 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 + * SHT25 temperature and humidity sensor driver + * \author + * Antonio Lignan + */ +#include "lib/sensors.h" + +#ifndef SHT25_H_ +#define SHT25_H_ + +/* -------------------------------------------------------------------------- */ +#define SHT25_ADDR 0x40 +#define SHT25_TEMP_HOLD 0xE3 +#define SHT25_HUM_HOLD 0xE5 +#define SHT25_TEMP_NO_HOLD 0xF3 +#define SHT25_HUM_NO_HOLD 0xF5 +#define SHT2X_UREG_WRITE 0xE6 +#define SHT2X_UREG_READ 0xE7 +#define SHT2X_SOFT_RESET 0XFE +#define SHT2X_NULL 0x00 +/* -------------------------------------------------------------------------- */ +#define SHT2X_RES_14T_12RH 0x00 +#define SHT2X_RES_12T_08RH 0x01 +#define SHT2X_RES_13T_10RH 0x80 +#define SHT2X_RES_11T_11RH 0x81 +#define SHT2X_HEATER_ON 0x04 +#define SHT2X_HEATER_OFF 0x00 +#define SHT2X_OTP_RELOAD_EN 0x00 +#define SHT2X_OTP_RELOAD_DIS 0x02 +/* -------------------------------------------------------------------------- */ +#define SHT25_VAL_TEMP SHT25_TEMP_HOLD +#define SHT25_VAL_HUM SHT25_HUM_HOLD +#define SHT25_ERROR -1 +/* -------------------------------------------------------------------------- */ +#define SHT25_SENSOR "SHT25 Sensor" +/* -------------------------------------------------------------------------- */ +extern const struct sensors_sensor sht25; +/* -------------------------------------------------------------------------- */ +#endif /* ifndef SHT25_H_ */ diff --git a/arch/platform/z1/dev/sky-sensors.c b/arch/platform/z1/dev/sky-sensors.c new file mode 100644 index 000000000..48ac22428 --- /dev/null +++ b/arch/platform/z1/dev/sky-sensors.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2010, 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-02-02 + * Updated : $Date: 2010/08/25 19:30:53 $ + * $Revision: 1.3 $ + */ +#include "contiki.h" +#include "lib/sensors.h" + +#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno] + +static uint16_t adc_on; +static uint16_t ready; +/*---------------------------------------------------------------------------*/ +static CC_INLINE void +start(void) +{ + uint16_t c, last; + + /* Set up the ADC. */ + P6DIR = 0xff; + P6OUT = 0x00; + + /* Setup ADC12, ref., sampling time */ + /* XXX Note according to the specification a minimum of 17 ms should + be allowed after turn on of the internal reference generator. */ + ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC + REFON; + /* Use sampling timer, repeat-sequence-of-channels */ + ADC12CTL1 = SHP + CONSEQ_3; + + last = 15; + for(c = 0; c < 16; c++) { + /* Clear all end-of-sequences */ + ADC12MCTL_NO(c) &= ~EOS; + if(adc_on & (1 << c)) { + if(last == 15) { + /* Set new start of sequence to lowest active memory holder */ + ADC12CTL1 |= (c * CSTARTADD_1); + } + last = c; + } + } + + /* Set highest end-of-sequence. */ + ADC12MCTL_NO(last) |= EOS; + + ADC12CTL0 |= ADC12ON; + ADC12CTL0 |= ENC; /* enable conversion */ + ADC12CTL0 |= ADC12SC; /* sample & convert */ +} +/*---------------------------------------------------------------------------*/ +static CC_INLINE void +stop(void) +{ + /* stop converting immediately, turn off reference voltage, etc. */ + + ADC12CTL0 &= ~ENC; + /* need to remove CONSEQ_3 if not EOS is configured */ + ADC12CTL1 &= ~CONSEQ_3; + + /* wait for conversion to stop */ + while(ADC12CTL1 & ADC12BUSY); + + /* clear any pending interrupts */ + ADC12IFG = 0; +} +/*---------------------------------------------------------------------------*/ +int +sky_sensors_status(uint16_t input, int type) +{ + if(type == SENSORS_ACTIVE) { + return (adc_on & input) == input; + } + if(type == SENSORS_READY) { + ready |= ADC12IFG & adc_on & input; + return (ready & adc_on & input) == input; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +int +sky_sensors_configure(uint16_t input, uint8_t ref, int type, int value) +{ + uint16_t c; + + if(type == SENSORS_ACTIVE) { + stop(); + + if(value) { + adc_on |= input; + P6SEL |= input & 0xff; + + /* Set ADC config */ + for(c = 0; c < 16; c++) { + if(input & (1 << c)) { + ADC12MCTL_NO(c) = (c * INCH_1) | ref; + } + } + + } else { + adc_on &= ~input; + ready &= ~input; + P6SEL &= ~(input & 0xff); + } + + if(adc_on == 0) { + P6DIR = 0x00; + P6SEL = 0x00; + + /* Turn off ADC and internal reference generator */ + ADC12CTL0 = 0; + ADC12CTL1 = 0; + } else { + start(); + } + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/sky-sensors.h b/arch/platform/z1/dev/sky-sensors.h new file mode 100644 index 000000000..df2aeea48 --- /dev/null +++ b/arch/platform/z1/dev/sky-sensors.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010, 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. + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-02-02 + * Updated : $Date: 2010/08/25 19:30:53 $ + * $Revision: 1.2 $ + */ + +#ifndef SKY_SENSORS_H_ +#define SKY_SENSORS_H_ + +int sky_sensors_status(uint16_t input, int type); +int sky_sensors_configure(uint16_t input, uint8_t reference, + int type, int value); + +#endif /* SKY_SENSORS_H_ */ diff --git a/arch/platform/z1/dev/temperature-sensor.c b/arch/platform/z1/dev/temperature-sensor.c new file mode 100644 index 000000000..1d4328d24 --- /dev/null +++ b/arch/platform/z1/dev/temperature-sensor.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2010, 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 + * Sensor driver for reading the built-in temperature sensor in the CPU. + * \author + * Adam Dunkels + * Joakim Eriksson + * Niclas Finne + */ + +#include "dev/temperature-sensor.h" +#include "dev/sky-sensors.h" +#include "contiki.h" + +#define INPUT_CHANNEL (1 << INCH_10) +#define INPUT_REFERENCE SREF_1 +#define TEMPERATURE_MEM ADC12MEM10 + +const struct sensors_sensor temperature_sensor; + +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return TEMPERATURE_MEM; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c); +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return sky_sensors_status(INPUT_CHANNEL, type); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR, + value, configure, status); diff --git a/arch/platform/z1/dev/temperature-sensor.h b/arch/platform/z1/dev/temperature-sensor.h new file mode 100644 index 000000000..05eafe852 --- /dev/null +++ b/arch/platform/z1/dev/temperature-sensor.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 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 + * Temperature sensor header file. + * \author + * Adam Dunkels + * Joakim Eriksson + * Niclas Finne + */ + +#ifndef TEMPERATURE_SENSOR_H_ +#define TEMPERATURE_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor temperature_sensor; + +#define TEMPERATURE_SENSOR "Temperature" + +#endif /* TEMPERATURE_SENSOR_H_ */ diff --git a/arch/platform/z1/dev/tlc59116.c b/arch/platform/z1/dev/tlc59116.c new file mode 100644 index 000000000..2db0bf093 --- /dev/null +++ b/arch/platform/z1/dev/tlc59116.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013, Jelmer Tiete. + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 + * Device drivers for tlc59116 i2c led driver on Zolertia Z1. + * See http://www.ti.com/product/tlc59116 for datasheet. + * \author + * Jelmer Tiete, VUB + */ + +#include +#include "contiki.h" +#include "tlc59116.h" +#include "i2cmaster.h" + +/*---------------------------------------------------------------------------*/ +/* Write to a register. + * args: + * reg register to write to + * val value to write + */ + +void +tlc59116_write_reg(uint8_t reg, uint8_t val) +{ + uint8_t tx_buf[] = { reg, val }; + + i2c_transmitinit(TLC59116_ADDR); + while(i2c_busy()); + PRINTFDEBUG("I2C Ready to TX\n"); + + i2c_transmit_n(2, tx_buf); + while(i2c_busy()); + PRINTFDEBUG("WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg); +} +/*---------------------------------------------------------------------------*/ +/* Write several registers from a stream. + * args: + * len number of bytes to write + * data pointer to where the data is written from + * + * First byte in stream must be the register address to begin writing to. + * The data is then written from second byte and increasing. + */ + +void +tlc59116_write_stream(uint8_t len, uint8_t *data) +{ + i2c_transmitinit(TLC59116_ADDR); + while(i2c_busy()); + PRINTFDEBUG("I2C Ready to TX(stream)\n"); + + i2c_transmit_n(len, data); /* start tx and send conf reg */ + while(i2c_busy()); + PRINTFDEBUG("WRITE_STR %u B to 0x%02X\n", len, data[0]); +} +/*---------------------------------------------------------------------------*/ +/* Read one register. + * args: + * reg what register to read + * returns the value of the read register + */ + +uint8_t +tlc59116_read_reg(uint8_t reg) +{ + uint8_t retVal = 0; + uint8_t rtx = reg; + + PRINTFDEBUG("READ_REG 0x%02X\n", reg); + + /* transmit the register to read */ + i2c_transmitinit(TLC59116_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, &rtx); + while(i2c_busy()); + + /* receive the data */ + i2c_receiveinit(TLC59116_ADDR); + while(i2c_busy()); + i2c_receive_n(1, &retVal); + while(i2c_busy()); + + return retVal; +} +/*---------------------------------------------------------------------------*/ +/* Read several registers in a stream. + * args: + * reg what register to start reading from + * len number of bytes to read + * whereto pointer to where the data is saved + */ + +void +tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto) +{ + uint8_t rtx = reg; + + PRINTFDEBUG("READ_STR %u B from 0x%02X\n", len, reg); + + /* transmit the register to start reading from */ + i2c_transmitinit(TLC59116_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, &rtx); + while(i2c_busy()); + + /* receive the data */ + i2c_receiveinit(TLC59116_ADDR); + while(i2c_busy()); + i2c_receive_n(len, whereto); + while(i2c_busy()); +} +/*---------------------------------------------------------------------------*/ +/* Set pwm value for individual led. Make sure PWM mode is enabled. + * args: + * led led output -> 0 till 15 + * pwm led pwm value + */ + +void +tlc59116_led(uint8_t led, uint8_t pwm) +{ + if((led < 0) || (led > 15)) { + PRINTFDEBUG("TLC59116: wrong led value."); + } else { + tlc59116_write_reg(led + TLC59116_PWM0, pwm); + } +} +/*---------------------------------------------------------------------------*/ +/* Init the led driver: ports, pins, registers, interrupts (none enabled), I2C, + * default threshold values etc. + */ + +void +tlc59116_init(void) +{ + /* Set up ports and pins for I2C communication */ + i2c_enable(); + + /* set default register values. */ + tlc59116_write_reg(TLC59116_MODE1, TLC59116_MODE1_DEFAULT); + tlc59116_write_reg(TLC59116_MODE2, TLC59116_MODE2_DEFAULT); + + /*Set all PWM values to 0x00 (off) */ + /*This would maybe be better with a SWRST */ + uint8_t tx_buf[] = + { TLC59116_PWM0_AUTOINCR, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + tlc59116_write_stream(17, tx_buf); + + /* set all leds to PWM control */ + tlc59116_write_reg(TLC59116_LEDOUT0, TLC59116_LEDOUT_PWM); + tlc59116_write_reg(TLC59116_LEDOUT1, TLC59116_LEDOUT_PWM); + tlc59116_write_reg(TLC59116_LEDOUT2, TLC59116_LEDOUT_PWM); + tlc59116_write_reg(TLC59116_LEDOUT3, TLC59116_LEDOUT_PWM); +} diff --git a/arch/platform/z1/dev/tlc59116.h b/arch/platform/z1/dev/tlc59116.h new file mode 100644 index 000000000..c5b74f76a --- /dev/null +++ b/arch/platform/z1/dev/tlc59116.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2013, Jelmer Tiete. + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 + * Device drivers header file for TLC59116 i2c led driver on Zolertia Z1. + * See http://www.ti.com/product/tlc59116 for datasheet. + * \author + * Jelmer Tiete, VUB + */ + +#ifndef TLC59116_H_ +#define TLC59116_H_ +#include +#include "dev/i2cmaster.h" + +#if 0 +#include +#define PRINTFDEBUG(...) printf(__VA_ARGS__) +#else +#define PRINTFDEBUG(...) +#endif + + +/* -------------------------------------------------------------------------- */ +/* Init the led driver: ports, pins, registers, I2C*/ +void tlc59116_init(void); + +/* Write to a register. + * args: + * reg register to write to + * val value to write + */ +void tlc59116_write_reg(uint8_t reg, uint8_t val); + +/* Write several registers from a stream. + * args: + * len number of bytes to read + * data pointer to where the data is read from + * First byte in stream must be the register address to begin writing to. + * The data is then written from the second byte and increasing. The address byte + * is not included in length len. + */ +void tlc59116_write_stream(uint8_t len, uint8_t * data); + +/* Read one register. + * args: + * reg what register to read + * returns the value of the read register + */ +uint8_t tlc59116_read_reg(uint8_t reg); + +/* Read several registers in a stream. + * args: + * reg what register to start reading from + * len number of bytes to read + * whereto pointer to where the data is saved + */ +void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t * whereto); + +/* Set pwm value for individual led + * args: + * led led output -> 0 till 15 + * pwm led pwm value + */ +void tlc59116_led(uint8_t led, uint8_t pwm); + + +/* -------------------------------------------------------------------------- */ +/* Application definitions, change if required by application. */ + +/* Suggested defaults according to the data sheet etc */ +#define TLC59116_MODE1_DEFAULT 0x00 /* Default (no sub or all call) + OSC on */ +#define TLC59116_MODE2_DEFAULT 0x00 /* Default (output change on stop) */ + +#define TLC59116_LEDOUT_PWM 0xAA /* LDRx = 01 -> PWM; 4 leds per reg: 01010101b -> 0xAA */ + +/* -------------------------------------------------------------------------- */ +/* Reference definitions, should not be changed */ +/* TLC59116 slave address */ +#define TLC59116_ADDR 0x60 /* 7bit adress, 8bit write adress: 0xC0 */ + /* address with all address pins pulled to ground */ +/* TLC59116 registers */ +#define TLC59116_MODE1 0x00 +#define TLC59116_MODE2 0x01 +#define TLC59116_PWM0_AUTOINCR 0xA2 /* auto increment address for first pwm register */ +#define TLC59116_PWM0 0x02 +#define TLC59116_PWM1 0x03 +#define TLC59116_PWM2 0x04 +#define TLC59116_PWM3 0x05 +#define TLC59116_PWM4 0x06 +#define TLC59116_PWM5 0x07 +#define TLC59116_PWM6 0x08 +#define TLC59116_PWM7 0x09 +#define TLC59116_PWM8 0x0A +#define TLC59116_PWM9 0x0B +#define TLC59116_PWM10 0x0C +#define TLC59116_PWM11 0x0D +#define TLC59116_PWM12 0x0E +#define TLC59116_PWM13 0x0F +#define TLC59116_PWM14 0x10 +#define TLC59116_PWM15 0x11 +#define TLC59116_GRPPWM 0x12 +#define TLC59116_GRPFREQ 0x13 +#define TLC59116_LEDOUT0 0x14 +#define TLC59116_LEDOUT1 0x15 +#define TLC59116_LEDOUT2 0x16 +#define TLC59116_LEDOUT3 0x17 + +/* More registers follow, but not used in this implementation */ + +/* -------------------------------------------------------------------------- */ +#endif /* ifndef TLC59116_H_ */ diff --git a/arch/platform/z1/dev/tmp102.c b/arch/platform/z1/dev/tmp102.c new file mode 100644 index 000000000..4bf267246 --- /dev/null +++ b/arch/platform/z1/dev/tmp102.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * Copyright (c) 2016, Zolertia + * 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 + * Device drivers for tmp102 temperature sensor in Zolertia Z1. + * \author + * Enric M. Calvo, Zolertia + * Marcus Lundén, SICS + * Antonio Lignan, Zolertia + */ +/*---------------------------------------------------------------------------*/ +#include +#include "contiki.h" +#include "i2cmaster.h" +#include "tmp102.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +static uint8_t enabled; +/*---------------------------------------------------------------------------*/ +void +tmp102_init(void) +{ + /* Power Up TMP102 via pin */ + TMP102_PWR_DIR |= TMP102_PWR_PIN; + TMP102_PWR_SEL &= ~TMP102_PWR_SEL; + TMP102_PWR_SEL2 &= ~TMP102_PWR_SEL; + TMP102_PWR_REN &= ~TMP102_PWR_SEL; + TMP102_PWR_OUT |= TMP102_PWR_PIN; + + /* Set up ports and pins for I2C communication */ + i2c_enable(); + + enabled = 1; +} +/*---------------------------------------------------------------------------*/ +void +tmp102_stop(void) +{ + /* Power off */ + TMP102_PWR_OUT &= ~TMP102_PWR_PIN; + enabled = 0; +} +/*---------------------------------------------------------------------------*/ +void +tmp102_write_reg(uint8_t reg, uint16_t val) +{ + uint8_t tx_buf[] = { reg, 0x00, 0x00 }; + + tx_buf[1] = (uint8_t)(val >> 8); + tx_buf[2] = (uint8_t)(val & 0x00FF); + + i2c_transmitinit(TMP102_ADDR); + while(i2c_busy()); + PRINTF("I2C Ready to TX\n"); + + i2c_transmit_n(3, tx_buf); + while(i2c_busy()); + PRINTF("WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg); +} +/*---------------------------------------------------------------------------*/ +uint16_t +tmp102_read_reg(uint8_t reg) +{ + uint8_t buf[] = { 0x00, 0x00 }; + uint16_t retVal = 0; + uint8_t rtx = reg; + PRINTF("READ_REG 0x%02X\n", reg); + + /* transmit the register to read */ + i2c_transmitinit(TMP102_ADDR); + while(i2c_busy()); + i2c_transmit_n(1, &rtx); + while(i2c_busy()); + + /* receive the data */ + i2c_receiveinit(TMP102_ADDR); + while(i2c_busy()); + i2c_receive_n(2, &buf[0]); + while(i2c_busy()); + + retVal = (uint16_t)(buf[0] << 8 | (buf[1])); + + return retVal; +} +/*---------------------------------------------------------------------------*/ +uint16_t +tmp102_read_temp_raw(void) +{ + uint16_t rd = 0; + rd = tmp102_read_reg(TMP102_TEMP); + return rd; +} +/*---------------------------------------------------------------------------*/ +int16_t +tmp102_read_temp_x100(void) +{ + int16_t raw = 0; + int16_t sign = 1; + int16_t abstemp, temp_int; + + raw = (int16_t)tmp102_read_reg(TMP102_TEMP); + if(raw < 0) { + abstemp = (raw ^ 0xFFFF) + 1; + sign = -1; + } else { + abstemp = raw; + } + + /* Integer part of the temperature value and percents*/ + temp_int = (abstemp >> 8) * sign * 100; + temp_int += ((abstemp & 0xff) * 100) / 0x100; + return temp_int; +} +/*---------------------------------------------------------------------------*/ +int8_t +tmp102_read_temp_simple(void) +{ + /* Casted to int8_t: We don't expect temperatures outside -128 to 127 C */ + return tmp102_read_temp_x100() / 100; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int value) +{ + if(type != SENSORS_ACTIVE) { + return TMP102_ERROR; + } + if(value) { + tmp102_init(); + } else { + tmp102_stop(); + } + enabled = value; + return TMP102_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return enabled; + } + return TMP102_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return (int)tmp102_read_temp_x100(); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(tmp102, TMP102_SENSOR, value, configure, status); +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/tmp102.h b/arch/platform/z1/dev/tmp102.h new file mode 100644 index 000000000..cf7a71eb8 --- /dev/null +++ b/arch/platform/z1/dev/tmp102.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * Copyright (c) 2016, Zolertia + * 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 + * Device drivers header file for tmp102 temperature sensor in Zolertia + * Z1 WSN Platform. + * \author + * Enric M. Calvo, Zolertia + * Marcus Lundén, SICS + * Antonio Lignan, Zolertia + */ +/* -------------------------------------------------------------------------- */ +#ifndef TMP102_H_ +#define TMP102_H_ +#include +#include "lib/sensors.h" +#include "i2cmaster.h" +/* -------------------------------------------------------------------------- */ +void tmp102_init(void); +void tmp102_write_reg(uint8_t reg, uint16_t val); +uint16_t tmp102_read_reg(uint8_t reg); +uint16_t tmp102_read_temp_raw(); +int8_t tmp102_read_temp_simple(); +int16_t tmp102_read_temp_x100(); +/* -------------------------------------------------------------------------- */ +#define TMP102_ADDR 0x48 +#define TMP102_TEMP 0x00 +#define TMP102_CONF 0x01 +#define TMP102_TLOW 0x02 +#define TMP102_THIGH 0x03 + +/* TMP102 pin-out */ +#define TMP102_PWR_DIR P5DIR +#define TMP102_PWR_SEL P5SEL +#define TMP102_PWR_SEL2 P5SEL2 +#define TMP102_PWR_REN P5REN +#define TMP102_PWR_OUT P5OUT +#define TMP102_PWR_PIN (1<<0) /* P5.0 */ +/* -------------------------------------------------------------------------- */ +#define TMP102_SUCCESS 0 +#define TMP102_ERROR (-1) +#define TMP102_READ 0x01 +/* -------------------------------------------------------------------------- */ +#define TMP102_SENSOR "TMP102 sensor" +/* -------------------------------------------------------------------------- */ +extern const struct sensors_sensor tmp102; +/* -------------------------------------------------------------------------- */ +#endif /* ifndef TMP102_H_ */ diff --git a/arch/platform/z1/dev/xmem.c b/arch/platform/z1/dev/xmem.c new file mode 100644 index 000000000..89ca9c17b --- /dev/null +++ b/arch/platform/z1/dev/xmem.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2006, 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 + * Device driver for the ST M25P16 40MHz 1Mbyte external memory. + * \author + * Björn Grönvall + * Enric M. Calvo + * + * Data is written bit inverted (~-operator) to flash so that + * unwritten data will read as zeros (UNIX style). + */ + +#include +#include + +#include "contiki.h" +#include "dev/spi-legacy.h" +#include "dev/xmem.h" +#include "dev/watchdog.h" + +#if 1 +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) do {} while (0) +#endif + +#define SPI_FLASH_INS_WREN 0x06 +#define SPI_FLASH_INS_WRDI 0x04 +#define SPI_FLASH_INS_RDSR 0x05 +#define SPI_FLASH_INS_WRSR 0x01 +#define SPI_FLASH_INS_READ 0x03 +#define SPI_FLASH_INS_FAST_READ 0x0b +#define SPI_FLASH_INS_PP 0x02 +#define SPI_FLASH_INS_SE 0xd8 +#define SPI_FLASH_INS_BE 0xc7 +#define SPI_FLASH_INS_DP 0xb9 +#define SPI_FLASH_INS_RES 0xab +/*---------------------------------------------------------------------------*/ +static void +write_enable(void) +{ + int s; + + s = splhigh(); + SPI_FLASH_ENABLE(); + + SPI_WRITE(SPI_FLASH_INS_WREN); + + SPI_FLASH_DISABLE(); + splx(s); +} +/*---------------------------------------------------------------------------*/ +static unsigned +read_status_register(void) +{ + unsigned char u; + + int s; + + s = splhigh(); + SPI_FLASH_ENABLE(); + + + SPI_WRITE(SPI_FLASH_INS_RDSR); + + SPI_FLUSH(); + SPI_READ(u); + + SPI_FLASH_DISABLE(); + splx(s); + + return u; +} +/*---------------------------------------------------------------------------*/ +/* + * Wait for a write/erase operation to finish. + */ +static unsigned +wait_ready(void) +{ + unsigned u; + do { + u = read_status_register(); + watchdog_periodic(); + } while(u & 0x01); /* WIP=1, write in progress */ + return u; +} +/*---------------------------------------------------------------------------*/ +/* + * Erase 64k bytes of data. It takes about 1s before WIP goes low! + */ +static void +erase_sector(unsigned long offset) +{ + int s; + wait_ready(); + + write_enable(); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + SPI_WRITE_FAST(SPI_FLASH_INS_SE); + SPI_WRITE_FAST(offset >> 16); /* MSB */ + SPI_WRITE_FAST(offset >> 8); + SPI_WRITE_FAST(offset >> 0); /* LSB */ + SPI_WAITFORTx_ENDED(); + + SPI_FLASH_DISABLE(); + splx(s); +} +/*---------------------------------------------------------------------------*/ +/* + * Initialize external flash *and* SPI bus! + */ +void +xmem_init(void) +{ + spi_init(); + + P4DIR |= BV(FLASH_CS); /* Unnecessary for Zolertia Z1 | BV(FLASH_PWR); */ + P5DIR |= BV(FLASH_HOLD); /* In P5 for Z1 */ + + SPI_FLASH_DISABLE(); /* Unselect flash. */ + SPI_FLASH_UNHOLD(); +} +/*---------------------------------------------------------------------------*/ +int +xmem_pread(void *_p, int size, unsigned long offset) +{ + unsigned char *p = _p; + const unsigned char *end = p + size; + int s; + wait_ready(); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + SPI_WRITE_FAST(SPI_FLASH_INS_READ); + SPI_WRITE_FAST(offset >> 16); /* MSB */ + SPI_WRITE_FAST(offset >> 8); + SPI_WRITE_FAST(offset >> 0); /* LSB */ + SPI_WAITFORTx_ENDED(); + + SPI_FLUSH(); + for(; p < end; p++) { + unsigned char u; + SPI_READ(u); + *p = ~u; + } + + SPI_FLASH_DISABLE(); + splx(s); + + return size; +} +/*---------------------------------------------------------------------------*/ +static const unsigned char * +program_page(unsigned long offset, const unsigned char *p, int nbytes) +{ + const unsigned char *end = p + nbytes; + int s; + + wait_ready(); + + write_enable(); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + SPI_WRITE_FAST(SPI_FLASH_INS_PP); + SPI_WRITE_FAST(offset >> 16); /* MSB */ + SPI_WRITE_FAST(offset >> 8); + SPI_WRITE_FAST(offset >> 0); /* LSB */ + + for(; p < end; p++) { + SPI_WRITE_FAST(~*p); + } + SPI_WAITFORTx_ENDED(); + + SPI_FLASH_DISABLE(); + splx(s); + + return p; +} +/*---------------------------------------------------------------------------*/ +int +xmem_pwrite(const void *_buf, int size, unsigned long addr) +{ + const unsigned char *p = _buf; + const unsigned long end = addr + size; + unsigned long i, next_page; + + for(i = addr; i < end;) { + next_page = (i | 0xff) + 1; + if(next_page > end) { + next_page = end; + } + p = program_page(i, p, next_page - i); + i = next_page; + } + + return size; +} +/*---------------------------------------------------------------------------*/ +int +xmem_erase(long size, unsigned long addr) +{ + unsigned long end = addr + size; + + if(size % XMEM_ERASE_UNIT_SIZE != 0) { + PRINTF("xmem_erase: bad size\n"); + return -1; + } + + if(addr % XMEM_ERASE_UNIT_SIZE != 0) { + PRINTF("xmem_erase: bad offset\n"); + return -1; + } + + for (; addr < end; addr += XMEM_ERASE_UNIT_SIZE) { + erase_sector(addr); + } + + return size; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/dev/z1-phidgets.c b/arch/platform/z1/dev/z1-phidgets.c new file mode 100644 index 000000000..e86c3e2f0 --- /dev/null +++ b/arch/platform/z1/dev/z1-phidgets.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2010, 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-02-02 + * Updated : $Date: 2010/11/05 10:31:57 $ + * $Revision: 1.3 $ + */ + +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/z1-phidgets.h" + +static uint8_t adc_on; +static uint8_t active; +/*---------------------------------------------------------------------------*/ +static void +sensors_activate(uint8_t type) +{ + uint8_t pre = adc_on; + + adc_on |= type; + + if(pre == 0 && adc_on > 0) { + P6DIR = 0xff; + P6OUT = 0x00; + P6SEL |= 0x8b; /* bit 7 + 3 + 1 + 0 */ + + /* if nothing was started before, start up the ADC system */ + /* Set up the ADC. */ + ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; /* Setup ADC12, ref., sampling time */ + ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; /* Use sampling timer, repeat-sequenc-of-channels */ + /* convert up to MEM4 */ + ADC12MCTL4 |= EOS; + + ADC12CTL0 |= ADC12ON + REFON; + ADC12CTL0 |= ENC; /* enable conversion */ + ADC12CTL0 |= ADC12SC; /* sample & convert */ + } +} +/*---------------------------------------------------------------------------*/ +static void +sensors_deactivate(uint8_t type) +{ + adc_on &= ~type; + + if(adc_on == 0) { + /* stop converting immediately, turn off reference voltage, etc. */ + /* wait for conversion to stop */ + + ADC12CTL0 &= ~ENC; + /* need to remove CONSEQ_3 if not EOS is configured */ + ADC12CTL1 &= ~CONSEQ_3; + + while(ADC12CTL1 & ADC12BUSY); + + ADC12CTL0 = 0; + ADC12CTL1 = 0; + + P6DIR = 0x00; + P6OUT = 0x00; + P6SEL = 0x00; + } +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + /* ADC0 corresponds to the port under the logo, ADC1 to the port over the logo, + ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) */ + switch(type) { + case PHIDGET5V_1: + return ADC12MEM0; + case PHIDGET5V_2: + return ADC12MEM1; + case PHIDGET3V_1: + return ADC12MEM2; + case PHIDGET3V_2: + return ADC12MEM3; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return active; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + if(!status(SENSORS_ACTIVE)) { + /* SREF_1 is Vref+ */ + /* MemReg6 == P6.0/A0 == 5V 1 */ + ADC12MCTL0 = (INCH_0 + SREF_0); + /* MemReg7 == P6.3/A3 == 5V 2 */ + ADC12MCTL1 = (INCH_3 + SREF_0); + /* MemReg8 == P6.1/A1 == 3V 1 */ + ADC12MCTL2 = (INCH_1 + SREF_0); + /* MemReg9 == P6.7/A7 == 3V_2 */ + ADC12MCTL3 = (INCH_7 + SREF_0); + + sensors_activate(0x0F); + active = 1; + } + } else { + sensors_deactivate(0x0F); + active = 0; + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(phidgets, "Phidgets", value, configure, status); diff --git a/arch/platform/z1/dev/z1-phidgets.h b/arch/platform/z1/dev/z1-phidgets.h new file mode 100644 index 000000000..f56356508 --- /dev/null +++ b/arch/platform/z1/dev/z1-phidgets.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-08-26 + * Updated : $Date: 2010/08/27 12:58:57 $ + * $Revision: 1.2 $ + */ +#ifndef Z1_PHIDGETS_H_ +#define Z1_PHIDGETS_H_ + +#define PHIDGET5V_1 0 +#define PHIDGET5V_2 1 +#define PHIDGET3V_1 2 +#define PHIDGET3V_2 3 + +extern const struct sensors_sensor phidgets; + +#endif /* Z1_PHIDGETS_H_ */ diff --git a/arch/platform/z1/dev/z1-sensors.c b/arch/platform/z1/dev/z1-sensors.c new file mode 100644 index 000000000..db5b418b9 --- /dev/null +++ b/arch/platform/z1/dev/z1-sensors.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, Zolertia - http://www.zolertia.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: + * 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. + */ +/*---------------------------------------------------------------------------*/ +/** + * \file + * Zolertia Z1 on-board sensors + * \author + * Antonio Lignan, Zolertia + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/button-sensor.h" +#include "dev/tmp102.h" +#include "dev/adxl345.h" +/*---------------------------------------------------------------------------*/ +/** \brief Exports global symbols for the sensor API */ +SENSORS(&button_sensor, &adxl345, &tmp102); +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/node-id-z1.c b/arch/platform/z1/node-id-z1.c new file mode 100644 index 000000000..7f65e2c58 --- /dev/null +++ b/arch/platform/z1/node-id-z1.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2006, 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. + * + */ + +/** + * \file + * Utility to store a node id in the external flash + * \author + * Adam Dunkels + */ + +#include "contiki.h" +#include "sys/node-id.h" +#include "dev/xmem.h" +#include + +unsigned char node_mac[8]; + +/*---------------------------------------------------------------------------*/ +void +node_id_z1_restore(void) +{ + unsigned char buf[12]; + xmem_pread(buf, 12, NODE_ID_XMEM_OFFSET); + if(buf[0] == 0xad && + buf[1] == 0xde) { + node_id = (buf[2] << 8) | buf[3]; + memcpy(node_mac, &buf[4], 8); + } else { + node_id = 0; + } +} +/*---------------------------------------------------------------------------*/ +void +node_id_z1_burn(unsigned short id) +{ + unsigned char buf[12]; + memset(buf, 0, sizeof(buf)); + buf[0] = 0xad; + buf[1] = 0xde; + buf[2] = id >> 8; + buf[3] = id & 0xff; + xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET); + xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET); +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/node-id-z1.h b/arch/platform/z1/node-id-z1.h new file mode 100644 index 000000000..d70c018d6 --- /dev/null +++ b/arch/platform/z1/node-id-z1.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006, 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. + * + * Author: Adam Dunkels + * + */ + +#ifndef NODE_ID_Z1_H_ +#define NODE_ID_Z1_H_ + +#include + +void node_id_z1_restore(void); +void node_id_z1_burn(uint16_t node_id); + +#endif /* NODE_ID_Z1_H_ */ diff --git a/arch/platform/z1/platform.c b/arch/platform/z1/platform.c new file mode 100644 index 000000000..0d8d248c5 --- /dev/null +++ b/arch/platform/z1/platform.c @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2006, 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. + * + */ + +#include +#include +#include + +#include "contiki.h" +#include "cc2420.h" +#include "dev/leds.h" +#include "dev/serial-line.h" +#include "dev/slip.h" +#include "dev/uart0.h" +#include "dev/watchdog.h" +#include "dev/xmem.h" +#include "lib/random.h" +#include "net/netstack.h" +#include "net/mac/framer/frame802154.h" +#include "dev/adxl345.h" +#include "sys/clock.h" +#include "sys/energest.h" + +#if NETSTACK_CONF_WITH_IPV6 +#include "net/ipv6/uip-ds6.h" +#endif /* NETSTACK_CONF_WITH_IPV6 */ + +#include "node-id-z1.h" +#include "cfs-coffee-arch.h" +#include "cfs/cfs-coffee.h" + +extern unsigned char node_mac[8]; + +#if DCOSYNCH_CONF_ENABLED +static struct timer mgt_timer; +#endif +extern int msp430_dco_required; + +#define UIP_OVER_MESH_CHANNEL 8 +#if NETSTACK_CONF_WITH_IPV4 +static uint8_t is_gateway; +#endif /* NETSTACK_CONF_WITH_IPV4 */ + +#ifdef EXPERIMENT_SETUP +#include "experiment-setup.h" +#endif + +void init_platform(void); +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Z1" +#define LOG_LEVEL LOG_LEVEL_MAIN +/*---------------------------------------------------------------------------*/ +#ifdef UART0_CONF_BAUD_RATE +#define UART0_BAUD_RATE UART0_CONF_BAUD_RATE +#else +#define UART0_BAUD_RATE 115200 +#endif +/*---------------------------------------------------------------------------*/ +#if 0 +int +force_float_inclusion() +{ + extern int __fixsfsi; + extern int __floatsisf; + extern int __mulsf3; + extern int __subsf3; + + return __fixsfsi + __floatsisf + __mulsf3 + __subsf3; +} +#endif +/*---------------------------------------------------------------------------*/ +void +uip_log(char *msg) +{ + puts(msg); +} +/*---------------------------------------------------------------------------*/ +#if 0 +void +force_inclusion(int d1, int d2) +{ + snprintf(NULL, 0, "%d", d1 % d2); +} +#endif +/*---------------------------------------------------------------------------*/ +static void +set_lladdr(void) +{ + linkaddr_t addr; + + memset(&addr, 0, sizeof(linkaddr_t)); +#if NETSTACK_CONF_WITH_IPV6 + memcpy(addr.u8, node_mac, sizeof(addr.u8)); +#else + if(node_id == 0) { + int i; + for(i = 0; i < sizeof(linkaddr_t); ++i) { + addr.u8[i] = node_mac[7 - i]; + } + } else { + addr.u8[0] = node_id & 0xff; + addr.u8[1] = node_id >> 8; + } +#endif + linkaddr_set_node_addr(&addr); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_one(void) +{ + /* + * Initalize hardware. + */ + msp430_cpu_init(); + + leds_init(); + leds_on(LEDS_RED); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_two(void) +{ + clock_wait(100); + + uart0_init(BAUD2UBR(UART0_BAUD_RATE)); /* Must come before first printf */ + + xmem_init(); + + leds_off(LEDS_RED); + /* + * Hardware initialization done! + */ + + /* Restore node id if such has been stored in external mem */ + node_id_z1_restore(); + + /* If no MAC address was burned, we use the node id or the Z1 product ID */ + if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] | + node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) { + +#ifdef SERIALNUM + if(!node_id) { + LOG_INFO("Node id is not set, using Z1 product ID\n"); + node_id = SERIALNUM; + } +#endif + node_mac[0] = 0xc1; /* Hardcoded for Z1 */ + node_mac[1] = 0x0c; /* Hardcoded for Revision C */ + node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that + the 802.15.4 MAC address is compatible with + an Ethernet MAC address - byte 0 (byte 2 in + the DS ID) */ + node_mac[3] = 0x00; /* Hardcoded */ + node_mac[4] = 0x00; /* Hardcoded */ + node_mac[5] = 0x00; /* Hardcoded */ + node_mac[6] = node_id >> 8; + node_mac[7] = node_id & 0xff; + } + + /* Overwrite node MAC if desired at compile time */ +#ifdef MACID +#warning "***** CHANGING DEFAULT MAC *****" + node_mac[0] = 0xc1; /* Hardcoded for Z1 */ + node_mac[1] = 0x0c; /* Hardcoded for Revision C */ + node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that + the 802.15.4 MAC address is compatible with + an Ethernet MAC address - byte 0 (byte 2 in + the DS ID) */ + node_mac[3] = 0x00; /* Hardcoded */ + node_mac[4] = 0x00; /* Hardcoded */ + node_mac[5] = 0x00; /* Hardcoded */ + node_mac[6] = MACID >> 8; + node_mac[7] = MACID & 0xff; +#endif + +#ifdef IEEE_802154_MAC_ADDRESS + /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ + { + uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; + memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); + node_mac[7] = node_id & 0xff; + } +#endif /* IEEE_802154_MAC_ADDRESS */ + + random_init(node_mac[6] + node_mac[7]); + + set_lladdr(); + + /* + * main() will turn the radio on inside netstack_init(). The CC2420 + * must already be initialised by that time, so we do this here early. + * Later on in stage three we set correct values for PANID and radio + * short/long address. + */ + cc2420_init(); + + SENSORS_ACTIVATE(adxl345); + + leds_off(LEDS_ALL); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_three(void) +{ + uint8_t longaddr[8]; + uint16_t shortaddr; + + init_platform(); + + shortaddr = (linkaddr_node_addr.u8[0] << 8) + linkaddr_node_addr.u8[1]; + memset(longaddr, 0, sizeof(longaddr)); + linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr); + + cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); + + LOG_INFO("CC2420 CCA threshold %i\n", CC2420_CONF_CCA_THRESH); + +#if DCOSYNCH_CONF_ENABLED + timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); +#endif +} +/*---------------------------------------------------------------------------*/ +void +platform_idle(void) +{ + /* + * Idle processing. + */ + int s = splhigh(); /* Disable interrupts. */ + /* uart0_active is for avoiding LPM3 when still sending or receiving */ + if(process_nevents() != 0 || uart0_active()) { + splx(s); /* Re-enable interrupts. */ + } else { +#if DCOSYNCH_CONF_ENABLED + /* before going down to sleep possibly do some management */ + if(timer_expired(&mgt_timer)) { + watchdog_periodic(); + timer_reset(&mgt_timer); + msp430_sync_dco(); +#if CC2420_CONF_SFD_TIMESTAMPS + cc2420_arch_sfd_init(); +#endif /* CC2420_CONF_SFD_TIMESTAMPS */ + } +#endif + + /* Re-enable interrupts and go to sleep atomically. */ + ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); + watchdog_stop(); + /* check if the DCO needs to be on - if so - only LPM 1 */ + if (msp430_dco_required) { + _BIS_SR(GIE | CPUOFF); /* LPM1 sleep for DMA to work!. */ + } else { + _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This + statement will block + until the CPU is + woken up by an + interrupt that sets + the wake up flag. */ + } + watchdog_start(); + ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); + } +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/z1/z1-def.h b/arch/platform/z1/z1-def.h new file mode 100644 index 000000000..e59165ee3 --- /dev/null +++ b/arch/platform/z1/z1-def.h @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2010, 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 + * Platform configuration for the Z1 platform + * \author + * Joakim Eriksson + */ + +#ifndef Z1_DEF_H_ +#define Z1_DEF_H_ + +#include + +/* + * Definitions below are dictated by the hardware and not really + * changeable! + */ + +#define ZOLERTIA_Z1 1 /* Enric */ + +/* 1 len byte, 2 bytes CRC */ + #define RADIO_PHY_OVERHEAD 3 + /* 250kbps data rate. One byte = 32us */ + #define RADIO_BYTE_AIR_TIME 32 +/* Delay between GO signal and SFD: radio fixed delay + 4Bytes preample + 1B SFD -- 1Byte time is 32us + * ~327us + 129preample = 456 us */ +#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(456)) +/* Delay between GO signal and start listening + * ~50us delay + 129preample + ?? = 183 us */ +#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(183)) +/* Delay between the SFD finishes arriving and it is detected in software */ +#define RADIO_DELAY_BEFORE_DETECT 0 + +#define PLATFORM_HAS_LEDS 1 +#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_HAS_RADIO 1 +#define PLATFORM_HAS_BATTERY 1 + +/* CPU target speed in Hz */ +#define F_CPU 8000000uL /* 8MHz by default */ + +/* the low-level radio driver */ +#define NETSTACK_CONF_RADIO cc2420_driver + +/* XXX Temporary place for defines that are lacking in mspgcc4's gpio.h */ +#ifdef __IAR_SYSTEMS_ICC__ +#ifndef P1SEL2_ +#define P1SEL2_ (0x0041u) /* Port 1 Selection 2*/ +DEFC(P1SEL2, P1SEL2_) +#endif +#ifndef P5SEL2_ +#define P5SEL2_ (0x0045u) /* Port 5 Selection 2*/ +DEFC(P5SEL2, P5SEL2_) +#endif +#else /* __IAR_SYSTEMS_ICC__ */ +#ifdef __GNUC__ +#ifndef P1SEL2_ +#define P1SEL2_ 0x0041 /* Port 1 Selection 2*/ +sfrb(P1SEL2, P1SEL2_); +#endif +#ifndef P5SEL2_ +#define P5SEL2_ 0x0045 /* Port 5 Selection 2*/ +sfrb(P5SEL2, P5SEL2_); +#endif +#endif /* __GNUC__ */ +#endif /* __IAR_SYSTEMS_ICC__ */ + +/* + * Definitions below are dictated by the hardware and not really + * changeable! + */ + +/* LED ports */ +#ifdef Z1_IS_Z1SP +#define LEDS_PxDIR P4DIR +#define LEDS_PxOUT P4OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x01 +#define LEDS_CONF_YELLOW 0x80 +#else +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x10 +#define LEDS_CONF_GREEN 0x40 +#define LEDS_CONF_YELLOW 0x20 +#endif /* Z1_IS_Z1SP */ + +#define LEDS_CONF_LEGACY_API 1 + +/* DCO speed resynchronization for more robust UART, etc. */ +#ifndef DCOSYNCH_CONF_ENABLED +#define DCOSYNCH_CONF_ENABLED (!(MAC_CONF_WITH_TSCH)) /* TSCH needs timerB +for SFD timestamping */ +#endif /* DCOSYNCH_CONF_ENABLED */ + +#ifndef CC2420_CONF_SFD_TIMESTAMPS +#define CC2420_CONF_SFD_TIMESTAMPS (MAC_CONF_WITH_TSCH) /* TSCH needs SFD timestamping */ +#endif /* CC2420_CONF_SFD_TIMESTAMPS */ + +#ifndef DCOSYNCH_CONF_PERIOD +#define DCOSYNCH_CONF_PERIOD 30 +#endif /* DCOSYNCH_CONF_PERIOD */ + +#define ROM_ERASE_UNIT_SIZE 512 +#define XMEM_ERASE_UNIT_SIZE (64 * 1024L) + +#define CFS_CONF_OFFSET_TYPE long + +/* Use the first 64k of external flash for node configuration */ +#define NODE_ID_XMEM_OFFSET (0 * XMEM_ERASE_UNIT_SIZE) + +/* Use the second 64k of external flash for codeprop. */ +#define EEPROMFS_ADDR_CODEPROP (1 * XMEM_ERASE_UNIT_SIZE) + +#define CFS_XMEM_CONF_OFFSET (2 * XMEM_ERASE_UNIT_SIZE) +#define CFS_XMEM_CONF_SIZE (1 * XMEM_ERASE_UNIT_SIZE) + +#define CFS_RAM_CONF_SIZE 4096 + +/* + * SPI bus configuration for the Z1 mote. + */ + +/* SPI input/output registers. */ +#define SPI_TXBUF UCB0TXBUF +#define SPI_RXBUF UCB0RXBUF + +/* USART0 Tx ready? */ +#define SPI_WAITFOREOTx() while((UCB0STAT & UCBUSY) != 0) +/* USART0 Rx ready? */ +#define SPI_WAITFOREORx() while((IFG2 & UCB0RXIFG) == 0) +/* USART0 Tx buffer ready? */ +#define SPI_WAITFORTxREADY() while((IFG2 & UCB0TXIFG) == 0) + +#define MOSI 1 /* P3.1 - Output: SPI Master out - slave in (MOSI) */ +#define MISO 2 /* P3.2 - Input: SPI Master in - slave out (MISO) */ +#define SCK 3 /* P3.3 - Output: SPI Serial Clock (SCLK) */ + +/* + * SPI bus - M25P80 external flash configuration. + */ +/* FLASH_PWR P4.3 Output ALWAYS POWERED ON Z1 */ +#define FLASH_CS 4 /* P4.4 Output */ +#define FLASH_HOLD 7 /* P5.7 Output */ + +/* Enable/disable flash access to the SPI bus (active low). */ + +#define SPI_FLASH_ENABLE() (P4OUT &= ~BV(FLASH_CS)) +#define SPI_FLASH_DISABLE() (P4OUT |= BV(FLASH_CS)) + +#define SPI_FLASH_HOLD() (P5OUT &= ~BV(FLASH_HOLD)) +#define SPI_FLASH_UNHOLD() (P5OUT |= BV(FLASH_HOLD)) + +/* + * SPI bus - CC2420 pin configuration. + */ + +#define CC2420_CONF_SYMBOL_LOOP_COUNT 1302 /* 326us msp430X @ 8MHz */ + +/* P1.2 - Input: FIFOP from CC2420 */ +#define CC2420_FIFOP_PORT(type) P1##type +#define CC2420_FIFOP_PIN 2 +/* P1.3 - Input: FIFO from CC2420 */ +#define CC2420_FIFO_PORT(type) P1##type +#define CC2420_FIFO_PIN 3 +/* P1.4 - Input: CCA from CC2420 */ +#define CC2420_CCA_PORT(type) P1##type +#define CC2420_CCA_PIN 4 +/* P4.1 - Input: SFD from CC2420 */ +#define CC2420_SFD_PORT(type) P4##type +#define CC2420_SFD_PIN 1 +/* P3.0 - Output: SPI Chip Select (CS_N) */ +#define CC2420_CSN_PORT(type) P3##type +#define CC2420_CSN_PIN 0 +/* P4.5 - Output: VREG_EN to CC2420 */ +#define CC2420_VREG_PORT(type) P4##type +#define CC2420_VREG_PIN 5 +/* P4.6 - Output: RESET_N to CC2420 */ +#define CC2420_RESET_PORT(type) P4##type +#define CC2420_RESET_PIN 6 + +#define CC2420_IRQ_VECTOR PORT1_VECTOR + +/* Pin status. */ +#define CC2420_FIFOP_IS_1 (!!(CC2420_FIFOP_PORT(IN) & BV(CC2420_FIFOP_PIN))) +#define CC2420_FIFO_IS_1 (!!(CC2420_FIFO_PORT(IN) & BV(CC2420_FIFO_PIN))) +#define CC2420_CCA_IS_1 (!!(CC2420_CCA_PORT(IN) & BV(CC2420_CCA_PIN))) +#define CC2420_SFD_IS_1 (!!(CC2420_SFD_PORT(IN) & BV(CC2420_SFD_PIN))) + +/* The CC2420 reset pin. */ +#define SET_RESET_INACTIVE() (CC2420_RESET_PORT(OUT) |= BV(CC2420_RESET_PIN)) +#define SET_RESET_ACTIVE() (CC2420_RESET_PORT(OUT) &= ~BV(CC2420_RESET_PIN)) + +/* CC2420 voltage regulator enable pin. */ +#define SET_VREG_ACTIVE() (CC2420_VREG_PORT(OUT) |= BV(CC2420_VREG_PIN)) +#define SET_VREG_INACTIVE() (CC2420_VREG_PORT(OUT) &= ~BV(CC2420_VREG_PIN)) + +/* CC2420 rising edge trigger for external interrupt 0 (FIFOP). */ +#define CC2420_FIFOP_INT_INIT() do { \ + CC2420_FIFOP_PORT(IES) &= ~BV(CC2420_FIFOP_PIN); \ + CC2420_CLEAR_FIFOP_INT(); \ +} while(0) + +/* FIFOP on external interrupt 0. */ +#define CC2420_ENABLE_FIFOP_INT() do { CC2420_FIFOP_PORT(IE) |= BV(CC2420_FIFOP_PIN); } while(0) +#define CC2420_DISABLE_FIFOP_INT() do { CC2420_FIFOP_PORT(IE) &= ~BV(CC2420_FIFOP_PIN); } while(0) +#define CC2420_CLEAR_FIFOP_INT() do { CC2420_FIFOP_PORT(IFG) &= ~BV(CC2420_FIFOP_PIN); } while(0) + +/* + * Enables/disables CC2420 access to the SPI bus (not the bus). + * (Chip Select) + */ + +/* ENABLE CSn (active low) */ +#define CC2420_SPI_ENABLE() (CC2420_CSN_PORT(OUT) &= ~BV(CC2420_CSN_PIN)) +/* DISABLE CSn (active low) */ +#define CC2420_SPI_DISABLE() (CC2420_CSN_PORT(OUT) |= BV(CC2420_CSN_PIN)) +#define CC2420_SPI_IS_ENABLED() ((CC2420_CSN_PORT(OUT) & BV(CC2420_CSN_PIN)) != BV(CC2420_CSN_PIN)) + +/* + * I2C configuration + */ + +#define I2C_PxDIR P5DIR +#define I2C_PxIN P5IN +#define I2C_PxOUT P5OUT +#define I2C_PxSEL P5SEL +#define I2C_PxSEL2 P5SEL2 +#define I2C_PxREN P5REN + +#define I2C_SDA (1 << 1) /* SDA == P5.1 */ +#define I2C_SCL (1 << 2) /* SCL == P5.2 */ +#define I2C_PRESC_1KHZ_LSB 0x00 +#define I2C_PRESC_1KHZ_MSB 0x20 +#define I2C_PRESC_100KHZ_LSB 0x50 +#define I2C_PRESC_100KHZ_MSB 0x00 +#define I2C_PRESC_400KHZ_LSB 0x14 +#define I2C_PRESC_400KHZ_MSB 0x00 + +/* Set rate as high as possible by default */ +#ifndef I2C_PRESC_Z1_LSB +#define I2C_PRESC_Z1_LSB I2C_PRESC_400KHZ_LSB +#endif + +#ifndef I2C_PRESC_Z1_MSB +#define I2C_PRESC_Z1_MSB I2C_PRESC_400KHZ_MSB +#endif + +/* I2C configuration with RX interrupts */ +#ifdef I2C_CONF_RX_WITH_INTERRUPT +#define I2C_RX_WITH_INTERRUPT I2C_CONF_RX_WITH_INTERRUPT +#else /* I2C_CONF_RX_WITH_INTERRUPT */ +#define I2C_RX_WITH_INTERRUPT 1 +#endif /* I2C_CONF_RX_WITH_INTERRUPT */ + +/* Platform-specific define for the end of the stack region */ +#define STACK_CONF_ORIGIN ((void *)0x3100) + +#endif /* PLATFORM_CONF_H_ */ From 8b8798ada9e08cac718805175b792476a3f15cb7 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 11 Jan 2019 15:40:30 +0000 Subject: [PATCH 172/184] add back zolertia tool folder --- tools/zolertia/license-bsl.txt | 62 + tools/zolertia/motelist-zolertia | 295 ++++ tools/zolertia/motelist-zolertia-macos | 75 + tools/zolertia/z1-bsl | 1929 +++++++++++++++++++++++ tools/zolertia/z1-bsl-nopic | 1941 ++++++++++++++++++++++++ 5 files changed, 4302 insertions(+) create mode 100644 tools/zolertia/license-bsl.txt create mode 100755 tools/zolertia/motelist-zolertia create mode 100755 tools/zolertia/motelist-zolertia-macos create mode 100755 tools/zolertia/z1-bsl create mode 100755 tools/zolertia/z1-bsl-nopic diff --git a/tools/zolertia/license-bsl.txt b/tools/zolertia/license-bsl.txt new file mode 100644 index 000000000..e6775e9d7 --- /dev/null +++ b/tools/zolertia/license-bsl.txt @@ -0,0 +1,62 @@ +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 new file mode 100755 index 000000000..e5f7da99e --- /dev/null +++ b/tools/zolertia/motelist-zolertia @@ -0,0 +1,295 @@ +#!/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 new file mode 100755 index 000000000..526b4887e --- /dev/null +++ b/tools/zolertia/motelist-zolertia-macos @@ -0,0 +1,75 @@ +#!/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 ); + } + } +} diff --git a/tools/zolertia/z1-bsl b/tools/zolertia/z1-bsl new file mode 100755 index 000000000..31d58d1df --- /dev/null +++ b/tools/zolertia/z1-bsl @@ -0,0 +1,1929 @@ +#!/usr/bin/env python +# Serial Bootstrap Loader software for the MSP430 embedded proccessor. +# +# (C) 2001-2003 Chris Liechti +# this is distributed under a free software license, see license-bsl.txt +# +# fixes from Colin Domoney +# +# based on the application note slas96b.pdf from Texas Instruments, Inc., +# Volker Rzehak +# additional infos from slaa089a.pdf +# +# Forked by Travis Goodspeed for use with the GoodFET +# JTAG programmer. + +import sys, time, string, cStringIO, struct +sys.path.append("/usr/lib/tinyos") +import serial, os, glob + +#forked from TinyOS Telos version. +VERSION = string.split("Revision: 1.39-goodfet-8 z1 fork")[1] + +DEBUG = 0 #disable debug messages by default + +#copy of the patch file provided by TI +#this part is (C) by Texas Instruments +PATCH = """@0220 +31 40 1A 02 09 43 B0 12 2A 0E B0 12 BA 0D 55 42 +0B 02 75 90 12 00 1F 24 B0 12 BA 02 55 42 0B 02 +75 90 16 00 16 24 75 90 14 00 11 24 B0 12 84 0E +06 3C B0 12 94 0E 03 3C 21 53 B0 12 8C 0E B2 40 +10 A5 2C 01 B2 40 00 A5 28 01 30 40 42 0C 30 40 +76 0D 30 40 AC 0C 16 42 0E 02 17 42 10 02 E2 B2 +08 02 14 24 B0 12 10 0F 36 90 00 10 06 28 B2 40 +00 A5 2C 01 B2 40 40 A5 28 01 D6 42 06 02 00 00 +16 53 17 83 EF 23 B0 12 BA 02 D3 3F B0 12 10 0F +17 83 FC 23 B0 12 BA 02 D0 3F 18 42 12 02 B0 12 +10 0F D2 42 06 02 12 02 B0 12 10 0F D2 42 06 02 +13 02 38 E3 18 92 12 02 BF 23 E2 B3 08 02 BC 23 +30 41 +q +""" + +#These BSL's are (C) by TI. They come with the application note slaa089a +F1X_BSL = """@0220 +24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 +F2 C0 32 00 00 00 B2 40 80 5A 20 01 F2 40 85 00 +57 00 F2 40 80 00 56 00 E2 D3 21 00 E2 D3 22 00 +E2 C3 26 00 E2 C2 2A 00 E2 C2 2E 00 B2 40 10 A5 +2C 01 B2 40 00 A5 28 01 3B C0 3A 00 B0 12 D6 04 +82 43 12 02 09 43 36 40 0A 02 37 42 B0 12 AC 05 +C6 4C 00 00 16 53 17 83 F9 23 D2 92 0C 02 0D 02 +28 20 55 42 0B 02 75 90 12 00 80 24 75 90 10 00 +6D 24 B0 12 9C 04 55 42 0B 02 75 90 18 00 31 24 +75 90 1E 00 B8 24 75 90 20 00 17 24 2B B2 11 24 +75 90 16 00 22 24 75 90 14 00 B3 24 75 90 1A 00 +18 24 75 90 1C 00 45 24 04 3C B0 12 36 05 BE 3F +21 53 B0 12 3C 05 BA 3F 03 43 B0 12 36 05 D2 42 +0E 02 56 00 D2 42 0F 02 57 00 D2 42 10 02 16 02 +AD 3F B0 12 36 05 10 42 0E 02 16 42 0E 02 15 43 +07 3C 36 40 FE FF B2 40 06 A5 10 02 35 40 0C 00 +B2 40 00 A5 2C 01 92 42 10 02 28 01 B6 43 00 00 +92 B3 2C 01 FD 23 15 83 F3 23 36 90 FE FF CD 27 +37 40 80 00 36 F0 80 FF 36 90 00 11 0E 28 07 57 +36 F0 00 FF 36 90 00 12 08 28 07 57 36 F0 00 FE +04 3C 16 42 0E 02 17 42 10 02 35 43 75 96 03 20 +17 83 FC 23 B2 3F 82 46 00 02 B3 3F 36 40 E0 FF +37 40 20 00 B0 12 AC 05 7C 96 01 24 2B D3 17 83 +F9 23 2B C2 B0 12 9C 04 2B D2 9F 3F 16 42 0E 02 +17 42 10 02 2B B2 38 24 3B D0 10 00 B0 12 AC 05 +36 90 00 10 06 2C 36 90 00 01 09 2C C6 4C 00 00 +25 3C B2 40 00 A5 2C 01 B2 40 40 A5 28 01 16 B3 +03 20 C2 4C 14 02 1A 3C C2 4C 15 02 86 9A FD FF +08 24 2B D3 3B B0 20 00 04 20 3B D0 20 00 82 46 +00 02 36 90 01 02 04 28 3B D2 3B B0 10 00 02 24 +3B C0 32 00 1A 42 14 02 86 4A FF FF 16 53 17 83 +CD 23 B0 12 9C 04 61 3F B0 12 AC 05 17 83 FC 23 +B0 12 9C 04 5E 3F B2 40 F0 0F 0E 02 B2 40 10 00 +10 02 B2 40 80 00 0A 02 D2 42 10 02 0C 02 D2 42 +10 02 0D 02 82 43 12 02 09 43 36 40 0A 02 27 42 +7C 46 B0 12 40 05 17 83 FB 23 16 42 0E 02 17 42 +10 02 36 90 00 01 0A 28 B2 46 14 02 5C 42 14 02 +B0 12 40 05 17 83 5C 42 15 02 01 3C 7C 46 B0 12 +40 05 17 83 EE 23 B2 E3 12 02 5C 42 12 02 B0 12 +40 05 5C 42 13 02 B0 12 40 05 E0 3E 18 42 12 02 +B0 12 AC 05 C2 4C 12 02 B0 12 AC 05 C2 4C 13 02 +38 E3 3B B2 0A 24 86 9A FE FF 07 24 3B B0 20 00 +04 20 16 53 82 46 00 02 2B D3 18 92 12 02 08 23 +2B B3 06 23 30 41 E2 B2 28 00 FD 27 E2 B2 28 00 +FD 23 B2 40 24 02 60 01 E2 B2 28 00 FD 27 15 42 +70 01 05 11 05 11 05 11 82 45 02 02 05 11 82 45 +04 02 B2 80 1E 00 04 02 57 42 16 02 37 80 03 00 +05 11 05 11 17 53 FD 23 35 50 40 A5 82 45 2A 01 +35 42 B2 40 24 02 60 01 92 92 70 01 02 02 FC 2F +15 83 F7 23 09 43 7C 40 90 00 02 3C 7C 40 A0 00 +C2 43 07 02 C9 EC 12 02 19 E3 1B C3 55 42 07 02 +55 45 56 05 00 55 0C 2E 2E 2E 2E 2E 2E 2E 2E 1A +34 34 92 42 70 01 72 01 B2 50 0C 00 72 01 07 3C +1B B3 0B 20 82 43 62 01 92 B3 62 01 FD 27 E2 C3 +21 00 0A 3C 4C 11 F6 2B 1B E3 82 43 62 01 92 B3 +62 01 FD 27 E2 D3 21 00 92 52 02 02 72 01 D2 53 +07 02 F0 90 0C 00 61 FC D1 23 30 41 C2 43 09 02 +1B C3 55 42 09 02 55 45 BC 05 00 55 0C 56 56 56 +56 56 56 56 56 36 76 00 E2 B2 28 00 FD 23 92 42 +70 01 72 01 92 52 04 02 72 01 82 43 62 01 92 B3 +62 01 FD 27 E2 B2 28 00 1E 28 2B D3 1C 3C 4C 10 +1A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +01 28 1B E3 1B B3 01 24 2B D3 C9 EC 12 02 19 E3 +0A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +E6 2B 4C 10 1B E3 92 52 02 02 72 01 D2 53 09 02 +C0 3F 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +01 2C 2B D3 30 41 +q +""" + +F4X_BSL = """@0220 +24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 +F2 C0 32 00 00 00 B2 40 80 5A 20 01 32 D0 40 00 +C2 43 50 00 F2 40 98 00 51 00 F2 C0 80 00 52 00 +D2 D3 21 00 D2 D3 22 00 D2 C3 26 00 E2 C3 22 00 +E2 C3 26 00 B2 40 10 A5 2C 01 B2 40 00 A5 28 01 +3B C0 3A 00 B0 12 DE 04 82 43 12 02 09 43 36 40 +0A 02 37 42 B0 12 B4 05 C6 4C 00 00 16 53 17 83 +F9 23 D2 92 0C 02 0D 02 28 20 55 42 0B 02 75 90 +12 00 80 24 75 90 10 00 6D 24 B0 12 A4 04 55 42 +0B 02 75 90 18 00 31 24 75 90 1E 00 B8 24 75 90 +20 00 17 24 2B B2 11 24 75 90 16 00 22 24 75 90 +14 00 B3 24 75 90 1A 00 18 24 75 90 1C 00 45 24 +04 3C B0 12 3E 05 BE 3F 21 53 B0 12 44 05 BA 3F +03 43 B0 12 3E 05 D2 42 0E 02 50 00 D2 42 0F 02 +51 00 D2 42 10 02 16 02 AD 3F B0 12 3E 05 10 42 +0E 02 16 42 0E 02 15 43 07 3C 36 40 FE FF B2 40 +06 A5 10 02 35 40 0C 00 B2 40 00 A5 2C 01 92 42 +10 02 28 01 B6 43 00 00 92 B3 2C 01 FD 23 15 83 +F3 23 36 90 FE FF CD 27 37 40 80 00 36 F0 80 FF +36 90 00 11 0E 28 07 57 36 F0 00 FF 36 90 00 12 +08 28 07 57 36 F0 00 FE 04 3C 16 42 0E 02 17 42 +10 02 35 43 75 96 03 20 17 83 FC 23 B2 3F 82 46 +00 02 B3 3F 36 40 E0 FF 37 40 20 00 B0 12 B4 05 +7C 96 01 24 2B D3 17 83 F9 23 2B C2 B0 12 A4 04 +2B D2 9F 3F 16 42 0E 02 17 42 10 02 2B B2 38 24 +3B D0 10 00 B0 12 B4 05 36 90 00 10 06 2C 36 90 +00 01 09 2C C6 4C 00 00 25 3C B2 40 00 A5 2C 01 +B2 40 40 A5 28 01 16 B3 03 20 C2 4C 14 02 1A 3C +C2 4C 15 02 86 9A FD FF 08 24 2B D3 3B B0 20 00 +04 20 3B D0 20 00 82 46 00 02 36 90 01 02 04 28 +3B D2 3B B0 10 00 02 24 3B C0 32 00 1A 42 14 02 +86 4A FF FF 16 53 17 83 CD 23 B0 12 A4 04 61 3F +B0 12 B4 05 17 83 FC 23 B0 12 A4 04 5E 3F B2 40 +F0 0F 0E 02 B2 40 10 00 10 02 B2 40 80 00 0A 02 +D2 42 10 02 0C 02 D2 42 10 02 0D 02 82 43 12 02 +09 43 36 40 0A 02 27 42 7C 46 B0 12 48 05 17 83 +FB 23 16 42 0E 02 17 42 10 02 36 90 00 01 0A 28 +B2 46 14 02 5C 42 14 02 B0 12 48 05 17 83 5C 42 +15 02 01 3C 7C 46 B0 12 48 05 17 83 EE 23 B2 E3 +12 02 5C 42 12 02 B0 12 48 05 5C 42 13 02 B0 12 +48 05 E0 3E 18 42 12 02 B0 12 B4 05 C2 4C 12 02 +B0 12 B4 05 C2 4C 13 02 38 E3 3B B2 0A 24 86 9A +FE FF 07 24 3B B0 20 00 04 20 16 53 82 46 00 02 +2B D3 18 92 12 02 08 23 2B B3 06 23 30 41 E2 B3 +20 00 FD 27 E2 B3 20 00 FD 23 B2 40 24 02 60 01 +E2 B3 20 00 FD 27 15 42 70 01 05 11 05 11 05 11 +82 45 02 02 05 11 82 45 04 02 B2 80 1E 00 04 02 +57 42 16 02 37 80 03 00 05 11 05 11 17 53 FD 23 +35 50 40 A5 82 45 2A 01 35 42 B2 40 24 02 60 01 +92 92 70 01 02 02 FC 2F 15 83 F7 23 09 43 7C 40 +90 00 02 3C 7C 40 A0 00 C2 43 07 02 C9 EC 12 02 +19 E3 1B C3 55 42 07 02 55 45 5E 05 00 55 0C 2E +2E 2E 2E 2E 2E 2E 2E 1A 34 34 92 42 70 01 72 01 +B2 50 0C 00 72 01 07 3C 1B B3 0B 20 82 43 62 01 +92 B3 62 01 FD 27 D2 C3 21 00 0A 3C 4C 11 F6 2B +1B E3 82 43 62 01 92 B3 62 01 FD 27 D2 D3 21 00 +92 52 02 02 72 01 D2 53 07 02 F0 90 0C 00 59 FC +D1 23 30 41 C2 43 09 02 1B C3 55 42 09 02 55 45 +C4 05 00 55 0C 56 56 56 56 56 56 56 56 36 76 00 +E2 B3 20 00 FD 23 92 42 70 01 72 01 92 52 04 02 +72 01 82 43 62 01 92 B3 62 01 FD 27 E2 B3 20 00 +1E 28 2B D3 1C 3C 4C 10 1A 3C 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 01 28 1B E3 1B B3 01 24 +2B D3 C9 EC 12 02 19 E3 0A 3C 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 E6 2B 4C 10 1B E3 92 52 +02 02 72 01 D2 53 09 02 C0 3F 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 01 2C 2B D3 30 41 +q +""" + +CALIB_TABLES = """ +84 C0 16 FE FF FF FF FF FF FF FF FF FF FF FF FF +FF FF FF FF FF FF FF FF FF FF 10 08 80 00 00 01 +7E 27 0B 79 0D AA 7E 4D 06 DF 08 33 08 FE FF FF +FF FF FF FF FF FF 08 01 8F 95 8E 9A 8D 88 86 D1 +""" + +#cpu types for "change baudrate" +#use strings as ID so that they can be used in outputs too +F1x = "F1x family" +F2x = "F2x family" +F4x = "F4x family" + +#known device list +deviceids = { + 0xf149: F1x, + 0xf16c: F1x, #for GoodFET10 to '20 + 0xf112: F1x, + 0xf413: F4x, + 0xf123: F1x, + 0xf449: F4x, + 0x1232: F1x, + 0xf26f: F2x, #for GoodFET20 + 0xf227: F2x, #for GoodFET30 +} + +#GoodFET firmware +firmware = { + 0xf16c: "http://goodfet.sourceforge.net/dist/msp430x1612.hex", + 0xf26f: "http://goodfet.sourceforge.net/dist/msp430x2618.hex", + 0xf227: "http://goodfet.sourceforge.net/dist/msp430x2274.hex" +} + +class BSLException(Exception): + pass + +class LowLevel: + "lowlevel communication" + #Constants + MODE_SSP = 0 + MODE_BSL = 1 + + BSL_SYNC = 0x80 + BSL_TXPWORD = 0x10 + BSL_TXBLK = 0x12 #Transmit block to boot loader + BSL_UNLOCK_INFO = 0x12 #unlocks / locks info segment A Not working on msp430f2617 + BSL_RXBLK = 0x14 #Receive block from boot loader + BSL_ERASE = 0x16 #Erase one segment + BSL_MERAS = 0x18 #Erase complete FLASH memory + BSL_CHANGEBAUD = 0x20 #Change baudrate + BSL_LOADPC = 0x1A #Load PC and start execution + BSL_TXVERSION = 0x1E #Get BSL version + + #Upper limit of address range that might be modified by + #"BSL checksum bug". + BSL_CRITICAL_ADDR = 0x0A00 + + #Header Definitions + CMD_FAILED = 0x70 + DATA_FRAME = 0x80 + DATA_ACK = 0x90 + DATA_NAK = 0xA0 + + QUERY_POLL = 0xB0 + QUERY_RESPONSE = 0x50 + + OPEN_CONNECTION = 0xC0 + ACK_CONNECTION = 0x40 + + DEFAULT_TIMEOUT = 1 + DEFAULT_PROLONG = 10 + MAX_FRAME_SIZE = 256 + MAX_DATA_BYTES = 250 + MAX_DATA_WORDS = 125 + + MAX_FRAME_COUNT = 16 + + #Error messages + ERR_COM = "Unspecific error" + ERR_RX_NAK = "NAK received (wrong password?)" + #ERR_CMD_NOT_COMPLETED = "Command did not send ACK: indicates that it didn't complete correctly" + ERR_CMD_FAILED = "Command failed, is not defined or is not allowed" + ERR_BSL_SYNC = "Bootstrap loader synchronization error" + ERR_FRAME_NUMBER = "Frame sequence number error." + + def calcChecksum(self, data, length): + """Calculates a checksum of "data".""" + checksum = 0 + + for i in range(length/2): + checksum = checksum ^ (ord(data[i*2]) | (ord(data[i*2+1]) << 8)) #xor-ing + return 0xffff & (checksum ^ 0xffff) #inverting + + def __init__(self, aTimeout = None, aProlongFactor = None): + """init bsl object, don't connect yet""" + if aTimeout is None: + self.timeout = self.DEFAULT_TIMEOUT + else: + self.timeout = aTimeout + if aProlongFactor is None: + self.prolongFactor = self.DEFAULT_PROLONG + else: + self.prolongFactor = aProlongFactor + + #flags for inverted use of control pins + #used for some hardware + self.invertRST = 0 + self.invertTEST = 0 + self.swapRSTTEST = 0 + self.telosLatch = 0 + self.telosI2C = 0 + + self.z1 = 0 + + self.protocolMode = self.MODE_BSL + self.BSLMemAccessWarning = 0 #Default: no warning. + self.slowmode = 0 + + def comInit(self, port): + """Tries to open the serial port given and + initialises the port and variables. + The timeout and the number of allowed errors is multiplied by + 'aProlongFactor' after transmission of a command to give + plenty of time to the micro controller to finish the command. + Returns zero if the function is successful.""" + if DEBUG > 1: sys.stderr.write("* comInit()\n") + self.seqNo = 0 + self.reqNo = 0 + self.rxPtr = 0 + self.txPtr = 0 + # Startup-Baudrate: 9600,8,E,1, 1s timeout + self.serialport = serial.Serial( + port, + 9600, + parity = serial.PARITY_EVEN, + timeout = self.timeout + ) + if DEBUG: sys.stderr.write("using serial port %r\n" % self.serialport.portstr) + #self.SetRSTpin() #enable power + #self.SetTESTpin() #enable power + self.serialport.flushInput() + self.serialport.flushOutput() + + def comDone(self): + """Closes the used serial port. + This function must be called at the end of a program, + otherwise the serial port might not be released and can not be + used in other programs. + Returns zero if the function is successful.""" + if DEBUG > 1: sys.stderr.write("* comDone()") + self.SetRSTpin(1) #disable power + self.SetTESTpin(0) #disable power + self.serialport.close() + + def comRxHeader(self): + """receive header and split data""" + if DEBUG > 1: sys.stderr.write("* comRxHeader()\n") + + hdr = self.serialport.read(1) + if not hdr: raise BSLException("Timeout") + rxHeader = ord(hdr) & 0xf0; + rxNum = ord(hdr) & 0x0f; + + if self.protocolMode == self.MODE_BSL: + self.reqNo = 0 + self.seqNo = 0 + rxNum = 0 + if DEBUG > 1: sys.stderr.write("* comRxHeader() OK\n") + return rxHeader, rxNum + + def comRxFrame(self, rxNum): + if DEBUG > 1: sys.stderr.write("* comRxFrame()\n") + rxFrame = chr(self.DATA_FRAME | rxNum) + + if DEBUG > 2: sys.stderr.write(" comRxFrame() header...\n") + rxFramedata = self.serialport.read(3) + if len(rxFramedata) != 3: raise BSLException("Timeout") + rxFrame = rxFrame + rxFramedata + + if DEBUG > 3: sys.stderr.write(" comRxFrame() check header...\n") + if rxFrame[1] == chr(0) and rxFrame[2] == rxFrame[3]: #Add. header info. correct? + rxLengthCRC = ord(rxFrame[2]) + 2 #Add CRC-Bytes to length + if DEBUG > 2: sys.stderr.write(" comRxFrame() receiving data, size: %s\n" % rxLengthCRC) + + rxFramedata = self.serialport.read(rxLengthCRC) + if len(rxFramedata) != rxLengthCRC: raise BSLException("Timeout") + rxFrame = rxFrame + rxFramedata + #Check received frame: + if DEBUG > 3: sys.stderr.write(" comRxFrame() crc check\n") + #rxLength+4: Length with header but w/o CRC: + checksum = self.calcChecksum(rxFrame, ord(rxFrame[2]) + 4) + if rxFrame[ord(rxFrame[2])+4] == chr(0xff & checksum) and \ + rxFrame[ord(rxFrame[2])+5] == chr(0xff & (checksum >> 8)): #Checksum correct? + #Frame received correctly (=> send next frame) + if DEBUG > 2: sys.stderr.write("* comRxFrame() OK\n") + return rxFrame + else: + if DEBUG: sys.stderr.write(" comRxFrame() Checksum wrong\n") + else: + if DEBUG: sys.stderr.write(" comRxFrame() Header corrupt %r" % rxFrame) + raise BSLException(self.ERR_COM) #Frame has errors! + + def comTxHeader(self, txHeader): + """send header""" + if DEBUG > 1: sys.stderr.write("* txHeader()\n") + self.serialport.write(txHeader) + + def comTxRx(self, cmd, dataOut, length): + """Sends the command cmd with the data given in dataOut to the + microcontroller and expects either an acknowledge or a frame + with result from the microcontroller. The results are stored + in dataIn (if not a NULL pointer is passed). + In this routine all the necessary protocol stuff is handled. + Returns zero if the function was successful.""" + if DEBUG > 1: sys.stderr.write("* comTxRx()\n") + txFrame = [] + rxHeader = 0 + rxNum = 0 + + dataOut = list(dataOut) #convert to a list for simpler data fill in + #Transmitting part ---------------------------------------- + #Prepare data for transmit + if (length % 2) != 0: + #/* Fill with one byte to have even number of bytes to send */ + if self.protocolMode == self.MODE_BSL: + dataOut.append(0xFF) #fill with 0xFF + else: + dataOut.append(0) #fill with zero + + txFrame = "%c%c%c%c" % (self.DATA_FRAME | self.seqNo, cmd, len(dataOut), len(dataOut)) + + self.reqNo = (self.seqNo + 1) % self.MAX_FRAME_COUNT + + txFrame = txFrame + string.join(dataOut,'') + checksum = self.calcChecksum(txFrame, length + 4) + txFrame = txFrame + chr(checksum & 0xff) + txFrame = txFrame + chr((checksum >> 8) & 0xff) + + accessAddr = (0x0212 + (checksum^0xffff)) & 0xfffe #0x0212: Address of wCHKSUM + if self.BSLMemAccessWarning and accessAddr < self.BSL_CRITICAL_ADDR: + sys.stderr.write("WARNING: This command might change data at address %04x or %04x!\n" % (accessAddr, accessAddr + 1)) + + self.serialport.flushInput() #clear receiving queue + #TODO: Check after each transmitted character, + #TODO: if microcontroller did send a character (probably a NAK!). + for c in txFrame: + self.serialport.write(c) + if DEBUG > 3: sys.stderr.write("\ttx %02x" % ord(c)) + #if self.serialport.inWaiting(): break #abort when BSL replies, probably NAK + else: + if DEBUG > 1: sys.stderr.write( " comTxRx() transmit OK\n") + + #Receiving part ------------------------------------------- + rxHeader, rxNum = self.comRxHeader() #receive header + if DEBUG > 1: sys.stderr.write(" comTxRx() rxHeader=0x%02x, rxNum=%d, seqNo=%d, reqNo=%s\n" % (rxHeader, rxNum, self.seqNo, self.reqNo)) + if rxHeader == self.DATA_ACK: #acknowledge/OK + if DEBUG > 2: sys.stderr.write(" comTxRx() DATA_ACK\n") + if rxNum == self.reqNo: + self.seqNo = self.reqNo + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_ACK OK\n") + return #Acknowledge received correctly => next frame + raise BSLException(self.ERR_FRAME_NUMBER) + elif rxHeader == self.DATA_NAK: #not acknowledge/error + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_NAK\n") + raise BSLException(self.ERR_RX_NAK) + elif rxHeader == self.DATA_FRAME: #receive data + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_FRAME\n") + if rxNum == self.reqNo: + rxFrame = self.comRxFrame(rxNum) + return rxFrame + raise BSLException(self.ERR_FRAME_NUMBER) + elif rxHeader == self.CMD_FAILED: #Frame ok, but command failed. + if DEBUG > 2: sys.stderr.write("* comTxRx() CMD_FAILED\n") + raise BSLException(self.ERR_CMD_FAILED) + + raise BSLException("Unknown header 0x%02x\nAre you downloading to RAM into an old device that requires the patch? Try option -U" % rxHeader) + + def SetDTR(self, level, invert): + """Controls DTR pin (0: GND; 1: VCC; unless inverted flag is set)""" + #print 'fucking the dtr' + if invert: + self.serialport.setDTR(not level) + else: + self.serialport.setDTR(level) + if self.slowmode: + time.sleep(0.040) + + def SetRTS(self, level, invert): + """Controls RTS pin (0: GND; 1: VCC; unless inverted flag is set)""" + if invert: + self.serialport.setRTS(not level) + else: + self.serialport.setRTS(level) + if self.slowmode: + time.sleep(0.040) + + def SetRSTpin(self, level=1): + """Controls RST/NMI pin (0: GND; 1: VCC; unless inverted flag is set)""" + if self.swapRSTTEST: + self.SetRTS(level, self.invertRST) + else: + self.SetDTR(level, self.invertRST) + + def SetTESTpin(self, level=1): + """Controls TEST pin (inverted on board: 0: VCC; 1: GND; unless inverted flag is set)""" + if self.swapRSTTEST: + self.SetDTR(level, self.invertTEST) + else: + self.SetRTS(level, self.invertTEST) + + + def writepicROM(self, address, data): + ''' Writes data to @address''' + for i in range(7,-1,-1): + self.picROMclock((address >> i) & 0x01) + self.picROMclock(0) + recbuf = 0 + for i in range(7,-1,-1): + s = ((data >> i) & 0x01) + #print s + if i < 1: + r = not self.picROMclock(s, True) + else: + r = not self.picROMclock(s) + recbuf = (recbuf << 1) + r + + self.picROMclock(0, True) + #k = 1 + #while not self.serial.getCTS(): + # pass + #time.sleep(0.1) + return recbuf + + def readpicROM(self, address): + ''' reads a byte from @address''' + for i in range(7,-1,-1): + self.picROMclock((address >> i) & 0x01) + self.picROMclock(1) + recbuf = 0 + r = 0 + for i in range(7,-1,-1): + r = self.picROMclock(0) + recbuf = (recbuf << 1) + r + self.picROMclock(r) + #time.sleep(0.1) + return recbuf + + def picROMclock(self, masterout, slow = False): + #print "setting masterout to "+str(masterout) + self.serialport.setRTS(masterout) + self.serialport.setDTR(1) + #time.sleep(0.02) + self.serialport.setDTR(0) + if slow: + time.sleep(0.02) + return self.serialport.getCTS() + + def picROMfastclock(self, masterout): + #print "setting masterout to "+str(masterout) + self.serialport.setRTS(masterout) + self.serialport.setDTR(1) + self.serialport.setDTR(0) + time.sleep(0.02) + return self.serialport.getCTS() + + def bslResetZ1(self, invokeBSL=0): + ''' + Applies BSL entry sequence on RST/NMI and TEST/VPP pins + Parameters: + invokeBSL = 1: complete sequence + invokeBSL = 0: only RST/NMI pin accessed + + By now only BSL mode is accessed + ''' + + if DEBUG > 1: sys.stderr.write("* bslReset(invokeBSL=%s)\n" % invokeBSL) + if invokeBSL: + #sys.stderr.write("in Z1 bsl reset...\n") + time.sleep(0.1) + self.writepicROM(0xFF, 0xFF) + time.sleep(0.1) + #sys.stderr.write("z1 bsl reset done...\n") + else: + #sys.stderr.write("in Z1 reset...\n") + time.sleep(0.1) + self.writepicROM(0xFF, 0xFE) + time.sleep(0.1) + #sys.stderr.write("z1 reset done...\n") + + def telosSetSCL(self, level): + self.serialport.setRTS(not level) + + def telosSetSDA(self, level): + self.serialport.setDTR(not level) + + def telosI2CStart(self): + self.telosSetSDA(1) + self.telosSetSCL(1) + self.telosSetSDA(0) + + def telosI2CStop(self): + self.telosSetSDA(0) + self.telosSetSCL(1) + self.telosSetSDA(1) + + def telosI2CWriteBit(self, bit): + self.telosSetSCL(0) + self.telosSetSDA(bit) + time.sleep(2e-6) + self.telosSetSCL(1) + time.sleep(1e-6) + self.telosSetSCL(0) + + def telosI2CWriteByte(self, byte): + self.telosI2CWriteBit( byte & 0x80 ); + self.telosI2CWriteBit( byte & 0x40 ); + self.telosI2CWriteBit( byte & 0x20 ); + self.telosI2CWriteBit( byte & 0x10 ); + self.telosI2CWriteBit( byte & 0x08 ); + self.telosI2CWriteBit( byte & 0x04 ); + self.telosI2CWriteBit( byte & 0x02 ); + self.telosI2CWriteBit( byte & 0x01 ); + self.telosI2CWriteBit( 0 ); # "acknowledge" + + def telosI2CWriteCmd(self, addr, cmdbyte): + self.telosI2CStart() + self.telosI2CWriteByte( 0x90 | (addr << 1) ) + self.telosI2CWriteByte( cmdbyte ) + self.telosI2CStop() + + def telosBReset(self,invokeBSL=0): + # "BSL entry sequence at dedicated JTAG pins" + # rst !s0: 0 0 0 0 1 1 + # tck !s1: 1 0 1 0 0 1 + # s0|s1: 1 3 1 3 2 0 + + # "BSL entry sequence at shared JTAG pins" + # rst !s0: 0 0 0 0 1 1 + # tck !s1: 0 1 0 1 1 0 + # s0|s1: 3 1 3 1 0 2 + if invokeBSL: + self.telosI2CWriteCmd(0,1) + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,1) + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,2) + self.telosI2CWriteCmd(0,0) + else: + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,2) + self.telosI2CWriteCmd(0,0) + time.sleep(0.250) #give MSP430's oscillator time to stabilize + self.serialport.flushInput() #clear buffers + + def bslReset(self, invokeBSL=0): + """Applies BSL entry sequence on RST/NMI and TEST/VPP pins + Parameters: + invokeBSL = 1: complete sequence + invokeBSL = 0: only RST/NMI pin accessed + + RST is inverted twice on boot loader hardware + TEST is inverted (only once) + Need positive voltage on DTR, RTS for power-supply of hardware""" + + #print 'goint to reset!' + + if self.telosI2C: + self.telosBReset(invokeBSL) + return + + if self.z1: + if DEBUG > 1: sys.stderr.write("* entering bsl with z1\n") + self.bslResetZ1(invokeBSL) + return + + if DEBUG > 1: sys.stderr.write("* bslReset(invokeBSL=%s)\n" % invokeBSL) + self.SetRSTpin(1) #power suply + self.SetTESTpin(1) #power suply + time.sleep(0.250) #charge capacitor on boot loader hardware + + if self.telosLatch: + self.SetTESTpin(0) + self.SetRSTpin(0) + self.SetTESTpin(1) + + self.SetRSTpin(0) #RST pin: GND + if invokeBSL: + self.SetTESTpin(1) #TEST pin: GND + self.SetTESTpin(0) #TEST pin: Vcc + self.SetTESTpin(1) #TEST pin: GND + self.SetTESTpin(0) #TEST pin: Vcc + self.SetRSTpin (1) #RST pin: Vcc + self.SetTESTpin(1) #TEST pin: GND + else: + self.SetRSTpin(1) #RST pin: Vcc + time.sleep(0.250) #give MSP430's oscillator time to stabilize + + self.serialport.flushInput() #clear buffers + + def bslSync(self,wait=0): + """Transmits Synchronization character and expects to receive Acknowledge character + if wait is 0 it must work the first time. otherwise if wait is 1 + it is retried (forever). + """ + loopcnt = 5 #Max. tries to get synchronization + + if DEBUG > 1: sys.stderr.write("* bslSync(wait=%d)\n" % wait) + while wait or loopcnt: + loopcnt = loopcnt - 1 #count down tries + self.serialport.flushInput() #clear input, in case a prog is running + + self.serialport.write(chr(self.BSL_SYNC)) #Send synchronization byte + c = self.serialport.read(1) #read answer + if c == chr(self.DATA_ACK): #ACk + if DEBUG > 1: sys.stderr.write(" bslSync() OK\n") + return #Sync. successful + elif not c: #timeout + if loopcnt > 4: + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout, retry ...\n") + elif loopcnt == 4: + #nmi may have caused the first reset to be ignored, try again + self.bslReset(0) + self.bslReset(1) + elif loopcnt > 0: + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout, retry ...\n") + else : + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout\n") + else: #garbage + if DEBUG > 1: sys.stderr.write(" bslSync() failed (0x%02x), retry ...\n" % ord(c)) + + raise BSLException(self.ERR_BSL_SYNC) #Sync. failed + + def bslTxRx(self, cmd, addr, length = 0, blkout = None, wait=0): + """Transmits a command (cmd) with its parameters: + start-address (addr), length (len) and additional + data (blkout) to boot loader. + wait specified if the bsl sync should be tried once or + repeated, forever + Parameters return by boot loader are passed via blkin. + """ + if DEBUG > 1: sys.stderr.write("* bslTxRx()\n") + + if cmd == self.BSL_TXBLK: + #Align to even start address + if (addr % 2) != 0: + addr = addr - 1 #Decrement address and + blkout = chr(0xFF) + blkOut #fill first byte of blkout with 0xFF + length = length + 1 + #Make sure that len is even + if (length % 2) != 0: + blkout = blkout + chr(0xFF) #Inc. len and fill last byte of blkout with 0xFF + length = length + 1 + + elif cmd == self.BSL_RXBLK: + #Align to even start address + if (addr % 2) != 0: + addr = addr - 1 #Decrement address but + length = length + 1 #request an additional byte + #Make sure that len is even + if (length % 2) != 0: + length = length + 1 + + #if cmd == self.BSL_TXBLK or cmd == self.BSL_TXPWORD: + # length = len + 4 + + #Add necessary information data to frame + dataOut = struct.pack("= 1: + #Read one line + l = file.readline() + if not l: break #EOF + l = l.strip() + if l[0] == 'q': break + elif l[0] == '@': #if @ => new address => send frame and set new addr. + #create a new segment + if segmentdata: + self.segments.append( Segment(startAddr, string.join(segmentdata,'')) ) + startAddr = int(l[1:],16) + segmentdata = [] + else: + for i in string.split(l): + segmentdata.append(chr(int(i,16))) + if segmentdata: + self.segments.append( Segment(startAddr, string.join(segmentdata,'')) ) + + def loadELF(self, file): + """load data from a (opened) file in ELF object format. + File must be seekable""" + import elf + obj = elf.ELFObject() + obj.fromFile(file) + if obj.e_type != elf.ELFObject.ET_EXEC: + raise Exception("No executable") + for section in obj.getSections(): + if DEBUG: + sys.stderr.write("ELF section %s at 0x%04x %d bytes\n" % (section.name, section.lma, len(section.data))) + if len(section.data): + self.segments.append( Segment(section.lma, section.data) ) + + def loadFile(self, filename): + """fill memory with the contents of a file. file type is determined from extension""" + #TODO: do a contents based detection + if filename[-4:].lower() == '.txt': + self.loadTIText(open(filename, "rb")) + elif filename[-4:].lower() in ('.a43', '.hex'): + self.loadIHex(open(filename, "rb")) + else: + self.loadELF(open(filename, "rb")) + + def getMemrange(self, fromadr, toadr): + """get a range of bytes from the memory. unavailable values are filled with 0xff.""" + res = '' + toadr = toadr + 1 #python indxes are excluding end, so include it + while fromadr < toadr: + #print "fromto: %04x %04x" % (fromadr, toadr) + for seg in self.segments: + #print seg + segend = seg.startaddress + len(seg.data) + if seg.startaddress <= fromadr and fromadr < segend: + #print "startok 0x%04x %d" % (seg.startaddress, len(seg.data)) + #print ("0x%04x "*3) % (segend, fromadr, toadr) + if toadr > segend: #not all data in segment + #print "out of segment" + catchlength = segend-fromadr + else: + catchlength = toadr-fromadr + #print toadr-fromadr + #print catchlength + res = res + seg.data[fromadr-seg.startaddress : fromadr-seg.startaddress+catchlength] + fromadr = fromadr + catchlength #adjust start + if len(res) >= toadr-fromadr: + break#return res + else: + res = res + chr(255) + fromadr = fromadr + 1 #adjust start + #print "fill FF" + #print "res: %r" % res + return res + + +class BootStrapLoader(LowLevel): + """higher level Bootstrap Loader functions.""" + + ERR_VERIFY_FAILED = "Error: verification failed" + ERR_ERASE_CHECK_FAILED = "Error: erase check failed" + + ACTION_PROGRAM = 0x01 #Mask: program data + ACTION_VERIFY = 0x02 #Mask: verify data + ACTION_ERASE_CHECK = 0x04 #Mask: erase check + + #Max. bytes sent within one frame if parsing a TI TXT file. + #( >= 16 and == n*16 and <= MAX_DATA_BYTES!) + MAXDATA = 240-16 + + + def __init__(self, *args, **kargs): + LowLevel.__init__(self, *args, **kargs) + self.byteCtr = 0 + self.meraseCycles = 1 + self.patchRequired = 0 + self.patchLoaded = 0 + self.bslVer = 0 + self.passwd = None + self.data = None + self.maxData = self.MAXDATA + self.cpu = None + self.pwdsent = False + + + def preparePatch(self): + """prepare to download patch""" + if DEBUG > 1: sys.stderr.write("* preparePatch()\n") + + if self.patchLoaded: + #Load PC with 0x0220. + #This will invoke the patched bootstrap loader subroutines. + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + 0x0220) #Address to load into PC + self.BSLMemAccessWarning = 0 #Error is removed within workaround code + return + + def postPatch(self): + """setup after the patch is loaded""" + if DEBUG > 1: sys.stderr.write("* postPatch()\n") + if self.patchLoaded: + self.BSLMemAccessWarning = 1 #Turn warning back on. + + + def verifyBlk(self, addr, blkout, action): + """verify memory against data or 0xff""" + if DEBUG > 1: sys.stderr.write("* verifyBlk()\n") + + if action & self.ACTION_VERIFY or action & self.ACTION_ERASE_CHECK: + if DEBUG: sys.stderr.write(" Check starting at 0x%04x, %d bytes ... \n" % (addr, len(blkout))) + + self.preparePatch() + blkin = self.bslTxRx(self.BSL_RXBLK, addr, len(blkout)) + self.postPatch() + + for i in range(len(blkout)): + if action & self.ACTION_VERIFY: + #Compare data in blkout and blkin + if blkin[i] != blkout[i]: + sys.stderr.write("Verification failed at 0x%04x (0x%02x, 0x%02x)\n" % (addr+i, ord(blkin[i]), ord(blkout[i]))) + sys.stderr.flush() + raise BSLException(self.ERR_VERIFY_FAILED) #Verify failed! + continue + elif action & self.ACTION_ERASE_CHECK: + #Compare data in blkin with erase pattern + if blkin[i] != chr(0xff): + sys.stderr.write("Erase Check failed at 0x%04x (0x%02x)\n" % (addr+i, ord(blkin[i]))) + sys.stderr.flush() + raise BSLException(self.ERR_ERASE_CHECK_FAILED) #Erase Check failed! + continue + def readBlk(self,adr,len): + """Read a block of memory.""" + blkin = self.bslTxRx(self.BSL_RXBLK, addr, len(blkout)) + + def programBlk(self, addr, blkout, action): + """program a memory block""" + if DEBUG > 1: sys.stderr.write("* programBlk()\n") + + #Check, if specified range is erased + self.verifyBlk(addr, blkout, action & self.ACTION_ERASE_CHECK) + + if action & self.ACTION_PROGRAM: + if DEBUG: sys.stderr.write(" Program starting at 0x%04x, %i bytes ...\n" % (addr, len(blkout))) + self.preparePatch() + #Program block + self.bslTxRx(self.BSL_TXBLK, addr, len(blkout), blkout) + self.postPatch() + + #Verify block + self.verifyBlk(addr, blkout, action & self.ACTION_VERIFY) + + #segments: + #list of tuples or lists: + #segements = [ (addr1, [d0,d1,d2,...]), (addr2, [e0,e1,e2,...])] + def programData(self, segments, action): + """programm or verify data""" + if DEBUG > 1: sys.stderr.write("* programData()\n") + for seg in segments: + currentAddr = seg.startaddress + pstart = 0 + while pstart len(seg.data): + length = len(seg.data) - pstart + self.programBlk(currentAddr, seg.data[pstart:pstart+length], action) + pstart = pstart + length + currentAddr = currentAddr + length + self.byteCtr = self.byteCtr + length #total sum + + def uploadData(self, startaddress, size, wait=0): + """upload a datablock""" + if DEBUG > 1: sys.stderr.write("* uploadData()\n") + data = '' + pstart = 0 + while pstart size: + length = size - pstart + data = data + self.bslTxRx(self.BSL_RXBLK, + pstart+startaddress, + length, + wait=wait)[:-2] #cut away checksum + pstart = pstart + length + return data + + def txPasswd(self, passwd=None, wait=0): + """transmit password, default if None is given.""" + if DEBUG > 1: sys.stderr.write("* txPassword(%r)\n" % passwd) + if passwd is None or self.pwdsent: + #Send "standard" password to get access to protected functions. + sys.stderr.write("Transmit default password ...\n") + sys.stderr.flush() + #Flash is completely erased, the contents of all Flash cells is 0xff + passwd = chr(0xff)*32 + else: + #sanity check of password + if len(passwd) != 32: + raise ValueError, "password has wrong length (%d)\n" % len(passwd) + sys.stderr.write('Transmit password ...\n') + sys.stderr.flush() + #send the password + self.bslTxRx(self.BSL_TXPWORD, #Command: Transmit Password + 0xffe0, #Address of interupt vectors + 0x0020, #Number of bytes + passwd, #password + wait=wait) #if wait is 1, try to sync forever + self.pwdsent = True + + + def getNewPassword(self): + print 'getting new password' + newpassword = self.bslTxRx(self.BSL_RXBLK, 0xffe0, 0x0020) + return newpassword + + + def writeCalibTables(self): + print 'writing new tables' + print CALIB_TABLES + calibtables = ["84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", + "FFFFFFFFFFFFFFFFFFFF100880000001", + "7E270B790DAA7E4D06DF083308FEFFFF", + "FFFFFFFFFFFF08018F958E9A8D8886D1"] + self.programBlk(0x10C0, "84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", self.ACTION_PROGRAM) + self.programBlk(0x10D0, "FFFFFFFFFFFFFFFFFFFF100880000001", self.ACTION_PROGRAM) + self.programBlk(0x10E0, "7E270B790DAA7E4D06DF083308FEFFFF", self.ACTION_PROGRAM) + self.programBlk(0x10F0, "FFFFFFFFFFFF08018F958E9A8D8886D1", self.ACTION_PROGRAM) + + def writeCalibTables2(self): + print 'writing new tables 2ond part' + #self.programBlk(0x10C0, "84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", self.ACTION_PROGRAM) + #self.programBlk(0x10D0, "FFFFFFFFFFFFFFFFFFFF100880000001", self.ACTION_PROGRAM) + #self.programBlk(0x10E0, "7E270B790DAA7E4D06DF083308FEFFFF", self.ACTION_PROGRAM) + #self.programBlk(0x10F0, "FFFFFFFFFFFF08018F958E9A8D8886D1", self.ACTION_PROGRAM) + + def actionSecureInfoSegment(self): + print 'securing info segment' + self.programBlk(0xFFBE, "0000", self.ACTION_PROGRAM) + print 'info segment secured' + + #----------------------------------------------------------------- + + def actionMassErase(self): + """Erase the flash memory completely (with mass erase command)""" + sys.stderr.write("Mass Erase...\n") + sys.stderr.flush() + self.bslReset(1) #Invoke the boot loader. + for i in range(self.meraseCycles): + if i == 1: sys.stderr.write("Additional Mass Erase Cycles...\n") + self.bslTxRx(self.BSL_MERAS, #Command: Mass Erase + 0xff00, #Any address within flash memory. + 0xa506) #Required setting for mass erase! + self.passwd = None #No password file required! + #print "Mass Erase complete" + #Transmit password to get access to protected BSL functions. + self.txPasswd() + + def actionMainErase(self): + """Erase the main flash memory only""" + sys.stderr.write("Main Erase...\n") + sys.stderr.flush() + self.bslTxRx(self.BSL_ERASE, #Command: Segment Erase + 0xfffe, #Any address within flash memory. + 0xa504) #Required setting for main erase! + #self.passwd = None #Password gets erased WHY?? + + + + def actionStartBSL(self, usepatch=1, adjsp=1, replacementBSL=None, forceBSL=0, mayuseBSL=0, speed=None, bslreset=1): + """start BSL, download patch if desired and needed, adjust SP if desired""" + sys.stderr.write("Invoking BSL...\n") + sys.stderr.flush() + + #for '30, invertTEST=0, else =1 + if bslreset: + #detext if is z1? + self.bslReset(1) #Invoke the boot loader. + + + if(self.z1): + ''' recover password from pic''' + + self.txPasswd(self.passwd) #transmit password + + #Read actual bootstrap loader version. + #sys.stderr.write("Reading BSL version ...\n") + blkin = self.bslTxRx(self.BSL_RXBLK, #Command: Read/Receive Block + 0x0ff0, #Start address + 16) #No. of bytes to read + dev_id, bslVerHi, bslVerLo = struct.unpack(">H8xBB4x", blkin[:-2]) #cut away checksum and extract data + self.dev_id=dev_id; + + + if self.cpu is None: #cpy type forced? + if deviceids.has_key(dev_id): + self.cpu = deviceids[dev_id] #try to autodectect CPU type + + if DEBUG: + sys.stderr.write("Autodetect successful: %04x -> %s\n" % (dev_id, self.cpu)) + else: + sys.stderr.write("Autodetect failed! Unkown ID: %04x. Trying to continue anyway.\n" % dev_id) + self.cpu = F1x #assume something and try anyway.. + + sys.stderr.write("Current bootstrap loader version: %x.%x (Device ID: %04x)\n" % (bslVerHi, bslVerLo, dev_id)) + sys.stderr.flush() + self.bslVer = (bslVerHi << 8) | bslVerLo + + if self.bslVer <= 0x0110: #check if patch is needed + self.BSLMemAccessWarning = 1 + else: + self.BSLMemAccessWarning = 0 #Fixed in newer versions of BSL. + + if self.bslVer <= 0x0130 and adjsp: + #only do this on BSL where it's needed to prevent + #malfunction with F4xx devices/ newer ROM-BSLs + + #Execute function within bootstrap loader + #to prepare stack pointer for the following patch. + #This function will lock the protected functions again. + sys.stderr.write("Adjust SP. Load PC with 0x0C22 ...\n") + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + 0x0C22) #Address to load into PC + #Re-send password to re-gain access to protected functions. + self.txPasswd(self.passwd) + + #get internal BSL replacement if needed or forced by the user + #required if speed is set but an old BSL is in the device + #if a BSL is given by the user, that one is used and not the internal one + if ((mayuseBSL and speed and self.bslVer < 0x0150) or forceBSL) and replacementBSL is None: + replacementBSL = Memory() #File to program + if self.cpu == F4x: + if DEBUG: + sys.stderr.write("Using built in BSL replacement for F4x devices\n") + sys.stderr.flush() + replacementBSL.loadTIText(cStringIO.StringIO(F4X_BSL)) #parse embedded BSL + else: + if DEBUG: + sys.stderr.write("Using built in BSL replacement for F1x devices\n") + sys.stderr.flush() + replacementBSL.loadTIText(cStringIO.StringIO(F1X_BSL)) #parse embedded BSL + + #now download the new BSL, if allowed and needed (version lower than the + #the replacement) or forced + if replacementBSL is not None: + self.actionDownloadBSL(replacementBSL) + + #debug message with the real BSL version in use (may have changed after replacement BSL) + if DEBUG: + sys.stderr.write("Current bootstrap loader version: 0x%04x\n" % (self.bslVer,)) + sys.stderr.flush() + + #now apply workarounds or patches if BSL in use requires that + if self.bslVer <= 0x0110: #check if patch is needed + if usepatch: #test if patch is desired + sys.stderr.write("Patch for flash programming required!\n") + self.patchRequired = 1 + + sys.stderr.write("Load and verify patch ...\n") + sys.stderr.flush() + #Programming and verification is done in one pass. + #The patch file is only read and parsed once. + segments = Memory() #data to program + segments.loadTIText(cStringIO.StringIO(PATCH)) #parse embedded patch + #program patch + self.programData(segments, self.ACTION_PROGRAM | self.ACTION_VERIFY) + self.patchLoaded = 1 + else: + if DEBUG: + sys.stderr.write("Device needs patch, but not applied (usepatch is false).\n") #message if not patched + + #should the baudrate be changed? + if speed is not None: + self.actionChangeBaudrate(speed) #change baudrate + + def actionDownloadBSL(self, bslsegments): + sys.stderr.write("Load new BSL into RAM...\n") + sys.stderr.flush() + self.programData(bslsegments, self.ACTION_PROGRAM) + sys.stderr.write("Verify new BSL...\n") + sys.stderr.flush() + self.programData(bslsegments, self.ACTION_VERIFY) #File to verify + + #Read startvector of bootstrap loader + #blkin = self.bslTxRx(self.BSL_RXBLK, 0x0300, 2) + #blkin = self.bslTxRx(self.BSL_RXBLK, 0x0220, 2) + blkin = self.bslTxRx(self.BSL_RXBLK, bslsegments[0].startaddress, 2) + startaddr = struct.unpack("%s" % (firmware[self.dev_id],fn)) + + fw=Memory(fn); + #fw.loadIhex(open(fn,"rb")); + + sys.stderr.write("Program ...\n") + sys.stderr.flush() + self.programData(fw, self.ACTION_PROGRAM | self.ACTION_VERIFY) + sys.stderr.write("%i bytes programmed.\n" % self.byteCtr) + sys.stderr.flush() + + def actionVerify(self): + """Verify programmed data""" + if self.data is not None: + sys.stderr.write("Verify ...\n") + sys.stderr.flush() + self.programData(self.data, self.ACTION_VERIFY) + else: + raise BSLException, "verify without data not possible" + + def actionReset(self): + """perform a reset, start user programm""" + sys.stderr.write("Reset device ...\n") + sys.stderr.flush() + self.bslReset(0) #only reset + + def actionRun(self, address=0x220): + """start program at specified address""" + sys.stderr.write("Load PC with 0x%04x ...\n" % address) + sys.stderr.flush() + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + address) #Address to load into PC + + #table with values from slaa089a.pdf + bauratetable = { + F1x: { + 9600:[0x8580, 0x0000], + 19200:[0x86e0, 0x0001], + 38400:[0x87e0, 0x0002], + }, + F2x: { + 9600:[0x8580, 0x0000], + 19200:[0x8B00, 0x0001], + 38400:[0x8C80, 0x0002], + }, + F4x: { + 9600:[0x9800, 0x0000], + 19200:[0xb000, 0x0001], + 38400:[0xc800, 0x0002], + }, + } + def actionChangeBaudrate(self, baudrate=9600): + """change baudrate. first the command is sent, then the comm + port is reprogrammed. only possible with newer MSP430-BSL versions. + (ROM >=1.6, downloadable >=1.5)""" + try: + baudconfigs = self.bauratetable[self.cpu] + except KeyError: + raise ValueError, "unknown CPU type %s, can't switch baudrate" % self.cpu + try: + a,l = baudconfigs[baudrate] + except KeyError: + raise ValueError, "baudrate not valid. valid values are %r" % baudconfigs.keys() + + sys.stderr.write("Changing baudrate to %d ...\n" % baudrate) + sys.stderr.flush() + self.bslTxRx(self.BSL_CHANGEBAUD, #Command: change baudrate + a, l) #args are coded in adr and len + self.serialport.flush() + time.sleep(0.010) #recomended delay + self.serialport.baudrate = baudrate + + def actionReadBSLVersion(self): + """informational output of BSL version number. + (newer MSP430-BSLs only)""" + ans = self.bslTxRx(self.BSL_TXVERSION, 0) #Command: receive version info + #the following values are in big endian style!!! + family_type, bsl_version = struct.unpack(">H8xH4x", ans[:-2]) #cut away checksum and extract data + print "Device Type: 0x%04x\nBSL version: 0x%04x\n" % (family_type, bsl_version) + + def actionWriteNewPassword(self): + passwd = self.getNewPassword() + #print passwd + self.picWritePassword(passwd) + + def actionRecoverPassword(self): + p = self.picRecoverPassword() + #print p + self.passwd = p + + def picRecoverPassword(self): + ''' recovers password from picrom''' + print 'recovering pic password', + p = '' + + for i in range(0,32): + c = self.readpicROM(i) + print c, + p = p + chr(c) + + print 'done' + return p + + def picWritePassword(self, password): + ''' writes a new password to picrom''' + print 'writing new password', + for i in range(0,32): + c = ord(password[i]) + print c, + self.writepicROM(i, c) + print 'done' + + +def usage(): + """print some help message""" + sys.stderr.write(""" +USAGE: %s [options] [file] +Version: %s + +If "-" is specified as file the data is read from the stdinput. +A file ending with ".txt" is considered to be in TIText format, +'.a43' and '.hex' as IntelHex and all other filenames are +considered as ELF files. + +General options: + -h, --help Show this help screen. + -c, --comport=port Specify the communication port to be used. + (Default is 0) + 0->COM1 / ttyS0 + 1->COM2 / ttyS1 + etc. + -P, --password=file Specify a file with the interrupt vectors that + are used as password. This can be any file that + has previously been used to program the device. + (e.g. -P INT_VECT.TXT). + -f, --framesize=num Max. number of data bytes within one transmitted + frame (16 to 240 in steps of 16) (e.g. -f 240). + -m, --erasecycles=num Number of mass erase cycles (default is 1). Some + old F149 devices need additional erase cycles. + On newer devices it is no longer needed. (e.g. for + an old F149: -m20) + -U, --unpatched Do not download the BSL patch, even when it is + needed. This is used when a program is downloaded + into RAM and executed from there (and where flash + programming is not needed.) + -D, --debug Increase level of debug messages. This won't be + very useful for the average user... + -I, --intelhex Force fileformat to IntelHex + -T, --titext Force fileformat to be TIText + -N, --notimeout Don't use timeout on serial port (use with care) + -B, --bsl=bsl.txt Load and use new BSL from the TI Text file + -S, --speed=baud Reconfigure speed, only possible with newer + MSP403-BSL versions (>1.5, read slaa089a.pdf for + details). If the --bsl option is not used, an + internal BSL replacement will be loaded. + Needs a target with at least 2kB RAM! + Possible values are 9600, 19200, 38400 + (default 9600) + -1, --f1x Specify CPU family, in case autodetect fails + -2, --f2x Specify CPU family, in case autodetect fails + -4, --f4x Specify CPU family, in case autodetect fails + --F1x and --f2x are only needed when the "change + baudrate" feature is used and the autodetect feature + fails. If the device ID that is uploaded is known, it + has precedence to the command line option. + --invert-reset Invert signal on RST pin (used for some BSL hardware) + --invert-test Invert signal on TEST/TCK pin (used for some BSL + hardware) + --swap-reset-test Swap the RST and TEST pins (used for some BSL hardware) + --telos-latch Special twiddle in BSL reset for Telos hardware + --telos-i2c DTR/RTS map via an I2C switch to TCK/RST in Telos Rev.B + --telos Implies options --invert-reset, --invert-test, + --swap-reset-test, and --telos-latch + --telosb Implies options --swap-reset-test, --telos-i2c, + --no-BSL-download, and --speed=38400 + --goodfet10 + --goodfet20 + --goodfet30 + --tmote Identical operation to --telosb + --z1 Bootstrap a Z1 + --no-BSL-download Do not download replacement BSL (disable automatic) + --force-BSL-download Download replacement BSL even if not needed (the one + in the device would have the required features) + --slow Add delays when operating the conrol pins. Useful if + the pins/circuit has high capacitance. + +Program Flow Specifiers: + -e, --masserase Mass Erase (clear all flash memory) + -E, --erasecheck Erase Check by file + -p, --program Program file + -v, --verify Verify by file + +The order of the above options matters! The table is ordered by normal +execution order. For the options "Epv" a file must be specified. +Program flow specifiers default to "pvr" if a file is given. +Don't forget to specify "e" or "eE" when programming flash! + +Data retreiving: + -u, --upload=addr Upload a datablock (see also: -s). + -s, --size=num Size of the data block do upload. (Default is 2) + -x, --hex Show a hexadecimal display of the uploaded data. + (Default) + -b, --bin Get binary uploaded data. This can be used + to redirect the output into a file. + +Do before exit: + -g, --go=address Start programm execution at specified address. + This implies option --wait. + -r, --reset Reset connected MSP430. Starts application. + This is a normal device reset and will start + the programm that is specified in the reset + vector. (see also -g) + -w, --wait Wait for before closing serial port. + +If it says "NAK received" it's probably because you specified no or a +wrong password. +""" % (sys.argv[0], VERSION)) + +#add some arguments to a function, but don't call it yet, instead return +#a wrapper object for later invocation +class curry: + """create a callable with some arguments specified in advance""" + def __init__(self, fun, *args, **kwargs): + self.fun = fun + self.pending = args[:] + self.kwargs = kwargs.copy() + + def __call__(self, *args, **kwargs): + if kwargs and self.kwargs: + kw = self.kwargs.copy() + kw.update(kwargs) + else: + kw = kwargs or self.kwargs + return apply(self.fun, self.pending + args, kw) + + def __repr__(self): + #first try if it a function + try: + return "curry(%s, %r, %r)" % (self.fun.func_name, self.pending, self.kwargs) + except AttributeError: + #fallback for callable classes + return "curry(%s, %r, %r)" % (self.fun, self.pending, self.kwargs) + +def hexify(line, bytes, width=16): + return '%04x %s%s %s' % ( + line, + ('%02x '*len(bytes)) % tuple(bytes), + ' '* (width-len(bytes)), + ('%c'*len(bytes)) % tuple(map(lambda x: (x>=32 and x<127) and x or ord('.'), bytes)) + ) + +#Main: +def main(itest=1): + global DEBUG + import getopt + filetype = None + filename = None + comPort = None #Default setting. + speed = None + unpatched = 0 + reset = 0 + wait = 0 #wait at the end + goaddr = None + bsl = BootStrapLoader() + toinit = [] + todo = [] + startaddr = None + size = 2 + hexoutput = 1 + notimeout = 0 + bslrepl = None + mayuseBSL = 1 + forceBSL = 0 + dumpivt = 0 + dumpinfo = 0 + + bsl.invertRST = 1 + bsl.invertTEST = itest + + if comPort is None and os.environ.get("GOODFET")!=None: + glob_list = glob.glob(os.environ.get("GOODFET")); + if len(glob_list) > 0: + comPort = glob_list[0]; + if comPort is None: + glob_list = glob.glob("/dev/tty.usbserial*"); + if len(glob_list) > 0: + comPort = glob_list[0]; + if comPort is None: + glob_list = glob.glob("/dev/ttyUSB*"); + if len(glob_list) > 0: + comPort = glob_list[0]; + + + sys.stderr.write("MSP430 Bootstrap Loader Version: %s\n" % VERSION) + + try: + opts, args = getopt.getopt(sys.argv[1:], + "hc:P:wf:m:neEpvrg:UDudsxbITNB:S:V14", + ["help", "comport=", "password=", "wait", "framesize=", + "erasecycles=", "masserase", "erasecheck", "program", + "verify", "reset", "go=", "unpatched", "debug", + "upload=", "download=", "size=", "hex", "bin", + "intelhex", "titext", "notimeout", "bsl=", "speed=", + "bslversion", "f1x", "f2x", "f4x", "invert-reset", "invert-test", + "swap-reset-test", "telos-latch", "telos-i2c", "telos", "telosb", + "tmote","no-BSL-download", "force-BSL-download", "slow", + "dumpivt", "dumpinfo", "fromweb", + "goodfet30", "goodfet20", "goodfet10", "z1", "mainerase" + ] + ) + except getopt.GetoptError: + # print help information and exit: + usage() + sys.exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + elif o in ("-c", "--comport"): + try: + comPort = int(a) #try to convert decimal + except ValueError: + comPort = a #take the string and let serial driver decide + elif o in ("-P", "--password"): + #extract password from file + bsl.passwd = Memory(a).getMemrange(0xffe0, 0xffff) + elif o in ("-w", "--wait"): + wait = 1 + elif o in ("--dumpivt"): + dumpivt=1; + elif o in ("--dumpinfo"): + dumpinfo=1; + elif o in ("-f", "--framesize"): + try: + maxData = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("framesize must be a valid number\n") + sys.exit(2) + #Make sure that conditions for maxData are met: + #( >= 16 and == n*16 and <= MAX_DATA_BYTES!) + if maxData > BootStrapLoader.MAX_DATA_BYTES: + maxData = BootStrapLoader.MAX_DATA_BYTES + elif maxData < 16: + maxData = 16 + bsl.maxData = maxData - (maxData % 16) + sys.stderr.write( "Max. number of data bytes within one frame set to %i.\n" % maxData) + elif o in ("-m", "--erasecycles"): + try: + meraseCycles = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("erasecycles must be a valid number\n") + sys.exit(2) + #sanity check of value + if meraseCycles < 1: + sys.stderr.write("erasecycles must be a positive number\n") + sys.exit(2) + if meraseCycles > 20: + sys.stderr.write("warning: erasecycles set to a large number (>20): %d\n" % meraseCycles) + sys.stderr.write( "Number of mass erase cycles set to %i.\n" % meraseCycles) + bsl.meraseCycles = meraseCycles + elif o in ("-e", "--masserase"): + #toinit.append(bsl.actionMassErase) #Erase Flash + todo.append(bsl.actionMainErase) #Erase Flash + #todo.append(bsl.actionSecureInfoSegment) + elif o in ("-n", "--mainerase"): + #todo.append(bsl.actionMainErase) #Erase Flash + toinit.append(bsl.actionMassErase) #Erase Flash + elif o in ("-E", "--erasecheck"): + toinit.append(bsl.actionEraseCheck) #Erase Check (by file) + elif o in ("-p", "--program"): + #pass + todo.append(bsl.actionProgram) #Program file + if bsl.z1: + #todo.append(bsl.actionUnlockInfo) + #todo.append(bsl.writeCalibTables) + #todo.append(bsl.writeCalibTables2) + + todo.append(bsl.actionWriteNewPassword) + + pass + elif o in ("--fromweb"): + toinit.append(bsl.actionMassErase) #Erase Flash + todo.append(bsl.actionFromweb) #Program GoodFET code + elif o in ("-v", "--verify"): + todo.append(bsl.actionVerify) #Verify file + elif o in ("-r", "--reset"): + reset = 1 + elif o in ("-g", "--go"): + try: + goaddr = int(a) #try to convert decimal + except ValueError: + try: + goaddr = int(a[2:],16) #try to convert hex + except ValueError: + sys.stderr.write("go address must be a valid number\n") + sys.exit(2) + wait = 1 + elif o in ("-U", "--unpatched"): + unpatched = 1 + elif o in ("-D", "--debug"): + DEBUG = DEBUG + 1 + elif o in ("-u", "--upload"): + try: + startaddr = int(a) #try to convert decimal + except ValueError: + try: + startaddr = int(a,16) #try to convert hex + except ValueError: + sys.stderr.write("upload address must be a valid number\n") + sys.exit(2) + elif o in ("-s", "--size"): + try: + size = int(a) + except ValueError: + try: + size = int(a,16) + except ValueError: + sys.stderr.write("size must be a valid number\n") + sys.exit(2) + elif o in ("-x", "--hex"): + hexoutput = 1 + elif o in ("-b", "--bin"): + hexoutput = 0 + elif o in ("-I", "--intelhex"): + filetype = 0 + elif o in ("-T", "--titext"): + filetype = 1 + elif o in ("-N", "--notimeout"): + notimeout = 1 + elif o in ("-B", "--bsl"): + bslrepl = Memory() #File to program + bslrepl.loadFile(a) + elif o in ("-V", "--bslversion"): + todo.append(bsl.actionReadBSLVersion) #load replacement BSL as first item + elif o in ("-S", "--speed"): + try: + speed = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("speed must be decimal number\n") + sys.exit(2) + elif o in ("-1", "--f1x"): + bsl.cpu = F1x + elif o in ("-2", "--f2x"): + bsl.cpu = F2x + elif o in ("-4", "--f4x"): + bsl.cpu = F4x + elif o in ("--invert-reset", ): + bsl.invertRST = 1 + elif o in ("--invert-test", ): + bsl.invertTEST = 1 + elif o in ("--swap-reset-test", ): + bsl.swapRSTTEST = 1 + elif o in ("--telos-latch", ): + bsl.telosLatch = 1 + elif o in ("--telos-i2c", ): + bsl.telosI2C = 1 + elif o in ("--telos", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + bsl.swapRSTTEST = 1 + bsl.telosLatch = 1 + elif o in ("--goodfet10", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + elif o in ("--goodfet20", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + elif o in ("--goodfet30", ): + bsl.invertRST = 1 + bsl.invertTEST = 0 + elif o in ("--telosb", ): + bsl.swapRSTTEST = 1 + bsl.telosI2C = 1 + mayuseBSL = 0 + speed = 38400 + elif o in ("--tmote", ): + bsl.swapRSTTEST = 1 + bsl.telosI2C = 1 + mayuseBSL = 0 + speed = 38400 + elif o in ("--z1", ): + bsl.z1 = 1 + speed = 38400 + toinit.append(bsl.actionRecoverPassword) + elif o in ("--no-BSL-download", ): + mayuseBSL = 0 + elif o in ("--force-BSL-download", ): + forceBSL = 1 + elif o in ("--slow", ): + bsl.slowmode = 1 + + if len(args) == 0: + sys.stderr.write("Use -h for help\n"); + sys.stderr.write("Use --fromweb to upgrade a GoodFET.\n") + elif len(args) == 1: #a filename is given + if not todo: #if there are no actions yet + todo.extend([ #add some useful actions... + bsl.actionProgram, + bsl.actionVerify, + ]) + filename = args[0] + else: #number of args is wrong + usage() + sys.exit(2) + + if DEBUG: #debug infos + sys.stderr.write("Debug level set to %d\n" % DEBUG) + sys.stderr.write("Python version: %s\n" % sys.version) + + #sanity check of options + if notimeout and goaddr is not None and startaddr is not None: + sys.stderr.write("Option --notimeout can not be used together with both --upload and --go\n") + sys.exit(1) + + if notimeout: + sys.stderr.write("Warning: option --notimeout can cause improper function in some cases!\n") + bsl.timeout = 0 + + if goaddr and reset: + sys.stderr.write("Warning: option --reset ignored as --go is specified!\n") + reset = 0 + + if startaddr and reset: + sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n") + reset = 0 + + sys.stderr.flush() + + #prepare data to download + bsl.data = Memory() #prepare downloaded data + if filetype is not None: #if the filetype is given... + if filename is None: + raise ValueError("no filename but filetype specified") + if filename == '-': #get data from stdin + file = sys.stdin + else: + file = open(filename, "rb") #or from a file + if filetype == 0: #select load function + bsl.data.loadIHex(file) #intel hex + elif filetype == 1: + bsl.data.loadTIText(file) #TI's format + else: + raise ValueError("illegal filetype specified") + else: #no filetype given... + if filename == '-': #for stdin: + bsl.data.loadIHex(sys.stdin) #assume intel hex + elif filename: + bsl.data.loadFile(filename) #autodetect otherwise + + if DEBUG > 3: sys.stderr.write("File: %r" % filename) + + bsl.comInit(comPort) #init port + + #initialization list + if toinit: #erase and erase check + if DEBUG: sys.stderr.write("Preparing device ...\n") + #bsl.actionStartBSL(usepatch=0, adjsp=0) #no workarounds needed + #if speed: bsl.actionChangeBaudrate(speed) #change baud rate as fast as possible + for f in toinit: f() + + if todo or goaddr or startaddr: + if DEBUG: sys.stderr.write("Actions ...\n") + #connect to the BSL + bsl.actionStartBSL( + usepatch=not unpatched, + replacementBSL=bslrepl, + forceBSL=forceBSL, + mayuseBSL=mayuseBSL, + speed=speed, + ) + + #work list + if todo: + if DEBUG > 0: #debug + #show a nice list of sheduled actions + sys.stderr.write("TODO list:\n") + for f in todo: + try: + sys.stderr.write(" %s\n" % f.func_name) + except AttributeError: + sys.stderr.write(" %r\n" % f) + for f in todo: f() #work through todo list + + if reset: #reset device first if desired + bsl.actionReset() + if dumpivt: + bsl.txPasswd(); #default pass + data=bsl.uploadData(0xc00,1024); + hex=""; + for c in data: + hex+=("%02x "%ord(c)); + print hex; + if dumpinfo: + bsl.txPasswd(); #default pass + data=bsl.uploadData(0x1000,256); + hex="@1000\n"; + for c in data: + hex+=("%02x "%ord(c)); + hex+="\nq\n"; + print hex; + + if goaddr is not None: #start user programm at specified address + bsl.actionRun(goaddr) #load PC and execute + + #upload datablock and output + if startaddr is not None: + if goaddr: #if a program was started... + #don't restart BSL but wait for the device to enter it itself + sys.stderr.write("Waiting for device to reconnect for upload: ") + sys.stderr.flush() + bsl.txPasswd(bsl.passwd, wait=1) #synchronize, try forever... + data = bsl.uploadData(startaddr, size) #upload data + else: + data = bsl.uploadData(startaddr, size) #upload data + if hexoutput: #depending on output format + m = 0 + while m < len(data): #print a hex display + print hexify(startaddr+m, map(ord,data[m:m+16])) + m = m + 16 + else: + sys.stdout.write(data) #binary output w/o newline! + wait = 0 #wait makes no sense as after the upload the device is still in BSL + + if wait: #wait at the end if desired + sys.stderr.write("Press ...\n") #display a prompt + sys.stderr.flush() + raw_input() #wait for newline + + bsl.comDone() #Release serial communication port + +if __name__ == '__main__': + try: + main(1) + except SystemExit: + raise #let pass exit() calls + except KeyboardInterrupt: + if DEBUG: raise #show full trace in debug mode + sys.stderr.write("user abort.\n") #short messy in user mode + sys.exit(1) #set errorlevel for script usage + except Exception, msg: #every Exception is caught and displayed + if DEBUG: raise #show full trace in debug mode + #sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode + #sys.exit(1) #set errorlevel for script usage + main(0); diff --git a/tools/zolertia/z1-bsl-nopic b/tools/zolertia/z1-bsl-nopic new file mode 100755 index 000000000..8b5edd8f5 --- /dev/null +++ b/tools/zolertia/z1-bsl-nopic @@ -0,0 +1,1941 @@ +#!/usr/bin/env python2 +# Serial Bootstrap Loader software for the MSP430 embedded proccessor. +# +# (C) 2001-2003 Chris Liechti +# this is distributed under a free software license, see license-bsl.txt +# +# fixes from Colin Domoney +# +# based on the application note slas96b.pdf from Texas Instruments, Inc., +# Volker Rzehak +# additional infos from slaa089a.pdf +# +# Forked by Travis Goodspeed for use with the GoodFET +# JTAG programmer. + +import sys, time, string, cStringIO, struct +sys.path.append("/usr/lib/tinyos") +import serial, os, glob + +#forked from TinyOS Telos version. +VERSION = string.split("Revision: 1.39-goodfet-8 z1 fork")[1] + +DEBUG = 0 #disable debug messages by default + +#copy of the patch file provided by TI +#this part is (C) by Texas Instruments +PATCH = """@0220 +31 40 1A 02 09 43 B0 12 2A 0E B0 12 BA 0D 55 42 +0B 02 75 90 12 00 1F 24 B0 12 BA 02 55 42 0B 02 +75 90 16 00 16 24 75 90 14 00 11 24 B0 12 84 0E +06 3C B0 12 94 0E 03 3C 21 53 B0 12 8C 0E B2 40 +10 A5 2C 01 B2 40 00 A5 28 01 30 40 42 0C 30 40 +76 0D 30 40 AC 0C 16 42 0E 02 17 42 10 02 E2 B2 +08 02 14 24 B0 12 10 0F 36 90 00 10 06 28 B2 40 +00 A5 2C 01 B2 40 40 A5 28 01 D6 42 06 02 00 00 +16 53 17 83 EF 23 B0 12 BA 02 D3 3F B0 12 10 0F +17 83 FC 23 B0 12 BA 02 D0 3F 18 42 12 02 B0 12 +10 0F D2 42 06 02 12 02 B0 12 10 0F D2 42 06 02 +13 02 38 E3 18 92 12 02 BF 23 E2 B3 08 02 BC 23 +30 41 +q +""" + +#These BSL's are (C) by TI. They come with the application note slaa089a +F1X_BSL = """@0220 +24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 +F2 C0 32 00 00 00 B2 40 80 5A 20 01 F2 40 85 00 +57 00 F2 40 80 00 56 00 E2 D3 21 00 E2 D3 22 00 +E2 C3 26 00 E2 C2 2A 00 E2 C2 2E 00 B2 40 10 A5 +2C 01 B2 40 00 A5 28 01 3B C0 3A 00 B0 12 D6 04 +82 43 12 02 09 43 36 40 0A 02 37 42 B0 12 AC 05 +C6 4C 00 00 16 53 17 83 F9 23 D2 92 0C 02 0D 02 +28 20 55 42 0B 02 75 90 12 00 80 24 75 90 10 00 +6D 24 B0 12 9C 04 55 42 0B 02 75 90 18 00 31 24 +75 90 1E 00 B8 24 75 90 20 00 17 24 2B B2 11 24 +75 90 16 00 22 24 75 90 14 00 B3 24 75 90 1A 00 +18 24 75 90 1C 00 45 24 04 3C B0 12 36 05 BE 3F +21 53 B0 12 3C 05 BA 3F 03 43 B0 12 36 05 D2 42 +0E 02 56 00 D2 42 0F 02 57 00 D2 42 10 02 16 02 +AD 3F B0 12 36 05 10 42 0E 02 16 42 0E 02 15 43 +07 3C 36 40 FE FF B2 40 06 A5 10 02 35 40 0C 00 +B2 40 00 A5 2C 01 92 42 10 02 28 01 B6 43 00 00 +92 B3 2C 01 FD 23 15 83 F3 23 36 90 FE FF CD 27 +37 40 80 00 36 F0 80 FF 36 90 00 11 0E 28 07 57 +36 F0 00 FF 36 90 00 12 08 28 07 57 36 F0 00 FE +04 3C 16 42 0E 02 17 42 10 02 35 43 75 96 03 20 +17 83 FC 23 B2 3F 82 46 00 02 B3 3F 36 40 E0 FF +37 40 20 00 B0 12 AC 05 7C 96 01 24 2B D3 17 83 +F9 23 2B C2 B0 12 9C 04 2B D2 9F 3F 16 42 0E 02 +17 42 10 02 2B B2 38 24 3B D0 10 00 B0 12 AC 05 +36 90 00 10 06 2C 36 90 00 01 09 2C C6 4C 00 00 +25 3C B2 40 00 A5 2C 01 B2 40 40 A5 28 01 16 B3 +03 20 C2 4C 14 02 1A 3C C2 4C 15 02 86 9A FD FF +08 24 2B D3 3B B0 20 00 04 20 3B D0 20 00 82 46 +00 02 36 90 01 02 04 28 3B D2 3B B0 10 00 02 24 +3B C0 32 00 1A 42 14 02 86 4A FF FF 16 53 17 83 +CD 23 B0 12 9C 04 61 3F B0 12 AC 05 17 83 FC 23 +B0 12 9C 04 5E 3F B2 40 F0 0F 0E 02 B2 40 10 00 +10 02 B2 40 80 00 0A 02 D2 42 10 02 0C 02 D2 42 +10 02 0D 02 82 43 12 02 09 43 36 40 0A 02 27 42 +7C 46 B0 12 40 05 17 83 FB 23 16 42 0E 02 17 42 +10 02 36 90 00 01 0A 28 B2 46 14 02 5C 42 14 02 +B0 12 40 05 17 83 5C 42 15 02 01 3C 7C 46 B0 12 +40 05 17 83 EE 23 B2 E3 12 02 5C 42 12 02 B0 12 +40 05 5C 42 13 02 B0 12 40 05 E0 3E 18 42 12 02 +B0 12 AC 05 C2 4C 12 02 B0 12 AC 05 C2 4C 13 02 +38 E3 3B B2 0A 24 86 9A FE FF 07 24 3B B0 20 00 +04 20 16 53 82 46 00 02 2B D3 18 92 12 02 08 23 +2B B3 06 23 30 41 E2 B2 28 00 FD 27 E2 B2 28 00 +FD 23 B2 40 24 02 60 01 E2 B2 28 00 FD 27 15 42 +70 01 05 11 05 11 05 11 82 45 02 02 05 11 82 45 +04 02 B2 80 1E 00 04 02 57 42 16 02 37 80 03 00 +05 11 05 11 17 53 FD 23 35 50 40 A5 82 45 2A 01 +35 42 B2 40 24 02 60 01 92 92 70 01 02 02 FC 2F +15 83 F7 23 09 43 7C 40 90 00 02 3C 7C 40 A0 00 +C2 43 07 02 C9 EC 12 02 19 E3 1B C3 55 42 07 02 +55 45 56 05 00 55 0C 2E 2E 2E 2E 2E 2E 2E 2E 1A +34 34 92 42 70 01 72 01 B2 50 0C 00 72 01 07 3C +1B B3 0B 20 82 43 62 01 92 B3 62 01 FD 27 E2 C3 +21 00 0A 3C 4C 11 F6 2B 1B E3 82 43 62 01 92 B3 +62 01 FD 27 E2 D3 21 00 92 52 02 02 72 01 D2 53 +07 02 F0 90 0C 00 61 FC D1 23 30 41 C2 43 09 02 +1B C3 55 42 09 02 55 45 BC 05 00 55 0C 56 56 56 +56 56 56 56 56 36 76 00 E2 B2 28 00 FD 23 92 42 +70 01 72 01 92 52 04 02 72 01 82 43 62 01 92 B3 +62 01 FD 27 E2 B2 28 00 1E 28 2B D3 1C 3C 4C 10 +1A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +01 28 1B E3 1B B3 01 24 2B D3 C9 EC 12 02 19 E3 +0A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +E6 2B 4C 10 1B E3 92 52 02 02 72 01 D2 53 09 02 +C0 3F 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 +01 2C 2B D3 30 41 +q +""" + +F4X_BSL = """@0220 +24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 +F2 C0 32 00 00 00 B2 40 80 5A 20 01 32 D0 40 00 +C2 43 50 00 F2 40 98 00 51 00 F2 C0 80 00 52 00 +D2 D3 21 00 D2 D3 22 00 D2 C3 26 00 E2 C3 22 00 +E2 C3 26 00 B2 40 10 A5 2C 01 B2 40 00 A5 28 01 +3B C0 3A 00 B0 12 DE 04 82 43 12 02 09 43 36 40 +0A 02 37 42 B0 12 B4 05 C6 4C 00 00 16 53 17 83 +F9 23 D2 92 0C 02 0D 02 28 20 55 42 0B 02 75 90 +12 00 80 24 75 90 10 00 6D 24 B0 12 A4 04 55 42 +0B 02 75 90 18 00 31 24 75 90 1E 00 B8 24 75 90 +20 00 17 24 2B B2 11 24 75 90 16 00 22 24 75 90 +14 00 B3 24 75 90 1A 00 18 24 75 90 1C 00 45 24 +04 3C B0 12 3E 05 BE 3F 21 53 B0 12 44 05 BA 3F +03 43 B0 12 3E 05 D2 42 0E 02 50 00 D2 42 0F 02 +51 00 D2 42 10 02 16 02 AD 3F B0 12 3E 05 10 42 +0E 02 16 42 0E 02 15 43 07 3C 36 40 FE FF B2 40 +06 A5 10 02 35 40 0C 00 B2 40 00 A5 2C 01 92 42 +10 02 28 01 B6 43 00 00 92 B3 2C 01 FD 23 15 83 +F3 23 36 90 FE FF CD 27 37 40 80 00 36 F0 80 FF +36 90 00 11 0E 28 07 57 36 F0 00 FF 36 90 00 12 +08 28 07 57 36 F0 00 FE 04 3C 16 42 0E 02 17 42 +10 02 35 43 75 96 03 20 17 83 FC 23 B2 3F 82 46 +00 02 B3 3F 36 40 E0 FF 37 40 20 00 B0 12 B4 05 +7C 96 01 24 2B D3 17 83 F9 23 2B C2 B0 12 A4 04 +2B D2 9F 3F 16 42 0E 02 17 42 10 02 2B B2 38 24 +3B D0 10 00 B0 12 B4 05 36 90 00 10 06 2C 36 90 +00 01 09 2C C6 4C 00 00 25 3C B2 40 00 A5 2C 01 +B2 40 40 A5 28 01 16 B3 03 20 C2 4C 14 02 1A 3C +C2 4C 15 02 86 9A FD FF 08 24 2B D3 3B B0 20 00 +04 20 3B D0 20 00 82 46 00 02 36 90 01 02 04 28 +3B D2 3B B0 10 00 02 24 3B C0 32 00 1A 42 14 02 +86 4A FF FF 16 53 17 83 CD 23 B0 12 A4 04 61 3F +B0 12 B4 05 17 83 FC 23 B0 12 A4 04 5E 3F B2 40 +F0 0F 0E 02 B2 40 10 00 10 02 B2 40 80 00 0A 02 +D2 42 10 02 0C 02 D2 42 10 02 0D 02 82 43 12 02 +09 43 36 40 0A 02 27 42 7C 46 B0 12 48 05 17 83 +FB 23 16 42 0E 02 17 42 10 02 36 90 00 01 0A 28 +B2 46 14 02 5C 42 14 02 B0 12 48 05 17 83 5C 42 +15 02 01 3C 7C 46 B0 12 48 05 17 83 EE 23 B2 E3 +12 02 5C 42 12 02 B0 12 48 05 5C 42 13 02 B0 12 +48 05 E0 3E 18 42 12 02 B0 12 B4 05 C2 4C 12 02 +B0 12 B4 05 C2 4C 13 02 38 E3 3B B2 0A 24 86 9A +FE FF 07 24 3B B0 20 00 04 20 16 53 82 46 00 02 +2B D3 18 92 12 02 08 23 2B B3 06 23 30 41 E2 B3 +20 00 FD 27 E2 B3 20 00 FD 23 B2 40 24 02 60 01 +E2 B3 20 00 FD 27 15 42 70 01 05 11 05 11 05 11 +82 45 02 02 05 11 82 45 04 02 B2 80 1E 00 04 02 +57 42 16 02 37 80 03 00 05 11 05 11 17 53 FD 23 +35 50 40 A5 82 45 2A 01 35 42 B2 40 24 02 60 01 +92 92 70 01 02 02 FC 2F 15 83 F7 23 09 43 7C 40 +90 00 02 3C 7C 40 A0 00 C2 43 07 02 C9 EC 12 02 +19 E3 1B C3 55 42 07 02 55 45 5E 05 00 55 0C 2E +2E 2E 2E 2E 2E 2E 2E 1A 34 34 92 42 70 01 72 01 +B2 50 0C 00 72 01 07 3C 1B B3 0B 20 82 43 62 01 +92 B3 62 01 FD 27 D2 C3 21 00 0A 3C 4C 11 F6 2B +1B E3 82 43 62 01 92 B3 62 01 FD 27 D2 D3 21 00 +92 52 02 02 72 01 D2 53 07 02 F0 90 0C 00 59 FC +D1 23 30 41 C2 43 09 02 1B C3 55 42 09 02 55 45 +C4 05 00 55 0C 56 56 56 56 56 56 56 56 36 76 00 +E2 B3 20 00 FD 23 92 42 70 01 72 01 92 52 04 02 +72 01 82 43 62 01 92 B3 62 01 FD 27 E2 B3 20 00 +1E 28 2B D3 1C 3C 4C 10 1A 3C 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 01 28 1B E3 1B B3 01 24 +2B D3 C9 EC 12 02 19 E3 0A 3C 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 E6 2B 4C 10 1B E3 92 52 +02 02 72 01 D2 53 09 02 C0 3F 82 43 62 01 92 B3 +62 01 FD 27 E2 B3 20 00 01 2C 2B D3 30 41 +q +""" + +CALIB_TABLES = """ +84 C0 16 FE FF FF FF FF FF FF FF FF FF FF FF FF +FF FF FF FF FF FF FF FF FF FF 10 08 80 00 00 01 +7E 27 0B 79 0D AA 7E 4D 06 DF 08 33 08 FE FF FF +FF FF FF FF FF FF 08 01 8F 95 8E 9A 8D 88 86 D1 +""" + +#cpu types for "change baudrate" +#use strings as ID so that they can be used in outputs too +F1x = "F1x family" +F2x = "F2x family" +F4x = "F4x family" + +#known device list +deviceids = { + 0xf149: F1x, + 0xf16c: F1x, #for GoodFET10 to '20 + 0xf112: F1x, + 0xf413: F4x, + 0xf123: F1x, + 0xf449: F4x, + 0x1232: F1x, + 0xf26f: F2x, #for GoodFET20 + 0xf227: F2x, #for GoodFET30 +} + +#GoodFET firmware +firmware = { + 0xf16c: "http://goodfet.sourceforge.net/dist/msp430x1612.hex", + 0xf26f: "http://goodfet.sourceforge.net/dist/msp430x2618.hex", + 0xf227: "http://goodfet.sourceforge.net/dist/msp430x2274.hex" +} + +class BSLException(Exception): + pass + +class LowLevel: + "lowlevel communication" + #Constants + MODE_SSP = 0 + MODE_BSL = 1 + + BSL_SYNC = 0x80 + BSL_TXPWORD = 0x10 + BSL_TXBLK = 0x12 #Transmit block to boot loader + BSL_UNLOCK_INFO = 0x12 #unlocks / locks info segment A Not working on msp430f2617 + BSL_RXBLK = 0x14 #Receive block from boot loader + BSL_ERASE = 0x16 #Erase one segment + BSL_MERAS = 0x18 #Erase complete FLASH memory + BSL_CHANGEBAUD = 0x20 #Change baudrate + BSL_SETMEMOFFSET = 0x21 #Set memory offset + BSL_LOADPC = 0x1A #Load PC and start execution + BSL_TXVERSION = 0x1E #Get BSL version + + #Upper limit of address range that might be modified by + #"BSL checksum bug". + BSL_CRITICAL_ADDR = 0x0A00 + + #Header Definitions + CMD_FAILED = 0x70 + DATA_FRAME = 0x80 + DATA_ACK = 0x90 + DATA_NAK = 0xA0 + + QUERY_POLL = 0xB0 + QUERY_RESPONSE = 0x50 + + OPEN_CONNECTION = 0xC0 + ACK_CONNECTION = 0x40 + + DEFAULT_TIMEOUT = 1 + DEFAULT_PROLONG = 10 + MAX_FRAME_SIZE = 256 + MAX_DATA_BYTES = 250 + MAX_DATA_WORDS = 125 + + MAX_FRAME_COUNT = 16 + + #Error messages + ERR_COM = "Unspecific error" + ERR_RX_NAK = "NAK received (wrong password?)" + #ERR_CMD_NOT_COMPLETED = "Command did not send ACK: indicates that it didn't complete correctly" + ERR_CMD_FAILED = "Command failed, is not defined or is not allowed" + ERR_BSL_SYNC = "Bootstrap loader synchronization error" + ERR_FRAME_NUMBER = "Frame sequence number error." + + def calcChecksum(self, data, length): + """Calculates a checksum of "data".""" + checksum = 0 + + for i in range(length/2): + checksum = checksum ^ (ord(data[i*2]) | (ord(data[i*2+1]) << 8)) #xor-ing + return 0xffff & (checksum ^ 0xffff) #inverting + + def __init__(self, aTimeout = None, aProlongFactor = None): + """init bsl object, don't connect yet""" + if aTimeout is None: + self.timeout = self.DEFAULT_TIMEOUT + else: + self.timeout = aTimeout + if aProlongFactor is None: + self.prolongFactor = self.DEFAULT_PROLONG + else: + self.prolongFactor = aProlongFactor + + #flags for inverted use of control pins + #used for some hardware + self.invertRST = 0 + self.invertTEST = 0 + self.swapRSTTEST = 0 + self.telosLatch = 0 + self.telosI2C = 0 + + self.z1 = 0 + + self.protocolMode = self.MODE_BSL + self.BSLMemAccessWarning = 0 #Default: no warning. + self.slowmode = 0 + + def comInit(self, port): + """Tries to open the serial port given and + initialises the port and variables. + The timeout and the number of allowed errors is multiplied by + 'aProlongFactor' after transmission of a command to give + plenty of time to the micro controller to finish the command. + Returns zero if the function is successful.""" + if DEBUG > 1: sys.stderr.write("* comInit()\n") + self.seqNo = 0 + self.reqNo = 0 + self.rxPtr = 0 + self.txPtr = 0 + # Startup-Baudrate: 9600,8,E,1, 1s timeout + self.serialport = serial.Serial( + port, + 9600, + parity = serial.PARITY_EVEN, + timeout = self.timeout + ) + if DEBUG: sys.stderr.write("using serial port %r\n" % self.serialport.portstr) + #self.SetRSTpin() #enable power + #self.SetTESTpin() #enable power + self.serialport.flushInput() + self.serialport.flushOutput() + + def comDone(self): + """Closes the used serial port. + This function must be called at the end of a program, + otherwise the serial port might not be released and can not be + used in other programs. + Returns zero if the function is successful.""" + if DEBUG > 1: sys.stderr.write("* comDone()") + self.SetRSTpin(1) #disable power + self.SetTESTpin(0) #disable power + self.serialport.close() + + def comRxHeader(self): + """receive header and split data""" + if DEBUG > 1: sys.stderr.write("* comRxHeader()\n") + + hdr = self.serialport.read(1) + if not hdr: raise BSLException("Timeout") + rxHeader = ord(hdr) & 0xf0; + rxNum = ord(hdr) & 0x0f; + + if self.protocolMode == self.MODE_BSL: + self.reqNo = 0 + self.seqNo = 0 + rxNum = 0 + if DEBUG > 1: sys.stderr.write("* comRxHeader() OK\n") + return rxHeader, rxNum + + def comRxFrame(self, rxNum): + if DEBUG > 1: sys.stderr.write("* comRxFrame()\n") + rxFrame = chr(self.DATA_FRAME | rxNum) + + if DEBUG > 2: sys.stderr.write(" comRxFrame() header...\n") + rxFramedata = self.serialport.read(3) + if len(rxFramedata) != 3: raise BSLException("Timeout") + rxFrame = rxFrame + rxFramedata + + if DEBUG > 3: sys.stderr.write(" comRxFrame() check header...\n") + if rxFrame[1] == chr(0) and rxFrame[2] == rxFrame[3]: #Add. header info. correct? + rxLengthCRC = ord(rxFrame[2]) + 2 #Add CRC-Bytes to length + if DEBUG > 2: sys.stderr.write(" comRxFrame() receiving data, size: %s\n" % rxLengthCRC) + + rxFramedata = self.serialport.read(rxLengthCRC) + if len(rxFramedata) != rxLengthCRC: raise BSLException("Timeout") + rxFrame = rxFrame + rxFramedata + #Check received frame: + if DEBUG > 3: sys.stderr.write(" comRxFrame() crc check\n") + #rxLength+4: Length with header but w/o CRC: + checksum = self.calcChecksum(rxFrame, ord(rxFrame[2]) + 4) + if rxFrame[ord(rxFrame[2])+4] == chr(0xff & checksum) and \ + rxFrame[ord(rxFrame[2])+5] == chr(0xff & (checksum >> 8)): #Checksum correct? + #Frame received correctly (=> send next frame) + if DEBUG > 2: sys.stderr.write("* comRxFrame() OK\n") + return rxFrame + else: + if DEBUG: sys.stderr.write(" comRxFrame() Checksum wrong\n") + else: + if DEBUG: sys.stderr.write(" comRxFrame() Header corrupt %r" % rxFrame) + raise BSLException(self.ERR_COM) #Frame has errors! + + def comTxHeader(self, txHeader): + """send header""" + if DEBUG > 1: sys.stderr.write("* txHeader()\n") + self.serialport.write(txHeader) + + def comTxRx(self, cmd, dataOut, length): + """Sends the command cmd with the data given in dataOut to the + microcontroller and expects either an acknowledge or a frame + with result from the microcontroller. The results are stored + in dataIn (if not a NULL pointer is passed). + In this routine all the necessary protocol stuff is handled. + Returns zero if the function was successful.""" + if DEBUG > 1: sys.stderr.write("* comTxRx()\n") + txFrame = [] + rxHeader = 0 + rxNum = 0 + + dataOut = list(dataOut) #convert to a list for simpler data fill in + #Transmitting part ---------------------------------------- + #Prepare data for transmit + if (length % 2) != 0: + #/* Fill with one byte to have even number of bytes to send */ + if self.protocolMode == self.MODE_BSL: + dataOut.append(0xFF) #fill with 0xFF + else: + dataOut.append(0) #fill with zero + + txFrame = "%c%c%c%c" % (self.DATA_FRAME | self.seqNo, cmd, len(dataOut), len(dataOut)) + + self.reqNo = (self.seqNo + 1) % self.MAX_FRAME_COUNT + + txFrame = txFrame + string.join(dataOut,'') + checksum = self.calcChecksum(txFrame, length + 4) + txFrame = txFrame + chr(checksum & 0xff) + txFrame = txFrame + chr((checksum >> 8) & 0xff) + + accessAddr = (0x0212 + (checksum^0xffff)) & 0xfffe #0x0212: Address of wCHKSUM + if self.BSLMemAccessWarning and accessAddr < self.BSL_CRITICAL_ADDR: + sys.stderr.write("WARNING: This command might change data at address %04x or %04x!\n" % (accessAddr, accessAddr + 1)) + + self.serialport.flushInput() #clear receiving queue + #TODO: Check after each transmitted character, + #TODO: if microcontroller did send a character (probably a NAK!). + for c in txFrame: + self.serialport.write(c) + if DEBUG > 3: sys.stderr.write("\ttx %02x" % ord(c)) + #if self.serialport.inWaiting(): break #abort when BSL replies, probably NAK + else: + if DEBUG > 1: sys.stderr.write( " comTxRx() transmit OK\n") + + #Receiving part ------------------------------------------- + rxHeader, rxNum = self.comRxHeader() #receive header + if DEBUG > 1: sys.stderr.write(" comTxRx() rxHeader=0x%02x, rxNum=%d, seqNo=%d, reqNo=%s\n" % (rxHeader, rxNum, self.seqNo, self.reqNo)) + if rxHeader == self.DATA_ACK: #acknowledge/OK + if DEBUG > 2: sys.stderr.write(" comTxRx() DATA_ACK\n") + if rxNum == self.reqNo: + self.seqNo = self.reqNo + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_ACK OK\n") + return #Acknowledge received correctly => next frame + raise BSLException(self.ERR_FRAME_NUMBER) + elif rxHeader == self.DATA_NAK: #not acknowledge/error + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_NAK\n") + raise BSLException(self.ERR_RX_NAK) + elif rxHeader == self.DATA_FRAME: #receive data + if DEBUG > 2: sys.stderr.write("* comTxRx() DATA_FRAME\n") + if rxNum == self.reqNo: + rxFrame = self.comRxFrame(rxNum) + return rxFrame + raise BSLException(self.ERR_FRAME_NUMBER) + elif rxHeader == self.CMD_FAILED: #Frame ok, but command failed. + if DEBUG > 2: sys.stderr.write("* comTxRx() CMD_FAILED\n") + raise BSLException(self.ERR_CMD_FAILED) + + raise BSLException("Unknown header 0x%02x\nAre you downloading to RAM into an old device that requires the patch? Try option -U" % rxHeader) + + def SetDTR(self, level, invert): + """Controls DTR pin (0: GND; 1: VCC; unless inverted flag is set)""" + #print 'fucking the dtr' + if invert: + self.serialport.setDTR(not level) + else: + self.serialport.setDTR(level) + if self.slowmode: + time.sleep(0.040) + + def SetRTS(self, level, invert): + """Controls RTS pin (0: GND; 1: VCC; unless inverted flag is set)""" + if invert: + self.serialport.setRTS(not level) + else: + self.serialport.setRTS(level) + if self.slowmode: + time.sleep(0.040) + + def SetRSTpin(self, level=1): + """Controls RST/NMI pin (0: GND; 1: VCC; unless inverted flag is set)""" + if self.swapRSTTEST: + self.SetRTS(level, self.invertRST) + else: + self.SetDTR(level, self.invertRST) + + def SetTESTpin(self, level=1): + """Controls TEST pin (inverted on board: 0: VCC; 1: GND; unless inverted flag is set)""" + if self.swapRSTTEST: + self.SetDTR(level, self.invertTEST) + else: + self.SetRTS(level, self.invertTEST) + + + def writepicROM(self, address, data): + ''' Writes data to @address''' + for i in range(7,-1,-1): + self.picROMclock((address >> i) & 0x01) + self.picROMclock(0) + recbuf = 0 + for i in range(7,-1,-1): + s = ((data >> i) & 0x01) + #print s + if i < 1: + r = not self.picROMclock(s, True) + else: + r = not self.picROMclock(s) + recbuf = (recbuf << 1) + r + + self.picROMclock(0, True) + #k = 1 + #while not self.serial.getCTS(): + # pass + #time.sleep(0.1) + return recbuf + + def readpicROM(self, address): + ''' reads a byte from @address''' + for i in range(7,-1,-1): + self.picROMclock((address >> i) & 0x01) + self.picROMclock(1) + recbuf = 0 + r = 0 + for i in range(7,-1,-1): + r = self.picROMclock(0) + recbuf = (recbuf << 1) + r + self.picROMclock(r) + #time.sleep(0.1) + return recbuf + + def picROMclock(self, masterout, slow = False): + #print "setting masterout to "+str(masterout) + self.serialport.setRTS(masterout) + self.serialport.setDTR(1) + #time.sleep(0.02) + self.serialport.setDTR(0) + if slow: + time.sleep(0.02) + return self.serialport.getCTS() + + def picROMfastclock(self, masterout): + #print "setting masterout to "+str(masterout) + self.serialport.setRTS(masterout) + self.serialport.setDTR(1) + self.serialport.setDTR(0) + time.sleep(0.02) + return self.serialport.getCTS() + + def bslResetZ1(self, invokeBSL=0): + ''' + Applies BSL entry sequence on RST/NMI and TEST/VPP pins + Parameters: + invokeBSL = 1: complete sequence + invokeBSL = 0: only RST/NMI pin accessed + + By now only BSL mode is accessed + ''' + + if DEBUG > 1: sys.stderr.write("* bslReset(invokeBSL=%s)\n" % invokeBSL) + if invokeBSL: + #sys.stderr.write("in Z1 bsl reset...\n") + time.sleep(0.1) + self.writepicROM(0xFF, 0xFF) + time.sleep(0.1) + #sys.stderr.write("z1 bsl reset done...\n") + else: + #sys.stderr.write("in Z1 reset...\n") + time.sleep(0.1) + self.writepicROM(0xFF, 0xFE) + time.sleep(0.1) + #sys.stderr.write("z1 reset done...\n") + + def telosSetSCL(self, level): + self.serialport.setRTS(not level) + + def telosSetSDA(self, level): + self.serialport.setDTR(not level) + + def telosI2CStart(self): + self.telosSetSDA(1) + self.telosSetSCL(1) + self.telosSetSDA(0) + + def telosI2CStop(self): + self.telosSetSDA(0) + self.telosSetSCL(1) + self.telosSetSDA(1) + + def telosI2CWriteBit(self, bit): + self.telosSetSCL(0) + self.telosSetSDA(bit) + time.sleep(2e-6) + self.telosSetSCL(1) + time.sleep(1e-6) + self.telosSetSCL(0) + + def telosI2CWriteByte(self, byte): + self.telosI2CWriteBit( byte & 0x80 ); + self.telosI2CWriteBit( byte & 0x40 ); + self.telosI2CWriteBit( byte & 0x20 ); + self.telosI2CWriteBit( byte & 0x10 ); + self.telosI2CWriteBit( byte & 0x08 ); + self.telosI2CWriteBit( byte & 0x04 ); + self.telosI2CWriteBit( byte & 0x02 ); + self.telosI2CWriteBit( byte & 0x01 ); + self.telosI2CWriteBit( 0 ); # "acknowledge" + + def telosI2CWriteCmd(self, addr, cmdbyte): + self.telosI2CStart() + self.telosI2CWriteByte( 0x90 | (addr << 1) ) + self.telosI2CWriteByte( cmdbyte ) + self.telosI2CStop() + + def telosBReset(self,invokeBSL=0): + # "BSL entry sequence at dedicated JTAG pins" + # rst !s0: 0 0 0 0 1 1 + # tck !s1: 1 0 1 0 0 1 + # s0|s1: 1 3 1 3 2 0 + + # "BSL entry sequence at shared JTAG pins" + # rst !s0: 0 0 0 0 1 1 + # tck !s1: 0 1 0 1 1 0 + # s0|s1: 3 1 3 1 0 2 + if invokeBSL: + self.telosI2CWriteCmd(0,1) + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,1) + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,2) + self.telosI2CWriteCmd(0,0) + else: + self.telosI2CWriteCmd(0,3) + self.telosI2CWriteCmd(0,2) + self.telosI2CWriteCmd(0,0) + time.sleep(0.250) #give MSP430's oscillator time to stabilize + self.serialport.flushInput() #clear buffers + + def bslReset(self, invokeBSL=0): + """Applies BSL entry sequence on RST/NMI and TEST/VPP pins + Parameters: + invokeBSL = 1: complete sequence + invokeBSL = 0: only RST/NMI pin accessed + + RST is inverted twice on boot loader hardware + TEST is inverted (only once) + Need positive voltage on DTR, RTS for power-supply of hardware""" + + #print 'goint to reset!' + + if self.telosI2C: + self.telosBReset(invokeBSL) + return + + if self.z1: + if DEBUG > 1: sys.stderr.write("* entering bsl with z1\n") + self.bslResetZ1(invokeBSL) + return + + if DEBUG > 1: sys.stderr.write("* bslReset(invokeBSL=%s)\n" % invokeBSL) + self.SetRSTpin(1) #power suply + self.SetTESTpin(1) #power suply + time.sleep(0.250) #charge capacitor on boot loader hardware + + if self.telosLatch: + self.SetTESTpin(0) + self.SetRSTpin(0) + self.SetTESTpin(1) + + self.SetRSTpin(0) #RST pin: GND + if invokeBSL: + self.SetTESTpin(1) #TEST pin: GND + self.SetTESTpin(0) #TEST pin: Vcc + self.SetTESTpin(1) #TEST pin: GND + self.SetTESTpin(0) #TEST pin: Vcc + self.SetRSTpin (1) #RST pin: Vcc + self.SetTESTpin(1) #TEST pin: GND + else: + self.SetRSTpin(1) #RST pin: Vcc + time.sleep(0.250) #give MSP430's oscillator time to stabilize + + self.serialport.flushInput() #clear buffers + + def bslSync(self,wait=0): + """Transmits Synchronization character and expects to receive Acknowledge character + if wait is 0 it must work the first time. otherwise if wait is 1 + it is retried (forever). + """ + loopcnt = 5 #Max. tries to get synchronization + + if DEBUG > 1: sys.stderr.write("* bslSync(wait=%d)\n" % wait) + while wait or loopcnt: + loopcnt = loopcnt - 1 #count down tries + self.serialport.flushInput() #clear input, in case a prog is running + + self.serialport.write(chr(self.BSL_SYNC)) #Send synchronization byte + c = self.serialport.read(1) #read answer + if c == chr(self.DATA_ACK): #ACk + if DEBUG > 1: sys.stderr.write(" bslSync() OK\n") + return #Sync. successful + elif not c: #timeout + if loopcnt > 4: + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout, retry ...\n") + elif loopcnt == 4: + #nmi may have caused the first reset to be ignored, try again + self.bslReset(0) + self.bslReset(1) + elif loopcnt > 0: + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout, retry ...\n") + else : + if DEBUG > 1: + sys.stderr.write(" bslSync() timeout\n") + else: #garbage + if DEBUG > 1: sys.stderr.write(" bslSync() failed (0x%02x), retry ...\n" % ord(c)) + + raise BSLException(self.ERR_BSL_SYNC) #Sync. failed + + def bslTxRx(self, cmd, addr, length = 0, blkout = None, wait=0): + """Transmits a command (cmd) with its parameters: + start-address (addr), length (len) and additional + data (blkout) to boot loader. + wait specified if the bsl sync should be tried once or + repeated, forever + Parameters return by boot loader are passed via blkin. + """ + if DEBUG > 1: sys.stderr.write("* bslTxRx()\n") + + if cmd == self.BSL_TXBLK: + #Align to even start address + if (addr % 2) != 0: + addr = addr - 1 #Decrement address and + blkout = chr(0xFF) + blkOut #fill first byte of blkout with 0xFF + length = length + 1 + #Make sure that len is even + if (length % 2) != 0: + blkout = blkout + chr(0xFF) #Inc. len and fill last byte of blkout with 0xFF + length = length + 1 + + elif cmd == self.BSL_RXBLK: + #Align to even start address + if (addr % 2) != 0: + addr = addr - 1 #Decrement address but + length = length + 1 #request an additional byte + #Make sure that len is even + if (length % 2) != 0: + length = length + 1 + + #if cmd == self.BSL_TXBLK or cmd == self.BSL_TXPWORD: + # length = len + 4 + + #Add necessary information data to frame + dataOut = struct.pack("= 1: + #Read one line + l = file.readline() + if not l: break #EOF + l = l.strip() + if l[0] == 'q': break + elif l[0] == '@': #if @ => new address => send frame and set new addr. + #create a new segment + if segmentdata: + self.segments.append( Segment(startAddr, string.join(segmentdata,'')) ) + startAddr = int(l[1:],16) + segmentdata = [] + else: + for i in string.split(l): + segmentdata.append(chr(int(i,16))) + if segmentdata: + self.segments.append( Segment(startAddr, string.join(segmentdata,'')) ) + + def loadELF(self, file): + """load data from a (opened) file in ELF object format. + File must be seekable""" + import elf + obj = elf.ELFObject() + obj.fromFile(file) + if obj.e_type != elf.ELFObject.ET_EXEC: + raise Exception("No executable") + for section in obj.getSections(): + if DEBUG: + sys.stderr.write("ELF section %s at 0x%04x %d bytes\n" % (section.name, section.lma, len(section.data))) + if len(section.data): + self.segments.append( Segment(section.lma, section.data) ) + + def loadFile(self, filename): + """fill memory with the contents of a file. file type is determined from extension""" + #TODO: do a contents based detection + if filename[-4:].lower() == '.txt': + self.loadTIText(open(filename, "rb")) + elif filename[-4:].lower() in ('.a43', '.hex'): + self.loadIHex(open(filename, "rb")) + else: + self.loadELF(open(filename, "rb")) + + def getMemrange(self, fromadr, toadr): + """get a range of bytes from the memory. unavailable values are filled with 0xff.""" + res = '' + toadr = toadr + 1 #python indxes are excluding end, so include it + while fromadr < toadr: + #print "fromto: %04x %04x" % (fromadr, toadr) + for seg in self.segments: + #print seg + segend = seg.startaddress + len(seg.data) + if seg.startaddress <= fromadr and fromadr < segend: + #print "startok 0x%04x %d" % (seg.startaddress, len(seg.data)) + #print ("0x%04x "*3) % (segend, fromadr, toadr) + if toadr > segend: #not all data in segment + #print "out of segment" + catchlength = segend-fromadr + else: + catchlength = toadr-fromadr + #print toadr-fromadr + #print catchlength + res = res + seg.data[fromadr-seg.startaddress : fromadr-seg.startaddress+catchlength] + fromadr = fromadr + catchlength #adjust start + if len(res) >= toadr-fromadr: + break#return res + else: + res = res + chr(255) + fromadr = fromadr + 1 #adjust start + #print "fill FF" + #print "res: %r" % res + return res + + +class BootStrapLoader(LowLevel): + """higher level Bootstrap Loader functions.""" + + ERR_VERIFY_FAILED = "Error: verification failed" + ERR_ERASE_CHECK_FAILED = "Error: erase check failed" + + ACTION_PROGRAM = 0x01 #Mask: program data + ACTION_VERIFY = 0x02 #Mask: verify data + ACTION_ERASE_CHECK = 0x04 #Mask: erase check + + #Max. bytes sent within one frame if parsing a TI TXT file. + #( >= 16 and == n*16 and <= MAX_DATA_BYTES!) + MAXDATA = 240-16 + + + def __init__(self, *args, **kargs): + LowLevel.__init__(self, *args, **kargs) + self.byteCtr = 0 + self.meraseCycles = 1 + self.patchRequired = 0 + self.patchLoaded = 0 + self.bslVer = 0 + self.passwd = None + self.data = None + self.maxData = self.MAXDATA + self.cpu = None + self.pwdsent = False + + + def preparePatch(self): + """prepare to download patch""" + if DEBUG > 1: sys.stderr.write("* preparePatch()\n") + + if self.patchLoaded: + #Load PC with 0x0220. + #This will invoke the patched bootstrap loader subroutines. + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + 0x0220) #Address to load into PC + self.BSLMemAccessWarning = 0 #Error is removed within workaround code + return + + def postPatch(self): + """setup after the patch is loaded""" + if DEBUG > 1: sys.stderr.write("* postPatch()\n") + if self.patchLoaded: + self.BSLMemAccessWarning = 1 #Turn warning back on. + + + def verifyBlk(self, addr, blkout, action): + """verify memory against data or 0xff""" + if DEBUG > 1: sys.stderr.write("* verifyBlk()\n") + + if action & self.ACTION_VERIFY or action & self.ACTION_ERASE_CHECK: + if DEBUG: sys.stderr.write(" Check starting at 0x%04x, %d bytes ... \n" % (addr, len(blkout))) + + self.preparePatch() + blkin = self.bslTxRx(self.BSL_RXBLK, addr, len(blkout)) + self.postPatch() + + for i in range(len(blkout)): + if action & self.ACTION_VERIFY: + #Compare data in blkout and blkin + if blkin[i] != blkout[i]: + sys.stderr.write("Verification failed at 0x%04x (0x%02x, 0x%02x)\n" % (addr+i, ord(blkin[i]), ord(blkout[i]))) + sys.stderr.flush() + raise BSLException(self.ERR_VERIFY_FAILED) #Verify failed! + continue + elif action & self.ACTION_ERASE_CHECK: + #Compare data in blkin with erase pattern + if blkin[i] != chr(0xff): + sys.stderr.write("Erase Check failed at 0x%04x (0x%02x)\n" % (addr+i, ord(blkin[i]))) + sys.stderr.flush() + raise BSLException(self.ERR_ERASE_CHECK_FAILED) #Erase Check failed! + continue + def readBlk(self,adr,len): + """Read a block of memory.""" + blkin = self.bslTxRx(self.BSL_RXBLK, addr, len(blkout)) + + def programBlk(self, addr, blkout, action): + """program a memory block""" + if DEBUG > 1: sys.stderr.write("* programBlk()\n") + + #Check, if specified range is erased + self.verifyBlk(addr, blkout, action & self.ACTION_ERASE_CHECK) + + if action & self.ACTION_PROGRAM: + if DEBUG: sys.stderr.write(" Program starting at 0x%04x, %i bytes ...\n" % (addr, len(blkout))) + self.preparePatch() + #Program block + self.bslTxRx(self.BSL_TXBLK, addr, len(blkout), blkout) + self.postPatch() + + #Verify block + self.verifyBlk(addr, blkout, action & self.ACTION_VERIFY) + + #segments: + #list of tuples or lists: + #segements = [ (addr1, [d0,d1,d2,...]), (addr2, [e0,e1,e2,...])] + def programData(self, segments, action): + """programm or verify data""" + if DEBUG > 1: sys.stderr.write("* programData()\n") + for seg in segments: + currentAddr = seg.startaddress + offsetAddr = 0 + if (seg.startaddress > 0xFFFF): + offsetAddr = seg.startaddress >> 16 + self.bslTxRx(self.BSL_SETMEMOFFSET, 0, offsetAddr) + currentAddr = currentAddr - (offsetAddr << 16) + pstart = 0 + while pstart len(seg.data): + length = len(seg.data) - pstart + self.programBlk(currentAddr, seg.data[pstart:pstart+length], action) + pstart = pstart + length + currentAddr = currentAddr + length + self.byteCtr = self.byteCtr + length #total sum + + def uploadData(self, startaddress, size, wait=0): + """upload a datablock""" + if DEBUG > 1: sys.stderr.write("* uploadData()\n") + data = '' + pstart = 0 + while pstart size: + length = size - pstart + data = data + self.bslTxRx(self.BSL_RXBLK, + pstart+startaddress, + length, + wait=wait)[:-2] #cut away checksum + pstart = pstart + length + return data + + def txPasswd(self, passwd=None, wait=0): + """transmit password, default if None is given.""" + if DEBUG > 1: sys.stderr.write("* txPassword(%r)\n" % passwd) + if passwd is None or self.pwdsent: + #Send "standard" password to get access to protected functions. + sys.stderr.write("Transmit default password ...\n") + sys.stderr.flush() + #Flash is completely erased, the contents of all Flash cells is 0xff + passwd = chr(0xff)*32 + else: + #sanity check of password + if len(passwd) != 32: + raise ValueError, "password has wrong length (%d)\n" % len(passwd) + sys.stderr.write('Transmit password ...\n') + sys.stderr.flush() + #send the password + self.bslTxRx(self.BSL_TXPWORD, #Command: Transmit Password + 0xffe0, #Address of interupt vectors + 0x0020, #Number of bytes + passwd, #password + wait=wait) #if wait is 1, try to sync forever + self.pwdsent = True + + + def getNewPassword(self): + print 'getting new password' + newpassword = self.bslTxRx(self.BSL_RXBLK, 0xffe0, 0x0020) + return newpassword + + + def writeCalibTables(self): + print 'writing new tables' + print CALIB_TABLES + calibtables = ["84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", + "FFFFFFFFFFFFFFFFFFFF100880000001", + "7E270B790DAA7E4D06DF083308FEFFFF", + "FFFFFFFFFFFF08018F958E9A8D8886D1"] + self.programBlk(0x10C0, "84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", self.ACTION_PROGRAM) + self.programBlk(0x10D0, "FFFFFFFFFFFFFFFFFFFF100880000001", self.ACTION_PROGRAM) + self.programBlk(0x10E0, "7E270B790DAA7E4D06DF083308FEFFFF", self.ACTION_PROGRAM) + self.programBlk(0x10F0, "FFFFFFFFFFFF08018F958E9A8D8886D1", self.ACTION_PROGRAM) + + def writeCalibTables2(self): + print 'writing new tables 2ond part' + #self.programBlk(0x10C0, "84C016FEFFFFFFFFFFFFFFFFFFFFFFFF", self.ACTION_PROGRAM) + #self.programBlk(0x10D0, "FFFFFFFFFFFFFFFFFFFF100880000001", self.ACTION_PROGRAM) + #self.programBlk(0x10E0, "7E270B790DAA7E4D06DF083308FEFFFF", self.ACTION_PROGRAM) + #self.programBlk(0x10F0, "FFFFFFFFFFFF08018F958E9A8D8886D1", self.ACTION_PROGRAM) + + + #----------------------------------------------------------------- + + def actionMassErase(self): + """Erase the flash memory completely (with mass erase command)""" + sys.stderr.write("Mass Erase...\n") + sys.stderr.flush() + self.bslReset(1) #Invoke the boot loader. + for i in range(self.meraseCycles): + if i == 1: sys.stderr.write("Additional Mass Erase Cycles...\n") + self.bslTxRx(self.BSL_MERAS, #Command: Mass Erase + 0xff00, #Any address within flash memory. + 0xa506) #Required setting for mass erase! + self.passwd = None #No password file required! + #print "Mass Erase complete" + #Transmit password to get access to protected BSL functions. + self.txPasswd() + + def actionMainErase(self): + """Erase the main flash memory only""" + sys.stderr.write("Main Erase...\n") + sys.stderr.flush() + self.bslTxRx(self.BSL_ERASE, #Command: Segment Erase + 0xfffe, #Any address within flash memory. + 0xa504) #Required setting for main erase! + #self.passwd = None #Password gets erased WHY?? + + + + def actionStartBSL(self, usepatch=1, adjsp=1, replacementBSL=None, forceBSL=0, mayuseBSL=0, speed=None, bslreset=1): + """start BSL, download patch if desired and needed, adjust SP if desired""" + sys.stderr.write("Invoking BSL...\n") + sys.stderr.flush() + + #for '30, invertTEST=0, else =1 + if bslreset: + #detext if is z1? + self.bslReset(1) #Invoke the boot loader. + + + if(self.z1): + ''' recover password from pic''' + + self.txPasswd(self.passwd) #transmit password + + #Read actual bootstrap loader version. + #sys.stderr.write("Reading BSL version ...\n") + blkin = self.bslTxRx(self.BSL_RXBLK, #Command: Read/Receive Block + 0x0ff0, #Start address + 16) #No. of bytes to read + dev_id, bslVerHi, bslVerLo = struct.unpack(">H8xBB4x", blkin[:-2]) #cut away checksum and extract data + self.dev_id=dev_id; + + + if self.cpu is None: #cpy type forced? + if deviceids.has_key(dev_id): + self.cpu = deviceids[dev_id] #try to autodectect CPU type + + if DEBUG: + sys.stderr.write("Autodetect successful: %04x -> %s\n" % (dev_id, self.cpu)) + else: + sys.stderr.write("Autodetect failed! Unkown ID: %04x. Trying to continue anyway.\n" % dev_id) + self.cpu = F1x #assume something and try anyway.. + + sys.stderr.write("Current bootstrap loader version: %x.%x (Device ID: %04x)\n" % (bslVerHi, bslVerLo, dev_id)) + sys.stderr.flush() + self.bslVer = (bslVerHi << 8) | bslVerLo + + if self.bslVer <= 0x0110: #check if patch is needed + self.BSLMemAccessWarning = 1 + else: + self.BSLMemAccessWarning = 0 #Fixed in newer versions of BSL. + + if self.bslVer <= 0x0130 and adjsp: + #only do this on BSL where it's needed to prevent + #malfunction with F4xx devices/ newer ROM-BSLs + + #Execute function within bootstrap loader + #to prepare stack pointer for the following patch. + #This function will lock the protected functions again. + sys.stderr.write("Adjust SP. Load PC with 0x0C22 ...\n") + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + 0x0C22) #Address to load into PC + #Re-send password to re-gain access to protected functions. + self.txPasswd(self.passwd) + + #get internal BSL replacement if needed or forced by the user + #required if speed is set but an old BSL is in the device + #if a BSL is given by the user, that one is used and not the internal one + if ((mayuseBSL and speed and self.bslVer < 0x0150) or forceBSL) and replacementBSL is None: + replacementBSL = Memory() #File to program + if self.cpu == F4x: + if DEBUG: + sys.stderr.write("Using built in BSL replacement for F4x devices\n") + sys.stderr.flush() + replacementBSL.loadTIText(cStringIO.StringIO(F4X_BSL)) #parse embedded BSL + else: + if DEBUG: + sys.stderr.write("Using built in BSL replacement for F1x devices\n") + sys.stderr.flush() + replacementBSL.loadTIText(cStringIO.StringIO(F1X_BSL)) #parse embedded BSL + + #now download the new BSL, if allowed and needed (version lower than the + #the replacement) or forced + if replacementBSL is not None: + self.actionDownloadBSL(replacementBSL) + + #debug message with the real BSL version in use (may have changed after replacement BSL) + if DEBUG: + sys.stderr.write("Current bootstrap loader version: 0x%04x\n" % (self.bslVer,)) + sys.stderr.flush() + + #now apply workarounds or patches if BSL in use requires that + if self.bslVer <= 0x0110: #check if patch is needed + if usepatch: #test if patch is desired + sys.stderr.write("Patch for flash programming required!\n") + self.patchRequired = 1 + + sys.stderr.write("Load and verify patch ...\n") + sys.stderr.flush() + #Programming and verification is done in one pass. + #The patch file is only read and parsed once. + segments = Memory() #data to program + segments.loadTIText(cStringIO.StringIO(PATCH)) #parse embedded patch + #program patch + self.programData(segments, self.ACTION_PROGRAM | self.ACTION_VERIFY) + self.patchLoaded = 1 + else: + if DEBUG: + sys.stderr.write("Device needs patch, but not applied (usepatch is false).\n") #message if not patched + + #should the baudrate be changed? + if speed is not None: + self.actionChangeBaudrate(speed) #change baudrate + + def actionDownloadBSL(self, bslsegments): + sys.stderr.write("Load new BSL into RAM...\n") + sys.stderr.flush() + self.programData(bslsegments, self.ACTION_PROGRAM) + sys.stderr.write("Verify new BSL...\n") + sys.stderr.flush() + self.programData(bslsegments, self.ACTION_VERIFY) #File to verify + + #Read startvector of bootstrap loader + #blkin = self.bslTxRx(self.BSL_RXBLK, 0x0300, 2) + #blkin = self.bslTxRx(self.BSL_RXBLK, 0x0220, 2) + blkin = self.bslTxRx(self.BSL_RXBLK, bslsegments[0].startaddress, 2) + startaddr = struct.unpack("%s" % (firmware[self.dev_id],fn)) + + fw=Memory(fn); + #fw.loadIhex(open(fn,"rb")); + + sys.stderr.write("Program ...\n") + sys.stderr.flush() + self.programData(fw, self.ACTION_PROGRAM | self.ACTION_VERIFY) + sys.stderr.write("%i bytes programmed.\n" % self.byteCtr) + sys.stderr.flush() + + def actionVerify(self): + """Verify programmed data""" + if self.data is not None: + sys.stderr.write("Verify ...\n") + sys.stderr.flush() + self.programData(self.data, self.ACTION_VERIFY) + else: + raise BSLException, "verify without data not possible" + + def actionReset(self): + """perform a reset, start user programm""" + sys.stderr.write("Reset device ...\n") + sys.stderr.flush() + self.bslReset(0) #only reset + + def actionRun(self, address=0x220): + """start program at specified address""" + sys.stderr.write("Load PC with 0x%04x ...\n" % address) + sys.stderr.flush() + self.bslTxRx(self.BSL_LOADPC, #Command: Load PC + address) #Address to load into PC + + #table with values from slaa089a.pdf + bauratetable = { + F1x: { + 9600:[0x8580, 0x0000], + 19200:[0x86e0, 0x0001], + 38400:[0x87e0, 0x0002], + }, + F2x: { + 9600:[0x8580, 0x0000], + 19200:[0x8B00, 0x0001], + 38400:[0x8C80, 0x0002], + }, + F4x: { + 9600:[0x9800, 0x0000], + 19200:[0xb000, 0x0001], + 38400:[0xc800, 0x0002], + }, + } + def actionChangeBaudrate(self, baudrate=9600): + """change baudrate. first the command is sent, then the comm + port is reprogrammed. only possible with newer MSP430-BSL versions. + (ROM >=1.6, downloadable >=1.5)""" + try: + baudconfigs = self.bauratetable[self.cpu] + except KeyError: + raise ValueError, "unknown CPU type %s, can't switch baudrate" % self.cpu + try: + a,l = baudconfigs[baudrate] + except KeyError: + raise ValueError, "baudrate not valid. valid values are %r" % baudconfigs.keys() + + sys.stderr.write("Changing baudrate to %d ...\n" % baudrate) + sys.stderr.flush() + self.bslTxRx(self.BSL_CHANGEBAUD, #Command: change baudrate + a, l) #args are coded in adr and len + self.serialport.flush() + time.sleep(0.010) #recomended delay + self.serialport.baudrate = baudrate + + def actionReadBSLVersion(self): + """informational output of BSL version number. + (newer MSP430-BSLs only)""" + ans = self.bslTxRx(self.BSL_TXVERSION, 0) #Command: receive version info + #the following values are in big endian style!!! + family_type, bsl_version = struct.unpack(">H8xH4x", ans[:-2]) #cut away checksum and extract data + print "Device Type: 0x%04x\nBSL version: 0x%04x\n" % (family_type, bsl_version) + + def actionWriteNewPassword(self): + passwd = self.getNewPassword() + #print passwd + self.picWritePassword(passwd) + + def actionRecoverPassword(self): + p = self.picRecoverPassword() + #print p + self.passwd = p + + def picRecoverPassword(self): + ''' recovers password from picrom''' + print 'recovering pic password', + p = '' + + for i in range(0,32): + c = self.readpicROM(i) + print c, + p = p + chr(c) + + print 'done' + return p + + def picWritePassword(self, password): + ''' writes a new password to picrom''' + print 'writing new password', + for i in range(0,32): + c = ord(password[i]) + print c, + self.writepicROM(i, c) + print 'done' + + +def usage(): + """print some help message""" + sys.stderr.write(""" +USAGE: %s [options] [file] +Version: %s + +If "-" is specified as file the data is read from the stdinput. +A file ending with ".txt" is considered to be in TIText format, +'.a43' and '.hex' as IntelHex and all other filenames are +considered as ELF files. + +General options: + -h, --help Show this help screen. + -c, --comport=port Specify the communication port to be used. + (Default is 0) + 0->COM1 / ttyS0 + 1->COM2 / ttyS1 + etc. + -P, --password=file Specify a file with the interrupt vectors that + are used as password. This can be any file that + has previously been used to program the device. + (e.g. -P INT_VECT.TXT). + -f, --framesize=num Max. number of data bytes within one transmitted + frame (16 to 240 in steps of 16) (e.g. -f 240). + -m, --erasecycles=num Number of mass erase cycles (default is 1). Some + old F149 devices need additional erase cycles. + On newer devices it is no longer needed. (e.g. for + an old F149: -m20) + -U, --unpatched Do not download the BSL patch, even when it is + needed. This is used when a program is downloaded + into RAM and executed from there (and where flash + programming is not needed.) + -D, --debug Increase level of debug messages. This won't be + very useful for the average user... + -I, --intelhex Force fileformat to IntelHex + -T, --titext Force fileformat to be TIText + -N, --notimeout Don't use timeout on serial port (use with care) + -B, --bsl=bsl.txt Load and use new BSL from the TI Text file + -S, --speed=baud Reconfigure speed, only possible with newer + MSP403-BSL versions (>1.5, read slaa089a.pdf for + details). If the --bsl option is not used, an + internal BSL replacement will be loaded. + Needs a target with at least 2kB RAM! + Possible values are 9600, 19200, 38400 + (default 9600) + -1, --f1x Specify CPU family, in case autodetect fails + -2, --f2x Specify CPU family, in case autodetect fails + -4, --f4x Specify CPU family, in case autodetect fails + --F1x and --f2x are only needed when the "change + baudrate" feature is used and the autodetect feature + fails. If the device ID that is uploaded is known, it + has precedence to the command line option. + --invert-reset Invert signal on RST pin (used for some BSL hardware) + --invert-test Invert signal on TEST/TCK pin (used for some BSL + hardware) + --swap-reset-test Swap the RST and TEST pins (used for some BSL hardware) + --telos-latch Special twiddle in BSL reset for Telos hardware + --telos-i2c DTR/RTS map via an I2C switch to TCK/RST in Telos Rev.B + --telos Implies options --invert-reset, --invert-test, + --swap-reset-test, and --telos-latch + --telosb Implies options --swap-reset-test, --telos-i2c, + --no-BSL-download, and --speed=38400 + --goodfet10 + --goodfet20 + --goodfet30 + --tmote Identical operation to --telosb + --z1 Bootstrap a Z1 + --no-BSL-download Do not download replacement BSL (disable automatic) + --force-BSL-download Download replacement BSL even if not needed (the one + in the device would have the required features) + --slow Add delays when operating the conrol pins. Useful if + the pins/circuit has high capacitance. + +Program Flow Specifiers: + -e, --masserase Mass Erase (clear all flash memory) + -E, --erasecheck Erase Check by file + -p, --program Program file + -v, --verify Verify by file + +The order of the above options matters! The table is ordered by normal +execution order. For the options "Epv" a file must be specified. +Program flow specifiers default to "pvr" if a file is given. +Don't forget to specify "e" or "eE" when programming flash! + +Data retreiving: + -u, --upload=addr Upload a datablock (see also: -s). + -s, --size=num Size of the data block do upload. (Default is 2) + -x, --hex Show a hexadecimal display of the uploaded data. + (Default) + -b, --bin Get binary uploaded data. This can be used + to redirect the output into a file. + +Do before exit: + -g, --go=address Start programm execution at specified address. + This implies option --wait. + -r, --reset Reset connected MSP430. Starts application. + This is a normal device reset and will start + the programm that is specified in the reset + vector. (see also -g) + -w, --wait Wait for before closing serial port. + +If it says "NAK received" it's probably because you specified no or a +wrong password. +""" % (sys.argv[0], VERSION)) + +#add some arguments to a function, but don't call it yet, instead return +#a wrapper object for later invocation +class curry: + """create a callable with some arguments specified in advance""" + def __init__(self, fun, *args, **kwargs): + self.fun = fun + self.pending = args[:] + self.kwargs = kwargs.copy() + + def __call__(self, *args, **kwargs): + if kwargs and self.kwargs: + kw = self.kwargs.copy() + kw.update(kwargs) + else: + kw = kwargs or self.kwargs + return apply(self.fun, self.pending + args, kw) + + def __repr__(self): + #first try if it a function + try: + return "curry(%s, %r, %r)" % (self.fun.func_name, self.pending, self.kwargs) + except AttributeError: + #fallback for callable classes + return "curry(%s, %r, %r)" % (self.fun, self.pending, self.kwargs) + +def hexify(line, bytes, width=16): + return '%04x %s%s %s' % ( + line, + ('%02x '*len(bytes)) % tuple(bytes), + ' '* (width-len(bytes)), + ('%c'*len(bytes)) % tuple(map(lambda x: (x>=32 and x<127) and x or ord('.'), bytes)) + ) + +#Main: +def main(itest=1): + global DEBUG + import getopt + filetype = None + filename = None + comPort = None #Default setting. + speed = None + unpatched = 0 + reset = 0 + wait = 0 #wait at the end + goaddr = None + bsl = BootStrapLoader() + toinit = [] + todo = [] + startaddr = None + size = 2 + hexoutput = 1 + notimeout = 0 + bslrepl = None + mayuseBSL = 1 + forceBSL = 0 + dumpivt = 0 + dumpinfo = 0 + + bsl.invertRST = 1 + bsl.invertTEST = itest + + if comPort is None and os.environ.get("GOODFET")!=None: + glob_list = glob.glob(os.environ.get("GOODFET")); + if len(glob_list) > 0: + comPort = glob_list[0]; + if comPort is None: + glob_list = glob.glob("/dev/tty.usbserial*"); + if len(glob_list) > 0: + comPort = glob_list[0]; + if comPort is None: + glob_list = glob.glob("/dev/ttyUSB*"); + if len(glob_list) > 0: + comPort = glob_list[0]; + + + sys.stderr.write("MSP430 Bootstrap Loader Version: %s\n" % VERSION) + + try: + opts, args = getopt.getopt(sys.argv[1:], + "hc:P:wf:m:neEpvrg:UDudsxbITNB:S:V14", + ["help", "comport=", "password=", "wait", "framesize=", + "erasecycles=", "masserase", "erasecheck", "program", + "verify", "reset", "go=", "unpatched", "debug", + "upload=", "download=", "size=", "hex", "bin", + "intelhex", "titext", "notimeout", "bsl=", "speed=", + "bslversion", "f1x", "f2x", "f4x", "invert-reset", "invert-test", + "swap-reset-test", "telos-latch", "telos-i2c", "telos", "telosb", + "tmote","no-BSL-download", "force-BSL-download", "slow", + "dumpivt", "dumpinfo", "fromweb", + "goodfet30", "goodfet20", "goodfet10", "z1", "mainerase" + ] + ) + except getopt.GetoptError: + # print help information and exit: + usage() + sys.exit(2) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + elif o in ("-c", "--comport"): + try: + comPort = int(a) #try to convert decimal + except ValueError: + comPort = a #take the string and let serial driver decide + elif o in ("-P", "--password"): + #extract password from file + bsl.passwd = Memory(a).getMemrange(0xffe0, 0xffff) + elif o in ("-w", "--wait"): + wait = 1 + elif o in ("--dumpivt"): + dumpivt=1; + elif o in ("--dumpinfo"): + dumpinfo=1; + elif o in ("-f", "--framesize"): + try: + maxData = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("framesize must be a valid number\n") + sys.exit(2) + #Make sure that conditions for maxData are met: + #( >= 16 and == n*16 and <= MAX_DATA_BYTES!) + if maxData > BootStrapLoader.MAX_DATA_BYTES: + maxData = BootStrapLoader.MAX_DATA_BYTES + elif maxData < 16: + maxData = 16 + bsl.maxData = maxData - (maxData % 16) + sys.stderr.write( "Max. number of data bytes within one frame set to %i.\n" % maxData) + elif o in ("-m", "--erasecycles"): + try: + meraseCycles = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("erasecycles must be a valid number\n") + sys.exit(2) + #sanity check of value + if meraseCycles < 1: + sys.stderr.write("erasecycles must be a positive number\n") + sys.exit(2) + if meraseCycles > 20: + sys.stderr.write("warning: erasecycles set to a large number (>20): %d\n" % meraseCycles) + sys.stderr.write( "Number of mass erase cycles set to %i.\n" % meraseCycles) + bsl.meraseCycles = meraseCycles + elif o in ("-e", "--masserase"): + toinit.append(bsl.actionMassErase) #Erase Flash + #todo.append(bsl.actionMainErase) #Erase Flash + elif o in ("-n", "--mainerase"): + todo.append(bsl.actionMainErase) #Erase Flash + #toinit.append(bsl.actionMassErase) #Erase Flash + elif o in ("-E", "--erasecheck"): + toinit.append(bsl.actionEraseCheck) #Erase Check (by file) + elif o in ("-p", "--program"): + #pass + todo.append(bsl.actionProgram) #Program file + if bsl.z1: + #todo.append(bsl.actionUnlockInfo) + #todo.append(bsl.writeCalibTables) + #todo.append(bsl.writeCalibTables2) + + #todo.append(bsl.actionWriteNewPassword) + pass + elif o in ("--fromweb"): + toinit.append(bsl.actionMassErase) #Erase Flash + todo.append(bsl.actionFromweb) #Program GoodFET code + elif o in ("-v", "--verify"): + todo.append(bsl.actionVerify) #Verify file + elif o in ("-r", "--reset"): + reset = 1 + elif o in ("-g", "--go"): + try: + goaddr = int(a) #try to convert decimal + except ValueError: + try: + goaddr = int(a[2:],16) #try to convert hex + except ValueError: + sys.stderr.write("go address must be a valid number\n") + sys.exit(2) + wait = 1 + elif o in ("-U", "--unpatched"): + unpatched = 1 + elif o in ("-D", "--debug"): + DEBUG = DEBUG + 1 + elif o in ("-u", "--upload"): + try: + startaddr = int(a) #try to convert decimal + except ValueError: + try: + startaddr = int(a,16) #try to convert hex + except ValueError: + sys.stderr.write("upload address must be a valid number\n") + sys.exit(2) + elif o in ("-s", "--size"): + try: + size = int(a) + except ValueError: + try: + size = int(a,16) + except ValueError: + sys.stderr.write("size must be a valid number\n") + sys.exit(2) + elif o in ("-x", "--hex"): + hexoutput = 1 + elif o in ("-b", "--bin"): + hexoutput = 0 + elif o in ("-I", "--intelhex"): + filetype = 0 + elif o in ("-T", "--titext"): + filetype = 1 + elif o in ("-N", "--notimeout"): + notimeout = 1 + elif o in ("-B", "--bsl"): + bslrepl = Memory() #File to program + bslrepl.loadFile(a) + elif o in ("-V", "--bslversion"): + todo.append(bsl.actionReadBSLVersion) #load replacement BSL as first item + elif o in ("-S", "--speed"): + try: + speed = int(a) #try to convert decimal + except ValueError: + sys.stderr.write("speed must be decimal number\n") + sys.exit(2) + elif o in ("-1", "--f1x"): + bsl.cpu = F1x + elif o in ("-2", "--f2x"): + bsl.cpu = F2x + elif o in ("-4", "--f4x"): + bsl.cpu = F4x + elif o in ("--invert-reset", ): + bsl.invertRST = 1 + elif o in ("--invert-test", ): + bsl.invertTEST = 1 + elif o in ("--swap-reset-test", ): + bsl.swapRSTTEST = 1 + elif o in ("--telos-latch", ): + bsl.telosLatch = 1 + elif o in ("--telos-i2c", ): + bsl.telosI2C = 1 + elif o in ("--telos", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + bsl.swapRSTTEST = 1 + bsl.telosLatch = 1 + elif o in ("--goodfet10", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + elif o in ("--goodfet20", ): + bsl.invertRST = 1 + bsl.invertTEST = 1 + elif o in ("--goodfet30", ): + bsl.invertRST = 1 + bsl.invertTEST = 0 + elif o in ("--telosb", ): + bsl.swapRSTTEST = 1 + bsl.telosI2C = 1 + mayuseBSL = 0 + speed = 38400 + elif o in ("--tmote", ): + bsl.swapRSTTEST = 1 + bsl.telosI2C = 1 + mayuseBSL = 0 + speed = 38400 + elif o in ("--z1", ): + bsl.z1 = 1 + speed = 38400 + #toinit.append(bsl.actionRecoverPassword) + elif o in ("--no-BSL-download", ): + mayuseBSL = 0 + elif o in ("--force-BSL-download", ): + forceBSL = 1 + elif o in ("--slow", ): + bsl.slowmode = 1 + + if len(args) == 0: + sys.stderr.write("Use -h for help\n"); + sys.stderr.write("Use --fromweb to upgrade a GoodFET.\n") + elif len(args) == 1: #a filename is given + if not todo: #if there are no actions yet + todo.extend([ #add some useful actions... + bsl.actionProgram, + bsl.actionVerify, + ]) + filename = args[0] + else: #number of args is wrong + usage() + sys.exit(2) + + if DEBUG: #debug infos + sys.stderr.write("Debug level set to %d\n" % DEBUG) + sys.stderr.write("Python version: %s\n" % sys.version) + + #sanity check of options + if notimeout and goaddr is not None and startaddr is not None: + sys.stderr.write("Option --notimeout can not be used together with both --upload and --go\n") + sys.exit(1) + + if notimeout: + sys.stderr.write("Warning: option --notimeout can cause improper function in some cases!\n") + bsl.timeout = 0 + + if goaddr and reset: + sys.stderr.write("Warning: option --reset ignored as --go is specified!\n") + reset = 0 + + if startaddr and reset: + sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n") + reset = 0 + + sys.stderr.flush() + + #prepare data to download + bsl.data = Memory() #prepare downloaded data + if filetype is not None: #if the filetype is given... + if filename is None: + raise ValueError("no filename but filetype specified") + if filename == '-': #get data from stdin + file = sys.stdin + else: + file = open(filename, "rb") #or from a file + if filetype == 0: #select load function + bsl.data.loadIHex(file) #intel hex + elif filetype == 1: + bsl.data.loadTIText(file) #TI's format + else: + raise ValueError("illegal filetype specified") + else: #no filetype given... + if filename == '-': #for stdin: + bsl.data.loadIHex(sys.stdin) #assume intel hex + elif filename: + bsl.data.loadFile(filename) #autodetect otherwise + + if DEBUG > 3: sys.stderr.write("File: %r" % filename) + + bsl.comInit(comPort) #init port + + #initialization list + if toinit: #erase and erase check + if DEBUG: sys.stderr.write("Preparing device ...\n") + #bsl.actionStartBSL(usepatch=0, adjsp=0) #no workarounds needed + #if speed: bsl.actionChangeBaudrate(speed) #change baud rate as fast as possible + for f in toinit: f() + + if todo or goaddr or startaddr: + if DEBUG: sys.stderr.write("Actions ...\n") + #connect to the BSL + bsl.actionStartBSL( + usepatch=not unpatched, + replacementBSL=bslrepl, + forceBSL=forceBSL, + mayuseBSL=mayuseBSL, + speed=speed, + ) + + #work list + if todo: + if DEBUG > 0: #debug + #show a nice list of sheduled actions + sys.stderr.write("TODO list:\n") + for f in todo: + try: + sys.stderr.write(" %s\n" % f.func_name) + except AttributeError: + sys.stderr.write(" %r\n" % f) + for f in todo: f() #work through todo list + + if reset: #reset device first if desired + bsl.actionReset() + if dumpivt: + bsl.txPasswd(); #default pass + data=bsl.uploadData(0xc00,1024); + hex=""; + for c in data: + hex+=("%02x "%ord(c)); + print hex; + if dumpinfo: + bsl.txPasswd(); #default pass + data=bsl.uploadData(0x1000,256); + hex="@1000\n"; + for c in data: + hex+=("%02x "%ord(c)); + hex+="\nq\n"; + print hex; + + if goaddr is not None: #start user programm at specified address + bsl.actionRun(goaddr) #load PC and execute + + #upload datablock and output + if startaddr is not None: + if goaddr: #if a program was started... + #don't restart BSL but wait for the device to enter it itself + sys.stderr.write("Waiting for device to reconnect for upload: ") + sys.stderr.flush() + bsl.txPasswd(bsl.passwd, wait=1) #synchronize, try forever... + data = bsl.uploadData(startaddr, size) #upload data + else: + data = bsl.uploadData(startaddr, size) #upload data + if hexoutput: #depending on output format + m = 0 + while m < len(data): #print a hex display + print hexify(startaddr+m, map(ord,data[m:m+16])) + m = m + 16 + else: + sys.stdout.write(data) #binary output w/o newline! + wait = 0 #wait makes no sense as after the upload the device is still in BSL + + if wait: #wait at the end if desired + sys.stderr.write("Press ...\n") #display a prompt + sys.stderr.flush() + raw_input() #wait for newline + + bsl.comDone() #Release serial communication port + +if __name__ == '__main__': + try: + main(1) + except SystemExit: + raise #let pass exit() calls + except KeyboardInterrupt: + if DEBUG: raise #show full trace in debug mode + sys.stderr.write("user abort.\n") #short messy in user mode + sys.exit(1) #set errorlevel for script usage + except Exception, msg: #every Exception is caught and displayed + if DEBUG: raise #show full trace in debug mode + #sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode + #sys.exit(1) #set errorlevel for script usage + main(0); From 313802dcbd1c85aede783d97235b4a12a00a0127 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 11 Jan 2019 15:41:28 +0000 Subject: [PATCH 173/184] Exclude z1 from some Makefiles: not all examples can be built on z1 due to limited memory --- examples/6tisch/6p-packet/Makefile | 2 +- examples/6tisch/channel-selection-demo/Makefile | 2 +- examples/6tisch/etsi-plugtest-2017/Makefile | 2 +- examples/6tisch/sixtop/Makefile | 2 +- examples/6tisch/timesync-demo/Makefile | 2 +- examples/6tisch/tsch-stats/Makefile | 2 +- examples/benchmarks/rpl-req-resp/Makefile | 2 +- examples/coap/coap-example-client/Makefile | 2 +- examples/coap/coap-example-server/Makefile | 2 +- examples/lwm2m-ipso-objects/Makefile | 2 +- examples/multicast/Makefile | 4 ++-- examples/rpl-border-router/Makefile | 2 +- examples/sensniff/Makefile | 2 +- examples/websocket/Makefile | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/6tisch/6p-packet/Makefile b/examples/6tisch/6p-packet/Makefile index 3ba74d3b9..707a02485 100644 --- a/examples/6tisch/6p-packet/Makefile +++ b/examples/6tisch/6p-packet/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = sixp-node PROJECT_SOURCEFILES += test-sf.c -PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +PLATFORMS_EXCLUDE = sky z1 nrf52dk native simplelink CONTIKI = ../../../ diff --git a/examples/6tisch/channel-selection-demo/Makefile b/examples/6tisch/channel-selection-demo/Makefile index ada4a5062..e3c4288f6 100644 --- a/examples/6tisch/channel-selection-demo/Makefile +++ b/examples/6tisch/channel-selection-demo/Makefile @@ -3,7 +3,7 @@ all: $(CONTIKI_PROJECT) CONTIKI=../../.. -PLATFORMS_EXCLUDE = sky nrf52dk native +PLATFORMS_EXCLUDE = sky z1 nrf52dk native BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 # The channel selection library diff --git a/examples/6tisch/etsi-plugtest-2017/Makefile b/examples/6tisch/etsi-plugtest-2017/Makefile index 6dc463078..6b1a23a4c 100644 --- a/examples/6tisch/etsi-plugtest-2017/Makefile +++ b/examples/6tisch/etsi-plugtest-2017/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +PLATFORMS_EXCLUDE = sky z1 nrf52dk native simplelink BOARDS_EXCLUDE = sensortag/cc2650 sensortag/cc1350 MAKE_WITH_SECURITY ?= 0 # force Security from command line diff --git a/examples/6tisch/sixtop/Makefile b/examples/6tisch/sixtop/Makefile index 5c35696e4..1e6f0ef5f 100644 --- a/examples/6tisch/sixtop/Makefile +++ b/examples/6tisch/sixtop/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = node-sixtop all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +PLATFORMS_EXCLUDE = sky z1 nrf52dk native simplelink PROJECT_SOURCEFILES += sf-simple.c CONTIKI=../../.. diff --git a/examples/6tisch/timesync-demo/Makefile b/examples/6tisch/timesync-demo/Makefile index cd18192d0..85c29659f 100644 --- a/examples/6tisch/timesync-demo/Makefile +++ b/examples/6tisch/timesync-demo/Makefile @@ -3,7 +3,7 @@ all: $(CONTIKI_PROJECT) CONTIKI=../../.. -PLATFORMS_EXCLUDE = sky nrf52dk native +PLATFORMS_EXCLUDE = sky z1 nrf52dk native # force Orchestra from command line MAKE_WITH_ORCHESTRA ?= 0 diff --git a/examples/6tisch/tsch-stats/Makefile b/examples/6tisch/tsch-stats/Makefile index 5fdb5feb6..156c0d526 100644 --- a/examples/6tisch/tsch-stats/Makefile +++ b/examples/6tisch/tsch-stats/Makefile @@ -3,7 +3,7 @@ all: $(CONTIKI_PROJECT) CONTIKI=../../.. -PLATFORMS_EXCLUDE = sky nrf52dk native +PLATFORMS_EXCLUDE = sky z1 nrf52dk native BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 # force Orchestra from command line diff --git a/examples/benchmarks/rpl-req-resp/Makefile b/examples/benchmarks/rpl-req-resp/Makefile index e23a35d5f..dadd7a2d7 100644 --- a/examples/benchmarks/rpl-req-resp/Makefile +++ b/examples/benchmarks/rpl-req-resp/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +PLATFORMS_EXCLUDE = sky z1 nrf52dk native simplelink BOARDS_EXCLUDE = srf06/cc13x0 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 MODULES_REL += ../testbeds diff --git a/examples/coap/coap-example-client/Makefile b/examples/coap/coap-example-client/Makefile index 1d3440990..21c9649e7 100644 --- a/examples/coap/coap-example-client/Makefile +++ b/examples/coap/coap-example-client/Makefile @@ -3,7 +3,7 @@ CONTIKI_PROJECT = coap-example-client all: $(CONTIKI_PROJECT) # Do not try to build on Sky because of code size limitation -PLATFORMS_EXCLUDE = sky +PLATFORMS_EXCLUDE = sky z1 # Include the CoAP implementation MODULES += os/net/app-layer/coap diff --git a/examples/coap/coap-example-server/Makefile b/examples/coap/coap-example-server/Makefile index 6d9e2db85..1647568cb 100644 --- a/examples/coap/coap-example-server/Makefile +++ b/examples/coap/coap-example-server/Makefile @@ -2,7 +2,7 @@ CONTIKI_PROJECT = coap-example-server all: $(CONTIKI_PROJECT) # Do not try to build on Sky because of code size limitation -PLATFORMS_EXCLUDE = sky +PLATFORMS_EXCLUDE = sky z1 # Include the CoAP implementation MODULES += os/net/app-layer/coap diff --git a/examples/lwm2m-ipso-objects/Makefile b/examples/lwm2m-ipso-objects/Makefile index c2cef2cfd..a8d461859 100644 --- a/examples/lwm2m-ipso-objects/Makefile +++ b/examples/lwm2m-ipso-objects/Makefile @@ -2,7 +2,7 @@ CONTIKI_PROJECT = example-ipso-objects CONTIKI_SOURCEFILES += serial-protocol.c example-ipso-temperature.c -PLATFORMS_EXCLUDE = sky +PLATFORMS_EXCLUDE = sky z1 all: $(CONTIKI_PROJECT) diff --git a/examples/multicast/Makefile b/examples/multicast/Makefile index 86c16e481..3e8a88d4a 100644 --- a/examples/multicast/Makefile +++ b/examples/multicast/Makefile @@ -3,8 +3,8 @@ all: $(CONTIKI_PROJECT) # nrf52dk only supports slave mode, i.e., with no routing PLATFORMS_EXCLUDE = nrf52dk -# does not fit sky motes -PLATFORMS_EXCLUDE += sky +# does not fit on sky and z1 motes +PLATFORMS_EXCLUDE += sky z1 CONTIKI = ../.. diff --git a/examples/rpl-border-router/Makefile b/examples/rpl-border-router/Makefile index 4d2db2a85..8d210dd3c 100644 --- a/examples/rpl-border-router/Makefile +++ b/examples/rpl-border-router/Makefile @@ -3,7 +3,7 @@ all: $(CONTIKI_PROJECT) CONTIKI = ../.. # The BR is either native or embedded, and in the latter case must support SLIP -PLATFORMS_EXCLUDE = nrf52dk +PLATFORMS_EXCLUDE = nrf52dk z1 # Include RPL BR module MODULES += os/services/rpl-border-router diff --git a/examples/sensniff/Makefile b/examples/sensniff/Makefile index 3b7c5116c..78cb41a3e 100644 --- a/examples/sensniff/Makefile +++ b/examples/sensniff/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = sensniff CONTIKI = ../.. -PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul cc26x0-cc13x0 jn516x simplelink +PLATFORMS_ONLY = cc2538dk openmote-cc2538 z1 zoul cc26x0-cc13x0 jn516x simplelink PROJECT_SOURCEFILES += sensniff-mac.c netstack.c MODULES_REL += pool $(TARGET) diff --git a/examples/websocket/Makefile b/examples/websocket/Makefile index 87d0789c1..d0b38d95d 100644 --- a/examples/websocket/Makefile +++ b/examples/websocket/Makefile @@ -3,6 +3,6 @@ all: $(CONTIKI_PROJECT) CONTIKI=../.. MODULES += os/net/app-layer/http-socket -PLATFORMS_EXCLUDE = sky +PLATFORMS_EXCLUDE = sky z1 include $(CONTIKI)/Makefile.include From 4d0ca686f2de2a65618390922b8263a652ad4000 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Sat, 12 Jan 2019 20:33:07 +0000 Subject: [PATCH 174/184] Add back some regression tests for the Z1 platform --- tests/01-compile-base/Makefile | 2 + .../07-simulation-base/07-hello-world-z1.csc | 83 +++++++ tests/07-simulation-base/23-rpl-tsch-z1.csc | 206 ++++++++++++++++++ tests/07-simulation-base/hello-world.js | 9 + 4 files changed, 300 insertions(+) create mode 100644 tests/07-simulation-base/07-hello-world-z1.csc create mode 100644 tests/07-simulation-base/23-rpl-tsch-z1.csc create mode 100644 tests/07-simulation-base/hello-world.js diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index 09f89418d..51e68f9a2 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -6,6 +6,7 @@ hello-world/native \ hello-world/native:MAKE_NET=MAKE_NET_NULLNET \ hello-world/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ hello-world/sky \ +hello-world/z1 \ storage/eeprom-test/native \ libs/logging/native \ libs/energest/native \ @@ -30,6 +31,7 @@ mqtt-client/native \ coap/coap-example-client/native \ coap/coap-example-server/native \ coap/coap-plugtest-server/native \ +sensniff/z1 \ TOOLS= diff --git a/tests/07-simulation-base/07-hello-world-z1.csc b/tests/07-simulation-base/07-hello-world-z1.csc new file mode 100644 index 000000000..33963c36c --- /dev/null +++ b/tests/07-simulation-base/07-hello-world-z1.csc @@ -0,0 +1,83 @@ + + + + Hello World (Z1) + generated + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.mspmote.Z1MoteType + z11 + Z1 Mote Type #z11 + [CONTIKI_DIR]/examples/hello-world/hello-world.c + make hello-world.z1 TARGET=z1 + [CONTIKI_DIR]/examples/hello-world/hello-world.z1 + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspDefaultSerial + org.contikios.cooja.mspmote.interfaces.MspLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + + + + + org.contikios.cooja.interfaces.Position + 94.96401380574989 + 21.247662337471553 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 1 + + z11 + + + + org.contikios.cooja.plugins.SimControl + 280 + 2 + 160 + 38 + 13 + + + org.contikios.cooja.plugins.LogListener + + + + 680 + 1 + 240 + 109 + 377 + + + org.contikios.cooja.plugins.ScriptRunner + + [CONFIG_DIR]/hello-world.js + true + + 600 + 0 + 700 + 330 + 24 + + + diff --git a/tests/07-simulation-base/23-rpl-tsch-z1.csc b/tests/07-simulation-base/23-rpl-tsch-z1.csc new file mode 100644 index 000000000..f5a182ecd --- /dev/null +++ b/tests/07-simulation-base/23-rpl-tsch-z1.csc @@ -0,0 +1,206 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + RPL+TSCH (Z1) + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.mspmote.Z1MoteType + z11 + Z1 Mote Type #z11 + [CONTIKI_DIR]/examples/6tisch/simple-node/node.c + make TARGET=z1 clean + make -j node.z1 TARGET=z1 MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0 MAKE_WITH_PERIODIC_ROUTES_PRINT=1 + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspDefaultSerial + org.contikios.cooja.mspmote.interfaces.MspLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + + + + + org.contikios.cooja.interfaces.Position + -1.285769821276336 + 38.58045647334346 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 1 + + z11 + + + + + org.contikios.cooja.interfaces.Position + -19.324109516886306 + 76.23135780254927 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 2 + + z11 + + + + + org.contikios.cooja.interfaces.Position + 5.815501305791592 + 76.77463755494317 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 3 + + z11 + + + + + org.contikios.cooja.interfaces.Position + 31.920697784030082 + 50.5212265977149 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 4 + + z11 + + + + + org.contikios.cooja.interfaces.Position + 47.21747673247198 + 30.217765340599726 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 5 + + z11 + + + + + org.contikios.cooja.interfaces.Position + 10.622284947035123 + 109.81862399725188 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 6 + + z11 + + + + org.contikios.cooja.plugins.SimControl + 242 + 4 + 160 + 11 + 241 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.TrafficVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + 1.7405603810040515 0.0 0.0 1.7405603810040515 47.95980153208088 -42.576134155447555 + + 236 + 3 + 230 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + ID:1 + + + + 1031 + 0 + 394 + 273 + 6 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + + + + 16529.88882215865 + + 1304 + 2 + 311 + 0 + 412 + + + org.contikios.cooja.plugins.ScriptRunner + + + true + + 764 + 1 + 995 + 963 + 111 + + diff --git a/tests/07-simulation-base/hello-world.js b/tests/07-simulation-base/hello-world.js new file mode 100644 index 000000000..5afaabe18 --- /dev/null +++ b/tests/07-simulation-base/hello-world.js @@ -0,0 +1,9 @@ +TIMEOUT(5000); + +while(true) { + log.log("> " + msg + "\n"); + if (msg.equals('Hello, world')) { + log.testOK(); + } + YIELD(); +} From bc09e105785870f936dfe9683798fa41939d2d5c Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 14 Jan 2019 12:47:10 +0000 Subject: [PATCH 175/184] add back sensniff config for Zolertia z1 --- examples/sensniff/z1/target-conf.h | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/sensniff/z1/target-conf.h diff --git a/examples/sensniff/z1/target-conf.h b/examples/sensniff/z1/target-conf.h new file mode 100644 index 000000000..6e3db2b48 --- /dev/null +++ b/examples/sensniff/z1/target-conf.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, George Oikonomou - http://www.spd.gr + * 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. + */ +/*---------------------------------------------------------------------------*/ +#ifndef TARGET_CONF_H_ +#define TARGET_CONF_H_ +/*---------------------------------------------------------------------------*/ +#define MSP430_IO_CONF_USE_UART1 0 +#define UART0_CONF_BAUD_RATE 460800 +/*---------------------------------------------------------------------------*/ +#define SENSNIFF_IO_DRIVER_H "pool/msp430-io.h" +/*---------------------------------------------------------------------------*/ +#endif /* TARGET_CONF_H_ */ +/*---------------------------------------------------------------------------*/ From b955dbe9a12f76c0f1aed13e0bb1ded388b0ee6e Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 14 Jan 2019 14:49:38 +0000 Subject: [PATCH 176/184] TSCH simple node: also set coordinator id node_id == 1 on Z1 --- examples/6tisch/simple-node/node.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/6tisch/simple-node/node.c b/examples/6tisch/simple-node/node.c index 381d81f8e..b8e29e7f6 100644 --- a/examples/6tisch/simple-node/node.c +++ b/examples/6tisch/simple-node/node.c @@ -60,7 +60,7 @@ PROCESS_THREAD(node_process, ev, data) is_coordinator = 0; -#if CONTIKI_TARGET_COOJA +#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_Z1 is_coordinator = (node_id == 1); #endif From 284b52c8b6e510dc74b6aed13b2a85b91ea7bdf0 Mon Sep 17 00:00:00 2001 From: firmwareguru Date: Mon, 14 Jan 2019 19:23:13 -0700 Subject: [PATCH 177/184] Fix cc26x0-cc13x0 example not building --- examples/platform-specific/cc26x0-cc13x0/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform-specific/cc26x0-cc13x0/Makefile b/examples/platform-specific/cc26x0-cc13x0/Makefile index 9962ab32a..bd9600c78 100644 --- a/examples/platform-specific/cc26x0-cc13x0/Makefile +++ b/examples/platform-specific/cc26x0-cc13x0/Makefile @@ -1,4 +1,4 @@ -CONTIKI_PROJECT = cc26xx-demo +CONTIKI_PROJECT = cc26x0-demo PLATFORMS_ONLY = cc26x0-cc13x0 From 8203abb2e7063206d477752aa8073bc971646d93 Mon Sep 17 00:00:00 2001 From: firmwareguru Date: Mon, 14 Jan 2019 19:35:12 -0700 Subject: [PATCH 178/184] fixes contiki-ng/contiki-ng#768 simplelink opt3001 wrong value --- .../cc13xx-cc26xx/sensortag/opt-3001-sensor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c index 885fefe88..42e3976d8 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c @@ -303,9 +303,13 @@ value(int type) result_value = SWAP16(result_value); - uint32_t e = (result_value & 0x0FFF) >> 0; - uint32_t m = (result_value & 0xF000) >> 12; - uint32_t converted = m * 100 * (1 << e); + /* formula for computing lux: lux = 0.01 * 2^e * m + * scale up by 100 to avoid floating point, then require + * users to scale down by same. + */ + uint32_t m = (result_value & 0x0FFF) >> 0; + uint32_t e = (result_value & 0xF000) >> 12; + uint32_t converted = m * (1 << e); PRINTF("OPT: %04X r=%d (centilux)\n", result_value, (int)(converted)); From 855089af8d4636572d287201917970bb65040c7f Mon Sep 17 00:00:00 2001 From: Takeshi Sakoda Date: Tue, 15 Jan 2019 14:10:59 +0900 Subject: [PATCH 179/184] tsch: fix for https://github.com/contiki-ng/contiki-ng/pull/769#discussion_r247239784 --- os/net/mac/tsch/tsch.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index bb1018677..6278ce0dc 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -861,13 +861,12 @@ PROCESS_THREAD(tsch_send_eb_process, ev, data) while(1) { unsigned long delay; - if(tsch_is_associated && tsch_current_eb_period > 0) { + if(tsch_is_associated && tsch_current_eb_period > 0 #ifdef TSCH_RPL_CHECK_DODAG_JOINED /* Implementation section 6.3 of RFC 8180 */ - if(!TSCH_RPL_CHECK_DODAG_JOINED()) { - goto tsch_send_eb_skipped; - } + && TSCH_RPL_CHECK_DODAG_JOINED() #endif /* TSCH_RPL_CHECK_DODAG_JOINED */ + ) { /* Enqueue EB only if there isn't already one in queue */ if(tsch_queue_packet_count(&tsch_eb_address) == 0) { uint8_t hdr_len = 0; @@ -887,9 +886,6 @@ PROCESS_THREAD(tsch_send_eb_process, ev, data) } } } -#ifdef TSCH_RPL_CHECK_DODAG_JOINED -tsch_send_eb_skipped: -#endif /* TSCH_RPL_CHECK_DODAG_JOINED */ if(tsch_current_eb_period > 0) { /* Next EB transmission with a random delay * within [tsch_current_eb_period*0.75, tsch_current_eb_period[ */ From c177034d39468bbbda7229b975e0793decfe44b9 Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Fri, 18 Jan 2019 17:37:25 +0100 Subject: [PATCH 180/184] Fixed BLE advertisement on SimpleLink A couple of issues was found: * Wrong CPE patches in RF settings * Wrong whitening init value for the CMD_BLE5_ADV_NC command * BLE MAC address was not copied to RAM before set in the bleAdvPar construct. * BLE advertisements were not transmitted in intervals as specified by BLE spec. --- .../rf-settings/cc13x0/ble-settings.c | 46 +---- .../rf-settings/cc13x0/ble-settings.h | 1 - .../rf-settings/cc13x0/ieee-settings.c | 2 +- .../rf-settings/cc13x0/prop-settings.c | 2 +- .../rf-settings/cc13x2/ble-settings.c | 56 ++---- .../rf-settings/cc13x2/ble-settings.h | 1 - .../rf-settings/cc13x2/ieee-settings.c | 4 +- .../rf-settings/cc13x2/prop-settings.c | 4 +- .../rf-settings/cc26x0/ble-settings.c | 46 +---- .../rf-settings/cc26x0/ble-settings.h | 1 - .../rf-settings/cc26x0/ieee-settings.c | 2 +- .../rf-settings/cc26x2/ble-settings.c | 56 ++---- .../rf-settings/cc26x2/ble-settings.h | 1 - .../rf-settings/cc26x2/ieee-settings.c | 4 +- .../simplelink-cc13xx-cc26xx/rf/ble-addr.c | 21 +- .../simplelink-cc13xx-cc26xx/rf/ble-addr.h | 17 +- .../simplelink-cc13xx-cc26xx/rf/ble-beacond.c | 161 +++++++++------- .../simplelink-cc13xx-cc26xx/rf/ieee-mode.c | 38 ++-- .../simplelink-cc13xx-cc26xx/rf/prop-mode.c | 38 ++-- arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c | 180 ++++++++++++++++-- arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h | 12 +- .../simplelink-cc13xx-cc26xx/rf/settings.h | 4 +- 22 files changed, 391 insertions(+), 306 deletions(-) diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c index 7fc79ae2d..539046a48 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c @@ -56,7 +56,7 @@ /* TI-RTOS RF Mode Object */ RF_Mode rf_ble_mode = { - .rfMode = RF_MODE_BLE, + .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = &rf_patch_cpe_ble, .mcePatchFxn = 0, .rfePatchFxn = &rf_patch_rfe_ble, @@ -117,38 +117,6 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = .pRegOverride = rf_ble_overrides, }; /*---------------------------------------------------------------------------*/ -/* Structure for CMD_BLE_ADV_NC.pParams */ -rfc_bleAdvPar_t rf_ble_adv_par = -{ - .pRxQ = 0, - .rxConfig.bAutoFlushIgnored = 0x0, - .rxConfig.bAutoFlushCrcErr = 0x0, - .rxConfig.bAutoFlushEmpty = 0x0, - .rxConfig.bIncludeLenByte = 0x0, - .rxConfig.bIncludeCrc = 0x0, - .rxConfig.bAppendRssi = 0x0, - .rxConfig.bAppendStatus = 0x0, - .rxConfig.bAppendTimestamp = 0x0, - .advConfig.advFilterPolicy = 0x0, - .advConfig.deviceAddrType = 0x0, - .advConfig.peerAddrType = 0x0, - .advConfig.bStrictLenFilter = 0x0, - .advConfig.rpaMode = 0x0, - .advLen = 0x18, - .scanRspLen = 0x00, - .pAdvData = 0, - .pScanRspData = 0, - .pDeviceAddress = 0, - .pWhiteList = 0, - .__dummy0 = 0x0000, - .__dummy1 = 0x00, - .endTrigger.triggerType = TRIG_NEVER, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, -}; -/*---------------------------------------------------------------------------*/ /* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = { @@ -159,13 +127,13 @@ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = COND_NEVER, + .startTrigger.pastTrig = 0x1, + .condition.rule = 0x0, /* set by driver */ .condition.nSkip = 0x0, - .channel = 0x8C, - .whitening.init = 0x51, + .channel = 0x00, /* set by driver */ + .whitening.init = 0x00, /* set by driver */ .whitening.bOverride = 0x1, - .pParams = &rf_ble_adv_par, - .pOutput = 0, + .pParams = 0x00000000, /* set by driver */ + .pOutput = 0x00000000, /* set by driver */ }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h index 81fbf67ba..4d94edca8 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h @@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode; /*---------------------------------------------------------------------------*/ /* RF Core API commands */ extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup; -extern rfc_bleAdvPar_t rf_ble_adv_par; extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc; /*---------------------------------------------------------------------------*/ /* RF Core API Overrides */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c index 2a383e6c6..ce7b00a0b 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c @@ -57,7 +57,7 @@ /* TI-RTOS RF Mode Object */ RF_Mode rf_ieee_mode = { - .rfMode = RF_MODE_IEEE_15_4, + .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = 0, .mcePatchFxn = 0, .rfePatchFxn = 0, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c index 64dbe591f..3d57fc3a3 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c @@ -68,7 +68,7 @@ /* TI-RTOS RF Mode Object */ RF_Mode rf_prop_mode = { - .rfMode = RF_MODE_PROPRIETARY_SUB_1, + .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = &rf_patch_cpe_genfsk, .mcePatchFxn = 0, .rfePatchFxn = &rf_patch_rfe_genfsk, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c index b9e32a04d..d44264f3a 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c @@ -47,7 +47,7 @@ #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h) @@ -59,7 +59,7 @@ RF_Mode rf_ble_mode = { .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_bt5, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, .mcePatchFxn = &rf_patch_mce_bt5, .rfePatchFxn = &rf_patch_rfe_bt5, }; @@ -148,60 +148,28 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = .pRegOverrideCoded = rf_ble_overrides_coded, }; /*---------------------------------------------------------------------------*/ -/* Structure for CMD_BLE5_ADV_NC.pParams */ -rfc_bleAdvPar_t rf_ble_adv_par = -{ - .pRxQ = 0, - .rxConfig.bAutoFlushIgnored = 0x0, - .rxConfig.bAutoFlushCrcErr = 0x0, - .rxConfig.bAutoFlushEmpty = 0x0, - .rxConfig.bIncludeLenByte = 0x0, - .rxConfig.bIncludeCrc = 0x0, - .rxConfig.bAppendRssi = 0x0, - .rxConfig.bAppendStatus = 0x0, - .rxConfig.bAppendTimestamp = 0x0, - .advConfig.advFilterPolicy = 0x0, - .advConfig.deviceAddrType = 0x0, - .advConfig.peerAddrType = 0x0, - .advConfig.bStrictLenFilter = 0x0, - .advConfig.rpaMode = 0x0, - .advLen = 0x18, - .scanRspLen = 0x00, - .pAdvData = 0, - .pScanRspData = 0, - .pDeviceAddress = 0, - .pWhiteList = 0, - .__dummy0 = 0x0000, - .__dummy1 = 0x00, - .endTrigger.triggerType = TRIG_NEVER, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, -}; -/*---------------------------------------------------------------------------*/ /* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */ rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc = { - .commandNo = 0x182D, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .commandNo = CMD_BLE5_ADV_NC, + .status = IDLE, + .pNextOp = 0, .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, + .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, + .startTrigger.pastTrig = 0x1, + .condition.rule = 0x0, /* set by driver */ .condition.nSkip = 0x0, - .channel = 0x8C, - .whitening.init = 0x51, + .channel = 0x00, /* set by driver */ + .whitening.init = 0x00, /* set by driver */ .whitening.bOverride = 0x1, .phyMode.mainMode = 0x0, .phyMode.coding = 0x0, .rangeDelay = 0x00, .txPower = 0x0000, - .pParams = &rf_ble_adv_par, - .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .pParams = 0x00000000, /* set by driver */ + .pOutput = 0x00000000, /* set by driver */ .tx20Power = 0x00000000, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h index 2e6defa71..c5295c868 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h @@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode; /*---------------------------------------------------------------------------*/ /* RF Core API commands */ extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup; -extern rfc_bleAdvPar_t rf_ble_adv_par; extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc; /*---------------------------------------------------------------------------*/ /* RF Core API Overrides */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c index 1f5e3d8d7..665bd568e 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c @@ -51,7 +51,7 @@ #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h) #include @@ -62,7 +62,7 @@ RF_Mode rf_ieee_mode = { .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_ieee_802_15_4, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, .mcePatchFxn = &rf_patch_mce_ieee_802_15_4, .rfePatchFxn = 0, }; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c index c63e6bef7..0f098c5e1 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c @@ -63,7 +63,7 @@ #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_prop.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_genfsk.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_mce_genfsk.h) @@ -75,7 +75,7 @@ RF_Mode rf_prop_mode = { .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_prop, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, .mcePatchFxn = &rf_patch_mce_genfsk, .rfePatchFxn = &rf_patch_rfe_genfsk, }; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c index 7edc3e487..255deb151 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c @@ -55,7 +55,7 @@ /* TI-RTOS RF Mode Object */ RF_Mode rf_ble_mode = { - .rfMode = RF_MODE_BLE, + .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = &rf_patch_cpe_ble, .mcePatchFxn = 0, .rfePatchFxn = &rf_patch_rfe_ble, @@ -113,38 +113,6 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = .pRegOverride = rf_ble_overrides, }; /*---------------------------------------------------------------------------*/ -/* Structure for CMD_BLE_ADV_NC.pParams */ -rfc_bleAdvPar_t rf_ble_adv_par = -{ - .pRxQ = 0, - .rxConfig.bAutoFlushIgnored = 0x0, - .rxConfig.bAutoFlushCrcErr = 0x0, - .rxConfig.bAutoFlushEmpty = 0x0, - .rxConfig.bIncludeLenByte = 0x0, - .rxConfig.bIncludeCrc = 0x0, - .rxConfig.bAppendRssi = 0x0, - .rxConfig.bAppendStatus = 0x0, - .rxConfig.bAppendTimestamp = 0x0, - .advConfig.advFilterPolicy = 0x0, - .advConfig.deviceAddrType = 0x0, - .advConfig.peerAddrType = 0x0, - .advConfig.bStrictLenFilter = 0x0, - .advConfig.rpaMode = 0x0, - .advLen = 0x18, - .scanRspLen = 0x00, - .pAdvData = 0, - .pScanRspData = 0, - .pDeviceAddress = 0, - .pWhiteList = 0, - .__dummy0 = 0x0000, - .__dummy1 = 0x00, - .endTrigger.triggerType = TRIG_NEVER, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, -}; -/*---------------------------------------------------------------------------*/ /* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = { @@ -155,13 +123,13 @@ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = COND_NEVER, + .startTrigger.pastTrig = 0x1, + .condition.rule = 0x0, /* set by driver */ .condition.nSkip = 0x0, - .channel = 0x8C, - .whitening.init = 0x51, + .channel = 0x00, /* set by driver */ + .whitening.init = 0x00, /* set by driver */ .whitening.bOverride = 0x1, - .pParams = &rf_ble_adv_par, - .pOutput = 0, + .pParams = 0x00000000, /* set by driver */ + .pOutput = 0x00000000, /* set by driver */ }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h index c89304105..0679265d6 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h @@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode; /*---------------------------------------------------------------------------*/ /* RF Core API commands */ extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup; -extern rfc_bleAdvPar_t rf_ble_adv_par; extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc; /*---------------------------------------------------------------------------*/ /* RF Core API Overrides */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c index e93561962..71842215e 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c @@ -53,7 +53,7 @@ /* TI-RTOS RF Mode Object */ RF_Mode rf_ieee_mode = { - .rfMode = RF_MODE_IEEE_15_4, + .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = &rf_patch_cpe_ieee, .mcePatchFxn = 0, .rfePatchFxn = 0, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c index 8ee2b2684..bba7c083b 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c @@ -46,7 +46,7 @@ #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h) @@ -58,7 +58,7 @@ RF_Mode rf_ble_mode = { .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_bt5, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, .mcePatchFxn = &rf_patch_mce_bt5, .rfePatchFxn = &rf_patch_rfe_bt5, }; @@ -148,60 +148,28 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = .pRegOverrideCoded = rf_ble_overrides_coded, }; /*---------------------------------------------------------------------------*/ -/* Structure for CMD_BLE5_ADV_NC.pParams */ -rfc_bleAdvPar_t rf_ble_adv_par = -{ - .pRxQ = 0, - .rxConfig.bAutoFlushIgnored = 0x0, - .rxConfig.bAutoFlushCrcErr = 0x0, - .rxConfig.bAutoFlushEmpty = 0x0, - .rxConfig.bIncludeLenByte = 0x0, - .rxConfig.bIncludeCrc = 0x0, - .rxConfig.bAppendRssi = 0x0, - .rxConfig.bAppendStatus = 0x0, - .rxConfig.bAppendTimestamp = 0x0, - .advConfig.advFilterPolicy = 0x0, - .advConfig.deviceAddrType = 0x0, - .advConfig.peerAddrType = 0x0, - .advConfig.bStrictLenFilter = 0x0, - .advConfig.rpaMode = 0x0, - .advLen = 0x18, - .scanRspLen = 0x00, - .pAdvData = 0, - .pScanRspData = 0, - .pDeviceAddress = 0, - .pWhiteList = 0, - .__dummy0 = 0x0000, - .__dummy1 = 0x00, - .endTrigger.triggerType = TRIG_NEVER, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, -}; -/*---------------------------------------------------------------------------*/ /* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */ rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc = { - .commandNo = 0x182D, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .commandNo = CMD_BLE5_ADV_NC, + .status = IDLE, + .pNextOp = 0, .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, + .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, + .startTrigger.pastTrig = 0x1, + .condition.rule = 0x0, /* set by driver */ .condition.nSkip = 0x0, - .channel = 0x8C, - .whitening.init = 0x51, + .channel = 0x00, /* set by driver */ + .whitening.init = 0x00, /* set by driver */ .whitening.bOverride = 0x1, .phyMode.mainMode = 0x0, .phyMode.coding = 0x0, .rangeDelay = 0x00, .txPower = 0x0000, - .pParams = &rf_ble_adv_par, - .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .pParams = 0x00000000, /* set by driver */ + .pOutput = 0x00000000, /* set by driver */ .tx20Power = 0x00000000, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h index 2e6defa71..c5295c868 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h @@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode; /*---------------------------------------------------------------------------*/ /* RF Core API commands */ extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup; -extern rfc_bleAdvPar_t rf_ble_adv_par; extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc; /*---------------------------------------------------------------------------*/ /* RF Core API Overrides */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c index cc012da89..c353a07c1 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c @@ -44,7 +44,7 @@ #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h) #include @@ -55,7 +55,7 @@ RF_Mode rf_ieee_mode = { .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_ieee_802_15_4, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, .mcePatchFxn = &rf_patch_mce_ieee_802_15_4, .rfePatchFxn = 0, }; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c index 357e7e7c5..7a445a229 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c @@ -81,7 +81,7 @@ ble_addr_ptr(void) } /*---------------------------------------------------------------------------*/ int -ble_addr_cpy(uint8_t *dst) +ble_addr_be_cpy(uint8_t *dst) { if(!dst) { return -1; @@ -102,6 +102,23 @@ ble_addr_cpy(uint8_t *dst) } /*---------------------------------------------------------------------------*/ int +ble_addr_le_cpy(uint8_t *dst) +{ + if(!dst) { + return -1; + } + + volatile const uint8_t *const ble_addr = ble_addr_ptr(); + + size_t i; + for(i = 0; i < BLE_ADDR_SIZE; i++) { + dst[i] = ble_addr[i]; + } + + return 0; +} +/*---------------------------------------------------------------------------*/ +int ble_addr_to_eui64(uint8_t *dst, uint8_t *src) { if(!dst || !src) { @@ -126,7 +143,7 @@ ble_addr_to_eui64_cpy(uint8_t *dst) int res; uint8_t ble_addr[BLE_ADDR_SIZE]; - res = ble_addr_cpy(ble_addr); + res = ble_addr_le_cpy(ble_addr); if(res) { return -1; } diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h index fd63c17d0..effc95d22 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h @@ -59,6 +59,7 @@ uint8_t *ble_addr_ptr(void); /*---------------------------------------------------------------------------*/ /** * \brief Copy the node's factory BLE address to a destination memory area + * in big-endian (be) order. * \param dst A pointer to the destination area where the BLE address is to be * written * \return 0 : Returned successfully @@ -68,7 +69,21 @@ uint8_t *ble_addr_ptr(void); * the process. The factory address on devices is normally little-endian, * therefore you should expect dst to store the address in a big-endian order. */ -int ble_addr_cpy(uint8_t *dst); +int ble_addr_be_cpy(uint8_t *dst); +/*---------------------------------------------------------------------------*/ +/** + * \brief Copy the node's factory BLE address to a destination memory area + * in little-endian (le) order. + * \param dst A pointer to the destination area where the BLE address is to be + * written + * \return 0 : Returned successfully + * -1 : Returned with error + * + * This function will copy 6 bytes, but will **not** invert the byte order. + * This is usefull for the RF core which assumes the BLE MAC address in + * little-endian order. + */ +int ble_addr_le_cpy(uint8_t *dst); /*---------------------------------------------------------------------------*/ /** * \brief Copy the node's BLE address to a destination memory area and converts diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c index 383d168be..79600afd6 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c @@ -70,32 +70,58 @@ /*---------------------------------------------------------------------------*/ #if RF_CONF_BLE_BEACON_ENABLE /*---------------------------------------------------------------------------*/ -/* BLE Advertisement channels. Not to be changed by the user. */ -typedef enum { - BLE_ADV_CHANNEL_37 = (1 << 0), - BLE_ADV_CHANNEL_38 = (1 << 1), - BLE_ADV_CHANNEL_39 = (1 << 2), - - BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 | - BLE_ADV_CHANNEL_38 | - BLE_ADV_CHANNEL_39), -} ble_adv_channel_t; - -#define BLE_ADV_CHANNEL_MIN 37 -#define BLE_ADV_CHANNEL_MAX 39 -/*---------------------------------------------------------------------------*/ /* Maximum BLE advertisement size. Not to be changed by the user. */ #define BLE_ADV_MAX_SIZE 31 /*---------------------------------------------------------------------------*/ -/* BLE Intervals: Send a burst of advertisements every BLE_ADV_INTERVAL secs */ -#define BLE_ADV_INTERVAL (CLOCK_SECOND * 5) -#define BLE_ADV_DUTY_CYCLE (CLOCK_SECOND / 10) -#define BLE_ADV_MESSAGES 10 +/* + * BLE Intervals: Send a burst of advertisements every BLE_ADV_INTERVAL + * specified in milliseconds. + */ +#define BLE_ADV_INTERVAL ((100 * CLOCK_SECOND) / 1000) + +/* GAP Advertisement data types */ +#define BLE_ADV_TYPE_FLAGS 0x01 +#define BLE_ADV_TYPE_16BIT_MORE 0x02 +#define BLE_ADV_TYPE_16BIT_COMPLETE 0x03 +#define BLE_ADV_TYPE_32BIT_MORE 0x04 +#define BLE_ADV_TYPE_32BIT_COMPLETE 0x05 +#define BLE_ADV_TYPE_128BIT_MORE 0x06 +#define BLE_ADV_TYPE_128BIT_COMPLETE 0x07 +#define BLE_ADV_TYPE_LOCAL_NAME_SHORT 0x08 +#define BLE_ADV_TYPE_LOCAL_NAME_COMPLETE 0x09 +#define BLE_ADV_TYPE_POWER_LEVEL 0x0A +#define BLE_ADV_TYPE_OOB_CLASS_OF_DEVICE 0x0D +#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_HASHC 0x0E +#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_RANDR 0x0F +#define BLE_ADV_TYPE_SM_TK 0x10 +#define BLE_ADV_TYPE_SM_OOB_FLAG 0x11 +#define BLE_ADV_TYPE_SLAVE_CONN_INTERVAL_RANGE 0x12 +#define BLE_ADV_TYPE_SIGNED_DATA 0x13 +#define BLE_ADV_TYPE_SERVICE_LIST_16BIT 0x14 +#define BLE_ADV_TYPE_SERVICE_LIST_128BIT 0x15 +#define BLE_ADV_TYPE_SERVICE_DATA 0x16 +#define BLE_ADV_TYPE_PUBLIC_TARGET_ADDR 0x17 +#define BLE_ADV_TYPE_RANDOM_TARGET_ADDR 0x18 +#define BLE_ADV_TYPE_APPEARANCE 0x19 +#define BLE_ADV_TYPE_ADV_INTERVAL 0x1A +#define BLE_ADV_TYPE_LE_BD_ADDR 0x1B +#define BLE_ADV_TYPE_LE_ROLE 0x1C +#define BLE_ADV_TYPE_SIMPLE_PAIRING_HASHC_256 0x1D +#define BLE_ADV_TYPE_SIMPLE_PAIRING_RANDR_256 0x1E +#define BLE_ADV_TYPE_SERVICE_DATA_32BIT 0x20 +#define BLE_ADV_TYPE_SERVICE_DATA_128BIT 0x21 +#define BLE_ADV_TYPE_3D_INFO_DATA 0x3D +#define BLE_ADV_TYPE_MANUFACTURER_SPECIFIC 0xFF + +/* GAP Advertisement data type flags */ + +/* Discovery Mode: LE Limited Discoverable Mode */ +#define BLE_ADV_TYPE_FLAGS_LIMITED 0x01 +/* Discovery Mode: LE General Discoverable Mode */ +#define BLE_ADV_TYPE_FLAGS_GENERAL 0x02 +/* Discovery Mode: BR/EDR Not Supported */ +#define BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED 0x04 -/* BLE Advertisement-related macros */ -#define BLE_ADV_TYPE_DEVINFO 0x01 -#define BLE_ADV_TYPE_NAME 0x09 -#define BLE_ADV_TYPE_MANUFACTURER 0xFF #define BLE_ADV_NAME_BUF_LEN BLE_ADV_MAX_SIZE #define BLE_ADV_PAYLOAD_BUF_LEN 64 #define BLE_UUID_SIZE 16 @@ -117,6 +143,11 @@ typedef struct { /* RF driver */ RF_Handle rf_handle; + + /* BLE command specific structures. Common accross BLE and BLE5. */ + uint8_t ble_mac_addr[6]; + rfc_bleAdvPar_t ble_adv_par; + rfc_bleAdvOutput_t ble_adv_output; } ble_beacond_t; static ble_beacond_t ble_beacond; @@ -126,13 +157,10 @@ PROCESS(ble_beacond_process, "RF BLE Beacon Daemon Process"); rf_ble_beacond_result_t rf_ble_beacond_init(void) { - ble_adv_par.pDeviceAddress = (uint16_t *)ble_addr_ptr(); - RF_Params rf_params; RF_Params_init(&rf_params); - /* Should immediately turn off radio if possible */ - rf_params.nInactivityTimeout = 0; + rf_params.nInactivityTimeout = RF_CONF_INACTIVITY_TIMEOUT; ble_beacond.rf_handle = ble_open(&rf_params); @@ -140,6 +168,18 @@ rf_ble_beacond_init(void) return RF_BLE_BEACOND_ERROR; } + /* + * It is important that the contents of the BLE MAC address is copied into + * RAM, as the System CPU, and subsequently flash, goes idle when pending + * on an RF command. This causes pend to hang forever. + */ + ble_addr_le_cpy(ble_beacond.ble_mac_addr); + ble_beacond.ble_adv_par.pDeviceAddress = (uint16_t *)ble_beacond.ble_mac_addr; + ble_beacond.ble_adv_par.endTrigger.triggerType = TRIG_NEVER; + + rf_ble_cmd_ble_adv_nc.pParams = &ble_beacond.ble_adv_par; + rf_ble_cmd_ble_adv_nc.pOutput = &ble_beacond.ble_adv_output; + return RF_BLE_BEACOND_OK; } /*---------------------------------------------------------------------------*/ @@ -154,12 +194,14 @@ rf_ble_beacond_config(clock_time_t interval, const char *name) ble_beacond.ble_adv_interval = interval; res = RF_BLE_BEACOND_OK; + } else { + ble_beacond.ble_adv_interval = BLE_ADV_INTERVAL; } if(name != NULL) { const size_t name_len = strlen(name); - if((name_len == 0) || (name_len >= BLE_ADV_NAME_BUF_LEN)) { + if((0 < name_len) && (name_len < BLE_ADV_NAME_BUF_LEN)) { ble_beacond.adv_name_len = name_len; memcpy(ble_beacond.adv_name, name, name_len); @@ -235,37 +277,9 @@ rf_ble_get_tx_power(void) return dbm; } /*---------------------------------------------------------------------------*/ -static rf_ble_beacond_result_t -ble_beacon_burst(uint8_t channels_bm, uint8_t *data, uint8_t len) -{ - rf_result_t res; - - uint8_t channel; - for(channel = BLE_ADV_CHANNEL_MIN; channel <= BLE_ADV_CHANNEL_MAX; ++channel) { - const uint8_t channel_bv = (1 << (channel - BLE_ADV_CHANNEL_MIN)); - if((channel_bv & channels_bm) == 0) { - continue; - } - - ble_adv_par.advLen = len; - ble_adv_par.pAdvData = data; - - ble_cmd_beacon.channel = channel; - - res = ble_sched_beacon(NULL, 0); - - if(res != RF_RESULT_OK) { - return RF_BLE_BEACOND_ERROR; - } - } - - return RF_BLE_BEACOND_OK; -} -/*---------------------------------------------------------------------------*/ PROCESS_THREAD(ble_beacond_process, ev, data) { - static size_t i; - static size_t len; + size_t len; PROCESS_BEGIN(); @@ -278,30 +292,33 @@ PROCESS_THREAD(ble_beacond_process, ev, data) PROCESS_EXIT(); } + /* Device info */ /* Set the adv payload each pass: The device name may have changed */ len = 0; - /* Device info */ - ble_beacond.tx_buf[len++] = (uint8_t)0x02; /* 2 bytes */ - ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_DEVINFO; - ble_beacond.tx_buf[len++] = (uint8_t)0x1A; /* LE general discoverable + BR/EDR */ - ble_beacond.tx_buf[len++] = (uint8_t)ble_beacond.adv_name_len; - ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_NAME; + #define append_byte(x) ble_beacond.tx_buf[len++] = (uint8_t)((x)) + + /* 2 bytes */ + append_byte(2); + append_byte(BLE_ADV_TYPE_FLAGS); + /* LE general discoverable + BR/EDR not supported */ + append_byte(BLE_ADV_TYPE_FLAGS_GENERAL | + BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED); + + /* 1 + len(name) bytes (excluding zero termination) */ + append_byte(1 + ble_beacond.adv_name_len); + append_byte(BLE_ADV_TYPE_LOCAL_NAME_COMPLETE); memcpy(ble_beacond.tx_buf + len, ble_beacond.adv_name, ble_beacond.adv_name_len); len += ble_beacond.adv_name_len; - /* - * Send BLE_ADV_MESSAGES beacon bursts. Each burst on all three - * channels, with a BLE_ADV_DUTY_CYCLE interval between bursts - */ - ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len); - for(i = 1; i < BLE_ADV_MESSAGES; ++i) { - etimer_set(&ble_beacond.ble_adv_et, BLE_ADV_DUTY_CYCLE); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ble_beacond.ble_adv_et)); + #undef append_byte - ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len); - } + /* Send advertisements on all three channels */ + ble_beacond.ble_adv_par.advLen = len; + ble_beacond.ble_adv_par.pAdvData = ble_beacond.tx_buf; + + ble_sched_beacons(BLE_ADV_CHANNEL_ALL); } PROCESS_END(); } diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c index d9f3a5acf..f5105a263 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c @@ -550,32 +550,42 @@ read(void *buf, unsigned short buf_len) static rf_result_t cca_request(cmd_cca_req_t *cmd_cca_req) { + RF_Stat stat = RF_StatRadioInactiveError; rf_result_t res; + bool stop_rx = false; - const bool rx_is_idle = !rx_is_active(); + /* RX is required to be running in order to do a CCA request */ + if(!rx_is_active()) { + /* If RX is not pending, i.e. soon to be running, schedule the RX command */ + if(cmd_rx.status != PENDING) { + res = netstack_sched_rx(false); + if(res != RF_RESULT_OK) { + LOG_ERR("CCA request failed to schedule RX\n"); + return res; + } - if(rx_is_idle) { - res = netstack_sched_rx(false); - if(res != RF_RESULT_OK) { + /* We only stop RX if we had to schedule it */ + stop_rx = true; + } + + /* Make sure RX is running before we continue, unless we timeout and fail */ + RTIMER_BUSYWAIT_UNTIL(!rx_is_active(), TIMEOUT_ENTER_RX_WAIT); + + if(!rx_is_active()) { + LOG_ERR("CCA request failed to turn on RX, RX status=0x%04X\n", cmd_rx.status); return RF_RESULT_ERROR; } } - const rtimer_clock_t t0 = RTIMER_NOW(); - while((cmd_rx.status != ACTIVE) && - RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ; + /* Perform the CCA request */ + stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_cca_req); - RF_Stat stat = RF_StatRadioInactiveError; - if(rx_is_active()) { - stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_cca_req); - } - - if(rx_is_idle) { + if(stop_rx) { netstack_stop_rx(); } if(stat != RF_StatCmdDoneSuccess) { - LOG_ERR("CCA request failed, stat=0x%02X\n", stat); + LOG_ERR("CCA request command failed, stat=0x%02X\n", stat); return RF_RESULT_ERROR; } diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c index a100f262a..33cfbfbba 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c @@ -207,26 +207,36 @@ static int8_t get_rssi(void) { rf_result_t res; + bool stop_rx = false; + int8_t rssi = RF_GET_RSSI_ERROR_VAL; - const bool rx_is_idle = !rx_is_active(); + /* RX is required to be running in order to do a RSSI measurement */ + if(!rx_is_active()) { + /* If RX is not pending, i.e. soon to be running, schedule the RX command */ + if(cmd_rx.status != PENDING) { + res = netstack_sched_rx(false); + if(res != RF_RESULT_OK) { + LOG_ERR("RSSI measurement failed to schedule RX\n"); + return res; + } - if(rx_is_idle) { - res = netstack_sched_rx(false); - if(res != RF_RESULT_OK) { - return RF_GET_RSSI_ERROR_VAL; + /* We only stop RX if we had to schedule it */ + stop_rx = true; + } + + /* Make sure RX is running before we continue, unless we timeout and fail */ + RTIMER_BUSYWAIT_UNTIL(!rx_is_active(), TIMEOUT_ENTER_RX_WAIT); + + if(!rx_is_active()) { + LOG_ERR("RSSI measurement failed to turn on RX, RX status=0x%04X\n", cmd_rx.status); + return RF_RESULT_ERROR; } } - const rtimer_clock_t t0 = RTIMER_NOW(); - while((cmd_rx.status != ACTIVE) && - RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ; + /* Perform the RSSI measurement */ + rssi = RF_getRssi(prop_radio.rf_handle); - int8_t rssi = RF_GET_RSSI_ERROR_VAL; - if(rx_is_active()) { - rssi = RF_getRssi(prop_radio.rf_handle); - } - - if(rx_is_idle) { + if(stop_rx) { netstack_stop_rx(); } diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c index 44387c138..eb2426dfc 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c @@ -51,6 +51,7 @@ #include #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_mailbox.h) #include /*---------------------------------------------------------------------------*/ @@ -68,8 +69,6 @@ #define LOG_MODULE "Radio" #define LOG_LEVEL LOG_LEVEL_NONE /*---------------------------------------------------------------------------*/ -/* Configuration parameters */ -/*---------------------------------------------------------------------------*/ #define CMD_FS_RETRIES 3 #define RF_EVENTS_CMD_DONE (RF_EventCmdDone | RF_EventLastCmdDone | \ @@ -82,6 +81,13 @@ #define EVENTS_CMD_DONE(events) (((events) & RF_EVENTS_CMD_DONE) != 0) /*---------------------------------------------------------------------------*/ +/* BLE advertisement channel range (inclusive) */ +#define BLE_ADV_CHANNEL_MIN 37 +#define BLE_ADV_CHANNEL_MAX 39 + +/* Number of BLE advertisement channels */ +#define NUM_BLE_ADV_CHANNELS (BLE_ADV_CHANNEL_MAX - BLE_ADV_CHANNEL_MIN + 1) +/*---------------------------------------------------------------------------*/ /* Synth re-calibration every 3 minutes */ #define SYNTH_RECAL_INTERVAL (CLOCK_SECOND * 60 * 3) /* Set re-calibration interval with a jitter of 10 seconds */ @@ -89,6 +95,12 @@ static struct etimer synth_recal_timer; /*---------------------------------------------------------------------------*/ +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) +typedef rfc_CMD_BLE_ADV_NC_t ble_cmd_adv_nc_t; +#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) +typedef rfc_CMD_BLE5_ADV_NC_t ble_cmd_adv_nc_t; +#endif +/*---------------------------------------------------------------------------*/ static RF_Object rf_netstack; #if RF_CONF_BLE_BEACON_ENABLE @@ -479,45 +491,171 @@ ble_open(RF_Params *params) #endif } /*---------------------------------------------------------------------------*/ +#if RF_CONF_BLE_BEACON_ENABLE +static RF_Op * +init_ble_adv_array(ble_cmd_adv_nc_t *ble_adv_array, uint8_t bm_channel) +{ + RF_Op *first_ble_adv = NULL; + ble_cmd_adv_nc_t *cmd_adv_37 = &ble_adv_array[0]; + ble_cmd_adv_nc_t *cmd_adv_38 = &ble_adv_array[1]; + ble_cmd_adv_nc_t *cmd_adv_39 = &ble_adv_array[2]; + + /* Setup channel 37 advertisement if enabled */ + if(bm_channel & BLE_ADV_CHANNEL_37) { + /* Default configurations from ble_cmd_adv_nc */ + memcpy(cmd_adv_37, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc)); + + cmd_adv_37->channel = 37; + /* Magic number: initialization for whitener, specific for channel 37 */ + cmd_adv_37->whitening.init = 0x65; + + /* + * The next advertisement is chained depending on whether they are + * enbled or not. If both 38 and 39 are disabled, then there is no + * chaining. + */ + if(bm_channel & BLE_ADV_CHANNEL_38) { + cmd_adv_37->pNextOp = (RF_Op *)cmd_adv_38; + cmd_adv_37->condition.rule = COND_ALWAYS; + } else if(bm_channel & BLE_ADV_CHANNEL_39) { + cmd_adv_37->pNextOp = (RF_Op *)cmd_adv_39; + cmd_adv_37->condition.rule = COND_ALWAYS; + } else { + cmd_adv_37->pNextOp = NULL; + cmd_adv_37->condition.rule = COND_NEVER; + } + + /* Channel 37 will always be first if enabled */ + first_ble_adv = (RF_Op *)cmd_adv_37; + } + + /* Setup channel 38 advertisement if enabled */ + if(bm_channel & BLE_ADV_CHANNEL_38) { + memcpy(cmd_adv_38, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc)); + + cmd_adv_38->channel = 38; + /* Magic number: initialization for whitener, specific for channel 38 */ + cmd_adv_38->whitening.init = 0x66; + + /* + * The next advertisement is chained depending on whether they are + * enbled or not. If 39 is disabled, then there is no chaining. + */ + if(bm_channel & BLE_ADV_CHANNEL_39) { + cmd_adv_38->pNextOp = (RF_Op *)cmd_adv_39; + cmd_adv_38->condition.rule = COND_ALWAYS; + } else { + cmd_adv_38->pNextOp = NULL; + cmd_adv_38->condition.rule = COND_NEVER; + } + + /* + * Channel 38 is only first if the first_ble_adv pointer is not + * set by channel 37. + */ + if(first_ble_adv == NULL) { + first_ble_adv = (RF_Op *)cmd_adv_38; + } + } + + /* Setup channel 39 advertisement if enabled */ + if(bm_channel & BLE_ADV_CHANNEL_39) { + memcpy(cmd_adv_39, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc)); + + cmd_adv_39->channel = 39; + /* Magic number: initialization for whitener, specific for channel 39 */ + cmd_adv_39->whitening.init = 0x67; + + /* Channel 39 is always the last advertisement in the chain */ + cmd_adv_39->pNextOp = NULL; + cmd_adv_39->condition.rule = COND_NEVER; + + /* + * Channel 39 is only first if the first_ble_adv pointer is not + * set by channel 37 or channel 38. + */ + if(first_ble_adv == NULL) { + first_ble_adv = (RF_Op *)cmd_adv_39; + } + } + + return first_ble_adv; +} +#endif /* RF_CONF_BLE_BEACON_ENABLE */ +/*---------------------------------------------------------------------------*/ rf_result_t -ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event) +ble_sched_beacons(uint8_t bm_channel) { #if RF_CONF_BLE_BEACON_ENABLE - RF_ScheduleCmdParams sched_params; - RF_ScheduleCmdParams_init(&sched_params); + /* + * Allocate the advertisement commands on the stack rather than statically + * to RAM in order to save space. We don't need them after the + * advertisements have been transmitted. + */ + ble_cmd_adv_nc_t ble_cmd_adv_nc_array[NUM_BLE_ADV_CHANNELS]; + RF_Op *initial_adv = NULL; + RF_ScheduleCmdParams sched_params; + RF_CmdHandle beacon_handle; + RF_EventMask beacon_events; + rf_result_t rf_result; + + /* If no channels are mapped, then early return OK */ + if((bm_channel & BLE_ADV_CHANNEL_ALL) == 0) { + return RF_RESULT_OK; + } + + initial_adv = init_ble_adv_array(ble_cmd_adv_nc_array, bm_channel); + + if(initial_adv == NULL) { + LOG_ERR("Initializing BLE Advertismenet chain failed\n"); + return RF_RESULT_ERROR; + } + + RF_ScheduleCmdParams_init(&sched_params); sched_params.priority = RF_PriorityNormal; sched_params.endTime = 0; sched_params.allowDelay = RF_AllowDelayAny; - CMD_STATUS(ble_cmd_beacon) = PENDING; - - RF_CmdHandle beacon_handle = RF_scheduleCmd( - &rf_ble, - (RF_Op *)&ble_cmd_beacon, - &sched_params, - cb, - bm_event); + /* + * The most efficient way to schedule the command is as follows: + * 1. Schedule the BLE advertisement chain + * 2. Reschedule the RX command IF it was running. + * 3. Pend on the BLE avertisement chain + */ + beacon_handle = RF_scheduleCmd( + &rf_ble, + initial_adv, + &sched_params, + NULL, + 0); if(!CMD_HANDLE_OK(beacon_handle)) { LOG_ERR("Unable to schedule BLE Beacon command, handle=%d status=0x%04x\n", - beacon_handle, CMD_STATUS(ble_cmd_beacon)); + beacon_handle, CMD_STATUS(ble_cmd_adv_nc)); + return RF_RESULT_ERROR; } - const uint_fast8_t rx_key = cmd_rx_disable(); + /* Note that this only reschedules RX if it is running */ + rf_result = cmd_rx_restore(cmd_rx_disable()); /* Wait until Beacon operation finishes */ - RF_EventMask beacon_events = RF_pendCmd(&rf_ble, beacon_handle, 0); - if(!EVENTS_CMD_DONE(beacon_events)) { - LOG_ERR("Pending on scheduled BLE Beacon command generated error, events=0x%08llx status=0x%04x\n", - beacon_events, CMD_STATUS(ble_cmd_beacon)); + beacon_events = RF_pendCmd(&rf_ble, beacon_handle, 0); + + if(rf_result != RF_RESULT_OK) { + LOG_ERR("Rescheduling CMD_RX failed when BLE advertising\n"); + + return RF_RESULT_ERROR; + } + + if(!EVENTS_CMD_DONE(beacon_events)) { + LOG_ERR("Pending on scheduled BLE Beacon command generated error, events=0x%08llx status=0x%04x\n", + beacon_events, CMD_STATUS(ble_cmd_adv_nc)); - cmd_rx_restore(rx_key); return RF_RESULT_ERROR; } - cmd_rx_restore(rx_key); return RF_RESULT_OK; #else diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h index de32dbbd4..fe4963036 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h @@ -58,6 +58,16 @@ typedef enum { RF_RESULT_ERROR, } rf_result_t; /*---------------------------------------------------------------------------*/ +typedef enum { + BLE_ADV_CHANNEL_37 = (1 << 0), + BLE_ADV_CHANNEL_38 = (1 << 1), + BLE_ADV_CHANNEL_39 = (1 << 2), + + BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 | + BLE_ADV_CHANNEL_38 | + BLE_ADV_CHANNEL_39), +} ble_adv_channel_t; +/*---------------------------------------------------------------------------*/ /** * \name Common RF scheduler functionality. * @@ -91,7 +101,7 @@ rf_result_t netstack_stop_rx(void); * @{ */ RF_Handle ble_open(RF_Params *params); -rf_result_t ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event); +rf_result_t ble_sched_beacons(uint8_t bm_adv_channel); /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_SCHED_H_ */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h index 174114bfb..1d20fce91 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h @@ -89,7 +89,7 @@ #define ble_mode rf_ble_mode #define ble_cmd_radio_setup rf_ble_cmd_radio_setup #define ble_adv_par rf_ble_adv_par -#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc +#define ble_cmd_adv_nc rf_ble_cmd_ble_adv_nc /* CC13x2/CC26x2 devices */ #elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) @@ -97,7 +97,7 @@ #define ble_mode rf_ble_mode #define ble_cmd_radio_setup rf_ble_cmd_radio_setup #define ble_adv_par rf_ble_adv_par -#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc +#define ble_cmd_adv_nc rf_ble_cmd_ble_adv_nc #endif /* DeviceFamily_PARENT */ From 257a3794a12dafaa375dc40c02aa3084a611d406 Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Tue, 22 Jan 2019 15:38:26 +0100 Subject: [PATCH 181/184] Fixed RF front-end configuration and RF switching for CC13xx Two issues caused the sensitivity on CC13xx devices to be dramatically worse than CC26xx devices: * Wrong front-end mode configuration * Faulty/outdated RF switching logic Both issues are inherently board-specific. Therefore, a generic configuration was aligned across all boards which allows a specific board to configure a correct RF front-end mode. In addition, the RF switching logic was updated to latest and greatest. --- .../cc13xx-cc26xx-conf.h | 12 ++++ .../rf-settings/cc13x0/ble-settings.c | 12 +++- .../rf-settings/cc13x0/ieee-settings.c | 4 +- .../rf-settings/cc13x2/ble-settings.c | 12 +++- .../rf-settings/cc13x2/ieee-settings.c | 4 +- .../rf-settings/cc26x0/ble-settings.c | 12 +++- .../rf-settings/cc26x0/ieee-settings.c | 4 +- .../rf-settings/cc26x2/ble-settings.c | 12 +++- .../rf-settings/cc26x2/ieee-settings.c | 4 +- .../simplelink-cc13xx-cc26xx/rf/ble-beacond.c | 4 ++ .../simplelink-cc13xx-cc26xx/rf/ieee-mode.c | 3 + .../simplelink-cc13xx-cc26xx/rf/prop-mode.c | 3 + arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h | 31 ++++++++++ .../cc13xx-cc26xx/launchpad/board-conf.h | 2 +- .../cc13xx-cc26xx/launchpad/cc1310/Board.h | 3 + .../cc13xx-cc26xx/launchpad/cc1310/rf-conf.h | 61 +++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1312r1/Board.h | 3 + .../launchpad/cc1312r1/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1350-4/Board.h | 3 + .../cc1350-4/CC1350_LAUNCHXL_433_fxns.c | 45 ++++++++++++-- .../launchpad/cc1350-4/rf-conf.h | 60 ++++++++++++++++++ .../launchpad/cc1350/CC1350_LAUNCHXL_fxns.c | 41 ++++++++++++- .../cc13xx-cc26xx/launchpad/cc1350/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1352p-2/Board.h | 3 + .../cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c | 43 +++++++++++-- .../launchpad/cc1352p-2/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1352p-4/Board.h | 3 + .../cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c | 43 +++++++++++-- .../launchpad/cc1352p-4/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1352p1/Board.h | 3 + .../cc1352p1/CC1352P1_LAUNCHXL_fxns.c | 43 +++++++++++-- .../launchpad/cc1352p1/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc1352r1/Board.h | 3 + .../cc1352r1/CC1352R1_LAUNCHXL_fxns.c | 50 +++++++++++++-- .../launchpad/cc1352r1/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/launchpad/cc2650/rf-conf.h | 60 ++++++++++++++++++ .../launchpad/cc26x2r1/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/sensortag/board-conf.h | 3 +- .../cc13xx-cc26xx/sensortag/cc1350/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/sensortag/cc2650/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/srf06/board-conf.h | 2 + .../cc13xx-cc26xx/srf06/cc13x0/rf-conf.h | 60 ++++++++++++++++++ .../cc13xx-cc26xx/srf06/cc26x0/rf-conf.h | 60 ++++++++++++++++++ 43 files changed, 1198 insertions(+), 53 deletions(-) create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h create mode 100644 arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h index 87fa922b9..58f34198f 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h @@ -133,6 +133,18 @@ #define RF_MODE RF_CONF_MODE #endif /* RF_CONF_MODE */ +#ifdef RF_CONF_FRONT_END_MODE +#define RF_FRONT_END_MODE RF_CONF_FRONT_END_MODE +#else +#define RF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#endif + +#ifdef RF_CONF_BIAS_MODE +#define RF_BIAS_MODE RF_CONF_BIAS_MODE +#else +#define RF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#endif + /* Number of RX buffers. */ #ifndef RF_CONF_RX_BUF_CNT #define RF_CONF_RX_BUF_CNT 4 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c index 539046a48..f9902f826 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c @@ -62,6 +62,12 @@ RF_Mode rf_ble_mode = .rfePatchFxn = &rf_patch_rfe_ble, }; /*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x5F3C /* 5 dBm */ +/*---------------------------------------------------------------------------*/ /* Overrides for CMD_RADIO_SETUP */ uint32_t rf_ble_overrides[] CC_ALIGN(4) = { @@ -109,11 +115,11 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = .condition.nSkip = 0x0, .mode = 0x00, .loDivider = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, - .txPower = 0x3D3F, + .txPower = DEFAULT_TX_POWER, .pRegOverride = rf_ble_overrides, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c index ce7b00a0b..1537f693c 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c @@ -110,8 +110,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = .condition.rule = COND_NEVER, .condition.nSkip = 0x0, .mode = 0x01, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c index d44264f3a..b43ce21a6 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c @@ -64,6 +64,12 @@ RF_Mode rf_ble_mode = .rfePatchFxn = &rf_patch_rfe_bt5, }; /*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x941E /* 5 dBm */ +/*---------------------------------------------------------------------------*/ /* Overrides for CMD_BLE5_RADIO_SETUP */ uint32_t rf_ble_overrides_common[] CC_ALIGN(4) = { @@ -137,11 +143,11 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = .defaultPhy.mainMode = 0x0, .defaultPhy.coding = 0x0, .loDivider = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, - .txPower = 0x941E, + .txPower = DEFAULT_TX_POWER, .pRegOverrideCommon = rf_ble_overrides_common, .pRegOverride1Mbps = rf_ble_overrides_1mbps, .pRegOverride2Mbps = rf_ble_overrides_2mbps, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c index 665bd568e..a81a83385 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c @@ -180,8 +180,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = .condition.nSkip = 0x0, .mode = 0x01, .loDivider = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c index 255deb151..9c19021fd 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c @@ -61,6 +61,12 @@ RF_Mode rf_ble_mode = .rfePatchFxn = &rf_patch_rfe_ble, }; /*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x9330 /* 5 dBm */ +/*---------------------------------------------------------------------------*/ /* Overrides for CMD_RADIO_SETUP */ uint32_t rf_ble_overrides[] CC_ALIGN(4) = { @@ -105,11 +111,11 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = .condition.nSkip = 0x0, .mode = 0x00, .__dummy0 = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, - .txPower = 0x9330, + .txPower = DEFAULT_TX_POWER, .pRegOverride = rf_ble_overrides, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c index 71842215e..4d860109d 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c @@ -107,8 +107,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = .condition.nSkip = 0x0, .mode = 0x01, .__dummy0 = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c index bba7c083b..21ed73201 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c @@ -63,6 +63,12 @@ RF_Mode rf_ble_mode = .rfePatchFxn = &rf_patch_rfe_bt5, }; /*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x941E /* 5 dBm */ +/*---------------------------------------------------------------------------*/ /* Overrides for CMD_BLE5_RADIO_SETUP */ uint32_t rf_ble_overrides_common[] CC_ALIGN(4) = { @@ -137,11 +143,11 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = .defaultPhy.mainMode = 0x0, .defaultPhy.coding = 0x0, .loDivider = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, - .txPower = 0x941E, + .txPower = DEFAULT_TX_POWER, .pRegOverrideCommon = rf_ble_overrides_common, .pRegOverride1Mbps = rf_ble_overrides_1mbps, .pRegOverride2Mbps = rf_ble_overrides_2mbps, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c index c353a07c1..d95ff87ba 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c @@ -104,8 +104,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = .condition.nSkip = 0x0, .mode = 0x01, .loDivider = 0x00, - .config.frontEndMode = 0x0, - .config.biasMode = 0x0, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = DEFAULT_TX_POWER, diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c index 79600afd6..1d2328803 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c @@ -52,6 +52,7 @@ #include /*---------------------------------------------------------------------------*/ +#include "rf/rf.h" #include "rf/sched.h" #include "rf/ble-addr.h" #include "rf/ble-beacond.h" @@ -157,6 +158,9 @@ PROCESS(ble_beacond_process, "RF BLE Beacon Daemon Process"); rf_ble_beacond_result_t rf_ble_beacond_init(void) { + ble_cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; + ble_cmd_radio_setup.config.biasMode = RF_BIAS_MODE; + RF_Params rf_params; RF_Params_init(&rf_params); diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c index f5105a263..678c50db7 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c @@ -217,6 +217,9 @@ rat_overflow_cb(void *arg) static void init_rf_params(void) { + cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; + cmd_radio_setup.config.biasMode = RF_BIAS_MODE; + data_queue_t *rx_q = data_queue_init(sizeof(lensz_t)); cmd_rx.pRxQ = rx_q; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c index 33cfbfbba..79c58c339 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c @@ -61,6 +61,7 @@ #include /*---------------------------------------------------------------------------*/ /* Platform RF dev */ +#include "rf/rf.h" #include "rf/dot-15-4g.h" #include "rf/sched.h" #include "rf/data-queue.h" @@ -193,6 +194,8 @@ static int off(void); static void init_rf_params(void) { + cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; + cmd_radio_setup.config.biasMode = RF_BIAS_MODE; cmd_radio_setup.centerFreq = PROP_MODE_CENTER_FREQ; cmd_radio_setup.loDivider = PROP_MODE_LO_DIVIDER; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h index cfc6b2277..c1f454970 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h @@ -60,6 +60,37 @@ RF_MODE_2_4_GHZ) /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name The different front-end modes the CC13xx/CC26xx devices support. The + * front-end mode can be configured independently of the bias mode. The + * two types of modes are as follows: + * - Differential: Both RF_P and RF_N are used as a differential RF + * interface. + * - Single ended: Either the RF_P pin or the RF_N pin is used as the + * RF path. + * + * @{ + */ +/* Available front-end mode configurations */ +#define RF_FRONT_END_MODE_DIFFERENTIAL 0 +#define RF_FRONT_END_MODE_SINGLE_ENDED_RFP 1 +#define RF_FRONT_END_MODE_SINGLE_ENDED_RFN 2 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name The different bias modes the CC13xx/CC26xx devices support. The + * bias mode can be configured independently of the front-end mode. The + * two different modes are as follows: + * - Internal bias: the LNA is biased by an internal bias. + * - External bias: the LNA is biased by an external bias. + * + * @{ + */ +/* Available bias mode configurations */ +#define RF_BIAS_MODE_INTERNAL 0 +#define RF_BIAS_MODE_EXTERNAL 1 +/** @} */ +/*---------------------------------------------------------------------------*/ #endif /* RF_CORE_H_ */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h index 71d59501d..5e5c75528 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h @@ -50,7 +50,7 @@ #ifndef BOARD_CONF_H_ #define BOARD_CONF_H_ /*---------------------------------------------------------------------------*/ -#include "contiki-conf.h" +#include "rf-conf.h" /*---------------------------------------------------------------------------*/ /** * \name LED configurations for the dev/leds.h API. diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h index 6b3c762d7..88999fe6f 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h @@ -36,6 +36,9 @@ #define Board_CC1310_LAUNCHXL #define BOARD_STRING "TI CC1310 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h new file mode 100644 index 000000000..d8468144f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h index c3763b019..6533b6bdf 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h @@ -36,6 +36,9 @@ #define Board_CC1312R1_LAUNCHXL #define BOARD_STRING "TI CC1312R1 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h index c8094432a..e224327d7 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h @@ -36,6 +36,9 @@ #define Board_CC1350_LAUNCHXL_433 #define BOARD_STRING "TI CC1350-433 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c index a8a6b16c0..92e349480 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c @@ -165,23 +165,60 @@ void Board_initHook() #if defined(Board_RF_SUB1GHZ) /* - * ======== CC1350_LAUNCHXL_433_rfDriverCallback ======== - * This is an implementation for the CC1350 launchpad which uses a + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + +/* + * ======== rfDriverCallback ======== + * This is an implementation for the CC1350 LaunchPad which uses a * single signal for antenna switching. */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Decode input arguments. */ (void)client; RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + if (events & RF_GlobalEventRadioSetup) { /* Power up the antenna switch */ PINCC26XX_setOutputValue(Board_RF_POWER, 1); - if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { - /* Sub-1 GHz, requires antenna switch high */ + /* Decision about the frequency band shall be made based on the + loDivider field. */ + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1 GHz, requires antenna switch high. */ + if ((loDivider != 0) && (loDivider != 2)) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1 GHz, requires antenna switch high. */ + if ((loDivider != 0) && (loDivider != 2)) { + sub1GHz = true; + } + break; + default:break; + } + + /* Select the correct antenna. */ + if (sub1GHz) { PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); } + else { + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } } else if (events & RF_GlobalEventRadioPowerDown) { /* Disable antenna switch to save current */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c index 90f69a0c0..56de7c562 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c @@ -166,6 +166,12 @@ void Board_initHook() */ #if defined(Board_RF_SUB1GHZ) +/* + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + /* * ======== rfDriverCallback ======== * This is an implementation for the CC1350 launchpad which uses a @@ -173,17 +179,48 @@ void Board_initHook() */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Decode input arguments. */ (void)client; RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + if (events & RF_GlobalEventRadioSetup) { /* Power up the antenna switch */ PINCC26XX_setOutputValue(Board_RF_POWER, 1); - if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { - /* Sub-1 GHz, requires antenna switch high */ + /* Decision about the frequency band shall be made based on the + loDivider field. */ + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1 GHz, requires antenna switch high. */ + if ((loDivider != 0) && (loDivider != 2)) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1 GHz, requires antenna switch high. */ + if ((loDivider != 0) && (loDivider != 2)) { + sub1GHz = true; + } + break; + default:break; + } + + /* Select the correct antenna. */ + if (sub1GHz) { PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); } + else { + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } } else if (events & RF_GlobalEventRadioPowerDown) { /* Disable antenna switch to save current */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h index d22d73c17..203c4abc0 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h @@ -36,6 +36,9 @@ #define Board_CC1352P_2_LAUNCHXL #define BOARD_STRING "TI CC1352P-2 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c index f8b4930c8..57f545360 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c @@ -152,6 +152,12 @@ void CC1352P_2_LAUNCHXL_shutDownExtFlash(void) */ #if defined(Board_RF_SUB1GHZ) +/* + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + /* * ======== Antenna switching ======== */ @@ -170,7 +176,7 @@ void initAntennaSwitch() } /* - * ======== rfDriverCallback ======== + * ======== CC1352P1_LAUNCHXL_rfDriverCallback ======== * Sets up the antenna switch depending on the current PHY configuration. * Truth table: * @@ -183,6 +189,10 @@ void initAntennaSwitch() */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); @@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) /* Decode the generic argument as a setup command. */ RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; - if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + default:break; + } + + if (sub1GHz) { /* Sub-1 GHz */ if (paType == RF_TxPowerTable_HighPA) { /* PA enable --> HIGH PA * LNA enable --> Sub-1 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); } else { @@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) * LNA enable --> 2.4 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); } else { diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h index 381651708..ccbed6d2a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h @@ -36,6 +36,9 @@ #define Board_CC1352P_4_LAUNCHXL #define BOARD_STRING "TI CC1352P-4 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c index ef9c0531c..eea9c3b33 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c @@ -152,6 +152,12 @@ void CC1352P_4_LAUNCHXL_shutDownExtFlash(void) */ #if defined(Board_RF_SUB1GHZ) +/* + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + /* * ======== Antenna switching ======== */ @@ -170,7 +176,7 @@ void initAntennaSwitch() } /* - * ======== rfDriverCallback ======== + * ======== CC1352P1_LAUNCHXL_rfDriverCallback ======== * Sets up the antenna switch depending on the current PHY configuration. * Truth table: * @@ -183,6 +189,10 @@ void initAntennaSwitch() */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); @@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) /* Decode the generic argument as a setup command. */ RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; - if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + default:break; + } + + if (sub1GHz) { /* Sub-1 GHz */ if (paType == RF_TxPowerTable_HighPA) { /* PA enable --> HIGH PA * LNA enable --> Sub-1 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); } else { @@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) * LNA enable --> 2.4 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); } else { diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h index 1fef09180..593f24066 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h @@ -36,6 +36,9 @@ #define Board_CC1352P1_LAUNCHXL #define BOARD_STRING "TI CC1352P1 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c index 9f3000929..795f60106 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c @@ -152,6 +152,12 @@ void CC1352P1_LAUNCHXL_shutDownExtFlash(void) */ #if defined(Board_RF_SUB1GHZ) +/* + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + /* * ======== Antenna switching ======== */ @@ -170,7 +176,7 @@ void initAntennaSwitch() } /* - * ======== rfDriverCallback ======== + * ======== CC1352P1_LAUNCHXL_rfDriverCallback ======== * Sets up the antenna switch depending on the current PHY configuration. * Truth table: * @@ -183,6 +189,10 @@ void initAntennaSwitch() */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); @@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) /* Decode the generic argument as a setup command. */ RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; - if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + default:break; + } + + if (sub1GHz) { /* Sub-1 GHz */ if (paType == RF_TxPowerTable_HighPA) { /* PA enable --> HIGH PA * LNA enable --> Sub-1 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); } else { @@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) * LNA enable --> 2.4 GHz */ PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); - // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not - // de-asserted on CC1352 Rev A. + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + de-asserted on CC1352 Rev A. */ PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); } else { diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h index 8bf0ee002..9edab4214 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h @@ -36,6 +36,9 @@ #define Board_CC1352R1_LAUNCHXL #define BOARD_STRING "TI CC1352R1 LaunchPad" +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c index 520b91297..79d97d7b6 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c @@ -164,23 +164,61 @@ void Board_initHook() */ #if defined(Board_RF_SUB1GHZ) +/* + * Mask to be used to determine the effective value of the setup command's + * loDivider field. + */ +#define LODIVIDER_MASK 0x7F + /* * ======== rfDriverCallback ======== - * This is an implementation for the CC1352R1 launchpad which uses a + * This is an implementation for the CC1352R launchpad which uses a * single signal for antenna switching. */ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) { + /* Decode input arguments. */ (void)client; RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; - if ((events & RF_GlobalEventRadioSetup) && - (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP)) { - /* Sub-1 GHz, requires antenna switch high */ - PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + /* Local variable. */ + bool sub1GHz = false; + uint8_t loDivider = 0; + + if (events & RF_GlobalEventRadioSetup) { + /* Decision about the frequency band shall be made based on the + loDivider field. */ + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->common.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider; + + /* Sub-1GHz front-end. */ + if (loDivider != 0) { + sub1GHz = true; + } + break; + default:break; + } + + /* Select the correct antenna. */ + if (sub1GHz) { + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + else { + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } } else if (events & RF_GlobalEventRadioPowerDown) { - /* Disable antenna switch to save current */ + /* Set the antenna to 2.4 GHz as default. */ PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); } } diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h new file mode 100644 index 000000000..70ae4d2cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h new file mode 100644 index 000000000..8dcd9e780 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h new file mode 100644 index 000000000..8dcd9e780 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h index bb8689c98..5ff2f78d8 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h @@ -50,8 +50,7 @@ #ifndef BOARD_CONF_H_ #define BOARD_CONF_H_ /*---------------------------------------------------------------------------*/ -#include "contiki-conf.h" -/*---------------------------------------------------------------------------*/ +#include "rf-conf.h" #include "leds-arch.h" /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h new file mode 100644 index 000000000..06c5b9876 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFP +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h new file mode 100644 index 000000000..8dcd9e780 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h index 037e7eb3f..7d6f8328f 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h @@ -42,6 +42,8 @@ #ifndef BOARD_CONF_H_ #define BOARD_CONF_H_ /*---------------------------------------------------------------------------*/ +#include "rf-conf.h" +/*---------------------------------------------------------------------------*/ /** * \name LED configurations for the dev/leds.h API. * diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h new file mode 100644 index 000000000..8dcd9e780 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h new file mode 100644 index 000000000..8dcd9e780 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.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: + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Header file with board-specific RF configurations. + * \author + * Texas Instruments + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CONF_H_ +#define RF_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board-specific front-end configurations for the radio. + * + * @{ + */ +#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ From ff93ef11dbb3149d8a14a91e55fc592717ea2418 Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Mon, 28 Jan 2019 16:20:50 +0100 Subject: [PATCH 182/184] Added individual configuration of front-end mode for each RF path --- .../cc13xx-cc26xx-conf.h | 26 ++++++++++++++----- .../simplelink-cc13xx-cc26xx/rf/ble-beacond.c | 4 +-- .../simplelink-cc13xx-cc26xx/rf/ieee-mode.c | 4 +-- .../simplelink-cc13xx-cc26xx/rf/prop-mode.c | 4 +-- arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h | 2 +- arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c | 2 +- .../simplelink/cc13xx-cc26xx/contiki-conf.h | 16 +++++++----- .../cc13xx-cc26xx/launchpad/cc1310/rf-conf.h | 11 +++++--- .../cc13xx-cc26xx/launchpad/cc1312r1/Board.h | 9 +++---- .../launchpad/cc1312r1/rf-conf.h | 11 +++++--- .../cc13xx-cc26xx/launchpad/cc1350-4/Board.h | 9 +++---- .../launchpad/cc1350-4/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc1350/Board.h | 6 ++--- .../cc13xx-cc26xx/launchpad/cc1350/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc1352p-2/Board.h | 9 +++---- .../launchpad/cc1352p-2/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc1352p-4/Board.h | 9 +++---- .../launchpad/cc1352p-4/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc1352p1/Board.h | 9 +++---- .../launchpad/cc1352p1/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc1352r1/Board.h | 9 +++---- .../launchpad/cc1352r1/CC1352R1_LAUNCHXL.c | 2 -- .../launchpad/cc1352r1/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/launchpad/cc2650/Board.h | 10 +++---- .../cc13xx-cc26xx/launchpad/cc2650/rf-conf.h | 11 +++++--- .../cc13xx-cc26xx/launchpad/cc26x2r1/Board.h | 10 +++---- .../launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c | 1 - .../launchpad/cc26x2r1/rf-conf.h | 11 +++++--- .../cc13xx-cc26xx/sensortag/cc1350/Board.h | 6 ++--- .../cc13xx-cc26xx/sensortag/cc1350/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/sensortag/cc2650/Board.h | 6 ++--- .../cc13xx-cc26xx/sensortag/cc2650/rf-conf.h | 11 +++++--- .../cc13xx-cc26xx/srf06/cc13x0/Board.h | 6 ++--- .../cc13xx-cc26xx/srf06/cc13x0/rf-conf.h | 15 ++++++++--- .../cc13xx-cc26xx/srf06/cc26x0/Board.h | 6 ++--- .../cc13xx-cc26xx/srf06/cc26x0/rf-conf.h | 11 +++++--- 36 files changed, 223 insertions(+), 128 deletions(-) diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h index 58f34198f..49013070e 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h @@ -133,16 +133,30 @@ #define RF_MODE RF_CONF_MODE #endif /* RF_CONF_MODE */ -#ifdef RF_CONF_FRONT_END_MODE -#define RF_FRONT_END_MODE RF_CONF_FRONT_END_MODE +/* Sub-1 GHz path front-end mode configuration */ +#ifdef RF_SUB_1_GHZ_CONF_FRONT_END_MODE +#define RF_SUB_1_GHZ_FRONT_END_MODE RF_SUB_1_GHZ_CONF_FRONT_END_MODE #else -#define RF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL #endif -#ifdef RF_CONF_BIAS_MODE -#define RF_BIAS_MODE RF_CONF_BIAS_MODE +#ifdef RF_SUB_1_GHZ_CONF_BIAS_MODE +#define RF_SUB_1_GHZ_BIAS_MODE RF_SUB_1_GHZ_CONF_BIAS_MODE #else -#define RF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_SUB_1_GHZ_BIAS_MODE RF_BIAS_MODE_INTERNAL +#endif + +/* 2.4 GHz path front-end mode configuration */ +#ifdef RF_2_4_GHZ_CONF_FRONT_END_MODE +#define RF_2_4_GHZ_FRONT_END_MODE RF_2_4_GHZ_CONF_FRONT_END_MODE +#else +#define RF_2_4_GHZ_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#endif + +#ifdef RF_2_4_GHZ_CONF_BIAS_MODE +#define RF_2_4_GHZ_BIAS_MODE RF_2_4_GHZ_CONF_BIAS_MODE +#else +#define RF_2_4_GHZ_BIAS_MODE RF_BIAS_MODE_INTERNAL #endif /* Number of RX buffers. */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c index 1d2328803..2e8d9d4bc 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c @@ -158,8 +158,8 @@ PROCESS(ble_beacond_process, "RF BLE Beacon Daemon Process"); rf_ble_beacond_result_t rf_ble_beacond_init(void) { - ble_cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; - ble_cmd_radio_setup.config.biasMode = RF_BIAS_MODE; + ble_cmd_radio_setup.config.frontEndMode = RF_2_4_GHZ_FRONT_END_MODE; + ble_cmd_radio_setup.config.biasMode = RF_2_4_GHZ_BIAS_MODE; RF_Params rf_params; RF_Params_init(&rf_params); diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c index 678c50db7..6f21c72ba 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c @@ -217,8 +217,8 @@ rat_overflow_cb(void *arg) static void init_rf_params(void) { - cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; - cmd_radio_setup.config.biasMode = RF_BIAS_MODE; + cmd_radio_setup.config.frontEndMode = RF_2_4_GHZ_FRONT_END_MODE; + cmd_radio_setup.config.biasMode = RF_2_4_GHZ_BIAS_MODE; data_queue_t *rx_q = data_queue_init(sizeof(lensz_t)); diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c index 79c58c339..241ae986d 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c @@ -194,8 +194,8 @@ static int off(void); static void init_rf_params(void) { - cmd_radio_setup.config.frontEndMode = RF_FRONT_END_MODE; - cmd_radio_setup.config.biasMode = RF_BIAS_MODE; + cmd_radio_setup.config.frontEndMode = RF_SUB_1_GHZ_FRONT_END_MODE; + cmd_radio_setup.config.biasMode = RF_SUB_1_GHZ_BIAS_MODE; cmd_radio_setup.centerFreq = PROP_MODE_CENTER_FREQ; cmd_radio_setup.loDivider = PROP_MODE_LO_DIVIDER; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h index c1f454970..65b2b1543 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h @@ -80,7 +80,7 @@ /** * \name The different bias modes the CC13xx/CC26xx devices support. The * bias mode can be configured independently of the front-end mode. The - * two different modes are as follows: + * two different modes are as follows: * - Internal bias: the LNA is biased by an internal bias. * - External bias: the LNA is biased by an external bias. * diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c index eb2426dfc..f15d33d2f 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c @@ -608,7 +608,7 @@ ble_sched_beacons(uint8_t bm_channel) initial_adv = init_ble_adv_array(ble_cmd_adv_nc_array, bm_channel); if(initial_adv == NULL) { - LOG_ERR("Initializing BLE Advertismenet chain failed\n"); + LOG_ERR("Initializing BLE Advertisement chain failed\n"); return RF_RESULT_ERROR; } diff --git a/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h index 212f4fd48..542f69869 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h @@ -31,6 +31,10 @@ * \addtogroup cc13xx-cc26xx-platform * @{ * + * The order of which these header files are included is important in order + * for the configurations to be correctly set. This has to do with some + * slight unfortunate configuration dependencies of the board file. + * * \file * Configuration for the SimpleLink CC13xx/CC26xx platform. * \author @@ -40,18 +44,16 @@ #ifndef CONTIKI_CONF_H_ #define CONTIKI_CONF_H_ /*---------------------------------------------------------------------------*/ -#include "board-conf.h" -/*---------------------------------------------------------------------------*/ -/* Include Project Specific conf */ +/* Include project-specific configurations */ #ifdef PROJECT_CONF_PATH #include PROJECT_CONF_PATH #endif /*---------------------------------------------------------------------------*/ -/* Include CPU-related configuration */ -#include "cc13xx-cc26xx-conf.h" +/* Include board-specific configurations */ +#include "board-conf.h" /*---------------------------------------------------------------------------*/ -/* Must be included after cc13xx-cc26xx-conf.h */ -#include +/* Include CPU-related configurations */ +#include "cc13xx-cc26xx-conf.h" /*---------------------------------------------------------------------------*/ #endif /* CONTIKI_CONF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h index d8468144f..d26d3a864 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the Sub-1 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC1310-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h index 6533b6bdf..a230c764e 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1312R1_LAUNCHXL -#define BOARD_STRING "TI CC1312R1 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1312R1_LAUNCHXL.h" +#define Board_CC1312R1_LAUNCHXL +#define BOARD_STRING "TI CC1312R1 LaunchPad" + #define Board_initGeneral() CC1312R1_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1312R1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1312R1_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h index 70ae4d2cd..f649dd170 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the Sub-1 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC1312R1-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h index e224327d7..4b8fbe5c0 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1350_LAUNCHXL_433 -#define BOARD_STRING "TI CC1350-433 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1350_LAUNCHXL_433.h" +#define Board_CC1350_LAUNCHXL_433 +#define BOARD_STRING "TI CC1350-433 LaunchPad" + #define Board_initGeneral() CC1350_LAUNCHXL_433_initGeneral() #define Board_shutDownExtFlash() CC1350_LAUNCHXL_433_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350_LAUNCHXL_433_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h index 70ae4d2cd..371af4d89 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1350-4-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h index 2099b1845..97ff04a59 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h @@ -33,15 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1350_LAUNCHXL -#define BOARD_STRING "TI CC1350 LaunchPad" - #ifdef __cplusplus extern "C" { #endif #include "CC1350_LAUNCHXL.h" +#define Board_CC1350_LAUNCHXL +#define BOARD_STRING "TI CC1350 LaunchPad" + #define Board_initGeneral() CC1350_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1350_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h index 70ae4d2cd..e6cd0b744 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1350-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h index 203c4abc0..40f76e18b 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1352P_2_LAUNCHXL -#define BOARD_STRING "TI CC1352P-2 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1352P_2_LAUNCHXL.h" +#define Board_CC1352P_2_LAUNCHXL +#define BOARD_STRING "TI CC1352P-2 LaunchPad" + #define Board_initGeneral() CC1352P_2_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1352P_2_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P_2_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h index 70ae4d2cd..1eb0926b7 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1352P-2-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h index ccbed6d2a..de9bc8e9d 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1352P_4_LAUNCHXL -#define BOARD_STRING "TI CC1352P-4 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1352P_4_LAUNCHXL.h" +#define Board_CC1352P_4_LAUNCHXL +#define BOARD_STRING "TI CC1352P-4 LaunchPad" + #define Board_initGeneral() CC1352P_4_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1352P_4_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P_4_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h index 70ae4d2cd..af183614b 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1352P-4-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h index 593f24066..db07b3a0d 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1352P1_LAUNCHXL -#define BOARD_STRING "TI CC1352P1 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1352P1_LAUNCHXL.h" +#define Board_CC1352P1_LAUNCHXL +#define BOARD_STRING "TI CC1352P1 LaunchPad" + #define Board_initGeneral() CC1352P1_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1352P1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P1_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h index 70ae4d2cd..c18573f7a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1352P1-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h index 9edab4214..83b27069a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h @@ -33,18 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1352R1_LAUNCHXL -#define BOARD_STRING "TI CC1352R1 LaunchPad" - -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL - #ifdef __cplusplus extern "C" { #endif #include "CC1352R1_LAUNCHXL.h" +#define Board_CC1352R1_LAUNCHXL +#define BOARD_STRING "TI CC1352R1 LaunchPad" + #define Board_initGeneral() CC1352R1_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC1352R1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352R1_LAUNCHXL_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c index d2b3eeee3..f3d002206 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c @@ -36,8 +36,6 @@ * CC1352R1_LAUNCHXL board. */ -#include "contiki.h" - #include #include #include diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h index 70ae4d2cd..ba652cd53 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1352R1-LAUNCHXL board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h index 8f3e437f0..577ce0422 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h @@ -33,18 +33,18 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC2650_LAUNCHXL -#define BOARD_STRING "TI CC2650 LaunchPad" - #ifdef __cplusplus extern "C" { #endif #include "CC2650_LAUNCHXL.h" -#define Board_initGeneral() CC2650_LAUNCHXL_initGeneral() +#define Board_CC2650_LAUNCHXL +#define BOARD_STRING "TI CC2650 LaunchPad" + +#define Board_initGeneral() CC2650_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC2650_LAUNCHXL_shutDownExtFlash() -#define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash() +#define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash() /* These #defines allow us to reuse TI-RTOS across other device families */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h index 8dcd9e780..9d6abaeac 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the 2.4 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC2650-LAUNCHXL board: + * - 2.4 GHz: differential and internal bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h index a19145b2c..ddf5e4946 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h @@ -33,20 +33,18 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC26X2R1_LAUNCHXL -#define BOARD_STRING "TI CC26x2R1 LaunchPad" - #ifdef __cplusplus extern "C" { #endif #include "CC26X2R1_LAUNCHXL.h" -#define Board_initGeneral() CC26X2R1_LAUNCHXL_initGeneral() +#define Board_CC26X2R1_LAUNCHXL +#define BOARD_STRING "TI CC26x2R1 LaunchPad" +#define Board_initGeneral() CC26X2R1_LAUNCHXL_initGeneral() #define Board_shutDownExtFlash() CC26X2R1_LAUNCHXL_shutDownExtFlash() - -#define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash() +#define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash() /* These #defines allow us to reuse TI-RTOS across other device families */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c index a66a6ef00..854d1d2ba 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c @@ -35,7 +35,6 @@ * This file is responsible for setting up the board specific items for the * CC26X2R1_LAUNCHXL board. */ -#include "contiki.h" #include #include diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h index 8dcd9e780..ed58c8732 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the 2.4 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC26X2R1-LAUNCHXL board: + * - 2.4 GHz: differential and internal bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h index ecdb6d2af..e32e74fc1 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h @@ -33,15 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1350STK -#define BOARD_STRING "TI CC1350 SensorTag" - #ifdef __cplusplus extern "C" { #endif #include "CC1350STK.h" +#define Board_CC1350STK +#define BOARD_STRING "TI CC1350 SensorTag" + #define Board_initGeneral() CC1350STK_initGeneral() #define Board_shutDownExtFlash() CC1350STK_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350STK_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h index 06c5b9876..1f3dfbe52 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1350STK board: + * - Sub-1 GHz: single-ended RFN and external bias + * - 2.4 GHz: single-ended RFP and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFP -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFN +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFP +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h index e334645bb..8425de454 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h @@ -33,15 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC2650STK -#define BOARD_STRING "TI CC2650 SensorTag" - #ifdef __cplusplus extern "C" { #endif #include "CC2650STK.h" +#define Board_CC2650STK +#define BOARD_STRING "TI CC2650 SensorTag" + #define Board_initGeneral() CC2650STK_initGeneral() #define Board_shutDownExtFlash() CC2650STK_shutDownExtFlash() #define Board_wakeUpExtFlash() CC2650STK_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h index 8dcd9e780..48db37a96 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the 2.4 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC2650STK board: + * - 2.4 GHz: differential and internal bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h index 0941b222f..48d232e54 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h @@ -33,15 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC1350DK_7XD -#define BOARD_STRING "TI SmartRF06EB + CC13x0 EM" - #ifdef __cplusplus extern "C" { #endif #include "CC1350DK_7XD.h" +#define Board_CC1350DK_7XD +#define BOARD_STRING "TI SmartRF06EB + CC13x0 EM" + #define Board_initGeneral() CC1350DK_7XD_initGeneral() #define Board_shutDownExtFlash() CC1350DK_7XD_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350DK_7XD_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h index 8dcd9e780..327e8fb5d 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/rf-conf.h @@ -45,12 +45,21 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for both the Sub-1 GHz + * path and the 2.4 GHz path on the radio. + * + * These are the following front-end mode configurations for the + * CC1350DK-7XD board: + * - Sub-1 GHz: differential and external bias + * - 2.4 GHz: differential and external bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL + +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h index c42d3a169..d90291418 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h @@ -33,15 +33,15 @@ #ifndef __BOARD_H #define __BOARD_H -#define Board_CC2650DK_7ID -#define BOARD_STRING "TI SmartRF06EB + CC26x0 EM" - #ifdef __cplusplus extern "C" { #endif #include "CC2650DK_7ID.h" +#define Board_CC2650DK_7ID +#define BOARD_STRING "TI SmartRF06EB + CC26x0 EM" + #define Board_initGeneral() CC2650DK_7ID_initGeneral() #define Board_shutDownExtFlash() CC2650DK_7ID_shutDownExtFlash() #define Board_wakeUpExtFlash() CC2650DK_7ID_wakeUpExtFlash() diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h index 8dcd9e780..bdbade005 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/rf-conf.h @@ -45,12 +45,17 @@ #include "rf/rf.h" /*---------------------------------------------------------------------------*/ /** - * \name Board-specific front-end configurations for the radio. + * \name Board-specific front-end mode configurations for the 2.4 GHz path + * on the radio. + * + * These are the following front-end mode configurations for the + * CC2650DK-7ID board: + * - 2.4 GHz: differential and internal bias * * @{ */ -#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL -#define RF_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL +#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL +#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL /** @} */ /*---------------------------------------------------------------------------*/ #endif /* RF_CONF_H_ */ From 28d7a6e1ba841b4078a1ff874e3b15fc5fd8ec95 Mon Sep 17 00:00:00 2001 From: firmwareguru Date: Mon, 4 Feb 2019 19:59:03 -0700 Subject: [PATCH 183/184] Fix simplelink gpio hysteresis bitmask --- arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c index e219faa93..f07a1f693 100644 --- a/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c @@ -96,7 +96,7 @@ to_hal_cfg(PIN_Config pin_cfg, gpio_hal_pin_cfg_t *cfg) /* Input config */ if(pin_cfg & PIN_BM_INPUT_MODE) { /* Hysteresis config */ - if((pin_cfg & PIN_BM_HYSTERESIS) == PIN_HYSTERESIS) { + if((pin_cfg & PIN_BM_HYSTERESIS) == PIN_BM_HYSTERESIS) { *cfg |= GPIO_HAL_PIN_CFG_HYSTERESIS; } From 87acf4a6459b52740375d33a62bcc611f8931e83 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Mon, 18 Feb 2019 16:38:29 +0200 Subject: [PATCH 184/184] 23-rpl-tsch-z1.csc - remove one node that does not like to be routed --- tests/07-simulation-base/23-rpl-tsch-z1.csc | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/07-simulation-base/23-rpl-tsch-z1.csc b/tests/07-simulation-base/23-rpl-tsch-z1.csc index f5a182ecd..170300f55 100644 --- a/tests/07-simulation-base/23-rpl-tsch-z1.csc +++ b/tests/07-simulation-base/23-rpl-tsch-z1.csc @@ -7,7 +7,7 @@ [APPS_DIR]/powertracker RPL+TSCH (Z1) - 123456 + 1 1000000 org.contikios.cooja.radiomediums.UDGM @@ -108,20 +108,6 @@ z11 - - - - org.contikios.cooja.interfaces.Position - 10.622284947035123 - 109.81862399725188 - 0.0 - - - org.contikios.cooja.mspmote.interfaces.MspMoteID - 6 - - z11 - org.contikios.cooja.plugins.SimControl @@ -168,7 +154,6 @@ 2 3 4 - 5