mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
6loWPAN: Fleshes out framwork for IEEE802.15.4 send. But still has some gaping holes.
This commit is contained in:
@@ -99,7 +99,6 @@
|
|||||||
#define SIXLOWPAN_IPHC_TTL_255 0x03
|
#define SIXLOWPAN_IPHC_TTL_255 0x03
|
||||||
#define SIXLOWPAN_IPHC_TTL_I 0x00
|
#define SIXLOWPAN_IPHC_TTL_I 0x00
|
||||||
|
|
||||||
|
|
||||||
/* Values of fields within the IPHC encoding second byte */
|
/* Values of fields within the IPHC encoding second byte */
|
||||||
|
|
||||||
#define SIXLOWPAN_IPHC_CID 0x80
|
#define SIXLOWPAN_IPHC_CID 0x80
|
||||||
@@ -422,6 +421,13 @@ struct ieee802154_driver_s
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t i_dsn;
|
uint8_t i_dsn;
|
||||||
|
|
||||||
|
/* i_dgramtag. Datagram tag to be put in the header of the set of
|
||||||
|
* fragments. It is used by the recipient to match fragments of the
|
||||||
|
* same payload.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint16_t i_dgramtag;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The structure of a next header compressor. This compressor is provided
|
/* The structure of a next header compressor. This compressor is provided
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* net/devif/devif.h
|
* net/devif/devif.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2013-2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2013-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* This logic was leveraged from uIP which also has a BSD-style license:
|
* This logic was leveraged from uIP which also has a BSD-style license:
|
||||||
@@ -170,11 +170,13 @@
|
|||||||
#define TCP_NEWDATA (1 << 1)
|
#define TCP_NEWDATA (1 << 1)
|
||||||
#define UDP_NEWDATA TCP_NEWDATA
|
#define UDP_NEWDATA TCP_NEWDATA
|
||||||
#define PKT_NEWDATA TCP_NEWDATA
|
#define PKT_NEWDATA TCP_NEWDATA
|
||||||
|
#define WPAN_NEWDATA TCP_NEWDATA
|
||||||
#define TCP_SNDACK (1 << 2)
|
#define TCP_SNDACK (1 << 2)
|
||||||
#define TCP_REXMIT (1 << 3)
|
#define TCP_REXMIT (1 << 3)
|
||||||
#define TCP_POLL (1 << 4)
|
#define TCP_POLL (1 << 4)
|
||||||
#define UDP_POLL TCP_POLL
|
#define UDP_POLL TCP_POLL
|
||||||
#define PKT_POLL TCP_POLL
|
#define PKT_POLL TCP_POLL
|
||||||
|
#define WPAN_POLL TCP_POLL
|
||||||
#define TCP_BACKLOG (1 << 5)
|
#define TCP_BACKLOG (1 << 5)
|
||||||
#define TCP_CLOSE (1 << 6)
|
#define TCP_CLOSE (1 << 6)
|
||||||
#define TCP_ABORT (1 << 7)
|
#define TCP_ABORT (1 << 7)
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
|
|||||||
|
|
||||||
FAR uint8_t *g_rimeptr;
|
FAR uint8_t *g_rimeptr;
|
||||||
|
|
||||||
|
/* The length of the payload in the Rime buffer.
|
||||||
|
*
|
||||||
|
* The payload is what comes after the compressed or uncompressed headers
|
||||||
|
* (can be the IP payload if the IP header only is compressed or the UDP
|
||||||
|
* payload if the UDP header is also compressed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t g_rime_payloadlen;
|
||||||
|
|
||||||
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
|
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
|
||||||
* is used this includes the UDP header in addition to the IP header).
|
* is used this includes the UDP header in addition to the IP header).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -82,24 +82,45 @@
|
|||||||
#define rimeaddr_cmp(addr1,addr2) \
|
#define rimeaddr_cmp(addr1,addr2) \
|
||||||
(memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0)
|
(memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0)
|
||||||
|
|
||||||
/* Frame buffer helpers */
|
/* Pointers in the Rime buffer */
|
||||||
|
|
||||||
#define FRAME_RESET() \
|
/* Fragment header.
|
||||||
do \
|
*
|
||||||
{ \
|
* The fragment header is used when the payload is too large to fit in a
|
||||||
g_dataoffset = 0; \
|
* single IEEE 802.15.4 frame. The fragment header contains three fields:
|
||||||
} \
|
* Datagram size, datagram tag and datagram offset.
|
||||||
while (0)
|
*
|
||||||
|
* 1. Datagram size describes the total (un-fragmented) payload.
|
||||||
|
* 2. Datagram tag identifies the set of fragments and is used to match
|
||||||
|
* fragments of the same payload.
|
||||||
|
* 3. Datagram offset identifies the fragment’s offset within the un-
|
||||||
|
* fragmented payload.
|
||||||
|
*
|
||||||
|
* The fragment header length is 4 bytes for the first header and 5
|
||||||
|
* bytes for all subsequent headers.
|
||||||
|
*/
|
||||||
|
|
||||||
#define FRAME_HDR_START(iob) ((iob)->io_data)
|
#define RIME_FRAG_PTR g_rimeptr
|
||||||
#define FRAME_HDR_SIZE(iob) g_dataoffset
|
#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */
|
||||||
|
#define RIME_FRAG_TAG 2 /* 16 bit */
|
||||||
|
#define RIME_FRAG_OFFSET 4 /* 8 bit */
|
||||||
|
|
||||||
#define FRAME_DATA_START(iob) ((FAR uint8_t *)((iob)->io_data) + g_dataoffset)
|
/* Define the Rime buffer as a byte array */
|
||||||
#define FRAME_DATA_SIZE(iob) ((iob)->io_len - g_dataoffset)
|
|
||||||
|
|
||||||
#define FRAME_REMAINING(iob) (CONFIG_NET_6LOWPAN_FRAMELEN - (iob)->io_len)
|
#define RIME_IPHC_BUF (g_rimeptr + g_rime_hdrlen)
|
||||||
#define FRAME_SIZE(ieee,iob) \
|
|
||||||
((iob)->io_len)
|
#define RIME_HC1_PTR (g_rimeptr + g_rime_hdrlen)
|
||||||
|
#define RIME_HC1_DISPATCH 0 /* 8 bit */
|
||||||
|
#define RIME_HC1_ENCODING 1 /* 8 bit */
|
||||||
|
#define RIME_HC1_TTL 2 /* 8 bit */
|
||||||
|
|
||||||
|
#define RIME_HC1_HC_UDP_PTR (g_rimeptr + g_rime_hdrlen)
|
||||||
|
#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */
|
||||||
|
#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */
|
||||||
|
#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */
|
||||||
|
#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */
|
||||||
|
#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */
|
||||||
|
#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */
|
||||||
|
|
||||||
/* These are some definitions of element values used in the FCF. See the
|
/* These are some definitions of element values used in the FCF. See the
|
||||||
* IEEE802.15.4 spec for details.
|
* IEEE802.15.4 spec for details.
|
||||||
@@ -185,6 +206,37 @@
|
|||||||
|
|
||||||
#define PACKETBUF_NUM_ADDRS 4
|
#define PACKETBUF_NUM_ADDRS 4
|
||||||
|
|
||||||
|
/* Frame buffer helpers *****************************************************/
|
||||||
|
|
||||||
|
#define FRAME_RESET() \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
g_dataoffset = 0; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
#define FRAME_HDR_START(iob) ((iob)->io_data)
|
||||||
|
#define FRAME_HDR_SIZE(iob) g_dataoffset
|
||||||
|
|
||||||
|
#define FRAME_DATA_START(iob) ((FAR uint8_t *)((iob)->io_data) + g_dataoffset)
|
||||||
|
#define FRAME_DATA_SIZE(iob) ((iob)->io_len - g_dataoffset)
|
||||||
|
|
||||||
|
#define FRAME_REMAINING(iob) (CONFIG_NET_6LOWPAN_FRAMELEN - (iob)->io_len)
|
||||||
|
#define FRAME_SIZE(ieee,iob) \
|
||||||
|
((iob)->io_len)
|
||||||
|
|
||||||
|
/* General helper macros ****************************************************/
|
||||||
|
|
||||||
|
#define GETINT16(ptr,index) \
|
||||||
|
((((uint16_t)((ptr)[index]) << 8)) | ((uint16_t)(((ptr)[(index) + 1]))))
|
||||||
|
#define PUTINT16(ptr,index,value) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
(ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \
|
||||||
|
(ptr)[index + 1] = (uint16_t)(value) & 0xff; \
|
||||||
|
} \
|
||||||
|
while(0)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -310,6 +362,15 @@ extern FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
|
|||||||
|
|
||||||
extern FAR uint8_t *g_rimeptr;
|
extern FAR uint8_t *g_rimeptr;
|
||||||
|
|
||||||
|
/* The length of the payload in the Rime buffer.
|
||||||
|
*
|
||||||
|
* The payload is what comes after the compressed or uncompressed headers
|
||||||
|
* (can be the IP payload if the IP header only is compressed or the UDP
|
||||||
|
* payload if the UDP header is also compressed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern uint8_t g_rime_payloadlen;
|
||||||
|
|
||||||
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
|
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
|
||||||
* is used this includes the UDP header in addition to the IP header).
|
* is used this includes the UDP header in addition to the IP header).
|
||||||
*/
|
*/
|
||||||
@@ -360,11 +421,12 @@ struct iob_s; /* Forward reference */
|
|||||||
* ieee->i_framelist.
|
* ieee->i_framelist.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* dev - The IEEE802.15.4 MAC network driver interface.
|
* dev - The IEEE802.15.4 MAC network driver interface.
|
||||||
* ipv6 - IPv6 plus TCP or UDP headers.
|
* ipv6 - IPv6 plus TCP or UDP headers.
|
||||||
* buf - Data to send
|
* buf - Data to send
|
||||||
* len - Length of data to send
|
* len - Length of data to send
|
||||||
* raddr - The MAC address of the destination
|
* raddr - The MAC address of the destination
|
||||||
|
* timeout - Send timeout in deciseconds
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
@@ -379,7 +441,8 @@ struct iob_s; /* Forward reference */
|
|||||||
|
|
||||||
int sixlowpan_send(FAR struct net_driver_s *dev,
|
int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||||
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
|
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
|
||||||
size_t len, FAR const struct rimeaddr_s *raddr);
|
size_t len, FAR const struct rimeaddr_s *raddr,
|
||||||
|
uint16_t timeout);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: sixlowpan_hdrlen
|
* Function: sixlowpan_hdrlen
|
||||||
|
|||||||
+387
-68
File diff suppressed because it is too large
Load Diff
@@ -86,6 +86,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
FAR struct net_driver_s *dev;
|
FAR struct net_driver_s *dev;
|
||||||
struct ipv6tcp_hdr_s ipv6tcp;
|
struct ipv6tcp_hdr_s ipv6tcp;
|
||||||
struct rimeaddr_s dest;
|
struct rimeaddr_s dest;
|
||||||
|
uint16_t timeout;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
|
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
|
||||||
@@ -173,8 +174,14 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* packet.
|
* packet.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_SOCKOPTS
|
||||||
|
timeout = psock->s_sndtimeo;
|
||||||
|
#else
|
||||||
|
timeout = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6tcp,
|
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6tcp,
|
||||||
buf, len, &dest);
|
buf, len, &dest, timeout);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
|
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
FAR struct net_driver_s *dev;
|
FAR struct net_driver_s *dev;
|
||||||
struct ipv6udp_hdr_s ipv6udp;
|
struct ipv6udp_hdr_s ipv6udp;
|
||||||
struct rimeaddr_s dest;
|
struct rimeaddr_s dest;
|
||||||
|
uint16_t timeout;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
|
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
|
||||||
@@ -174,8 +175,14 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* packet.
|
* packet.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_SOCKOPTS
|
||||||
|
timeout = psock->s_sndtimeo;
|
||||||
|
#else
|
||||||
|
timeout = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6udp,
|
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6udp,
|
||||||
buf, len, &dest);
|
buf, len, &dest, timeout);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
|
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ struct send_s
|
|||||||
* TRUE:timeout FALSE:no timeout
|
* TRUE:timeout FALSE:no timeout
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* Running at the interrupt level
|
* The network is locked.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ static inline int send_timeout(FAR struct send_s *pstate)
|
|||||||
FAR struct socket *psock;
|
FAR struct socket *psock;
|
||||||
|
|
||||||
/* Check for a timeout configured via setsockopts(SO_SNDTIMEO).
|
/* Check for a timeout configured via setsockopts(SO_SNDTIMEO).
|
||||||
* If none... we well let the send wait forever.
|
* If none... we will let the send wait forever.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
psock = pstate->snd_sock;
|
psock = pstate->snd_sock;
|
||||||
@@ -173,7 +173,7 @@ static inline int send_timeout(FAR struct send_s *pstate)
|
|||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* Running at the interrupt level
|
* The network is locked.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ static inline void tcpsend_ipselect(FAR struct net_driver_s *dev,
|
|||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* Running at the interrupt level
|
* The network is locked.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn)
|
|||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* Running at the interrupt level
|
* The network is locked.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -708,8 +708,6 @@ static inline void send_txnotify(FAR struct socket *psock,
|
|||||||
* In this case the process will also receive a SIGPIPE unless
|
* In this case the process will also receive a SIGPIPE unless
|
||||||
* MSG_NOSIGNAL is set.
|
* MSG_NOSIGNAL is set.
|
||||||
*
|
*
|
||||||
* Assumptions:
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
ssize_t psock_tcp_send(FAR struct socket *psock,
|
ssize_t psock_tcp_send(FAR struct socket *psock,
|
||||||
|
|||||||
Reference in New Issue
Block a user