From 2947ca06c9aae427a3442e52c1c70726d521d0d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 5 Aug 2017 12:32:31 -0600 Subject: [PATCH] Avoid some harsh, inappropriate DEBUGASSERT's. --- configs/clicker2-stm32/README.txt | 3 ++ .../wireless/spirit/drivers/spirit_netdev.c | 45 ++++++++++++++++--- net/sixlowpan/sixlowpan_utils.c | 18 +++++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt index e4a967648a..9c4029cbe0 100644 --- a/configs/clicker2-stm32/README.txt +++ b/configs/clicker2-stm32/README.txt @@ -686,6 +686,9 @@ Configurations some additional fixes for byte ordering in 16-bit and 64-bit compressed IPv6 addresses, then all tests are working as expected: TCP, UDP, Telnet. + 2017-08-5: It looks like I have lost one of my Clicker2-STM32 boards. + This means that I will not be able to do any regression testing as + changes are made to the radio interfaces and 6LoWPAN :( nsh: diff --git a/drivers/wireless/spirit/drivers/spirit_netdev.c b/drivers/wireless/spirit/drivers/spirit_netdev.c index f53c2b27c1..f224f78dcb 100644 --- a/drivers/wireless/spirit/drivers/spirit_netdev.c +++ b/drivers/wireless/spirit/drivers/spirit_netdev.c @@ -959,9 +959,22 @@ static void spirit_interrupt_work(FAR void *arg) if (irqstatus.IRQ_RX_FIFO_ERROR != 0) { wlwarn("WARNING: Rx FIFO Error\n"); - DEBUGVERIFY(spirit_command(spirit, CMD_FLUSHRXFIFO)); - priv->state = DRIVER_STATE_IDLE; + /* Discard RX data */ + + DEBUGVERIFY(spirit_command(spirit, CMD_FLUSHRXFIFO)); + irqstatus.IRQ_RX_DATA_READY = 0; + irqstatus.IRQ_VALID_SYNC = 0; + + /* Revert the receiving state */ + + if (priv->state == DRIVER_STATE_RECEIVING) + { + priv->state = DRIVER_STATE_IDLE; + } + + /* Update error statistics */ + NETDEV_RXERRORS(&priv->radio.r_dev); NETDEV_ERRORS(&priv->radio.r_dev); @@ -976,9 +989,21 @@ static void spirit_interrupt_work(FAR void *arg) irqstatus.IRQ_MAX_RE_TX_REACH != 0) { wlwarn("WARNING: Tx FIFO Error/Max retries\n"); - DEBUGVERIFY(spirit_command(spirit, COMMAND_FLUSHTXFIFO)); - priv->state = DRIVER_STATE_IDLE; + /* Discard TX data */ + + DEBUGVERIFY(spirit_command(spirit, COMMAND_FLUSHTXFIFO)); + irqstatus.IRQ_TX_DATA_SENT = 0; + + /* Revert the sending state */ + + if (priv->state == DRIVER_STATE_SENDING) + { + priv->state = DRIVER_STATE_IDLE; + } + + /* Update error statistics */ + NETDEV_TXERRORS(&priv->radio.r_dev); NETDEV_ERRORS(&priv->radio.r_dev); @@ -1031,8 +1056,16 @@ static void spirit_interrupt_work(FAR void *arg) if (irqstatus.IRQ_VALID_SYNC != 0) { wlinfo("Valid sync\n"); - DEBUGASSERT(priv->state == DRIVER_STATE_IDLE); - priv->state = DRIVER_STATE_RECEIVING; + + /* I have seen multiple Valid Sync interrupts following an RX error + * condition. + */ + + if (priv->state != DRIVER_STATE_RECEIVING) + { + DEBUGASSERT(priv->state == DRIVER_STATE_IDLE); + priv->state = DRIVER_STATE_RECEIVING; + } } /* The IRQ_RX_DATA_READY notifies that a new packet has been received */ diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index d2bbea2d29..0765dd4ff1 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -124,8 +124,6 @@ #ifdef HAVE_BYTEADDR static void sixlowpan_baddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *baddr) { - DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); - /* Big-endian uint16_t to byte order */ baddr[0] = ipaddr[7] >> 8 ^ 0x02; @@ -135,8 +133,6 @@ static void sixlowpan_baddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *badd #ifdef HAVE_SADDR static void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *saddr) { - DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); - /* Big-endian uint16_t to byte order */ saddr[0] = ipaddr[7] >> 8; @@ -181,7 +177,7 @@ static void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *eadd * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xx00 1-byte short address IEEE 48-bit MAC + * xxxx 0000 0000 0000 0000 00ff fe00 xx00 1-byte short address IEEE 48-bit MAC * xxxx 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC * xxxx 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 * @@ -218,6 +214,16 @@ int sixlowpan_destaddrfromip(FAR struct sixlowpan_driver_s *radio, /* Otherwise, the destination MAC address is encoded in the IP address */ + /* Check for compressible link-local address. + * REVISIT: This should not restrict us to link-local addresses. + */ + + if (ipaddr[0] != HTONS(0xfe80) || ipaddr[1] != 0 || + ipaddr[2] != 0 || ipaddr[3] != 0) + { + return -EADDRNOTAVAIL; + } + #ifdef CONFIG_WIRELESS_PKTRADIO /* If this is a packet radio, then we cannot know the correct size of the * radio's MAC address without asking. The setting CONFIG_PKTRADIO_ADDRLEN @@ -242,8 +248,6 @@ int sixlowpan_destaddrfromip(FAR struct sixlowpan_driver_s *radio, return ret; } - DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); - #ifdef HAVE_BYTEADDR if (properties.sp_addrlen == 1 && SIXLOWPAN_IS_IID_8BIT_COMPRESSABLE(ipaddr))