ieee802154: remove need for IEEE802154_BCAST flag

This commit is contained in:
Martine Lenders 2016-09-30 13:06:20 +02:00
parent 15c4ceae04
commit a0454b3787
3 changed files with 54 additions and 48 deletions

View File

@ -78,12 +78,24 @@ extern "C" {
/** @} */ /** @} */
/** /**
* @brief Flag for @ref ieee802154_set_frame_hdr to indicate to ignore @p dst * @brief Special address defintions
* and @p dst_len and send broadcast. * @{
* @note This flag is RIOT internal and shall not be used in the FCF of
* packets send over the air
*/ */
#define IEEE802154_BCAST (0x80) /**
* @brief Static initializer for broadcast address
*/
#define IEEE802154_ADDR_BCAST { 0xff, 0xff }
/**
* @brief Length in byte of @ref IEEE802154_ADDR_BCAST
*/
#define IEEE802154_ADDR_BCAST_LEN (IEEE802154_SHORT_ADDRESS_LEN)
/**
* @brief Broadcast address
*/
extern const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN];
/** @} */
/** /**
* @brief Initializes an IEEE 802.15.4 MAC frame header in @p buf. * @brief Initializes an IEEE 802.15.4 MAC frame header in @p buf.
@ -121,9 +133,6 @@ extern "C" {
* @ref IEEE802154_FCF_SECURITY_EN, * @ref IEEE802154_FCF_SECURITY_EN,
* @ref IEEE802154_FCF_FRAME_PEND, and * @ref IEEE802154_FCF_FRAME_PEND, and
* @ref IEEE802154_FCF_ACK_REQ. * @ref IEEE802154_FCF_ACK_REQ.
* Additionally the @ref IEEE802154_BCAST flag can be set
* do ignore @p dst and @p dst_len and just set `ff:ff`
* (broadcast) as destination address
* @param[in] seq Sequence number for frame. * @param[in] seq Sequence number for frame.
* *
* The version field in the FCF will be set implicitly to version 1. * The version field in the FCF will be set implicitly to version 1.

View File

@ -144,9 +144,9 @@ static int _send(gnrc_netdev2_t *gnrc_netdev2, gnrc_pktsnip_t *pkt)
netdev2_ieee802154_t *state = (netdev2_ieee802154_t *)gnrc_netdev2->dev; netdev2_ieee802154_t *state = (netdev2_ieee802154_t *)gnrc_netdev2->dev;
gnrc_netif_hdr_t *netif_hdr; gnrc_netif_hdr_t *netif_hdr;
gnrc_pktsnip_t *vec_snip; gnrc_pktsnip_t *vec_snip;
uint8_t *src, *dst = NULL; const uint8_t *src, *dst = NULL;
int res = 0; int res = 0;
size_t n, src_len; size_t n, src_len, dst_len;
uint8_t mhr[IEEE802154_MAX_HDR_LEN]; uint8_t mhr[IEEE802154_MAX_HDR_LEN];
uint8_t flags = (uint8_t)(state->flags & NETDEV2_IEEE802154_SEND_MASK); uint8_t flags = (uint8_t)(state->flags & NETDEV2_IEEE802154_SEND_MASK);
le_uint16_t dev_pan = byteorder_btols(byteorder_htons(state->pan)); le_uint16_t dev_pan = byteorder_btols(byteorder_htons(state->pan));
@ -164,10 +164,12 @@ static int _send(gnrc_netdev2_t *gnrc_netdev2, gnrc_pktsnip_t *pkt)
/* prepare destination address */ /* prepare destination address */
if (netif_hdr->flags & /* If any of these flags is set so this is correct */ if (netif_hdr->flags & /* If any of these flags is set so this is correct */
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) { (GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
flags |= IEEE802154_BCAST; dst = ieee802154_addr_bcast;
dst_len = IEEE802154_ADDR_BCAST_LEN;
} }
else { else {
dst = gnrc_netif_hdr_get_dst_addr(netif_hdr); dst = gnrc_netif_hdr_get_dst_addr(netif_hdr);
dst_len = netif_hdr->dst_l2addr_len;
} }
src_len = netif_hdr->src_l2addr_len; src_len = netif_hdr->src_l2addr_len;
if (src_len > 0) { if (src_len > 0) {
@ -183,9 +185,8 @@ static int _send(gnrc_netdev2_t *gnrc_netdev2, gnrc_pktsnip_t *pkt)
} }
/* fill MAC header, seq should be set by device */ /* fill MAC header, seq should be set by device */
if ((res = ieee802154_set_frame_hdr(mhr, src, src_len, if ((res = ieee802154_set_frame_hdr(mhr, src, src_len,
dst, netif_hdr->dst_l2addr_len, dst, dst_len, dev_pan,
dev_pan, dev_pan, flags, dev_pan, flags, state->seq++)) == 0) {
state->seq++)) == 0) {
DEBUG("_send_ieee802154: Error preperaring frame\n"); DEBUG("_send_ieee802154: Error preperaring frame\n");
return -EINVAL; return -EINVAL;
} }
@ -199,7 +200,8 @@ static int _send(gnrc_netdev2_t *gnrc_netdev2, gnrc_pktsnip_t *pkt)
vector[0].iov_base = mhr; vector[0].iov_base = mhr;
vector[0].iov_len = (size_t)res; vector[0].iov_len = (size_t)res;
#ifdef MODULE_NETSTATS_L2 #ifdef MODULE_NETSTATS_L2
if (flags & IEEE802154_BCAST) { if (netif_hdr->flags &
(GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
gnrc_netdev2->dev->stats.tx_mcast_count++; gnrc_netdev2->dev->stats.tx_mcast_count++;
} }
else { else {

View File

@ -15,9 +15,12 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include "net/ieee802154.h" #include "net/ieee802154.h"
const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN] = IEEE802154_ADDR_BCAST;
size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len, size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len,
const uint8_t *dst, size_t dst_len, const uint8_t *dst, size_t dst_len,
le_uint16_t src_pan, le_uint16_t dst_pan, le_uint16_t src_pan, le_uint16_t dst_pan,
@ -25,15 +28,12 @@ size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len
{ {
int pos = 3; /* 0-1: FCS, 2: seq */ int pos = 3; /* 0-1: FCS, 2: seq */
uint8_t type = (flags & IEEE802154_FCF_TYPE_MASK); uint8_t type = (flags & IEEE802154_FCF_TYPE_MASK);
uint8_t bcast = (flags & IEEE802154_BCAST);
buf[0] = flags & (~IEEE802154_BCAST); buf[0] = flags;
buf[1] = IEEE802154_FCF_VERS_V1; buf[1] = IEEE802154_FCF_VERS_V1;
if (((src_len != 0) && (src == NULL)) || if (((src_len != 0) && (src == NULL)) ||
((!bcast) && (dst_len != 0) && (dst == NULL)) || ((dst_len != 0) && (dst == NULL))) {
((flags & IEEE802154_FCF_PAN_COMP) &&
(((!bcast) && (dst_len == 0)) || (src_len == 0)))) {
return 0; return 0;
} }
@ -46,39 +46,34 @@ size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len
/* set sequence number */ /* set sequence number */
buf[2] = seq; buf[2] = seq;
if (bcast || (dst_len != 0)) { if (dst_len != 0) {
buf[pos++] = dst_pan.u8[0]; buf[pos++] = dst_pan.u8[0];
buf[pos++] = dst_pan.u8[1]; buf[pos++] = dst_pan.u8[1];
} }
/* fill in destination address */ /* fill in destination address */
if (bcast) { switch (dst_len) {
/* no ACK_REQ for broadcast */ case 0:
buf[0] &= ~IEEE802154_FCF_ACK_REQ; buf[1] |= IEEE802154_FCF_DST_ADDR_VOID;
buf[1] &= ~IEEE802154_FCF_DST_ADDR_MASK; break;
buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT; case 2:
buf[pos++] = 0xff; if (memcmp(dst, ieee802154_addr_bcast,
buf[pos++] = 0xff; sizeof(ieee802154_addr_bcast)) == 0) {
} /* do not request ACKs for broadcast address */
else { buf[0] &= ~IEEE802154_FCF_ACK_REQ;
switch (dst_len) { }
case 0: buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT;
buf[1] |= IEEE802154_FCF_DST_ADDR_VOID; buf[pos++] = dst[1];
break; buf[pos++] = dst[0];
case 2: break;
buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT; case 8:
buf[pos++] = dst[1]; buf[1] |= IEEE802154_FCF_DST_ADDR_LONG;
buf[pos++] = dst[0]; for (int i = 7; i >= 0; i--) {
break; buf[pos++] = dst[i];
case 8: }
buf[1] |= IEEE802154_FCF_DST_ADDR_LONG; break;
for (int i = 7; i >= 0; i--) { default:
buf[pos++] = dst[i]; return 0;
}
break;
default:
return 0;
}
} }
/* fill in source PAN ID (if applicable) */ /* fill in source PAN ID (if applicable) */