nl802154: add support to set cca ed level
authorAlexander Aring <alex.aring@gmail.com>
Wed, 27 May 2015 11:42:10 +0000 (13:42 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 27 May 2015 17:29:42 +0000 (19:29 +0200)
This patch adds support for setting the current cca ed level value over
nl802154.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Reviewed-by: Varka Bhadram <varkabhadram@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/cfg802154.h
net/ieee802154/nl802154.c
net/ieee802154/rdev-ops.h
net/ieee802154/trace.h
net/mac802154/cfg.c

index 2e3bb012c2ffe51e09c8bf097298aadabdc70cc0..290a9a69af0788794619b0ededc4a6ccfbab5e07 100644 (file)
@@ -44,6 +44,7 @@ struct cfg802154_ops {
        int     (*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
        int     (*set_cca_mode)(struct wpan_phy *wpan_phy,
                                const struct wpan_phy_cca *cca);
+       int     (*set_cca_ed_level)(struct wpan_phy *wpan_phy, s32 ed_level);
        int     (*set_tx_power)(struct wpan_phy *wpan_phy, s32 power);
        int     (*set_pan_id)(struct wpan_phy *wpan_phy,
                              struct wpan_dev *wpan_dev, __le16 pan_id);
index a89d9d02412624f06233eb17abdec9cd28fc5911..7dbb1f4ce7df6bebb28d202f8907e00f71bd497c 100644 (file)
@@ -790,6 +790,28 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)
        return rdev_set_cca_mode(rdev, &cca);
 }
 
+static int nl802154_set_cca_ed_level(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg802154_registered_device *rdev = info->user_ptr[0];
+       s32 ed_level;
+       int i;
+
+       if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL))
+               return -EOPNOTSUPP;
+
+       if (!info->attrs[NL802154_ATTR_CCA_ED_LEVEL])
+               return -EINVAL;
+
+       ed_level = nla_get_s32(info->attrs[NL802154_ATTR_CCA_ED_LEVEL]);
+
+       for (i = 0; i < rdev->wpan_phy.supported.cca_ed_levels_size; i++) {
+               if (ed_level == rdev->wpan_phy.supported.cca_ed_levels[i])
+                       return rdev_set_cca_ed_level(rdev, ed_level);
+       }
+
+       return -EINVAL;
+}
+
 static int nl802154_set_tx_power(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg802154_registered_device *rdev = info->user_ptr[0];
@@ -1122,6 +1144,14 @@ static const struct genl_ops nl802154_ops[] = {
                .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
                                  NL802154_FLAG_NEED_RTNL,
        },
+       {
+               .cmd = NL802154_CMD_SET_CCA_ED_LEVEL,
+               .doit = nl802154_set_cca_ed_level,
+               .policy = nl802154_policy,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
+                                 NL802154_FLAG_NEED_RTNL,
+       },
        {
                .cmd = NL802154_CMD_SET_TX_POWER,
                .doit = nl802154_set_tx_power,
index 36456118a6ecafb12847f699374e1fe29d3359af..b2155a123f6c88980c180eeb7b4ffdcf68bea4fb 100644 (file)
@@ -74,6 +74,17 @@ rdev_set_cca_mode(struct cfg802154_registered_device *rdev,
        return ret;
 }
 
+static inline int
+rdev_set_cca_ed_level(struct cfg802154_registered_device *rdev, s32 ed_level)
+{
+       int ret;
+
+       trace_802154_rdev_set_cca_ed_level(&rdev->wpan_phy, ed_level);
+       ret = rdev->ops->set_cca_ed_level(&rdev->wpan_phy, ed_level);
+       trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
+       return ret;
+}
+
 static inline int
 rdev_set_tx_power(struct cfg802154_registered_device *rdev,
                  s32 power)
index ac790bb1b4fe27e49ef36d1413debd0a275eafe6..73eb7605c1eb64ec6d342498ff32a0be9c195c01 100644 (file)
@@ -123,6 +123,21 @@ TRACE_EVENT(802154_rdev_set_cca_mode,
                  WPAN_CCA_PR_ARG)
 );
 
+TRACE_EVENT(802154_rdev_set_cca_ed_level,
+       TP_PROTO(struct wpan_phy *wpan_phy, s32 ed_level),
+       TP_ARGS(wpan_phy, ed_level),
+       TP_STRUCT__entry(
+               WPAN_PHY_ENTRY
+               __field(s32, ed_level)
+       ),
+       TP_fast_assign(
+               WPAN_PHY_ASSIGN;
+               __entry->ed_level = ed_level;
+       ),
+       TP_printk(WPAN_PHY_PR_FMT ", ed_level: %d", WPAN_PHY_PR_ARG,
+                 __entry->ed_level)
+);
+
 DECLARE_EVENT_CLASS(802154_le16_template,
        TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
                 __le16 le16arg),
index ab12fa296eb344fd998a9125794140d5ff6cc7a7..317c4662e544679ab37dcc8cfa92fc8108c4820b 100644 (file)
@@ -105,6 +105,24 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy,
        return ret;
 }
 
+static int
+ieee802154_set_cca_ed_level(struct wpan_phy *wpan_phy, s32 ed_level)
+{
+       struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+       int ret;
+
+       ASSERT_RTNL();
+
+       if (wpan_phy->cca_ed_level == ed_level)
+               return 0;
+
+       ret = drv_set_cca_ed_level(local, ed_level);
+       if (!ret)
+               wpan_phy->cca_ed_level = ed_level;
+
+       return ret;
+}
+
 static int
 ieee802154_set_tx_power(struct wpan_phy *wpan_phy, s32 power)
 {
@@ -213,6 +231,7 @@ const struct cfg802154_ops mac802154_config_ops = {
        .del_virtual_intf = ieee802154_del_iface,
        .set_channel = ieee802154_set_channel,
        .set_cca_mode = ieee802154_set_cca_mode,
+       .set_cca_ed_level = ieee802154_set_cca_ed_level,
        .set_tx_power = ieee802154_set_tx_power,
        .set_pan_id = ieee802154_set_pan_id,
        .set_short_addr = ieee802154_set_short_addr,