From 6fa3d0fa3e779b5f1fb3be3cb60aef7e3f90ea13 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Mon, 11 Sep 2017 10:14:48 +0200 Subject: [PATCH] net/ieee802154: Verify in L2 the Sub-Ghz channel value Depending on device's band, the upper channel limit can vary a lot in Sub-Ghz. Thus verifying it directly in L2 before requesting it to the device. Signed-off-by: Tomasz Bursztyka --- subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c | 4 ++++ subsys/net/ip/l2/ieee802154/ieee802154_utils.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c b/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c index 13d17cc932e..78d717b1dff 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c +++ b/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c @@ -389,6 +389,10 @@ static int ieee802154_set_parameters(u32_t mgmt_request, if (mgmt_request == NET_REQUEST_IEEE802154_SET_CHANNEL) { if (ctx->channel != value) { + if (!ieee802154_verify_channel(iface->dev, value)) { + return -EINVAL; + } + ret = radio->set_channel(iface->dev, value); if (!ret) { ctx->channel = value; diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_utils.h b/subsys/net/ip/l2/ieee802154/ieee802154_utils.h index c321fab83f6..b0390c1c4b9 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_utils.h +++ b/subsys/net/ip/l2/ieee802154/ieee802154_utils.h @@ -68,4 +68,19 @@ static inline void ieee802154_filter_pan_id(struct net_if *iface, } } +static inline bool ieee802154_verify_channel(struct device *dev, u16_t channel) +{ +#ifdef CONFIG_NET_L2_IEEE802154_SUB_GHZ + const struct ieee802154_radio_api *radio = dev->driver_api; + + if (radio->get_capabilities(dev) & IEEE802154_HW_SUB_GHZ) { + if (channel > radio->get_subg_channel_count(dev)) { + return false; + } + } +#endif /* CONFIG_NET_L2_IEEE802154_SUB_GHZ */ + + return true; +} + #endif /* __IEEE802154_UTILS_H__ */