ieee802154: add ieee802154_dst_filter

This commit is contained in:
Jose Alamos 2021-06-21 13:47:22 +02:00
parent 2a1a2ee1d5
commit 8f2be7b486
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
2 changed files with 46 additions and 0 deletions

View File

@ -396,6 +396,25 @@ int ieee802154_get_src(const uint8_t *mhr, uint8_t *src, le_uint16_t *src_pan);
*/ */
int ieee802154_get_dst(const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan); int ieee802154_get_dst(const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan);
/**
* @brief Check whether a frame pass the IEEE 802.15.4 frame filter.
*
* A frame passes the frame filter only if:
* - The PAN ID matches the PAN ID of the frame filter or the broadcast PAN ID
* - Either the Short or Extended Address matches the frame filter OR the
* Short Address is the broadcast address.
*
* @param[in] mhr MAC header (PSDU)
* @param[in] pan PAN ID of the frame filter.
* @param[in] short_addr Short Address of the frame filter.
* @param[in] ext_addr Extended Address of the frame filter.
*
* @return 0 if frame passes the frame filter.
* @return 1 if frame doesn't pass the frame filter.
*/
int ieee802154_dst_filter(const uint8_t *mhr, uint16_t pan,
network_uint16_t short_addr, const eui64_t *ext_addr);
/** /**
* @brief Gets sequence number from MAC header. * @brief Gets sequence number from MAC header.
* *

View File

@ -241,4 +241,31 @@ int ieee802154_get_dst(const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan)
return 0; return 0;
} }
int ieee802154_dst_filter(const uint8_t *mhr, uint16_t pan,
network_uint16_t short_addr, const eui64_t *ext_addr)
{
uint8_t dst_addr[IEEE802154_LONG_ADDRESS_LEN];
le_uint16_t dst_pan;
uint8_t pan_bcast[] = IEEE802154_PANID_BCAST;
int addr_len = ieee802154_get_dst(mhr, dst_addr, &dst_pan);
/* filter PAN ID */
if ((memcmp(pan_bcast, dst_pan.u8, 2) != 0) &&
(memcmp(&pan, dst_pan.u8, 2) != 0)) {
return 1;
}
/* check destination address */
if (((addr_len == IEEE802154_SHORT_ADDRESS_LEN) &&
(memcmp(&short_addr.u8, dst_addr, addr_len) == 0 ||
memcmp(ieee802154_addr_bcast, dst_addr, addr_len) == 0)) ||
((addr_len == IEEE802154_LONG_ADDRESS_LEN) &&
(memcmp(ext_addr->uint8, dst_addr, addr_len) == 0))) {
return 0;
}
return 1;
}
/** @} */ /** @} */