diff --git a/configs/sim/README.txt b/configs/sim/README.txt index fc5dcb10880..c47b9e60b25 100644 --- a/configs/sim/README.txt +++ b/configs/sim/README.txt @@ -829,6 +829,13 @@ pashello Configures to use apps/examples/pashello. +pf_ieee802154 + + This is the configuration that used for unit level test of the + socket support for the PF_IEEE802154 address family. It uses + the IEEE 802.15.4 loopback network driver and the test at + apps/examples/pf_ieee802154. + pktradio This configuration is identical to the 'sixlowpan configuration diff --git a/configs/sim/pf_ieee802154/defconfig b/configs/sim/pf_ieee802154/defconfig new file mode 100644 index 00000000000..a34151620c9 --- /dev/null +++ b/configs/sim/pf_ieee802154/defconfig @@ -0,0 +1,113 @@ +# CONFIG_MMCSD_MMCSUPPORT is not set +# 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 +CONFIG_ARCH_BOARD="sim" +CONFIG_ARCH_SIM=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH="sim" +CONFIG_AT24XX_ADDR=0x57 +CONFIG_AT24XX_EXTENDED=y +CONFIG_AT24XX_EXTSIZE=160 +CONFIG_AT24XX_SIZE=2 +CONFIG_BOARD_LOOPSPERMSEC=51262 +CONFIG_BOARDCTL_POWEROFF=y +CONFIG_BUILTIN_PROXY_STACKSIZE=2048 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +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 +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_I2C_DRIVER=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_IEEE802154_LOOPBACK=y +CONFIG_IOB_BUFSIZE=128 +CONFIG_IOB_NBUFFERS=48 +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MMCSD_MULTIBLOCK_DISABLE=y +CONFIG_MMCSD=y +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_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 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_NOMAC=y +CONFIG_NSH_READLINE=y +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048 +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_STACK_DEFAULT=4096 +CONFIG_RAM_SIZE=393216 +CONFIG_RAM_START=0x20400000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKSTACKSIZE=4096 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_STANDARD_SERIAL=y +CONFIG_START_DAY=10 +CONFIG_START_MONTH=3 +CONFIG_START_YEAR=2014 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=4096 +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_USERMAIN_STACKSIZE=8192 +CONFIG_WIRELESS_IEEE802154=y +CONFIG_WIRELESS=y diff --git a/drivers/wireless/spirit/drivers/spirit_netdev.c b/drivers/wireless/spirit/drivers/spirit_netdev.c index 73f84ba9728..b53f29a8472 100644 --- a/drivers/wireless/spirit/drivers/spirit_netdev.c +++ b/drivers/wireless/spirit/drivers/spirit_netdev.c @@ -265,7 +265,7 @@ enum spirit_driver_state_e struct spirit_driver_s { - struct sixlowpan_driver_s radio; /* Interface understood by the network */ + struct radio_driver_s radio; /* Interface understood by the network */ struct spirit_library_s spirit; /* Spirit library state */ FAR const struct spirit_lower_s *lower; /* Low-level MCU-specific support */ FAR struct pktradio_metadata_s *txhead; /* Head of pending TX transfers */ @@ -347,11 +347,11 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif -static int spirit_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int spirit_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta); -static int spirit_req_data(FAR struct sixlowpan_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 sixlowpan_driver_s *netdev, +static int spirit_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties); /* Initialization */ @@ -567,7 +567,7 @@ static void spirit_set_ipaddress(FAR struct net_driver_s *dev) /* Get a convenient pointer to the PktRadio variable length address struct */ - addr = (FAR struct netdev_varaddr_s *)&dev->d_mac.sixlowpan; + addr = (FAR struct netdev_varaddr_s *)&dev->d_mac.radio; /* Has a node address been assigned? */ @@ -1894,12 +1894,12 @@ static int spirit_ifup(FAR struct net_driver_s *dev) /* Instantiate the assigned node address in hardware */ - DEBUGASSERT(dev->d_mac.sixlowpan.nv_addrlen == 1); + DEBUGASSERT(dev->d_mac.radio.nv_addrlen == 1); wlinfo("Set node address to %02x\n", - dev->d_mac.sixlowpan.nv_addr[0]); + dev->d_mac.radio.nv_addr[0]); ret = spirit_pktcommon_set_nodeaddress(spirit, - dev->d_mac.sixlowpan.nv_addr[0]); + dev->d_mac.radio.nv_addr[0]); if (ret < 0) { wlerr("ERROR: Failed to set node address: %d\n", ret); @@ -2139,8 +2139,8 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, case SIOCPKTRADIOGGPROPS: { - FAR struct sixlowpan_driver_s *radio = - (FAR struct sixlowpan_driver_s *)dev; + 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; @@ -2166,7 +2166,7 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, } else { - FAR struct netdev_varaddr_s *devaddr = &dev->d_mac.sixlowpan; + FAR struct netdev_varaddr_s *devaddr = &dev->d_mac.radio; devaddr->nv_addrlen = 1; devaddr->nv_addr[0] = newaddr->pa_addr[0]; @@ -2190,7 +2190,7 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, { FAR struct pktradio_addr_s *retaddr = (FAR struct pktradio_addr_s *)&cmddata->pifr_hwaddr; - FAR struct netdev_varaddr_s *devaddr = &dev->d_mac.sixlowpan; + FAR struct netdev_varaddr_s *devaddr = &dev->d_mac.radio; retaddr->pa_addrlen = devaddr->nv_addrlen; retaddr->pa_addr[0] = devaddr->nv_addr[0]; @@ -2231,7 +2231,7 @@ static int spirit_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static int spirit_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int spirit_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta) { DEBUGASSERT(netdev != NULL && netdev->r_dev.d_private != NULL && meta != NULL); @@ -2265,7 +2265,7 @@ static int spirit_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int spirit_req_data(FAR struct sixlowpan_driver_s *netdev, +static int spirit_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist) { FAR struct spirit_driver_s *priv; @@ -2372,7 +2372,7 @@ static int spirit_req_data(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int spirit_properties(FAR struct sixlowpan_driver_s *netdev, +static int spirit_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); @@ -2750,7 +2750,7 @@ int spirit_netdev_initialize(FAR struct spi_dev_s *spi, FAR const struct spirit_lower_s *lower) { FAR struct spirit_driver_s *priv; - FAR struct sixlowpan_driver_s *radio; + FAR struct radio_driver_s *radio; FAR struct net_driver_s *dev; FAR uint8_t *pktbuf; int ret; diff --git a/include/netpacket/ieee802154.h b/include/netpacket/ieee802154.h index b4fec88c803..8c70afd8fac 100644 --- a/include/netpacket/ieee802154.h +++ b/include/netpacket/ieee802154.h @@ -68,7 +68,7 @@ * See also the definitions above for portable union selectors. */ -struct ieee802154_addr_s +struct ieee802154_saddr_s { uint8_t s_mode; /* Address mode (see enum * ieee802154_addrmode_e) */ @@ -91,7 +91,7 @@ struct ieee802154_addr_s struct sockaddr_ieee802154_s { sa_family_t sa_family; /* AF_IEEE802154 */ - struct ieee802154_addr_s sa_addr; /* Radio address */ + struct ieee802154_saddr_s sa_addr; /* Radio address */ }; /**************************************************************************** diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h new file mode 100644 index 00000000000..18843e833b4 --- /dev/null +++ b/include/nuttx/net/ieee802154.h @@ -0,0 +1,93 @@ +/**************************************************************************** + * include/nuttx/net/ieee802154.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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_IEEE802154_H +#define __INCLUDE_NUTTX_NET_IEEE802154_H + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_input + * + * Description: + * Handle incoming IEEE 802.15.4 input + * + * This function is called when the radio device driver has received an + * frame from the network. The frame from the device driver must be + * provided in by the IOB frame argument of the function call: + * + * - The frame data is in the IOB io_data[] buffer, + * - The length of the frame is in the IOB io_len field, and + * - The offset past and radio MAC header is provided in the io_offset + * field. + * + * The frame argument may refer to a single frame (a list of length one) + * or may it be the head of a list of multiple frames. + * + * - The io_flink field points to the next frame in the list (if enable) + * - The last frame in the list will have io_flink == NULL. + * + * Parameters: + * radio The radio network driver interface. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * meta - Meta data characterizing the received frame. + * + * If there are multilple frames in the list, this metadata + * must apply to all of the frames in the list. + * + * Return: + * OK The IEEE 802.15.4 has been processed and can be deleted + * ERROR Hold the IEEE 802.15.4 and try again later. There is a listening + * socket but no recv in place to catch the IEEE 802.15.4 yet. + * Useful when a packet arrives before a recv call is in place. + * + * Assumptions: + * Called from the network diver with the network locked. + * + ****************************************************************************/ + +struct radio_driver_s; /* Forward reference */ +struct ieee802154_data_ind_s; /* Forward reference */ +struct iob_s; /* Forward reference */ + +int ieee802154_input(FAR struct radio_driver_s *radio, + FAR struct iob_s *framelist, + FAR const struct ieee802154_data_ind_s *meta); + +#endif /* __INCLUDE_NUTTX_NET_IEEE802154_H */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 7608a634b54..fc27f6b7b73 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -247,10 +247,10 @@ struct net_driver_s struct ether_addr ether; /* Device Ethernet MAC address */ #endif -#ifdef CONFIG_NET_6LOWPAN +#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) /* The address assigned to an IEEE 802.15.4 or generic packet radio. */ - struct netdev_varaddr_s sixlowpan; + struct netdev_varaddr_s radio; #endif /* CONFIG_NET_6LOWPAN */ } d_mac; #endif /* CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN */ @@ -463,9 +463,9 @@ int ipv6_input(FAR struct net_driver_s *dev); #endif #ifdef CONFIG_NET_6LOWPAN -struct sixlowpan_driver_s; /* See sixlowpan.h */ +struct radio_driver_s; /* See sixlowpan.h */ struct iob_s; /* See iob.h */ -int sixlowpan_input(FAR struct sixlowpan_driver_s *ieee, +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/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 64a075d5cfe..6eea2bf77c2 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -387,7 +387,7 @@ struct sixlowpan_properties_s * * 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 sixlowpan_driver_s' is cast + * 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. * @@ -428,7 +428,7 @@ struct sixlowpan_properties_s struct iob_s; /* Forward reference */ -struct sixlowpan_driver_s +struct radio_driver_s { /* This definitiona must appear first in the structure definition to * assure cast compatibility. @@ -534,7 +534,7 @@ struct sixlowpan_driver_s * **************************************************************************/ - CODE int (*r_get_mhrlen)(FAR struct sixlowpan_driver_s *netdev, + CODE int (*r_get_mhrlen)(FAR struct radio_driver_s *netdev, FAR const void *meta); /************************************************************************** @@ -555,7 +555,7 @@ struct sixlowpan_driver_s * **************************************************************************/ - CODE int (*r_req_data)(FAR struct sixlowpan_driver_s *netdev, + CODE int (*r_req_data)(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist); /************************************************************************** @@ -577,7 +577,7 @@ struct sixlowpan_driver_s * **************************************************************************/ - CODE int (*r_properties)(FAR struct sixlowpan_driver_s *netdev, + CODE int (*r_properties)(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties); }; @@ -651,7 +651,7 @@ struct sixlowpan_driver_s * ****************************************************************************/ -int sixlowpan_input(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_input(FAR struct radio_driver_s *radio, FAR struct iob_s *framelist, FAR const void *metadata); #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/Kconfig b/net/Kconfig index d9b2e37abae..615cebee20f 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -280,6 +280,7 @@ source "net/pkt/Kconfig" source "net/local/Kconfig" source "net/tcp/Kconfig" source "net/udp/Kconfig" +source "net/ieee802154/Kconfig" source "net/icmp/Kconfig" source "net/icmpv6/Kconfig" source "net/igmp/Kconfig" diff --git a/net/Makefile b/net/Makefile index 513c88d110d..eb51cc79b0d 100644 --- a/net/Makefile +++ b/net/Makefile @@ -68,6 +68,7 @@ include local/Make.defs include tcp/Make.defs include udp/Make.defs include sixlowpan/Make.defs +include ieee802154/Make.defs include devif/Make.defs include ipforward/Make.defs include loopback/Make.defs diff --git a/net/README.txt b/net/README.txt index 6492efc2140..a912e881be8 100644 --- a/net/README.txt +++ b/net/README.txt @@ -8,23 +8,25 @@ Directory Structure | `- net/ | - +- arp - Address resolution protocol (IPv4) - +- devif - Stack/device interface layer - +- icmp - Internet Control Message Protocol (IPv4) - +- icmpv6 - Internet Control Message Protocol (IPv6) - +- inet - PF_INET/PF_INET6 socket interface - +- ipforward - IP forwarding logic - +- local - Unix domain (local) sockets - +- loopback - Local loopback - +- neighbor - Neighbor Discovery Protocol (IPv6) - +- netdev - Socket network device interface - +- pkt - "Raw" packet socket support - +- socket - BSD socket interface - +- route - Routing table support - +- tcp - Transmission Control Protocol - +- udp - User Datagram Protocol - +- usrsock - User socket API for user-space networking stack - `- utils - Miscellaneous utility functions + +- arp - Address resolution protocol (IPv4) + +- devif - Stack/device interface layer + +- icmp - Internet Control Message Protocol (IPv4) + +- icmpv6 - Internet Control Message Protocol (IPv6) + +- ieee802154 - PF_IEEE802154 socket interface + +- inet - PF_INET/PF_INET6 socket interface + +- ipforward - IP forwarding logic + +- local - Unix domain (local) sockets + +- loopback - Local loopback + +- neighbor - Neighbor Discovery Protocol (IPv6) + +- netdev - Socket network device interface + +- pkt - "Raw" packet socket support + +- sixlowpan - 6LoWPAN implementation + +- socket - BSD socket interface + +- route - Routing table support + +- tcp - Transmission Control Protocol + +- udp - User Datagram Protocol + +- usrsock - User socket API for user-space networking stack + `- utils - Miscellaneous utility functions +-------------------------------------------------------------------++------------------------+ diff --git a/net/devif/devif.h b/net/devif/devif.h index 411f2a4cbdc..438e275f46e 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -74,7 +74,7 @@ * TCP_NEWDATA IN: Set to indicate that the peer has sent us new data. * UDP_NEWDATA OUT: Cleared (only) by the socket layer logic to indicate * PKT_NEWDATA that the new data was consumed, suppressing further - * attempts to process the new data. + * IEEE802154_NEWDATA attempts to process the new data. * * TCP_SNDACK IN: Not used; always zero * OUT: Set by the socket layer if the new data was consumed @@ -87,7 +87,7 @@ * TCP_POLL IN: Used for polling the socket layer. This is provided * UDP_POLL periodically from the drivers to support (1) timed * PKT_POLL operations, and (2) to check if the socket layer has - * data that it wants to send. These are socket oriented + * IEEE802154_POLL data that it wants to send. These are socket oriented * callbacks where the context depends on the specific * set * OUT: Not used @@ -174,31 +174,33 @@ /* Bits 0-9: Connection specific event bits */ -#define TCP_ACKDATA (1 << 0) -#define TCP_NEWDATA (1 << 1) -#define UDP_NEWDATA TCP_NEWDATA -#define PKT_NEWDATA TCP_NEWDATA -#define WPAN_NEWDATA TCP_NEWDATA -#define IPFWD_NEWDATA TCP_NEWDATA -#define TCP_SNDACK (1 << 2) -#define TCP_REXMIT (1 << 3) -#define TCP_POLL (1 << 4) -#define UDP_POLL TCP_POLL -#define PKT_POLL TCP_POLL -#define WPAN_POLL TCP_POLL -#define TCP_BACKLOG (1 << 5) -#define TCP_CLOSE (1 << 6) -#define TCP_ABORT (1 << 7) -#define TCP_CONNECTED (1 << 8) -#define TCP_TIMEDOUT (1 << 9) +#define TCP_ACKDATA (1 << 0) +#define TCP_NEWDATA (1 << 1) +#define UDP_NEWDATA TCP_NEWDATA +#define IEEE802154_NEWDATA TCP_NEWDATA +#define PKT_NEWDATA TCP_NEWDATA +#define WPAN_NEWDATA TCP_NEWDATA +#define IPFWD_NEWDATA TCP_NEWDATA +#define TCP_SNDACK (1 << 2) +#define TCP_REXMIT (1 << 3) +#define TCP_POLL (1 << 4) +#define UDP_POLL TCP_POLL +#define PKT_POLL TCP_POLL +#define IEEE802154_POLL TCP_POLL +#define WPAN_POLL TCP_POLL +#define TCP_BACKLOG (1 << 5) +#define TCP_CLOSE (1 << 6) +#define TCP_ABORT (1 << 7) +#define TCP_CONNECTED (1 << 8) +#define TCP_TIMEDOUT (1 << 9) /* Bits 10-12: Device specific event bits */ -#define ICMP_NEWDATA TCP_NEWDATA -#define ICMPv6_NEWDATA TCP_NEWDATA -#define ICMP_ECHOREPLY (1 << 10) -#define ICMPv6_ECHOREPLY (1 << 11) -#define NETDEV_DOWN (1 << 12) +#define ICMP_NEWDATA TCP_NEWDATA +#define ICMPv6_NEWDATA TCP_NEWDATA +#define ICMP_ECHOREPLY (1 << 10) +#define ICMPv6_ECHOREPLY (1 << 11) +#define NETDEV_DOWN (1 << 12) /* Bits 13-15: Encoded device specific poll events. Unlike connection * oriented poll events, device related poll events must distinguish @@ -206,13 +208,13 @@ * the same list in the network device structure. */ -#define DEVPOLL_SHIFT (13) -#define DEVPOLL_MASK (7 << DEVPOLL_SHIFT) -# define DEVPOLL_NONE (0 << DEVPOLL_SHIFT) -# define ARP_POLL (1 << DEVPOLL_SHIFT) -# define ICMP_POLL (2 << DEVPOLL_SHIFT) -# define ICMPv6_POLL (3 << DEVPOLL_SHIFT) -# define IPFWD_POLL (4 << DEVPOLL_SHIFT) +#define DEVPOLL_SHIFT (13) +#define DEVPOLL_MASK (7 << DEVPOLL_SHIFT) +# define DEVPOLL_NONE (0 << DEVPOLL_SHIFT) +# define ARP_POLL (1 << DEVPOLL_SHIFT) +# define ICMP_POLL (2 << DEVPOLL_SHIFT) +# define ICMPv6_POLL (3 << DEVPOLL_SHIFT) +# define IPFWD_POLL (4 << DEVPOLL_SHIFT) /* The set of events that and implications to the TCP connection state */ diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index e0c2e2e1e61..52632515fcd 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -53,6 +53,7 @@ #include "tcp/tcp.h" #include "udp/udp.h" #include "pkt/pkt.h" +#include "ieee802154/ieee802154.h" #include "icmp/icmp.h" #include "icmpv6/icmpv6.h" #include "igmp/igmp.h" @@ -237,6 +238,42 @@ static int devif_poll_pkt_connections(FAR struct net_driver_s *dev, } #endif /* CONFIG_NET_PKT */ +/**************************************************************************** + * Name: devif_poll_ieee802154_connections + * + * Description: + * Poll all packet connections for available packets to send. + * + * Assumptions: + * This function is called from the MAC device driver with the network + * locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IEEE802154 +static int devif_poll_ieee802154_connections(FAR struct net_driver_s *dev, + devif_poll_callback_t callback) +{ + FAR struct ieee802154_conn_s *ieee802154_conn = NULL; + int bstop = 0; + + /* Traverse all of the allocated packet connections and perform the poll action */ + + while (!bstop && (ieee802154_conn = ieee802154_nextconn(ieee802154_conn))) + { + /* Perform the packet TX poll */ + + ieee802154_poll(dev, ieee802154_conn); + + /* Call back into the driver */ + + bstop = callback(dev); + } + + return bstop; +} +#endif /* CONFIG_NET_PKT */ + /**************************************************************************** * Name: devif_poll_icmp * @@ -524,6 +561,15 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) if (!bstop) #endif +#ifdef CONFIG_NET_IEEE802154 + { + /* Check for pending PF_IEEE802154 socket transfer */ + + bstop = devif_poll_ieee802154_connections(dev, callback); + } + + if (!bstop) +#endif #ifdef CONFIG_NET_IGMP { /* Check for pending IGMP messages */ diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig new file mode 100644 index 00000000000..97093bf9d0f --- /dev/null +++ b/net/ieee802154/Kconfig @@ -0,0 +1,30 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +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 + select NETDEV_IOCTL + ---help--- + Enable support for raw, IEEE 802.15.4 sockets. + + Raw sockets allow receiving and transmitting IEEE 802.15.3 radio + frames without a layer2 protocol such as 6LoWPAN in between. Frames + received are copied into a IEEE 802.15.4 socket tap before they + enter the network. Frames written into a IEEE 802.15.4 socket will + bypass the network altogether and will be sent directly to the + IEEE 802.15.4 MAC network interface driver outgoing frame queue. + +if NET_IEEE802154 + +config NET_IEEE802154_NCONNS + int "Max IEEE 802.15.4 sockets" + default 1 + +endif # NET_IEEE802154 +endmenu # IEEE 802.15.4 Socket Support diff --git a/net/ieee802154/Make.defs b/net/ieee802154/Make.defs new file mode 100644 index 00000000000..cc33e07d561 --- /dev/null +++ b/net/ieee802154/Make.defs @@ -0,0 +1,59 @@ +############################################################################ +# net/ieee802154/Make.defs +# +# 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 NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Packet socket support + +ifeq ($(CONFIG_NET_IEEE802154),y) + +# Socket layer + +SOCK_CSRCS += ieee802154_sockif.c +SOCK_CSRCS += ieee802154_sendto.c +SOCK_CSRCS += ieee802154_recvfrom.c + +# Transport layer + +NET_CSRCS += ieee802154_conn.c +NET_CSRCS += ieee802154_input.c +NET_CSRCS += ieee802154_callback.c +NET_CSRCS += ieee802154_poll.c +NET_CSRCS += ieee802154_finddev.c + +# Include packet socket build support + +DEPPATH += --dep-path ieee802154 +VPATH += :ieee802154 + +endif # CONFIG_NET_IEEE802154 diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h new file mode 100644 index 00000000000..4528e9ea1f9 --- /dev/null +++ b/net/ieee802154/ieee802154.h @@ -0,0 +1,346 @@ +/**************************************************************************** + * net/ieee802154/ieee802154.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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef _NET_IEEE802154_IEEE802154_H +#define _NET_IEEE802154_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Allocate a new IEEE 802.15.4 socket data callback */ + +#define ieee802154_callback_alloc(dev,conn) \ + devif_callback_alloc(dev, &conn->list) +#define ieee802154_callback_free(dev,conn,cb) \ + devif_conn_callback_free(dev, cb, &conn->list) + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Representation of a IEEE 802.15.4 socket connection */ + +struct devif_callback_s; /* Forward reference */ + +struct ieee802154_conn_s +{ + dq_entry_t node; /* Supports a double linked list */ + struct ieee802154_saddr_s laddr; /* Locally bound address */ + struct ieee802154_saddr_s raddr; /* Connected remote address */ + uint8_t crefs; /* Reference counts on this instance */ + + /* Defines the list of IEEE 802.15.4 callbacks */ + + struct devif_callback_s *list; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +/* The IEEE 802.15.4 socket interface */ + +EXTERN const struct sock_intf_s g_ieee802154_sockif; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +struct ieee802154_data_ind_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 */ +struct sockaddr; /* Forward reference */ + +/**************************************************************************** + * Name: ieee802154_initialize() + * + * Description: + * Initialize the IEEE 802.15.4 socket connection structures. Called + * once and only from the network initialization logic. + * + ****************************************************************************/ + +void ieee802154_initialize(void); + +/**************************************************************************** + * Name: ieee802154_alloc() + * + * Description: + * Allocate a new, uninitialized IEEE 802.15.4 socket connection + * structure. This is normally something done by the implementation of + * the socket() API + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s *ieee802154_alloc(void); + +/**************************************************************************** + * Name: ieee802154_free() + * + * Description: + * Free a IEEE 802.15.4 socket connection structure that is no longer in + * use. This should be done by the implementation of close(). + * + ****************************************************************************/ + +void ieee802154_free(FAR struct ieee802154_conn_s *conn); + +/**************************************************************************** + * Name: ieee802154_active() + * + * Description: + * Find a connection structure that is the appropriate + * connection to be used with the provided Ethernet header + * + * Assumptions: + * This function is called from network logic at with the network locked. + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s * + ieee802154_active(FAR const struct ieee802154_data_ind_s *meta); + +/**************************************************************************** + * Name: ieee802154_nextconn() + * + * Description: + * Traverse the list of allocated IEEE 802.15.4 connections + * + * Assumptions: + * This function is called from network logic at with the network locked. + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s * + ieee802154_nextconn(FAR struct ieee802154_conn_s *conn); + +/**************************************************************************** + * Name: ieee802154_input + * + * Description: + * Handle incoming IEEE 802.15.4 input + * + * This function is called when the radio device driver has received an + * frame from the network. The frame from the device driver must be + * provided in by the IOB frame argument of the function call: + * + * - The frame data is in the IOB io_data[] buffer, + * - The length of the frame is in the IOB io_len field, and + * - The offset past and radio MAC header is provided in the io_offset + * field. + * + * The frame argument may refer to a single frame (a list of length one) + * or may it be the head of a list of multiple frames. + * + * - The io_flink field points to the next frame in the list (if enable) + * - The last frame in the list will have io_flink == NULL. + * + * Parameters: + * radio The radio network driver interface. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * meta - Meta data characterizing the received frame. + * + * If there are multilple frames in the list, this metadata + * must apply to all of the frames in the list. + * + * Return: + * OK The IEEE 802.15.4 has been processed and can be deleted + * ERROR Hold the IEEE 802.15.4 and try again later. There is a listening + * socket but no recv in place to catch the IEEE 802.15.4 yet. + * Useful when a packet arrives before a recv call is in place. + * + * Assumptions: + * Called from the network diver with the network locked. + * + ****************************************************************************/ + +/* ieee802154_input() is prototyped in include/nuttx/net/ieee802154.h */ + +/**************************************************************************** + * Name: ieee802154_callback + * + * Description: + * Inform the application holding the IEEE 802.15.4 socket of a change in state. + * + * Returned Value: + * OK if IEEE 802.15.4 has been processed, otherwise ERROR. + * + * Assumptions: + * This function is called from network logic at with the network locked. + * + ****************************************************************************/ + +uint16_t ieee802154_callback(FAR struct radio_driver_s *radio, + FAR struct ieee802154_conn_s *conn, + uint16_t flags); + +/**************************************************************************** + * Name: ieee802154_recvfrom + * + * Description: + * Implements the socket recvfrom interface for the case of the AF_INET + * and AF_INET6 address families. ieee802154_recvfrom() receives messages from + * a socket, and may be used to receive data on a socket whether or not it + * is connection-oriented. + * + * If 'from' is not NULL, and the underlying protocol provides the source + * address, this source address is filled in. The argument 'fromlen' is + * initialized to the size of the buffer associated with from, and + * modified on return to indicate the actual size of the address stored + * there. + * + * Parameters: + * psock A pointer to a NuttX-specific, internal socket structure + * buf Buffer to receive data + * len Length of buffer + * flags Receive flags + * from Address of source (may be NULL) + * fromlen The length of the address structure + * + * Returned Value: + * On success, returns the number of characters received. If no data is + * available to be received and the peer has performed an orderly shutdown, + * recv() will return 0. Otherwise, on errors, a negated errno value is + * returned (see recvfrom() for the list of appropriate error values). + * + ****************************************************************************/ + +ssize_t ieee802154_recvfrom(FAR struct socket *psock, FAR void *buf, + size_t len, int flags, FAR struct sockaddr *from, + FAR socklen_t *fromlen); + +/**************************************************************************** + * Name: ieee802154_find_device + * + * Description: + * Select the network driver to use with the IEEE802154 transaction. + * + * Input Parameters: + * conn - IEEE802154 connection structure (not currently used). + * addr - The address to match the devices assigned address + * + * Returned Value: + * A pointer to the network driver to use. NULL is returned on any + * failure. + * + ****************************************************************************/ + +FAR struct radio_driver_s * + ieee802154_find_device(FAR struct ieee802154_conn_s *conn, + FAR const struct ieee802154_saddr_s *addr); + +/**************************************************************************** + * Name: ieee802154_poll + * + * Description: + * Poll a IEEE 802.15.4 "connection" structure for availability of TX data + * + * Parameters: + * dev - The device driver structure to use in the send operation + * conn - The IEEE 802.15.4 "connection" to poll for TX data + * + * Return: + * None + * + * Assumptions: + * Called from the network device interface (devif) with the network + * locked. + * + ****************************************************************************/ + +void ieee802154_poll(FAR struct net_driver_s *dev, + FAR struct ieee802154_conn_s *conn); + +/**************************************************************************** + * Name: psock_ieee802154_sendto + * + * Description: + * If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) + * socket, the parameters to and 'tolen' are ignored (and the error EISCONN + * may be returned when they are not NULL and 0), and the error ENOTCONN is + * returned when the socket was not actually connected. + * + * Parameters: + * psock A pointer to a NuttX-specific, internal socket structure + * buf Data to send + * len Length of data to send + * flags Send flags + * to Address of recipient + * tolen The length of the address structure + * + * Returned Value: + * On success, returns the number of characters sent. On error, + * -1 is returned, and errno is set appropriately. See sendto() + * for the complete list of return values. + * + ****************************************************************************/ + +ssize_t psock_ieee802154_sendto(FAR struct socket *psock, + FAR const void *buf, + size_t len, int flags, + FAR const struct sockaddr *to, socklen_t tolen); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NET_IEEE802154 */ +#endif /* _NET_IEEE802154_IEEE802154_H */ diff --git a/net/ieee802154/ieee802154_callback.c b/net/ieee802154/ieee802154_callback.c new file mode 100644 index 00000000000..18538cef360 --- /dev/null +++ b/net/ieee802154/ieee802154_callback.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_callback.c + * Forward events to waiting PF_IEEE802154 sockets. + * + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include "devif/devif.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_callback + * + * Description: + * Inform the application holding the packet socket of a change in state. + * + * Returned Value: + * OK if packet has been processed, otherwise ERROR. + * + * Assumptions: + * This function is called at the interrupt level with interrupts disabled. + * + ****************************************************************************/ + +uint16_t ieee802154_callback(FAR struct radio_driver_s *radio, + FAR struct ieee802154_conn_s *conn, + uint16_t flags) +{ + ninfo("flags: %04x\n", flags); + + /* Some sanity checking */ + + if (conn != NULL) + { + /* Perform the callback */ + + flags = devif_conn_event(&radio->r_dev, conn, flags, conn->list); + } + + return flags; +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_conn.c b/net/ieee802154/ieee802154_conn.c new file mode 100644 index 00000000000..acf80701741 --- /dev/null +++ b/net/ieee802154/ieee802154_conn.c @@ -0,0 +1,298 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_conn.c + * + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "devif/devif.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* The array containing all packet socket connections */ + +static struct ieee802154_conn_s + g_ieee802154_connections[CONFIG_NET_IEEE802154_NCONNS]; + +/* A list of all free packet socket connections */ + +static dq_queue_t g_free_ieee802154_connections; +static sem_t g_free_sem; + +/* A list of all allocated packet socket connections */ + +static dq_queue_t g_active_ieee802154_connections; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: _ieee802154_semtake() and _ieee802154_semgive() + * + * Description: + * Take/give semaphore + * + ****************************************************************************/ + +static inline void _ieee802154_semtake(sem_t *sem) +{ + /* Take the semaphore (perhaps waiting) */ + + while (net_lockedwait(sem) != 0) + { + /* The only case that an error should occur here is if + * the wait was awakened by a signal. + */ + + DEBUGASSERT(get_errno() == EINTR); + } +} + +#define _ieee802154_semgive(sem) sem_post(sem) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_initialize() + * + * Description: + * Initialize the packet socket connection structures. Called once and + * only from the network logic early in initialization. + * + ****************************************************************************/ + +void ieee802154_initialize(void) +{ + int i; + + /* Initialize the queues */ + + dq_init(&g_free_ieee802154_connections); + dq_init(&g_active_ieee802154_connections); + sem_init(&g_free_sem, 0, 1); + + for (i = 0; i < CONFIG_NET_IEEE802154_NCONNS; i++) + { + /* Link each pre-allocated connection structure into the free list. */ + + dq_addlast(&g_ieee802154_connections[i].node, + &g_free_ieee802154_connections); + } +} + +/**************************************************************************** + * Name: ieee802154_alloc() + * + * Description: + * Allocate a new, uninitialized packet socket connection structure. This + * is normally something done by the implementation of the socket() API + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s *ieee802154_alloc(void) +{ + FAR struct ieee802154_conn_s *conn; + + /* The free list is only accessed from user, non-interrupt level and + * is protected by a semaphore (that behaves like a mutex). + */ + + _ieee802154_semtake(&g_free_sem); + conn = (FAR struct ieee802154_conn_s *) + dq_remfirst(&g_free_ieee802154_connections); + + if (conn) + { + /* Enqueue the connection into the active list */ + + dq_addlast(&conn->node, &g_active_ieee802154_connections); + } + + _ieee802154_semgive(&g_free_sem); + return conn; +} + +/**************************************************************************** + * Name: ieee802154_free() + * + * Description: + * Free a packet socket connection structure that is no longer in use. + * This should be done by the implementation of close(). + * + ****************************************************************************/ + +void ieee802154_free(FAR struct ieee802154_conn_s *conn) +{ + /* The free list is only accessed from user, non-interrupt level and + * is protected by a semaphore (that behaves like a mutex). + */ + + DEBUGASSERT(conn->crefs == 0); + + _ieee802154_semtake(&g_free_sem); + + /* Remove the connection from the active list */ + + dq_rem(&conn->node, &g_active_ieee802154_connections); + + /* Free the connection */ + + dq_addlast(&conn->node, &g_free_ieee802154_connections); + _ieee802154_semgive(&g_free_sem); +} + +/**************************************************************************** + * Name: ieee802154_active() + * + * Description: + * Find a connection structure that is the appropriate + * connection to be used with the provided IEEE 802.15.4 header + * + * Assumptions: + * This function is called from network logic at with the network locked. + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s * + ieee802154_active(FAR const struct ieee802154_data_ind_s *meta) +{ + FAR struct ieee802154_conn_s *conn; + + DEBUGASSERT(meta != NULL); + + for (conn = (FAR struct ieee802154_conn_s *)g_active_ieee802154_connections.head; + conn != NULL; + conn = (FAR struct ieee802154_conn_s *)conn->node.flink) + { + /* Does the destination address match the bound address of the socket. */ + /* REVISIT: Currently and explict address must be assigned. Should we + * support some moral equivalent to INADDR_ANY? + */ + + if (meta->dest.mode != conn->laddr.s_mode) + { + continue; + } + + if (meta->dest.mode == IEEE802154_ADDRMODE_SHORT && + !IEEE802154_SADDRCMP(meta->dest.saddr, conn->laddr.s_saddr)) + { + continue; + } + + if (meta->dest.mode == IEEE802154_ADDRMODE_EXTENDED && + !IEEE802154_EADDRCMP(meta->dest.saddr, conn->laddr.s_eaddr)) + { + continue; + } + + /* Is the socket "connected?" to a remote peer? If so, check if the + * source address matches the connected remote adress. + */ + + switch (conn->raddr.s_mode) + { + case IEEE802154_ADDRMODE_NONE: + return conn; /* No.. accept the connection */ + + case IEEE802154_ADDRMODE_SHORT: + if (IEEE802154_SADDRCMP(meta->dest.saddr, conn->raddr.s_saddr)) + { + return conn; + } + break; + + case IEEE802154_ADDRMODE_EXTENDED: + if (IEEE802154_EADDRCMP(meta->dest.eaddr, conn->raddr.s_eaddr)) + { + return conn; + } + break; + + default: + nerr("ERROR: Invalid address mode: %u\n", conn->raddr.s_mode); + return NULL; + } + } + + return conn; +} + +/**************************************************************************** + * Name: ieee802154_nextconn() + * + * Description: + * Traverse the list of allocated packet connections + * + * Assumptions: + * This function is called from network logic at with the network locked. + * + ****************************************************************************/ + +FAR struct ieee802154_conn_s * + ieee802154_nextconn(FAR struct ieee802154_conn_s *conn) +{ + if (!conn) + { + return (FAR struct ieee802154_conn_s *) + g_active_ieee802154_connections.head; + } + else + { + return (FAR struct ieee802154_conn_s *)conn->node.flink; + } +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_finddev.c b/net/ieee802154/ieee802154_finddev.c new file mode 100644 index 00000000000..8cf41544e13 --- /dev/null +++ b/net/ieee802154/ieee802154_finddev.c @@ -0,0 +1,190 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_finddev.c + * + * Copyright (C) 2015 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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include "netdev/netdev.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ieee802154_finddev_s +{ + FAR const struct ieee802154_saddr_s *addr; + FAR struct radio_driver_s *radio; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee8021545_dev_callback + * + * Description: + * Check if this device matches the connections local address. + * + * Input Parameters: + * dev - The next network device in the enumeration + * + * Returned Value: + * 0 if there is no match (meaning to continue looking); 1 if there is a + * match (meaning to stop the search). + * + ****************************************************************************/ + +static int ieee8021545_dev_callback(FAR struct net_driver_s *dev, FAR void *arg) +{ + FAR struct ieee802154_finddev_s *match = + (FAR struct ieee802154_finddev_s *)arg; + + DEBUGASSERT(dev != NULL && match != NULL && match->addr != NULL); + + /* First, check if this network device is an IEEE 802.15.4 radio and that + * it has an assigned IEEE 802.15.4 address. + */ + + if (dev->d_lltype == NET_LL_IEEE802154 && dev->d_mac.radio.nv_addrlen > 0) + { + DEBUGASSERT(dev->d_mac.radio.nv_addrlen == 2 || + dev->d_mac.radio.nv_addrlen == 8); + + /* Does the address mode match? */ + + if (match->addr->s_mode == IEEE802154_ADDRMODE_SHORT && + dev->d_mac.radio.nv_addrlen == 2) + { + /* Does the device address match */ + + if (IEEE802154_SADDRCMP(dev->d_mac.radio.nv_addr, + match->addr->s_saddr)) + { + /* Yes.. save the match and return 1 to stop the search */ + + match->radio = (FAR struct radio_driver_s *)dev; + return 1; + } + } + else if (match->addr->s_mode == IEEE802154_ADDRMODE_EXTENDED && + dev->d_mac.radio.nv_addrlen == 8) + { + /* Does the device address match */ + + if (IEEE802154_EADDRCMP(dev->d_mac.radio.nv_addr, + match->addr->s_eaddr)) + { + /* Yes.. save the match and return 1 to stop the search */ + + match->radio = (FAR struct radio_driver_s *)dev; + return 1; + } + } + } + + /* Keep looking */ + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_find_device + * + * Description: + * Select the network driver to use with the IEEE802154 transaction. + * + * Input Parameters: + * conn - IEEE802154 connection structure (not currently used). + * addr - The address to match the devices assigned address + * + * Returned Value: + * A pointer to the network driver to use. NULL is returned on any + * failure. + * + ****************************************************************************/ + +FAR struct radio_driver_s * + ieee802154_find_device(FAR struct ieee802154_conn_s *conn, + FAR const struct ieee802154_saddr_s *addr) +{ + struct ieee802154_finddev_s match; + int ret; + + DEBUGASSERT(conn != NULL); + match.addr = addr; + match.radio = NULL; + + /* If the socket is not bound to a local address, then return a failure */ + + if (addr->s_mode == IEEE802154_ADDRMODE_NONE) + { + return NULL; + } + + DEBUGASSERT(addr->s_mode == IEEE802154_ADDRMODE_SHORT || + addr->s_mode == IEEE802154_ADDRMODE_EXTENDED); + + /* Other, search for the IEEE 802.15.4 network device whose MAC is equal to + * the sockets bount local address. + */ + + ret = netdev_foreach(ieee8021545_dev_callback, (FAR void *)&match); + if (ret == 1) + { + DEBUGASSERT(match.radio != NULL); + return match.radio; + } + + return NULL; +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_input.c b/net/ieee802154/ieee802154_input.c new file mode 100644 index 00000000000..c7766321518 --- /dev/null +++ b/net/ieee802154/ieee802154_input.c @@ -0,0 +1,150 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_input.c + * Handle incoming IEEE 802.15.4 frame input + * + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include + +#include "devif/devif.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_input + * + * Description: + * Handle incoming IEEE 802.15.4 input + * + * This function is called when the radio device driver has received an + * frame from the network. The frame from the device driver must be + * provided in by the IOB frame argument of the function call: + * + * - The frame data is in the IOB io_data[] buffer, + * - The length of the frame is in the IOB io_len field, and + * - The offset past and radio MAC header is provided in the io_offset + * field. + * + * The frame argument may refer to a single frame (a list of length one) + * or may it be the head of a list of multiple frames. + * + * - The io_flink field points to the next frame in the list (if enable) + * - The last frame in the list will have io_flink == NULL. + * + * Parameters: + * radio The radio network driver interface. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * meta - Meta data characterizing the received frane. + * + * If there are multilple frames in the list, this metadata + * must apply to all of the frames in the list. + * + * Return: + * OK The IEEE 802.15.4 has been processed and can be deleted + * ERROR Hold the IEEE 802.15.4 and try again later. There is a listening + * socket but no recv in place to catch the IEEE 802.15.4 yet. + * Useful when a packet arrives before a recv call is in place. + * + * Assumptions: + * Called from the network diver with the network locked. + * + ****************************************************************************/ + +int ieee802154_input(FAR struct radio_driver_s *radio, + FAR struct iob_s *framelist, + FAR const struct ieee802154_data_ind_s *meta) +{ + FAR struct ieee802154_conn_s *conn; + int ret = OK; + + /* Check if there is a connection that will accept this packet */ + + conn = ieee802154_active(meta); + if (conn) + { + uint16_t flags; + + /* Setup for the application callback (NOTE: These should not be + * used by PF_IEEE802154 sockets). + */ + + radio->r_dev.d_appdata = radio->r_dev.d_buf; + radio->r_dev.d_len = 0; + radio->r_dev.d_sndlen = 0; + + /* Perform the application callback */ + /* REVISIT: Need to pass the meta data and the IOB through the callback */ +#warning Missing logic + + flags = ieee802154_callback(radio, conn, IEEE802154_NEWDATA); + + /* If the operation was successful, the PKT_NEWDATA flag is removed + * and thus the packet can be deleted (OK will be returned). + */ + + if ((flags & PKT_NEWDATA) != 0) + { + /* No.. the packet was not processed now. Return ERROR so + * that the driver may retry again later. We still need to + * set d_len to zero so that the driver is aware that there + * is nothing to be sent. + */ + + nwarn("WARNING: Packet not processed\n"); + ret = ERROR; + } + } + else + { + nerr("ERROR: No listener\n"); + } + + return ret; +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_poll.c b/net/ieee802154/ieee802154_poll.c new file mode 100644 index 00000000000..9e8da42f283 --- /dev/null +++ b/net/ieee802154/ieee802154_poll.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_poll.c + * Poll for the availability of ougoing IEEE 802.15.4 frames + * + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#include "devif/devif.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_poll + * + * Description: + * Poll a packet "connection" structure for availability of TX data + * + * Parameters: + * dev - The device driver structure to use in the send operation + * conn - The packet "connection" to poll for TX data + * + * Return: + * None + * + * Assumptions: + * Called from the interrupt level or with interrupts disabled. + * + ****************************************************************************/ + +void ieee802154_poll(FAR struct net_driver_s *dev, + FAR struct ieee802154_conn_s *conn) +{ + FAR struct radio_driver_s *radio; + + DEBUGASSERT(dev != NULL && conn != NULL); + radio = (FAR struct radio_driver_s *)dev; + + /* Verify that the packet connection is valid */ + + if (conn != NULL) + { + /* Setup for the application callback (NOTE: These should not be + * used by PF_IEEE802154 sockets). + */ + + radio->r_dev.d_appdata = radio->r_dev.d_buf; + radio->r_dev.d_len = 0; + radio->r_dev.d_sndlen = 0; + + /* Perform the application callback */ + /* REVISIT: Need to pass the meta data and the IOB through the callback */ +#warning Missing logic + + /* Perform the application callback */ + + (void)ieee802154_callback(radio, conn, IEEE802154_POLL); + } +} + +#endif /* CONFIG_NET && CONFIG_NET_PKT */ diff --git a/net/ieee802154/ieee802154_recvfrom.c b/net/ieee802154/ieee802154_recvfrom.c new file mode 100644 index 00000000000..4bf77644e2e --- /dev/null +++ b/net/ieee802154/ieee802154_recvfrom.c @@ -0,0 +1,500 @@ +/**************************************************************************** + * net/socket/ieee802154_recvfrom.c + * + * 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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "netdev/netdev.h" +#include "devif/devif.h" +#include "socket/socket.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ieee802154_recvfrom_s +{ + FAR struct devif_callback_s *ir_cb; /* Reference to callback instance */ + sem_t ir_sem; /* Semaphore signals recv completion */ + size_t ir_buflen; /* Length of receive buffer */ + uint8_t *ir_buffer; /* Pointer to receive buffer */ + ssize_t ir_recvlen; /* The received length */ + int ir_result; /* Success:OK, failure:negated errno */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_add_recvlen + * + * Description: + * Update information about space available for new data and update size + * of data in buffer, This logic accounts for the case where + * recvfrom_udpreadahead() sets state.ir_recvlen == -1 . + * + * Parameters: + * pstate recvfrom state structure + * recvlen size of new data appended to buffer + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline void + ieee802154_add_recvlen(FAR struct ieee802154_recvfrom_s *pstate, + size_t recvlen) +{ + if (pstate->ir_recvlen < 0) + { + pstate->ir_recvlen = 0; + } + + pstate->ir_recvlen += recvlen; + pstate->ir_buffer += recvlen; + pstate->ir_buflen -= recvlen; +} + +/**************************************************************************** + * Name: ieee802154_recvfrom_newdata + * + * Description: + * Copy the read data from the packet + * + * Parameters: + * radio The structure of the network driver that caused the interrupt + * pstate recvfrom state structure + * + * Returned Value: + * None. + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void ieee802154_recvfrom_newdata(FAR struct radio_driver_s *radio, + FAR struct ieee802154_recvfrom_s *pstate) +{ + size_t recvlen; + + if (radio->r_dev.d_len > pstate->ir_buflen) + { + recvlen = pstate->ir_buflen; + } + else + { + recvlen = radio->r_dev.d_len; + } + + /* Copy the new packet data into the user buffer */ + + memcpy(pstate->ir_buffer, radio->r_dev.d_buf, recvlen); + ninfo("Received %d bytes (of %d)\n", (int)recvlen, (int)radio->r_dev.d_len); + + /* Update the accumulated size of the data read */ + + ieee802154_add_recvlen(pstate, recvlen); +} + +/**************************************************************************** + * Name: ieee802154_recvfrom_sender + * + * Description: + * + * Parameters: + * + * Returned Values: + * + * Assumptions: + * + ****************************************************************************/ + +static inline void + ieee802154_recvfrom_sender(FAR struct radio_driver_s *radio, + FAR struct ieee802154_recvfrom_s *pstate) +{ +} + +/**************************************************************************** + * Name: ieee802154_recvfrom_interrupt + * + * Description: + * + * Parameters: + * + * Returned Values: + * + * Assumptions: + * + ****************************************************************************/ + +static uint16_t ieee802154_recvfrom_interrupt(FAR struct net_driver_s *dev, + FAR void *pvconn, FAR void *pvpriv, + uint16_t flags) +{ + FAR struct ieee802154_recvfrom_s *pstate; + FAR struct radio_driver_s *radio; + + ninfo("flags: %04x\n", flags); + + DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL); + + /* Ignore polls from non IEEE 802.15.4 network drivers */ + + if (dev->d_lltype != NET_LL_IEEE802154) + { + return flags; + } + + /* Make sure that this is the driver to which the socket is bound. */ +#warning Missing logic + + pstate = (FAR struct ieee802154_recvfrom_s *)pvpriv; + radio = (FAR struct radio_driver_s *)dev; + + /* 'priv' might be null in some race conditions (?) */ + + if (pstate) + { + /* If a new packet is available, then complete the read action. */ + + if ((flags & IEEE802154_NEWDATA) != 0) + { + /* Copy the packet */ + + ieee802154_recvfrom_newdata(radio, pstate); + + /* Don't allow any further call backs. */ + + pstate->ir_cb->flags = 0; + pstate->ir_cb->priv = NULL; + pstate->ir_cb->event = NULL; +#if 0 + /* Save the sender's address in the caller's 'from' location */ + + ieee802154_recvfrom_sender(radio, pstate); +#endif + /* indicate that the data has been consumed */ + + flags &= ~IEEE802154_NEWDATA; + + /* Wake up the waiting thread, returning the number of bytes + * actually read. + */ + + sem_post(&pstate->ir_sem); + } + } + + return flags; +} + +/**************************************************************************** + * Name: ieee802154_recvfrom_initialize + * + * Description: + * Initialize the state structure + * + * Parameters: + * psock Pointer to the socket structure for the socket + * buf Buffer to receive data + * len Length of buffer + * pstate A pointer to the state structure to be initialized + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void ieee802154_recvfrom_initialize(FAR struct socket *psock, FAR void *buf, + size_t len, FAR struct sockaddr *infrom, + FAR socklen_t *fromlen, + FAR struct ieee802154_recvfrom_s *pstate) +{ + /* Initialize the state structure. */ + + memset(pstate, 0, sizeof(struct ieee802154_recvfrom_s)); + + /* This semaphore is used for signaling and, hence, should not have + * priority inheritance enabled. + */ + + (void)sem_init(&pstate->ir_sem, 0, 0); /* Doesn't really fail */ + (void)sem_setprotocol(&pstate->ir_sem, SEM_PRIO_NONE); + + pstate->ir_buflen = len; + pstate->ir_buffer = buf; +} + +/* The only un-initialization that has to be performed is destroying the + * semaphore. + */ + +#define ieee802154_recvfrom_uninitialize(s) sem_destroy(&(s)->ir_sem) + +/**************************************************************************** + * Name: ieee802154_recvfrom_result + * + * Description: + * Evaluate the result of the recv operations + * + * Parameters: + * result The result of the net_lockedwait operation (may indicate EINTR) + * pstate A pointer to the state structure to be initialized + * + * Returned Value: + * The result of the recv operation with errno set appropriately + * + * Assumptions: + * + ****************************************************************************/ + +static ssize_t ieee802154_recvfrom_result(int result, struct ieee802154_recvfrom_s *pstate) +{ + int save_errno = get_errno(); /* In case something we do changes it */ + + /* Check for a error/timeout detected by the interrupt handler. Errors are + * signaled by negative errno values for the rcv length + */ + + if (pstate->ir_result < 0) + { + /* This might return EAGAIN on a timeout or ENOTCONN on loss of + * connection (TCP only) + */ + + return pstate->ir_result; + } + + /* If net_lockedwait failed, then we were probably reawakened by a signal. In + * this case, net_lockedwait will have set errno appropriately. + */ + + if (result < 0) + { + return -save_errno; + } + + return pstate->ir_recvlen; +} + +/**************************************************************************** + * Name: ieee802154_recvfrom_rxnotify + * + * Description: + * Notify the appropriate device driver that we are ready to receive an + * IEEE 802.1.5.4 frame + * + * Parameters: + * conn - The PF_IEEE802154 connection structure + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if 0 /* Not implemented */ +static void ieee802154_recvfrom_rxnotify(FAR struct ieee802154_conn_s *conn) +{ +# warning Missing logic +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_recvfrom + * + * Description: + * Implements the socket recvfrom interface for the case of the AF_INET + * and AF_INET6 address families. ieee802154_recvfrom() receives messages from + * a socket, and may be used to receive data on a socket whether or not it + * is connection-oriented. + * + * If 'from' is not NULL, and the underlying protocol provides the source + * address, this source address is filled in. The argument 'fromlen' is + * initialized to the size of the buffer associated with from, and + * modified on return to indicate the actual size of the address stored + * there. + * + * Parameters: + * psock A pointer to a NuttX-specific, internal socket structure + * buf Buffer to receive data + * len Length of buffer + * flags Receive flags + * from Address of source (may be NULL) + * fromlen The length of the address structure + * + * Returned Value: + * On success, returns the number of characters received. If no data is + * available to be received and the peer has performed an orderly shutdown, + * recv() will return 0. Otherwise, on errors, a negated errno value is + * returned (see recvfrom() for the list of appropriate error values). + * + ****************************************************************************/ + +ssize_t ieee802154_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, + int flags, FAR struct sockaddr *from, + FAR socklen_t *fromlen) +{ + FAR struct ieee802154_conn_s *conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + FAR struct radio_driver_s *radio; + struct ieee802154_recvfrom_s state; + ssize_t ret; + + /* If a 'from' address has been provided, verify that it is large + * enough to hold this address family. + */ + + if (from != NULL && *fromlen < sizeof(sa_family_t)) + { + return -EINVAL; + } + + if (psock->s_type != SOCK_DGRAM) + { + nerr("ERROR: Unsupported socket type: %d\n", psock->s_type); + ret = -ENOSYS; + } + + /* Perform the packet recvfrom() operation */ + + /* Initialize the state structure. This is done with interrupts + * disabled because we don't want anything to happen until we + * are ready. + */ + + net_lock(); + ieee802154_recvfrom_initialize(psock, buf, len, from, fromlen, &state); + + /* Get the device driver that will service this transfer */ + + radio = ieee802154_find_device(conn, &conn->laddr); + if (radio == NULL) + { + ret = -ENODEV; + goto errout_with_state; + } + + /* TODO ieee802154_recvfrom_initialize() expects from to be of type + * sockaddr_in, but in our case is sockaddr_ll + */ + +#if 0 + ret = ieee802154_connect(conn, NULL); + if (ret < 0) + { + goto errout_with_state; + } +#endif + + /* Set the socket state to receiving */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_RECV); + + /* Set up the callback in the connection */ + + state.ir_cb = ieee802154_callback_alloc(&radio->r_dev, conn); + if (state.ir_cb) + { + state.ir_cb->flags = (IEEE802154_NEWDATA | IEEE802154_POLL); + state.ir_cb->priv = (FAR void *)&state; + state.ir_cb->event = ieee802154_recvfrom_interrupt; + + /* Notify the device driver of the receive call */ + +#if 0 /* Not implemented */ + ieee802154_recvfrom_rxnotify(conn); +#endif + + /* Wait for either the receive to complete or for an error/timeout to + * occur. NOTES: (1) net_lockedwait will also terminate if a signal + * is received, (2) interrupts are disabled! They will be re-enabled + * while the task sleeps and automatically re-enabled when the task + & restarts. + */ + + ret = net_lockedwait(&state.ir_sem); + + /* Make sure that no further interrupts are processed */ + + ieee802154_callback_free(&radio->r_dev, conn, state.ir_cb); + ret = ieee802154_recvfrom_result(ret, &state); + } + else + { + ret = -EBUSY; + } + + /* Set the socket state to idle */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); + +errout_with_state: + net_unlock(); + ieee802154_recvfrom_uninitialize(&state); + return ret; +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_sendto.c b/net/ieee802154/ieee802154_sendto.c new file mode 100644 index 00000000000..d101dc5169c --- /dev/null +++ b/net/ieee802154/ieee802154_sendto.c @@ -0,0 +1,318 @@ +/**************************************************************************** + * net/ieee802154/ieee802154_sendto.c + * + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "netdev/netdev.h" +#include "devif/devif.h" +#include "socket/socket.h" +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure holds the state of the send operation until it can be + * operated upon from the interrupt level. + */ + +struct send_s +{ + FAR struct socket *snd_sock; /* Points to the parent socket structure */ + FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */ + sem_t snd_sem; /* Used to wake up the waiting thread */ + FAR const uint8_t *snd_buffer; /* Points to the buffer of data to send */ + size_t snd_buflen; /* Number of bytes in the buffer to send */ + ssize_t snd_sent; /* The number of bytes sent */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: psock_send_interrupt + ****************************************************************************/ + +static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev, + FAR void *pvconn, + FAR void *pvpriv, uint16_t flags) +{ + FAR struct send_s *pstate; + FAR struct radio_driver_s *radio; + + DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL); + + /* Ignore polls from non IEEE 802.15.4 network drivers */ + + if (dev->d_lltype != NET_LL_IEEE802154) + { + return flags; + } + + /* Make sure that this is the driver to which the socket is connected. */ +#warning Missing logic + + pstate = (FAR struct send_s *)pvpriv; + radio = (FAR struct radio_driver_s *)dev; + + ninfo("flags: %04x sent: %d\n", flags, pstate->snd_sent); + + if (pstate) + { + /* Check if the outgoing packet is available. It may have been claimed + * by a send interrupt serving a different thread -OR- if the output + * buffer currently contains unprocessed incoming data. In these cases + * we will just have to wait for the next polling cycle. + */ + + if (radio->r_dev.d_sndlen > 0 || (flags & PKT_NEWDATA) != 0) + { + /* Another thread has beat us sending data or the buffer is busy, + * Check for a timeout. If not timed out, wait for the next + * polling cycle and check again. + */ + + /* No timeout. Just wait for the next polling cycle */ + + return flags; + } + + /* It looks like we are good to send the data */ + + else + { + /* Copy the packet data into the device packet buffer and send it */ +#warning Missing logic + //devif_ieee802154_send(radio, pstate->snd_buffer, pstate->snd_buflen); + pstate->snd_sent = pstate->snd_buflen; + + /* Make sure no ARP request overwrites this ARP request. This + * flag will be cleared in arp_out(). + */ + + IFF_SET_NOARP(radio->r_dev.d_flags); + } + + /* Don't allow any further call backs. */ + + pstate->snd_cb->flags = 0; + pstate->snd_cb->priv = NULL; + pstate->snd_cb->event = NULL; + + /* Wake up the waiting thread */ + + sem_post(&pstate->snd_sem); + } + + return flags; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: psock_ieee802154_sendto + * + * Description: + * If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) + * socket, the parameters to and 'tolen' are ignored (and the error EISCONN + * may be returned when they are not NULL and 0), and the error ENOTCONN is + * returned when the socket was not actually connected. + * + * Parameters: + * psock A pointer to a NuttX-specific, internal socket structure + * buf Data to send + * len Length of data to send + * flags Send flags + * to Address of recipient + * tolen The length of the address structure + * + * Returned Value: + * On success, returns the number of characters sent. On error, + * -1 is returned, and errno is set appropriately. See sendto() + * for the complete list of return values. + * + ****************************************************************************/ + +ssize_t psock_ieee802154_sendto(FAR struct socket *psock, FAR const void *buf, + size_t len, int flags, + FAR const struct sockaddr *to, socklen_t tolen) +{ + FAR struct radio_driver_s *radio; + FAR struct ieee802154_conn_s *conn; + struct send_s state; + int errcode; + int ret = OK; + + /* Verify that the sockfd corresponds to valid, allocated socket */ + + if (psock == NULL || psock->s_crefs <= 0) + { + errcode = EBADF; + goto errout; + } + + conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + DEBUGASSERT(conn != NULL); + + /* Get the device driver that will service this transfer */ + + radio = ieee802154_find_device(conn, &conn->laddr); + if (radio == NULL) + { + errcode = ENODEV; + goto errout; + } + + /* Set the socket state to sending */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); + + /* Perform the send operation */ + + /* Initialize the state structure. This is done with interrupts + * disabled because we don't want anything to happen until we + * are ready. + */ + + net_lock(); + memset(&state, 0, sizeof(struct send_s)); + + /* This semaphore is used for signaling and, hence, should not have + * priority inheritance enabled. + */ + + (void)sem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */ + (void)sem_setprotocol(&state.snd_sem, SEM_PRIO_NONE); + + state.snd_sock = psock; /* Socket descriptor to use */ + state.snd_buflen = len; /* Number of bytes to send */ + state.snd_buffer = buf; /* Buffer to send from */ + + if (len > 0) + { + /* Allocate resource to receive a callback */ + + state.snd_cb = ieee802154_callback_alloc(&radio->r_dev, conn); + if (state.snd_cb) + { + /* Set up the callback in the connection */ + + state.snd_cb->flags = PKT_POLL; + state.snd_cb->priv = (FAR void *)&state; + state.snd_cb->event = psock_send_interrupt; + + /* Notify the device driver that new TX data is available. */ + + netdev_txnotify_dev(&radio->r_dev); + + /* Wait for the send to complete or an error to occur: NOTES: (1) + * net_lockedwait will also terminate if a signal is received, (2) + * interrupts may be disabled! They will be re-enabled while the + * task sleeps and automatically re-enabled when the task restarts. + */ + + ret = net_lockedwait(&state.snd_sem); + + /* Make sure that no further interrupts are processed */ + + ieee802154_callback_free(&radio->r_dev, conn, state.snd_cb); + } + } + + sem_destroy(&state.snd_sem); + net_unlock(); + + /* Set the socket state to idle */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); + + /* Check for a errors, Errors are signalled by negative errno values + * for the send length + */ + + if (state.snd_sent < 0) + { + errcode = state.snd_sent; + goto errout; + } + + /* If net_lockedwait failed, then we were probably reawakened by a signal. In + * this case, net_lockedwait will have set errno appropriately. + */ + + if (ret < 0) + { + errcode = -ret; + goto errout; + } + + /* Return the number of bytes actually sent */ + + return state.snd_sent; + +errout: + set_errno(errcode); + return ERROR; +} + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/ieee802154/ieee802154_sockif.c b/net/ieee802154/ieee802154_sockif.c new file mode 100644 index 00000000000..8624c0fe04b --- /dev/null +++ b/net/ieee802154/ieee802154_sockif.c @@ -0,0 +1,705 @@ +/**************************************************************************** + * net/socket/ieee802154_sockif.c + * + * 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 NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ieee802154/ieee802154.h" + +#ifdef CONFIG_NET_IEEE802154 + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int ieee802154_setup(FAR struct socket *psock, int protocol); +static sockcaps_t ieee802154_sockcaps(FAR struct socket *psock); +static void ieee802154_addref(FAR struct socket *psock); +static int ieee802154_bind(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen); +static int ieee802154_getsockname(FAR struct socket *psock, + FAR struct sockaddr *addr, FAR socklen_t *addrlen); +static int ieee802154_listen(FAR struct socket *psock, int backlog); +static int ieee802154_connect(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen); +static int ieee802154_accept(FAR struct socket *psock, + FAR struct sockaddr *addr, FAR socklen_t *addrlen, + FAR struct socket *newsock); +#ifndef CONFIG_DISABLE_POLL +static int ieee802154_poll_local(FAR struct socket *psock, + FAR struct pollfd *fds, bool setup); +#endif +static ssize_t ieee802154_send(FAR struct socket *psock, + FAR const void *buf, size_t len, int flags); +static ssize_t ieee802154_sendto(FAR struct socket *psock, + FAR const void *buf, size_t len, int flags, + FAR const struct sockaddr *to, socklen_t tolen); +static int ieee802154_close(FAR struct socket *psock); + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +const struct sock_intf_s g_ieee802154_sockif = +{ + ieee802154_setup, /* si_setup */ + ieee802154_sockcaps, /* si_sockcaps */ + ieee802154_addref, /* si_addref */ + ieee802154_bind, /* si_bind */ + ieee802154_getsockname, /* si_getsockname */ + ieee802154_listen, /* si_listen */ + ieee802154_connect, /* si_connect */ + ieee802154_accept, /* si_accept */ +#ifndef CONFIG_DISABLE_POLL + ieee802154_poll_local, /* si_poll */ +#endif + ieee802154_send, /* si_send */ + ieee802154_sendto, /* si_sendto */ +#ifdef CONFIG_NET_SENDFILE + NULL, /* si_sendfile */ +#endif + ieee802154_recvfrom, /* si_recvfrom */ + ieee802154_close /* si_close */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_sockif_alloc + * + * Description: + * Allocate and attach a PF_IEEE802154 connection structure. + * + ****************************************************************************/ + +static int ieee802154_sockif_alloc(FAR struct socket *psock) +{ + /* Allocate the packet socket connection structure and save in the new + * socket instance. + */ + + FAR struct ieee802154_conn_s *conn = ieee802154_alloc(); + if (conn == NULL) + { + /* Failed to reserve a connection structure */ + + return -ENOMEM; + } + + /* Set the reference count on the connection structure. This reference + * count will be incremented only if the socket is dup'ed + */ + + DEBUGASSERT(conn->crefs == 0); + conn->crefs = 1; + + /* Save the pre-allocated connection in the socket structure */ + + psock->s_conn = conn; + return OK; +} + +/**************************************************************************** + * Name: ieee802154_setup + * + * Description: + * Called for socket() to verify that the provided socket type and + * protocol are usable by this address family. Perform any family- + * specific socket fields. + * + * Parameters: + * psock A pointer to a user allocated socket structure to be + * initialized. + * protocol (see sys/socket.h) + * + * Returned Value: + * Zero (OK) is returned on success. Otherwise, a negater errno value is + * returned. + * + ****************************************************************************/ + +static int ieee802154_setup(FAR struct socket *psock, int protocol) +{ + /* Allocate the appropriate connection structure. This reserves the + * the connection structure is is unallocated at this point. It will + * not actually be initialized until the socket is connected. + * + * Only SOCK_DGRAM is supported (since the MAC header is stripped) + */ + + if (psock->s_type == SOCK_DGRAM) + { + return ieee802154_sockif_alloc(psock); + } + else + { + return -EPROTONOSUPPORT; + } +} + +/**************************************************************************** + * Name: ieee802154_sockcaps + * + * Description: + * Return the bit encoded capabilities of this socket. + * + * Parameters: + * psock - Socket structure of the socket whose capabilities are being + * queried. + * + * Returned Value: + * The set of socket cababilities is returned. + * + ****************************************************************************/ + +static sockcaps_t ieee802154_sockcaps(FAR struct socket *psock) +{ + return 0; +} + +/**************************************************************************** + * Name: ieee802154_addref + * + * Description: + * Increment the refernce count on the underlying connection structure. + * + * Parameters: + * psock - Socket structure of the socket whose reference count will be + * incremented. + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void ieee802154_addref(FAR struct socket *psock) +{ + FAR struct ieee802154_conn_s *conn; + + DEBUGASSERT(psock != NULL && psock->s_conn != NULL && + psock->s_type == SOCK_DGRAM); + + conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255); + conn->crefs++; +} + +/**************************************************************************** + * Name: ieee802154_connect + * + * Description: + * ieee802154_connect() connects the local socket referred to by the structure + * 'psock' to the address specified by 'addr'. The addrlen argument + * specifies the size of 'addr'. The format of the address in 'addr' is + * determined by the address space of the socket 'psock'. + * + * If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address + * to which datagrams are sent by default, and the only address from which + * datagrams are received. If the socket is of type SOCK_STREAM or + * SOCK_SEQPACKET, this call attempts to make a connection to the socket + * that is bound to the address specified by 'addr'. + * + * Generally, connection-based protocol sockets may successfully + * ieee802154_connect() only once; connectionless protocol sockets may use + * ieee802154_connect() multiple times to change their association. + * Connectionless sockets may dissolve the association by connecting to + * an address with the sa_family member of sockaddr set to AF_UNSPEC. + * + * Parameters: + * psock Pointer to a socket structure initialized by psock_socket() + * addr Server address (form depends on type of socket) + * addrlen Length of actual 'addr' + * + * Returned Value: + * 0 on success; a negated errno value on failue. See connect() for the + * list of appropriate errno values to be returned. + * + ****************************************************************************/ + +static int ieee802154_connect(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen) +{ + return -EAFNOSUPPORT; +} + +/**************************************************************************** + * Name: ieee802154_accept + * + * Description: + * The ieee802154_accept function is used with connection-based socket types + * (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM). It extracts the first + * connection request on the queue of pending connections, creates a new + * connected socket with mostly the same properties as 'sockfd', and + * allocates a new socket descriptor for the socket, which is returned. The + * newly created socket is no longer in the listening state. The original + * socket 'sockfd' is unaffected by this call. Per file descriptor flags + * are not inherited across an ieee802154_accept. + * + * The 'sockfd' argument is a socket descriptor that has been created with + * socket(), bound to a local address with bind(), and is listening for + * connections after a call to listen(). + * + * On return, the 'addr' structure is filled in with the address of the + * connecting entity. The 'addrlen' argument initially contains the size + * of the structure pointed to by 'addr'; on return it will contain the + * actual length of the address returned. + * + * If no pending connections are present on the queue, and the socket is + * not marked as non-blocking, ieee802154_accept blocks the caller until a + * connection is present. If the socket is marked non-blocking and no + * pending connections are present on the queue, ieee802154_accept returns + * EAGAIN. + * + * Parameters: + * psock Reference to the listening socket structure + * addr Receives the address of the connecting client + * addrlen Input: allocated size of 'addr', Return: returned size of 'addr' + * newsock Location to return the accepted socket information. + * + * Returned Value: + * Returns 0 (OK) on success. On failure, it returns a negated errno + * value. See accept() for a desrciption of the approriate error value. + * + ****************************************************************************/ + +static int ieee802154_accept(FAR struct socket *psock, + FAR struct sockaddr *addr, + FAR socklen_t *addrlen, + FAR struct socket *newsock) +{ + return -EAFNOSUPPORT; +} + +/**************************************************************************** + * Name: ieee802154_bind + * + * Description: + * ieee802154_bind() gives the socket 'psock' the local address 'addr'. + * 'addr' is 'addrlen' bytes long. Traditionally, this is called + * "assigning a name to a socket." When a socket is created with + * socket(), it exists in a name space (address family) but has no name + * assigned. + * + * Parameters: + * psock Socket structure of the socket to bind + * addr Socket local address + * addrlen Length of 'addr' + * + * Returned Value: + * 0 on success; A negated errno value is returned on failure. See + * bind() for a list a appropriate error values. + * + ****************************************************************************/ + +static int ieee802154_bind(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen) +{ + FAR const struct sockaddr_ieee802154_s *iaddr; + FAR struct radio_driver_s *radio; + FAR struct ieee802154_conn_s *conn; + + DEBUGASSERT(psock != NULL && addr != NULL); + + /* Verify that a valid address has been provided */ + + if (addr->sa_family != AF_IEEE802154 || + addrlen < sizeof(struct sockaddr_ieee802154_s)) + { + nerr("ERROR: Invalid family: %u or address length: %d < %d\n", + addr->sa_family, addrlen, sizeof(struct sockaddr_ll)); + return -EBADF; + } + + /* Bind a PF_IEEE802154 socket to an network device. */ + + if (psock->s_type != SOCK_DGRAM) + { + nerr("ERROR: Invalid socket type: %u\n", psock->s_type); + return -EBADF; + } + + /* Verify that the socket is not already bound. */ + + if (_SS_ISBOUND(psock->s_flags)) + { + nerr("ERROR: Already bound\n"); + return -EINVAL; + } + + iaddr = (FAR const struct sockaddr_ieee802154_s *)addr; + + /* Very that some address was provided */ + /* REVISIT: Currently and explict address must be assigned. Should we + * support some moral equivalent to INADDR_ANY? + */ + + if (iaddr->sa_addr.s_mode == IEEE802154_ADDRMODE_NONE) + { + nerr("ERROR: No address provided\n"); + return -EADDRNOTAVAIL; + } + + conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + + /* Find the device associated with the requested address */ + + radio = ieee802154_find_device(conn, &iaddr->sa_addr); + if (radio == NULL) + { + nerr("ERROR: No radio at this address\n"); + return -ENODEV; + } + + /* Save the address as the socket's local address */ + + memcpy(&conn->laddr, &iaddr->sa_addr, sizeof(struct ieee802154_saddr_s)); + + /* Mark the socket bound */ + + psock->s_flags |= _SF_BOUND; + return OK; +} + +/**************************************************************************** + * Name: ieee802154_getsockname + * + * Description: + * The ieee802154_getsockname() function retrieves the locally-bound name of the + * specified packet socket, stores this address in the sockaddr structure + * pointed to by the 'addr' argument, and stores the length of this + * address in the object pointed to by the 'addrlen' argument. + * + * If the actual length of the address is greater than the length of the + * supplied sockaddr structure, the stored address will be truncated. + * + * If the socket has not been bound to a local name, the value stored in + * the object pointed to by address is unspecified. + * + * Parameters: + * psock Socket structure of the socket to be queried + * addr sockaddr structure to receive data [out] + * addrlen Length of sockaddr structure [in/out] + * + * Returned Value: + * On success, 0 is returned, the 'addr' argument points to the address + * of the socket, and the 'addrlen' argument points to the length of the + * address. Otherwise, a negated errno value is returned. See + * getsockname() for the list of appropriate error numbers. + * + ****************************************************************************/ + +static int ieee802154_getsockname(FAR struct socket *psock, + FAR struct sockaddr *addr, FAR + socklen_t *addrlen) +{ + FAR struct ieee802154_conn_s *conn; + FAR struct sockaddr_ieee802154_s tmp; + socklen_t copylen; + + DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL); + + conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + DEBUGASSERT(conn != NULL); + + /* Create a copy of the full address on the stack */ + + tmp.sa_family = PF_IEEE802154; + memcpy(&tmp.sa_addr, &conn->laddr, sizeof(struct ieee802154_saddr_s)); + + /* Copy to the user buffer, truncating if necessary */ + + copylen = sizeof(struct sockaddr_ieee802154_s); + if (copylen > *addrlen) + { + copylen = *addrlen; + } + + memcpy(addr, &tmp, copylen); + + /* Return the actual size transferred */ + + *addrlen = copylen; + return OK; +} + +/**************************************************************************** + * Name: ieee802154_listen + * + * Description: + * To accept connections, a socket is first created with psock_socket(), a + * willingness to accept incoming connections and a queue limit for + * incoming connections are specified with psock_listen(), and then the + * connections are accepted with psock_accept(). For the case of + * PF_IEEE802154 sockets, psock_listen() calls this function. The listen() + * call does not apply only to PF_IEEE802154 sockets. + * + * Parameters: + * psock Reference to an internal, boound socket structure. + * backlog The maximum length the queue of pending connections may grow. + * If a connection request arrives with the queue full, the client + * may receive an error with an indication of ECONNREFUSED or, + * if the underlying protocol supports retransmission, the request + * may be ignored so that retries succeed. + * + * Returned Value: + * On success, zero is returned. On error, a negated errno value is + * returned. See list() for the set of appropriate error values. + * + ****************************************************************************/ + +int ieee802154_listen(FAR struct socket *psock, int backlog) +{ + return -EOPNOTSUPP; +} + +/**************************************************************************** + * Name: ieee802154_poll + * + * Description: + * The standard poll() operation redirects operations on socket descriptors + * to net_poll which, indiectly, calls to function. + * + * Input Parameters: + * psock - An instance of the internal socket structure. + * fds - The structure describing the events to be monitored, OR NULL if + * this is a request to stop monitoring events. + * setup - true: Setup up the poll; false: Teardown the poll + * + * Returned Value: + * 0: Success; Negated errno on failure + * + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_POLL +static int ieee802154_poll_local(FAR struct socket *psock, + FAR struct pollfd *fds, bool setup) +{ + /* We should need to support some kind of write ahead buffering for this + * feature. + */ + +#warning Missing logic + return -ENOSYS; +} +#endif /* !CONFIG_DISABLE_POLL */ + +/**************************************************************************** + * Name: ieee802154_send + * + * Description: + * Socket send() method for the PF_IEEE802154 socket. + * + * Parameters: + * psock An instance of the internal socket structure. + * buf Data to send + * len Length of data to send + * flags Send flags + * + * Returned Value: + * On success, returns the number of characters sent. On error, a negated + * errno value is returned (see send() for the list of appropriate error + * values. + * + ****************************************************************************/ + +static ssize_t ieee802154_send(FAR struct socket *psock, FAR const void *buf, + size_t len, int flags) +{ + struct sockaddr_ieee802154_s to; + FAR struct ieee802154_conn_s *conn; + ssize_t ret; + + DEBUGASSERT(psock != NULL || buf != NULL); + conn = (FAR struct ieee802154_conn_s *)psock->s_conn; + DEBUGASSERT(conn != NULL); + + /* Only SOCK_DGRAM is supported (because the MAC header is stripped) */ + + if (psock->s_type == SOCK_DGRAM) + { + /* send() may be used only if the socket is has been connected. */ + + if (!_SS_ISCONNECTED( psock->s_flags) || + conn->raddr.s_mode == IEEE802154_ADDRMODE_NONE) + { + ret = -ENOTCONN; + } + else + { + to.sa_family = PF_IEEE802154; + memcpy(&to.sa_addr, &conn->raddr, + sizeof(struct ieee802154_saddr_s)); + + /* Then perform the send() as sendto() */ + + ret = psock_ieee802154_sendto(psock, buf, len, flags, + (FAR const struct sockaddr *)&to, + sizeof(struct sockaddr_ieee802154_s)); + } + } + else + { + /* EDESTADDRREQ. Signifies that the socket is not connection-mode and + * no peer address is set. + */ + + ret = -EDESTADDRREQ; + } + + return ret; +} + +/**************************************************************************** + * Name: ieee802154_sendto + * + * Description: + * Implements the sendto() operation for the case of the PF_IEEE802154 + * socket. + * + * Parameters: + * psock A pointer to a NuttX-specific, internal socket structure + * buf Data to send + * len Length of data to send + * flags Send flags + * to Address of recipient + * tolen The length of the address structure + * + * Returned Value: + * On success, returns the number of characters sent. On error, a negated + * errno value is returned (see send_to() for the list of appropriate error + * values. + * + ****************************************************************************/ + +static ssize_t ieee802154_sendto(FAR struct socket *psock, FAR const void *buf, + size_t len, int flags, + FAR const struct sockaddr *to, socklen_t tolen) +{ + ssize_t ret; + + /* Only SOCK_DGRAM is supported (because the MAC header is stripped) */ + + if (psock->s_type == SOCK_DGRAM) + { + /* Raw packet send */ + + ret = psock_ieee802154_sendto(psock, buf, len, flags, to, tolen); + } + else + { + /* EDESTADDRREQ. Signifies that the socket is not connection-mode and + * no peer address is set. + */ + + ret = -EDESTADDRREQ; + } + + return ret; +} + +/**************************************************************************** + * Name: ieee802154_close + * + * Description: + * Performs the close operation on a PF_IEEE802154 socket instance + * + * Parameters: + * psock Socket instance + * + * Returned Value: + * 0 on success; a negated errno value is returned on any failure. + * + * Assumptions: + * + ****************************************************************************/ + +static int ieee802154_close(FAR struct socket *psock) +{ + /* Perform some pre-close operations for the PF_IEEE802154 address type */ + + switch (psock->s_type) + { + case SOCK_DGRAM: + { + FAR struct ieee802154_conn_s *conn = psock->s_conn; + + /* Is this the last reference to the connection structure (there + * could be more if the socket was dup'ed). + */ + + if (conn->crefs <= 1) + { + /* Yes... free the connection structure */ + + conn->crefs = 0; /* No more references on the connection */ + ieee802154_free(psock->s_conn); /* Free network resources */ + } + else + { + /* No.. Just decrement the reference count */ + + conn->crefs--; + } + + return OK; + } + + default: + return -EBADF; + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_NET_IEEE802154 */ diff --git a/net/net_initialize.c b/net/net_initialize.c index 597aaeb717c..4dc8ea47a72 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -54,6 +54,7 @@ #include "tcp/tcp.h" #include "udp/udp.h" #include "pkt/pkt.h" +#include "ieee802154/ieee802154.h" #include "local/local.h" #include "igmp/igmp.h" #include "route/route.h" @@ -125,6 +126,12 @@ void net_setup(void) pkt_initialize(); #endif +#ifdef CONFIG_NET_IEEE802154 + /* Initialize IEEE 802.15.4 socket support */ + + ieee802154_initialize(); +#endif + #ifdef CONFIG_NET_LOCAL /* Initialize the local, "Unix domain" socket support */ diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 6f5d5cd9903..ff38ed0e0d2 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -833,8 +833,8 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd, { req->ifr_hwaddr.sa_family = AF_INETX; memcpy(req->ifr_hwaddr.sa_data, - dev->d_mac.sixlowpan.nv_addr, - dev->d_mac.sixlowpan.nv_addrlen); + dev->d_mac.radio.nv_addr, + dev->d_mac.radio.nv_addrlen); ret = OK; } else @@ -865,19 +865,19 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd, if (dev->d_lltype == NET_LL_IEEE802154 || dev->d_lltype == NET_LL_PKTRADIO) { - FAR struct sixlowpan_driver_s *radio; + FAR struct radio_driver_s *radio; struct sixlowpan_properties_s properties; /* Get the radio properties */ - radio = (FAR struct sixlowpan_driver_s *)dev; + radio = (FAR struct radio_driver_s *)dev; DEBUGASSERT(radio->r_properties != NULL); ret = radio->r_properties(radio, &properties); if (ret >= 0) { - dev->d_mac.sixlowpan.nv_addrlen = properties.sp_addrlen; - memcpy(dev->d_mac.sixlowpan.nv_addr, + dev->d_mac.radio.nv_addrlen = properties.sp_addrlen; + memcpy(dev->d_mac.radio.nv_addr, req->ifr_hwaddr.sa_data, NET_6LOWPAN_ADDRSIZE); } } diff --git a/net/netdev/netdev_lladdrsize.c b/net/netdev/netdev_lladdrsize.c index e5470837c38..10fa3460145 100644 --- a/net/netdev/netdev_lladdrsize.c +++ b/net/netdev/netdev_lladdrsize.c @@ -75,7 +75,7 @@ #if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_WIRELESS_PKTRADIO) static inline int netdev_pktradio_addrlen(FAR struct net_driver_s *dev) { - FAR struct sixlowpan_driver_s *radio = (FAR struct sixlowpan_driver_s *)dev; + FAR struct radio_driver_s *radio = (FAR struct radio_driver_s *)dev; struct sixlowpan_properties_s properties; int ret; diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index fe195148afd..a39772022e2 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -78,8 +78,6 @@ void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn) { - ninfo("IN\n"); - /* Verify that the packet connection is valid */ if (conn) diff --git a/net/pkt/pkt_recvfrom.c b/net/pkt/pkt_recvfrom.c index e7075fccaa5..63bbf76748f 100644 --- a/net/pkt/pkt_recvfrom.c +++ b/net/pkt/pkt_recvfrom.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/socket/pkt_recvfrom.c + * net/pkt/pkt_recvfrom.c * * Copyright (C) 2007-2009, 2011-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 74323d1dc1c..0ec04f09474 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -120,7 +120,7 @@ static int netprocfs_6lowpan_linklayer(FAR struct netprocfs_file_s *netfile, DEBUGASSERT(netfile != NULL && netfile->dev != NULL); dev = netfile->dev; - addr = &dev->d_mac.sixlowpan; + addr = &dev->d_mac.radio; len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6LoWPAN HWaddr ", diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 004e4a75373..092b25fdf1e 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -210,7 +210,7 @@ static uint16_t sixlowpan_protosize(FAR const struct ipv6_hdr_s *ipv6hdr, ****************************************************************************/ #ifdef CONFIG_WIRELESS_IEEE802154 -static int sixlowpan_ieee802154_metadata(FAR struct sixlowpan_driver_s *radio, +static int sixlowpan_ieee802154_metadata(FAR struct radio_driver_s *radio, FAR const struct netdev_varaddr_s *destmac, FAR union sixlowpan_metadata_u *meta) { @@ -250,10 +250,10 @@ static int sixlowpan_ieee802154_metadata(FAR struct sixlowpan_driver_s *radio, #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR pktmeta.sextended = TRUE; sixlowpan_eaddrcopy(pktmeta.source.nm_addr, - &radio->r_dev.d_mac.sixlowpan.nv_addr); + &radio->r_dev.d_mac.radio.nv_addr); #else sixlowpan_saddrcopy(pktmeta.source.nm_addr, - &radio->r_dev.d_mac.sixlowpan.nv_addr); + &radio->r_dev.d_mac.radio.nv_addr); #endif /* Copy the destination node address into the meta data */ @@ -309,7 +309,7 @@ static int sixlowpan_ieee802154_metadata(FAR struct sixlowpan_driver_s *radio, ****************************************************************************/ #ifdef CONFIG_WIRELESS_PKTRADIO -static int sixlowpan_pktradio_metadata(FAR struct sixlowpan_driver_s *radio, +static int sixlowpan_pktradio_metadata(FAR struct radio_driver_s *radio, FAR const struct netdev_varaddr_s *destmac, FAR union sixlowpan_metadata_u *meta) { @@ -321,10 +321,10 @@ static int sixlowpan_pktradio_metadata(FAR struct sixlowpan_driver_s *radio, /* Set the source address */ - pktmeta->pm_src.pa_addrlen = radio->r_dev.d_mac.sixlowpan.nv_addrlen; + pktmeta->pm_src.pa_addrlen = radio->r_dev.d_mac.radio.nv_addrlen; memcpy(pktmeta->pm_src.pa_addr, - radio->r_dev.d_mac.sixlowpan.nv_addr, - radio->r_dev.d_mac.sixlowpan.nv_addrlen); + radio->r_dev.d_mac.radio.nv_addr, + radio->r_dev.d_mac.radio.nv_addrlen); /* Set the destination address. * REVISIT: Do we need to check for multicast or broadcast addresses @@ -373,7 +373,7 @@ static int sixlowpan_pktradio_metadata(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_queue_frames(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf, size_t buflen, FAR const struct netdev_varaddr_s *destmac) diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 961ed493ab6..e1503fa8911 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -151,7 +151,7 @@ static inline bool sixlowpan_eaddrnull(FAR const uint8_t *eaddr) ****************************************************************************/ #ifdef CONFIG_WIRELESS_IEEE802154 -int sixlowpan_meta_data(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_meta_data(FAR struct radio_driver_s *radio, FAR const struct ieee802_txmetadata_s *pktmeta, FAR struct ieee802154_frame_meta_s *meta, uint16_t paylen) @@ -258,7 +258,7 @@ int sixlowpan_meta_data(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_frame_hdrlen(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_frame_hdrlen(FAR struct radio_driver_s *radio, FAR const void *meta) { return radio->r_get_mhrlen(radio, meta); @@ -284,7 +284,7 @@ int sixlowpan_frame_hdrlen(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_frame_submit(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_frame_submit(FAR struct radio_driver_s *radio, FAR const void *meta, FAR struct iob_s *frame) { return radio->r_req_data(radio, meta, frame); diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 6cb5c623d0d..1f7f1fb741b 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -623,7 +623,7 @@ void sixlowpan_hc06_initialize(void) * ****************************************************************************/ -int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const struct netdev_varaddr_s *destmac, FAR uint8_t *fptr) @@ -794,7 +794,7 @@ int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, /* Compression compare with this nodes address (source) */ iphc1 |= compress_laddr(ipv6->srcipaddr, - &radio->r_dev.d_mac.sixlowpan, + &radio->r_dev.d_mac.radio, SIXLOWPAN_IPHC_SAM_BIT); } @@ -805,7 +805,7 @@ int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, ipv6->srcipaddr[3] == 0) { iphc1 |= compress_laddr(ipv6->srcipaddr, - &radio->r_dev.d_mac.sixlowpan, + &radio->r_dev.d_mac.radio, SIXLOWPAN_IPHC_SAM_BIT); } else @@ -1037,7 +1037,7 @@ int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -void sixlowpan_uncompresshdr_hc06(FAR struct sixlowpan_driver_s *radio, +void sixlowpan_uncompresshdr_hc06(FAR struct radio_driver_s *radio, FAR const void *metadata, uint16_t iplen, FAR struct iob_s *iob, FAR uint8_t *fptr, FAR uint8_t *bptr) diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index ef7ef40a329..b732ef857d2 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -120,7 +120,7 @@ * ****************************************************************************/ -int sixlowpan_compresshdr_hc1(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_compresshdr_hc1(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const struct netdev_varaddr_s *destmac, FAR uint8_t *fptr) @@ -132,7 +132,7 @@ int sixlowpan_compresshdr_hc1(FAR struct sixlowpan_driver_s *radio, if (ipv6->vtc != 0x60 || ipv6->tcf != 0 || ipv6->flow != 0 || !sixlowpan_islinklocal(ipv6->srcipaddr) || - !sixlowpan_ismacbased(ipv6->srcipaddr, &radio->r_dev.d_mac.sixlowpan) || + !sixlowpan_ismacbased(ipv6->srcipaddr, &radio->r_dev.d_mac.radio) || !sixlowpan_islinklocal(ipv6->destipaddr) || !sixlowpan_ismacbased(ipv6->destipaddr, destmac) || ( 1 @@ -292,7 +292,7 @@ int sixlowpan_compresshdr_hc1(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_uncompresshdr_hc1(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_uncompresshdr_hc1(FAR struct radio_driver_s *radio, FAR const void *metadata, uint16_t iplen, FAR struct iob_s *iob, FAR uint8_t *fptr, FAR uint8_t *bptr) diff --git a/net/sixlowpan/sixlowpan_icmpv6send.c b/net/sixlowpan/sixlowpan_icmpv6send.c index 78bfbbe3466..179907f8359 100644 --- a/net/sixlowpan/sixlowpan_icmpv6send.c +++ b/net/sixlowpan/sixlowpan_icmpv6send.c @@ -117,7 +117,7 @@ void sixlowpan_icmpv6_send(FAR struct net_driver_s *dev, * assumes an encoding of the MAC address in the IPv6 address. */ - ret = sixlowpan_destaddrfromip((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev, ipv6icmpv6->ipv6.destipaddr, &destmac); if (ret < 0) { @@ -147,7 +147,7 @@ void sixlowpan_icmpv6_send(FAR struct net_driver_s *dev, buflen = dev->d_len - hdrlen; (void)sixlowpan_queue_frames( - (FAR struct sixlowpan_driver_s *)fwddev, + (FAR struct radio_driver_s *)fwddev, &ipv6icmpv6->ipv6, buf, buflen, &destmac); } } diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 5dde2df3b51..6b4177a8ace 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -147,7 +147,7 @@ static uint8_t g_bitbucket[UNCOMP_MAXHDR]; * ****************************************************************************/ -static bool sixlowpan_compare_fragsrc(FAR struct sixlowpan_driver_s *radio, +static bool sixlowpan_compare_fragsrc(FAR struct radio_driver_s *radio, FAR const void *metadata) { struct netdev_varaddr_s fragsrc; @@ -299,7 +299,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) * ****************************************************************************/ -static int sixlowpan_frame_process(FAR struct sixlowpan_driver_s *radio, +static int sixlowpan_frame_process(FAR struct radio_driver_s *radio, FAR const void *metadata, FAR struct iob_s *iob) { FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */ @@ -667,7 +667,7 @@ static int sixlowpan_frame_process(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -static int sixlowpan_dispatch(FAR struct sixlowpan_driver_s *radio) +static int sixlowpan_dispatch(FAR struct radio_driver_s *radio) { sixlowpan_dumpbuffer("Incoming packet", (FAR const uint8_t *)IPv6BUF(&radio->r_dev), @@ -763,7 +763,7 @@ static int sixlowpan_dispatch(FAR struct sixlowpan_driver_s *radio) * ****************************************************************************/ -int sixlowpan_input(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_input(FAR struct radio_driver_s *radio, FAR struct iob_s *framelist, FAR const void *metadata) { int ret = -EINVAL; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 1463de44c29..fb193465583 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 sixlowpan_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 */ @@ -301,7 +301,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev, ****************************************************************************/ #ifdef CONFIG_WIRELESS_IEEE802154 -int sixlowpan_meta_data(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_meta_data(FAR struct radio_driver_s *radio, FAR const struct ieee802_txmetadata_s *pktmeta, FAR struct ieee802154_frame_meta_s *meta, uint16_t paylen); @@ -325,7 +325,7 @@ int sixlowpan_meta_data(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_frame_hdrlen(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_frame_hdrlen(FAR struct radio_driver_s *radio, FAR const void *meta); /**************************************************************************** @@ -348,7 +348,7 @@ int sixlowpan_frame_hdrlen(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_frame_submit(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_frame_submit(FAR struct radio_driver_s *radio, FAR const void *meta, FAR struct iob_s *frame); /**************************************************************************** @@ -383,7 +383,7 @@ int sixlowpan_frame_submit(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_queue_frames(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf, size_t buflen, FAR const struct netdev_varaddr_s *destmac); @@ -441,7 +441,7 @@ void sixlowpan_hc06_initialize(void); ****************************************************************************/ #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 -int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const struct netdev_varaddr_s *destmac, FAR uint8_t *fptr); @@ -479,7 +479,7 @@ int sixlowpan_compresshdr_hc06(FAR struct sixlowpan_driver_s *radio, ****************************************************************************/ #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 -void sixlowpan_uncompresshdr_hc06(FAR struct sixlowpan_driver_s *radio, +void sixlowpan_uncompresshdr_hc06(FAR struct radio_driver_s *radio, FAR const void *metadata, uint16_t iplen, FAR struct iob_s *iob, FAR uint8_t *fptr, FAR uint8_t *bptr); @@ -509,7 +509,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct sixlowpan_driver_s *radio, ****************************************************************************/ #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 -int sixlowpan_compresshdr_hc1(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_compresshdr_hc1(FAR struct radio_driver_s *radio, FAR const struct ipv6_hdr_s *ipv6, FAR const struct netdev_varaddr_s *destmac, FAR uint8_t *fptr); @@ -547,7 +547,7 @@ int sixlowpan_compresshdr_hc1(FAR struct sixlowpan_driver_s *radio, ****************************************************************************/ #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 -int sixlowpan_uncompresshdr_hc1(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_uncompresshdr_hc1(FAR struct radio_driver_s *radio, FAR const void *metadata, uint16_t iplen, FAR struct iob_s *iob, FAR uint8_t *fptr, FAR uint8_t *bptr); @@ -586,7 +586,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct sixlowpan_driver_s *radio, #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80)) -int sixlowpan_destaddrfromip(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio, const net_ipv6addr_t ipaddr, FAR struct netdev_varaddr_s *addr); @@ -613,7 +613,7 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, ****************************************************************************/ #ifdef CONFIG_WIRELESS_IEEE802154 -int sixlowpan_src_panid(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_src_panid(FAR struct radio_driver_s *radio, FAR uint8_t *panid); #endif @@ -634,7 +634,7 @@ int sixlowpan_src_panid(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_extract_srcaddr(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_extract_srcaddr(FAR struct radio_driver_s *radio, FAR const void *metadata, FAR struct netdev_varaddr_s *srcaddr); @@ -655,7 +655,7 @@ int sixlowpan_extract_srcaddr(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_extract_destaddr(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_extract_destaddr(FAR struct radio_driver_s *radio, FAR const void *metadata, FAR struct netdev_varaddr_s *destaddr); diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index ce429405dd6..a097a77f04e 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -193,7 +193,7 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev, /* Transfer the frame list to the IEEE802.15.4 MAC device */ sinfo->s_result = - sixlowpan_queue_frames((FAR struct sixlowpan_driver_s *)dev, + sixlowpan_queue_frames((FAR struct radio_driver_s *)dev, sinfo->s_ipv6hdr, sinfo->s_buf, sinfo->s_len, sinfo->s_destmac); diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index c4bbb0c69b5..77f517e1313 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -521,7 +521,7 @@ static uint16_t tcp_send_interrupt(FAR struct net_driver_s *dev, /* Transfer the frame list to the IEEE802.15.4 MAC device */ - ret = sixlowpan_queue_frames((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_queue_frames((FAR struct radio_driver_s *)dev, &ipv6tcp.ipv6, &sinfo->s_buf[sinfo->s_sent], sndlen, sinfo->s_destmac); @@ -827,7 +827,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, * an encoding of the MAC address in the IPv6 address. */ - ret = sixlowpan_destaddrfromip((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev, conn->u.ipv6.raddr, &destmac); if (ret < 0) { @@ -946,7 +946,7 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev, * assumes an encoding of the MAC address in the IPv6 address. */ - ret = sixlowpan_destaddrfromip((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev, ipv6hdr->ipv6.destipaddr, &destmac); if (ret < 0) { @@ -976,7 +976,7 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev, buflen = dev->d_len - hdrlen; (void)sixlowpan_queue_frames( - (FAR struct sixlowpan_driver_s *)fwddev, + (FAR struct radio_driver_s *)fwddev, &ipv6hdr->ipv6, buf, buflen, &destmac); } } diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 18661472ad3..818f5bfb6c7 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -295,7 +295,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, * encoding of the MAC address in the IPv6 address. */ - ret = sixlowpan_destaddrfromip((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev, to6->sin6_addr.in6_u.u6_addr16, &destmac); if (ret < 0) { @@ -471,7 +471,7 @@ void sixlowpan_udp_send(FAR struct net_driver_s *dev, * assumes an encoding of the MAC address in the IPv6 address. */ - ret = sixlowpan_destaddrfromip((FAR struct sixlowpan_driver_s *)dev, + ret = sixlowpan_destaddrfromip((FAR struct radio_driver_s *)dev, ipv6udp->ipv6.destipaddr, &destmac); if (ret < 0) { @@ -498,7 +498,7 @@ void sixlowpan_udp_send(FAR struct net_driver_s *dev, buflen = dev->d_len - hdrlen; (void)sixlowpan_queue_frames( - (FAR struct sixlowpan_driver_s *)fwddev, + (FAR struct radio_driver_s *)fwddev, &ipv6udp->ipv6, buf, buflen, &destmac); } } diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index bd9bb36722c..c3415374575 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -188,7 +188,7 @@ static void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *eadd * ****************************************************************************/ -int sixlowpan_destaddrfromip(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_destaddrfromip(FAR struct radio_driver_s *radio, const net_ipv6addr_t ipaddr, FAR struct netdev_varaddr_s *destaddr) { @@ -524,7 +524,7 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, ****************************************************************************/ #ifdef CONFIG_WIRELESS_IEEE802154 -int sixlowpan_src_panid(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_src_panid(FAR struct radio_driver_s *radio, FAR uint8_t *panid) { FAR struct net_driver_s *dev = &radio->r_dev; @@ -563,7 +563,7 @@ int sixlowpan_src_panid(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_extract_srcaddr(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_extract_srcaddr(FAR struct radio_driver_s *radio, FAR const void *metadata, FAR struct netdev_varaddr_s *srcaddr) { @@ -630,7 +630,7 @@ int sixlowpan_extract_srcaddr(FAR struct sixlowpan_driver_s *radio, * ****************************************************************************/ -int sixlowpan_extract_destaddr(FAR struct sixlowpan_driver_s *radio, +int sixlowpan_extract_destaddr(FAR struct radio_driver_s *radio, FAR const void *metadata, FAR struct netdev_varaddr_s *destaddr) { diff --git a/net/socket/net_sockif.c b/net/socket/net_sockif.c index 0a70d1e92db..07e496cbbbb 100644 --- a/net/socket/net_sockif.c +++ b/net/socket/net_sockif.c @@ -48,6 +48,7 @@ #include "inet/inet.h" #include "local/local.h" #include "pkt/pkt.h" +#include "ieee802154/ieee802154.h" #include "socket/socket.h" /**************************************************************************** @@ -100,6 +101,12 @@ FAR const struct sock_intf_s *net_sockif(sa_family_t family) break; #endif +#ifdef CONFIG_NET_IEEE802154 + case PF_IEEE802154: + sockif = &g_ieee802154_sockif; + break; +#endif + default: nerr("ERROR: Address family unsupported: %d\n", family); } diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 054cfb390b6..95dea9a137b 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -106,7 +106,7 @@ struct lo_driver_s /* This holds the information visible to the NuttX network */ - struct sixlowpan_driver_s lo_radio; /* Interface understood by the network */ + struct radio_driver_s lo_radio; /* Interface understood by the network */ }; /**************************************************************************** @@ -161,11 +161,11 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif -static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta); -static int lo_req_data(FAR struct sixlowpan_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 sixlowpan_driver_s *netdev, +static int lo_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties); /**************************************************************************** @@ -191,8 +191,8 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) { /* Set the MAC address as the eaddr */ - dev->d_mac.sixlowpan.nv_addrlen = NET_6LOWPAN_EADDRSIZE; - IEEE802154_EADDRCOPY(dev->d_mac.sixlowpan.nv_addr, g_eaddr); + dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_EADDRSIZE; + IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr, g_eaddr); /* Set the IP address based on the eaddr */ @@ -211,8 +211,8 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) { /* Set the MAC address as the saddr */ - dev->d_mac.sixlowpan.nv_addrlen = NET_6LOWPAN_SADDRSIZE; - IEEE802154_SADDRCOPY(dev->d_mac.sixlowpan.nv_addr, g_saddr); + dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + IEEE802154_SADDRCOPY(dev->d_mac.radio.nv_addr, g_saddr); /* Set the IP address based on the saddr */ @@ -482,14 +482,14 @@ static int lo_ifup(FAR struct net_driver_s *dev) #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1], - dev->d_mac.sixlowpan.nv_addr[2], dev->d_mac.sixlowpan.nv_addr[3], - dev->d_mac.sixlowpan.nv_addr[4], dev->d_mac.sixlowpan.nv_addr[5], - dev->d_mac.sixlowpan.nv_addr[6], dev->d_mac.sixlowpan.nv_addr[7], + 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 ninfo(" Node: %02x:%02x PANID=%02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1], + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1], priv->lo_panid[0], priv->lo_panid[1]); #endif @@ -811,7 +811,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta) { return MAC_HDRLEN; @@ -835,7 +835,7 @@ static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int lo_req_data(FAR struct sixlowpan_driver_s *netdev, +static int lo_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist) { FAR struct lo_driver_s *priv; @@ -905,7 +905,7 @@ static int lo_req_data(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int lo_properties(FAR struct sixlowpan_driver_s *netdev, +static int lo_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); @@ -969,7 +969,7 @@ static int lo_properties(FAR struct sixlowpan_driver_s *netdev, int ieee8021514_loopback(void) { FAR struct lo_driver_s *priv; - FAR struct sixlowpan_driver_s *radio; + FAR struct radio_driver_s *radio; FAR struct net_driver_s *dev; ninfo("Initializing\n"); diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 1a168832034..5f276f1fb01 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -121,7 +121,7 @@ struct macnet_driver_s { /* This holds the information visible to the NuttX network */ - struct sixlowpan_driver_s md_dev; /* Interface understood by the network */ + struct radio_driver_s md_dev; /* Interface understood by the network */ /* Cast compatible with struct macnet_driver_s */ /* For internal use by this driver */ @@ -169,10 +169,10 @@ static void macnet_txpoll_expiry(int argc, wdparm_t arg, ...); #ifdef CONFIG_NET_STARPOINT #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR -static int macnet_coord_eaddr(FAR struct sixlowpan_driver_s *radio, +static int macnet_coord_eaddr(FAR struct radio_driver_s *radio, FAR uint8_t *eaddr); #else -static int macnet_coord_saddr(FAR struct sixlowpan_driver_s *radio, +static int macnet_coord_saddr(FAR struct radio_driver_s *radio, FAR uint8_t *saddr); #endif #endif @@ -195,11 +195,11 @@ static int macnet_rmmac(FAR struct net_driver_s *dev, static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif -static int macnet_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int macnet_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta); -static int macnet_req_data(FAR struct sixlowpan_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 sixlowpan_driver_s *netdev, +static int macnet_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties); /**************************************************************************** @@ -249,8 +249,8 @@ static int macnet_advertise(FAR struct net_driver_s *dev) /* Set the MAC address as the eaddr */ eaddr = arg.getreq.attrval.mac.eaddr; - IEEE802154_EADDRCOPY(dev->d_mac.sixlowpan.nv_addr, eaddr); - dev->d_mac.sixlowpan.nv_addrlen = NET_6LOWPAN_EADDRSIZE; + IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr, eaddr); + dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_EADDRSIZE; /* Set the IP address based on the eaddr */ @@ -287,8 +287,8 @@ static int macnet_advertise(FAR struct net_driver_s *dev) /* Set the MAC address as the saddr */ saddr = arg.getreq.attrval.mac.saddr; - IEEE802154_SADDRCOPY(dev->d_mac.sixlowpan.nv_addr, saddr); - dev->d_mac.sixlowpan.nv_addrlen = NET_6LOWPAN_SADDRSIZE; + IEEE802154_SADDRCOPY(dev->d_mac.radio.nv_addr, saddr); + dev->d_mac.radio.nv_addrlen = NET_6LOWPAN_SADDRSIZE; /* Set the IP address based on the saddr */ @@ -572,7 +572,7 @@ static void macnet_txpoll_expiry(int argc, wdparm_t arg, ...) ****************************************************************************/ #if defined(CONFIG_NET_STARPOINT) && defined(CONFIG_NET_6LOWPAN_EXTENDEDADDR) -static int macnet_coord_eaddr(FAR struct sixlowpan_driver_s *radio, +static int macnet_coord_eaddr(FAR struct radio_driver_s *radio, FAR uint8_t *eaddr) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)radio; @@ -609,7 +609,7 @@ static int macnet_coord_eaddr(FAR struct sixlowpan_driver_s *radio, ****************************************************************************/ #if defined(CONFIG_NET_STARPOINT) && !defined(CONFIG_NET_6LOWPAN_EXTENDEDADDR) -static int macnet_coord_saddr(FAR struct sixlowpan_driver_s *radio, +static int macnet_coord_saddr(FAR struct radio_driver_s *radio, FAR uint8_t *saddr) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)radio; @@ -665,13 +665,13 @@ static int macnet_ifup(FAR struct net_driver_s *dev) #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR wlinfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1], - dev->d_mac.sixlowpan.nv_addr[2], dev->d_mac.sixlowpan.nv_addr[3], - dev->d_mac.sixlowpan.nv_addr[4], dev->d_mac.sixlowpan.nv_addr[5], - dev->d_mac.sixlowpan.nv_addr[6], dev->d_mac.sixlowpan.nv_addr[7]); + 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]); #else wlinfo(" Node: %02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1]); + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1]); #endif /* Set and activate a timer process */ @@ -945,7 +945,7 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static int macnet_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int macnet_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta) { FAR struct macnet_driver_s *priv = @@ -975,7 +975,7 @@ static int macnet_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int macnet_req_data(FAR struct sixlowpan_driver_s *netdev, +static int macnet_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist) { FAR struct macnet_driver_s *priv = @@ -1055,7 +1055,7 @@ static int macnet_req_data(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int macnet_properties(FAR struct sixlowpan_driver_s *netdev, +static int macnet_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); @@ -1131,7 +1131,7 @@ static int macnet_properties(FAR struct sixlowpan_driver_s *netdev, int mac802154netdev_register(MACHANDLE mac) { FAR struct macnet_driver_s *priv; - FAR struct sixlowpan_driver_s *radio; + FAR struct radio_driver_s *radio; FAR struct net_driver_s *dev; FAR struct mac802154_maccb_s *maccb; FAR uint8_t *pktbuf; diff --git a/wireless/pktradio/pktradio_loopback.c b/wireless/pktradio/pktradio_loopback.c index c245b08b6e6..a5b97198c8f 100644 --- a/wireless/pktradio/pktradio_loopback.c +++ b/wireless/pktradio/pktradio_loopback.c @@ -121,7 +121,7 @@ struct lo_driver_s /* This holds the information visible to the NuttX network */ - struct sixlowpan_driver_s lo_radio; /* Interface understood by the network */ + struct radio_driver_s lo_radio; /* Interface understood by the network */ }; /**************************************************************************** @@ -172,11 +172,11 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif -static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta); -static int lo_req_data(FAR struct sixlowpan_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 sixlowpan_driver_s *netdev, +static int lo_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties); /**************************************************************************** @@ -201,8 +201,8 @@ static void lo_addr2ip(FAR struct net_driver_s *dev) { /* Set the MAC address as the saddr */ - dev->d_mac.sixlowpan.nv_addrlen = CONFIG_PKTRADIO_ADDRLEN; - memcpy(dev->d_mac.sixlowpan.nv_addr, g_mac_addr, CONFIG_PKTRADIO_ADDRLEN); + dev->d_mac.radio.nv_addrlen = CONFIG_PKTRADIO_ADDRLEN; + memcpy(dev->d_mac.radio.nv_addr, g_mac_addr, CONFIG_PKTRADIO_ADDRLEN); /* Set the IP address */ @@ -491,18 +491,18 @@ static int lo_ifup(FAR struct net_driver_s *dev) #if CONFIG_PKTRADIO_ADDRLEN == 1 ninfo(" Node: %02x\n", - dev->d_mac.sixlowpan.nv_addr[0]); + dev->d_mac.radio.nv_addr[0]); #elif CONFIG_PKTRADIO_ADDRLEN == 2 ninfo(" Node: %02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1]); + dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1]); #elif CONFIG_PKTRADIO_ADDRLEN == 8 ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n", - dev->d_mac.sixlowpan.nv_addr[0], dev->d_mac.sixlowpan.nv_addr[1], - dev->d_mac.sixlowpan.nv_addr[2], dev->d_mac.sixlowpan.nv_addr[3], - dev->d_mac.sixlowpan.nv_addr[4], dev->d_mac.sixlowpan.nv_addr[5], - dev->d_mac.sixlowpan.nv_addr[6], dev->d_mac.sixlowpan.nv_addr[7]); + 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]); #endif /* Set and activate a timer process */ @@ -746,8 +746,8 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, case SIOCPKTRADIOGGPROPS: { - FAR struct sixlowpan_driver_s *radio = - (FAR struct sixlowpan_driver_s *)dev; + 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; @@ -773,7 +773,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, } else { - FAR const struct netdev_varaddr_s *devaddr = &dev->d_mac.sixlowpan; + FAR const struct netdev_varaddr_s *devaddr = &dev->d_mac.radio; devaddr->nv_addrlen = 1; devaddr->nv_addr[0] = newaddr->pa_addr[0]; @@ -797,7 +797,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, { FAR struct pktradio_addr_s *retaddr = (FAR struct pktradio_addr_s *)&cmddata->pifr_hwaddr; - FAR const struct netdev_varaddr_s *devaddr = &dev->d_mac.sixlowpan; + FAR const struct netdev_varaddr_s *devaddr = &dev->d_mac.radio; retaddr->pa_addrlen = devaddr->nv_addrlen; retaddr->pa_addr[0] = devaddr->nv_addr[0]; @@ -834,7 +834,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, +static int lo_get_mhrlen(FAR struct radio_driver_s *netdev, FAR const void *meta) { return MAC_HDRLEN; @@ -858,7 +858,7 @@ static int lo_get_mhrlen(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int lo_req_data(FAR struct sixlowpan_driver_s *netdev, +static int lo_req_data(FAR struct radio_driver_s *netdev, FAR const void *meta, FAR struct iob_s *framelist) { FAR struct lo_driver_s *priv; @@ -928,7 +928,7 @@ static int lo_req_data(FAR struct sixlowpan_driver_s *netdev, * ****************************************************************************/ -static int lo_properties(FAR struct sixlowpan_driver_s *netdev, +static int lo_properties(FAR struct radio_driver_s *netdev, FAR struct sixlowpan_properties_s *properties) { DEBUGASSERT(netdev != NULL && properties != NULL); @@ -982,7 +982,7 @@ static int lo_properties(FAR struct sixlowpan_driver_s *netdev, int pktradio_loopback(void) { FAR struct lo_driver_s *priv; - FAR struct sixlowpan_driver_s *radio; + FAR struct radio_driver_s *radio; FAR struct net_driver_s *dev; ninfo("Initializing\n");