6loWPAN: Repartition some logic

This commit is contained in:
Gregory Nutt 2017-03-29 18:07:52 -06:00
parent c8cb2009c8
commit 2e48af78e7
14 changed files with 703 additions and 466 deletions

View file

@ -43,6 +43,14 @@ NET_CSRCS += sixlowpan_initialize.c sixlowpan_globals.c sixlowpan_utils.c
NET_CSRCS += sixlowpan_input.c sixlowpan_send.c
NET_CSRCS += sixlowpan_compressor.c
ifeq ($(CONFIG_NET_TCP),y)
NET_CSRCS += sixlowpan_tcpsend.c
endif
ifeq ($(CONFIG_NET_UDP),y)
NET_CSRCS += sixlowpan_udpsend.c
endif
ifeq ($(CONFIG_NET_6LOWPAN_COMPRESSION_HC1),y)
NET_CSRCS += sixlowpan_hc1.c
endif

View file

@ -1,7 +1,7 @@
/****************************************************************************
* net/sixlowpan/sixlowpan.h
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* 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
@ -45,41 +45,6 @@
#ifdef CONFIG_NET_6LOWPAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Rime addres macros */
/* Copy a Rime address */
#define rimeaddr_copy(dest,src) \
memcpy(dest, src, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE)
/* Compare two Rime addresses */
#define rimeaddr_cmp(addr1,addr2) \
(memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0)
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/* A pointer to the optional, architecture-specific compressor */
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
/****************************************************************************
* Public Types
****************************************************************************/
@ -88,10 +53,7 @@ extern FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
* Public Function Prototypes
****************************************************************************/
struct net_driver_s; /* Forward reference */
struct ieee802154_driver_s; /* Forward reference */
struct rimeaddr_s; /* Forward reference */
struct socket; /* Forward reference */
struct socket; /* Forward reference */
/****************************************************************************
* Name: sixlowpan_initialize
@ -170,151 +132,5 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
size_t len);
#endif
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* sixlowpan_hc06_initialize() is called during OS initialization at power-up
* reset. It is called from the common sixlowpan_initialize() function.
* sixlowpan_hc06_initialize() configures HC06 networking data structures.
* It is called prior to platform-specific driver initialization so that
* the 6loWPAN networking subsystem is prepared to deal with network
* driver initialization actions.
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_hc06_initialize(void);
#endif
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* Compress IP/UDP header
*
* This function is called by the 6lowpan code to create a compressed
* 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
* uip_buf buffer.
*
* HC-06 (draft-ietf-6lowpan-hc, version 6)
* http://tools.ietf.org/html/draft-ietf-6lowpan-hc-06
*
* NOTE: sixlowpan_compresshdr_hc06() does not support ISA100_UDP header
* compression
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress IP dest
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
FAR struct rimeaddr_s *destaddr);
#endif
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* Uncompress HC06 (i.e., IPHC and LOWPAN_UDP) headers and put them in
* sixlowpan_buf
*
* This function is called by the input function when the dispatch is HC06.
* We process the packet in the rime buffer, uncompress the header fields,
* and copy the result in the sixlowpan buffer. At the end of the
* decompression, g_rime_hdrlen and g_uncompressed_hdrlen are set to the
* appropriate values
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
uint16_t iplen);
#endif
/****************************************************************************
* Name: sixlowpan_compresshdr_hc1
*
* Description:
* Compress IP/UDP header using HC1 and HC_UDP
*
* This function is called by the 6lowpan code to create a compressed
* 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
* uip_buf buffer.
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress the IP
* destination field
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
FAR struct rimeaddr_s *destaddr);
#endif
/****************************************************************************
* Name: sixlowpan_uncompresshdr_hc1
*
* Description:
* Uncompress HC1 (and HC_UDP) headers and put them in sixlowpan_buf
*
* This function is called by the input function when the dispatch is
* HC1. It processes the packet in the rime buffer, uncompresses the
* header fields, and copies the result in the sixlowpan buffer. At the
* end of the decompression, g_rime_hdrlen and uncompressed_hdr_len
* are set to the appropriate values
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_uncompresshdr_hc1(FAR struct net_driver_s *dev,
uint16_t ip_len);
#endif
/****************************************************************************
* Name: sixlowpan_pktbuf_reset
*
* Description:
* Reset all attributes and addresses in the packet buffer metadata in the
* provided IEEE802.15.4 MAC driver structure.
*
****************************************************************************/
void sixlowpan_pktbuf_reset(FAR struct ieee802154_driver_s *ieee);
#endif /* CONFIG_NET_6LOWPAN */
#endif /* _NET_SIXLOWPAN_SIXLOWPAN_H */

View file

@ -42,7 +42,7 @@
#include "nuttx/net/net.h"
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN

View file

@ -41,7 +41,7 @@
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN

View file

@ -60,7 +60,7 @@
#include <nuttx/net/netdev.h>
#include <nuttx/net/sixlowpan.h>
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06

View file

@ -49,7 +49,7 @@
#include <nuttx/config.h>
#include <nuttx/net/netdev.h>
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1

View file

@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN

View file

@ -42,7 +42,7 @@
#include <errno.h>
#include "nuttx/net/netdev.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN

View file

@ -0,0 +1,307 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_internal.h
*
* 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.
*
****************************************************************************/
#ifndef _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H
#define _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/net/tcp.h>
#include <nuttx/net/udp.h>
#include <nuttx/net/icmpv6.h>
#ifdef CONFIG_NET_6LOWPAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Rime addres macros */
/* Copy a Rime address */
#define rimeaddr_copy(dest,src) \
memcpy(dest, src, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE)
/* Compare two Rime addresses */
#define rimeaddr_cmp(addr1,addr2) \
(memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0)
/****************************************************************************
* Public Types
****************************************************************************/
/* IPv6 + TCP header */
struct ipv6tcp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct tcp_hdr_s tcp;
};
/* IPv6 + UDP header */
struct ipv6udp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct udp_hdr_s udp;
};
/* IPv6 + ICMPv6 header */
struct ipv6icmp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct icmpv6_iphdr_s icmp;
};
/****************************************************************************
* Public Data
****************************************************************************/
/* A pointer to the optional, architecture-specific compressor */
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
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
struct net_driver_s; /* Forward reference */
struct ieee802154_driver_s; /* Forward reference */
struct rimeaddr_s; /* Forward reference */
/****************************************************************************
* Name: sixlowpan_send
*
* Description:
* Process an outgoing UDP or TCP packet. Takes an IP packet and formats
* it to be sent on an 802.15.4 network using 6lowpan. Called from common
* UDP/TCP send logic.
*
* The payload data is in the caller 'buf' and is of length 'len'.
* Compressed headers will be added and if necessary the packet is
* fragmented. The resulting packet/fragments are put in dev->d_buf and
* the first frame will be delivered to the 802.15.4 MAC. via ieee->i_frame.
*
* Input Parmeters:
*
* Input Parameters:
* dev - The IEEE802.15.4 MAC network driver interface.
* ipv6 - IPv6 plus TCP or UDP headers.
* buf - Data to send
* len - Length of data to send
* raddr - The MAC address of the destination
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
* This function is expected to fail if the driver is not an IEEE802.15.4
* MAC network driver. In that case, the UDP/TCP will fall back to normal
* IPv4/IPv6 formatting.
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
int sixlowpan_send(FAR struct net_driver_s *dev,
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
size_t len, FAR const struct rimeaddr_s *raddr);
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* sixlowpan_hc06_initialize() is called during OS initialization at power-up
* reset. It is called from the common sixlowpan_initialize() function.
* sixlowpan_hc06_initialize() configures HC06 networking data structures.
* It is called prior to platform-specific driver initialization so that
* the 6loWPAN networking subsystem is prepared to deal with network
* driver initialization actions.
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_hc06_initialize(void);
#endif
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* Compress IP/UDP header
*
* This function is called by the 6lowpan code to create a compressed
* 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
* uip_buf buffer.
*
* HC-06 (draft-ietf-6lowpan-hc, version 6)
* http://tools.ietf.org/html/draft-ietf-6lowpan-hc-06
*
* NOTE: sixlowpan_compresshdr_hc06() does not support ISA100_UDP header
* compression
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress IP dest
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
FAR struct rimeaddr_s *destaddr);
#endif
/****************************************************************************
* Name: sixlowpan_hc06_initialize
*
* Description:
* Uncompress HC06 (i.e., IPHC and LOWPAN_UDP) headers and put them in
* sixlowpan_buf
*
* This function is called by the input function when the dispatch is HC06.
* We process the packet in the rime buffer, uncompress the header fields,
* and copy the result in the sixlowpan buffer. At the end of the
* decompression, g_rime_hdrlen and g_uncompressed_hdrlen are set to the
* appropriate values
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
uint16_t iplen);
#endif
/****************************************************************************
* Name: sixlowpan_compresshdr_hc1
*
* Description:
* Compress IP/UDP header using HC1 and HC_UDP
*
* This function is called by the 6lowpan code to create a compressed
* 6lowpan packet in the packetbuf buffer from a full IPv6 packet in the
* uip_buf buffer.
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress the IP
* destination field
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
FAR struct rimeaddr_s *destaddr);
#endif
/****************************************************************************
* Name: sixlowpan_uncompresshdr_hc1
*
* Description:
* Uncompress HC1 (and HC_UDP) headers and put them in sixlowpan_buf
*
* This function is called by the input function when the dispatch is
* HC1. It processes the packet in the rime buffer, uncompresses the
* header fields, and copies the result in the sixlowpan buffer. At the
* end of the decompression, g_rime_hdrlen and uncompressed_hdr_len
* are set to the appropriate values
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_uncompresshdr_hc1(FAR struct net_driver_s *dev,
uint16_t ip_len);
#endif
/****************************************************************************
* Name: sixlowpan_pktbuf_reset
*
* Description:
* Reset all attributes and addresses in the packet buffer metadata in the
* provided IEEE802.15.4 MAC driver structure.
*
****************************************************************************/
void sixlowpan_pktbuf_reset(FAR struct ieee802154_driver_s *ieee);
#endif /* CONFIG_NET_6LOWPAN */
#endif /* _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H */

View file

@ -55,38 +55,10 @@
#include "socket/socket.h"
#include "tcp/tcp.h"
#include "udp/udp.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN
/****************************************************************************
* Private Types
****************************************************************************/
/* IPv6 + TCP header */
struct ipv6tcp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct tcp_hdr_s tcp;
};
/* IPv6 + UDP header */
struct ipv6udp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct udp_hdr_s udp;
};
/* IPv6 + ICMPv6 header */
struct ipv6icmp_hdr_s
{
struct ipv6_hdr_s ipv6;
struct icmpv6_iphdr_s icmp;
};
/****************************************************************************
* Private Functions
****************************************************************************/
@ -186,6 +158,10 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
ieee->i_uncomp_hdrlen += IPv6_HDRLEN;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sixlowpan_send
*
@ -206,7 +182,7 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
* ipv6 - IPv6 plus TCP or UDP headers.
* buf - Data to send
* len - Length of data to send
* raddr - The MAC address of the destination
* raddr - The IEEE802.15.4 MAC address of the destination
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
@ -219,9 +195,9 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
*
****************************************************************************/
static int sixlowpan_send(FAR struct net_driver_s *dev,
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
size_t len, net_ipv6addr_t raddr)
int sixlowpan_send(FAR struct net_driver_s *dev,
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
size_t len, FAR const struct rimeaddr_s *raddr)
{
FAR struct ieee802154_driver_s *ieee = (FAR struct ieee802154_driver_s *)dev;
@ -271,7 +247,14 @@ static int sixlowpan_send(FAR struct net_driver_s *dev,
* argument raddr is NULL, we are sending a broadcast packet.
*/
#warning Missing logic
if (raddr == NULL)
{
memset(&dest, 0, sizeof(struct rimeaddr_s));
}
else
{
rimeaddr_copy(&dest, (FAR const struct rimeaddr_s *)raddr);
}
ninfo("Sending packet len %d\n", len);
@ -303,243 +286,4 @@ static int sixlowpan_send(FAR struct net_driver_s *dev,
return -ENOSYS;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: psock_6lowpan_tcp_send
*
* Description:
* psock_6lowpan_tcp_send() call may be used only when the TCP socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
* psock - An instance of the internal socket structure.
* buf - Data to send
* len - Length of data to send
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately. Returned error numbers
* must be consistent with definition of errors reported by send() or
* sendto().
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
size_t len)
{
FAR struct tcp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6tcp_hdr_s ipv6tcp;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
DEBUGASSERT(psock->s_type == SOCK_STREAM);
/* Make sure that this is a valid socket */
if (psock != NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
return (ssize_t)-EBADF;
}
/* Make sure that this is a connected TCP socket */
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
{
nerr("ERROR: Not connected\n");
return (ssize_t)-ENOTCONN;
}
/* Get the underlying TCP connection structure */
conn = (FAR struct tcp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6)
{
nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE;
}
#endif
/* Route outgoing message to the correct device */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
if (dev == NULL)
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
/* Make sure that the IP address mapping is in the Neighbor Table */
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
/* Initialize the IPv6/TCP headers */
#warning Missing logic
/* Set the socket state to sending */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND);
/* If routable, then call sixlowpan_send() to format and send the 6loWPAN
* packet.
*/
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6tcp,
buf, len, conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
return ret;
}
#endif
/****************************************************************************
* Function: psock_6lowpan_udp_send
*
* Description:
* psock_6lowpan_udp_send() call may be used with connectionlesss UDP
* sockets.
*
* Parameters:
* psock - An instance of the internal socket structure.
* buf - Data to send
* len - Length of data to send
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately. Returned error numbers
* must be consistent with definition of errors reported by send() or
* sendto().
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
#ifdef CONFIG_NET_UDP
ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
size_t len)
{
FAR struct udp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6udp_hdr_s ipv6udp;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
DEBUGASSERT(psock->s_type == SOCK_DGRAM);
/* Make sure that this is a valid socket */
if (psock != NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
return (ssize_t)-EBADF;
}
/* Was the UDP socket connected via connect()? */
if (psock->s_type != SOCK_DGRAM || !_SS_ISCONNECTED(psock->s_flags))
{
/* No, then it is not legal to call send() with this socket. */
return -ENOTCONN;
}
/* Get the underlying UDP "connection" structure */
conn = (FAR struct udp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6)
{
nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE;
}
#endif
/* Route outgoing message to the correct device */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
if (dev == NULL)
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
/* Make sure that the IP address mapping is in the Neighbor Table */
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
/* Initialize the IPv6/UDP headers */
#warning Missing logic
/* Set the socket state to sending */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND);
/* If routable, then call sixlowpan_send() to format and send the 6loWPAN
* packet.
*/
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6udp,
buf, len, conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
return ret;
}
#endif
#endif /* CONFIG_NET_6LOWPAN */

View file

@ -42,7 +42,7 @@
#include "nuttx/net/net.h"
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN_SNIFFER

View file

@ -0,0 +1,180 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_tcpsend.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 <assert.h>
#include <errno.h>
#include <debug.h>
#include "nuttx/net/netdev.h"
#include "nuttx/net/tcp.h"
#include "nuttx/net/sixlowpan.h"
#include "netdev/netdev.h"
#include "socket/socket.h"
#include "tcp/tcp.h"
#include "sixlowpan/sixlowpan_internal.h"
#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_NET_TCP)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: psock_6lowpan_tcp_send
*
* Description:
* psock_6lowpan_tcp_send() call may be used only when the TCP socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
* psock - An instance of the internal socket structure.
* buf - Data to send
* len - Length of data to send
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately. Returned error numbers
* must be consistent with definition of errors reported by send() or
* sendto().
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
size_t len)
{
FAR struct tcp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6tcp_hdr_s ipv6tcp;
struct rimeaddr_s dest;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
DEBUGASSERT(psock->s_type == SOCK_STREAM);
/* Make sure that this is a valid socket */
if (psock != NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
return (ssize_t)-EBADF;
}
/* Make sure that this is a connected TCP socket */
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
{
nerr("ERROR: Not connected\n");
return (ssize_t)-ENOTCONN;
}
/* Get the underlying TCP connection structure */
conn = (FAR struct tcp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6)
{
nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE;
}
#endif
/* Route outgoing message to the correct device */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
if (dev == NULL)
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
/* Make sure that the IP address mapping is in the Neighbor Table */
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
/* Initialize the IPv6/TCP headers */
#warning Missing logic
/* Set the socket state to sending */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND);
/* Get the Rime MAC address of the destination */
#warning Missing logic
/* If routable, then call sixlowpan_send() to format and send the 6loWPAN
* packet.
*/
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6tcp,
buf, len, &dest);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
return ret;
}
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NET_TCP */

View file

@ -0,0 +1,181 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_udpsend.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 <assert.h>
#include <errno.h>
#include <debug.h>
#include "nuttx/net/netdev.h"
#include "nuttx/net/udp.h"
#include "nuttx/net/sixlowpan.h"
#include "netdev/netdev.h"
#include "socket/socket.h"
#include "udp/udp.h"
#include "sixlowpan/sixlowpan_internal.h"
#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_NET_UDP)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: psock_6lowpan_udp_send
*
* Description:
* psock_6lowpan_udp_send() call may be used with connectionlesss UDP
* sockets.
*
* Parameters:
* psock - An instance of the internal socket structure.
* buf - Data to send
* len - Length of data to send
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately. Returned error numbers
* must be consistent with definition of errors reported by send() or
* sendto().
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
size_t len)
{
FAR struct udp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6udp_hdr_s ipv6udp;
struct rimeaddr_s dest;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
DEBUGASSERT(psock->s_type == SOCK_DGRAM);
/* Make sure that this is a valid socket */
if (psock != NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
return (ssize_t)-EBADF;
}
/* Was the UDP socket connected via connect()? */
if (psock->s_type != SOCK_DGRAM || !_SS_ISCONNECTED(psock->s_flags))
{
/* No, then it is not legal to call send() with this socket. */
return -ENOTCONN;
}
/* Get the underlying UDP "connection" structure */
conn = (FAR struct udp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6)
{
nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE;
}
#endif
/* Route outgoing message to the correct device */
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
if (dev == NULL)
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
/* Make sure that the IP address mapping is in the Neighbor Table */
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
if (ret < 0)
{
nerr("ERROR: Not reachable\n");
return (ssize_t)-ENETUNREACH;
}
#endif
/* Initialize the IPv6/UDP headers */
#warning Missing logic
/* Set the socket state to sending */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND);
/* Get the Rime MAC address of the destination */
#warning Missing logic
/* If routable, then call sixlowpan_send() to format and send the 6loWPAN
* packet.
*/
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6udp,
buf, len, &dest);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
return ret;
}
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NET_UDP */

View file

@ -55,7 +55,7 @@
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN