mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36:28 +08:00
6loWPAN: Changes to use new MAC interfaces. Incomplete and needs some clean-up of dangling, unused definitions.
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
|
||||
#include "sixlowpan/sixlowpan_internal.h"
|
||||
|
||||
@@ -183,9 +184,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
*
|
||||
* The payload data is in the caller 'buf' and is of length 'buflen'.
|
||||
* Compressed headers will be added and if necessary the packet is
|
||||
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
|
||||
* and the entire list of frames will be delivered to the 802.15.4 MAC via
|
||||
* ieee->i_framelist.
|
||||
* fragmented. The resulting packet/fragments are submitted to the MAC
|
||||
* where they are queue for transfer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - The IEEE802.15.4 MAC driver instance
|
||||
@@ -211,6 +211,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR const void *buf, size_t buflen,
|
||||
FAR const struct rimeaddr_s *destmac)
|
||||
{
|
||||
struct ieee802154_frame_meta_s meta;
|
||||
FAR struct iob_s *iob;
|
||||
FAR uint8_t *fptr;
|
||||
int framer_hdrlen;
|
||||
@@ -221,6 +222,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
#ifdef CONFIG_NET_6LOWPAN_FRAG
|
||||
uint16_t outlen = 0;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
/* Initialize global data. Locking the network guarantees that we have
|
||||
* exclusive use of the global values for intermediate calculations.
|
||||
@@ -297,18 +299,33 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
dest_panid = 0xffff;
|
||||
(void)sixlowpan_src_panid(ieee, &dest_panid);
|
||||
|
||||
/* Based on the collected attributes and addresses, construct the MAC meta
|
||||
* data structure that we need to interface with the IEEE802.15.4 MAC.
|
||||
*/
|
||||
|
||||
ret = sixlowpan_meta_data(dest_panid, &meta);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
/* Pre-calculate frame header length. */
|
||||
|
||||
framer_hdrlen = sixlowpan_send_hdrlen(ieee, dest_panid);
|
||||
framer_hdrlen = sixlowpan_frame_hdrlen(ieee, &meta);
|
||||
if (framer_hdrlen < 0)
|
||||
{
|
||||
/* Failed to determine the size of the header failed. */
|
||||
|
||||
nerr("ERROR: sixlowpan_send_hdrlen() failed: %d\n", framer_hdrlen);
|
||||
nerr("ERROR: sixlowpan_frame_hdrlen() failed: %d\n", framer_hdrlen);
|
||||
return framer_hdrlen;
|
||||
}
|
||||
|
||||
g_frame_hdrlen = framer_hdrlen;
|
||||
/* This sill be the initial offset into io_data. Valid data begins at
|
||||
* this offset and must be reflected in io_offset.
|
||||
*/
|
||||
|
||||
g_frame_hdrlen = framer_hdrlen;
|
||||
iob->io_offset = framer_hdrlen;
|
||||
|
||||
#ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6
|
||||
if (buflen >= CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD)
|
||||
@@ -338,15 +355,15 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
if (buflen > (CONFIG_NET_6LOWPAN_FRAMELEN - g_frame_hdrlen))
|
||||
{
|
||||
#ifdef CONFIG_NET_6LOWPAN_FRAG
|
||||
/* ieee->i_framelist will hold the generated frames; frames will be
|
||||
/* qhead will hold the generated frame list; frames will be
|
||||
* added at qtail.
|
||||
*/
|
||||
|
||||
FAR struct iob_s *qhead;
|
||||
FAR struct iob_s *qtail;
|
||||
FAR uint8_t *frame1;
|
||||
FAR uint8_t *fragptr;
|
||||
uint16_t frag1_hdrlen;
|
||||
int verify;
|
||||
|
||||
/* The outbound IPv6 packet is too large to fit into a single 15.4
|
||||
* packet, so we fragment it into multiple packets and send them.
|
||||
@@ -358,13 +375,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
ninfo("Sending fragmented packet length %d\n", buflen);
|
||||
|
||||
/* Create 1st Fragment */
|
||||
/* Add the frame header using the pre-allocated IOB using the DSN
|
||||
* selected by sixlowpan_send_hdrlen().
|
||||
*/
|
||||
|
||||
verify = sixlowpan_framecreate(ieee, iob, dest_panid);
|
||||
DEBUGASSERT(verify == framer_hdrlen);
|
||||
UNUSED(verify);
|
||||
|
||||
/* Move HC1/HC06/IPv6 header to make space for the FRAG1 header at the
|
||||
* beginning of the frame.
|
||||
@@ -405,8 +415,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
/* Set outlen to what we already sent from the IP payload */
|
||||
|
||||
iob->io_len = paysize + g_frame_hdrlen;
|
||||
outlen = paysize;
|
||||
iob->io_len = paysize + g_frame_hdrlen;
|
||||
outlen = paysize;
|
||||
|
||||
ninfo("First fragment: length %d, tag %d\n",
|
||||
paysize, ieee->i_dgramtag);
|
||||
@@ -415,17 +425,17 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
/* Add the first frame to the IOB queue */
|
||||
|
||||
ieee->i_framelist = iob;
|
||||
qtail = iob;
|
||||
qhead = iob;
|
||||
qtail = iob;
|
||||
|
||||
/* Keep track of the total amount of data queue */
|
||||
|
||||
iob->io_pktlen = iob->io_len;
|
||||
iob->io_pktlen = iob->io_len;
|
||||
|
||||
/* Create following fragments */
|
||||
|
||||
frame1 = iob->io_data;
|
||||
frag1_hdrlen = g_frame_hdrlen;
|
||||
frame1 = iob->io_data;
|
||||
frag1_hdrlen = g_frame_hdrlen;
|
||||
|
||||
while (outlen < buflen)
|
||||
{
|
||||
@@ -442,20 +452,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
iob->io_flink = NULL;
|
||||
iob->io_len = 0;
|
||||
iob->io_offset = 0;
|
||||
iob->io_offset = framer_hdrlen;
|
||||
iob->io_pktlen = 0;
|
||||
fptr = iob->io_data;
|
||||
|
||||
/* Add a new frame header to the IOB (same as the first but with a
|
||||
* different DSN).
|
||||
*/
|
||||
|
||||
g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = 0;
|
||||
|
||||
verify = sixlowpan_framecreate(ieee, iob, dest_panid);
|
||||
DEBUGASSERT(verify == framer_hdrlen);
|
||||
UNUSED(verify);
|
||||
|
||||
/* Copy the HC1/HC06/IPv6 header the frame header from first
|
||||
* frame, into the correct location after the FRAGN header
|
||||
* of subsequent frames.
|
||||
@@ -508,9 +508,23 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
/* Keep track of the total amount of data queue */
|
||||
|
||||
ieee->i_framelist->io_pktlen += iob->io_len;
|
||||
qhead->io_pktlen += iob->io_len;
|
||||
}
|
||||
|
||||
/* Submit all of the fragments to the MAC */
|
||||
|
||||
while (qhead != NULL)
|
||||
{
|
||||
iob = qhead;
|
||||
qhead = iob->io_flink;
|
||||
|
||||
ret = sixlowpan_frame_submit(ieee, &meta, iob);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the datagram TAG value */
|
||||
|
||||
ieee->i_dgramtag++;
|
||||
@@ -524,34 +538,27 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
}
|
||||
else
|
||||
{
|
||||
int verify;
|
||||
|
||||
/* The packet does not need to be fragmented just copy the "payload"
|
||||
* and send in one frame.
|
||||
*/
|
||||
|
||||
/* Add the frame header to the preallocated IOB. */
|
||||
|
||||
verify = sixlowpan_framecreate(ieee, iob, dest_panid);
|
||||
DEBUGASSERT(verify == framer_hdrlen);
|
||||
UNUSED(verify);
|
||||
|
||||
/* Copy the payload and queue */
|
||||
/* Copy the payload into the frame. */
|
||||
|
||||
memcpy(fptr + g_frame_hdrlen, buf, buflen);
|
||||
iob->io_len = buflen + g_frame_hdrlen;
|
||||
iob->io_len = buflen + g_frame_hdrlen;
|
||||
iob->io_pktlen = iob->io_len;
|
||||
|
||||
ninfo("Non-fragmented: length %d\n", iob->io_len);
|
||||
sixlowpan_dumpbuffer("Outgoing frame",
|
||||
(FAR const uint8_t *)iob->io_data, iob->io_len);
|
||||
|
||||
/* Add the first frame to the IOB queue */
|
||||
/* Submit the frame to the MAC */
|
||||
|
||||
ieee->i_framelist = iob;
|
||||
|
||||
/* Keep track of the total amount of data queue */
|
||||
|
||||
iob->io_pktlen = iob->io_len;
|
||||
ret = sixlowpan_frame_submit(ieee, &meta, iob);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+41
-123
@@ -129,92 +129,6 @@ static uint8_t g_bitbucket[UNCOMP_MAXHDR];
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_recv_hdrlen
|
||||
*
|
||||
* Description:
|
||||
* Get the length of the IEEE802.15.4 FCF header on the received frame.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - The IEEE802.15.4 MAC network driver interface.
|
||||
* iob - The IOB containing the frame.
|
||||
*
|
||||
* Returned Value:
|
||||
* Ok is returned on success; Othewise a negated errno value is returned.
|
||||
*
|
||||
* Assumptions:
|
||||
* Network is locked
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr)
|
||||
{
|
||||
uint16_t hdrlen;
|
||||
uint8_t addrmode;
|
||||
|
||||
/* Minimum header: 2 byte FCF + 1 byte sequence number */
|
||||
|
||||
hdrlen = 3;
|
||||
|
||||
/* Account for destination address size */
|
||||
|
||||
addrmode = (fptr[1] & FRAME802154_DSTADDR_MASK) >> FRAME802154_DSTADDR_SHIFT;
|
||||
if (addrmode == FRAME802154_SHORTADDRMODE)
|
||||
{
|
||||
/* 2 byte dest PAN + 2 byte dest short address */
|
||||
|
||||
hdrlen += 4;
|
||||
}
|
||||
else if (addrmode == FRAME802154_LONGADDRMODE)
|
||||
{
|
||||
/* 2 byte dest PAN + 8 byte dest long address */
|
||||
|
||||
hdrlen += 10;
|
||||
}
|
||||
else if (addrmode != FRAME802154_NOADDR)
|
||||
{
|
||||
nwarn("WARNING: Unrecognized address mode\n");
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
else if ((fptr[0] & (1 << FRAME802154_PANIDCOMP_SHIFT)) != 0)
|
||||
{
|
||||
nwarn("WARNING: PAN compression, but no destination address\n");
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Account for source address size */
|
||||
|
||||
addrmode = (fptr[1] & FRAME802154_SRCADDR_MASK) >> FRAME802154_SRCADDR_SHIFT;
|
||||
if (addrmode == FRAME802154_NOADDR)
|
||||
{
|
||||
return hdrlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add source PANID if PANIDs are not compressed */
|
||||
|
||||
if ((fptr[0] & (1 << FRAME802154_PANIDCOMP_SHIFT)) == 0)
|
||||
{
|
||||
hdrlen += 2;
|
||||
}
|
||||
|
||||
/* Add the length of the source address */
|
||||
|
||||
if (addrmode == FRAME802154_SHORTADDRMODE)
|
||||
{
|
||||
return hdrlen + 2;
|
||||
}
|
||||
else if (addrmode == FRAME802154_LONGADDRMODE)
|
||||
{
|
||||
return hdrlen + 8;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_compress_ipv6hdr
|
||||
*
|
||||
@@ -245,7 +159,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr)
|
||||
{
|
||||
FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)bptr;
|
||||
uint16_t protosize;
|
||||
|
||||
|
||||
/* Put uncompressed IPv6 header in d_buf. */
|
||||
|
||||
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
|
||||
@@ -355,8 +269,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
|
||||
* This size includes both fragmentation and FCF headers.
|
||||
*/
|
||||
|
||||
fptr = iob->io_data;
|
||||
hdrsize = sixlowpan_recv_hdrlen(fptr);
|
||||
fptr = iob->io_data; /* Frame data is in I/O buffer */
|
||||
hdrsize = iob->io_offset; /* Offset past the MAC header */
|
||||
if (hdrsize < 0)
|
||||
{
|
||||
nwarn("Invalid IEEE802.15.2 header: %d\n", hdrsize);
|
||||
@@ -729,25 +643,32 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee)
|
||||
* Description:
|
||||
* Process an incoming 6loWPAN frame.
|
||||
*
|
||||
* This function is called when the device driver has received a 6loWPAN
|
||||
* frame from the network. The frame from the device driver must be
|
||||
* provided in a IOB present in the i_framelist: The frame data is in the
|
||||
* IOB io_data[] buffer and the length of the frame is in the IOB io_len
|
||||
* field. Only a single IOB is expected in the i_framelist. This incoming
|
||||
* data will be processed one frame at a time.
|
||||
* This function is called when the device driver has received an
|
||||
* IEEE802.15.4 frame from the network. The frame from the device
|
||||
* driver must be provided in by the IOB frame argument of the
|
||||
* function call:
|
||||
*
|
||||
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU must also be provided.
|
||||
* The frame will be decompressed and placed in the d_buf. Fragmented
|
||||
* packets will also be reassembled in the d_buf as they are received
|
||||
* (meaning for the driver, that two packet buffers are required: One for
|
||||
* reassembly of RX packets and one used for TX polling).
|
||||
* - The frame data is in the IOB io_data[] buffer,
|
||||
* - The length of the frame is in the IOB io_len field, and
|
||||
* - The offset past the IEEE802.15.4 MAC header is provided in the
|
||||
* io_offset field.
|
||||
*
|
||||
* After each frame is processed into d_buf, the IOB is removed and
|
||||
* deallocated. i_framelist will be nullified. If reassembly is
|
||||
* incomplete, this function will return to called with i_framelist
|
||||
* equal to NULL. The partially reassembled packet must be preserved by
|
||||
* the IEEE802.15.4 MAC and provided again when the next frame is
|
||||
* received.
|
||||
* The frame argument may refer to a single frame (a list of length one)
|
||||
* or may it be the head of a list of multiple frames.
|
||||
*
|
||||
* - The io_flink field points to the next frame in the list (if enable)
|
||||
* - The last frame in the list will have io_flink == NULL.
|
||||
*
|
||||
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE
|
||||
* must also be provided. The frame will be decompressed and placed in
|
||||
* the d_buf. Fragmented packets will also be reassembled in the d_buf as
|
||||
* they are received (meaning for the driver, that two packet buffers are
|
||||
* required: One for reassembly of RX packets and one used for TX polling).
|
||||
*
|
||||
* After each frame is processed into d_buf, the IOB is deallocated. If
|
||||
* reassembly is incomplete, the partially reassembled packet must be
|
||||
* preserved by the IEEE802.15.4 MAC network drvier sand provided again
|
||||
* when the next frame is received.
|
||||
*
|
||||
* When the packet in the d_buf is fully reassembled, it will be provided
|
||||
* to the network as with any other received packet. d_len will be set
|
||||
@@ -755,43 +676,40 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee)
|
||||
*
|
||||
* After the network processes the packet, d_len will be set to zero.
|
||||
* Network logic may also decide to send a response to the packet. In
|
||||
* that case, the outgoing network packet will be placed in d_buf the
|
||||
* d_buf and d_len will be set to a non-zero value. That case is handled
|
||||
* by this function.
|
||||
* that case, the outgoing network packet will be placed in d_buf and
|
||||
* d_len will be set to a non-zero value. That case is handled by this
|
||||
* function.
|
||||
*
|
||||
* If that case occurs, the packet will be converted to a list of
|
||||
* compressed and possibly fragmented frames in i_framelist as with other
|
||||
* TX operations.
|
||||
*
|
||||
* So from the standpoint of the IEEE802.15.4 MAC driver, there are two
|
||||
* possible results: (1) i_framelist is NULL meaning that the frame
|
||||
* was fully processed and freed, or (2) i_framelist is non-NULL meaning
|
||||
* that there are outgoing frame(s) to be sent.
|
||||
* compressed and possibly fragmented frames and provided to the MAC
|
||||
* network driver via the req_data() method as with other TX operations.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - The IEEE802.15.4 MAC network driver interface.
|
||||
* ieee - The IEEE802.15.4 MAC network driver interface.
|
||||
* framelist - The head of an incoming list of frames.
|
||||
*
|
||||
* Returned Value:
|
||||
* Ok is returned on success; Othewise a negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_input(FAR struct ieee802154_driver_s *ieee)
|
||||
int sixlowpan_input(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR struct iob_s *framelist)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
|
||||
DEBUGASSERT(ieee != NULL && !FRAME_IOB_EMPTY(ieee));
|
||||
DEBUGASSERT(ieee != NULL && framelist != NULL);
|
||||
|
||||
/* Verify that an IOB is provided in the device structure */
|
||||
/* Verify that an frame has been provided. */
|
||||
|
||||
while (!FRAME_IOB_EMPTY(ieee))
|
||||
while (framelist != NULL)
|
||||
{
|
||||
FAR struct iob_s *iob;
|
||||
|
||||
/* Remove the IOB containing the frame from the device structure */
|
||||
|
||||
FRAME_IOB_REMOVE(ieee, iob);
|
||||
DEBUGASSERT(iob != NULL);
|
||||
iob = framelist;
|
||||
framelist = iob->io_flink;
|
||||
|
||||
sixlowpan_dumpbuffer("Incoming frame", iob->io_data, iob->io_len);
|
||||
|
||||
|
||||
@@ -107,28 +107,27 @@
|
||||
#define PACKETBUF_ATTR_LISTEN_TIME 7
|
||||
#define PACKETBUF_ATTR_TRANSMIT_TIME 8
|
||||
#define PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 9
|
||||
#define PACKETBUF_ATTR_MAC_SEQNO 10
|
||||
#define PACKETBUF_ATTR_MAC_ACK 11
|
||||
#define PACKETBUF_ATTR_MAC_ACK 10
|
||||
|
||||
/* Scope 1 attributes: used between two neighbors only. */
|
||||
|
||||
#define PACKETBUF_ATTR_RELIABLE 12
|
||||
#define PACKETBUF_ATTR_PACKET_ID 13
|
||||
#define PACKETBUF_ATTR_PACKET_TYPE 14
|
||||
#define PACKETBUF_ATTR_REXMIT 15
|
||||
#define PACKETBUF_ATTR_MAX_REXMIT 16
|
||||
#define PACKETBUF_ATTR_NUM_REXMIT 17
|
||||
#define PACKETBUF_ATTR_PENDING 18
|
||||
#define PACKETBUF_ATTR_RELIABLE 11
|
||||
#define PACKETBUF_ATTR_PACKET_ID 12
|
||||
#define PACKETBUF_ATTR_PACKET_TYPE 13
|
||||
#define PACKETBUF_ATTR_REXMIT 14
|
||||
#define PACKETBUF_ATTR_MAX_REXMIT 15
|
||||
#define PACKETBUF_ATTR_NUM_REXMIT 16
|
||||
#define PACKETBUF_ATTR_PENDING 17
|
||||
|
||||
/* Scope 2 attributes: used between end-to-end nodes. */
|
||||
|
||||
#define PACKETBUF_ATTR_HOPS 11
|
||||
#define PACKETBUF_ATTR_TTL 20
|
||||
#define PACKETBUF_ATTR_EPACKET_ID 21
|
||||
#define PACKETBUF_ATTR_EPACKET_TYPE 22
|
||||
#define PACKETBUF_ATTR_ERELIABLE 23
|
||||
#define PACKETBUF_ATTR_HOPS 18
|
||||
#define PACKETBUF_ATTR_TTL 19
|
||||
#define PACKETBUF_ATTR_EPACKET_ID 20
|
||||
#define PACKETBUF_ATTR_EPACKET_TYPE 21
|
||||
#define PACKETBUF_ATTR_ERELIABLE 22
|
||||
|
||||
#define PACKETBUF_NUM_ATTRS 24
|
||||
#define PACKETBUF_NUM_ATTRS 23
|
||||
|
||||
/* Addresses (indices into g_pktaddrs) */
|
||||
|
||||
@@ -188,69 +187,6 @@ struct ipv6icmp_hdr_s
|
||||
struct icmpv6_iphdr_s icmp;
|
||||
};
|
||||
|
||||
/* IEEE802.15.4 Frame Definitions *******************************************/
|
||||
/* The IEEE 802.15.4 frame has a number of constant/fixed fields that can be
|
||||
* counted to make frame construction and max payload calculations easier.
|
||||
* These include:
|
||||
*
|
||||
* 1. FCF - 2 bytes - Fixed
|
||||
* 2. Sequence number - 1 byte - Fixed
|
||||
* 3. Addressing fields - 4 - 20 bytes - Variable
|
||||
* 4. Aux security header - 0 - 14 bytes - Variable
|
||||
* 5. CRC - 2 bytes - Fixed
|
||||
*/
|
||||
|
||||
/* Defines the bitfields of the frame control field (FCF). */
|
||||
|
||||
struct frame802154_fcf_s
|
||||
{
|
||||
uint8_t frame_type; /* 3 bit. Frame type field, see 802.15.4 */
|
||||
uint8_t security_enabled; /* 1 bit. True if security is used in this frame */
|
||||
uint8_t frame_pending; /* 1 bit. True if sender has more data to send */
|
||||
uint8_t ack_required; /* 1 bit. Is an ack frame required? */
|
||||
uint8_t panid_compression; /* 1 bit. Is this a compressed header? */
|
||||
/* 3 bit. Unused bits */
|
||||
uint8_t dest_addr_mode; /* 2 bit. Destination address mode, see 802.15.4 */
|
||||
uint8_t frame_version; /* 2 bit. 802.15.4 frame version */
|
||||
uint8_t src_addr_mode; /* 2 bit. Source address mode, see 802.15.4 */
|
||||
};
|
||||
|
||||
/* 802.15.4 security control bitfield. See section 7.6.2.2.1 in 802.15.4
|
||||
* specification.
|
||||
*/
|
||||
|
||||
struct frame802154_scf_s
|
||||
{
|
||||
uint8_t security_level; /* 3 bit. security level */
|
||||
uint8_t key_id_mode; /* 2 bit. Key identifier mode */
|
||||
uint8_t reserved; /* 3 bit. Reserved bits */
|
||||
};
|
||||
|
||||
/* 802.15.4 Aux security header */
|
||||
|
||||
struct frame802154_aux_hdr_s
|
||||
{
|
||||
struct frame802154_scf_s security_control; /* Security control bitfield */
|
||||
uint32_t frame_counter; /* Frame counter, used for security */
|
||||
uint8_t key[9]; /* The key itself, or an index to the key */
|
||||
};
|
||||
|
||||
/* Parameters used by the frame802154_create() function. These parameters
|
||||
* are used in the 802.15.4 frame header. See the 802.15.4 specification
|
||||
* for details.
|
||||
*/
|
||||
|
||||
struct frame802154_s
|
||||
{
|
||||
struct frame802154_fcf_s fcf; /* Frame control field */
|
||||
uint8_t seq; /* Sequence number */
|
||||
uint16_t dest_pid; /* Destination PAN ID */
|
||||
uint8_t dest_addr[8]; /* Destination address */
|
||||
uint16_t src_pid; /* Source PAN ID */
|
||||
uint8_t src_addr[8]; /* Source address */
|
||||
struct frame802154_aux_hdr_s aux_hdr; /* Aux security header */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@@ -313,9 +249,8 @@ struct iob_s; /* Forward reference */
|
||||
*
|
||||
* The payload data is in the caller 'buf' and is of length 'buflen'.
|
||||
* Compressed headers will be added and if necessary the packet is
|
||||
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
|
||||
* and the entire list of frames will be delivered to the 802.15.4 MAC via
|
||||
* ieee->i_framelist.
|
||||
* fragmented. The resulting packet/fragments are submitted to the MAC
|
||||
* via the network driver i_req_data method.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The IEEE802.15.4 MAC network driver interface.
|
||||
@@ -344,7 +279,30 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||
uint16_t timeout);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_send_hdrlen
|
||||
* Name: sixlowpan_meta_data
|
||||
*
|
||||
* Description:
|
||||
* Based on the collected attributes and addresses, construct the MAC meta
|
||||
* data structure that we need to interface with the IEEE802.15.4 MAC.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
|
||||
* is not associated.
|
||||
* meta - Location to return the corresponding meta data.
|
||||
*
|
||||
* Returned Value:
|
||||
* Ok is returned on success; Othewise a negated errno value is returned.
|
||||
*
|
||||
* Assumptions:
|
||||
* Called with the network locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_meta_data(uint16_t dest_panid,
|
||||
FAR struct ieee802154_frame_meta_s *meta);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_frame_hdrlen
|
||||
*
|
||||
* Description:
|
||||
* This function is before the first frame has been sent in order to
|
||||
@@ -352,9 +310,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||
* buffer is required to make this determination.
|
||||
*
|
||||
* Input parameters:
|
||||
* ieee - A reference IEEE802.15.4 MAC network device structure.
|
||||
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
|
||||
* is not associated.
|
||||
* ieee - A reference IEEE802.15.4 MAC network device structure.
|
||||
* meta - Meta data that describes the MAC header
|
||||
*
|
||||
* Returned Value:
|
||||
* The frame header length is returnd on success; otherwise, a negated
|
||||
@@ -362,30 +319,32 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_send_hdrlen(FAR struct ieee802154_driver_s *ieee,
|
||||
uint16_t dest_panid);
|
||||
int sixlowpan_frame_hdrlen(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR const struct ieee802154_frame_meta_s *meta);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_framecreate
|
||||
* Name: sixlowpan_frame_submit
|
||||
*
|
||||
* Description:
|
||||
* This function is called after the IEEE802.15.4 MAC driver polls for
|
||||
* TX data. It creates the IEEE802.15.4 header in the frame buffer.
|
||||
* This function is called after eiether (1) the IEEE802.15.4 MAC driver
|
||||
* polls for TX data or (2) after the IEEE802.15.4 MAC driver provides a
|
||||
* new incoming frame and the network responds with an outgoing packet. It
|
||||
* submits any new outgoing frame to the MAC.
|
||||
*
|
||||
* Input parameters:
|
||||
* ieee - A reference IEEE802.15.4 MAC network device structure.
|
||||
* iob - The IOB in which to create the frame.
|
||||
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
|
||||
* is not associated.
|
||||
* ieee - A reference IEEE802.15.4 MAC network device structure.
|
||||
* meta - Meta data that describes the MAC header
|
||||
* frame - The IOB containing the frame to be submitted.
|
||||
*
|
||||
* Returned Value:
|
||||
* The frame header length is returnd on success; otherwise, a negated
|
||||
* errno value is return on failure.
|
||||
* Zero (OK) is returned on success; otherwise, a negated errno value is
|
||||
* return on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR struct iob_s *iob, uint16_t dest_panid);
|
||||
int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR const struct ieee802154_frame_meta_s *meta,
|
||||
FAR struct iob_s *frame);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_queue_frames
|
||||
@@ -397,9 +356,8 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
|
||||
*
|
||||
* The payload data is in the caller 'buf' and is of length 'buflen'.
|
||||
* Compressed headers will be added and if necessary the packet is
|
||||
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
|
||||
* and the entire list of frames will be delivered to the 802.15.4 MAC via
|
||||
* ieee->i_framelist.
|
||||
* fragmented. The resulting packet/fragments are submitted to the MAC
|
||||
* via the network driver i_req_data method.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - The IEEE802.15.4 MAC driver instance
|
||||
|
||||
@@ -246,11 +246,10 @@ end_wait:
|
||||
* 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'.
|
||||
* The payload data is in the caller 'buf' and is of length 'buflen'.
|
||||
* Compressed headers will be added and if necessary the packet is
|
||||
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
|
||||
* and the entire list of frames will be delivered to the 802.15.4 MAC via
|
||||
* ieee->i_framelist.
|
||||
* fragmented. The resulting packet/fragments are submitted to the MAC
|
||||
* via the network driver i_req_data method.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The IEEE802.15.4 MAC network driver interface.
|
||||
|
||||
Reference in New Issue
Block a user