diff --git a/configs/sim/pf_ieee802154/defconfig b/configs/sim/pf_ieee802154/defconfig index a10f742ee19..9ed5a30ad51 100644 --- a/configs/sim/pf_ieee802154/defconfig +++ b/configs/sim/pf_ieee802154/defconfig @@ -2,7 +2,6 @@ # CONFIG_MMCSD_SPI is not set # CONFIG_NET_ETHERNET is not set # CONFIG_NET_IPv4 is not set -# CONFIG_NET_UDP_CHECKSUMS is not set # CONFIG_NSH_CMDOPT_DF_H is not set # CONFIG_SIM_NETDEV is not set CONFIG_ARCH_BOARD_SIM=y @@ -23,29 +22,10 @@ CONFIG_DEBUG_FEATURES=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DISABLE_POLL=y CONFIG_DRIVERS_WIRELESS=y -CONFIG_EXAMPLES_NETTEST_DAEMON_STACKSIZE=4096 -CONFIG_EXAMPLES_NETTEST_LOOPBACK=y -CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO=61616 -CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_1=0xfe80 -CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_6=0x00ff -CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_7=0xfe00 -CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_8=0xcda9 -CONFIG_EXAMPLES_NETTEST_STACKSIZE1=4096 -CONFIG_EXAMPLES_NETTEST=y CONFIG_EXAMPLES_NSH=y CONFIG_EXAMPLES_PFIEEE802154_STACKSIZE1=8192 CONFIG_EXAMPLES_PFIEEE802154_STACKSIZE2=8192 CONFIG_EXAMPLES_PFIEEE802154=y -CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_1=0xfe80 -CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_6=0x00ff -CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_7=0xfe00 -CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_8=0x1034 -CONFIG_EXAMPLES_UDPBLASTER_STACKSIZE=8192 -CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_1=0xfe80 -CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_6=0x00ff -CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_7=0xfe00 -CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_8=0xa9cd -CONFIG_EXAMPLES_UDPBLASTER=y CONFIG_EXPERIMENTAL=y CONFIG_FAT_LCNAMES=y CONFIG_FAT_LFN=y @@ -64,24 +44,13 @@ CONFIG_MTD_AT24XX=y CONFIG_MTD_AT25=y CONFIG_MTD_CONFIG=y CONFIG_MTD=y -CONFIG_NET_6LOWPAN_TCP_RECVWNDO=102 -CONFIG_NET_6LOWPAN=y -CONFIG_NET_BROADCAST=y CONFIG_NET_HOSTNAME="SAMV71-XULT" CONFIG_NET_IEEE802154=y -CONFIG_NET_IEEE802154_NCONNS=4 -CONFIG_NET_IPv6=y CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y -CONFIG_NET_TCP_WRITE_BUFFERS=y -CONFIG_NET_TCP=y -CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_UDP=y CONFIG_NET=y -CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDEV_PHY_IOCTL=y CONFIG_NETDEV_STATISTICS=y -CONFIG_NETDEV_TELNET=y CONFIG_NETDEVICES=y CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 diff --git a/drivers/net/tun.c b/drivers/net/tun.c index d00bbaa1ef1..1bef4351cc5 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -38,7 +38,6 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET) && defined(CONFIG_NET_TUN) #include #include @@ -55,19 +54,22 @@ #include +#include + +#ifdef CONFIG_NET_PKT +# include +#endif + #include #include #include #include #include #include +#include #include -#include - -#ifdef CONFIG_NET_PKT -# include -#endif +#if defined(CONFIG_NET) && defined(CONFIG_NET_TUN) /**************************************************************************** * Pre-processor Definitions @@ -1222,6 +1224,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv = filep->f_priv; strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ); +#ifdef CONFIG_NET_ETHERNET if ((ifr->ifr_flags & IFF_MASK) == IFF_TAP) { /* TAP device -> handling raw Ethernet packets @@ -1231,6 +1234,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv->dev.d_llhdrlen = ETH_HDRLEN; } else if ((ifr->ifr_flags & IFF_MASK) == IFF_TUN) +#endif { /* TUN device -> handling an application data stream * -> no header diff --git a/drivers/wireless/spirit/drivers/spirit_netdev.c b/drivers/wireless/spirit/drivers/spirit_netdev.c index b53f29a8472..dc2193db221 100644 --- a/drivers/wireless/spirit/drivers/spirit_netdev.c +++ b/drivers/wireless/spirit/drivers/spirit_netdev.c @@ -126,7 +126,7 @@ #include #include #include -#include +#include #include #include @@ -352,7 +352,7 @@ static int spirit_get_mhrlen(FAR struct radio_driver_s *netdev, static int spirit_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist); static int spirit_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties); + FAR struct radiodev_properties_s *properties); /* Initialization */ @@ -2141,8 +2141,8 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, { FAR struct radio_driver_s *radio = (FAR struct radio_driver_s *)dev; - FAR struct sixlowpan_properties_s *props = - (FAR struct sixlowpan_properties_s *)&cmddata->pifr_props; + FAR struct radiodev_properties_s *props = + (FAR struct radiodev_properties_s *)&cmddata->pifr_props; ret = spirit_properties(radio, props); } @@ -2373,10 +2373,10 @@ static int spirit_req_data(FAR struct radio_driver_s *netdev, ****************************************************************************/ static int spirit_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties) + FAR struct radiodev_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); - memset(properties, 0, sizeof(struct sixlowpan_properties_s)); + memset(properties, 0, sizeof(struct radiodev_properties_s)); /* General */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index fc27f6b7b73..ac30990ce05 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -182,7 +182,7 @@ struct netdev_statistics_s }; #endif -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) /* This structure is used to represent addresses of varying length. This * structure is used to represent the address assigned to a radio. */ @@ -236,7 +236,9 @@ struct net_driver_s uint16_t d_recvwndo; /* TCP receive window size */ #endif -#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) +#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) || \ + defined(CONFIG_NET_IEEE802154) + /* Link layer address */ union @@ -251,9 +253,9 @@ struct net_driver_s /* The address assigned to an IEEE 802.15.4 or generic packet radio. */ struct netdev_varaddr_s radio; -#endif /* CONFIG_NET_6LOWPAN */ +#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */ } d_mac; -#endif /* CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN */ +#endif /* CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */ /* Network identity */ @@ -463,8 +465,9 @@ int ipv6_input(FAR struct net_driver_s *dev); #endif #ifdef CONFIG_NET_6LOWPAN -struct radio_driver_s; /* See sixlowpan.h */ -struct iob_s; /* See iob.h */ +struct radio_driver_s; /* Forward reference. See radiodev.h */ +struct iob_s; /* Forward reference See iob.h */ + int sixlowpan_input(FAR struct radio_driver_s *ieee, FAR struct iob_s *framelist, FAR const void *metadata); #endif diff --git a/include/nuttx/net/radiodev.h b/include/nuttx/net/radiodev.h new file mode 100644 index 00000000000..c796cb2d5eb --- /dev/null +++ b/include/nuttx/net/radiodev.h @@ -0,0 +1,299 @@ +/**************************************************************************** + * include/nuttx/net/radiodev.h + * + * Copyright (C) 2017, Gregory Nutt, all rights reserved + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_RADIODEV_H +#define __INCLUDE_NUTTX_NET_RADIODEV_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Different packet radios may have different properties. If there are + * multiple packet radios, then those properties have to be queried at + * run time. This information is provided to the 6LoWPAN network via the + * following structure. + */ + +struct radiodev_properties_s +{ + uint8_t sp_addrlen; /* Length of an address */ + uint8_t sp_pktlen; /* Fixed packet/frame size (up to 255) */ + struct netdev_varaddr_s sp_mcast; /* Multicast address */ + struct netdev_varaddr_s sp_bcast; /* Broadcast address */ +#ifdef CONFIG_NET_STARPOINT + struct netdev_varaddr_s sp_hubnode; /* Address of the hub node in a star */ +#endif +}; + +/* The device structure for radio network device differs from the standard + * Ethernet MAC device structure. The main reason for this difference is + * that fragmentation must be supported. + * + * The radio network driver does not use the d_buf packet buffer directly. + * Rather, it uses a list smaller frame buffers. + * + * - The packet fragment data is provided in an IOB in the via the + * r_req_data() interface method each time that the radio needs to + * send more data. The length of the frame is provided in the io_len + * field of the IOB. + * + * In this case, the d_buf is not used at all and, if fact, may be + * NULL. + * + * - Received frames are provided by radio network driver to the network + * via an IOB parameter in the sixlowpan_input() pr ieee802154_input() + * interface. The length of the frame is io_len. + * + * - 6LoWPAN frames and will be uncompressed and possibly reassembled in + * the d_buf; d_len will hold the size of the reassembled packet. + * + * In this case, a d_buf of size CONFIG_NET_6LOWPAN_MTU must be provided. + * + * This is accomplished by "inheriting" the standard 'struct net_driver_s' + * and appending the frame buffer as well as other metadata needed to + * manage the fragmentation. 'struct radio_driver_s' is cast + * compatible with 'struct net_driver_s' when dev->d_lltype == + * NET_LL_IEEE802154 or dev->d_lltype == NET_LL_PKTRADIO. + * + * The radio network driver has reponsibility for initializing this + * structure. In general, all fields must be set to NULL. In addition: + * + * 1. On a TX poll, the radio network driver should provide its driver + * structure. During the course of the poll, the networking layer may + * generate outgoing frames. These frames will by provided to the MAC + * driver via the req_data() method. + * + * After sending each frame through the radio, the MAC driver must + * return the frame to the pool of free IOBs using the iob_free(). + * + * 2. When receiving data both buffers must be provided for 6LoWPAN + * frames; PF_IEEE802154 frames do not require the d_buf. + * + * The radio driver should receive the frame data directly into the + * payload area of an IOB frame structure. That IOB structure may be + * obtained using the iob_alloc() function. + * + * For 6LoWPAN, the larger dev.d_buf must have a size of at least the + * advertised MTU of the protocol, CONFIG_NET_6LOWPAN_MTU, plus + * CONFIG_NET_GUARDSIZE. If fragmentation is enabled, then the logical + * packet size may be significantly larger than the size of the frame + * buffer. The dev.d_buf is used for de-compressing each frame and + * reassembling any fragmented packets to create the full input packet + * that is provided to the application. + * + * The MAC driver should then inform the network of the reciptor of a + * frame by calling sixlowpan_input() or ieee802154_input(). That + * single frame (or, perhaps, list of frames) should be provided as + * second argument of that call. + * + * The network will free the IOB by calling iob_free after it has + * processed the incoming frame. As a complexity, the result of + * receiving a frame may be that the network may respond provide an + * outgoing frames in the via a nested call to the req_data() method. + */ + +struct iob_s; /* Forward reference */ + +struct radio_driver_s +{ + /* This definitiona must appear first in the structure definition to + * assure cast compatibility. + */ + + struct net_driver_s r_dev; + + /* Radio network driver-specific definitions follow. */ + +#ifdef CONFIG_WIRELESS_IEEE802154 + /* The msdu_handle is basically an id for the frame. The standard just + * says that the next highest layer should determine it. It is used in + * three places + * + * 1. When you do that data request + * 2. When the transmission is complete, the conf_data is called with + * that handle so that the user can be notified of the frames success/ + * failure + * 3. For a req_purge, to basically "cancel" the transaction. This is + * often particularly useful on a coordinator that has indirect data + * waiting to be requested from another device + * + * Here is a simple frame counter. + */ + + uint8_t r_msdu_handle; +#endif + +#if CONFIG_NET_6LOWPAN_FRAG + /* Fragmentation Support *************************************************/ + /* Fragmentation is handled frame by frame and requires that certain + * state information be retained from frame to frame. + */ + + /* r_dgramtag. Datagram tag to be put in the header of the set of + * fragments. It is used by the recipient to match fragments of the + * same payload. + * + * This is the sender's copy of the tag. It is incremented after each + * fragmented packet is sent so that it will be unique to that + * sequence fragmentation. Its value is then persistent, the values of + * other fragmentation variables are valid on during a single + * fragmentation sequence (while r_accumlen > 0) + */ + + uint16_t r_dgramtag; + + /* r_reasstag. Each frame in the reassembly has a tag. That tag must + * match the reassembly tag in the fragments being merged. + * + * This is the same tag as r_dgramtag but is saved on the receiving + * side to match all of the fragments of the packet. + */ + + uint16_t r_reasstag; + + /* r_pktlen. The total length of the IPv6 packet to be re-assembled in + * d_buf. Used to determine when the re-assembly is complete. + */ + + uint16_t r_pktlen; + + /* The current accumulated length of the packet being received in d_buf. + * Included IPv6 and protocol headers. Currently used only to determine + * there is a fragmentation sequence in progress. + */ + + uint16_t r_accumlen; + + /* r_boffset. Offset to the beginning of data in d_buf. As each fragment + * is received, data is placed at an appriate offset added to this. + */ + + uint16_t r_boffset; + + /* The source MAC address of the fragments being merged */ + + struct netdev_varaddr_s r_fragsrc; + + /* That time at which reassembly was started. If the elapsed time + * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will + * be cancelled. + */ + + systime_t r_time; +#endif /* CONFIG_NET_6LOWPAN_FRAG */ + + /* MAC network driver callback functions **********************************/ + /************************************************************************** + * Name: r_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Obfuscated metadata structure needed to recreate the + * radio MAC header + * + * Returned Value: + * A non-negative MAC headeer length is returned on success; a negated + * errno value is returned on any failure. + * + **************************************************************************/ + + CODE int (*r_get_mhrlen)(FAR struct radio_driver_s *netdev, + FAR const void *meta); + + /************************************************************************** + * Name: r_req_data + * + * Description: + * Requests the transfer of a list of frames to the MAC. + * + * Input parameters: + * netdev - The network device that will mediate the MAC interface + * meta - Obfuscated metadata structure needed to create the radio + * MAC header + * framelist - Head of a list of frames to be transferred. + * + * Returned Value: + * Zero (OK) returned on success; a negated errno value is returned on + * any failure. + * + **************************************************************************/ + + CODE int (*r_req_data)(FAR struct radio_driver_s *netdev, + FAR const void *meta, FAR struct iob_s *framelist); + + /************************************************************************** + * Name: r_properties + * + * Description: + * Different packet radios may have different properties. If there are + * multiple packet radios, then those properties have to be queried at + * run time. This information is provided to the 6LoWPAN network via the + * following structure. + * + * Input parameters: + * netdev - The network device to be queried + * properties - Location where radio properities will be returned. + * + * Returned Value: + * Zero (OK) returned on success; a negated errno value is returned on + * any failure. + * + **************************************************************************/ + + CODE int (*r_properties)(FAR struct radio_driver_s *netdev, + FAR struct radiodev_properties_s *properties); +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */ +#endif /* __INCLUDE_NUTTX_NET_RADIODEV_H */ diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index a951f2757c1..4eab7cc48a6 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -54,10 +54,6 @@ #include -#include -#include -#include - #ifdef CONFIG_NET_6LOWPAN /**************************************************************************** @@ -341,246 +337,6 @@ (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ (((a)[7] & HTONS(0xff00)) == 0x0000)) -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* Different packet radios may have different properties. If there are - * multiple packet radios, then those properties have to be queried at - * run time. This information is provided to the 6LoWPAN network via the - * following structure. - */ - -struct sixlowpan_properties_s -{ - uint8_t sp_addrlen; /* Length of an address */ - uint8_t sp_pktlen; /* Fixed packet/frame size (up to 255) */ - struct netdev_varaddr_s sp_mcast; /* Multicast address */ - struct netdev_varaddr_s sp_bcast; /* Broadcast address */ -#ifdef CONFIG_NET_STARPOINT - struct netdev_varaddr_s sp_hubnode; /* Address of the hub node in a star */ -#endif -}; - -/* The device structure for radio network device differs from the standard - * Ethernet MAC device structure. The main reason for this difference is - * that fragmentation must be supported. - * - * The radio network driver does not use the d_buf packet buffer directly. - * Rather, it uses a list smaller frame buffers. - * - * - The packet fragment data is provided in an IOB in the via the - * r_req_data() interface method each time that the radio needs to - * send more data. The length of the frame is provided in the io_len - * field of the IOB. - * - * In this case, the d_buf is not used at all and, if fact, may be - * NULL. - * - * - Received frames are provided by radio network driver to the network - * via an IOB parameter in the sixlowpan_submit() interface. The - * length of the frawme is io_len and will be uncompressed and possibly - * reassembled in the d_buf; d_len will hold the size of the - * reassembled packet. - * - * In this case, a d_buf of size CONFIG_NET_6LOWPAN_MTU must be provided. - * - * This is accomplished by "inheriting" the standard 'struct net_driver_s' - * and appending the frame buffer as well as other metadata needed to - * manage the fragmentation. 'struct radio_driver_s' is cast - * compatible with 'struct net_driver_s' when dev->d_lltype == - * NET_LL_IEEE802154 or dev->d_lltype == NET_LL_PKTRADIO. - * - * The radio network driver has reponsibility for initializing this - * structure. In general, all fields must be set to NULL. In addition: - * - * 1. On a TX poll, the radio network driver should provide its driver - * structure. During the course of the poll, the networking layer may - * generate outgoing frames. These frames will by provided to the MAC - * driver via the req_data() method. - * - * After sending each frame through the radio, the MAC driver must - * return the frame to the pool of free IOBs using the iob_free(). - * - * 2. When receiving data both buffers must be provided: - * - * The radio driver should receive the frame data directly into the - * payload area of an IOB frame structure. That IOB structure may be - * obtained using the iob_alloc() function. - * - * The larger dev.d_buf must have a size of at least the advertised MTU - * of the protocol, CONFIG_NET_6LOWPAN_MTU, plus CONFIG_NET_GUARDSIZE. - * If fragmentation is enabled, then the logical packet size may be - * significantly larger than the size of the frame buffer. The dev.d_buf - * is used for de-compressing each frame and reassembling any fragmented - * packets to create the full input packet that is provided to the - * application. - * - * The MAC driver should then inform the network of the by calling - * sixlowpan_input(). That single frame (or, perhaps, list of frames) - * should be provided as second argument of that call. - * - * The network will free the IOB by calling iob_free after it has - * processed the incoming frame. As a complexity, the result of - * receiving a frame may be that the network may respond provide an - * outgoing frames in the via a nested calle to the req_data() method. - */ - -struct iob_s; /* Forward reference */ - -struct radio_driver_s -{ - /* This definitiona must appear first in the structure definition to - * assure cast compatibility. - */ - - struct net_driver_s r_dev; - - /* Radio network driver-specific definitions follow. */ - -#ifdef CONFIG_WIRELESS_IEEE802154 - /* The msdu_handle is basically an id for the frame. The standard just - * says that the next highest layer should determine it. It is used in - * three places - * - * 1. When you do that data request - * 2. When the transmission is complete, the conf_data is called with - * that handle so that the user can be notified of the frames success/ - * failure - * 3. For a req_purge, to basically "cancel" the transaction. This is - * often particularly useful on a coordinator that has indirect data - * waiting to be requested from another device - * - * Here is a simple frame counter. - */ - - uint8_t r_msdu_handle; -#endif - -#if CONFIG_NET_6LOWPAN_FRAG - /* Fragmentation Support *************************************************/ - /* Fragmentation is handled frame by frame and requires that certain - * state information be retained from frame to frame. - */ - - /* r_dgramtag. Datagram tag to be put in the header of the set of - * fragments. It is used by the recipient to match fragments of the - * same payload. - * - * This is the sender's copy of the tag. It is incremented after each - * fragmented packet is sent so that it will be unique to that - * sequence fragmentation. Its value is then persistent, the values of - * other fragmentation variables are valid on during a single - * fragmentation sequence (while r_accumlen > 0) - */ - - uint16_t r_dgramtag; - - /* r_reasstag. Each frame in the reassembly has a tag. That tag must - * match the reassembly tag in the fragments being merged. - * - * This is the same tag as r_dgramtag but is saved on the receiving - * side to match all of the fragments of the packet. - */ - - uint16_t r_reasstag; - - /* r_pktlen. The total length of the IPv6 packet to be re-assembled in - * d_buf. Used to determine when the re-assembly is complete. - */ - - uint16_t r_pktlen; - - /* The current accumulated length of the packet being received in d_buf. - * Included IPv6 and protocol headers. Currently used only to determine - * there is a fragmentation sequence in progress. - */ - - uint16_t r_accumlen; - - /* r_boffset. Offset to the beginning of data in d_buf. As each fragment - * is received, data is placed at an appriate offset added to this. - */ - - uint16_t r_boffset; - - /* The source MAC address of the fragments being merged */ - - struct netdev_varaddr_s r_fragsrc; - - /* That time at which reassembly was started. If the elapsed time - * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will - * be cancelled. - */ - - systime_t r_time; -#endif /* CONFIG_NET_6LOWPAN_FRAG */ - - /* MAC network driver callback functions **********************************/ - /************************************************************************** - * Name: r_get_mhrlen - * - * Description: - * Calculate the MAC header length given the frame meta-data. - * - * Input parameters: - * netdev - The networkd device that will mediate the MAC interface - * meta - Obfuscated metadata structure needed to recreate the - * radio MAC header - * - * Returned Value: - * A non-negative MAC headeer length is returned on success; a negated - * errno value is returned on any failure. - * - **************************************************************************/ - - CODE int (*r_get_mhrlen)(FAR struct radio_driver_s *netdev, - FAR const void *meta); - - /************************************************************************** - * Name: r_req_data - * - * Description: - * Requests the transfer of a list of frames to the MAC. - * - * Input parameters: - * netdev - The network device that will mediate the MAC interface - * meta - Obfuscated metadata structure needed to create the radio - * MAC header - * framelist - Head of a list of frames to be transferred. - * - * Returned Value: - * Zero (OK) returned on success; a negated errno value is returned on - * any failure. - * - **************************************************************************/ - - CODE int (*r_req_data)(FAR struct radio_driver_s *netdev, - FAR const void *meta, FAR struct iob_s *framelist); - - /************************************************************************** - * Name: r_properties - * - * Description: - * Different packet radios may have different properties. If there are - * multiple packet radios, then those properties have to be queried at - * run time. This information is provided to the 6LoWPAN network via the - * following structure. - * - * Input parameters: - * netdev - The network device to be queried - * properties - Location where radio properities will be returned. - * - * Returned Value: - * Zero (OK) returned on success; a negated errno value is returned on - * any failure. - * - **************************************************************************/ - - CODE int (*r_properties)(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties); -}; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -651,6 +407,9 @@ struct radio_driver_s * ****************************************************************************/ +struct radio_driver_s; /* Forward reference. See radiodev.h */ +struct iob_s; /* Forward reference See iob.h */ + int sixlowpan_input(FAR struct radio_driver_s *radio, FAR struct iob_s *framelist, FAR const void *metadata); diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index df17b3bcd1d..22e26bd07fb 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -51,7 +51,7 @@ #include #include -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) # include #endif @@ -1581,7 +1581,7 @@ union ieee802154_macarg_u /* To be determined */ /* MAC802154IOC_MLME_CALIBRATE_REQUEST */ }; -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) /* For the case of network IOCTLs, the network IOCTL to the MAC network * driver will include a device name like "wpan0" as the destination of * the IOCTL command. diff --git a/include/nuttx/wireless/pktradio.h b/include/nuttx/wireless/pktradio.h index 6ec742bec39..d4f405b4142 100644 --- a/include/nuttx/wireless/pktradio.h +++ b/include/nuttx/wireless/pktradio.h @@ -112,8 +112,8 @@ struct pktradio_addr_s * run time. This information is provided to the 6LoWPAN network via the * following structure. * - * NOTE: This MUST be the same as the struct sixlowpan_properties_s as - * defined in sixlowpan.h. It is duplicated here with a different name in + * NOTE: This MUST be the same as the struct radiodev_properties_s as + * defined in radiodev.h. It is duplicated here with a different name in * order to avoid circular header file inclusion. */ diff --git a/net/Kconfig b/net/Kconfig index 615cebee20f..48163d26bfa 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -108,7 +108,7 @@ config NET_GUARDSIZE endmenu # Driver buffer configuration -menu "Data link support" +menu "Link layer support" config NET_USER_DEVFMT bool "User provided devfmt" @@ -125,15 +125,10 @@ config NET_ETHERNET no need to define anything special in the configuration file to use Ethernet -- it is the default). -config NET_6LOWPAN - bool "6LoWPAN support" - default n - select NETDEV_IOCTL - select NET_HAVE_STAR - depends on NET_IPv6 - ---help--- - Enable support for Low power Wireless Personal Area Networking (6LoWPAN) - for IEEE 802.15.4 or other packet radios. +#menu "IEEE 802.15.4" +# depends on WIRELESS_IEEE802154 +# +#endmenu # IEEE 802.15.4 config NET_LOOPBACK bool "Local loopback" @@ -141,7 +136,7 @@ config NET_LOOPBACK ---help--- Add support for the local network loopback device, lo. -config NET_SLIP +menuconfig NET_SLIP bool "SLIP support" default n ---help--- @@ -186,7 +181,7 @@ config SLIP_DEFPRIO endif # NET_SLIP -config NET_TUN +menuconfig NET_TUN bool "TUN Virtual Network Device support" default n select ARCH_HAVE_NETDEV_STATISTICS @@ -262,13 +257,24 @@ config NET_IPv4 ---help--- Build in support for IPv4. -menuconfig NET_IPv6 +config NET_IPv6 bool "IPv6" default n ---help--- Build in support for IPv6. source "net/neighbor/Kconfig" + +menuconfig NET_6LOWPAN + bool "6LoWPAN support" + default n + select NETDEV_IOCTL + select NET_HAVE_STAR + depends on NET_IPv6 + ---help--- + Enable support for Low power Wireless Personal Area Networking (6LoWPAN) + for IEEE 802.15.4 or other packet radios. + source "net/sixlowpan/Kconfig" source "net/ipforward/Kconfig" diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig index f32844ccfe4..531677eeb53 100644 --- a/net/ieee802154/Kconfig +++ b/net/ieee802154/Kconfig @@ -8,7 +8,7 @@ menu "IEEE 802.15.4 socket support" config NET_IEEE802154 bool "IEEE 802.15.4 socket support" default n - depends on NET_IPv6 && WIRELESS_IEEE802154 + depends on WIRELESS_IEEE802154 select NETDEV_IOCTL ---help--- Enable support for raw, IEEE 802.15.4 sockets. @@ -22,6 +22,17 @@ config NET_IEEE802154 if NET_IEEE802154 +config NET_IEEE802154_FRAMELEN + int "IEEE802.15.4 Frame Length" + default 127 + range 1 999999 + ---help--- + For standard IEEE 802.15.4 radios, this should always be 127 bytes. + However, some IEEE 802.15.4 radios may non-standard frame lengths. + + This setting is currently used only for detection data transfers + that would exceed the radio frame length. + config NET_IEEE802154_NCONNS int "Max IEEE 802.15.4 sockets" default 4 diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h index 35641acdc67..1daa61f48b1 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/ieee802154/ieee802154.h @@ -64,6 +64,32 @@ #define IEEE802154_POOL_PREALLOCATED 0 #define IEEE802154_POOL_DYNAMIC 1 +/* Frame size */ + +/* This maximum size of an IEEE802.15.4 frame. Certain, non-standard + * devices may exceed this value, however. + */ + +#define IEEE802154_MAC_STDFRAME 127 + +/* Space for a two byte FCS must be reserved at the end of the frame */ + +#define IEEE802154_MAC_FCSSIZE 2 + +/* This, then, is the usable size of the frame... + * REVISIT: Too many frame length definitions + */ + +#if defined(CONFIG_NET_6LOWPAN_FRAMELEN) +# define IEEE802_MAX_FRAMELEN CONFIG_NET_6LOWPAN_FRAMELEN +#elif defined(CONFIG_NET_IEEE802154_FRAMELEN) +# define IEEE802_MAX_FRAMELEN CONFIG_NET_IEEE802154_FRAMELEN +#else +# define IEEE802_MAX_FRAMELEN IEEE802154_MAC_STDFRAME +#endif + +#define IEEE802154_FRAMELEN (IEEE802_MAX_FRAMELEN - IEEE802154_MAC_FCSSIZE) + /**************************************************************************** * Public Type Definitions ****************************************************************************/ @@ -126,7 +152,7 @@ EXTERN const struct sock_intf_s g_ieee802154_sockif; ****************************************************************************/ struct ieee802154_data_ind_s; /* Forward reference */ -struct radio_driver_s; /* Forward reference */ +struct radio_driver_s; /* Forward reference */ struct net_driver_s; /* Forward reference */ struct eth_hdr_s; /* Forward reference */ struct socket; /* Forward reference */ diff --git a/net/ieee802154/ieee802154_callback.c b/net/ieee802154/ieee802154_callback.c index 18538cef360..48eefd4580c 100644 --- a/net/ieee802154/ieee802154_callback.c +++ b/net/ieee802154/ieee802154_callback.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include "devif/devif.h" diff --git a/net/ieee802154/ieee802154_finddev.c b/net/ieee802154/ieee802154_finddev.c index 8cf41544e13..477328bc078 100644 --- a/net/ieee802154/ieee802154_finddev.c +++ b/net/ieee802154/ieee802154_finddev.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include "netdev/netdev.h" diff --git a/net/ieee802154/ieee802154_input.c b/net/ieee802154/ieee802154_input.c index c17ed82c869..3e4846ffdd5 100644 --- a/net/ieee802154/ieee802154_input.c +++ b/net/ieee802154/ieee802154_input.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include "devif/devif.h" diff --git a/net/ieee802154/ieee802154_poll.c b/net/ieee802154/ieee802154_poll.c index 9e8da42f283..f46f6611b4c 100644 --- a/net/ieee802154/ieee802154_poll.c +++ b/net/ieee802154/ieee802154_poll.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include "devif/devif.h" diff --git a/net/ieee802154/ieee802154_recvfrom.c b/net/ieee802154/ieee802154_recvfrom.c index 9d06700afc1..83dd6b74dee 100644 --- a/net/ieee802154/ieee802154_recvfrom.c +++ b/net/ieee802154/ieee802154_recvfrom.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include "netdev/netdev.h" diff --git a/net/ieee802154/ieee802154_sendto.c b/net/ieee802154/ieee802154_sendto.c index a125bb1bfa0..7941df8daff 100644 --- a/net/ieee802154/ieee802154_sendto.c +++ b/net/ieee802154/ieee802154_sendto.c @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include #include @@ -334,8 +334,8 @@ static uint16_t ieee802154_sendto_interrupt(FAR struct net_driver_s *dev, * MAC header. */ - DEBUGASSERT(CONFIG_NET_6LOWPAN_FRAMELEN <= CONFIG_IOB_BUFSIZE); - if (pstate->is_buflen + hdrlen > CONFIG_IOB_BUFSIZE) + DEBUGASSERT(CONFIG_NET_IEEE802154_FRAMELEN <= CONFIG_IOB_BUFSIZE); + if (pstate->is_buflen + hdrlen > IEEE802154_FRAMELEN) { nerr("ERROR: User buffer will not fit into the frame: %u > %u\n", (unsigned int)(pstate->is_buflen + hdrlen), diff --git a/net/ieee802154/ieee802154_sockif.c b/net/ieee802154/ieee802154_sockif.c index c8bf2767e0e..62cd1c5de26 100644 --- a/net/ieee802154/ieee802154_sockif.c +++ b/net/ieee802154/ieee802154_sockif.c @@ -48,6 +48,7 @@ #include #include +#include #include #include diff --git a/net/ipforward/ipv6_forward.c b/net/ipforward/ipv6_forward.c index 81cca68956d..b2fea28f4ac 100644 --- a/net/ipforward/ipv6_forward.c +++ b/net/ipforward/ipv6_forward.c @@ -151,7 +151,6 @@ static int ipv6_hdrsize(FAR struct ipv6_hdr_s *ipv6) * ****************************************************************************/ -#ifdef CONFIG_NET_6LOWPAN static int ipv6_decr_ttl(FAR struct ipv6_hdr_s *ipv6) { int ttl = (int)ipv6->ttl - 1; @@ -179,7 +178,6 @@ static int ipv6_decr_ttl(FAR struct ipv6_hdr_s *ipv6) return ttl; } -#endif /**************************************************************************** * Name: ipv6_packet_conversion diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index ff38ed0e0d2..37d11c8807e 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -57,6 +57,7 @@ #include #include +#include #include #ifdef CONFIG_NET_6LOWPAN @@ -866,7 +867,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd, dev->d_lltype == NET_LL_PKTRADIO) { FAR struct radio_driver_s *radio; - struct sixlowpan_properties_s properties; + struct radiodev_properties_s properties; /* Get the radio properties */ diff --git a/net/netdev/netdev_lladdrsize.c b/net/netdev/netdev_lladdrsize.c index 10fa3460145..e07586ce29a 100644 --- a/net/netdev/netdev_lladdrsize.c +++ b/net/netdev/netdev_lladdrsize.c @@ -47,6 +47,7 @@ #include #include +#include #include #include "netdev/netdev.h" @@ -76,7 +77,7 @@ static inline int netdev_pktradio_addrlen(FAR struct net_driver_s *dev) { FAR struct radio_driver_s *radio = (FAR struct radio_driver_s *)dev; - struct sixlowpan_properties_s properties; + struct radiodev_properties_s properties; int ret; DEBUGASSERT(radio != NULL && radio->r_properties != NULL); diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index a87942e6481..2f9de8a3856 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -214,13 +214,15 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) break; #endif -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) case NET_LL_IEEE802154: /* IEEE 802.15.4 MAC */ case NET_LL_PKTRADIO: /* Non-IEEE 802.15.4 packet radio */ dev->d_llhdrlen = 0; +#ifdef CONFIG_NET_6LOWPAN dev->d_mtu = CONFIG_NET_6LOWPAN_MTU; #ifdef CONFIG_NET_TCP dev->d_recvwndo = CONFIG_NET_6LOWPAN_TCP_RECVWNDO; +#endif #endif devfmt = NETDEV_WPAN_FORMAT; break; diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 2b3175d3ddf..0a363597bf0 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -3,8 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -menu "6LoWPAN Configuration" - depends on NET_6LOWPAN +if NET_6LOWPAN config NET_6LOWPAN_FRAG bool "6LoWPAN Fragmentation" @@ -14,12 +13,13 @@ config NET_6LOWPAN_FRAG used or not. Fragmentation is on by default. config NET_6LOWPAN_FRAMELEN - int "IEEE802.15.4 MAC Frame Length" + int "Max Radio Frame Size" default 127 range 1 999999 ---help--- - Some wireless devices may use non-standard frame lengths. This - setting should never be smaller than 127. + Wireless devices use a variety of frame sizes. For IEEE 802.15.4 + radios, this should be 127 bytes. However, some IEEE 802.15.4 + radios may support non-standard frame lengths. choice prompt "6LoWPAN Compression" @@ -199,4 +199,4 @@ config NET_6LOWPAN_DUMPBUFFER of the 6LoWPAN logic. This will generate a large volume of data if selected. -endmenu # 6LoWPAN Configuration +endif # NET_6LOWPAN diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 96022156689..5df2103d4b7 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -55,6 +55,7 @@ #include #include +#include #include #include "sixlowpan/sixlowpan_internal.h" diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 8a253e876cc..95d44d85597 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -46,6 +46,7 @@ #include #include "nuttx/net/net.h" +#include "nuttx/net/radiodev.h" #include "nuttx/wireless/ieee802154/ieee802154_mac.h" #include "sixlowpan/sixlowpan_internal.h" diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 1f7f1fb741b..85b41a0ff65 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -62,6 +62,7 @@ #include #include +#include #include #include "sixlowpan/sixlowpan_internal.h" diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index b732ef857d2..4daa4cabb06 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -54,6 +54,7 @@ #include #include +#include #include "sixlowpan/sixlowpan_internal.h" #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 diff --git a/net/sixlowpan/sixlowpan_icmpv6send.c b/net/sixlowpan/sixlowpan_icmpv6send.c index 179907f8359..2bb7a46165b 100644 --- a/net/sixlowpan/sixlowpan_icmpv6send.c +++ b/net/sixlowpan/sixlowpan_icmpv6send.c @@ -43,6 +43,7 @@ #include #include +#include #include #include "icmpv6/icmpv6.h" diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 6b4177a8ace..a5d14ed9644 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -59,6 +59,7 @@ #endif #include "nuttx/net/netdev.h" +#include "nuttx/net/radiodev.h" #include "nuttx/net/ip.h" #include "nuttx/net/icmpv6.h" #include "nuttx/net/sixlowpan.h" diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 6909a81ff9f..a65666880f1 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -233,7 +233,7 @@ extern uint8_t g_frame_hdrlen; ****************************************************************************/ struct net_driver_s; /* Forward reference */ -struct radio_driver_s; /* Forward reference */ +struct radio_driver_s; /* Forward reference */ struct devif_callback_s; /* Forward reference */ struct ipv6_hdr_s; /* Forward reference */ struct netdev_varaddr_s; /* Forward reference */ diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index a097a77f04e..3f7cface202 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -47,6 +47,7 @@ #include #include #include +#include #include "netdev/netdev.h" #include "devif/devif.h" diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 77f517e1313..d5b11d23d93 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -46,6 +46,7 @@ #include "nuttx/semaphore.h" #include "nuttx/net/netdev.h" +#include "nuttx/net/radiodev.h" #include "nuttx/net/netstats.h" #include "netdev/netdev.h" diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 818f5bfb6c7..be7dfce581b 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -46,6 +46,7 @@ #include #include "nuttx/net/netdev.h" +#include "nuttx/net/radiodev.h" #include "nuttx/net/netstats.h" #include "netdev/netdev.h" diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index c3415374575..120db500598 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -54,6 +54,7 @@ #include #include +#include #include #include #include @@ -192,7 +193,7 @@ int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio, const net_ipv6addr_t ipaddr, FAR struct netdev_varaddr_s *destaddr) { - struct sixlowpan_properties_s properties; + struct radiodev_properties_s properties; int ret; #ifdef CONFIG_NET_STARPOINT diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index c5381c7afd3..cf96b166169 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -165,7 +165,7 @@ endif # IEEE802154_MACDEV config IEEE802154_NETDEV bool "IEEE802154 6LoWPAN Network Device" default n - depends on NET_6LOWPAN && NET_IPv6 + depends on NET_6LOWPAN || NET_IEEE802154 select ARCH_HAVE_NETDEV_STATISTICS ---help--- Add support for the IEEE802.15.4 6LoWPAN network device built on @@ -224,7 +224,7 @@ endif # IEEE802154_NETDEV config IEEE802154_LOOPBACK bool "IEEE802154 6LoWPAN Loopback" default n - depends on NET_6LOWPAN && NET_IPv6 + depends on NET_6LOWPAN || NET_IEEE802154 select ARCH_HAVE_NETDEV_STATISTICS ---help--- Add support for the IEEE802.15.4 6LoWPAN Loopback test device. diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index a4c96d9414b..0c32c4c683d 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,26 @@ # endif #endif +/* Preferred address size */ + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR +# define LO_ADDRSIZE IEEE802154_EADDRSIZE +#else +# define LO_ADDRSIZE IEEE802154_SADDRSIZE +#endif + +/* Frame size + * REVISIT: Too many frame length definitions + */ + +#if defined(CONFIG_NET_6LOWPAN_FRAMELEN) +# define LO_FRAMELEN CONFIG_NET_6LOWPAN_FRAMELEN +#elif defined(CONFIG_NET_IEEE802154_FRAMELEN) +# define LO_FRAMELEN CONFIG_NET_IEEE802154_FRAMELEN +#else +# define LO_FRAMELEN IEEE802154_MAX_PHY_PACKET_SIZE +#endif + /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define LO_WDDELAY (1*CLK_TCK) @@ -115,7 +136,9 @@ struct lo_driver_s ****************************************************************************/ static struct lo_driver_s g_loopback; +#ifdef CONFIG_NET_6LOWPAN static uint8_t g_iobuffer[CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE]; +#endif static uint8_t g_eaddr[IEEE802154_EADDRSIZE] = { @@ -167,7 +190,7 @@ static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, static int lo_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist); static int lo_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties); + FAR struct radiodev_properties_s *properties); /**************************************************************************** * Private Functions @@ -192,9 +215,10 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) { /* Set the MAC address as the eaddr */ - dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_EADDRSIZE; + dev->d_mac.radio.nv_addrlen = IEEE802154_EADDRSIZE; IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr, g_eaddr); +#ifdef CONFIG_NET_IPv6 /* Set the IP address based on the eaddr */ dev->d_ipv6addr[0] = HTONS(0xfe80); @@ -207,14 +231,16 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) dev->d_ipv6addr[7] = (uint16_t)g_eaddr[6] << 8 | (uint16_t)g_eaddr[7]; dev->d_ipv6addr[4] ^= 0x200; } +#endif #else static void lo_addr2ip(FAR struct net_driver_s *dev) { /* Set the MAC address as the saddr */ - dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + dev->d_mac.radio.nv_addrlen = IEEE802154_SADDRSIZE; IEEE802154_SADDRCOPY(dev->d_mac.radio.nv_addr, g_saddr); +#ifdef CONFIG_NET_IPv6 /* Set the IP address based on the saddr */ dev->d_ipv6addr[0] = HTONS(0xfe80); @@ -226,6 +252,7 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) dev->d_ipv6addr[6] = HTONS(0xfe00); dev->d_ipv6addr[7] = (uint16_t)g_saddr[0] << 8 | (uint16_t)g_saddr[1]; dev->d_ipv6addr[7] ^= 0x200; +#endif } #endif @@ -245,6 +272,7 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) static inline void lo_netmask(FAR struct net_driver_s *dev) { +#ifdef CONFIG_NET_IPv6 dev->d_ipv6netmask[0] = 0xffff; dev->d_ipv6netmask[1] = 0xffff; dev->d_ipv6netmask[2] = 0xffff; @@ -260,6 +288,7 @@ static inline void lo_netmask(FAR struct net_driver_s *dev) dev->d_ipv6netmask[6] = 0xffff; dev->d_ipv6netmask[7] = 0; #endif +#endif } /**************************************************************************** @@ -495,11 +524,11 @@ static int lo_ifup(FAR struct net_driver_s *dev) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; +#ifdef CONFIG_NET_IPv6 ninfo("Bringing up: IPv6 %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 PANID=%02x:%02x\n", dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], @@ -512,6 +541,27 @@ static int lo_ifup(FAR struct net_driver_s *dev) dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], priv->lo_panid[0], priv->lo_panid[1]); #endif +#else + if (dev->d_mac.radio.nv_addrlen == 8) + { + ninfo("Bringing up: Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n", + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], + dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3], + dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5], + dev->d_mac.radio.nv_addr[6], dev->d_mac.radio.nv_addr[7], + priv->lo_panid[0], priv->lo_panid[1]); + } + else if (dev->d_mac.radio.nv_addrlen == 2) + { + ninfo("Bringing up: Node: %02x:%02x PANID=%02x:%02x\n", + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], + priv->lo_panid[0], priv->lo_panid[1]); + } + else + { + nerr("ERROR: No address assigned\n"); + } +#endif /* Set and activate a timer process */ @@ -926,15 +976,15 @@ static int lo_req_data(FAR struct radio_driver_s *netdev, ****************************************************************************/ static int lo_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties) + FAR struct radiodev_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); - memset(properties, 0, sizeof(struct sixlowpan_properties_s)); + memset(properties, 0, sizeof(struct radiodev_properties_s)); /* General */ - properties->sp_addrlen = NET_6LOWPAN_ADDRSIZE; /* Length of an address */ - properties->sp_pktlen = CONFIG_NET_6LOWPAN_FRAMELEN; /* Fixed frame length */ + properties->sp_addrlen = LO_ADDRSIZE; /* Length of an address */ + properties->sp_pktlen = LO_FRAMELEN; /* Fixed frame length */ /* Multicast address (uses broadcast address) * @@ -951,12 +1001,12 @@ static int lo_properties(FAR struct radio_driver_s *netdev, * (qualified by the destination PANID). */ - properties->sp_mcast.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + properties->sp_mcast.nv_addrlen = IEEE802154_SADDRSIZE; memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); /* Broadcast address */ - properties->sp_bcast.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + properties->sp_bcast.nv_addrlen = IEEE802154_SADDRSIZE; memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); #ifdef CONFIG_NET_STARPOINT @@ -1014,7 +1064,9 @@ int ieee8021514_loopback(void) #ifdef CONFIG_NETDEV_IOCTL dev->d_ioctl = lo_ioctl; /* Handle network IOCTL commands */ #endif +#ifdef CONFIG_NET_6LOWPAN dev->d_buf = g_iobuffer; /* Attach the IO buffer */ +#endif dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Set the network mask and advertise our MAC-based IP address */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 53e354b9fa8..a47b50e75b9 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -57,13 +57,14 @@ #include #include #include +#include #include #include #include #include "mac802154.h" -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) /**************************************************************************** * Pre-processor Definitions @@ -96,6 +97,26 @@ # define CONFIG_IEEE802154_NETDEV_NINTERFACES 1 #endif +/* Preferred address size */ + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR +# define MACNET_ADDRSIZE IEEE802154_EADDRSIZE +#else +# define MACNET_ADDRSIZE IEEE802154_SADDRSIZE +#endif + +/* Frame size + * REVISIT: Too many frame length definitions + */ + +#if defined(CONFIG_NET_6LOWPAN_FRAMELEN) +# define MACNET_FRAMELEN CONFIG_NET_6LOWPAN_FRAMELEN +#elif defined(CONFIG_NET_IEEE802154_FRAMELEN) +# define MACNET_FRAMELEN CONFIG_NET_IEEE802154_FRAMELEN +#else +# define MACNET_FRAMELEN IEEE802154_MAX_PHY_PACKET_SIZE +#endif + /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ #define TXPOLL_WDDELAY (1*CLK_TCK) @@ -201,7 +222,7 @@ static int macnet_get_mhrlen(FAR struct radio_driver_s *netdev, static int macnet_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist); static int macnet_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties); + FAR struct radiodev_properties_s *properties); /**************************************************************************** * Private Functions @@ -251,8 +272,9 @@ static int macnet_advertise(FAR struct net_driver_s *dev) eaddr = arg.getreq.attrval.mac.eaddr; IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr, eaddr); - dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_EADDRSIZE; + dev->d_mac.radio.nv_addrlen = IEEE802154_EADDRSIZE; +#ifdef CONFIG_NET_IPv6 /* Set the IP address based on the eaddr */ dev->d_ipv6addr[0] = HTONS(0xfe80); @@ -264,6 +286,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev) dev->d_ipv6addr[6] = (uint16_t)eaddr[4] << 8 | (uint16_t)eaddr[5]; dev->d_ipv6addr[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[7]; dev->d_ipv6addr[4] ^= 0x200; +#endif return OK; } @@ -289,8 +312,9 @@ static int macnet_advertise(FAR struct net_driver_s *dev) saddr = arg.getreq.attrval.mac.saddr; IEEE802154_SADDRCOPY(dev->d_mac.radio.nv_addr, saddr); - dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + dev->d_mac.radio.nv_addrlen = IEEE802154_SADDRSIZE; +#ifdef CONFIG_NET_IPv6 /* Set the IP address based on the saddr */ dev->d_ipv6addr[0] = HTONS(0xfe80); @@ -302,6 +326,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev) dev->d_ipv6addr[6] = HTONS(0xfe00); dev->d_ipv6addr[7] = (uint16_t)saddr[0] << 8 | (uint16_t)saddr[1]; dev->d_ipv6addr[7] ^= 0x200; +#endif return OK; } #endif @@ -323,6 +348,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev) static inline void macnet_netmask(FAR struct net_driver_s *dev) { +#ifdef CONFIG_NET_IPv6 dev->d_ipv6netmask[0] = 0xffff; dev->d_ipv6netmask[1] = 0xffff; dev->d_ipv6netmask[2] = 0xffff; @@ -338,6 +364,7 @@ static inline void macnet_netmask(FAR struct net_driver_s *dev) dev->d_ipv6netmask[6] = 0xffff; dev->d_ipv6netmask[7] = 0; #endif +#endif } /**************************************************************************** @@ -394,6 +421,7 @@ static int macnet_rxframe(FAR struct mac802154_maccb_s *maccb, (FAR struct macnet_callback_s *)maccb; FAR struct macnet_driver_s *priv; FAR struct iob_s *iob; + int ret; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; @@ -411,24 +439,6 @@ static int macnet_rxframe(FAR struct mac802154_maccb_s *maccb, DEBUGASSERT(priv != NULL && ind != NULL && ind->frame != NULL); iob = ind->frame; - /* If the frame is not a 6LoWPAN frame, then return an error. The first - * byte following the MAC head at the io_offset should be a valid IPHC - * header. - */ - - 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; - } - - /* Increment statistics */ - - NETDEV_RXPACKETS(&priv->md_dev.r_dev); - NETDEV_RXIPV6(&priv->md_dev.r_dev); - /* Remove the IOB containing the frame. */ ind->frame = NULL; @@ -441,17 +451,40 @@ static int macnet_rxframe(FAR struct mac802154_maccb_s *maccb, * frame and return success. */ -#ifndef CONFIG_NET_6LOWPAN - (void)ieee802154_input(&priv->md_dev, iob, (FAR void *)ind); -#else - if (ieee802154_input(&priv->md_dev, iob, (FAR void *)ind) < 0) -#endif + ret = ieee802154_input(&priv->md_dev, iob, (FAR void *)ind); + if (ret < 0) #endif #ifdef CONFIG_NET_6LOWPAN { - (void)sixlowpan_input(&priv->md_dev, iob, (FAR void *)ind); + /* If the frame is not a 6LoWPAN frame, then return an error. The + * first byte following the MAC head at the io_offset should be a + * valid IPHC header. + */ + + 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]); + ret = -EINVAL; + } + else + { + ret = sixlowpan_input(&priv->md_dev, iob, (FAR void *)ind); + } } + + if (ret < 0) #endif + { + ind->frame = iob; + return ret; + } + + /* Increment statistics */ + + NETDEV_RXPACKETS(&priv->md_dev.r_dev); + NETDEV_RXIPV6(&priv->md_dev.r_dev); /* sixlowpan_input() will free the IOB, but we must free the struct * ieee802154_data_ind_s container here. @@ -675,6 +708,7 @@ static int macnet_ifup(FAR struct net_driver_s *dev) ret = macnet_advertise(dev); if (ret >= 0) { +#ifdef CONFIG_NET_IPv6 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], @@ -690,6 +724,27 @@ static int macnet_ifup(FAR struct net_driver_s *dev) wlinfo(" Node: %02x:%02x\n", dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1]); #endif +#else + if (dev->d_mac.radio.nv_addrlen == 8) + { + ninfo("Bringing up: Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n", + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], + dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3], + dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5], + dev->d_mac.radio.nv_addr[6], dev->d_mac.radio.nv_addr[7], + priv->lo_panid[0], priv->lo_panid[1]); + } + else if (dev->d_mac.radio.nv_addrlen == 2) + { + ninfo("Bringing up: Node: %02x:%02x PANID=%02x:%02x\n", + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], + priv->lo_panid[0], priv->lo_panid[1]); + } + else + { + nerr("ERROR: No address assigned\n"); + } +#endif /* Set and activate a timer process */ @@ -1073,15 +1128,15 @@ static int macnet_req_data(FAR struct radio_driver_s *netdev, ****************************************************************************/ static int macnet_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties) + FAR struct radiodev_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); - memset(properties, 0, sizeof(struct sixlowpan_properties_s)); + memset(properties, 0, sizeof(struct radiodev_properties_s)); /* General */ - properties->sp_addrlen = NET_6LOWPAN_ADDRSIZE; /* Length of an address */ - properties->sp_pktlen = CONFIG_NET_6LOWPAN_FRAMELEN; /* Fixed frame length */ + properties->sp_addrlen = MACNET_ADDRSIZE; /* Length of an address */ + properties->sp_pktlen = MACNET_FRAMELEN; /* Fixed frame length */ /* Multicast address (uses broadcast address) * @@ -1098,12 +1153,12 @@ static int macnet_properties(FAR struct radio_driver_s *netdev, * (qualified by the destination PANID). */ - properties->sp_mcast.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + properties->sp_mcast.nv_addrlen = IEEE802154_SADDRSIZE; memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); /* Broadcast address */ - properties->sp_bcast.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + properties->sp_bcast.nv_addrlen = IEEE802154_SADDRSIZE; memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); #ifdef CONFIG_NET_STARPOINT @@ -1115,10 +1170,10 @@ static int macnet_properties(FAR struct radio_driver_s *netdev, #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR (void)macnet_coord_eaddr(netdev, properties->sp_hubnode.nv_addr); - properties->sp_hubnode.nv_addrlen = NET_6LOWPAN_EADDRSIZE; + properties->sp_hubnode.nv_addrlen = IEEE802154_EADDRSIZE; #else (void)macnet_coord_saddr(netdev, properties->sp_hubnode.nv_addr); - properties->sp_hubnode.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + properties->sp_hubnode.nv_addrlen = IEEE802154_SADDRSIZE; #endif #endif @@ -1151,7 +1206,9 @@ int mac802154netdev_register(MACHANDLE mac) FAR struct radio_driver_s *radio; FAR struct net_driver_s *dev; FAR struct mac802154_maccb_s *maccb; +#ifdef CONFIG_NET_6LOWPAN FAR uint8_t *pktbuf; +#endif int ret; DEBUGASSERT(mac != NULL); @@ -1167,7 +1224,8 @@ int mac802154netdev_register(MACHANDLE mac) return -ENOMEM; } - /* Allocate a packet buffer (not used by this driver, but need by the +#ifdef CONFIG_NET_6LOWPAN + /* Allocate a packet buffer (not used by this driver, but needed by the * upper networking layer) */ @@ -1178,12 +1236,15 @@ int mac802154netdev_register(MACHANDLE mac) kmm_free(priv); return -ENOMEM; } +#endif /* Initialize the driver structure */ radio = &priv->md_dev; dev = &radio->r_dev; +#ifdef CONFIG_NET_6LOWPAN dev->d_buf = pktbuf; /* Single packet buffer */ +#endif dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = macnet_ifdown; /* I/F down callback */ dev->d_txavail = macnet_txavail; /* New TX data callback */ @@ -1236,7 +1297,9 @@ int mac802154netdev_register(MACHANDLE mac) /* Free memory and return the error */ +#ifdef CONFIG_NET_6LOWPAN kmm_free(pktbuf); +#endif kmm_free(priv); return ret; } diff --git a/wireless/pktradio/pktradio_loopback.c b/wireless/pktradio/pktradio_loopback.c index a5b97198c8f..6362e6bc9fb 100644 --- a/wireless/pktradio/pktradio_loopback.c +++ b/wireless/pktradio/pktradio_loopback.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -177,7 +178,7 @@ static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, static int lo_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist); static int lo_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties); + FAR struct radiodev_properties_s *properties); /**************************************************************************** * Private Functions @@ -748,8 +749,8 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, { FAR struct radio_driver_s *radio = (FAR struct radio_driver_s *)dev; - FAR struct sixlowpan_properties_s *props = - (FAR struct sixlowpan_properties_s *)&cmddata->pifr_props; + FAR struct radiodev_properties_s *props = + (FAR struct radiodev_properties_s *)&cmddata->pifr_props; ret = lo_properties(radio, props); } @@ -929,10 +930,10 @@ static int lo_req_data(FAR struct radio_driver_s *netdev, ****************************************************************************/ static int lo_properties(FAR struct radio_driver_s *netdev, - FAR struct sixlowpan_properties_s *properties) + FAR struct radiodev_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); - memset(properties, 0, sizeof(struct sixlowpan_properties_s)); + memset(properties, 0, sizeof(struct radiodev_properties_s)); /* General */