nl802154: export supported commands
authorVarka Bhadram <varkabhadram@gmail.com>
Thu, 4 Jun 2015 07:37:36 +0000 (13:07 +0530)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 4 Jun 2015 10:27:15 +0000 (12:27 +0200)
This patch will export the supported commands by the devices
to the userspace. This will be useful to check if HardMAC
drivers can support a specific command or not.

Signed-off-by: Varka Bhadram <varkab@cdac.in>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/nl802154.h
net/ieee802154/nl802154.c

index 0badebd1de7fbe179542a440f31e9042821a2e3d..6fc231e609207bddd6891d1f0f39201a901a550e 100644 (file)
@@ -102,6 +102,8 @@ enum nl802154_attrs {
 
        NL802154_ATTR_WPAN_PHY_CAPS,
 
+       NL802154_ATTR_SUPPORTED_COMMANDS,
+
        /* add attributes here, update the policy in nl802154.c */
 
        __NL802154_ATTR_AFTER_LAST,
index 7dbb1f4ce7df6bebb28d202f8907e00f71bd497c..68f24016860c30c7800b36d45046cf3e7f23b8c9 100644 (file)
@@ -228,6 +228,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
        [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
 
        [NL802154_ATTR_WPAN_PHY_CAPS] = { .type = NLA_NESTED },
+
+       [NL802154_ATTR_SUPPORTED_COMMANDS] = { .type = NLA_NESTED },
 };
 
 /* message building helper */
@@ -372,7 +374,9 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
                                  struct sk_buff *msg, u32 portid, u32 seq,
                                  int flags)
 {
+       struct nlattr *nl_cmds;
        void *hdr;
+       int i;
 
        hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
        if (!hdr)
@@ -431,6 +435,42 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
        if (nl802154_put_capabilities(msg, rdev))
                goto nla_put_failure;
 
+       nl_cmds = nla_nest_start(msg, NL802154_ATTR_SUPPORTED_COMMANDS);
+       if (!nl_cmds)
+               goto nla_put_failure;
+
+       i = 0;
+#define CMD(op, n)                                                     \
+       do {                                                            \
+               if (rdev->ops->op) {                                    \
+                       i++;                                            \
+                       if (nla_put_u32(msg, i, NL802154_CMD_ ## n))    \
+                               goto nla_put_failure;                   \
+               }                                                       \
+       } while (0)
+
+       CMD(add_virtual_intf, NEW_INTERFACE);
+       CMD(del_virtual_intf, DEL_INTERFACE);
+       CMD(set_channel, SET_CHANNEL);
+       CMD(set_pan_id, SET_PAN_ID);
+       CMD(set_short_addr, SET_SHORT_ADDR);
+       CMD(set_backoff_exponent, SET_BACKOFF_EXPONENT);
+       CMD(set_max_csma_backoffs, SET_MAX_CSMA_BACKOFFS);
+       CMD(set_max_frame_retries, SET_MAX_FRAME_RETRIES);
+       CMD(set_lbt_mode, SET_LBT_MODE);
+
+       if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER)
+               CMD(set_tx_power, SET_TX_POWER);
+
+       if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL)
+               CMD(set_cca_ed_level, SET_CCA_ED_LEVEL);
+
+       if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_MODE)
+               CMD(set_cca_mode, SET_CCA_MODE);
+
+#undef CMD
+       nla_nest_end(msg, nl_cmds);
+
 finish:
        genlmsg_end(msg, hdr);
        return 0;