Skip to content

Commit

Permalink
6loWPAN: Local MAC address is fixed by the configuration. The remote …
Browse files Browse the repository at this point in the history
…address be with short or extended.
  • Loading branch information
gregory-nutt committed May 5, 2017
1 parent 9d9fbcb commit 14fc1b2
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 75 deletions.
6 changes: 6 additions & 0 deletions include/nuttx/net/ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ union sixlowpan_anyaddr_u
struct sixlowpan_eaddr_s eaddr;
};

struct sixlowpan_tagaddr_s
{
bool extended;
union sixlowpan_anyaddr_u u;
};

/* Represents the configured address size */

struct sixlowpan_addr_s
Expand Down
2 changes: 1 addition & 1 deletion include/nuttx/net/sixlowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@

#define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \
((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \
(((a)[6]) == 0xfe00))
(((a)[6]) == HTONS(0xfe00)))

/* Check whether the 9-bit group-id of the compressed multicast address is
* known. It is true if the 9-bit group is the all nodes or all routers
Expand Down
37 changes: 18 additions & 19 deletions net/sixlowpan/sixlowpan_framelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *destip,
FAR const void *buf, size_t buflen,
FAR const struct sixlowpan_addr_s *destmac)
FAR const struct sixlowpan_tagaddr_s *destmac)
{
struct ieee802154_frame_meta_s meta;
FAR struct iob_s *iob;
FAR uint8_t *fptr;
int framer_hdrlen;
struct sixlowpan_addr_s bcastmac;
struct sixlowpan_tagaddr_s bcastmac;
uint16_t pktlen;
uint16_t paysize;
#ifdef CONFIG_NET_6LOWPAN_FRAG
Expand Down Expand Up @@ -261,7 +261,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,

if (destmac == NULL)
{
memset(&bcastmac, 0, sizeof(struct sixlowpan_addr_s));
memset(&bcastmac, 0, sizeof(struct sixlowpan_tagaddr_s));
destmac = &bcastmac;
}

Expand Down Expand Up @@ -296,16 +296,15 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
&ieee->i_dev.d_mac.ieee802154);
#endif

/* REVISIT: Destination MAC address could be of different size than
* the source MAC address.
*/

#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
g_packet_meta.dextended = TRUE;
sixlowpan_addrcopy(g_packet_meta.dest.eaddr.u8, destmac);
#else
sixlowpan_addrcopy(g_packet_meta.dest.saddr.u8, destmac);
#endif
if (destmac->extended)
{
g_packet_meta.dextended = TRUE;
sixlowpan_eaddrcopy(g_packet_meta.dest.eaddr.u8, destmac->u.eaddr.u8);
}
else
{
sixlowpan_saddrcopy(g_packet_meta.dest.saddr.u8, destmac->u.saddr.u8);
}

/* Get the destination PAN ID.
*
Expand Down Expand Up @@ -418,9 +417,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
*/

pktlen = buflen + g_uncomp_hdrlen;
PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen));
PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag);
PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen));
PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag);

g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;

Expand Down Expand Up @@ -487,9 +486,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,

/* Setup up the FRAGN header after the frame header. */

PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen));
PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag);
PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen));
PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag);
fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3;

fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN;
Expand Down
45 changes: 31 additions & 14 deletions net/sixlowpan/sixlowpan_hc06.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static FAR struct sixlowpan_addrcontext_s *
}

/****************************************************************************
* Name: compress_addr_64
* Name: compress_tagaddr and compress_laddr
*
* Description:
* Uncompress addresses based on a prefix and a postfix with zeroes in
Expand All @@ -232,12 +232,12 @@ static FAR struct sixlowpan_addrcontext_s *
*
****************************************************************************/

static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr,
FAR const struct sixlowpan_addr_s *macaddr,
static uint8_t compress_tagaddr(FAR const net_ipv6addr_t ipaddr,
FAR const struct sixlowpan_tagaddr_s *macaddr,
uint8_t bitpos)
{
ninfo("ipaddr=%p macaddr=%p bitpos=%u g_hc06ptr=%p\n",
ipaddr, macaddr, bitpos, g_hc06ptr);
ninfo("ipaddr=%p macaddr=%p extended=%u bitpos=%u g_hc06ptr=%p\n",
ipaddr, macaddr, macaddr->extended, bitpos, g_hc06ptr);

if (sixlowpan_ismacbased(ipaddr, macaddr))
{
Expand All @@ -261,6 +261,23 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr,
}
}

static uint8_t compress_laddr(FAR const net_ipv6addr_t ipaddr,
FAR const struct sixlowpan_addr_s *macaddr,
uint8_t bitpos)
{
struct sixlowpan_tagaddr_s tagaddr;

#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
tagaddr.extended = true;
sixlowpan_eaddrcopy(tagaddr.u.eaddr.u8, macaddr->u8);
#else
tagaddr.extended = false;
sixlowpan_saddrcopy(tagaddr.u.saddr.u8, macaddr->u8);
#endif

return compress_tagaddr(ipaddr, &tagaddr, bitpos);
}

/****************************************************************************
* Name: uncompress_addr
*
Expand Down Expand Up @@ -446,7 +463,7 @@ void sixlowpan_hc06_initialize(void)

void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_addr_s *destmac,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
{
FAR uint8_t *iphc = fptr + g_frame_hdrlen;
Expand Down Expand Up @@ -614,9 +631,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,

/* Compression compare with this nodes address (source) */

iphc1 |= compress_addr_64(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT);
iphc1 |= compress_laddr(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT);
}

/* No address context found for this address */
Expand All @@ -625,9 +642,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 &&
ipv6->destipaddr[3] == 0)
{
iphc1 |= compress_addr_64(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT);
iphc1 |= compress_laddr(ipv6->srcipaddr,
&ieee->i_dev.d_mac.ieee802154,
SIXLOWPAN_IPHC_SAM_BIT);
}
else
{
Expand Down Expand Up @@ -701,7 +718,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,

/* Compession compare with link adress (destination) */

iphc1 |= compress_addr_64(ipv6->destipaddr, destmac,
iphc1 |= compress_tagaddr(ipv6->destipaddr, destmac,
SIXLOWPAN_IPHC_DAM_BIT);

/* No address context found for this address */
Expand All @@ -710,7 +727,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 &&
ipv6->destipaddr[3] == 0)
{
iphc1 |= compress_addr_64(ipv6->destipaddr, destmac,
iphc1 |= compress_tagaddr(ipv6->destipaddr, destmac,
SIXLOWPAN_IPHC_DAM_BIT);
}
else
Expand Down
2 changes: 1 addition & 1 deletion net/sixlowpan/sixlowpan_hc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_addr_s *destmac,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
{
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
Expand Down
12 changes: 6 additions & 6 deletions net/sixlowpan/sixlowpan_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
*/

fragptr = fptr + hdrsize;
switch ((GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
switch ((GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
{
/* First fragment of new reassembly */

case SIXLOWPAN_DISPATCH_FRAG1:
{
/* Set up for the reassembly */

fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG);
fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG);
g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;

ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n",
Expand All @@ -318,8 +318,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Set offset, tag, size. Offset is in units of 8 bytes. */

fragoffset = fragptr[SIXLOWPAN_FRAG_OFFSET];
fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG);
fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG);
fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN;

ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n",
Expand Down Expand Up @@ -755,7 +755,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee,
{
FAR struct ipv6_hdr_s *ipv6hdr;
FAR uint8_t *buffer;
struct sixlowpan_addr_s destmac;
struct sixlowpan_tagaddr_s destmac;
size_t hdrlen;
size_t buflen;

Expand Down
35 changes: 25 additions & 10 deletions net/sixlowpan/sixlowpan_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,19 @@

/* General helper macros ****************************************************/

#define GETINT16(ptr,index) \
/* GET 16-bit data: source in network order, result in host order */

#define GETHOST16(ptr,index) \
((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1]))))
#define PUTINT16(ptr,index,value) \

/* GET 16-bit data: source in network order, result in network order */

#define GETNET16(ptr,index) \
((((uint16_t)((ptr)[(index) + 1])) << 8) | ((uint16_t)(((ptr)[index]))))

/* PUT 16-bit data: source in host order, result in newtwork order */

#define PUTHOST16(ptr,index,value) \
do \
{ \
(ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \
Expand Down Expand Up @@ -211,7 +221,7 @@ struct net_driver_s; /* Forward reference */
struct ieee802154_driver_s; /* Forward reference */
struct devif_callback_s; /* Forward reference */
struct ipv6_hdr_s; /* Forward reference */
struct sixlowpan_addr_s; /* Forward reference */
struct sixlowpan_addr_s; /* Forward reference */
struct iob_s; /* Forward reference */

/****************************************************************************
Expand All @@ -232,7 +242,7 @@ struct iob_s; /* Forward reference */
* list - Head of callback list for send interrupt
* ipv6hdr - IPv6 plus TCP or UDP headers.
* buf - Data to send
* buflen - Length of data to send
* len - Length of data to send
* raddr - The MAC address of the destination
* timeout - Send timeout in deciseconds
*
Expand All @@ -250,7 +260,7 @@ struct iob_s; /* Forward reference */
int sixlowpan_send(FAR struct net_driver_s *dev,
FAR struct devif_callback_s **list,
FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf,
size_t buflen, FAR const struct sixlowpan_addr_s *raddr,
size_t len, FAR const struct sixlowpan_tagaddr_s *destmac,
uint16_t timeout);

/****************************************************************************
Expand Down Expand Up @@ -357,7 +367,7 @@ int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee,
int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6hdr,
FAR const void *buf, size_t buflen,
FAR const struct sixlowpan_addr_s *destmac);
FAR const struct sixlowpan_tagaddr_s *destmac);

/****************************************************************************
* Name: sixlowpan_hc06_initialize
Expand Down Expand Up @@ -413,7 +423,7 @@ void sixlowpan_hc06_initialize(void);
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_addr_s *destmac,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
#endif

Expand Down Expand Up @@ -474,7 +484,7 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob,
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_addr_s *destmac,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
#endif

Expand Down Expand Up @@ -529,10 +539,15 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob,

#define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80))

void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr,
FAR struct sixlowpan_saddr_s *saddr);
void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr,
FAR struct sixlowpan_eaddr_s *eaddr);
void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr,
FAR struct sixlowpan_addr_s *addr);
FAR struct sixlowpan_tagaddr_s *addr);

bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
FAR const struct sixlowpan_addr_s *addr);
FAR const struct sixlowpan_tagaddr_s *addr);

/****************************************************************************
* Name: sixlowpan_src_panid
Expand Down
4 changes: 2 additions & 2 deletions net/sixlowpan/sixlowpan_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct sixlowpan_send_s
uint16_t s_timeout; /* Send timeout in deciseconds */
systime_t s_time; /* Last send time for determining timeout */
FAR const struct ipv6_hdr_s *s_ipv6hdr; /* IPv6 header, followed by UDP or TCP header. */
FAR const struct sixlowpan_addr_s *s_destmac; /* Destination MAC address */
FAR const struct sixlowpan_tagaddr_s *s_destmac; /* Destination MAC address */
FAR const void *s_buf; /* Data to send */
size_t s_len; /* Length of data in buf */
};
Expand Down Expand Up @@ -274,7 +274,7 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev,
int sixlowpan_send(FAR struct net_driver_s *dev,
FAR struct devif_callback_s **list,
FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf,
size_t len, FAR const struct sixlowpan_addr_s *destmac,
size_t len, FAR const struct sixlowpan_tagaddr_s *destmac,
uint16_t timeout)
{
struct sixlowpan_send_s sinfo;
Expand Down
4 changes: 2 additions & 2 deletions net/sixlowpan/sixlowpan_tcpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
FAR struct tcp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6tcp_hdr_s ipv6tcp;
struct sixlowpan_addr_s destmac;
struct sixlowpan_tagaddr_s destmac;
uint16_t timeout;
uint16_t iplen;
int ret;
Expand Down Expand Up @@ -409,7 +409,7 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev)
}
else
{
struct sixlowpan_addr_s destmac;
struct sixlowpan_tagaddr_s destmac;
FAR uint8_t *buf;
uint16_t hdrlen;
uint16_t buflen;
Expand Down
2 changes: 1 addition & 1 deletion net/sixlowpan/sixlowpan_udpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
FAR struct udp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6udp_hdr_s ipv6udp;
struct sixlowpan_addr_s destmac;
struct sixlowpan_tagaddr_s destmac;
uint16_t iplen;
uint16_t timeout;
int ret;
Expand Down
Loading

0 comments on commit 14fc1b2

Please sign in to comment.