ieee802154: introduce wpan_phy_supported
[cascardo/linux.git] / net / ieee802154 / nl802154.c
index a4daf91..d271879 100644 (file)
@@ -207,7 +207,7 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
        [NL802154_ATTR_PAGE] = { .type = NLA_U8, },
        [NL802154_ATTR_CHANNEL] = { .type = NLA_U8, },
 
-       [NL802154_ATTR_TX_POWER] = { .type = NLA_S8, },
+       [NL802154_ATTR_TX_POWER] = { .type = NLA_S32, },
 
        [NL802154_ATTR_CCA_MODE] = { .type = NLA_U32, },
        [NL802154_ATTR_CCA_OPT] = { .type = NLA_U32, },
@@ -248,7 +248,7 @@ nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
 
        for (page = 0; page <= IEEE802154_MAX_PAGE; page++) {
                if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
-                               rdev->wpan_phy.channels_supported[page]))
+                               rdev->wpan_phy.supported.channels[page]))
                        return -ENOBUFS;
        }
        nla_nest_end(msg, nl_page);
@@ -301,8 +301,8 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
                        goto nla_put_failure;
        }
 
-       if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
-                      rdev->wpan_phy.transmit_power))
+       if (nla_put_s32(msg, NL802154_ATTR_TX_POWER,
+                       rdev->wpan_phy.transmit_power))
                goto nla_put_failure;
 
 finish:
@@ -589,7 +589,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
 
        return rdev_add_virtual_intf(rdev,
                                     nla_data(info->attrs[NL802154_ATTR_IFNAME]),
-                                    type, extended_addr);
+                                    NET_NAME_USER, type, extended_addr);
 }
 
 static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info)
@@ -625,7 +625,8 @@ static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
        channel = nla_get_u8(info->attrs[NL802154_ATTR_CHANNEL]);
 
        /* check 802.15.4 constraints */
-       if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL)
+       if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL ||
+           !(rdev->wpan_phy.supported.channels[page] & BIT(channel)))
                return -EINVAL;
 
        return rdev_set_channel(rdev, page, channel);
@@ -668,14 +669,22 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
                return -EBUSY;
 
        /* don't change address fields on monitor */
-       if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR)
-               return -EINVAL;
-
-       if (!info->attrs[NL802154_ATTR_PAN_ID])
+       if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
+           !info->attrs[NL802154_ATTR_PAN_ID])
                return -EINVAL;
 
        pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]);
 
+       /* TODO
+        * I am not sure about to check here on broadcast pan_id.
+        * Broadcast is a valid setting, comment from 802.15.4:
+        * If this value is 0xffff, the device is not associated.
+        *
+        * This could useful to simple deassociate an device.
+        */
+       if (pan_id == cpu_to_le16(IEEE802154_PAN_ID_BROADCAST))
+               return -EINVAL;
+
        return rdev_set_pan_id(rdev, wpan_dev, pan_id);
 }
 
@@ -691,14 +700,27 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
                return -EBUSY;
 
        /* don't change address fields on monitor */
-       if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR)
-               return -EINVAL;
-
-       if (!info->attrs[NL802154_ATTR_SHORT_ADDR])
+       if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
+           !info->attrs[NL802154_ATTR_SHORT_ADDR])
                return -EINVAL;
 
        short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
 
+       /* TODO
+        * I am not sure about to check here on broadcast short_addr.
+        * Broadcast is a valid setting, comment from 802.15.4:
+        * A value of 0xfffe indicates that the device has
+        * associated but has not been allocated an address. A
+        * value of 0xffff indicates that the device does not
+        * have a short address.
+        *
+        * I think we should allow to set these settings but
+        * don't allow to allow socket communication with it.
+        */
+       if (short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC) ||
+           short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST))
+               return -EINVAL;
+
        return rdev_set_short_addr(rdev, wpan_dev, short_addr);
 }