From b86b7d3a418f1d20e8aa1ab4963b76414c7956de Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Sun, 4 Sep 2022 16:06:50 +0200 Subject: [PATCH] net: l2: ieee802154: Fix address length macros When validating a MAC command, there is sometimes a misunderstanding of what "src" and "dst" length mean. There are actually two fields in the MHR: - One giving the type of address, if it is short or extended, it is the value provided by the macros IEEE802154_ADDR_MODE_{SHORT,EXTENDED} and their respective decimal values are 2 and 3. - One giving the size of the address field, this is IEEE802154_{SHORT,EXT}_ADDR_LENGTH and their value is actually 2 and 8 (bytes). The function validate_mac_command() provides inputs to validate_mac_command_cfi_to_mhr() which expects the former information. Signed-off-by: Miquel Raynal --- subsys/net/l2/ieee802154/ieee802154_frame.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/net/l2/ieee802154/ieee802154_frame.c b/subsys/net/l2/ieee802154/ieee802154_frame.c index b89cfb4a334..07c13f19b3f 100644 --- a/subsys/net/l2/ieee802154/ieee802154_frame.c +++ b/subsys/net/l2/ieee802154/ieee802154_frame.c @@ -283,7 +283,7 @@ static inline bool validate_mac_command(struct ieee802154_mpdu *mpdu, uint8_t *b return false; case IEEE802154_CFI_ASSOCIATION_REQUEST: len += IEEE802154_CMD_ASSOC_REQ_LENGTH; - src = IEEE802154_EXT_ADDR_LENGTH; + src = IEEE802154_ADDR_MODE_EXTENDED; src_pan_brdcst_chk = true; dst = IEEE802154_ADDR_MODE_SHORT | IEEE802154_ADDR_MODE_EXTENDED; @@ -299,8 +299,8 @@ static inline bool validate_mac_command(struct ieee802154_mpdu *mpdu, uint8_t *b case IEEE802154_CFI_PAN_ID_CONLICT_NOTIFICATION: ar = 1U; comp = 1U; - src = IEEE802154_EXT_ADDR_LENGTH; - dst = IEEE802154_EXT_ADDR_LENGTH; + src = IEEE802154_ADDR_MODE_EXTENDED; + dst = IEEE802154_ADDR_MODE_EXTENDED; break; case IEEE802154_CFI_DATA_REQUEST: @@ -317,7 +317,7 @@ static inline bool validate_mac_command(struct ieee802154_mpdu *mpdu, uint8_t *b break; case IEEE802154_CFI_ORPHAN_NOTIFICATION: comp = 1U; - src = IEEE802154_EXT_ADDR_LENGTH; + src = IEEE802154_ADDR_MODE_EXTENDED; dst = IEEE802154_ADDR_MODE_SHORT; break; @@ -329,7 +329,7 @@ static inline bool validate_mac_command(struct ieee802154_mpdu *mpdu, uint8_t *b break; case IEEE802154_CFI_COORDINATOR_REALIGNEMENT: len += IEEE802154_CMD_COORD_REALIGN_LENGTH; - src = IEEE802154_EXT_ADDR_LENGTH; + src = IEEE802154_ADDR_MODE_EXTENDED; if (mpdu->mhr.fs->fc.dst_addr_mode == IEEE802154_ADDR_MODE_SHORT) { dst = IEEE802154_ADDR_MODE_SHORT;