6loWPAN: IEEE802.15.4 MAC driver will need a special form of the network device structure to manage fragmentation of the large packet into frames.

This commit is contained in:
Gregory Nutt 2017-03-29 10:17:34 -06:00
parent eb344d7260
commit 5fb222180c
5 changed files with 85 additions and 39 deletions

View File

@ -96,6 +96,7 @@ CONFIG_ARCH="arm"
# CONFIG_ARCH_CHIP_LPC2378 is not set # CONFIG_ARCH_CHIP_LPC2378 is not set
# CONFIG_ARCH_CHIP_LPC31XX is not set # CONFIG_ARCH_CHIP_LPC31XX is not set
# CONFIG_ARCH_CHIP_LPC43XX is not set # CONFIG_ARCH_CHIP_LPC43XX is not set
# CONFIG_ARCH_CHIP_MOXART is not set
# CONFIG_ARCH_CHIP_NUC1XX is not set # CONFIG_ARCH_CHIP_NUC1XX is not set
# CONFIG_ARCH_CHIP_SAMA5 is not set # CONFIG_ARCH_CHIP_SAMA5 is not set
# CONFIG_ARCH_CHIP_SAMD is not set # CONFIG_ARCH_CHIP_SAMD is not set
@ -107,7 +108,7 @@ CONFIG_ARCH_CHIP_SAMV7=y
# CONFIG_ARCH_CHIP_STM32L4 is not set # CONFIG_ARCH_CHIP_STM32L4 is not set
# CONFIG_ARCH_CHIP_STR71X is not set # CONFIG_ARCH_CHIP_STR71X is not set
# CONFIG_ARCH_CHIP_TMS570 is not set # CONFIG_ARCH_CHIP_TMS570 is not set
# CONFIG_ARCH_CHIP_MOXART is not set # CONFIG_ARCH_CHIP_XMC4 is not set
# CONFIG_ARCH_ARM7TDMI is not set # CONFIG_ARCH_ARM7TDMI is not set
# CONFIG_ARCH_ARM926EJS is not set # CONFIG_ARCH_ARM926EJS is not set
# CONFIG_ARCH_ARM920T is not set # CONFIG_ARCH_ARM920T is not set
@ -457,6 +458,8 @@ CONFIG_SCHED_WAITPID=y
# #
# CONFIG_PTHREAD_MUTEX_TYPES is not set # CONFIG_PTHREAD_MUTEX_TYPES is not set
CONFIG_PTHREAD_MUTEX_ROBUST=y CONFIG_PTHREAD_MUTEX_ROBUST=y
# CONFIG_PTHREAD_MUTEX_UNSAFE is not set
# CONFIG_PTHREAD_MUTEX_BOTH is not set
CONFIG_NPTHREAD_KEYS=4 CONFIG_NPTHREAD_KEYS=4
# CONFIG_PTHREAD_CLEANUP is not set # CONFIG_PTHREAD_CLEANUP is not set
# CONFIG_CANCELLATION_POINTS is not set # CONFIG_CANCELLATION_POINTS is not set
@ -1160,6 +1163,7 @@ CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_USBSERIAL is not set # CONFIG_EXAMPLES_USBSERIAL is not set
# CONFIG_EXAMPLES_WATCHDOG is not set # CONFIG_EXAMPLES_WATCHDOG is not set
# CONFIG_EXAMPLES_WEBSERVER is not set # CONFIG_EXAMPLES_WEBSERVER is not set
# CONFIG_EXAMPLES_XBC_TEST is not set
# #
# File System Utilities # File System Utilities

View File

@ -50,8 +50,11 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <nuttx/net/netdev.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
@ -223,51 +226,66 @@
(((a)->u16[6]) == 0) && \ (((a)->u16[6]) == 0) && \
(((a)->u8[14]) == 0)) (((a)->u8[14]) == 0))
/* Maximum size of an IEEE802.15.4 frame */ /* This maximum size of an IEEE802.15.4 frame. Certain, non-standard
* devices may exceed this value, however.
*/
#define SIXLOWPAN_MAC_MAXFRAME 127 #define SIXLOWPAN_MAC_STDFRAME 127
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* The header for fragments /* The device structure for IEEE802.15.4 MAC network device differs from the
* standard Ethernet MAC device structure. The main reason for this
* difference is that fragmentation must be supported.
* *
* NOTE: We do not define different structures for FRAG1 and FRAGN headers, * The IEEE802.15.4 MAC does not use the d_buf packet buffer directly.
* which are different. For FRAG1, the offset field is just not used * Rather, it uses a smaller frame buffer. The packet data is provided to
* the frame buffer each time that the IEEE802.15.4 MAC needs to send
* more data.
*
* 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 ieee802154_driver_s' is cast
* compatible with 'struct net_driver_s' when CONFIG_NET_MULTINIC is not
* defined or when dev->d_lltype == NET_LL_IEEE802154.
*/ */
struct sixlowpan_frag_hdr struct ieee802154_driver_s
{ {
uint16_t dispatch_size; /* This definitiona must appear first in the structure definition to
uint16_t tag; * assure cast compatibility.
uint8_t offset; */
};
/* The HC1 header when HC_UDP is not used struct net_driver_s i_dev;
*
* When all fields are compressed and HC_UDP is not used, we use this
* structure. If HC_UDP is used, the ttl is in another spot, and we use the
* sixlowpan_hc1_hc_udp structure
*/
struct sixlowpan_hc1hdr_s /* IEEE802.15.4 MAC-specific definitions follow. */
{
uint8_t dispatch;
uint8_t encoding;
uint8_t ttl;
};
/* HC1 followed by HC_UDP */ /* The i_frame array is used to hold outgoing frame. When the
* IEEE802.15.4 device polls for new data, the outgoing frame containing
* the next fragment is placed in i_frame.
*
* The network will handle only a single outgong frame at a time. The
* IEEE802.15.4 MAC driver design may be concurrently sending and
* requesting new framesusing break-off fram buffers. That frame buffer
* management must be controlled by the IEEE802.15.4 MAC driver.
*
* Driver provied frame buffers should be 16-bit aligned.
*/
struct sixlowpan_hc1_hcudp_hdr_s FAR uint8_t *i_frame;
{
uint8_t dispatch; /* The length of valid data in the i_frame buffer.
uint8_t hc1_encoding; *
uint8_t hc_udp_encoding; * When the network device driver calls the network input function,
uint8_t ttl; * i_framelen should be set to zero. If there is frame to be sent
uint8_t ports; * by the network, i_framelen will be set to indicate the size of
uint16_t udpchksum; * frame to be sent. The value zero means that there is no frame
* to be sent.
*/
uint16_t i_framelen;
}; };
/* The structure of a next header compressor. This compressor is provided /* The structure of a next header compressor. This compressor is provided

View File

@ -230,7 +230,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
case NET_LL_IEEE802154: /* IEEE 802.15.4 MAC */ case NET_LL_IEEE802154: /* IEEE 802.15.4 MAC */
dev->d_llhdrlen = 0; /* REVISIT */ dev->d_llhdrlen = 0; /* REVISIT */
dev->d_mtu = SIXLOWPAN_MAC_MAXFRAME; dev->d_mtu = CONFIG_NET_6LOWPAN_FRAMELEN;
#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_TCP
dev->d_recvwndo = CONFIG_NET_6LOWPAN_TCP_RECVWNDO; dev->d_recvwndo = CONFIG_NET_6LOWPAN_TCP_RECVWNDO;
#endif #endif

View File

@ -20,6 +20,14 @@ config NET_6LOWPAN_FRAG
CONFIG_NET_6LOWPAN_FRAG specifies if 6lowpan fragmentation should be CONFIG_NET_6LOWPAN_FRAG specifies if 6lowpan fragmentation should be
used or not. Fragmentation is on by default. used or not. Fragmentation is on by default.
config NET_6LOWPAN_FRAMELEN
int "IEEE802.15.4 MAC Frame Length"
default 127
range 127 999999
---help---
Some wireless devices may use non-standard frame lengths. This
setting should never be smaller than 127.
choice choice
prompt "6loWPAN Compression" prompt "6loWPAN Compression"
default NET_6LOWPAN_COMPRESSION_HC06 default NET_6LOWPAN_COMPRESSION_HC06

View File

@ -54,6 +54,7 @@
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -62,11 +63,20 @@
* Name: sixlowpan_send * Name: sixlowpan_send
* *
* Description: * Description:
* Process an outgoing UDP or TCP packet. Called from UDP/TCP logic to * Process an outgoing UDP or TCP packet. Takes an IP packet and formats
* determine if the the packet should be formatted for 6loWPAN output. * 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: * Input Parameters:
* dev - The IEEE802.15.4 MAC network driver interface. * dev - The IEEE802.15.4 MAC network driver interface.
* raddr - The MAC address of the destination
* *
* Returned Value: * Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned. * Ok is returned on success; Othewise a negated errno value is returned.
@ -79,8 +89,10 @@
* *
****************************************************************************/ ****************************************************************************/
int sixlowpan_send(FAR struct net_driver_s *dev) int sixlowpan_send(FAR struct net_driver_s *dev, net_ipv6addr_t raddr)
{ {
FAR struct ieee802154_driver_s *ieee = (FAR struct ieee802154_driver_s *)dev;
net_lock(); net_lock();
/* REVISIT: To be provided */ /* REVISIT: To be provided */
net_unlock(); net_unlock();
@ -143,6 +155,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
conn = (FAR struct tcp_conn_s *)psock->s_conn; conn = (FAR struct tcp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL); DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */ /* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6) if (conn->domain != PF_INET6)
@ -150,6 +163,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
nwarn("WARNING: Not IPv6\n"); nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE; return (ssize_t)-EPROTOTYPE;
} }
#endif
/* Route outgoing message to the correct device */ /* Route outgoing message to the correct device */
@ -188,7 +202,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
* packet. * packet.
*/ */
ret = sixlowpan_send(dev); ret = sixlowpan_send(dev, conn->u.ipv6.raddr);
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: sixlowpan_send() failed: %d\n", ret); nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
@ -251,6 +265,7 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
conn = (FAR struct udp_conn_s *)psock->s_conn; conn = (FAR struct udp_conn_s *)psock->s_conn;
DEBUGASSERT(conn != NULL); DEBUGASSERT(conn != NULL);
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
/* Ignore if not IPv6 domain */ /* Ignore if not IPv6 domain */
if (conn->domain != PF_INET6) if (conn->domain != PF_INET6)
@ -258,6 +273,7 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
nwarn("WARNING: Not IPv6\n"); nwarn("WARNING: Not IPv6\n");
return (ssize_t)-EPROTOTYPE; return (ssize_t)-EPROTOTYPE;
} }
#endif
/* Route outgoing message to the correct device */ /* Route outgoing message to the correct device */
@ -296,7 +312,7 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
* packet. * packet.
*/ */
ret = sixlowpan_send(dev); ret = sixlowpan_send(dev, conn->u.ipv6.raddr);
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: sixlowpan_send() failed: %d\n", ret); nerr("ERROR: sixlowpan_send() failed: %d\n", ret);