6loWPAN: Local MAC address is fixed by the configuration. The remote address be with short or extended.
This commit is contained in:
parent
9d9fbcb6dc
commit
14fc1b2d39
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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.
|
||||
*
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
@ -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
|
||||
@ -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))
|
||||
{
|
||||
@ -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
|
||||
*
|
||||
@ -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;
|
||||
@ -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 */
|
||||
@ -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
|
||||
{
|
||||
@ -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 */
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
@ -291,7 +291,7 @@ 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 */
|
||||
|
||||
@ -299,8 +299,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
|
||||
{
|
||||
/* 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",
|
||||
@ -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",
|
||||
@ -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;
|
||||
|
||||
|
@ -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; \
|
||||
@ -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 */
|
||||
|
||||
/****************************************************************************
|
||||
@ -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
|
||||
*
|
||||
@ -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);
|
||||
|
||||
/****************************************************************************
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
@ -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 */
|
||||
};
|
||||
@ -274,7 +274,7 @@ end_wait:
|
||||
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;
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -80,17 +80,39 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr,
|
||||
FAR struct sixlowpan_addr_s *addr)
|
||||
void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr,
|
||||
FAR struct sixlowpan_saddr_s *saddr)
|
||||
{
|
||||
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
memcpy(addr, &ipaddr[4], NET_6LOWPAN_ADDRSIZE);
|
||||
#else
|
||||
memcpy(addr, &ipaddr[7], NET_6LOWPAN_ADDRSIZE);
|
||||
#endif
|
||||
addr->u8[0] ^= 0x02;
|
||||
memcpy(saddr, &ipaddr[7], NET_6LOWPAN_SADDRSIZE);
|
||||
saddr->u8[0] ^= 0x02;
|
||||
}
|
||||
|
||||
void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr,
|
||||
FAR struct sixlowpan_eaddr_s *eaddr)
|
||||
{
|
||||
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
|
||||
|
||||
memcpy(eaddr, &ipaddr[4], NET_6LOWPAN_EADDRSIZE);
|
||||
eaddr->u8[0] ^= 0x02;
|
||||
}
|
||||
|
||||
void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr,
|
||||
FAR struct sixlowpan_tagaddr_s *addr)
|
||||
{
|
||||
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
|
||||
|
||||
if (SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(ipaddr))
|
||||
{
|
||||
memset(addr, 0, sizeof(struct sixlowpan_tagaddr_s));
|
||||
sixlowpan_saddrfromip(ipaddr, &addr->u.saddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
sixlowpan_eaddrfromip(ipaddr, &addr->u.eaddr);
|
||||
addr->extended = true;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -106,20 +128,37 @@ void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
|
||||
FAR const struct sixlowpan_addr_s *addr)
|
||||
bool sixlowpan_issaddrbased(const net_ipv6addr_t ipaddr,
|
||||
FAR const struct sixlowpan_saddr_s *saddr)
|
||||
{
|
||||
FAR const uint8_t *byteptr = addr->u8;
|
||||
FAR const uint8_t *byteptr = saddr->u8;
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
return (ipaddr[4] == htons((GETINT16(byteptr, 0) ^ 0x0200)) &&
|
||||
ipaddr[5] == GETINT16(byteptr, 2) &&
|
||||
ipaddr[6] == GETINT16(byteptr, 4) &&
|
||||
ipaddr[7] == GETINT16(byteptr, 6));
|
||||
#else
|
||||
return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) &&
|
||||
ipaddr[7] == htons((GETINT16(byteptr, 0) ^ 0x0200)));
|
||||
#endif
|
||||
ipaddr[7] == (GETNET16(byteptr, 0) ^ HTONS(0x0200)));
|
||||
}
|
||||
|
||||
bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr,
|
||||
FAR const struct sixlowpan_eaddr_s *eaddr)
|
||||
{
|
||||
FAR const uint8_t *byteptr = eaddr->u8;
|
||||
|
||||
return (ipaddr[4] == (GETNET16(byteptr, 0) ^ HTONS(0x0200)) &&
|
||||
ipaddr[5] == GETNET16(byteptr, 2) &&
|
||||
ipaddr[6] == GETNET16(byteptr, 4) &&
|
||||
ipaddr[7] == GETNET16(byteptr, 6));
|
||||
}
|
||||
|
||||
bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
|
||||
FAR const struct sixlowpan_tagaddr_s *addr)
|
||||
{
|
||||
if (addr->extended)
|
||||
{
|
||||
return sixlowpan_iseaddrbased(ipaddr, &addr->u.eaddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sixlowpan_issaddrbased(ipaddr, &addr->u.saddr);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
x
Reference in New Issue
Block a user