Merge branch 'ieee802154'

This commit is contained in:
Gregory Nutt 2017-06-19 08:04:12 -06:00
commit 90adeb49b7
20 changed files with 310 additions and 365 deletions

2
TODO
View File

@ -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.

View File

@ -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 */

View File

@ -208,32 +208,18 @@ static inline void mrf24j40_norm_trigger(FAR struct mrf24j40_radio_s *dev);
static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev,
uint8_t chan);
static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *chan);
static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev,
uint16_t panid);
static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev,
FAR uint16_t *panid);
FAR const uint8_t *panid);
static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev,
uint16_t saddr);
static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev,
FAR uint16_t *saddr);
FAR const uint8_t *saddr);
static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev,
FAR const uint8_t *eaddr);
static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *eaddr);
static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev,
uint8_t mode);
static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *mode);
static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *dev,
int32_t txpwr);
static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *dev,
FAR int32_t *txpwr);
static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *dev,
FAR struct ieee802154_cca_s *cca);
static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *dev,
FAR struct ieee802154_cca_s *cca);
static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *energy);
static void mrf24j40_mactimer(FAR struct mrf24j40_radio_s *dev, int numsymbols);
@ -964,22 +950,6 @@ static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev, uint8_t chan)
return OK;
}
/****************************************************************************
* Name: mrf24j40_getchannel
*
* Description:
* Get the channel the device is operating on.
*
****************************************************************************/
static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *chan)
{
*chan = dev->channel;
return OK;
}
/****************************************************************************
* Name: mrf24j40_setpanid
*
@ -989,29 +959,13 @@ static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev,
****************************************************************************/
static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev,
uint16_t panid)
FAR const uint8_t *panid)
{
mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8));
mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF));
mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, panid[0]);
mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, panid[1]);
dev->addr.panid = panid;
wlinfo("%04X\n", (unsigned)panid);
return OK;
}
/****************************************************************************
* Name: mrf24j40_getpanid
*
* Description:
* Define the current PAN ID the device is operating on.
*
****************************************************************************/
static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev,
FAR uint16_t *panid)
{
*panid = dev->addr.panid;
IEEE802154_PANIDCOPY(dev->addr.panid, panid);
wlinfo("%02X:%02X\n", panid[1], panid[0]);
return OK;
}
@ -1027,29 +981,14 @@ static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev,
****************************************************************************/
static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev,
uint16_t saddr)
FAR const uint8_t *saddr)
{
mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8));
mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF));
mrf24j40_setreg(dev->spi, MRF24J40_SADRL, saddr[0]);
mrf24j40_setreg(dev->spi, MRF24J40_SADRH, saddr[1]);
dev->addr.saddr = saddr;
wlinfo("%04X\n", (unsigned)saddr);
return OK;
}
/****************************************************************************
* Name: mrf24j40_getsaddr
*
* Description:
* Define the current short address the device is using.
*
****************************************************************************/
static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev,
FAR uint16_t *saddr)
{
*saddr = dev->addr.saddr;
IEEE802154_SADDRCOPY(dev->addr.saddr, saddr);
wlinfo("%02X:%02X\n", saddr[1], saddr[0]);
return OK;
}
@ -1076,22 +1015,6 @@ static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev,
return OK;
}
/****************************************************************************
* Name: mrf24j40_geteaddr
*
* Description:
* Define the current extended address the device is using.
*
****************************************************************************/
static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *eaddr)
{
memcpy(eaddr, dev->addr.eaddr, 8);
return OK;
}
/****************************************************************************
* Name: mrf24j40_setdevmode
*
@ -1142,21 +1065,6 @@ static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev,
return ret;
}
/****************************************************************************
* Name: mrf24j40_setdevmode
*
* Description:
* Return the current device mode
*
****************************************************************************/
static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *mode)
{
*mode = dev->devmode;
return OK;
}
/****************************************************************************
* Name: mrf24j40_settxpower
*
@ -1241,21 +1149,6 @@ static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *dev,
return OK;
}
/****************************************************************************
* Name: mrf24j40_gettxpower
*
* Description:
* Return the actual transmit power, in mBm.
*
****************************************************************************/
static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *dev,
FAR int32_t *txpwr)
{
*txpwr = dev->txpower;
return OK;
}
/****************************************************************************
* Name: mrf24j40_setcca
*
@ -1300,21 +1193,6 @@ static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *dev,
return OK;
}
/****************************************************************************
* Name: mrf24j40_getcca
*
* Description:
* Return the Clear Channel Assessement method.
*
****************************************************************************/
static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *dev,
FAR struct ieee802154_cca_s *cca)
{
memcpy(cca, &dev->cca, sizeof(struct ieee802154_cca_s));
return OK;
}
/****************************************************************************
* Name: mrf24j40_regdump
*

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -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;
}

View File

@ -292,19 +292,15 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv,
if (coordaddr->mode != IEEE802154_ADDRMODE_NONE)
{
memcpy(&iob->io_data[iob->io_len], &coordaddr->panid, 2);
iob->io_len += 2;
mac802154_putpanid(iob, coordaddr->panid);
if (coordaddr->mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&iob->io_data[iob->io_len], &coordaddr->saddr, 2);
iob->io_len += 2;
mac802154_putsaddr(iob, coordaddr->saddr);
}
else if (coordaddr->mode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&iob->io_data[iob->io_len], &coordaddr->eaddr,
IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, coordaddr->eaddr);
}
}
@ -320,25 +316,22 @@ void mac802154_create_datareq(FAR struct ieee802154_privmac_s *priv,
*/
if (coordaddr->mode != IEEE802154_ADDRMODE_NONE &&
coordaddr->panid == priv->addr.panid)
IEEE802154_PANIDCMP(coordaddr->panid, priv->addr.panid))
{
*u16 |= IEEE802154_FRAMECTRL_PANIDCOMP;
}
else
{
memcpy(&iob->io_data[iob->io_len], &priv->addr.panid, 2);
iob->io_len += 2;
mac802154_putpanid(iob, priv->addr.panid);
}
if (srcmode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&iob->io_data[iob->io_len], &priv->addr.saddr, 2);
iob->io_len += 2;
mac802154_putsaddr(iob, priv->addr.saddr);
}
else if (srcmode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&iob->io_data[iob->io_len], &priv->addr.eaddr, IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, priv->addr.eaddr);
}
/* Copy in the Command Frame Identifier */
@ -792,7 +785,7 @@ static void mac802154_rxframe_worker(FAR void *arg)
FAR struct ieee802154_privmac_s *priv =
(FAR struct ieee802154_privmac_s *)arg;
FAR struct ieee802154_data_ind_s *ind;
FAR struct iob_s *frame;
FAR struct iob_s *iob;
uint16_t *frame_ctrl;
bool panid_comp;
uint8_t ftype;
@ -820,14 +813,14 @@ static void mac802154_rxframe_worker(FAR void *arg)
/* Get a local copy of the frame to make it easier to access */
frame = ind->frame;
iob = ind->frame;
/* Set a local pointer to the frame control then move the offset past
* the frame control field
*/
frame_ctrl = (uint16_t *)&frame->io_data[frame->io_offset];
frame->io_offset += 2;
frame_ctrl = (uint16_t *)&iob->io_data[iob->io_offset];
iob->io_offset += 2;
/* We use the data_ind_s as a container for the frame information even if
* this isn't a data frame
@ -842,7 +835,7 @@ static void mac802154_rxframe_worker(FAR void *arg)
panid_comp = (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP) >>
IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP;
ind->dsn = frame->io_data[frame->io_offset++];
ind->dsn = iob->io_data[iob->io_offset++];
/* If the destination address is included */
@ -850,19 +843,15 @@ static void mac802154_rxframe_worker(FAR void *arg)
{
/* Get the destination PAN ID */
memcpy(&ind->dest.panid, &frame->io_data[frame->io_offset], 2);
frame->io_offset += 2;
mac802154_takepanid(iob, ind->dest.panid);
if (ind->dest.mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&ind->dest.saddr, &frame->io_data[frame->io_offset], 2);
frame->io_offset += 2;
mac802154_takesaddr(iob, ind->dest.saddr);
}
else if (ind->dest.mode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&ind->dest.eaddr[0], &frame->io_data[frame->io_offset],
IEEE802154_EADDR_LEN);
frame->io_offset += IEEE802154_EADDR_LEN;
mac802154_takeeaddr(iob, ind->dest.eaddr);
}
}
@ -876,24 +865,20 @@ static void mac802154_rxframe_worker(FAR void *arg)
{
/* The source PAN ID is equal to the destination PAN ID */
ind->src.panid = ind->dest.panid;
IEEE802154_PANIDCOPY(ind->src.panid, ind->dest.panid);
}
else
{
memcpy(&ind->src.panid, &frame->io_data[frame->io_offset], 2);
frame->io_offset += 2;
mac802154_takepanid(iob, ind->src.panid);
}
if (ind->src.mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&ind->src.saddr, &frame->io_data[frame->io_offset], 2);
frame->io_offset += 2;
mac802154_takesaddr(iob, ind->src.saddr);
}
else if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&ind->src.eaddr[0], &frame->io_data[frame->io_offset],
IEEE802154_EADDR_LEN);
frame->io_offset += 8;
mac802154_takeeaddr(iob, ind->src.eaddr);
}
}
@ -915,7 +900,7 @@ static void mac802154_rxframe_worker(FAR void *arg)
* subsequent functions can start from the byte after the command ID.
*/
uint8_t cmdtype = frame->io_data[frame->io_offset++];
uint8_t cmdtype = iob->io_data[iob->io_offset++];
switch (cmdtype)
{
@ -1028,19 +1013,18 @@ static void mac802154_rx_dataframe(FAR struct ieee802154_privmac_s *priv,
if (priv->promisc)
{
if (ind->dest.panid != priv->addr.panid)
if (!IEEE802154_PANIDCMP(ind->dest.panid, priv->addr.panid))
{
goto notify_with_lock;
}
if (ind->dest.mode == IEEE802154_ADDRMODE_SHORT &&
ind->dest.saddr != priv->addr.saddr)
!IEEE802154_SADDRCMP(ind->dest.saddr, priv->addr.saddr))
{
goto notify_with_lock;
}
else if (ind->dest.mode == IEEE802154_ADDRMODE_EXTENDED &&
(memcmp(&ind->dest.eaddr[0], &priv->addr.eaddr[0],
IEEE802154_EADDR_LEN) != 0))
!IEEE802154_EADDRCMP(ind->dest.eaddr, priv->addr.eaddr))
{
goto notify_with_lock;
}
@ -1063,13 +1047,12 @@ static void mac802154_rx_dataframe(FAR struct ieee802154_privmac_s *priv,
}
if (ind->src.mode == IEEE802154_ADDRMODE_SHORT &&
ind->src.saddr != priv->cmd_desc->destaddr.saddr)
!IEEE802154_SADDRCMP(ind->src.saddr, priv->cmd_desc->destaddr.saddr))
{
goto notify_with_lock;
}
else if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED &&
(memcmp(&ind->src.eaddr[0], &priv->cmd_desc->destaddr.eaddr[0],
IEEE802154_EADDR_LEN) != 0))
!IEEE802154_EADDRCMP(ind->src.eaddr, priv->cmd_desc->destaddr.eaddr))
{
goto notify_with_lock;
}
@ -1218,7 +1201,7 @@ static void mac802154_rx_datareq(FAR struct ieee802154_privmac_s *priv,
{
if (txdesc->destaddr.mode == IEEE802154_ADDRMODE_SHORT)
{
if (txdesc->destaddr.saddr == ind->src.saddr)
if (IEEE802154_SADDRCMP(txdesc->destaddr.saddr, ind->src.saddr))
{
/* Remove the transaction from the queue */
@ -1233,7 +1216,7 @@ static void mac802154_rx_datareq(FAR struct ieee802154_privmac_s *priv,
else if (txdesc->destaddr.mode == IEEE802154_ADDRMODE_EXTENDED)
{
if (memcmp(&txdesc->destaddr.eaddr[0], &ind->src.eaddr[0],
sizeof(IEEE802154_EADDR_LEN)) == 0)
sizeof(IEEE802154_EADDRSIZE)) == 0)
{
/* Remove the transaction from the queue */
@ -1306,18 +1289,15 @@ no_data:
* respond.
*/
*((uint16_t *)&iob->io_data[iob->io_len]) = ind->src.panid;
iob->io_len += 2;
mac802154_putpanid(iob, ind->src.panid);
if (ind->src.mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&iob->io_data[iob->io_len], &ind->src.saddr, 2);
iob->io_len += 2;
mac802154_putsaddr(iob, ind->src.saddr);
}
else if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&iob->io_data[iob->io_len], &ind->src.eaddr, IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, ind->src.eaddr);
}
else
{
@ -1330,7 +1310,7 @@ no_data:
/* Check if the source PAN ID of the incoming request is the same as ours. */
if (ind->src.panid == priv->addr.panid)
if (IEEE802154_PANIDCMP(ind->src.panid, priv->addr.panid))
{
*frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP;
}
@ -1338,23 +1318,19 @@ no_data:
{
/* Copy in our PAN ID */
memcpy(&iob->io_data[iob->io_len], &priv->addr.panid, 2);
iob->io_len += 2;
mac802154_putpanid(iob, priv->addr.panid);
}
/* Copy in our address using the mode that the device used to address us */
if (ind->dest.mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&iob->io_data[iob->io_len], &priv->addr.saddr, 2);
iob->io_len += 2;
mac802154_putsaddr(iob, priv->addr.saddr);
*frame_ctrl |= (IEEE802154_ADDRMODE_SHORT << IEEE802154_FRAMECTRL_SHIFT_SADDR);
}
else
{
memcpy(&iob->io_data[iob->io_len], &ind->dest.eaddr, IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, priv->addr.eaddr);
*frame_ctrl |= (IEEE802154_ADDRMODE_EXTENDED << IEEE802154_FRAMECTRL_SHIFT_SADDR);
}
@ -1520,7 +1496,7 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev)
{
FAR struct ieee802154_privmac_s *mac;
FAR struct ieee802154_radiocb_s *radiocb;
uint8_t eaddr[IEEE802154_EADDR_LEN];
uint8_t eaddr[IEEE802154_EADDRSIZE];
int i;
/* Allocate object */
@ -1571,12 +1547,12 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev)
/* Set the default extended address */
for (i = 0; i < IEEE802154_EADDR_LEN; i++)
for (i = 0; i < IEEE802154_EADDRSIZE; i++)
{
eaddr[i] = (CONFIG_IEEE802154_DEFAULT_EADDR >> (8 * i)) & 0xFF;
}
memcpy(&mac->addr.eaddr, &eaddr[0], IEEE802154_EADDR_LEN);
IEEE802154_EADDRCOPY(mac->addr.eaddr, eaddr);
mac->radio->set_attr(mac->radio, IEEE802154_ATTR_MAC_EXTENDED_ADDR,
(union ieee802154_attr_u *)&eaddr[0]);

View File

@ -90,6 +90,11 @@ int mac802154_req_associate(MACHANDLE mac,
bool rxonidle;
int ret;
if (req->coordaddr.mode == IEEE802154_ADDRMODE_NONE)
{
return -EINVAL;
}
/* Get exlusive access to the operation sempaphore. This must happen before
* getting exclusive access to the MAC struct or else there could be a lockup
* condition. This would occur if another thread is using the cmdtrans but
@ -122,34 +127,16 @@ int mac802154_req_associate(MACHANDLE mac,
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_PHY_CURRENT_PAGE,
(FAR const union ieee802154_attr_u *)&req->chpage);
/* Set the PANID attribute */
priv->addr.panid = req->coordaddr.panid;
priv->coordaddr.panid = req->coordaddr.panid;
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_MAC_PANID,
(FAR const union ieee802154_attr_u *)&req->coordaddr.panid);
/* Set the coordinator address attributes */
priv->coordaddr.mode = req->coordaddr.mode;
memcpy(&priv->coordaddr, &req->coordaddr, sizeof(struct ieee802154_addr_s));
if (priv->coordaddr.mode == IEEE802154_ADDRMODE_SHORT)
{
priv->coordaddr.saddr = req->coordaddr.saddr;
memcpy(&priv->coordaddr.eaddr[0], IEEE802154_EADDR_UNSPEC,
IEEE802154_EADDR_LEN);
}
else if (priv->coordaddr.mode == IEEE802154_ADDRMODE_EXTENDED)
{
priv->coordaddr.saddr = IEEE802154_SADDR_UNSPEC;
memcpy(&priv->coordaddr.eaddr[0], &req->coordaddr.eaddr[0],
IEEE802154_EADDR_LEN);
}
else
{
ret = -EINVAL;
goto errout;
}
/* Copy the coordinator PAN ID to our PAN ID */
IEEE802154_PANIDCOPY(priv->addr.panid, req->coordaddr.panid);
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_MAC_PANID,
(FAR const union ieee802154_attr_u *)req->coordaddr.panid);
/* Copy in the capabilities information bitfield */
@ -210,8 +197,7 @@ int mac802154_req_associate(MACHANDLE mac,
* PAN to which to associate. [1] pg. 68
*/
memcpy(&iob->io_data[iob->io_len], &priv->coordaddr.panid, 2);
iob->io_len += 2;
mac802154_putpanid(iob, priv->coordaddr.panid);
/* The Destination Address field shall contain the address from the beacon
* frame that was transmitted by the coordinator to which the association
@ -220,27 +206,20 @@ int mac802154_req_associate(MACHANDLE mac,
if (priv->coordaddr.mode == IEEE802154_ADDRMODE_SHORT)
{
memcpy(&iob->io_data[iob->io_len], &priv->coordaddr.saddr, 2);
iob->io_len += 2;
mac802154_putsaddr(iob, priv->coordaddr.saddr);
}
else if (priv->coordaddr.mode == IEEE802154_ADDRMODE_EXTENDED)
{
memcpy(&iob->io_data[iob->io_len], &priv->coordaddr.eaddr[0],
IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, priv->coordaddr.eaddr);
}
/* The Source PAN Identifier field shall contain the broadcast PAN identifier.*/
u16 = (uint16_t *)&iob->io_data[iob->io_len];
*u16 = IEEE802154_SADDR_BCAST;
iob->io_len += 2;
mac802154_putsaddr(iob, &IEEE802154_SADDR_BCAST);
/* The Source Address field shall contain the value of macExtendedAddress. */
memcpy(&iob->io_data[iob->io_len], &priv->addr.eaddr[0],
IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, priv->addr.eaddr);
/* Copy in the Command Frame Identifier */
@ -284,10 +263,6 @@ int mac802154_req_associate(MACHANDLE mac,
priv->radio->txdelayed(priv->radio, txdesc, 0);
return OK;
errout:
mac802154_givesem(&priv->exclsem);
return ret;
}
/****************************************************************************
@ -351,20 +326,17 @@ int mac802154_resp_associate(MACHANDLE mac,
* Destination PAN Identifier field shall contain the value of macPANId, while
* the Source PAN Identifier field shall be omitted. [1] pg. 69
*/
memcpy(&iob->io_data[iob->io_len], &priv->addr.panid, 2);
iob->io_len += 2;
mac802154_putpanid(iob, priv->addr.panid);
/* The Destination Address field shall contain the extended address of the
* device requesting association. [1] pg. 69 */
memcpy(&iob->io_data[iob->io_len], &resp->devaddr[0], IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, resp->devaddr);
/* The Source Address field shall contain the value of macExtendedAddress. */
memcpy(&iob->io_data[iob->io_len], &priv->addr.eaddr[0], IEEE802154_EADDR_LEN);
iob->io_len += IEEE802154_EADDR_LEN;
mac802154_puteaddr(iob, priv->addr.eaddr);
/* Copy in the Command Frame Identifier */
@ -374,14 +346,12 @@ int mac802154_resp_associate(MACHANDLE mac,
if (resp->status == IEEE802154_STATUS_SUCCESS)
{
memcpy(&iob->io_data[iob->io_len], &resp->assocsaddr, 2);
mac802154_putsaddr(iob, resp->assocsaddr);
}
else
{
u16 = (FAR uint16_t *)&iob->io_data[iob->io_len];
*u16 = IEEE802154_SADDR_UNSPEC;
mac802154_putsaddr(iob, &IEEE802154_SADDR_UNSPEC);
}
iob->io_len += 2;
/* Copy in the association status */
@ -409,9 +379,9 @@ int mac802154_resp_associate(MACHANDLE mac,
txdesc->frame = iob;
txdesc->frametype = IEEE802154_FRAME_COMMAND;
txdesc->destaddr.panid = priv->addr.panid;
txdesc->destaddr.mode = IEEE802154_ADDRMODE_EXTENDED;
memcpy(&txdesc->destaddr.eaddr[0], &resp->devaddr[0], IEEE802154_EADDR_LEN);
IEEE802154_PANIDCOPY(txdesc->destaddr.panid, priv->addr.panid);
IEEE802154_EADDRCOPY(txdesc->destaddr.eaddr, resp->devaddr);
mac802154_setupindirect(priv, txdesc);
@ -469,7 +439,7 @@ void mac802154_txdone_assocreq(FAR struct ieee802154_privmac_s *priv,
* if the association attempt was unsuccessful. [1] pg. 81
*/
notif->u.assocconf.saddr = IEEE802154_SADDR_UNSPEC;
IEEE802154_SADDRCOPY(notif->u.assocconf.saddr, &IEEE802154_SADDR_UNSPEC);
/* We are now done the operation, unlock the semaphore */
@ -601,7 +571,7 @@ void mac802154_txdone_datareq_assoc(FAR struct ieee802154_privmac_s *priv,
* if the association attempt was unsuccessful. [1] pg. 81
*/
notif->u.assocconf.saddr = IEEE802154_SADDR_UNSPEC;
IEEE802154_SADDRCOPY(notif->u.assocconf.saddr, &IEEE802154_SADDR_UNSPEC);
/* We are now done the operation, and can release the command */
@ -681,8 +651,7 @@ void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv,
/* Copy the extended address of the requesting device */
memcpy(&notif->u.assocind.devaddr[0], &ind->src.eaddr[0],
sizeof(struct ieee802154_addr_s));
IEEE802154_EADDRCOPY(notif->u.assocind.devaddr, ind->src.eaddr);
/* Copy in the capability information from the frame to the notification */
@ -728,7 +697,7 @@ errout_with_sem:
void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_data_ind_s *ind)
{
FAR struct iob_s *frame = ind->frame;
FAR struct iob_s *iob = ind->frame;
FAR struct ieee802154_notif_s *notif;
/* Check if we are performing an Association operation, if not, we will just
@ -755,13 +724,12 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
/* Parse the short address from the response */
priv->addr.saddr = (uint16_t)(frame->io_data[frame->io_offset]);
frame->io_offset += 2;
mac802154_takesaddr(iob, priv->addr.saddr);
/* Inform the radio of the address change */
priv->radio->set_attr(priv->radio, IEEE802154_ATTR_MAC_SHORT_ADDRESS,
(FAR union ieee802154_attr_u *)&priv->addr.saddr);
(FAR union ieee802154_attr_u *)priv->addr.saddr);
/* A Short Address field value equal to 0xfffe shall indicate that the device
* has been successfully associated with a PAN but has not been allocated a
@ -769,7 +737,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
* only its extended address. [1] pg. 70
*/
if (priv->addr.saddr == IEEE802154_SADDR_BCAST)
if (IEEE802154_SADDRCMP(priv->addr.saddr, &IEEE802154_SADDR_BCAST))
{
/* TODO: Figure out if this is sufficient */
@ -778,7 +746,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
/* Parse the status from the response */
notif->u.assocconf.status = frame->io_data[frame->io_offset++];
notif->u.assocconf.status = iob->io_data[iob->io_offset++];
if (notif->u.assocconf.status == IEEE802154_STATUS_SUCCESS)
{
@ -789,7 +757,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
priv->isassoc = false;
}
notif->u.assocconf.saddr = priv->addr.saddr;
IEEE802154_SADDRCOPY(notif->u.assocconf.saddr, priv->addr.saddr);
/* Unlock the MAC */
@ -850,7 +818,7 @@ static void mac802154_timeout_assoc(FAR struct ieee802154_privmac_s *priv)
notif->notiftype = IEEE802154_NOTIFY_CONF_ASSOC;
notif->u.assocconf.status = IEEE802154_STATUS_NO_DATA;
notif->u.assocconf.saddr = IEEE802154_SADDR_UNSPEC;
IEEE802154_SADDRCOPY(notif->u.assocconf.saddr, &IEEE802154_SADDR_UNSPEC);
mac802154_notify(priv, notif);
}

View File

@ -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

View File

@ -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;

View File

@ -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 */

View File

@ -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.

View File

@ -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:

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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,