mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 15:54:57 +08:00
Merge branch 'ieee802154'
This commit is contained in:
@@ -1260,7 +1260,7 @@ o Network (net/, drivers/net)
|
||||
implementation.
|
||||
|
||||
If we want to use IPv6 neighbor discovery, we could dispense
|
||||
with the all MAC based addressing. But if we want to retain
|
||||
with the all MAC based addressing. But if we want to retain
|
||||
the more compact MAC-based addressing, then we don't need
|
||||
IPv6 neighbor discovery.
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ struct at86rf23x_dev_s
|
||||
FAR struct spi_dev_s *spi; /* Saved SPI interface instance */
|
||||
struct work_s irqwork; /* Interrupt continuation work queue support */
|
||||
FAR const struct at86rf23x_lower_s *lower; /* Low-level MCU-specific support */
|
||||
uint16_t panid; /* PAN identifier, FFFF = not set */
|
||||
uint8_t panid[2]; /* PAN identifier, FFFF = not set */
|
||||
uint16_t saddr; /* Short address, FFFF = not set */
|
||||
uint8_t eaddr[8]; /* Extended address, FFFFFFFFFFFFFFFF = not set */
|
||||
uint8_t channel; /* 11 to 26 for the 2.4 GHz band */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -61,6 +61,42 @@
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IEEE 802.15.4 address macros */
|
||||
/* Copy a an IEEE 802.15.4 address */
|
||||
|
||||
#define IEEE802154_ANYADDRCOPY(dest,src,len) \
|
||||
memcpy(dest, src, len)
|
||||
|
||||
#define IEEE802154_PANIDCOPY(dest,src) \
|
||||
IEEE802154_ANYADDRCOPY(dest,src,IEEE802154_PANIDSIZE)
|
||||
|
||||
#define IEEE802154_SADDRCOPY(dest,src) \
|
||||
IEEE802154_ANYADDRCOPY(dest,src,IEEE802154_SADDRSIZE)
|
||||
|
||||
#define IEEE802154_EADDRCOPY(dest,src) \
|
||||
IEEE802154_ANYADDRCOPY(dest,src,IEEE802154_EADDRSIZE)
|
||||
|
||||
/* Compare two IEEE 802.15.4 addresses */
|
||||
|
||||
#define IEEE802154_ANYADDRCMP(addr1,addr2,len) \
|
||||
(memcmp(addr1, addr2, len) == 0)
|
||||
|
||||
#define IEEE802154_PANIDCMP(addr1,addr2) \
|
||||
IEEE802154_ANYADDRCMP(addr1,addr2,IEEE802154_PANIDSIZE)
|
||||
|
||||
#define IEEE802154_SADDRCMP(addr1,addr2) \
|
||||
IEEE802154_ANYADDRCMP(addr1,addr2,IEEE802154_SADDRSIZE)
|
||||
|
||||
#define IEEE802154_EADDRCMP(addr1,addr2) \
|
||||
IEEE802154_ANYADDRCMP(addr1,addr2,IEEE802154_EADDRSIZE)
|
||||
|
||||
/* Some addresses */
|
||||
|
||||
#define IEEE802154_PANID_UNSPEC ((uint8_t[]){0xFF,0xFF})
|
||||
#define IEEE802154_SADDR_UNSPEC ((uint8_t[]){0xFF,0xFF})
|
||||
#define IEEE802154_SADDR_BCAST ((uint8_t[]){0xFE,0xFF})
|
||||
#define IEEE802154_EADDR_UNSPEC ((uint8_t[]){0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF})
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* None at the moment */
|
||||
|
||||
@@ -102,13 +138,6 @@
|
||||
|
||||
/* IEEE 802.15.4 MAC Interface **********************************************/
|
||||
|
||||
/* Some addresses */
|
||||
|
||||
#define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF
|
||||
#define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF
|
||||
#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE
|
||||
#define IEEE802154_EADDR_UNSPEC (uint8_t[]){0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}
|
||||
|
||||
/* Frame control field masks, 2 bytes
|
||||
* Seee IEEE 802.15.4/2011 5.2.1.1 page 57
|
||||
*/
|
||||
@@ -398,7 +427,9 @@ enum ieee802154_devmode_e
|
||||
IEEE802154_DEVMODE_PANCOORD
|
||||
};
|
||||
|
||||
#define IEEE802154_EADDR_LEN 8
|
||||
#define IEEE802154_PANIDSIZE 2
|
||||
#define IEEE802154_SADDRSIZE 2
|
||||
#define IEEE802154_EADDRSIZE 8
|
||||
|
||||
/* IEEE 802.15.4 Device address
|
||||
* The addresses in ieee802154 have several formats:
|
||||
@@ -424,10 +455,9 @@ struct ieee802154_addr_s
|
||||
|
||||
enum ieee802154_addrmode_e mode;
|
||||
|
||||
uint16_t panid; /* PAN identifier, can be
|
||||
* IEEE802154_PAN_UNSPEC */
|
||||
uint16_t saddr; /* short address */
|
||||
uint8_t eaddr[IEEE802154_EADDR_LEN]; /* extended address */
|
||||
uint8_t panid[IEEE802154_PANIDSIZE]; /* PAN identifier */
|
||||
uint8_t saddr[IEEE802154_SADDRSIZE]; /* short address */
|
||||
uint8_t eaddr[IEEE802154_EADDRSIZE]; /* extended address */
|
||||
};
|
||||
|
||||
#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */
|
||||
@@ -540,12 +570,12 @@ struct ieee802154_cca_s
|
||||
|
||||
union ieee802154_macattr_u
|
||||
{
|
||||
uint8_t eaddr[IEEE802154_EADDR_LEN];
|
||||
uint16_t saddr;
|
||||
uint16_t panid;
|
||||
uint8_t eaddr[IEEE802154_EADDRSIZE];
|
||||
uint8_t saddr[IEEE802154_SADDRSIZE];
|
||||
uint8_t panid[IEEE802154_PANIDSIZE];
|
||||
|
||||
uint8_t coord_eaddr[IEEE802154_EADDR_LEN];
|
||||
uint16_t coord_saddr;
|
||||
uint8_t coord_eaddr[IEEE802154_EADDRSIZE];
|
||||
uint8_t coord_saddr[IEEE802154_SADDRSIZE];
|
||||
|
||||
enum ieee802154_devmode_e devmode;
|
||||
|
||||
@@ -845,7 +875,7 @@ struct ieee802154_assoc_ind_s
|
||||
{
|
||||
/* Address of device requesting association. Always in extended mode */
|
||||
|
||||
uint8_t devaddr[IEEE802154_EADDR_LEN];
|
||||
uint8_t devaddr[IEEE802154_EADDRSIZE];
|
||||
|
||||
/* Capabilities of associating device */
|
||||
|
||||
@@ -870,11 +900,11 @@ struct ieee802154_assoc_resp_s
|
||||
{
|
||||
/* Address of device requesting association. Always in extended mode */
|
||||
|
||||
uint8_t devaddr[8];
|
||||
uint8_t devaddr[IEEE802154_EADDRSIZE];
|
||||
|
||||
/* Address assigned to the device. 0xFFFF if failure */
|
||||
|
||||
uint16_t assocsaddr;
|
||||
uint8_t assocsaddr[IEEE802154_SADDRSIZE];
|
||||
|
||||
/* Status of association attempt */
|
||||
|
||||
@@ -903,7 +933,7 @@ struct ieee802154_assoc_conf_s
|
||||
* unsuccessful.
|
||||
*/
|
||||
|
||||
uint16_t saddr;
|
||||
uint8_t saddr[IEEE802154_SADDRSIZE];
|
||||
|
||||
/* Status of association attempt */
|
||||
|
||||
@@ -1287,7 +1317,7 @@ struct ieee802154_set_req_s
|
||||
|
||||
struct ieee802154_start_req_s
|
||||
{
|
||||
uint16_t panid;
|
||||
uint8_t panid[IEEE802154_PANIDSIZE];
|
||||
uint8_t chnum;
|
||||
uint8_t chpage;
|
||||
|
||||
|
||||
@@ -3,16 +3,41 @@
|
||||
|
||||
The current 6LoWPAN implementation uses only link local, MAC-based
|
||||
addressing addressing (as discussed in more detail below). Thus if you know
|
||||
the node addressing, then you know the IPv6 address (and vice-versa)
|
||||
the node addressing, then you know the IPv6 address (and vice-versa).
|
||||
|
||||
As a configuration option, the 6LoWPAN implementation will use either the
|
||||
node's 2-byte short address or 8-byte extended address as the MAC address
|
||||
that the IPv6 address is based on. This is determined by the configuration
|
||||
setting CONFIG_NET_6LOWPAN_EXTENDEDADDR. By default, the 2-byte short
|
||||
address is used for the IEEE802.15.4 MAC device's link layer address. If
|
||||
this option is selected, then an 8-byte extended address will be used,
|
||||
instead.
|
||||
|
||||
All nodes operating on a network have unique, 8-byte extended address,
|
||||
that was assigned before the network is configured. 6LoWPAN will use
|
||||
either the extended address for direct communication within the PAN or
|
||||
the short 2-byte address. The short 2-byte address, however, is allocated
|
||||
by the PAN coordinator when the device associated. If short addresses are
|
||||
used, the network cannot be brought up until is is associated.
|
||||
|
||||
Node addressing is modified through IOCTL calls from application logic.
|
||||
The network must be in the DOWN state when ever the node addressing is
|
||||
modified. The modified node addresses will have no effect on the reported
|
||||
IPv6 address until the network is brought to the UP state. The new IPv6
|
||||
MAC-based addresses are only instantiated when the network transitions
|
||||
from the DOWN to UP state.
|
||||
|
||||
IPv6 Neighbor Discovery
|
||||
-----------------------
|
||||
|
||||
IPv6 Neighbor Discovery is not supported. The current ICMPv6 and neighbor-
|
||||
related logic only works with Ethernet MAC. For 6LoWPAN, a
|
||||
new more conservative IPv6 neigbor discovery is provided by RFC 6775 which
|
||||
is not currently suppored. With IPv6 neighbor discovery, any IPv6 address
|
||||
may be associated with any short or extended address. In fact, that is the
|
||||
whole purpose of the neighbor discover logic: It plays the same role as ARP
|
||||
in IPv4; it ultimately just manages a neighbor table that, like the arp
|
||||
table, provides the mapping between IP addresses and node addresses.
|
||||
related logic only works with Ethernet MAC. For 6LoWPAN, a new more
|
||||
conservative IPv6 neigbor discovery is provided by RFC 6775 which is not
|
||||
currently supported. With IPv6 neighbor discovery, any IPv6 address may be
|
||||
associated with any short or extended address. In fact, that is the whole
|
||||
purpose of the neighbor discover logic: It plays the same role as ARP in
|
||||
IPv4; it ultimately just manages a neighbor table that, like the arp table,
|
||||
provides the mapping between IP addresses and node addresses.
|
||||
|
||||
The NuttX, Contiki-based 6LoWPAN implementation circumvents the need for
|
||||
the neighbor discovery logic by using only MAC-based addressing, i.e., the
|
||||
|
||||
@@ -313,8 +313,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
* PAN IDs are the same.
|
||||
*/
|
||||
|
||||
pktmeta.dpanid = 0xffff;
|
||||
(void)sixlowpan_src_panid(ieee, &pktmeta.dpanid);
|
||||
(void)sixlowpan_src_panid(ieee, pktmeta.dpanid);
|
||||
|
||||
/* Based on the collected attributes and addresses, construct the MAC meta
|
||||
* data structure that we need to interface with the IEEE802.15.4 MAC (we
|
||||
|
||||
@@ -198,7 +198,8 @@ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee,
|
||||
/* Broadcast requires short address mode. */
|
||||
|
||||
meta->destaddr.mode = IEEE802154_ADDRMODE_SHORT;
|
||||
meta->destaddr.saddr = 0;
|
||||
meta->destaddr.saddr[0] = 0;
|
||||
meta->destaddr.saddr[1] = 0;
|
||||
}
|
||||
else if (pktmeta->dextended != 0)
|
||||
{
|
||||
@@ -215,7 +216,7 @@ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee,
|
||||
sixlowpan_saddrcopy(&meta->destaddr.saddr, pktmeta->dest.saddr.u8);
|
||||
}
|
||||
|
||||
meta->destaddr.panid = pktmeta->dpanid;
|
||||
IEEE802154_SADDRCOPY(meta->destaddr.panid, pktmeta->dpanid);
|
||||
|
||||
/* Handle associated with MSDU. Will increment once per packet, not
|
||||
* necesarily per frame: The same MSDU handle will be used for each
|
||||
|
||||
@@ -180,12 +180,12 @@ struct ipv6icmp_hdr_s
|
||||
|
||||
struct packet_metadata_s
|
||||
{
|
||||
uint8_t sextended : 1; /* Extended source address */
|
||||
uint8_t dextended : 1; /* Extended destination address */
|
||||
uint8_t xmits; /* Max MAC transmisstion */
|
||||
uint16_t dpanid; /* Destination PAN ID */
|
||||
union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */
|
||||
union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */
|
||||
uint8_t sextended : 1; /* Extended source address */
|
||||
uint8_t dextended : 1; /* Extended destination address */
|
||||
uint8_t xmits; /* Max MAC transmisstion */
|
||||
uint8_t dpanid[IEEE802154_PANIDSIZE]; /* Destination PAN ID */
|
||||
union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */
|
||||
union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -592,6 +592,6 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR uint16_t *panid);
|
||||
FAR uint8_t *panid);
|
||||
#endif /* CONFIG_NET_6LOWPAN */
|
||||
#endif /* _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H */
|
||||
|
||||
@@ -188,7 +188,7 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR uint16_t *panid)
|
||||
FAR uint8_t *panid)
|
||||
{
|
||||
FAR struct net_driver_s *dev = &ieee->i_dev;
|
||||
struct ieee802154_netmac_s arg;
|
||||
@@ -204,7 +204,7 @@ int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee,
|
||||
return ret;
|
||||
}
|
||||
|
||||
*panid = arg.u.getreq.attrval.mac.panid;
|
||||
IEEE802154_PANIDCOPY(panid, arg.u.getreq.attrval.mac.panid);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -79,7 +79,7 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
(FAR struct ieee802154_privmac_s *)mac;
|
||||
FAR struct ieee802154_txdesc_s *txdesc;
|
||||
uint16_t *frame_ctrl;
|
||||
uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */
|
||||
uint8_t mhr_len = 3;
|
||||
int ret;
|
||||
|
||||
/* Check the required frame size */
|
||||
@@ -123,20 +123,18 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
|
||||
if (meta->destaddr.mode != IEEE802154_ADDRMODE_NONE)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &meta->destaddr.panid, 2);
|
||||
IEEE802154_PANIDCOPY(&frame->io_data[mhr_len], meta->destaddr.panid);
|
||||
mhr_len += 2;
|
||||
|
||||
if (meta->destaddr.mode == IEEE802154_ADDRMODE_SHORT)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &meta->destaddr.saddr, 2);
|
||||
IEEE802154_SADDRCOPY(&frame->io_data[mhr_len], meta->destaddr.saddr);
|
||||
mhr_len += 2;
|
||||
}
|
||||
else if (meta->destaddr.mode == IEEE802154_ADDRMODE_EXTENDED)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &meta->destaddr.eaddr,
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
mhr_len += IEEE802154_EADDR_LEN;
|
||||
IEEE802154_EADDRCOPY(&frame->io_data[mhr_len], meta->destaddr.eaddr);
|
||||
mhr_len += IEEE802154_EADDRSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +163,7 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
* from the transmitted frame. [1] pg. 41.
|
||||
*/
|
||||
|
||||
if (meta->destaddr.panid == priv->addr.panid)
|
||||
if (IEEE802154_PANIDCMP(meta->destaddr.panid, priv->addr.panid))
|
||||
{
|
||||
*frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP;
|
||||
}
|
||||
@@ -180,21 +178,19 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
if ((meta->destaddr.mode == IEEE802154_ADDRMODE_NONE) ||
|
||||
(!(*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)))
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &priv->addr.panid, 2);
|
||||
IEEE802154_PANIDCOPY(&frame->io_data[mhr_len], priv->addr.panid);
|
||||
mhr_len += 2;
|
||||
}
|
||||
|
||||
if (meta->srcaddr_mode == IEEE802154_ADDRMODE_SHORT)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &priv->addr.saddr, 2);
|
||||
IEEE802154_SADDRCOPY(&frame->io_data[mhr_len], priv->addr.saddr);
|
||||
mhr_len += 2;
|
||||
}
|
||||
else if (meta->srcaddr_mode == IEEE802154_ADDRMODE_EXTENDED)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr,
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
mhr_len += IEEE802154_EADDR_LEN;
|
||||
IEEE802154_EADDRCOPY(&frame->io_data[mhr_len], priv->addr.eaddr);
|
||||
mhr_len += IEEE802154_EADDRSIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -110,7 +110,7 @@ int mac802154_get_mhrlen(MACHANDLE mac,
|
||||
* from the transmitted frame. [1] pg. 41.
|
||||
*/
|
||||
|
||||
if (meta->destaddr.panid == priv->addr.panid)
|
||||
if (IEEE802154_PANIDCMP(meta->destaddr.panid, priv->addr.panid))
|
||||
{
|
||||
ret += 2; /* 2 bytes for destination PAN ID */
|
||||
return ret;
|
||||
|
||||
@@ -84,13 +84,13 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_attr_e attr,
|
||||
switch (attr)
|
||||
{
|
||||
case IEEE802154_ATTR_MAC_PANID:
|
||||
attrval->mac.panid = priv->addr.panid;
|
||||
IEEE802154_PANIDCOPY(attrval->mac.panid, priv->addr.panid);
|
||||
break;
|
||||
case IEEE802154_ATTR_MAC_SHORT_ADDRESS:
|
||||
attrval->mac.saddr = priv->addr.saddr;
|
||||
IEEE802154_SADDRCOPY(attrval->mac.saddr, priv->addr.saddr);
|
||||
break;
|
||||
case IEEE802154_ATTR_MAC_EXTENDED_ADDR:
|
||||
memcpy(&attrval->mac.eaddr[0], &priv->addr.eaddr[0], IEEE802154_EADDR_LEN);
|
||||
IEEE802154_EADDRCOPY(attrval->mac.eaddr, priv->addr.eaddr);
|
||||
break;
|
||||
case IEEE802154_ATTR_MAC_DEVMODE:
|
||||
attrval->mac.devmode = priv->devmode;
|
||||
@@ -133,7 +133,7 @@ int mac802154_req_set(MACHANDLE mac, enum ieee802154_attr_e attr,
|
||||
{
|
||||
case IEEE802154_ATTR_MAC_PANID:
|
||||
{
|
||||
priv->addr.panid = attrval->mac.panid;
|
||||
IEEE802154_PANIDCOPY(priv->addr.panid, attrval->mac.panid);
|
||||
|
||||
/* Tell the radio about the attribute */
|
||||
|
||||
@@ -144,7 +144,7 @@ int mac802154_req_set(MACHANDLE mac, enum ieee802154_attr_e attr,
|
||||
break;
|
||||
case IEEE802154_ATTR_MAC_SHORT_ADDRESS:
|
||||
{
|
||||
priv->addr.saddr = attrval->mac.saddr;
|
||||
IEEE802154_SADDRCOPY(priv->addr.saddr, attrval->mac.saddr);
|
||||
|
||||
/* Tell the radio about the attribute */
|
||||
|
||||
@@ -157,8 +157,7 @@ int mac802154_req_set(MACHANDLE mac, enum ieee802154_attr_e attr,
|
||||
{
|
||||
/* Set the MAC copy of the address in the table */
|
||||
|
||||
memcpy(&priv->addr.eaddr[0], &attrval->mac.eaddr[0],
|
||||
IEEE802154_EADDR_LEN);
|
||||
IEEE802154_EADDRCOPY(priv->addr.eaddr, attrval->mac.eaddr);
|
||||
|
||||
/* Tell the radio about the attribute */
|
||||
|
||||
|
||||
@@ -66,6 +66,77 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define mac802154_putpanid(iob, panid) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_PANIDCOPY(&iob->io_data[iob->io_len], panid); \
|
||||
iob->io_len += IEEE802154_PANIDSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define mac802154_putsaddr(iob, saddr) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_SADDRCOPY(&iob->io_data[iob->io_len], saddr); \
|
||||
iob->io_len += IEEE802154_SADDRSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define mac802154_puteaddr(iob, eaddr) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_EADDRCOPY(&iob->io_data[iob->io_len], eaddr); \
|
||||
iob->io_len += IEEE802154_EADDRSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define mac802154_takepanid(iob, panid) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_PANIDCOPY(panid, &iob->io_data[iob->io_offset]); \
|
||||
iob->io_offset += IEEE802154_PANIDSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define mac802154_takesaddr(iob, saddr) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_SADDRCOPY(saddr, &iob->io_data[iob->io_offset]); \
|
||||
iob->io_offset += IEEE802154_SADDRSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define mac802154_takeeaddr(iob, eaddr) \
|
||||
do \
|
||||
{ \
|
||||
IEEE802154_EADDRCOPY(eaddr, &iob->io_data[iob->io_offset]); \
|
||||
iob->io_offset += IEEE802154_EADDRSIZE; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
/* General helper macros ****************************************************/
|
||||
|
||||
/* 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]))))
|
||||
|
||||
/* 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; \
|
||||
(ptr)[index + 1] = (uint16_t)(value) & 0xff; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* If processing is not done at the interrupt level, then work queue support
|
||||
* is required.
|
||||
|
||||
@@ -98,7 +98,7 @@ struct lo_driver_s
|
||||
{
|
||||
bool lo_bifup; /* true:ifup false:ifdown */
|
||||
bool lo_pending; /* True: TX poll pending */
|
||||
uint16_t lo_panid; /* Fake PAN ID for testing */
|
||||
uint8_t lo_panid[2]; /* Fake PAN ID for testing */
|
||||
WDOG_ID lo_polldog; /* TX poll timer */
|
||||
struct work_s lo_work; /* For deferring poll work to the work queue */
|
||||
FAR struct iob_s *lo_head; /* Head of IOBs queued for loopback */
|
||||
@@ -116,13 +116,20 @@ struct lo_driver_s
|
||||
static struct lo_driver_s g_loopback;
|
||||
static uint8_t g_iobuffer[CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE];
|
||||
|
||||
static uint8_t g_eaddr[8] =
|
||||
static uint8_t g_eaddr[IEEE802154_EADDRSIZE] =
|
||||
{
|
||||
0x00, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xef
|
||||
};
|
||||
|
||||
static uint16_t g_saddr = 0xabcd;
|
||||
static uint16_t g_panid = 0xcafe;
|
||||
static uint8_t g_saddr[IEEE802154_SADDRSIZE] =
|
||||
{
|
||||
0xab, 0xcd
|
||||
};
|
||||
|
||||
static uint8_t g_panid[IEEE802154_PANIDSIZE] =
|
||||
{
|
||||
0xca, 0xfe
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
@@ -203,7 +210,7 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
|
||||
dev->d_ipv6addr[4] = 0;
|
||||
dev->d_ipv6addr[5] = HTONS(0x00ff);
|
||||
dev->d_ipv6addr[6] = HTONS(0xfe00);
|
||||
dev->d_ipv6addr[7] = htons(g_saddr);
|
||||
dev->d_ipv6addr[7] = (uint16_t)g_saddr[0] << 8 | (uint16_t)g_saddr[1];
|
||||
dev->d_ipv6addr[7] ^= 0x200;
|
||||
}
|
||||
#endif
|
||||
@@ -441,16 +448,16 @@ static int lo_ifup(FAR struct net_driver_s *dev)
|
||||
dev->d_ipv6addr[6], dev->d_ipv6addr[7]);
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n",
|
||||
ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n",
|
||||
dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
|
||||
dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3],
|
||||
dev->d_mac.ieee802154.u8[4], dev->d_mac.ieee802154.u8[5],
|
||||
dev->d_mac.ieee802154.u8[6], dev->d_mac.ieee802154.u8[7],
|
||||
priv->lo_panid);
|
||||
priv->lo_panid[0], priv->lo_panid[1]);
|
||||
#else
|
||||
ninfo(" Node: %02x:%02x PANID=%04x\n",
|
||||
ninfo(" Node: %02x:%02x PANID=%02x:%02x\n",
|
||||
dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1],
|
||||
priv->lo_panid);
|
||||
priv->lo_panid[0], priv->lo_panid[1]);
|
||||
#endif
|
||||
|
||||
/* Set and activate a timer process */
|
||||
@@ -691,18 +698,18 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd,
|
||||
switch (setreq->attr)
|
||||
{
|
||||
case IEEE802154_ATTR_MAC_PANID:
|
||||
g_panid = setreq->attrval.mac.panid;
|
||||
IEEE802154_PANIDCOPY(g_panid, setreq->attrval.mac.panid);
|
||||
break;
|
||||
|
||||
case IEEE802154_ATTR_MAC_EXTENDED_ADDR:
|
||||
memcpy(setreq->attrval.mac.eaddr, g_eaddr, 8);
|
||||
IEEE802154_EADDRCOPY(g_eaddr, setreq->attrval.mac.eaddr);
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
lo_addr2ip(dev);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case IEEE802154_ATTR_MAC_SHORT_ADDRESS:
|
||||
g_saddr = setreq->attrval.mac.saddr;
|
||||
IEEE802154_SADDRCOPY(g_saddr, setreq->attrval.mac.saddr);
|
||||
#ifndef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
lo_addr2ip(dev);
|
||||
#endif
|
||||
@@ -721,15 +728,15 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd,
|
||||
switch (getreq->attr)
|
||||
{
|
||||
case IEEE802154_ATTR_MAC_PANID:
|
||||
getreq->attrval.mac.panid = g_panid;
|
||||
IEEE802154_PANIDCOPY(getreq->attrval.mac.panid, g_panid);
|
||||
break;
|
||||
|
||||
case IEEE802154_ATTR_MAC_EXTENDED_ADDR:
|
||||
memcpy(g_eaddr, getreq->attrval.mac.eaddr, 8);
|
||||
IEEE802154_EADDRCOPY(getreq->attrval.mac.eaddr, g_eaddr);
|
||||
break;
|
||||
|
||||
case IEEE802154_ATTR_MAC_SHORT_ADDRESS:
|
||||
getreq->attrval.mac.saddr = g_saddr;
|
||||
IEEE802154_SADDRCOPY(getreq->attrval.mac.saddr, g_saddr);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -261,7 +261,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
|
||||
/* Set the IP address based on the eaddr */
|
||||
|
||||
eaddr = arg.u.getreq.attrval.mac.eaddr;
|
||||
memcpy(dev->d_mac.ieee802154.u8, eaddr, 8);
|
||||
IEEE802154_EADDRCOPY(dev->d_mac.ieee802154.u8, eaddr);
|
||||
|
||||
dev->d_ipv6addr[0] = HTONS(0xfe80);
|
||||
dev->d_ipv6addr[1] = 0;
|
||||
@@ -276,6 +276,8 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
|
||||
}
|
||||
|
||||
#else
|
||||
uint8_t *saddr;
|
||||
|
||||
/* Get the saddr from the MAC */
|
||||
|
||||
memcpy(arg.ifr_name, dev->d_ifname, IFNAMSIZ);
|
||||
@@ -289,15 +291,8 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
|
||||
}
|
||||
else
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16_t u16;
|
||||
uint8_t u8[2];
|
||||
} u;
|
||||
|
||||
u.u16 = arg.u.getreq.attrval.mac.saddr;
|
||||
dev->d_mac.ieee802154.u8[0] = u.u8[0];
|
||||
dev->d_mac.ieee802154.u8[1] = u.u8[1];
|
||||
saddr = arg.u.getreq.attrval.mac.saddr;
|
||||
IEEE802154_SADDRCOPY(dev->d_mac.ieee802154.u8, saddr);
|
||||
|
||||
/* Set the IP address based on the saddr */
|
||||
|
||||
@@ -308,7 +303,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
|
||||
dev->d_ipv6addr[4] = 0;
|
||||
dev->d_ipv6addr[5] = HTONS(0x00ff);
|
||||
dev->d_ipv6addr[6] = HTONS(0xfe00);
|
||||
dev->d_ipv6addr[7] = u.u16;
|
||||
dev->d_ipv6addr[7] = (uint16_t)saddr[0] << 8 | (uint16_t)saddr[1];
|
||||
dev->d_ipv6addr[7] ^= 0x200;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req)
|
||||
* shall be used. Extended addressing shall be used otherwise.
|
||||
*/
|
||||
|
||||
if (priv->addr.saddr == IEEE802154_SADDR_BCAST)
|
||||
if (IEEE802154_SADDRCMP(priv->addr.saddr, &IEEE802154_SADDR_BCAST))
|
||||
{
|
||||
mac802154_create_datareq(priv, &req->coordaddr, IEEE802154_ADDRMODE_EXTENDED,
|
||||
txdesc);
|
||||
|
||||
@@ -114,16 +114,16 @@ int mac802154_req_reset(MACHANDLE mac, bool rst_pibattr)
|
||||
/* Reset the Coordinator address */
|
||||
|
||||
priv->coordaddr.mode = IEEE802154_ADDRMODE_NONE;
|
||||
priv->coordaddr.saddr = IEEE802154_SADDR_UNSPEC;
|
||||
memcpy(&priv->coordaddr.eaddr[0], IEEE802154_EADDR_UNSPEC,
|
||||
IEEE802154_EADDR_LEN);
|
||||
IEEE802154_PANIDCOPY(priv->coordaddr.panid, &IEEE802154_PANID_UNSPEC);
|
||||
IEEE802154_SADDRCOPY(priv->coordaddr.saddr, &IEEE802154_SADDR_UNSPEC);
|
||||
IEEE802154_EADDRCOPY(priv->coordaddr.eaddr, &IEEE802154_EADDR_UNSPEC);
|
||||
|
||||
/* Reset the device's address */
|
||||
|
||||
priv->addr.mode = IEEE802154_ADDRMODE_NONE;
|
||||
priv->addr.panid = IEEE802154_PAN_UNSPEC;
|
||||
priv->addr.saddr = IEEE802154_SADDR_UNSPEC;
|
||||
memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, IEEE802154_EADDR_LEN);
|
||||
IEEE802154_PANIDCOPY(priv->addr.panid, &IEEE802154_PANID_UNSPEC);
|
||||
IEEE802154_SADDRCOPY(priv->addr.saddr, &IEEE802154_SADDR_UNSPEC);
|
||||
IEEE802154_EADDRCOPY(priv->addr.eaddr, &IEEE802154_EADDR_UNSPEC);
|
||||
|
||||
priv->radio->reset_attrs(priv->radio);
|
||||
|
||||
|
||||
@@ -97,9 +97,9 @@ int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req)
|
||||
|
||||
/* Set the PANID attribute */
|
||||
|
||||
priv->addr.panid = req->panid;
|
||||
IEEE802154_PANIDCOPY(priv->addr.panid, req->panid);
|
||||
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_MAC_PANID,
|
||||
(FAR const union ieee802154_attr_u *)&req->panid);
|
||||
(FAR const union ieee802154_attr_u *)req->panid);
|
||||
|
||||
/* Set the radio attributes */
|
||||
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_PHY_CURRENT_CHANNEL,
|
||||
|
||||
Reference in New Issue
Block a user