diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2010-03-18 19:26:23 +0300 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2011-06-30 16:18:09 +0400 |
commit | 060e41794e3f09f0b28f79b8d6c7ac1a9641d672 (patch) | |
tree | 20aeda68993b5ee07459e339222c7d3b8f88d88b /net | |
parent | 6e10c469f0997a5ebaffa955d8716c59ba102a1f (diff) | |
download | linux-3.10-060e41794e3f09f0b28f79b8d6c7ac1a9641d672.tar.gz linux-3.10-060e41794e3f09f0b28f79b8d6c7ac1a9641d672.tar.bz2 linux-3.10-060e41794e3f09f0b28f79b8d6c7ac1a9641d672.zip |
ieee802154: support specifying hw address for created devices
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/ieee802154/nl-phy.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c index 02548b292b5..c64a38d57aa 100644 --- a/net/ieee802154/nl-phy.c +++ b/net/ieee802154/nl-phy.c @@ -24,6 +24,7 @@ #include <linux/kernel.h> #include <linux/slab.h> +#include <linux/if_arp.h> #include <net/netlink.h> #include <net/genetlink.h> #include <net/wpan-phy.h> @@ -213,12 +214,37 @@ static int ieee802154_add_iface(struct sk_buff *skb, goto nla_put_failure; } + if (info->attrs[IEEE802154_ATTR_HW_ADDR] && + nla_len(info->attrs[IEEE802154_ATTR_HW_ADDR]) != + IEEE802154_ADDR_LEN) { + rc = -EINVAL; + goto nla_put_failure; + } + dev = phy->add_iface(phy, devname); if (IS_ERR(dev)) { rc = PTR_ERR(dev); goto nla_put_failure; } + if (info->attrs[IEEE802154_ATTR_HW_ADDR]) { + struct sockaddr addr; + + addr.sa_family = ARPHRD_IEEE802154; + nla_memcpy(&addr.sa_data, info->attrs[IEEE802154_ATTR_HW_ADDR], + IEEE802154_ADDR_LEN); + + /* + * strangely enough, some callbacks (inetdev_event) from + * dev_set_mac_address require RTNL_LOCK + */ + rtnl_lock(); + rc = dev_set_mac_address(dev, &addr); + rtnl_unlock(); + if (rc) + goto dev_unregister; + } + NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); @@ -228,6 +254,11 @@ static int ieee802154_add_iface(struct sk_buff *skb, return ieee802154_nl_reply(msg, info); +dev_unregister: + rtnl_lock(); /* del_iface must be called with RTNL lock */ + phy->del_iface(phy, dev); + dev_put(dev); + rtnl_unlock(); nla_put_failure: nlmsg_free(msg); out_dev: |