6loWPAN: Clean up some send logic; remove sniffer.

This commit is contained in:
Gregory Nutt
2017-03-31 16:33:21 -06:00
parent 503f3e5477
commit cccbb6c693
11 changed files with 85 additions and 291 deletions
-28
View File
@@ -454,14 +454,6 @@ struct sixlowpan_nhcompressor_s
FAR uint8_t *uncompressed_len); 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 * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@@ -483,24 +475,4 @@ struct sixlowpan_rime_sniffer_s
void sixlowpan_set_compressor(FAR struct sixlowpan_nhcompressor_s *compressor); 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 */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWOAN_H */
-6
View File
@@ -178,10 +178,4 @@ config NET_6LOWPAN_TCP_RECVWNDO
the application is slow to process incoming data, or high (32768 the application is slow to process incoming data, or high (32768
bytes) if the application processes data quickly. 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 endif # NET_6LOWPAN
-4
View File
@@ -59,10 +59,6 @@ ifeq ($(CONFIG_NET_6LOWPAN_COMPRESSION_HC06),y)
NET_CSRCS += sixlowpan_hc06.c NET_CSRCS += sixlowpan_hc06.c
endif endif
ifeq ($(CONFIG_NET_6LOWPAN_SNIFFER),y)
NET_CSRCS += sixlowpan_sniffer.c
endif
# Include the sixlowpan directory in the build # Include the sixlowpan directory in the build
DEPPATH += --dep-path sixlowpan DEPPATH += --dep-path sixlowpan
-6
View File
@@ -51,12 +51,6 @@
FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor; 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 /* The following data values are used to hold intermediate settings while
* processing IEEE802.15.4 frames. These globals are shared with incoming * processing IEEE802.15.4 frames. These globals are shared with incoming
* and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC * and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC
+56
View File
@@ -79,6 +79,62 @@ static bool sixlowpan_isbroadcast(uint8_t mode, FAR uint8_t *addr)
return true; 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 * Public Functions
****************************************************************************/ ****************************************************************************/
-7
View File
@@ -340,13 +340,6 @@ struct frame802154_s
struct sixlowpan_nhcompressor_s; /* Foward reference */ struct sixlowpan_nhcompressor_s; /* Foward reference */
extern FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor; 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 /* The following data values are used to hold intermediate settings while
* processing IEEE802.15.4 frames. These globals are shared with incoming * processing IEEE802.15.4 frames. These globals are shared with incoming
* and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC * and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC
+22 -160
View File
@@ -103,10 +103,8 @@ struct sixlowpan_send_s
FAR struct devif_callback_s *s_cb; /* Reference to callback instance */ FAR struct devif_callback_s *s_cb; /* Reference to callback instance */
sem_t s_waitsem; /* Supports waiting for driver events */ sem_t s_waitsem; /* Supports waiting for driver events */
int s_result; /* The result of the transfer */ int s_result; /* The result of the transfer */
#ifdef CONFIG_NET_SOCKOPTS
uint16_t s_timeout; /* Send timeout in deciseconds */ uint16_t s_timeout; /* Send timeout in deciseconds */
systime_t s_time; /* Last send time for determining timeout */ 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 ipv6_hdr_s *s_destip; /* Destination IP address */
FAR const struct rimeaddr_s *s_destmac; /* Destination MAC address */ FAR const struct rimeaddr_s *s_destmac; /* Destination MAC address */
FAR const void *s_buf; /* Data to send */ FAR const void *s_buf; /* Data to send */
@@ -117,63 +115,6 @@ struct sixlowpan_send_s
* Private Functions * 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 * Name: sixlowpan_compress_ipv6hdr
* *
@@ -214,33 +155,6 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
g_uncomp_hdrlen += IPv6_HDRLEN; 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 * 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] = g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] =
CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; 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. */ /* Set stream mode for all TCP packets, except FIN packets. */
if (sinfo->s_destip->proto == IP_PROTO_TCP) 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; ieee->i_framelist->io_pktlen += iob->io_len;
} }
/* Send the list of frames */
return sixlowpan_send_frame(ieee, ieee->i_framelist);
#else #else
nerr("ERROR: Packet too large: %d\n", sinfo->s_len); nerr("ERROR: Packet too large: %d\n", sinfo->s_len);
nerr(" Cannot to be sent without fragmentation support\n"); 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 */ /* Keep track of the total amount of data queue */
iob->io_pktlen = iob->io_len; iob->io_pktlen = iob->io_len;
return sixlowpan_send_frame(ieee, iob);
} }
return OK;
} }
/**************************************************************************** /****************************************************************************
* Function: send_timeout * Function: send_timeout
* *
@@ -624,8 +510,7 @@ int sixlowpan_queue_frames(FAR struct net_driver_s *dev,
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_SOCKOPTS static inline bool send_timeout(FAR struct sixlowpan_send_s *sinfo)
static inline int send_timeout(FAR struct sixlowpan_send_s *sinfo)
{ {
/* Check for a timeout. Zero means none and, in that case, we will let /* Check for a timeout. Zero means none and, in that case, we will let
* the send wait forever. * the send wait forever.
@@ -634,17 +519,20 @@ static inline int send_timeout(FAR struct sixlowpan_send_s *sinfo)
if (sinfo->s_timeout != 0) if (sinfo->s_timeout != 0)
{ {
/* Check if the configured timeout has elapsed */ /* 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); systime_t timeo_ticks = DSEC2TICK(sinfo->s_timeout);
#warning Missing logic systime_t elapsed = clock_systimer() - sinfo->s_time;
if (elapsed >= timeo_ticks)
{
return true;
}
} }
/* No timeout */ /* No timeout */
return FALSE; return false;
} }
#endif /* CONFIG_NET_SOCKOPTS */
/**************************************************************************** /****************************************************************************
* Function: tcpsend_interrupt * Function: tcpsend_interrupt
@@ -696,10 +584,7 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev,
goto end_wait; goto end_wait;
} }
#ifdef CONFIG_NET_SOCKOPTS /* Check for a timeout. */
/* All data has been sent and we are just waiting for ACK or re-transmit
* indications to complete the send. Check for a timeout.
*/
if (send_timeout(sinfo)) if (send_timeout(sinfo))
{ {
@@ -709,7 +594,6 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev,
sinfo->s_result = -ETIMEDOUT; sinfo->s_result = -ETIMEDOUT;
goto end_wait; goto end_wait;
} }
#endif /* CONFIG_NET_SOCKOPTS */
/* Continue waiting */ /* Continue waiting */
@@ -778,28 +662,20 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
(void)sem_setprotocol(&sinfo.s_waitsem, SEM_PRIO_NONE); (void)sem_setprotocol(&sinfo.s_waitsem, SEM_PRIO_NONE);
sinfo.s_result = -EBUSY; sinfo.s_result = -EBUSY;
sinfo.s_timeout = timeout;
sinfo.s_time = clock_systimer();
sinfo.s_destip = ipv6; sinfo.s_destip = ipv6;
sinfo.s_destmac = raddr; sinfo.s_destmac = raddr;
sinfo.s_buf = buf; sinfo.s_buf = buf;
sinfo.s_len = len; 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(); net_lock();
if (len > 0) if (len > 0)
{ {
/* Allocate resources to receive a callback */ /* Allocate resources to receive a callback.
/* REVISIT: Need a psock instance to get the second argument *
* to devif_conn_callback_alloc(). * 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); 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; sinfo.s_cb->event = send_interrupt;
/* Notify the the IEEE802.15.4 MAC that we have data to send. */ /* 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); netdev_txnotify_dev(dev);
#warning Missing logic
/* Wait for the send to complete or an error to occur: NOTES: (1) /* 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 * 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 */ /* 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); devif_dev_callback_free(dev, sinfo.s_cb);
#warning Missing logic
} }
} }
sem_destroy(&sinfo.s_waitsem); sem_destroy(&sinfo.s_waitsem);
net_unlock(); net_unlock();
/* Set the socket state to idle */ return (sinfo.s_result < 0 ? sinfo.s_result : len);
/* 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);
} }
#endif /* CONFIG_NET_6LOWPAN */ #endif /* CONFIG_NET_6LOWPAN */
-80
View File
@@ -1,80 +0,0 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_sniffer.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#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 */
+3
View File
@@ -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); 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; return ret;
} }
+3
View File
@@ -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); 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; return ret;
} }
+1
View File
@@ -78,6 +78,7 @@ int net_timeo(systime_t start_time, socktimeo_t timeo)
{ {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }