diff --git a/drivers/include/net/netdev/ieee802154.h b/drivers/include/net/netdev/ieee802154.h index d8eb260c185ee4f478d84fd7d3acccbbdf6667cd..70da2a0a5f30f1a43e0f81c115fc9ebf91ffad0e 100644 --- a/drivers/include/net/netdev/ieee802154.h +++ b/drivers/include/net/netdev/ieee802154.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Freie Universität Berlin + * Copyright (C) 2016-2019 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -177,6 +177,21 @@ int netdev_ieee802154_get(netdev_ieee802154_t *dev, netopt_t opt, void *value, int netdev_ieee802154_set(netdev_ieee802154_t *dev, netopt_t opt, const void *value, size_t value_len); +/** + * @brief This funtion compares destination address and pan id with addresses + * and pan id of the device + * + * this funciton is meant top be used by drivers that do not support address + * filtering in hw + * + * @param[in] dev network device descriptor + * @param[in] mhr mac header + * + * @return 0 successfull if packet is for the device + * @return 1 fails if packet is not for the device or pan + */ +int netdev_ieee802154_dst_filter(netdev_ieee802154_t *dev, const uint8_t *mhr); + #ifdef __cplusplus } #endif diff --git a/drivers/netdev_ieee802154/netdev_ieee802154.c b/drivers/netdev_ieee802154/netdev_ieee802154.c index d21e798e078079f8532fb9659018261ff74d73ab..623604f39027c0bb0847e7a0b65c214d1e3d9e9e 100644 --- a/drivers/netdev_ieee802154/netdev_ieee802154.c +++ b/drivers/netdev_ieee802154/netdev_ieee802154.c @@ -253,4 +253,30 @@ int netdev_ieee802154_set(netdev_ieee802154_t *dev, netopt_t opt, const void *va return res; } +int netdev_ieee802154_dst_filter(netdev_ieee802154_t *dev, const uint8_t *mhr) +{ + 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(&dev->pan, dst_pan.u8, 2) != 0)) { + return 1; + } + + /* check destination address */ + if (((addr_len == IEEE802154_SHORT_ADDRESS_LEN) && + (memcmp(dev->short_addr, dst_addr, addr_len) == 0 || + memcmp(ieee802154_addr_bcast, dst_addr, addr_len) == 0)) || + ((addr_len == IEEE802154_LONG_ADDRESS_LEN) && + (memcmp(dev->long_addr, dst_addr, addr_len) == 0))) { + return 0; + } + + return 1; +} + /** @} */ diff --git a/sys/include/net/ieee802154.h b/sys/include/net/ieee802154.h index 69d4f6c4b2961c85770ea2e8e7d10a3e5d454f96..0f86442b50e8dfee50e473258ba78753dc923be9 100644 --- a/sys/include/net/ieee802154.h +++ b/sys/include/net/ieee802154.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-16 Freie Universität Berlin + * Copyright (C) 2015-2019 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -31,6 +31,11 @@ extern "C" { #endif +/** + * @brief Default start frame delimiter + */ +#define IEEE802154_SFD (0xa7) + /** * @brief IEEE 802.15.4 address lengths * @{ @@ -144,6 +149,13 @@ extern const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN]; #define IEEE802154_DEFAULT_PANID (0x0023U) #endif +/** + * @brief IEEE802.15.4 Broadcast PANID + */ +#ifndef IEEE802154_PANID_BCAST +#define IEEE802154_PANID_BCAST { 0xff, 0xff } +#endif + /** * @brief IEEE802.15.4 default TX power (in dBm) */