From fc4f1de76653bab5888d9a06fc56805a2751c2d4 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 19 Jun 2017 15:54:36 -0400 Subject: [PATCH 01/10] wireless/ieee802154: Cleans up some endianness issues --- wireless/ieee802154/mac802154.c | 19 +++++++-------- wireless/ieee802154/mac802154_assoc.c | 30 ++++++++++-------------- wireless/ieee802154/mac802154_internal.h | 23 ++++++++++++++---- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index c7d53fd265..44068a6705 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -251,7 +251,6 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv, FAR struct ieee802154_txdesc_s *txdesc) { FAR struct iob_s *iob; - FAR uint16_t *u16; /* The only node allowed to use a source address of none is the PAN Coordinator. * PAN coordinators should not be sending data request commans. @@ -269,16 +268,16 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv, iob->io_offset = 0; iob->io_pktlen = 0; - /* Get a uin16_t reference to the first two bytes. ie frame control field */ + /* Set the frame control fields */ - u16 = (FAR uint16_t *)&iob->io_data[iob->io_len]; + iob->io_data[0] = 0; + iob->io_data[1] = 0; + IEEE802154_SETACKREQ(iob->io_data, 0); + IEEE802154_SETFTYPE(iob->io_data, 0, IEEE802154_FRAME_COMMAND); + IEEE802154_SETDADDRMODE(iob->io_data, 0, coordaddr->mode); + IEEE802154_SETSADDRMODE(iob->io_data, 0, srcmode); iob->io_len = 2; - *u16 = (IEEE802154_FRAME_COMMAND << IEEE802154_FRAMECTRL_SHIFT_FTYPE); - *u16 |= IEEE802154_FRAMECTRL_ACKREQ; - *u16 |= (coordaddr->mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); - *u16 |= (srcmode << IEEE802154_FRAMECTRL_SHIFT_SADDR); - /* Each time a data or a MAC command frame is generated, the MAC sublayer * shall copy the value of macDSN into the Sequence Number field of the * MHR of the outgoing frame and then increment it by one. [1] pg. 40. @@ -304,8 +303,6 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv, } } - *u16 |= (coordaddr->mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); - /* If the Destination Addressing Mode field is set to indicate that * destination addressing information is not present, the PAN ID Compression * field shall be set to zero and the source PAN identifier shall contain the @@ -318,7 +315,7 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv, if (coordaddr->mode != IEEE802154_ADDRMODE_NONE && IEEE802154_PANIDCMP(coordaddr->panid, priv->addr.panid)) { - *u16 |= IEEE802154_FRAMECTRL_PANIDCOMP; + IEEE802154_SETPANIDCOMP(iob->io_data, 0); } else { diff --git a/wireless/ieee802154/mac802154_assoc.c b/wireless/ieee802154/mac802154_assoc.c index c6c2135fc0..fd31623d20 100644 --- a/wireless/ieee802154/mac802154_assoc.c +++ b/wireless/ieee802154/mac802154_assoc.c @@ -86,7 +86,6 @@ int mac802154_req_associate(MACHANDLE mac, (FAR struct ieee802154_privmac_s *)mac; FAR struct ieee802154_txdesc_s *txdesc; FAR struct iob_s *iob; - FAR uint16_t *u16; bool rxonidle; int ret; @@ -177,12 +176,13 @@ int mac802154_req_associate(MACHANDLE mac, /* Get a uin16_t reference to the first two bytes. ie frame control field */ - u16 = (FAR uint16_t *)&iob->io_data[0]; + iob->io_data[0] = 0; + iob->io_data[1] = 0; - *u16 = (IEEE802154_FRAME_COMMAND << IEEE802154_FRAMECTRL_SHIFT_FTYPE); - *u16 |= IEEE802154_FRAMECTRL_ACKREQ; - *u16 |= (priv->coordaddr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); - *u16 |= (IEEE802154_ADDRMODE_EXTENDED << IEEE802154_FRAMECTRL_SHIFT_SADDR); + IEEE802154_SETACKREQ(iob->io_data, 0); + IEEE802154_SETFTYPE(iob->io_data, 0, IEEE802154_FRAME_COMMAND); + IEEE802154_SETDADDRMODE(iob->io_data, 0, priv->coordaddr.mode); + IEEE802154_SETSADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED); iob->io_len = 2; @@ -281,7 +281,6 @@ int mac802154_resp_associate(MACHANDLE mac, (FAR struct ieee802154_privmac_s *)mac; FAR struct ieee802154_txdesc_s *txdesc; FAR struct iob_s *iob; - FAR uint16_t *u16; int ret; /* Allocate an IOB to put the frame in */ @@ -294,10 +293,6 @@ int mac802154_resp_associate(MACHANDLE mac, iob->io_offset = 0; iob->io_pktlen = 0; - /* Get a uin16_t reference to the first two bytes. ie frame control field */ - - u16 = (FAR uint16_t *)&iob->io_data[0]; - /* The Destination Addressing Mode and Source Addressing Mode fields shall * each be set to indicate extended addressing. * @@ -307,12 +302,13 @@ int mac802154_resp_associate(MACHANDLE mac, * The PAN ID Compression field shall be set to one. [1] pg. 69 */ - *u16 = (IEEE802154_FRAME_COMMAND << IEEE802154_FRAMECTRL_SHIFT_FTYPE); - *u16 |= IEEE802154_FRAMECTRL_ACKREQ; - *u16 |= IEEE802154_FRAMECTRL_PANIDCOMP; - *u16 |= (IEEE802154_ADDRMODE_EXTENDED << IEEE802154_FRAMECTRL_SHIFT_DADDR); - *u16 |= (IEEE802154_ADDRMODE_EXTENDED << IEEE802154_FRAMECTRL_SHIFT_SADDR); - + iob->io_data[0] = 0; + iob->io_data[1] = 0; + IEEE802154_SETACKREQ(iob->io_data, 0); + IEEE802154_SETPANIDCOMP(iob->io_data, 0); + IEEE802154_SETFTYPE(iob->io_data, 0, IEEE802154_FRAME_COMMAND); + IEEE802154_SETDADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED); + IEEE802154_SETSADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED); iob->io_len = 2; /* Each time a data or a MAC command frame is generated, the MAC sublayer diff --git a/wireless/ieee802154/mac802154_internal.h b/wireless/ieee802154/mac802154_internal.h index 2fa01eda5b..1ebfa0e15a 100644 --- a/wireless/ieee802154/mac802154_internal.h +++ b/wireless/ieee802154/mac802154_internal.h @@ -127,16 +127,31 @@ #define GETNET16(ptr,index) \ ((((uint16_t)((ptr)[(index) + 1])) << 8) | ((uint16_t)(((ptr)[index])))) -/* PUT 16-bit data: source in host order, result in newtwork order */ +/* Set 16-bit data: source in host order, result in network order. */ -#define PUTHOST16(ptr,index,value) \ +#define IEEE802154_SETBITS_U16(ptr,index,value) \ do \ { \ - (ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \ - (ptr)[index + 1] = (uint16_t)(value) & 0xff; \ + (ptr)[index] |= (uint16_t)(value) & 0xff; \ + (ptr)[index + 1] |= ((uint16_t)(value) >> 8) & 0xff; \ } \ while(0) +#define IEEE802154_SETFTYPE(ptr, index, ftype) \ + IEEE802154_SETBITS_U16(ptr, index, (ftype << IEEE802154_FRAMECTRL_SHIFT_FTYPE)) + +#define IEEE802154_SETACKREQ(ptr, index) \ + IEEE802154_SETBITS_U16(ptr, index, IEEE802154_FRAMECTRL_ACKREQ) + +#define IEEE802154_SETDADDRMODE(ptr, index, mode) \ + IEEE802154_SETBITS_U16(ptr, index, (mode << IEEE802154_FRAMECTRL_SHIFT_DADDR)) + +#define IEEE802154_SETSADDRMODE(ptr, index, mode) \ + IEEE802154_SETBITS_U16(ptr, index, (mode << IEEE802154_FRAMECTRL_SHIFT_SADDR)) + +#define IEEE802154_SETPANIDCOMP(ptr, index) \ + IEEE802154_SETBITS_U16(ptr, index, IEEE802154_FRAMECTRL_PANIDCOMP) + /* Configuration ************************************************************/ /* If processing is not done at the interrupt level, then work queue support * is required. From 0603d34ad937af34584bdacdf23a0a7c35851443 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 19 Jun 2017 15:55:02 -0400 Subject: [PATCH 02/10] wireless/ieee80215: Fixes poll request issue --- wireless/ieee802154/mac802154_poll.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wireless/ieee802154/mac802154_poll.c b/wireless/ieee802154/mac802154_poll.c index 7f5251fdc9..f82ba91f3d 100644 --- a/wireless/ieee802154/mac802154_poll.c +++ b/wireless/ieee802154/mac802154_poll.c @@ -142,6 +142,12 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) txdesc); } + /* Save a copy of the destination addressing infromation into the tx descriptor. + * We only do this for commands to help with handling their progession. + */ + + memcpy(&txdesc->destaddr, &req->coordaddr, sizeof(struct ieee802154_addr_s)); + /* Save a reference of the tx descriptor */ priv->cmd_desc = txdesc; From 68a2b84277988f8dbc61bc7a90a759ee6863caef Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 19 Jun 2017 16:01:35 -0600 Subject: [PATCH 03/10] Update a README --- configs/clicker2-stm32/README.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt index 49b645204a..4789921809 100644 --- a/configs/clicker2-stm32/README.txt +++ b/configs/clicker2-stm32/README.txt @@ -453,6 +453,16 @@ Configurations NOTE: There is no way to stop the UDP test once it has been started other than by resetting the board. + STATUS: + 2017-06-19: The Telnet Daemon does not start. This is simply because + the daemon is started too early in the sequence... befor the network + has been brought up: + + telnetd_daemon: ERROR: socket failure: 106 + + Basic network bring-up sequence works. At least no errors are + reported. + nsh: Configures the NuttShell (nsh) located at examples/nsh. This From 6dafb4f53293f8f906b006251cc87f15ebfa6c74 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 10:37:32 -0600 Subject: [PATCH 04/10] 6LoWPAN: Add debug statements; Update configuration, need to specific 6LoWPAN compatible port numbers. --- Kconfig | 18 +++---- .../clicker2-stm32/mrf24j40-6lowpan/defconfig | 2 + net/sixlowpan/README.txt | 3 +- net/sixlowpan/sixlowpan_framelist.c | 2 + net/sixlowpan/sixlowpan_send.c | 14 ++++-- wireless/ieee802154/mac802154_netdev.c | 49 +++++++------------ 6 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Kconfig b/Kconfig index d2157939e8..0479955f52 100644 --- a/Kconfig +++ b/Kconfig @@ -848,15 +848,6 @@ config DEBUG_SYSCALL_INFO endif # DEBUG_SYSCALL -config DEBUG_WIRELESS - bool "Wireless Device Debug Output" - default n - depends on WIRELESS - ---help--- - Enable low level debug SYSLOG output from the wireless subsystem and - device drivers. (disabled by default). Support for this debug option - is architecture-specific and may not be available for some MCUs. - comment "OS Function Debug Options" config DEBUG_DMA @@ -1107,6 +1098,15 @@ config DEBUG_ANALOG_INFO endif # DEBUG_ANALOG +config DEBUG_WIRELESS + bool "Wireless Device Debug Output" + default n + depends on WIRELESS + ---help--- + Enable low level debug SYSLOG output from the wireless subsystem and + device drivers. (disabled by default). Support for this debug option + is architecture-specific and may not be available for some MCUs. + config DEBUG_CAN bool "CAN Debug Features" default n diff --git a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig index 9619d02170..8759fc1248 100644 --- a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig +++ b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig @@ -1374,6 +1374,8 @@ CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_5=0x0000 CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_6=0x00ff CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_7=0xfe00 CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_8=0x0d00 +CONFIG_EXAMPLES_SERVER_PORTNO=61616 +CONFIG_EXAMPLES_CLIENT_PORTNO=61617 # CONFIG_EXAMPLES_UDPBLASTER is not set # CONFIG_EXAMPLES_USBSERIAL is not set # CONFIG_EXAMPLES_WATCHDOG is not set diff --git a/net/sixlowpan/README.txt b/net/sixlowpan/README.txt index 775357260b..4c654caef1 100644 --- a/net/sixlowpan/README.txt +++ b/net/sixlowpan/README.txt @@ -82,7 +82,8 @@ Optimal 6LoWPAN Configuration fe80 0000 0000 0000 0000 00ff fe00 MMMM 2-byte short address IEEE 48-bit MAC fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte extended address IEEE EUI-64 -4. Compressable port numbers in the rangs 0xf0b0-0xf0bf +4. To be compressable, port numbers must be in the range 0xf0b0-0xf0bf, + hexadecimal. That is 61616-61631 decimal. 5. IOBs: Must be big enough to hold one IEEE802.15.4 frame (CONFIG_NET_6LOWPAN_FRAMELEN, typically 127). There must be enough IOBs to decompose the largest IPv6 diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 0b17e6dbab..226711af02 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -224,6 +224,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, #endif int ret; + ninfo("buflen=%lu", (unsigned long)buflen); + /* Initialize global data. Locking the network guarantees that we have * exclusive use of the global values for intermediate calculations. */ diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index a8fcdea983..18202d4b95 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -182,7 +182,7 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev, if ((flags & NETDEV_DOWN) != 0) { - ninfo("Device is down\n"); + nwarn("WARNING: Device is down\n"); sinfo->s_result = -ENOTCONN; goto end_wait; } @@ -279,6 +279,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev, { struct sixlowpan_send_s sinfo; + ninfo("len=%lu timeout=%u\n", (unsigned long)len, timeout); + /* Initialize the send state structure */ sem_init(&sinfo.s_waitsem, 0, 0); @@ -301,16 +303,16 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * device related events, no connect-related events. */ - sinfo.s_cb = devif_callback_alloc(dev, list); + sinfo.s_cb = devif_callback_alloc(dev, list); if (sinfo.s_cb != NULL) { int ret; /* Set up the callback in the connection */ - sinfo.s_cb->flags = (NETDEV_DOWN | WPAN_POLL); - sinfo.s_cb->priv = (FAR void *)&sinfo; - sinfo.s_cb->event = send_interrupt; + sinfo.s_cb->flags = (NETDEV_DOWN | WPAN_POLL); + sinfo.s_cb->priv = (FAR void *)&sinfo; + sinfo.s_cb->event = send_interrupt; /* Notify the IEEE802.15.4 MAC that we have data to send. */ @@ -322,6 +324,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * automatically re-enabled when the task restarts. */ + ninfo("Wait for send complete\n"); + ret = net_lockedwait(&sinfo.s_waitsem); if (ret < 0) { diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index d30320efb7..5966532b88 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -676,27 +676,6 @@ static int macnet_txpoll_callback(FAR struct net_driver_s *dev) return 0; } -/**************************************************************************** - * Name: macnet_txpoll_process - * - * Description: - * Perform the periodic poll. This may be called either from watchdog - * timer logic or from the worker thread, depending upon the configuration. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static inline void macnet_txpoll_process(FAR struct macnet_driver_s *priv) -{ -} - /**************************************************************************** * Name: macnet_txpoll_work * @@ -792,20 +771,20 @@ static int macnet_ifup(FAR struct net_driver_s *dev) ret = macnet_advertise(dev); if (ret >= 0) { - ninfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", - dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], - dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], - dev->d_ipv6addr[6], dev->d_ipv6addr[7]); + wlinfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], + dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], + dev->d_ipv6addr[6], dev->d_ipv6addr[7]); #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1], - dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3], - dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5], - dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7]); + wlinfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1], + dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3], + dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5], + dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7]); #else - ninfo(" Node: %02x:%02x\n", - dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1]); + wlinfo(" Node: %02x:%02x\n", + dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1]); #endif /* Set and activate a timer process */ @@ -884,6 +863,8 @@ static void macnet_txavail_work(FAR void *arg) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; + wlinfo("ifup=%u\n", priv->md_bifup); + /* Lock the network and serialize driver operations if necessary. * NOTE: Serialization is only required in the case where the driver work * is performed on an LP worker thread and where more than one LP worker @@ -929,6 +910,8 @@ static int macnet_txavail(FAR struct net_driver_s *dev) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; + wlinfo("Available=%u\n", work_available(&priv->md_pollwork)); + /* Is our single work structure available? It may not be if there are * pending interrupt actions and we will have to ignore the Tx * availability action. @@ -1111,6 +1094,8 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, FAR struct iob_s *iob; int ret; + wlinfo("Received framelist\n"); + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL); priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private; From a82ab4b7296e4e21711871b4da89500216a89ca6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 11:23:31 -0600 Subject: [PATCH 05/10] mac802154_req_data() can return without releasing the exclsem --- configs/clicker2-stm32/README.txt | 8 ++++---- wireless/ieee802154/mac802154.c | 2 -- wireless/ieee802154/mac802154_data.c | 25 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt index 4789921809..c016313636 100644 --- a/configs/clicker2-stm32/README.txt +++ b/configs/clicker2-stm32/README.txt @@ -447,7 +447,7 @@ Configurations The ifconfig command will show the IP address of the server. Then on the client node use this IP address to start the client: - nsh> udpserver & + nsh> udpclient & Where is the IP address of the server that you got above. NOTE: There is no way to stop the UDP test once it has been started @@ -455,13 +455,13 @@ Configurations STATUS: 2017-06-19: The Telnet Daemon does not start. This is simply because - the daemon is started too early in the sequence... befor the network + the daemon is started too early in the sequence... before the network has been brought up: telnetd_daemon: ERROR: socket failure: 106 - Basic network bring-up sequence works. At least no errors are - reported. + 2017-06-20: I am get EINTR errors from the MAC layer when trying the + udpclient tries to send messages. Still under investigation. nsh: diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 44068a6705..b7b4b3ca3e 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -169,7 +169,6 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, */ ret = sem_trywait(&priv->txdesc_sem); - if (ret == OK) { *txdesc = (FAR struct ieee802154_txdesc_s *)sq_remfirst(&priv->txdesc_queue); @@ -228,7 +227,6 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, } (*txdesc)->conf = ¬if->u.dataconf; - return OK; } diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index c97d55eddb..b51d31880f 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -147,7 +147,10 @@ int mac802154_req_data(MACHANDLE mac, ret = mac802154_takesem(&priv->exclsem, true); if (ret < 0) { - return ret; + /* Should only fail it interrupted by a signal */ + + wlwarn("WARNING: mac802154_takesem failed: %d", ret); + goto errout_with_sem; } /* If both destination and source addressing information is present, the MAC @@ -201,7 +204,8 @@ int mac802154_req_data(MACHANDLE mac, if (priv->devmode != IEEE802154_DEVMODE_PANCOORD) { - return -EINVAL; + ret = -EINVAL; + goto errout_with_sem; } } @@ -231,7 +235,8 @@ int mac802154_req_data(MACHANDLE mac, ret = mac802154_txdesc_alloc(priv, &txdesc, true); if (ret < 0) { - return ret; + wlwarn("WARNING: mac802154_txdesc_alloc failed: %d", ret); + goto errout_with_sem; } txdesc->conf->handle = meta->msdu_handle; @@ -259,11 +264,8 @@ int mac802154_req_data(MACHANDLE mac, * don't have to try and kick-off any transmission here. */ - /* We no longer need to have the MAC layer locked. */ - - mac802154_givesem(&priv->exclsem); - - return -ENOTSUP; + ret = -ENOTSUP; + goto errout_with_sem; } else { @@ -300,7 +302,8 @@ int mac802154_req_data(MACHANDLE mac, else { mac802154_givesem(&priv->exclsem); - return -EINVAL; + ret = -EINVAL; + goto errout_with_sem; } } else @@ -320,6 +323,10 @@ int mac802154_req_data(MACHANDLE mac, } return OK; + +errout_with_sem: + mac802154_givesem(&priv->exclsem); + return ret; } /**************************************************************************** From e0b1bb6c5f1d333a746135f0323889e02b61480c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 11:33:03 -0600 Subject: [PATCH 06/10] 802.15.4 MAC: Fix some errors in the previous commit. --- wireless/ieee802154/mac802154_data.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index b51d31880f..bd06e58b16 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -147,10 +147,10 @@ int mac802154_req_data(MACHANDLE mac, ret = mac802154_takesem(&priv->exclsem, true); if (ret < 0) { - /* Should only fail it interrupted by a signal */ + /* Should only fail if interrupted by a signal */ wlwarn("WARNING: mac802154_takesem failed: %d", ret); - goto errout_with_sem; + return ret; } /* If both destination and source addressing information is present, the MAC @@ -235,8 +235,12 @@ int mac802154_req_data(MACHANDLE mac, ret = mac802154_txdesc_alloc(priv, &txdesc, true); if (ret < 0) { + /* Should only fail if interrupted by a signal while re-acquiring + * exclsem. So the lock is not held if a failure is returned. + */ + wlwarn("WARNING: mac802154_txdesc_alloc failed: %d", ret); - goto errout_with_sem; + return ret; } txdesc->conf->handle = meta->msdu_handle; @@ -301,7 +305,6 @@ int mac802154_req_data(MACHANDLE mac, } else { - mac802154_givesem(&priv->exclsem); ret = -EINVAL; goto errout_with_sem; } From d3b9ea9d66a125e8b0d60e7c0fde7daef40cf9f1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 11:50:04 -0600 Subject: [PATCH 07/10] Trivial.. missing newlines in debug output --- wireless/ieee802154/mac802154.c | 3 +++ wireless/ieee802154/mac802154_data.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index b7b4b3ca3e..cfc59700da 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -188,6 +188,7 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, { /* MAC is already released */ + wlwarn("WARNING: mac802154_takesem failed: %d\n", ret); return -EINTR; } @@ -199,6 +200,8 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, ret = mac802154_takesem(&priv->exclsem, allow_interrupt); if (ret < 0) { + wlwarn("WARNING: mac802154_takesem failed: %d\n", ret); + mac802154_givesem(&priv->txdesc_sem); return -EINTR; } diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index bd06e58b16..0676c52103 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -149,7 +149,7 @@ int mac802154_req_data(MACHANDLE mac, { /* Should only fail if interrupted by a signal */ - wlwarn("WARNING: mac802154_takesem failed: %d", ret); + wlwarn("WARNING: mac802154_takesem failed: %d\n", ret); return ret; } @@ -239,7 +239,7 @@ int mac802154_req_data(MACHANDLE mac, * exclsem. So the lock is not held if a failure is returned. */ - wlwarn("WARNING: mac802154_txdesc_alloc failed: %d", ret); + wlwarn("WARNING: mac802154_txdesc_alloc failed: %d\n", ret); return ret; } From 192bacbd7fd46cee5789c6dabc7d3199ac3d93a2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 13:30:17 -0600 Subject: [PATCH 08/10] ieee802154 network driver now retries if ieee802154_req_data() returns EINTR. In clicker2-stm32 6LoWPAN configuration, increased the number of TX descriptors to match then number of IOBs. --- configs/clicker2-stm32/mrf24j40-6lowpan/defconfig | 2 +- wireless/ieee802154/Kconfig | 11 +++++++++-- wireless/ieee802154/mac802154_netdev.c | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig index 8759fc1248..76c738cd11 100644 --- a/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig +++ b/configs/clicker2-stm32/mrf24j40-6lowpan/defconfig @@ -1138,7 +1138,7 @@ CONFIG_WIRELESS=y CONFIG_WIRELESS_IEEE802154=y CONFIG_IEEE802154_DEFAULT_EADDR=0x00fade00deadbeef CONFIG_MAC802154_HPWORK=y -CONFIG_IEEE802154_NTXDESC=3 +CONFIG_IEEE802154_NTXDESC=32 CONFIG_IEEE802154_IND_PREALLOC=20 CONFIG_IEEE802154_IND_IRQRESERVE=10 CONFIG_IEEE802154_MACDEV=y diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index d06ed743c1..baf801b7e7 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -46,7 +46,14 @@ config IEEE802154_NTXDESC default 3 ---help--- Configured number of Tx descriptors. Default: 3 - + + When used with 6LoWPAN, the descriptor allocator runs on a work + and must avoid blocking if possible. Each frame will be provided in + an IOB and each TX frame will need a TX descriptor. So the safe + thing to do is set CONFIG_IEEE802154_NTXDESC to CONFIG_IOB_NBUFFERS. + Then there should be the maximum pre-allocated buffers for each + possible TX frame. + config IEEE802154_IND_PREALLOC int "Number of pre-allocated meta-data structures" default 20 @@ -75,7 +82,7 @@ config IEEE802154_IND_IRQRESERVE Non-interrupt logic will also first attempt to allocate from the general, pre-allocated structure pool. If that fails, it will dynamically allocate the meta data structure with an additional cost in performance. - + config IEEE802154_MACDEV bool "Character driver for IEEE 802.15.4 MAC layer" default n diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 5966532b88..b48c6afcaa 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -405,6 +405,7 @@ static int macnet_rxframe(FAR struct mac802154_maccb_s *maccb, if (!priv->md_bifup) { + wlwarn("WARNING: Dropped... Network is down\n"); return -ENETDOWN; } @@ -421,6 +422,8 @@ static int macnet_rxframe(FAR struct mac802154_maccb_s *maccb, if ((iob->io_data[iob->io_offset] & SIXLOWPAN_DISPATCH_NALP_MASK) == SIXLOWPAN_DISPATCH_NALP) { + wlwarn("WARNING: Dropped... Not a 6LoWPAN frame: %02x\n", + iob->io_data[iob->io_offset]); return -EINVAL; } @@ -1114,9 +1117,17 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, framelist = iob->io_flink; iob->io_flink = NULL; - /* Transfer the frame to the MAC */ + /* Transfer the frame to the MAC. mac802154_req_data will return + * -EINTR if a signal is received during certain phases of processing. + * In this context we just need to ignore -EINTR errors and try again. + */ + + do + { + ret = mac802154_req_data(priv->md_mac, meta, iob); + } + while (ret == -EINTR); - ret = mac802154_req_data(priv->md_mac, meta, iob); if (ret < 0) { wlerr("ERROR: mac802154_req_data failed: %d\n", ret); From d9f549121c0a67c1b34c6aaeefbea4da91139a22 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 14:27:22 -0600 Subject: [PATCH 09/10] ieee802154_req_data: Don't modify the IOB until we are certain that no EINTR errors will occur. Otherwise, the retry will fail --- configs/clicker2-stm32/README.txt | 3 +-- net/sixlowpan/sixlowpan_framelist.c | 10 ++++++++++ wireless/ieee802154/mac802154_data.c | 29 +++++++++++++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt index c016313636..260137c152 100644 --- a/configs/clicker2-stm32/README.txt +++ b/configs/clicker2-stm32/README.txt @@ -460,8 +460,7 @@ Configurations telnetd_daemon: ERROR: socket failure: 106 - 2017-06-20: I am get EINTR errors from the MAC layer when trying the - udpclient tries to send messages. Still under investigation. + 2017-06-20: Debug underway.. not yet functional. nsh: diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 226711af02..bf57aa5027 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -444,6 +444,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the first frame to the IOB queue */ + ninfo("Queuing frame io_len=%u io_offset=%u\n", + iob->io_len, iob->io_offset); + qhead = iob; qtail = iob; @@ -522,6 +525,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the next frame to the tail of the IOB queue */ + ninfo("Queuing frame io_len=%u io_offset=%u\n", + iob->io_len, iob->io_offset); + qtail->io_flink = iob; qtail = iob; @@ -544,6 +550,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* And submit the frame to the MAC */ + ninfo("Submitting framelist\n"); ret = sixlowpan_frame_submit(ieee, &meta, iob); if (ret < 0) { @@ -580,6 +587,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* And submit the frame to the MAC */ + ninfo("Submitting frame length=%u io_offset=%u\n", + iob->io_len, iob->io_offset); + ret = sixlowpan_frame_submit(ieee, &meta, iob); if (ret < 0) { diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index 0676c52103..12a664e5e4 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -82,12 +82,15 @@ int mac802154_req_data(MACHANDLE mac, uint8_t mhr_len = 3; int ret; + wlinfo("Received frame io_len=%u io_offset=%u\n", + frame->io_offset, frame->io_len); + /* Check the required frame size */ if (frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) - { - return -E2BIG; - } + { + return -E2BIG; + } /* Cast the first two bytes of the IOB to a uint16_t frame control field */ @@ -226,10 +229,9 @@ int mac802154_req_data(MACHANDLE mac, * here that created the header */ + wlinfo("mhr_len=%u\n", mhr_len); DEBUGASSERT(mhr_len == frame->io_offset); - frame->io_offset = 0; /* Set the offset to 0 to include the header */ - /* Allocate the txdesc, waiting if necessary, allow interruptions */ ret = mac802154_txdesc_alloc(priv, &txdesc, true); @@ -243,6 +245,16 @@ int mac802154_req_data(MACHANDLE mac, return ret; } + /* Set the offset to 0 to include the header ( we do not want to + * modify the frame until AFTER the last place that -EINTR could + * be returned and could generate a retry. Subsequent error returns + * are fatal and no retry should occur. + */ + + frame->io_offset = 0; + + /* Then initialize the TX descriptor */ + txdesc->conf->handle = meta->msdu_handle; txdesc->frame = frame; txdesc->frametype = IEEE802154_FRAME_DATA; @@ -269,7 +281,7 @@ int mac802154_req_data(MACHANDLE mac, */ ret = -ENOTSUP; - goto errout_with_sem; + goto errout_with_txdesc; } else { @@ -306,7 +318,7 @@ int mac802154_req_data(MACHANDLE mac, else { ret = -EINVAL; - goto errout_with_sem; + goto errout_with_txdesc; } } else @@ -327,6 +339,9 @@ int mac802154_req_data(MACHANDLE mac, return OK; +errout_with_txdesc: + /* REVISIT: Free TX descriptor, but preserve the IOB. */ + errout_with_sem: mac802154_givesem(&priv->exclsem); return ret; From cd8ac3f070e70cd74935b974a018336fa9fae572 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 20 Jun 2017 15:00:23 -0600 Subject: [PATCH 10/10] ieee802154 MAC: Free allocated TX descriptor if an error occurs after the descriptor has been allocated. --- net/sixlowpan/sixlowpan_framelist.c | 2 +- wireless/ieee802154/mac802154.c | 1 + wireless/ieee802154/mac802154_data.c | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index bf57aa5027..db420cbdd3 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -550,7 +550,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* And submit the frame to the MAC */ - ninfo("Submitting framelist\n"); + ninfo("Submitting frame\n"); ret = sixlowpan_frame_submit(ieee, &meta, iob); if (ret < 0) { diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index cfc59700da..70e44b68f5 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -130,6 +130,7 @@ static void mac802154_resetqueues(FAR struct ieee802154_privmac_s *priv) { sq_addlast((FAR sq_entry_t *)&priv->txdesc_pool[i], &priv->txdesc_queue); } + sem_init(&priv->txdesc_sem, 0, CONFIG_MAC802154_NTXDESC); /* Initialize the notifcation allocation pool */ diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index 12a664e5e4..6223cd6a03 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -340,7 +340,10 @@ int mac802154_req_data(MACHANDLE mac, return OK; errout_with_txdesc: - /* REVISIT: Free TX descriptor, but preserve the IOB. */ + /* Free TX the descriptor, but preserve the IOB. */ + + txdesc->frame = NULL; + mac802154_txdesc_free(priv, txdesc); errout_with_sem: mac802154_givesem(&priv->exclsem);