From 9f29e56020262035f6c58241b8ff515b1d973bd0 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 30 Sep 2016 13:04:14 +0200 Subject: [PATCH 1/5] netdev2_ieee802154: remove NETDEV2_IEEE802154_PAN_COMP flag --- drivers/at86rf2xx/at86rf2xx.c | 1 - drivers/include/net/netdev2/ieee802154.h | 3 +-- sys/include/net/ieee802154.h | 5 ++--- sys/net/link_layer/ieee802154/ieee802154.c | 13 +++++++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/at86rf2xx/at86rf2xx.c b/drivers/at86rf2xx/at86rf2xx.c index 19c41bd134..fbd06d80d9 100644 --- a/drivers/at86rf2xx/at86rf2xx.c +++ b/drivers/at86rf2xx/at86rf2xx.c @@ -100,7 +100,6 @@ void at86rf2xx_reset(at86rf2xx_t *dev) /* set default TX power */ at86rf2xx_set_txpower(dev, AT86RF2XX_DEFAULT_TXPOWER); /* set default options */ - at86rf2xx_set_option(dev, NETDEV2_IEEE802154_PAN_COMP, true); at86rf2xx_set_option(dev, AT86RF2XX_OPT_AUTOACK, true); at86rf2xx_set_option(dev, AT86RF2XX_OPT_CSMA, true); at86rf2xx_set_option(dev, AT86RF2XX_OPT_TELL_RX_START, false); diff --git a/drivers/include/net/netdev2/ieee802154.h b/drivers/include/net/netdev2/ieee802154.h index 26c861af5e..75f7b36740 100644 --- a/drivers/include/net/netdev2/ieee802154.h +++ b/drivers/include/net/netdev2/ieee802154.h @@ -38,7 +38,7 @@ extern "C" { * @{ */ -#define NETDEV2_IEEE802154_SEND_MASK (0x0068) /**< flags to take for send packets */ +#define NETDEV2_IEEE802154_SEND_MASK (0x0028) /**< flags to take for send packets */ #define NETDEV2_IEEE802154_RESV1 (0x0001) /**< reserved flag */ #define NETDEV2_IEEE802154_RAW (0x0002) /**< pass raw frame to upper layer */ /** @@ -52,7 +52,6 @@ extern "C" { * @brief request ACK from receiver */ #define NETDEV2_IEEE802154_ACK_REQ (0x0020) -#define NETDEV2_IEEE802154_PAN_COMP (0x0040) /**< compress source PAN ID */ #define NETDEV2_IEEE802154_RESV3 (0x0080) /**< reserved flag */ /** * @} diff --git a/sys/include/net/ieee802154.h b/sys/include/net/ieee802154.h index 7989e3597f..14fb31663f 100644 --- a/sys/include/net/ieee802154.h +++ b/sys/include/net/ieee802154.h @@ -119,9 +119,8 @@ extern "C" { * first byte of the IEEE 802.15.4 FCF. This means that * it encompasses the type values, * @ref IEEE802154_FCF_SECURITY_EN, - * @ref IEEE802154_FCF_FRAME_PEND, - * @ref IEEE802154_FCF_ACK_REQ, and - * @ref IEEE802154_FCF_PAN_COMP. + * @ref IEEE802154_FCF_FRAME_PEND, and + * @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 diff --git a/sys/net/link_layer/ieee802154/ieee802154.c b/sys/net/link_layer/ieee802154/ieee802154.c index 489d8f6a80..6bc2bd5c44 100644 --- a/sys/net/link_layer/ieee802154/ieee802154.c +++ b/sys/net/link_layer/ieee802154/ieee802154.c @@ -82,10 +82,15 @@ size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len } /* fill in source PAN ID (if applicable) */ - if (!(flags & IEEE802154_FCF_PAN_COMP) && (src_len != 0)) { - /* (little endian) */ - buf[pos++] = src_pan.u8[0]; - buf[pos++] = src_pan.u8[1]; + if (src_len != 0) { + if ((dst_len != 0) && (src_pan.u16 == dst_pan.u16)) { + buf[0] |= IEEE802154_FCF_PAN_COMP; + } + else { + /* (little endian) */ + buf[pos++] = src_pan.u8[0]; + buf[pos++] = src_pan.u8[1]; + } } /* fill in source address */ From 15c4ceae042262d0fdbd763ffd44a87c741bb047 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 30 Sep 2016 13:05:13 +0200 Subject: [PATCH 2/5] netdev2_ieee802154: cleanup flag definitions --- drivers/include/net/netdev2/ieee802154.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/include/net/netdev2/ieee802154.h b/drivers/include/net/netdev2/ieee802154.h index 75f7b36740..b94a7f9d54 100644 --- a/drivers/include/net/netdev2/ieee802154.h +++ b/drivers/include/net/netdev2/ieee802154.h @@ -39,20 +39,20 @@ extern "C" { */ #define NETDEV2_IEEE802154_SEND_MASK (0x0028) /**< flags to take for send packets */ -#define NETDEV2_IEEE802154_RESV1 (0x0001) /**< reserved flag */ #define NETDEV2_IEEE802154_RAW (0x0002) /**< pass raw frame to upper layer */ /** * @brief use long source addres (set) or short source address (unset) */ #define NETDEV2_IEEE802154_SRC_MODE_LONG (0x0004) -#define NETDEV2_IEEE802154_SECURITY_EN (0x0008) /**< enable security */ -#define NETDEV2_IEEE802154_RESV2 (0x0010) /**< reserved flag */ +/** + * @brief enable security + */ +#define NETDEV2_IEEE802154_SECURITY_EN (IEEE802154_FCF_SECURITY_EN) /** * @brief request ACK from receiver */ -#define NETDEV2_IEEE802154_ACK_REQ (0x0020) -#define NETDEV2_IEEE802154_RESV3 (0x0080) /**< reserved flag */ +#define NETDEV2_IEEE802154_ACK_REQ (IEEE802154_FCF_ACK_REQ) /** * @} */ From a0454b3787e96547488753b36994e8792c00827e Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 30 Sep 2016 13:06:20 +0200 Subject: [PATCH 3/5] ieee802154: remove need for IEEE802154_BCAST flag --- sys/include/net/ieee802154.h | 25 +++++--- .../netdev2/gnrc_netdev2_ieee802154.c | 16 ++--- sys/net/link_layer/ieee802154/ieee802154.c | 61 +++++++++---------- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/sys/include/net/ieee802154.h b/sys/include/net/ieee802154.h index 14fb31663f..65f59862e7 100644 --- a/sys/include/net/ieee802154.h +++ b/sys/include/net/ieee802154.h @@ -78,12 +78,24 @@ extern "C" { /** @} */ /** - * @brief Flag for @ref ieee802154_set_frame_hdr to indicate to ignore @p dst - * 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 + * @brief Special address defintions + * @{ */ -#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. @@ -121,9 +133,6 @@ extern "C" { * @ref IEEE802154_FCF_SECURITY_EN, * @ref IEEE802154_FCF_FRAME_PEND, and * @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. * * The version field in the FCF will be set implicitly to version 1. diff --git a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2_ieee802154.c b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2_ieee802154.c index 60ac303e84..4903662e1d 100644 --- a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2_ieee802154.c +++ b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2_ieee802154.c @@ -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; gnrc_netif_hdr_t *netif_hdr; gnrc_pktsnip_t *vec_snip; - uint8_t *src, *dst = NULL; + const uint8_t *src, *dst = NULL; int res = 0; - size_t n, src_len; + size_t n, src_len, dst_len; uint8_t mhr[IEEE802154_MAX_HDR_LEN]; uint8_t flags = (uint8_t)(state->flags & NETDEV2_IEEE802154_SEND_MASK); 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 */ 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)) { - flags |= IEEE802154_BCAST; + dst = ieee802154_addr_bcast; + dst_len = IEEE802154_ADDR_BCAST_LEN; } else { dst = gnrc_netif_hdr_get_dst_addr(netif_hdr); + dst_len = netif_hdr->dst_l2addr_len; } src_len = netif_hdr->src_l2addr_len; 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 */ if ((res = ieee802154_set_frame_hdr(mhr, src, src_len, - dst, netif_hdr->dst_l2addr_len, - dev_pan, dev_pan, flags, - state->seq++)) == 0) { + dst, dst_len, dev_pan, + dev_pan, flags, state->seq++)) == 0) { DEBUG("_send_ieee802154: Error preperaring frame\n"); 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_len = (size_t)res; #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++; } else { diff --git a/sys/net/link_layer/ieee802154/ieee802154.c b/sys/net/link_layer/ieee802154/ieee802154.c index 6bc2bd5c44..ae687703d6 100644 --- a/sys/net/link_layer/ieee802154/ieee802154.c +++ b/sys/net/link_layer/ieee802154/ieee802154.c @@ -15,9 +15,12 @@ #include #include +#include #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, const uint8_t *dst, size_t dst_len, 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 */ 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; if (((src_len != 0) && (src == NULL)) || - ((!bcast) && (dst_len != 0) && (dst == NULL)) || - ((flags & IEEE802154_FCF_PAN_COMP) && - (((!bcast) && (dst_len == 0)) || (src_len == 0)))) { + ((dst_len != 0) && (dst == NULL))) { 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 */ buf[2] = seq; - if (bcast || (dst_len != 0)) { + if (dst_len != 0) { buf[pos++] = dst_pan.u8[0]; buf[pos++] = dst_pan.u8[1]; } /* fill in destination address */ - if (bcast) { - /* no ACK_REQ for broadcast */ - buf[0] &= ~IEEE802154_FCF_ACK_REQ; - buf[1] &= ~IEEE802154_FCF_DST_ADDR_MASK; - buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT; - buf[pos++] = 0xff; - buf[pos++] = 0xff; - } - else { - switch (dst_len) { - case 0: - buf[1] |= IEEE802154_FCF_DST_ADDR_VOID; - break; - case 2: - buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT; - buf[pos++] = dst[1]; - buf[pos++] = dst[0]; - break; - case 8: - buf[1] |= IEEE802154_FCF_DST_ADDR_LONG; - for (int i = 7; i >= 0; i--) { - buf[pos++] = dst[i]; - } - break; - default: - return 0; - } + switch (dst_len) { + case 0: + buf[1] |= IEEE802154_FCF_DST_ADDR_VOID; + break; + case 2: + if (memcmp(dst, ieee802154_addr_bcast, + sizeof(ieee802154_addr_bcast)) == 0) { + /* do not request ACKs for broadcast address */ + buf[0] &= ~IEEE802154_FCF_ACK_REQ; + } + buf[1] |= IEEE802154_FCF_DST_ADDR_SHORT; + buf[pos++] = dst[1]; + buf[pos++] = dst[0]; + break; + case 8: + buf[1] |= IEEE802154_FCF_DST_ADDR_LONG; + for (int i = 7; i >= 0; i--) { + buf[pos++] = dst[i]; + } + break; + default: + return 0; } /* fill in source PAN ID (if applicable) */ From 3b35dae6cd0e75ba14820ee638003af129d7ce0b Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 30 Sep 2016 13:07:24 +0200 Subject: [PATCH 4/5] tests: adapt unittests for removal of user-controlled PAN_COMP --- .../tests-ieee802154/tests-ieee802154.c | 122 ++---------------- 1 file changed, 12 insertions(+), 110 deletions(-) diff --git a/tests/unittests/tests-ieee802154/tests-ieee802154.c b/tests/unittests/tests-ieee802154/tests-ieee802154.c index 2116d36e90..10eab1b5f6 100644 --- a/tests/unittests/tests-ieee802154/tests-ieee802154.c +++ b/tests/unittests/tests-ieee802154/tests-ieee802154.c @@ -173,85 +173,22 @@ static void test_ieee802154_set_frame_hdr_bcast_src8(void) IEEE802154_FCF_SRC_ADDR_LONG, TEST_UINT8, dst_pan.u8[0], dst_pan.u8[1], - 0xff, 0xff, + ieee802154_addr_bcast[0], ieee802154_addr_bcast[1], src_pan.u8[0], src_pan.u8[1], src.u8[7], src.u8[6], src.u8[5], src.u8[4], src.u8[3], src.u8[2], src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_BCAST; + const uint8_t flags = 0; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - NULL, 0, + ieee802154_addr_bcast, + IEEE802154_ADDR_BCAST_LEN, src_pan, dst_pan, flags, TEST_UINT8)); TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); } -static void test_ieee802154_set_frame_hdr_dst0_src2(void) -{ - const network_uint16_t src = byteorder_htons(TEST_UINT16); - const le_uint16_t src_pan = byteorder_htols(TEST_UINT16 + 1); - const le_uint16_t dst_pan = byteorder_htols(0); - /* IEEE 802.15.4 is little endian! */ - const uint8_t exp[] = { IEEE802154_FCF_ACK_REQ, - IEEE802154_FCF_VERS_V1 | - IEEE802154_FCF_DST_ADDR_VOID | - IEEE802154_FCF_SRC_ADDR_SHORT, - TEST_UINT8, - src_pan.u8[0], src_pan.u8[1], - src.u8[1], src.u8[0] }; - uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_ACK_REQ; - - TEST_ASSERT_EQUAL_INT(sizeof(exp), - ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - NULL, 0, - src_pan, dst_pan, - flags, TEST_UINT8)); - TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); -} - -static void test_ieee802154_set_frame_hdr_dst0_src8(void) -{ - const network_uint64_t src = byteorder_htonll(TEST_UINT64); - const le_uint16_t src_pan = byteorder_htols(TEST_UINT16); - const le_uint16_t dst_pan = byteorder_htols(0); - /* IEEE 802.15.4 is little endian! */ - const uint8_t exp[] = { IEEE802154_FCF_FRAME_PEND, - IEEE802154_FCF_VERS_V1 | - IEEE802154_FCF_DST_ADDR_VOID | - IEEE802154_FCF_SRC_ADDR_LONG, - TEST_UINT8, - src_pan.u8[0], src_pan.u8[1], - src.u8[7], src.u8[6], src.u8[5], src.u8[4], - src.u8[3], src.u8[2], src.u8[1], src.u8[0] }; - uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_FRAME_PEND; - - TEST_ASSERT_EQUAL_INT(sizeof(exp), - ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - NULL, 0, - src_pan, dst_pan, - flags, TEST_UINT8)); - TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); -} - -static void test_ieee802154_set_frame_hdr_dst0_src8_pancomp(void) -{ - const network_uint64_t src = byteorder_htonll(TEST_UINT64); - const le_uint16_t src_pan = byteorder_htols(TEST_UINT16); - const le_uint16_t dst_pan = byteorder_htols(0); - uint8_t res; - const uint8_t flags = IEEE802154_FCF_PAN_COMP; - - TEST_ASSERT_EQUAL_INT(0, - ieee802154_set_frame_hdr(&res, src.u8, sizeof(src), - NULL, 0, - src_pan, dst_pan, - flags, TEST_UINT8)); -} - static void test_ieee802154_set_frame_hdr_dst2_src0(void) { const network_uint16_t dst = byteorder_htons(TEST_UINT16); @@ -276,21 +213,6 @@ static void test_ieee802154_set_frame_hdr_dst2_src0(void) TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); } -static void test_ieee802154_set_frame_hdr_dst2_src0_pancomp(void) -{ - const network_uint16_t dst = byteorder_htons(TEST_UINT16); - const le_uint16_t src_pan = byteorder_htols(0); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 1); - uint8_t res; - const uint8_t flags = IEEE802154_FCF_PAN_COMP; - - TEST_ASSERT_EQUAL_INT(0, - ieee802154_set_frame_hdr(&res, NULL, 0, - dst.u8, sizeof(dst), - src_pan, dst_pan, - flags, TEST_UINT8)); -} - static void test_ieee802154_set_frame_hdr_dst2_src2(void) { const network_uint16_t src = byteorder_htons(TEST_UINT16); @@ -323,7 +245,7 @@ static void test_ieee802154_set_frame_hdr_dst2_src2_pancomp(void) const network_uint16_t src = byteorder_htons(TEST_UINT16); const le_uint16_t src_pan = byteorder_htols(TEST_UINT16 + 1); const network_uint16_t dst = byteorder_htons(TEST_UINT16 + 2); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 3); + const le_uint16_t dst_pan = src_pan; /* IEEE 802.15.4 is little endian! */ const uint8_t exp[] = { IEEE802154_FCF_TYPE_DATA | IEEE802154_FCF_PAN_COMP, IEEE802154_FCF_VERS_V1 | @@ -335,7 +257,7 @@ static void test_ieee802154_set_frame_hdr_dst2_src2_pancomp(void) /* src_pan compressed (and assumed equal to dst_pan) */ src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_TYPE_DATA | IEEE802154_FCF_PAN_COMP; + const uint8_t flags = IEEE802154_FCF_TYPE_DATA; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), @@ -378,7 +300,7 @@ static void test_ieee802154_set_frame_hdr_dst2_src8_pancomp(void) const network_uint64_t src = byteorder_htonll(TEST_UINT64); const le_uint16_t src_pan = byteorder_htols(TEST_UINT16); const network_uint16_t dst = byteorder_htons(TEST_UINT16 + 1); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 2); + const le_uint16_t dst_pan = src_pan; /* IEEE 802.15.4 is little endian! */ const uint8_t exp[] = { IEEE802154_FCF_TYPE_DATA | IEEE802154_FCF_PAN_COMP, IEEE802154_FCF_VERS_V1 | @@ -391,7 +313,7 @@ static void test_ieee802154_set_frame_hdr_dst2_src8_pancomp(void) src.u8[7], src.u8[6], src.u8[5], src.u8[4], src.u8[3], src.u8[2], src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_TYPE_DATA | IEEE802154_FCF_PAN_COMP; + const uint8_t flags = IEEE802154_FCF_TYPE_DATA; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), @@ -426,21 +348,6 @@ static void test_ieee802154_set_frame_hdr_dst8_src0(void) TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); } -static void test_ieee802154_set_frame_hdr_dst8_src0_pancomp(void) -{ - const network_uint64_t dst = byteorder_htonll(TEST_UINT64); - const le_uint16_t src_pan = byteorder_htols(0); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16); - uint8_t res; - const uint8_t flags = IEEE802154_FCF_PAN_COMP; - - TEST_ASSERT_EQUAL_INT(0, - ieee802154_set_frame_hdr(&res, NULL, 0, - dst.u8, sizeof(dst), - src_pan, dst_pan, - flags, TEST_UINT8)); -} - static void test_ieee802154_set_frame_hdr_dst8_src2(void) { const network_uint16_t src = byteorder_htons(TEST_UINT16); @@ -474,7 +381,7 @@ static void test_ieee802154_set_frame_hdr_dst8_src2_pancomp(void) const network_uint16_t src = byteorder_htons(TEST_UINT16); const le_uint16_t src_pan = byteorder_htols(TEST_UINT16 + 1); const network_uint64_t dst = byteorder_htonll(TEST_UINT64); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 2); + const le_uint16_t dst_pan = src_pan; /* IEEE 802.15.4 is little endian! */ const uint8_t exp[] = { IEEE802154_FCF_TYPE_BEACON | IEEE802154_FCF_PAN_COMP, IEEE802154_FCF_VERS_V1 | @@ -487,7 +394,7 @@ static void test_ieee802154_set_frame_hdr_dst8_src2_pancomp(void) /* src_pan compressed (and assumed equal to dst_pan) */ src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_TYPE_BEACON | IEEE802154_FCF_PAN_COMP; + const uint8_t flags = IEEE802154_FCF_TYPE_BEACON; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), @@ -531,7 +438,7 @@ static void test_ieee802154_set_frame_hdr_dst8_src8_pancomp(void) const network_uint64_t src = byteorder_htonll(TEST_UINT64); const le_uint16_t src_pan = byteorder_htols(TEST_UINT16); const network_uint64_t dst = byteorder_htonll(TEST_UINT64); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 1); + const le_uint16_t dst_pan = src_pan; /* IEEE 802.15.4 is little endian! */ const uint8_t exp[] = { IEEE802154_FCF_TYPE_BEACON | IEEE802154_FCF_PAN_COMP, IEEE802154_FCF_VERS_V1 | @@ -545,7 +452,7 @@ static void test_ieee802154_set_frame_hdr_dst8_src8_pancomp(void) src.u8[7], src.u8[6], src.u8[5], src.u8[4], src.u8[3], src.u8[2], src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_FCF_TYPE_BEACON | IEEE802154_FCF_PAN_COMP; + const uint8_t flags = IEEE802154_FCF_TYPE_BEACON; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), @@ -1167,17 +1074,12 @@ Test *tests_ieee802154_tests(void) new_TestFixture(test_ieee802154_set_frame_hdr_bcast_dst2_src2), new_TestFixture(test_ieee802154_set_frame_hdr_bcast_dst8_src2), new_TestFixture(test_ieee802154_set_frame_hdr_bcast_src8), - new_TestFixture(test_ieee802154_set_frame_hdr_dst0_src2), - new_TestFixture(test_ieee802154_set_frame_hdr_dst0_src8), - new_TestFixture(test_ieee802154_set_frame_hdr_dst0_src8_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src0), - new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src0_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src2), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src2_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src8), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src8_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst8_src0), - new_TestFixture(test_ieee802154_set_frame_hdr_dst8_src0_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst8_src2), new_TestFixture(test_ieee802154_set_frame_hdr_dst8_src2_pancomp), new_TestFixture(test_ieee802154_set_frame_hdr_dst8_src8), From ed343907e49f47f3f2ff5cdfcddf213eb2bc5593 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 30 Sep 2016 13:08:05 +0200 Subject: [PATCH 5/5] tests: adapt tests for changed broadcast settings --- .../tests-ieee802154/tests-ieee802154.c | 71 +++---------------- 1 file changed, 8 insertions(+), 63 deletions(-) diff --git a/tests/unittests/tests-ieee802154/tests-ieee802154.c b/tests/unittests/tests-ieee802154/tests-ieee802154.c index 10eab1b5f6..a73bd8aee8 100644 --- a/tests/unittests/tests-ieee802154/tests-ieee802154.c +++ b/tests/unittests/tests-ieee802154/tests-ieee802154.c @@ -68,13 +68,14 @@ static void test_ieee802154_set_frame_hdr_bcast_src0(void) IEEE802154_FCF_DST_ADDR_SHORT, TEST_UINT8, dst_pan.u8[0], dst_pan.u8[1], - 0xff, 0xff }; + ieee802154_addr_bcast[0], ieee802154_addr_bcast[1] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_BCAST; + const uint8_t flags = 0; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, NULL, 0, - NULL, 0, + ieee802154_addr_bcast, + IEEE802154_ADDR_BCAST_LEN, src_pan, dst_pan, flags, TEST_UINT8)); TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); @@ -92,70 +93,16 @@ static void test_ieee802154_set_frame_hdr_bcast_src2(void) IEEE802154_FCF_SRC_ADDR_SHORT, TEST_UINT8, dst_pan.u8[0], dst_pan.u8[1], - 0xff, 0xff, + ieee802154_addr_bcast[0], ieee802154_addr_bcast[1], src_pan.u8[0], src_pan.u8[1], src.u8[1], src.u8[0] }; uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_BCAST; + const uint8_t flags = 0; TEST_ASSERT_EQUAL_INT(sizeof(exp), ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - NULL, 0, - src_pan, dst_pan, - flags, TEST_UINT8)); - TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); -} - -static void test_ieee802154_set_frame_hdr_bcast_dst2_src2(void) -{ - const network_uint16_t src = byteorder_htons(TEST_UINT16); - const le_uint16_t src_pan = byteorder_htols(TEST_UINT16 + 1); - const network_uint16_t dst = byteorder_htons(TEST_UINT16); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 2); - /* IEEE 802.15.4 is little endian! */ - const uint8_t exp[] = { 0x00, - IEEE802154_FCF_VERS_V1 | - IEEE802154_FCF_DST_ADDR_SHORT | - IEEE802154_FCF_SRC_ADDR_SHORT, - TEST_UINT8, - dst_pan.u8[0], dst_pan.u8[1], - 0xff, 0xff, - src_pan.u8[0], src_pan.u8[1], - src.u8[1], src.u8[0] }; - uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_BCAST; /* broadcast flag lets dst be ignored */ - - TEST_ASSERT_EQUAL_INT(sizeof(exp), - ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - dst.u8, sizeof(dst), - src_pan, dst_pan, - flags, TEST_UINT8)); - TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); -} - -static void test_ieee802154_set_frame_hdr_bcast_dst8_src2(void) -{ - const network_uint16_t src = byteorder_htons(TEST_UINT16); - const le_uint16_t src_pan = byteorder_htols(TEST_UINT16 + 1); - const network_uint64_t dst = byteorder_htonll(TEST_UINT64); - const le_uint16_t dst_pan = byteorder_htols(TEST_UINT16 + 2); - /* IEEE 802.15.4 is little endian! */ - const uint8_t exp[] = { 0x00, - IEEE802154_FCF_VERS_V1 | - /* broadcast address is short */ - IEEE802154_FCF_DST_ADDR_SHORT | - IEEE802154_FCF_SRC_ADDR_SHORT, - TEST_UINT8, - dst_pan.u8[0], dst_pan.u8[1], - 0xff, 0xff, - src_pan.u8[0], src_pan.u8[1], - src.u8[1], src.u8[0] }; - uint8_t res[sizeof(exp)]; - const uint8_t flags = IEEE802154_BCAST; /* broadcast flag lets dst be ignored */ - - TEST_ASSERT_EQUAL_INT(sizeof(exp), - ieee802154_set_frame_hdr(res, src.u8, sizeof(src), - dst.u8, sizeof(dst), + ieee802154_addr_bcast, + IEEE802154_ADDR_BCAST_LEN, src_pan, dst_pan, flags, TEST_UINT8)); TEST_ASSERT_EQUAL_INT(0, memcmp(exp, res, sizeof(exp))); @@ -1071,8 +1018,6 @@ Test *tests_ieee802154_tests(void) new_TestFixture(test_ieee802154_set_frame_hdr_flags0_non_beacon_non_ack), new_TestFixture(test_ieee802154_set_frame_hdr_bcast_src0), new_TestFixture(test_ieee802154_set_frame_hdr_bcast_src2), - new_TestFixture(test_ieee802154_set_frame_hdr_bcast_dst2_src2), - new_TestFixture(test_ieee802154_set_frame_hdr_bcast_dst8_src2), new_TestFixture(test_ieee802154_set_frame_hdr_bcast_src8), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src0), new_TestFixture(test_ieee802154_set_frame_hdr_dst2_src2),