From cccbb6c693f68c51127c4a004e6d47efbd31fd94 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 31 Mar 2017 16:33:21 -0600 Subject: [PATCH] 6loWPAN: Clean up some send logic; remove sniffer. --- include/nuttx/net/sixlowpan.h | 28 ----- net/sixlowpan/Kconfig | 6 - net/sixlowpan/Make.defs | 4 - net/sixlowpan/sixlowpan_globals.c | 6 - net/sixlowpan/sixlowpan_input.c | 56 +++++++++ net/sixlowpan/sixlowpan_internal.h | 7 -- net/sixlowpan/sixlowpan_send.c | 182 ++++------------------------- net/sixlowpan/sixlowpan_sniffer.c | 80 ------------- net/sixlowpan/sixlowpan_tcpsend.c | 3 + net/sixlowpan/sixlowpan_udpsend.c | 3 + net/socket/net_timeo.c | 1 + 11 files changed, 85 insertions(+), 291 deletions(-) delete mode 100644 net/sixlowpan/sixlowpan_sniffer.c diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 1fbfee79b4..db4bbd1d02 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -454,14 +454,6 @@ struct sixlowpan_nhcompressor_s FAR uint8_t *uncompressed_len); }; -/* RIME sniffer callbacks */ - -struct sixlowpan_rime_sniffer_s -{ - CODE void (*input)(void); - CODE void (*output)(int mac_status); -}; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -483,24 +475,4 @@ struct sixlowpan_rime_sniffer_s void sixlowpan_set_compressor(FAR struct sixlowpan_nhcompressor_s *compressor); -/**************************************************************************** - * Function: sixlowpan_set_sniffer - * - * Description: - * Configure to use an architecture-specific sniffer to enable tracing of - * IP. - * - * Input parameters: - * sniffer - A reference to the new sniffer to be used. This may - * be a NULL value to disable the sniffer. - * - * Returned Value: - * None - * - ****************************************************************************/ - -#ifdef CONFIG_NET_6LOWPAN_SNIFFER -void sixlowpan_set_sniffer(FAR struct sixlowpan_rime_sniffer_s *sniffer); -#endif - #endif /* __INCLUDE_NUTTX_NET_SIXLOWOAN_H */ diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 4b4c6ad9eb..4d0be0b660 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -178,10 +178,4 @@ config NET_6LOWPAN_TCP_RECVWNDO the application is slow to process incoming data, or high (32768 bytes) if the application processes data quickly. -config NET_6LOWPAN_SNIFFER - default n - ---help--- - Enable use use an architecture-specific sniffer to support tracing - of IP. - endif # NET_6LOWPAN diff --git a/net/sixlowpan/Make.defs b/net/sixlowpan/Make.defs index e0370185e6..becc0a7edd 100644 --- a/net/sixlowpan/Make.defs +++ b/net/sixlowpan/Make.defs @@ -59,10 +59,6 @@ ifeq ($(CONFIG_NET_6LOWPAN_COMPRESSION_HC06),y) NET_CSRCS += sixlowpan_hc06.c endif -ifeq ($(CONFIG_NET_6LOWPAN_SNIFFER),y) -NET_CSRCS += sixlowpan_sniffer.c -endif - # Include the sixlowpan directory in the build DEPPATH += --dep-path sixlowpan diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index b62c3e110f..6b0f5bcf74 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -51,12 +51,6 @@ FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor; -#ifdef CONFIG_NET_6LOWPAN_SNIFFER -/* A pointer to the optional, architecture-specific sniffer */ - -FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer; -#endif - /* The following data values are used to hold intermediate settings while * processing IEEE802.15.4 frames. These globals are shared with incoming * and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index ce520f8e5e..466069f2d5 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -79,6 +79,62 @@ static bool sixlowpan_isbroadcast(uint8_t mode, FAR uint8_t *addr) return true; } +/**************************************************************************** + * Name: sixlowpan_set_pktattrs + * + * Description: + * Setup some packet buffer attributes + * + * Input Parameters: + * ieee - Pointer to IEEE802.15.4 MAC driver structure. + * ipv6 - Pointer to the IPv6 header to "compress" + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void sixlowpan_set_pktattrs(FAR struct ieee802154_driver_s *ieee, + FAR const struct ipv6_hdr_s *ipv6) +{ + int attr = 0; + + /* Set protocol in NETWORK_ID */ + + g_pktattrs[PACKETBUF_ATTR_NETWORK_ID] = ipv6->proto; + + /* Assign values to the channel attribute (port or type + code) */ + + if (ipv6->proto == IP_PROTO_UDP) + { + FAR struct udp_hdr_s *udp = &((FAR struct ipv6udp_hdr_s *)ipv6)->udp; + + attr = udp->srcport; + if (udp->destport < attr) + { + attr = udp->destport; + } + } + else if (ipv6->proto == IP_PROTO_TCP) + { + FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6)->tcp; + + attr = tcp->srcport; + if (tcp->destport < attr) + { + attr = tcp->destport; + } + } + else if (ipv6->proto == IP_PROTO_ICMP6) + { + FAR struct icmpv6_iphdr_s *icmp = &((FAR struct ipv6icmp_hdr_s *)ipv6)->icmp; + + attr = icmp->type << 8 | icmp->code; + } + + g_pktattrs[PACKETBUF_ATTR_CHANNEL] = attr; +} + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 3bf65fc09c..d96c4213b7 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -340,13 +340,6 @@ struct frame802154_s struct sixlowpan_nhcompressor_s; /* Foward reference */ extern FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor; -#ifdef CONFIG_NET_6LOWPAN_SNIFFER -/* Rime Sniffer support for one single listener to enable trace of IP */ - -struct sixlowpan_rime_sniffer_s; /* Foward reference */ -extern FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer; -#endif - /* The following data values are used to hold intermediate settings while * processing IEEE802.15.4 frames. These globals are shared with incoming * and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index 69bf3b8392..12420a2574 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -103,10 +103,8 @@ struct sixlowpan_send_s FAR struct devif_callback_s *s_cb; /* Reference to callback instance */ sem_t s_waitsem; /* Supports waiting for driver events */ int s_result; /* The result of the transfer */ -#ifdef CONFIG_NET_SOCKOPTS uint16_t s_timeout; /* Send timeout in deciseconds */ systime_t s_time; /* Last send time for determining timeout */ -#endif FAR const struct ipv6_hdr_s *s_destip; /* Destination IP address */ FAR const struct rimeaddr_s *s_destmac; /* Destination MAC address */ FAR const void *s_buf; /* Data to send */ @@ -117,63 +115,6 @@ struct sixlowpan_send_s * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: sixlowpan_set_pktattrs - * - * Description: - * Setup some packet buffer attributes - * - * Input Parameters: - * ieee - Pointer to IEEE802.15.4 MAC driver structure. - * ipv6 - Pointer to the IPv6 header to "compress" - * - * Returned Value: - * None - * - ****************************************************************************/ - -/* REVISIT: This is use in input function, but only for sniffer on output */ -static void sixlowpan_set_pktattrs(FAR struct ieee802154_driver_s *ieee, - FAR const struct ipv6_hdr_s *ipv6) -{ - int attr = 0; - - /* Set protocol in NETWORK_ID */ - - g_pktattrs[PACKETBUF_ATTR_NETWORK_ID] = ipv6->proto; - - /* Assign values to the channel attribute (port or type + code) */ - - if (ipv6->proto == IP_PROTO_UDP) - { - FAR struct udp_hdr_s *udp = &((FAR struct ipv6udp_hdr_s *)ipv6)->udp; - - attr = udp->srcport; - if (udp->destport < attr) - { - attr = udp->destport; - } - } - else if (ipv6->proto == IP_PROTO_TCP) - { - FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6)->tcp; - - attr = tcp->srcport; - if (tcp->destport < attr) - { - attr = tcp->destport; - } - } - else if (ipv6->proto == IP_PROTO_ICMP6) - { - FAR struct icmpv6_iphdr_s *icmp = &((FAR struct ipv6icmp_hdr_s *)ipv6)->icmp; - - attr = icmp->type << 8 | icmp->code; - } - - g_pktattrs[PACKETBUF_ATTR_CHANNEL] = attr; -} - /**************************************************************************** * Name: sixlowpan_compress_ipv6hdr * @@ -214,33 +155,6 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen += IPv6_HDRLEN; } -/**************************************************************************** - * Name: sixlowpan_send_frame - * - * Description: - * Send one frame when the IEEE802.15.4 MAC device next polls. - * - * Input Parameters: - * ieee - Pointer to IEEE802.15.4 MAC driver structure. - * iobq - The list of frames to send. - * - * Returned Value: - * Zero (OK) on success; otherwise a negated errno value is returned. - * - ****************************************************************************/ - -static int sixlowpan_send_frame(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *iobq) -{ - /* Prepare the frame */ -#warning Missing logic - /* Notify the IEEE802.14.5 MAC driver that we have data to be sent */ -#warning Missing logic - /* Wait for the transfer to complete */ -#warning Missing logic - return -ENOSYS; -} - /**************************************************************************** * Name: sixlowpan_queue_frames * @@ -297,31 +211,6 @@ int sixlowpan_queue_frames(FAR struct net_driver_s *dev, g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; -#ifdef CONFIG_NET_6LOWPAN_SNIFFER - if (g_sixlowpan_sniffer != NULL) - { - /* Reset rime buffer, packet buffer metatadata */ - - memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); - memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct rimeaddr_s)); - - g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = - CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; - - /* Call the attribution when the callback comes, but set attributes here */ - - sixlowpan_set_pktattrs(ieee, sinfo->s_destip); - } -#endif - - /* Reset rime buffer, packet buffer metatadata */ - - memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); - memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct rimeaddr_s)); - - g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = - CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; - /* Set stream mode for all TCP packets, except FIN packets. */ if (sinfo->s_destip->proto == IP_PROTO_TCP) @@ -552,10 +441,6 @@ int sixlowpan_queue_frames(FAR struct net_driver_s *dev, ieee->i_framelist->io_pktlen += iob->io_len; } - - /* Send the list of frames */ - - return sixlowpan_send_frame(ieee, ieee->i_framelist); #else nerr("ERROR: Packet too large: %d\n", sinfo->s_len); nerr(" Cannot to be sent without fragmentation support\n"); @@ -603,10 +488,11 @@ int sixlowpan_queue_frames(FAR struct net_driver_s *dev, /* Keep track of the total amount of data queue */ iob->io_pktlen = iob->io_len; - - return sixlowpan_send_frame(ieee, iob); } + + return OK; } + /**************************************************************************** * Function: send_timeout * @@ -624,8 +510,7 @@ int sixlowpan_queue_frames(FAR struct net_driver_s *dev, * ****************************************************************************/ -#ifdef CONFIG_NET_SOCKOPTS -static inline int send_timeout(FAR struct sixlowpan_send_s *sinfo) +static inline bool send_timeout(FAR struct sixlowpan_send_s *sinfo) { /* Check for a timeout. Zero means none and, in that case, we will let * the send wait forever. @@ -634,17 +519,20 @@ static inline int send_timeout(FAR struct sixlowpan_send_s *sinfo) if (sinfo->s_timeout != 0) { /* Check if the configured timeout has elapsed */ - /* REVISIT: I would need a psock to do this */ - //return net_timeo(sinfo->s_time, psock->s_sndtimeo); -#warning Missing logic + systime_t timeo_ticks = DSEC2TICK(sinfo->s_timeout); + systime_t elapsed = clock_systimer() - sinfo->s_time; + + if (elapsed >= timeo_ticks) + { + return true; + } } /* No timeout */ - return FALSE; + return false; } -#endif /* CONFIG_NET_SOCKOPTS */ /**************************************************************************** * Function: tcpsend_interrupt @@ -696,10 +584,7 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev, goto end_wait; } -#ifdef CONFIG_NET_SOCKOPTS - /* All data has been sent and we are just waiting for ACK or re-transmit - * indications to complete the send. Check for a timeout. - */ + /* Check for a timeout. */ if (send_timeout(sinfo)) { @@ -709,7 +594,6 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev, sinfo->s_result = -ETIMEDOUT; goto end_wait; } -#endif /* CONFIG_NET_SOCKOPTS */ /* Continue waiting */ @@ -778,28 +662,20 @@ int sixlowpan_send(FAR struct net_driver_s *dev, (void)sem_setprotocol(&sinfo.s_waitsem, SEM_PRIO_NONE); sinfo.s_result = -EBUSY; + sinfo.s_timeout = timeout; + sinfo.s_time = clock_systimer(); sinfo.s_destip = ipv6; sinfo.s_destmac = raddr; sinfo.s_buf = buf; sinfo.s_len = len; -#ifdef CONFIG_NET_SOCKOPTS - sinfo.s_timeout = timeout; - sinfo.s_time = clock_systimer(); -#endif - - /* Set the socket state to sending */ - /* REVISIT: We would need a psock to do this. Already done by caller. */ - - //psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); -#warning Missing logic - net_lock(); if (len > 0) { - /* Allocate resources to receive a callback */ - /* REVISIT: Need a psock instance to get the second argument - * to devif_conn_callback_alloc(). + /* Allocate resources to receive a callback. + * + * The second parameter is NULL meaning that we can get only + * device related events, no connect-related events. */ sinfo.s_cb = devif_callback_alloc(dev, NULL); @@ -814,12 +690,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev, sinfo.s_cb->event = send_interrupt; /* Notify the the IEEE802.15.4 MAC that we have data to send. */ - /* REVISIT: Need a psock instance for the arguments to - * send_txnotify(). - */ - // send_txnotify(psock, conn); -#warning Missing logic + netdev_txnotify_dev(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 @@ -834,25 +706,15 @@ int sixlowpan_send(FAR struct net_driver_s *dev, } /* Make sure that no further interrupts are processed */ - /* REVISIT: Need a psock instance to get the arguments - * to devif_conn_callback_free(). - */ - //devif_conn_callback_free(conn, sinfo.s_cb, NULL); -#warning Missing logic + devif_dev_callback_free(dev, sinfo.s_cb); } } sem_destroy(&sinfo.s_waitsem); net_unlock(); - /* Set the socket state to idle */ - /* REVISIT: Again, need a psock instance */ - - // psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); -#warning Missing logic - - return (sinfo.s_result < 0 ? sinfo.s_result : len); + return (sinfo.s_result < 0 ? sinfo.s_result : len); } #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_sniffer.c b/net/sixlowpan/sixlowpan_sniffer.c deleted file mode 100644 index eb8a77e3f7..0000000000 --- a/net/sixlowpan/sixlowpan_sniffer.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * net/sixlowpan/sixlowpan_sniffer.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 "nuttx/net/net.h" - -#include "sixlowpan/sixlowpan_internal.h" - -#ifdef CONFIG_NET_6LOWPAN_SNIFFER - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sixlowpan_set_sniffer - * - * Description: - * Configure to use an architecture-specific sniffer to enable tracing of - * IP. - * - * Input parameters: - * sniffer - A reference to the new sniffer to be used. This may - * be a NULL value to disable the sniffer. - * - * Returned Value: - * None - * - ****************************************************************************/ - -void sixlowpan_set_sniffer(FAR struct sixlowpan_rime_sniffer_s *sniffer) -{ - /* Make sure that the sniffer is not in use */ - - net_lock(); - - /* Then instantiate the new sniffer */ - - g_sixlowpan_sniffer = sniffer; - net_unlock(); -} - -#endif /* CONFIG_NET_6LOWPAN_SNIFFER */ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index c84e04e388..7089b19b27 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -187,6 +187,9 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, nerr("ERROR: sixlowpan_send() failed: %d\n", ret); } + /* Set the socket state to idle */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); return ret; } diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 5f76245f76..18f9ea8ac1 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -188,6 +188,9 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf, nerr("ERROR: sixlowpan_send() failed: %d\n", ret); } + /* Set the socket state to idle */ + + psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); return ret; } diff --git a/net/socket/net_timeo.c b/net/socket/net_timeo.c index 47099d205d..81b7123a31 100644 --- a/net/socket/net_timeo.c +++ b/net/socket/net_timeo.c @@ -78,6 +78,7 @@ int net_timeo(systime_t start_time, socktimeo_t timeo) { return TRUE; } + return FALSE; }