ieee802154: introduce nl802154 framework
Subsystems (2)
Alexander Aring
maintainercover ieee802154: introduce nl802154 framework
This patch series introduce the nl802154 framework. Code was mostly grabbed from wireless nl80211 implementation. Furthermore we should add some net namespace handling like wireless. I added some TODO comment for the things which we doesn't handled right now like wireless nl80211. Also add some cleanups and fixes for the deprecated netlink interface.
Alexander Aring (15):
mac802154: move mac pib attributes into wpan_dev
mac802154: remove mac_params in sdata
ieee802154: rename wpan_phy_alloc
ieee802154: add cfg802154_registered_device list
ieee802154: add iftype to wpan_dev
ieee802154: add wpan_dev_list
ieee802154: sysfs add wpan_phy index and name
ieee802154: add new nl802154 header
ieee802154: add nl802154 framework
ieee802154: add wpan_phy dump support
ieee802154: add wpan_dev dump support
mac820154: don't set monitor dev_addr
ieee802154: netlink add rtnl lock
ieee802154: fix iface dump with lowpan
mac802154: protect address changes via ioctl
MAINTAINERS | 1 + include/net/cfg802154.h | 33 ++- include/net/nl802154.h | 122 ++++++++ net/ieee802154/Makefile | 2 +- net/ieee802154/core.c | 166 ++++++++++- net/ieee802154/core.h | 17 ++ net/ieee802154/ieee802154.h | 2 +- net/ieee802154/netlink.c | 2 +- net/ieee802154/nl-mac.c | 23 +- net/ieee802154/nl802154.c | 675 +++++++++++++++++++++++++++++++++++++++++++ net/ieee802154/nl802154.h | 7 + net/ieee802154/sysfs.c | 24 ++ net/mac802154/ieee802154_i.h | 12 - net/mac802154/iface.c | 84 +++--- net/mac802154/mac_cmd.c | 36 ++- net/mac802154/main.c | 2 +- net/mac802154/mib.c | 10 +- net/mac802154/rx.c | 7 +- 18 files changed, 1148 insertions(+), 77 deletions(-) create mode 100644 include/net/nl802154.h create mode 100644 net/ieee802154/nl802154.c create mode 100644 net/ieee802154/nl802154.h
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 1/15 mac802154: move mac pib attributes into wpan_dev
This patch moves all mac pib attributes into the wpan_dev struct. Furthermore we can easier access these attributes over the netdev 802154_ptr pointer. Currently this is only possible over a complicated callback structure in mac802154 because subif data structure is accessable inside mac802154 only.
--- include/net/cfg802154.h | 24 +++++++++++++++---- net/mac802154/ieee802154_i.h | 10 -------- net/mac802154/iface.c | 55 +++++++++++++++++++++++++------------------- net/mac802154/mib.c | 10 ++++---- net/mac802154/rx.c | 7 +++--- 5 files changed, 59 insertions(+), 47 deletions(-)
include/net/cfg802154.h +19 -5
@@ -52,14 +52,9 @@ struct wpan_phy {u32 channels_supported[32 ];s8 transmit_power;u8 cca_mode; -u8 min_be; -u8 max_be; -u8 csma_retries; -s8 frame_retries;__le64 perm_extended_addr; -bool lbt;s32 cca_ed_level;struct device dev;
@@ -69,6 +64,25 @@ struct wpan_phy {struct wpan_dev {struct wpan_phy *wpan_phy; + +/* MAC PIB */ +__le16 pan_id; +__le16 short_addr; +__le64 extended_addr; + +/* MAC BSN field */ +u8 bsn; +/* MAC DSN field */ +u8 dsn; + +u8 min_be; +u8 max_be; +u8 csma_retries; +s8 frame_retries; + +bool lbt; + +bool promiscuous_mode; };#define to_phy (_dev) container_of(_dev, struct wpan_phy, dev)
net/mac802154/ieee802154_i.h +0 -10
@@ -84,18 +84,8 @@ struct ieee802154_sub_if_data {spinlock_t mib_lock; -__le16 pan_id; -__le16 short_addr; -__le64 extended_addr; -bool promiscuous_mode; -struct ieee802154_mac_params mac_params; -/* MAC BSN field */ -u8 bsn; -/* MAC DSN field */ -u8 dsn; -/* protects sec from concurrent access by netlink. access by * encrypt/decrypt/header_create safe without additional protection. */
net/mac802154/iface.c +31 -24
160 lines not on this page · raw message
net/mac802154/mib.c +5 -5
@@ -33,7 +33,7 @@ void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)BUG_ON (dev->type !=ARPHRD_IEEE802154 );spin_lock_bh (&sdata->mib_lock); - sdata->short_addr = val; + sdata->wpan_dev.short_addr = val;spin_unlock_bh (&sdata->mib_lock); }
@@ -45,7 +45,7 @@ __le16 mac802154_dev_get_short_addr(const struct net_device *dev)BUG_ON (dev->type !=ARPHRD_IEEE802154 );spin_lock_bh (&sdata->mib_lock); - ret = sdata->short_addr; + ret = sdata->wpan_dev.short_addr;spin_unlock_bh (&sdata->mib_lock);return ret;
@@ -59,7 +59,7 @@ __le16 mac802154_dev_get_pan_id(const struct net_device *dev)BUG_ON (dev->type !=ARPHRD_IEEE802154 );spin_lock_bh (&sdata->mib_lock); - ret = sdata->pan_id; + ret = sdata->wpan_dev.pan_id;spin_unlock_bh (&sdata->mib_lock);return ret;
@@ -72,7 +72,7 @@ void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)BUG_ON (dev->type !=ARPHRD_IEEE802154 );spin_lock_bh (&sdata->mib_lock); - sdata->pan_id = val; + sdata->wpan_dev.pan_id = val;spin_unlock_bh (&sdata->mib_lock); }
@@ -82,7 +82,7 @@ u8 mac802154_dev_get_dsn(const struct net_device *dev)BUG_ON (dev->type !=ARPHRD_IEEE802154 ); -return sdata->dsn++; +return sdata->wpan_dev.dsn++; }void mac802154_dev_set_page_channel (struct net_device *dev,u8 page,u8 chan)
net/mac802154/rx.c +4 -3
@@ -42,6 +42,7 @@ static int ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata, struct sk_buff *skb, const struct ieee802154_hdr *hdr) { + struct wpan_dev *wpan_dev = &sdata->wpan_dev;__le16 span, sshort;int rc;
@@ -49,8 +50,8 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,spin_lock_bh (&sdata->mib_lock); - span = sdata->pan_id; - sshort = sdata->short_addr; + span = wpan_dev->pan_id; + sshort = wpan_dev->short_addr;switch (mac_cb (skb)->dest.mode) {case IEEE802154_ADDR_NONE :
@@ -65,7 +66,7 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,if (mac_cb (skb)->dest.pan_id != span &&mac_cb (skb)->dest.pan_id !=cpu_to_le16 (IEEE802154_PANID_BROADCAST )) skb->pkt_type =PACKET_OTHERHOST ; -else if (mac_cb (skb)->dest.extended_addr == sdata->extended_addr) +else if (mac_cb (skb)->dest.extended_addr == wpan_dev->extended_addr) skb->pkt_type =PACKET_HOST ;else skb->pkt_type =PACKET_OTHERHOST ;
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 2/15 mac802154: remove mac_params in sdata
In reply to Alexander AringThis patch removes the mac_params from subif data struct. Instead we manipulate the wpan attributes directly.
--- net/mac802154/ieee802154_i.h | 2 -- net/mac802154/iface.c | 19 +++++++++---------- net/mac802154/mac_cmd.c | 26 ++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 14 deletions(-)
net/mac802154/ieee802154_i.h +0 -2
@@ -84,8 +84,6 @@ struct ieee802154_sub_if_data {spinlock_t mib_lock; -struct ieee802154_mac_params mac_params; -/* protects sec from concurrent access by netlink. access by * encrypt/decrypt/header_create safe without additional protection. */
net/mac802154/iface.c +9 -10
@@ -205,22 +205,21 @@ static int mac802154_wpan_open(struct net_device *dev) }if (local->hw.flags &IEEE802154_HW_LBT ) { - rc =drv_set_lbt_mode (local, sdata->mac_params.lbt); + rc =drv_set_lbt_mode (local, wpan_dev->lbt);if (rc <0 ) goto out; }if (local->hw.flags &IEEE802154_HW_CSMA_PARAMS ) { - rc =drv_set_csma_params (local, sdata->mac_params.min_be, - sdata->mac_params.max_be, - sdata->mac_params.csma_retries); + rc =drv_set_csma_params (local, wpan_dev->min_be, + wpan_dev->max_be, + wpan_dev->csma_retries);if (rc <0 ) goto out; }if (local->hw.flags &IEEE802154_HW_FRAME_RETRIES ) { - rc =drv_set_max_frame_retries (local, - sdata->mac_params.frame_retries); + rc =drv_set_max_frame_retries (local, wpan_dev->frame_retries);if (rc <0 ) goto out; }
@@ -410,11 +409,11 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)get_random_bytes (&wpan_dev->dsn,1 );/* defaults per 802.15.4-2011 */ - sdata->mac_params.min_be =3 ; - sdata->mac_params.max_be =5 ; - sdata->mac_params.csma_retries =4 ; + wpan_dev->min_be =3 ; + wpan_dev->max_be =5 ; + wpan_dev->csma_retries =4 ;/* for compatibility, actual default is 3 */ - sdata->mac_params.frame_retries =-1 ; + wpan_dev->frame_retries =-1 ;ieee802154_be64_to_le64 (&wpan_dev->extended_addr, sdata->dev->dev_addr); wpan_dev->pan_id =cpu_to_le16 (IEEE802154_PANID_BROADCAST );
net/mac802154/mac_cmd.c +24 -2
@@ -72,10 +72,21 @@ static int mac802154_set_mac_params(struct net_device *dev, {struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev);struct ieee802154_local *local = sdata->local; +struct wpan_dev *wpan_dev = &sdata->wpan_dev;int ret;mutex_lock (&sdata->local->iflist_mtx); - sdata->mac_params = *params; +/* PHY */ + wpan_dev->wpan_phy->transmit_power = params->transmit_power; + wpan_dev->wpan_phy->cca_mode = params->cca_mode; + wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level; + +/* MAC */ + wpan_dev->min_be = params->min_be; + wpan_dev->max_be = params->max_be; + wpan_dev->csma_retries = params->csma_retries; + wpan_dev->frame_retries = params->frame_retries; + wpan_dev->lbt = params->lbt;mutex_unlock (&sdata->local->iflist_mtx);if (local->hw.flags &IEEE802154_HW_TXPOWER ) {
@@ -103,9 +114,20 @@ static void mac802154_get_mac_params(struct net_device *dev, struct ieee802154_mac_params *params) {struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev); +struct wpan_dev *wpan_dev = &sdata->wpan_dev;mutex_lock (&sdata->local->iflist_mtx); - *params = sdata->mac_params; +/* PHY */ + params->transmit_power = wpan_dev->wpan_phy->transmit_power; + params->cca_mode = wpan_dev->wpan_phy->cca_mode; + params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level; + +/* MAC */ + params->min_be = wpan_dev->min_be; + params->max_be = wpan_dev->max_be; + params->csma_retries = wpan_dev->csma_retries; + params->frame_retries = wpan_dev->frame_retries; + params->lbt = wpan_dev->lbt;mutex_unlock (&sdata->local->iflist_mtx); }
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 3/15 ieee802154: rename wpan_phy_alloc
In reply to Alexander AringThis patch renames the wpan_phy_alloc function to wpan_phy_new. This naming convention is like wireless and "wiphy_new" function.
--- include/net/cfg802154.h | 2 +- net/ieee802154/core.c | 4 ++-- net/mac802154/main.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/net/cfg802154.h +1 -1
@@ -88,7 +88,7 @@ struct wpan_dev {#define to_phy (_dev) container_of(_dev, struct wpan_phy, dev)struct wpan_phy * -wpan_phy_alloc (const struct cfg802154_ops *ops,size_t priv_size); +wpan_phy_new (const struct cfg802154_ops *ops,size_t priv_size);static inline void wpan_phy_set_dev (struct wpan_phy *phy,struct device *dev) { phy->dev.parent = dev;
net/ieee802154/core.c +2 -2
@@ -70,7 +70,7 @@ int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),EXPORT_SYMBOL (wpan_phy_for_each);struct wpan_phy * -wpan_phy_alloc (const struct cfg802154_ops *ops,size_t priv_size) +wpan_phy_new (const struct cfg802154_ops *ops,size_t priv_size) {static atomic_t wpan_phy_counter =ATOMIC_INIT (0 );struct cfg802154_registered_device *rdev;
@@ -105,7 +105,7 @@ wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size)return &rdev->wpan_phy; } -EXPORT_SYMBOL (wpan_phy_alloc); +EXPORT_SYMBOL (wpan_phy_new);int wpan_phy_register (struct wpan_phy *phy) {
net/mac802154/main.c +1 -1
@@ -86,7 +86,7 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops) priv_size =ALIGN (sizeof (*local),NETDEV_ALIGN ) + priv_data_len; - phy =wpan_phy_alloc (&mac802154_config_ops, priv_size); + phy =wpan_phy_new (&mac802154_config_ops, priv_size);if (!phy) {pr_err ("failure to allocate master IEEE802.15.4 device\n" );return NULL ;
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 4/15 ieee802154: add cfg802154_registered_device list
In reply to Alexander AringThis patch adds a new cfg802154_rdev_list to remember all registered cfg802154_registered_device structs. This is needed to prepare the upcomming nl802154 framework.
--- net/ieee802154/core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- net/ieee802154/core.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-)
net/ieee802154/core.c +44 -1
@@ -18,11 +18,16 @@#include <linux/device.h> #include <net/cfg802154.h> +#include <net/rtnetlink.h> #include "ieee802154.h" #include "sysfs.h" #include "core.h" +/* RCU-protected (and RTNL for writers) */ +static LIST_HEAD (cfg802154_rdev_list); +static int cfg802154_rdev_list_generation; +static int wpan_phy_match (struct device *dev,const void *data) {return !strcmp (dev_name (dev), (const char *)data);
@@ -109,13 +114,51 @@ EXPORT_SYMBOL(wpan_phy_new);int wpan_phy_register (struct wpan_phy *phy) { -return device_add (&phy->dev); +struct cfg802154_registered_device *rdev =wpan_phy_to_rdev (phy); +int ret; + +rtnl_lock (); + ret =device_add (&phy->dev); +if (ret) { +rtnl_unlock (); +return ret; + } + +list_add_rcu (&rdev->list, &cfg802154_rdev_list); + cfg802154_rdev_list_generation++; + +/* TODO phy registered lock */ +rtnl_unlock (); + +/* TODO nl802154 phy notify */ + +return 0 ; }EXPORT_SYMBOL (wpan_phy_register);void wpan_phy_unregister (struct wpan_phy *phy) { +struct cfg802154_registered_device *rdev =wpan_phy_to_rdev (phy); + +/* TODO open count */ + +rtnl_lock (); +/* TODO nl802154 phy notify */ +/* TODO phy registered lock */ + +/* TODO WARN_ON wpan_dev_list */ + +/* First remove the hardware from everywhere, this makes +* it impossible to find from userspace. +*/ +list_del_rcu (&rdev->list); +synchronize_rcu (); + + cfg802154_rdev_list_generation++; +device_del (&phy->dev); + +rtnl_unlock (); }EXPORT_SYMBOL (wpan_phy_unregister);
net/ieee802154/core.h +1 -0
@@ -5,6 +5,7 @@struct cfg802154_registered_device {const struct cfg802154_ops *ops; +struct list_head list;/* wpan_phy index, internal only */ int wpan_phy_idx;
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 5/15 ieee802154: add iftype to wpan_dev
In reply to Alexander AringThis patch adds an iftype argument to the wpan_dev. This is needed to get the interface type from netdev ieee802154_ptr. The subif data struct can only accessible in mac802154 branch.
--- include/net/cfg802154.h | 1 + net/mac802154/iface.c | 1 + 2 files changed, 2 insertions(+)
include/net/cfg802154.h +1 -0
@@ -64,6 +64,7 @@ struct wpan_phy {struct wpan_dev {struct wpan_phy *wpan_phy; +int iftype;/* MAC PIB */ __le16 pan_id;
net/mac802154/iface.c +1 -0
@@ -404,6 +404,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)/* set some type-dependent values */ sdata->vif.type = type; + sdata->wpan_dev.iftype = type;get_random_bytes (&wpan_dev->bsn,1 );get_random_bytes (&wpan_dev->dsn,1 );
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 6/15 ieee802154: add wpan_dev_list
In reply to Alexander AringThis patch adds a wpan_dev_list list into cfg802154_registered_device struct. Also adding new wpan_dev into this list while cfg802154_netdev_notifier_call. This behaviour is mostly grab from wireless core.c implementation and is needed for preparing nl802154 framework.
--- include/net/cfg802154.h | 6 ++++ net/ieee802154/core.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++-- net/ieee802154/core.h | 11 ++++++ 3 files changed, 109 insertions(+), 3 deletions(-)
include/net/cfg802154.h +6 -0
@@ -66,6 +66,12 @@ struct wpan_dev {struct wpan_phy *wpan_phy;int iftype; +/* the remainder of this struct should be private to cfg802154 */ +struct list_head list; +struct net_device *netdev; + +u32 identifier; +/* MAC PIB */ __le16 pan_id;__le16 short_addr;
net/ieee802154/core.c +92 -3
140 lines not on this page · raw message
net/ieee802154/core.h +11 -0
@@ -10,6 +10,17 @@ struct cfg802154_registered_device {/* wpan_phy index, internal only */ int wpan_phy_idx; +/* also protected by devlist_mtx */ +int opencount; +wait_queue_head_t dev_wait; + +/* protected by RTNL only */ +int num_running_ifaces; + +/* associated wpan interfaces, protected by rtnl or RCU */ +struct list_head wpan_dev_list; +int devlist_generation, wpan_dev_id; +/* must be last because of the way we do wpan_phy_priv(), * and it should at least be aligned to NETDEV_ALIGN */
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 7/15 ieee802154: sysfs add wpan_phy index and name
In reply to Alexander AringThis patch adds new sysfs entries for wpan_phy index and name. This needed for the new 802.15.4 userspace tool.
--- net/ieee802154/sysfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
net/ieee802154/sysfs.c +24 -0
@@ -27,6 +27,27 @@ dev_to_rdev(struct device *dev) wpan_phy.dev); } +#define SHOW_FMT (name, fmt, member) \ +static ssize_t name ## _show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \ +} \ +static DEVICE_ATTR_RO(name) + +SHOW_FMT (index,"%d" , wpan_phy_idx); + +static ssize_t name_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct wpan_phy *wpan_phy = &dev_to_rdev (dev)->wpan_phy; + +return sprintf (buf,"%s\n" ,dev_name (&wpan_phy->dev)); +} +static DEVICE_ATTR_RO (name); + #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ static ssize_t name ## _show(struct device *dev, \ struct device_attribute *attr, char *buf) \
@@ -78,6 +99,9 @@ static void wpan_phy_release(struct device *dev) }static struct attribute *pmib_attrs[] = { + &dev_attr_index.attr, + &dev_attr_name.attr, +/* below will be removed soon */ &dev_attr_current_channel.attr, &dev_attr_current_page.attr, &dev_attr_channels_supported.attr,
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 8/15 ieee802154: add new nl802154 header
In reply to Alexander AringThis patch adds the new userspace header for nl802154. We don't place this header in include/uapi now. This header could be modified in the next time.
--- MAINTAINERS | 1 + include/net/nl802154.h | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 include/net/nl802154.h
MAINTAINERS +1 -0
@@ -4699,6 +4699,7 @@ F: net/mac802154/ F: drivers/net/ieee802154/ F: include/linux/nl802154.h F: include/linux/ieee802154.h +F: include/net/nl802154.h F: include/net/mac802154.h F: include/net/af_ieee802154.h F: include/net/cfg802154.h
include/net/nl802154.h new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 9/15 ieee802154: add nl802154 framework
In reply to Alexander AringThis patch adds a basic nl802154 framework. Most of this code was grabbed from nl80211 framework.
--- net/ieee802154/Makefile | 2 +- net/ieee802154/core.c | 28 +++- net/ieee802154/core.h | 4 + net/ieee802154/ieee802154.h | 2 +- net/ieee802154/netlink.c | 2 +- net/ieee802154/nl802154.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ net/ieee802154/nl802154.h | 7 + 7 files changed, 350 insertions(+), 4 deletions(-) create mode 100644 net/ieee802154/nl802154.c create mode 100644 net/ieee802154/nl802154.h
net/ieee802154/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \ - header_ops.o sysfs.o + header_ops.o sysfs.o nl802154.o af_802154-y := af_ieee802154.o raw.o dgram.o ccflags-y += -D__CHECK_ENDIAN__
net/ieee802154/core.c +27 -1
@@ -21,11 +21,12 @@#include <net/rtnetlink.h> #include "ieee802154.h" +#include "nl802154.h" #include "sysfs.h" #include "core.h" /* RCU-protected (and RTNL for writers) */ -static LIST_HEAD (cfg802154_rdev_list); +LIST_HEAD (cfg802154_rdev_list);static int cfg802154_rdev_list_generation;static int wpan_phy_match (struct device *dev,const void *data)
@@ -74,6 +75,23 @@ int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), }EXPORT_SYMBOL (wpan_phy_for_each); +struct cfg802154_registered_device * +cfg802154_rdev_by_wpan_phy_idx (int wpan_phy_idx) +{ +struct cfg802154_registered_device *result =NULL , *rdev; + +ASSERT_RTNL (); + +list_for_each_entry (rdev, &cfg802154_rdev_list, list) { +if (rdev->wpan_phy_idx == wpan_phy_idx) { + result = rdev; +break ; + } + } + +return result; +} +struct wpan_phy *wpan_phy_new (const struct cfg802154_ops *ops,size_t priv_size) {
@@ -270,8 +288,15 @@ static int __init wpan_phy_class_init(void)if (rc) goto err_notifier; + rc =nl802154_init (); +if (rc) + goto err_ieee802154_nl; +return 0 ; +err_ieee802154_nl: +ieee802154_nl_exit (); + err_notifier:unregister_netdevice_notifier (&cfg802154_netdev_notifier); err_nl:
@@ -283,6 +308,7 @@ subsys_initcall(wpan_phy_class_init); static void __exit wpan_phy_class_exit(void) { +nl802154_exit ();ieee802154_nl_exit ();unregister_netdevice_notifier (&cfg802154_netdev_notifier);wpan_phy_sysfs_exit ();
net/ieee802154/core.h +4 -0
@@ -35,7 +35,11 @@ wpan_phy_to_rdev(struct wpan_phy *wpan_phy) wpan_phy); } +extern struct list_head cfg802154_rdev_list; +/* free object */ void cfg802154_dev_free (struct cfg802154_registered_device *rdev); +struct cfg802154_registered_device * +cfg802154_rdev_by_wpan_phy_idx (int wpan_phy_idx);#endif /* __IEEE802154_CORE_H */
net/ieee802154/ieee802154.h +1 -1
@@ -15,7 +15,7 @@#define IEEE_802154_LOCAL_H int __init ieee802154_nl_init (void ); -void __exit ieee802154_nl_exit(void); +void ieee802154_nl_exit (void );#define IEEE802154_OP (_cmd, _func) \ { \
net/ieee802154/netlink.c +1 -1
@@ -155,7 +155,7 @@ int __init ieee802154_nl_init(void) ieee802154_mcgrps); } -void __exit ieee802154_nl_exit(void) +void ieee802154_nl_exit (void ) {genl_unregister_family (&nl802154_family); }
net/ieee802154/nl802154.c new file +309 -0
309 lines not on this page · raw message
net/ieee802154/nl802154.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __IEEE802154_NL802154_H +#define __IEEE802154_NL802154_H + +int nl802154_init (void ); +void nl802154_exit (void ); + +#endif /* __IEEE802154_NL802154_H */
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 10/15 ieee802154: add wpan_phy dump support
In reply to Alexander AringThis patch adds support for dumping wpan_phy attributes via nl802154.
--- net/ieee802154/core.c | 2 +- net/ieee802154/core.h | 1 + net/ieee802154/nl802154.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+), 1 deletion(-)
net/ieee802154/core.c +1 -1
@@ -27,7 +27,7 @@/* RCU-protected (and RTNL for writers) */ LIST_HEAD (cfg802154_rdev_list); -static int cfg802154_rdev_list_generation; +int cfg802154_rdev_list_generation;static int wpan_phy_match (struct device *dev,const void *data) {
net/ieee802154/core.h +1 -0
@@ -36,6 +36,7 @@ wpan_phy_to_rdev(struct wpan_phy *wpan_phy) }extern struct list_head cfg802154_rdev_list; +extern int cfg802154_rdev_list_generation;/* free object */ void cfg802154_dev_free (struct cfg802154_registered_device *rdev);
net/ieee802154/nl802154.c +221 -0
239 lines not on this page · raw message
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 11/15 ieee802154: add wpan_dev dump support
In reply to Alexander AringThis patch adds support for wpan_dev dump via nl802154 framework.
--- net/ieee802154/nl802154.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+)
net/ieee802154/nl802154.c +145 -0
@@ -198,6 +198,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = { .len = 20-1 }, [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 }, + [NL802154_ATTR_IFTYPE] = { .type = NLA_U32 }, + [NL802154_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 },
@@ -209,6 +211,18 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = { [NL802154_ATTR_CCA_MODE] = { .type = NLA_U8, }, [NL802154_ATTR_SUPPORTED_CHANNEL] = { .type = NLA_U32, }, + + [NL802154_ATTR_PAN_ID] = { .type = NLA_U16, }, + [NL802154_ATTR_EXTENDED_ADDR] = { .type = NLA_U64 }, + [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, }, + + [NL802154_ATTR_MIN_BE] = { .type = NLA_U8, }, + [NL802154_ATTR_MAX_BE] = { .type = NLA_U8, }, + [NL802154_ATTR_MAX_CSMA_BACKOFFS] = { .type = NLA_U8, }, + + [NL802154_ATTR_MAX_FRAME_RETRIES] = { .type = NLA_S8, }, + + [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, }, };/* message building helper */
@@ -414,6 +428,128 @@ static int nl802154_get_wpan_phy(struct sk_buff *skb, struct genl_info *info)return genlmsg_reply (msg, info); } +static inline u64 wpan_dev_id (struct wpan_dev *wpan_dev) +{ +return (u64 )wpan_dev->identifier | + ((u64 )wpan_phy_to_rdev (wpan_dev->wpan_phy)->wpan_phy_idx <<32 ); +} + +static int +nl802154_send_iface (struct sk_buff *msg,u32 portid,u32 seq,int flags, +struct cfg802154_registered_device *rdev, +struct wpan_dev *wpan_dev) +{ +struct net_device *dev = wpan_dev->netdev; +void *hdr; + + hdr =nl802154hdr_put (msg, portid, seq, flags, +NL802154_CMD_NEW_INTERFACE ); +if (!hdr) +return -1 ; + +if (dev && + (nla_put_u32 (msg,NL802154_ATTR_IFINDEX , dev->ifindex) || +nla_put_string (msg,NL802154_ATTR_IFNAME , dev->name))) + goto nla_put_failure; + +if (nla_put_u32 (msg,NL802154_ATTR_WPAN_PHY , rdev->wpan_phy_idx) || +nla_put_u32 (msg,NL802154_ATTR_IFTYPE , wpan_dev->iftype) || +nla_put_u64 (msg,NL802154_ATTR_WPAN_DEV ,wpan_dev_id (wpan_dev)) || +nla_put_u32 (msg,NL802154_ATTR_GENERATION , + rdev->devlist_generation ^ + (cfg802154_rdev_list_generation <<2 ))) + goto nla_put_failure; + +/* address settings */ +if (nla_put_le64 (msg,NL802154_ATTR_EXTENDED_ADDR , + wpan_dev->extended_addr) || +nla_put_le16 (msg,NL802154_ATTR_SHORT_ADDR , + wpan_dev->short_addr) || +nla_put_le16 (msg,NL802154_ATTR_PAN_ID , wpan_dev->pan_id)) + goto nla_put_failure; + +/* ARET handling */ +if (nla_put_s8 (msg,NL802154_ATTR_MAX_FRAME_RETRIES , + wpan_dev->frame_retries) || +nla_put_u8 (msg,NL802154_ATTR_MAX_BE , wpan_dev->max_be) || +nla_put_u8 (msg,NL802154_ATTR_MAX_CSMA_BACKOFFS , + wpan_dev->csma_retries) || +nla_put_u8 (msg,NL802154_ATTR_MIN_BE , wpan_dev->min_be)) + goto nla_put_failure; + +/* listen before transmit */ +if (nla_put_u8 (msg,NL802154_ATTR_LBT_MODE , wpan_dev->lbt)) + goto nla_put_failure; + +return genlmsg_end (msg, hdr); + +nla_put_failure: +genlmsg_cancel (msg, hdr); +return -EMSGSIZE ; +} + +static int +nl802154_dump_interface (struct sk_buff *skb,struct netlink_callback *cb) +{ +int wp_idx =0 ; +int if_idx =0 ; +int wp_start = cb->args[0 ]; +int if_start = cb->args[1 ]; +struct cfg802154_registered_device *rdev; +struct wpan_dev *wpan_dev; + +rtnl_lock (); +list_for_each_entry (rdev, &cfg802154_rdev_list, list) { +/* TODO netns compare */ +if (wp_idx < wp_start) { + wp_idx++; +continue ; + } + if_idx =0 ; + +list_for_each_entry (wpan_dev, &rdev->wpan_dev_list, list) { +if (if_idx < if_start) { + if_idx++; +continue ; + } +if (nl802154_send_iface (skb,NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq,NLM_F_MULTI , + rdev, wpan_dev) <0 ) { + goto out; + } + if_idx++; + } + + wp_idx++; + } +out: +rtnl_unlock (); + + cb->args[0 ] = wp_idx; + cb->args[1 ] = if_idx; + +return skb->len; +} + +static int nl802154_get_interface (struct sk_buff *skb,struct genl_info *info) +{ +struct sk_buff *msg; +struct cfg802154_registered_device *rdev = info->user_ptr[0 ]; +struct wpan_dev *wdev = info->user_ptr[1 ]; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + +if (nl802154_send_iface (msg, info->snd_portid, info->snd_seq,0 , + rdev, wdev) <0 ) { +nlmsg_free (msg); +return -ENOBUFS ; + } + +return genlmsg_reply (msg, info); +} +#define NL802154_FLAG_NEED_WPAN_PHY 0x01#define NL802154_FLAG_NEED_NETDEV 0x02#define NL802154_FLAG_NEED_RTNL 0x04
@@ -515,6 +651,15 @@ static const struct genl_ops nl802154_ops[] = { .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | NL802154_FLAG_NEED_RTNL, }, + { + .cmd = NL802154_CMD_GET_INTERFACE, + .doit = nl802154_get_interface, + .dumpit = nl802154_dump_interface, + .policy = nl802154_policy, + /* can be retrieved by unprivileged users */ + .internal_flags = NL802154_FLAG_NEED_WPAN_DEV | + NL802154_FLAG_NEED_RTNL, + }, };/* initialisation/exit functions */
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 12/15 mac820154: don't set monitor dev_addr
In reply to Alexander AringThis patch removes the setting of dev_addr on a monitor device. This address should be zero. A monitor should only sniff and send raw frames out. The address should be never used by upper layers and receiving frame parsing.
--- net/mac802154/iface.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mac802154/iface.c +3 -1
@@ -416,12 +416,14 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)/* for compatibility, actual default is 3 */ wpan_dev->frame_retries =-1 ; -ieee802154_be64_to_le64 (&wpan_dev->extended_addr, sdata->dev->dev_addr); wpan_dev->pan_id =cpu_to_le16 (IEEE802154_PANID_BROADCAST ); wpan_dev->short_addr =cpu_to_le16 (IEEE802154_ADDR_BROADCAST );switch (type) {case IEEE802154_DEV_WPAN : +ieee802154_be64_to_le64 (&wpan_dev->extended_addr, + sdata->dev->dev_addr); + sdata->dev->header_ops = &mac802154_header_ops; sdata->dev->destructor = mac802154_wpan_free; sdata->dev->netdev_ops = &mac802154_wpan_ops;
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 13/15 ieee802154: netlink add rtnl lock
In reply to Alexander AringThis patch adds rtnl lock hold mechanism while accessing wpan_dev attributes. Furthermore these attributes should be protected by rtnl lock and netif_running only.
--- net/ieee802154/nl-mac.c | 6 ++++++ net/mac802154/mac_cmd.c | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)
net/ieee802154/nl-mac.c +6 -0
@@ -113,7 +113,9 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,if (ops->get_mac_params) {struct ieee802154_mac_params params; +rtnl_lock (); ops->get_mac_params (dev, ¶ms); +rtnl_unlock (); if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER, params.transmit_power) ||
@@ -348,8 +350,10 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)return -EINVAL ; } +rtnl_lock (); ret =ieee802154_mlme_ops (dev)->start_req (dev, &addr, channel, page, bcn_ord, sf_ord, pan_coord, blx, coord_realign); +rtnl_unlock ();/* FIXME: add validation for unused parameters to be sane * for SoftMAC
@@ -497,6 +501,7 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info) phy = dev->ieee802154_ptr->wpan_phy;get_device (&phy->dev); +rtnl_lock (); ops->get_mac_params (dev, ¶ms);if (info->attrs[IEEE802154_ATTR_TXPOWER ])
@@ -524,6 +529,7 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info) params.frame_retries =nla_get_s8 (info->attrs[IEEE802154_ATTR_FRAME_RETRIES ]); rc = ops->set_mac_params (dev, ¶ms); +rtnl_unlock ();wpan_phy_put (phy);dev_put (dev);
net/mac802154/mac_cmd.c +6 -4
@@ -39,6 +39,8 @@ static int mac802154_mlme_start_req(struct net_device *dev,struct ieee802154_mlme_ops *ops =ieee802154_mlme_ops (dev);int rc =0 ; +ASSERT_RTNL (); +BUG_ON (addr->mode !=IEEE802154_ADDR_SHORT );mac802154_dev_set_pan_id (dev, addr->pan_id);
@@ -75,7 +77,8 @@ static int mac802154_set_mac_params(struct net_device *dev,struct wpan_dev *wpan_dev = &sdata->wpan_dev;int ret; -mutex_lock (&sdata->local->iflist_mtx); +ASSERT_RTNL (); +/* PHY */ wpan_dev->wpan_phy->transmit_power = params->transmit_power; wpan_dev->wpan_phy->cca_mode = params->cca_mode;
@@ -87,7 +90,6 @@ static int mac802154_set_mac_params(struct net_device *dev, wpan_dev->csma_retries = params->csma_retries; wpan_dev->frame_retries = params->frame_retries; wpan_dev->lbt = params->lbt; -mutex_unlock (&sdata->local->iflist_mtx);if (local->hw.flags &IEEE802154_HW_TXPOWER ) { ret =drv_set_tx_power (local, params->transmit_power);
@@ -116,7 +118,8 @@ static void mac802154_get_mac_params(struct net_device *dev,struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev);struct wpan_dev *wpan_dev = &sdata->wpan_dev; -mutex_lock (&sdata->local->iflist_mtx); +ASSERT_RTNL (); +/* PHY */ params->transmit_power = wpan_dev->wpan_phy->transmit_power; params->cca_mode = wpan_dev->wpan_phy->cca_mode;
@@ -128,7 +131,6 @@ static void mac802154_get_mac_params(struct net_device *dev, params->csma_retries = wpan_dev->csma_retries; params->frame_retries = wpan_dev->frame_retries; params->lbt = wpan_dev->lbt; -mutex_unlock (&sdata->local->iflist_mtx); }static struct ieee802154_llsec_ops mac802154_llsec_ops = {
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 14/15 ieee802154: fix iface dump with lowpan
In reply to Alexander AringThis patch adds a hacked solution for an interface dump with a running lowpan interface. This will crash because lowpan and wpan interface use the same arphdr. To change the arphdr will change the UAPI, this patch checks on mtu which should on lowpan interface always different than IEEE802154_MTU.
--- net/ieee802154/nl-mac.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
net/ieee802154/nl-mac.c +14 -3
@@ -166,7 +166,10 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)if (!dev)return NULL ; -if (dev->type !=ARPHRD_IEEE802154 ) { +/* Check on mtu is currently a hacked solution because lowpan +* and wpan have the same ARPHRD type. +*/ +if (dev->type !=ARPHRD_IEEE802154 || dev->mtu !=IEEE802154_MTU ) {dev_put (dev);return NULL ; }
@@ -448,7 +451,11 @@ int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb) idx =0 ;for_each_netdev (net, dev) { -if (idx < s_idx || (dev->type !=ARPHRD_IEEE802154 )) +/* Check on mtu is currently a hacked solution because lowpan +* and wpan have the same ARPHRD type. +*/ +if (idx < s_idx || dev->type !=ARPHRD_IEEE802154 || + dev->mtu !=IEEE802154_MTU ) goto cont; if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
@@ -782,7 +789,11 @@ ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb,int rc;for_each_netdev (net, dev) { -if (idx < first_dev || dev->type !=ARPHRD_IEEE802154 ) +/* Check on mtu is currently a hacked solution because lowpan +* and wpan have the same ARPHRD type. +*/ +if (idx < first_dev || dev->type !=ARPHRD_IEEE802154 || + dev->mtu !=IEEE802154_MTU ) goto skip; data.ops =ieee802154_mlme_ops (dev);
Signature · 1 line
2.1.3
Alexander Aring
maintainerPATCH 15/15 mac802154: protect address changes via ioctl
In reply to Alexander AringThis patch adds a netif_running check while trying to change the address attributes via ioctl. While netif_running is true these attributes should be only readable.
--- net/mac802154/iface.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/mac802154/iface.c +7 -0
@@ -63,6 +63,8 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) (struct sockaddr_ieee802154 *)&ifr->ifr_addr;int err = -ENOIOCTLCMD ; +ASSERT_RTNL (); +spin_lock_bh (&sdata->mib_lock);switch (cmd) {
@@ -87,6 +89,11 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)break ; }case SIOCSIFADDR : +if (netif_running (dev)) { +spin_unlock_bh (&sdata->mib_lock); +return -EBUSY ; + } +dev_warn (&dev->dev,"Using DEBUGing ioctl SIOCSIFADDR isn't recommended!\n" ); if (sa->family != AF_IEEE802154 ||
Signature · 1 line
2.1.3
Hi Alex,
Quoted 42 lines
This patch series introduce the nl802154 framework. Code was mostly grabbed from wireless nl80211 implementation. Furthermore we should add some net namespace handling like wireless. I added some TODO comment for the things which we doesn't handled right now like wireless nl80211. Also add some cleanups and fixes for the deprecated netlink interface.
Alexander Aring (15):
mac802154: move mac pib attributes intowpan_dev
mac802154: removemac_paramsin sdata
ieee802154: renamewpan_phy_alloc
ieee802154: addcfg802154_registered_devicelist
ieee802154: add iftype towpan_dev
ieee802154: addwpan_dev_list
ieee802154: sysfs addwpan_phyindex and name
ieee802154: add new nl802154 header
ieee802154: add nl802154 framework
ieee802154: addwpan_phydump support
ieee802154: addwpan_devdump support
mac820154: don't set monitordev_addr
ieee802154: netlink add rtnl lock
ieee802154: fix iface dump with lowpan
mac802154: protect address changes via ioctlMAINTAINERS | 1 + include/net/cfg802154.h | 33 ++- include/net/nl802154.h | 122 ++++++++ net/ieee802154/Makefile | 2 +- net/ieee802154/core.c | 166 ++++++++++- net/ieee802154/core.h | 17 ++ net/ieee802154/ieee802154.h | 2 +- net/ieee802154/netlink.c | 2 +- net/ieee802154/nl-mac.c | 23 +- net/ieee802154/nl802154.c | 675 +++++++++++++++++++++++++++++++++++++++++++ net/ieee802154/nl802154.h | 7 + net/ieee802154/sysfs.c | 24 ++ net/mac802154/ieee802154_i.h | 12 - net/mac802154/iface.c | 84 +++--- net/mac802154/mac_cmd.c | 36 ++- net/mac802154/main.c | 2 +- net/mac802154/mib.c | 10 +- net/mac802154/rx.c | 7 +- 18 files changed, 1148 insertions(+), 77 deletions(-)
Quoted 3 lines
create mode 100644
include/net/nl802154.h
create mode 100644net/ieee802154/nl802154.c
create mode 100644net/ieee802154/nl802154.h
all 15 patches have been applied to bluetooth-next tree.
Regards
Marcel