* [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework
@ 2014-11-09 7:36 Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 01/15] mac802154: move mac pib attributes into wpan_dev Alexander Aring
` (15 more replies)
0 siblings, 16 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
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
--
2.1.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 01/15] mac802154: move mac pib attributes into wpan_dev
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 02/15] mac802154: remove mac_params in sdata Alexander Aring
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
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(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 9d99b96..ac8dd3b 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -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)
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 4acacea..803f529 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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.
*/
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 384f4bb..6669da7 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -35,16 +35,17 @@ static int mac802154_wpan_update_llsec(struct net_device *dev)
{
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
+ struct wpan_dev *wpan_dev = &sdata->wpan_dev;
int rc = 0;
if (ops->llsec) {
struct ieee802154_llsec_params params;
int changed = 0;
- params.pan_id = sdata->pan_id;
+ params.pan_id = wpan_dev->pan_id;
changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
- params.hwaddr = sdata->extended_addr;
+ params.hwaddr = wpan_dev->extended_addr;
changed |= IEEE802154_LLSEC_PARAM_HWADDR;
rc = ops->llsec->set_params(dev, ¶ms, changed);
@@ -57,6 +58,7 @@ static int
mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
+ struct wpan_dev *wpan_dev = &sdata->wpan_dev;
struct sockaddr_ieee802154 *sa =
(struct sockaddr_ieee802154 *)&ifr->ifr_addr;
int err = -ENOIOCTLCMD;
@@ -68,8 +70,8 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
u16 pan_id, short_addr;
- pan_id = le16_to_cpu(sdata->pan_id);
- short_addr = le16_to_cpu(sdata->short_addr);
+ pan_id = le16_to_cpu(wpan_dev->pan_id);
+ short_addr = le16_to_cpu(wpan_dev->short_addr);
if (pan_id == IEEE802154_PANID_BROADCAST ||
short_addr == IEEE802154_ADDR_BROADCAST) {
err = -EADDRNOTAVAIL;
@@ -96,8 +98,8 @@ mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
break;
}
- sdata->pan_id = cpu_to_le16(sa->addr.pan_id);
- sdata->short_addr = cpu_to_le16(sa->addr.short_addr);
+ wpan_dev->pan_id = cpu_to_le16(sa->addr.pan_id);
+ wpan_dev->short_addr = cpu_to_le16(sa->addr.short_addr);
err = mac802154_wpan_update_llsec(dev);
break;
@@ -121,7 +123,7 @@ static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
return -EINVAL;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
- sdata->extended_addr = extended_addr;
+ sdata->wpan_dev.extended_addr = extended_addr;
return mac802154_wpan_update_llsec(dev);
}
@@ -172,6 +174,7 @@ static int mac802154_wpan_open(struct net_device *dev)
int rc;
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;
struct wpan_phy *phy = sdata->local->phy;
rc = mac802154_slave_open(dev);
@@ -181,21 +184,22 @@ static int mac802154_wpan_open(struct net_device *dev)
mutex_lock(&phy->pib_lock);
if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
- rc = drv_set_promiscuous_mode(local, sdata->promiscuous_mode);
+ rc = drv_set_promiscuous_mode(local,
+ wpan_dev->promiscuous_mode);
if (rc < 0)
goto out;
}
if (local->hw.flags & IEEE802154_HW_AFILT) {
- rc = drv_set_pan_id(local, sdata->pan_id);
+ rc = drv_set_pan_id(local, wpan_dev->pan_id);
if (rc < 0)
goto out;
- rc = drv_set_extended_addr(local, sdata->extended_addr);
+ rc = drv_set_extended_addr(local, wpan_dev->extended_addr);
if (rc < 0)
goto out;
- rc = drv_set_short_addr(local, sdata->short_addr);
+ rc = drv_set_short_addr(local, wpan_dev->short_addr);
if (rc < 0)
goto out;
}
@@ -288,6 +292,7 @@ static int mac802154_header_create(struct sk_buff *skb,
{
struct ieee802154_hdr hdr;
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
+ struct wpan_dev *wpan_dev = &sdata->wpan_dev;
struct ieee802154_mac_cb *cb = mac_cb(skb);
int hlen;
@@ -306,17 +311,17 @@ static int mac802154_header_create(struct sk_buff *skb,
if (!saddr) {
spin_lock_bh(&sdata->mib_lock);
- if (sdata->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
- sdata->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
- sdata->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
+ if (wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
+ wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
+ wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
hdr.source.mode = IEEE802154_ADDR_LONG;
- hdr.source.extended_addr = sdata->extended_addr;
+ hdr.source.extended_addr = wpan_dev->extended_addr;
} else {
hdr.source.mode = IEEE802154_ADDR_SHORT;
- hdr.source.short_addr = sdata->short_addr;
+ hdr.source.short_addr = wpan_dev->short_addr;
}
- hdr.source.pan_id = sdata->pan_id;
+ hdr.source.pan_id = wpan_dev->pan_id;
spin_unlock_bh(&sdata->mib_lock);
} else {
@@ -396,11 +401,13 @@ static void ieee802154_if_setup(struct net_device *dev)
static int
ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
{
+ struct wpan_dev *wpan_dev = &sdata->wpan_dev;
+
/* set some type-dependent values */
sdata->vif.type = type;
- get_random_bytes(&sdata->bsn, 1);
- get_random_bytes(&sdata->dsn, 1);
+ get_random_bytes(&wpan_dev->bsn, 1);
+ get_random_bytes(&wpan_dev->dsn, 1);
/* defaults per 802.15.4-2011 */
sdata->mac_params.min_be = 3;
@@ -409,9 +416,9 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
/* for compatibility, actual default is 3 */
sdata->mac_params.frame_retries = -1;
- ieee802154_be64_to_le64(&sdata->extended_addr, sdata->dev->dev_addr);
- sdata->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
- sdata->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
+ 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:
@@ -419,7 +426,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
sdata->dev->destructor = mac802154_wpan_free;
sdata->dev->netdev_ops = &mac802154_wpan_ops;
sdata->dev->ml_priv = &mac802154_mlme_wpan;
- sdata->promiscuous_mode = false;
+ wpan_dev->promiscuous_mode = false;
spin_lock_init(&sdata->mib_lock);
mutex_init(&sdata->sec_mtx);
@@ -429,7 +436,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
case IEEE802154_DEV_MONITOR:
sdata->dev->destructor = free_netdev;
sdata->dev->netdev_ops = &mac802154_monitor_ops;
- sdata->promiscuous_mode = true;
+ wpan_dev->promiscuous_mode = true;
break;
default:
BUG();
diff --git a/net/mac802154/mib.c b/net/mac802154/mib.c
index 6fa7491..3596b29 100644
--- a/net/mac802154/mib.c
+++ b/net/mac802154/mib.c
@@ -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)
diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c
index 4b54cf3..b18e755 100644
--- a/net/mac802154/rx.c
+++ b/net/mac802154/rx.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 02/15] mac802154: remove mac_params in sdata
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 01/15] mac802154: move mac pib attributes into wpan_dev Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 03/15] ieee802154: rename wpan_phy_alloc Alexander Aring
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch removes the mac_params from subif data struct. Instead we
manipulate the wpan attributes directly.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/mac802154/ieee802154_i.h | 2 --
net/mac802154/iface.c | 19 +++++++++----------
net/mac802154/mac_cmd.c | 26 ++++++++++++++++++++++++--
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 803f529..e22f509 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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.
*/
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 6669da7..c0b96cf5 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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);
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index 00b2b21..b8bd952 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -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);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 03/15] ieee802154: rename wpan_phy_alloc
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 01/15] mac802154: move mac pib attributes into wpan_dev Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 02/15] mac802154: remove mac_params in sdata Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 04/15] ieee802154: add cfg802154_registered_device list Alexander Aring
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch renames the wpan_phy_alloc function to wpan_phy_new. This
naming convention is like wireless and "wiphy_new" function.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 2 +-
net/ieee802154/core.c | 4 ++--
net/mac802154/main.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index ac8dd3b..72c4723 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -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;
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index d1cd0ed..a3aa23f 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -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)
{
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 7d0ff7f..234084d 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 04/15] ieee802154: add cfg802154_registered_device list
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (2 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 03/15] ieee802154: rename wpan_phy_alloc Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 05/15] ieee802154: add iftype to wpan_dev Alexander Aring
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds a new cfg802154_rdev_list to remember all registered
cfg802154_registered_device structs. This is needed to prepare the
upcomming nl802154 framework.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
net/ieee802154/core.h | 1 +
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index a3aa23f..11a1d2e 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -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);
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index fea60b3..38887cb2 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 05/15] ieee802154: add iftype to wpan_dev
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (3 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 04/15] ieee802154: add cfg802154_registered_device list Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 06/15] ieee802154: add wpan_dev_list Alexander Aring
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 1 +
net/mac802154/iface.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 72c4723..7e1bc21 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -64,6 +64,7 @@ struct wpan_phy {
struct wpan_dev {
struct wpan_phy *wpan_phy;
+ int iftype;
/* MAC PIB */
__le16 pan_id;
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index c0b96cf5..4630ceb 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 06/15] ieee802154: add wpan_dev_list
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (4 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 05/15] ieee802154: add iftype to wpan_dev Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 07/15] ieee802154: sysfs add wpan_phy index and name Alexander Aring
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/cfg802154.h | 6 ++++
net/ieee802154/core.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++--
net/ieee802154/core.h | 11 ++++++
3 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 7e1bc21..e5570e0 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -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;
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 11a1d2e..3ee00bf 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -102,12 +102,15 @@ wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
mutex_init(&rdev->wpan_phy.pib_lock);
+ INIT_LIST_HEAD(&rdev->wpan_dev_list);
device_initialize(&rdev->wpan_phy.dev);
dev_set_name(&rdev->wpan_phy.dev, "wpan-phy%d", rdev->wpan_phy_idx);
rdev->wpan_phy.dev.class = &wpan_phy_class;
rdev->wpan_phy.dev.platform_data = rdev;
+ init_waitqueue_head(&rdev->dev_wait);
+
return &rdev->wpan_phy;
}
EXPORT_SYMBOL(wpan_phy_new);
@@ -140,13 +143,18 @@ void wpan_phy_unregister(struct wpan_phy *phy)
{
struct cfg802154_registered_device *rdev = wpan_phy_to_rdev(phy);
- /* TODO open count */
+ wait_event(rdev->dev_wait, ({
+ int __count;
+ rtnl_lock();
+ __count = rdev->opencount;
+ rtnl_unlock();
+ __count == 0; }));
rtnl_lock();
/* TODO nl802154 phy notify */
/* TODO phy registered lock */
- /* TODO WARN_ON wpan_dev_list */
+ WARN_ON(!list_empty(&rdev->wpan_dev_list));
/* First remove the hardware from everywhere, this makes
* it impossible to find from userspace.
@@ -173,6 +181,79 @@ void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
kfree(rdev);
}
+static void
+cfg802154_update_iface_num(struct cfg802154_registered_device *rdev,
+ int iftype, int num)
+{
+ ASSERT_RTNL();
+
+ rdev->num_running_ifaces += num;
+}
+
+static int cfg802154_netdev_notifier_call(struct notifier_block *nb,
+ unsigned long state, void *ptr)
+{
+ struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+ struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
+ struct cfg802154_registered_device *rdev;
+
+ if (!wpan_dev)
+ return NOTIFY_DONE;
+
+ rdev = wpan_phy_to_rdev(wpan_dev->wpan_phy);
+
+ /* TODO WARN_ON unspec type */
+
+ switch (state) {
+ /* TODO NETDEV_DEVTYPE */
+ case NETDEV_REGISTER:
+ wpan_dev->identifier = ++rdev->wpan_dev_id;
+ list_add_rcu(&wpan_dev->list, &rdev->wpan_dev_list);
+ rdev->devlist_generation++;
+
+ wpan_dev->netdev = dev;
+ break;
+ case NETDEV_DOWN:
+ cfg802154_update_iface_num(rdev, wpan_dev->iftype, -1);
+
+ rdev->opencount--;
+ wake_up(&rdev->dev_wait);
+ break;
+ case NETDEV_UP:
+ cfg802154_update_iface_num(rdev, wpan_dev->iftype, 1);
+
+ rdev->opencount++;
+ break;
+ case NETDEV_UNREGISTER:
+ /* It is possible to get NETDEV_UNREGISTER
+ * multiple times. To detect that, check
+ * that the interface is still on the list
+ * of registered interfaces, and only then
+ * remove and clean it up.
+ */
+ if (!list_empty(&wpan_dev->list)) {
+ list_del_rcu(&wpan_dev->list);
+ rdev->devlist_generation++;
+ }
+ /* synchronize (so that we won't find this netdev
+ * from other code any more) and then clear the list
+ * head so that the above code can safely check for
+ * !list_empty() to avoid double-cleanup.
+ */
+ synchronize_rcu();
+ INIT_LIST_HEAD(&wpan_dev->list);
+ break;
+ default:
+ return NOTIFY_DONE;
+ }
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block cfg802154_netdev_notifier = {
+ .notifier_call = cfg802154_netdev_notifier_call,
+};
+
static int __init wpan_phy_class_init(void)
{
int rc;
@@ -181,11 +262,18 @@ static int __init wpan_phy_class_init(void)
if (rc)
goto err;
- rc = ieee802154_nl_init();
+ rc = register_netdevice_notifier(&cfg802154_netdev_notifier);
if (rc)
goto err_nl;
+ rc = ieee802154_nl_init();
+ if (rc)
+ goto err_notifier;
+
return 0;
+
+err_notifier:
+ unregister_netdevice_notifier(&cfg802154_netdev_notifier);
err_nl:
wpan_phy_sysfs_exit();
err:
@@ -196,6 +284,7 @@ subsys_initcall(wpan_phy_class_init);
static void __exit wpan_phy_class_exit(void)
{
ieee802154_nl_exit();
+ unregister_netdevice_notifier(&cfg802154_netdev_notifier);
wpan_phy_sysfs_exit();
}
module_exit(wpan_phy_class_exit);
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index 38887cb2..e708d9d 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -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
*/
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 07/15] ieee802154: sysfs add wpan_phy index and name
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (5 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 06/15] ieee802154: add wpan_dev_list Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 08/15] ieee802154: add new nl802154 header Alexander Aring
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds new sysfs entries for wpan_phy index and name. This
needed for the new 802.15.4 userspace tool.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/sysfs.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/net/ieee802154/sysfs.c b/net/ieee802154/sysfs.c
index 8819998..1613b9c 100644
--- a/net/ieee802154/sysfs.c
+++ b/net/ieee802154/sysfs.c
@@ -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,
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 08/15] ieee802154: add new nl802154 header
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (6 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 07/15] ieee802154: sysfs add wpan_phy index and name Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 09/15] ieee802154: add nl802154 framework Alexander Aring
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
MAINTAINERS | 1 +
include/net/nl802154.h | 122 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 123 insertions(+)
create mode 100644 include/net/nl802154.h
diff --git a/MAINTAINERS b/MAINTAINERS
index b42eb50..7ec37a3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
new file mode 100644
index 0000000..6dbd406
--- /dev/null
+++ b/include/net/nl802154.h
@@ -0,0 +1,122 @@
+#ifndef __NL802154_H
+#define __NL802154_H
+/*
+ * 802.15.4 netlink interface public header
+ *
+ * Copyright 2014 Alexander Aring <aar@pengutronix.de>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#define NL802154_GENL_NAME "nl802154"
+
+enum nl802154_commands {
+/* don't change the order or add anything between, this is ABI! */
+/* currently we don't shipping this file via uapi, ignore the above one */
+ NL802154_CMD_UNSPEC,
+
+ NL802154_CMD_GET_WPAN_PHY, /* can dump */
+ NL802154_CMD_SET_WPAN_PHY,
+ NL802154_CMD_NEW_WPAN_PHY,
+ NL802154_CMD_DEL_WPAN_PHY,
+
+ NL802154_CMD_GET_INTERFACE, /* can dump */
+ NL802154_CMD_SET_INTERFACE,
+ NL802154_CMD_NEW_INTERFACE,
+ NL802154_CMD_DEL_INTERFACE,
+
+ NL802154_CMD_SET_CHANNEL,
+
+ NL802154_CMD_SET_PAN_ID,
+ NL802154_CMD_SET_SHORT_ADDR,
+
+ NL802154_CMD_SET_TX_POWER,
+ NL802154_CMD_SET_CCA_MODE,
+ NL802154_CMD_SET_CCA_ED_LEVEL,
+
+ NL802154_CMD_SET_MAX_FRAME_RETRIES,
+
+ NL802154_CMD_SET_BACKOFF_EXPONENT,
+ NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
+
+ NL802154_CMD_SET_LBT_MODE,
+
+ /* add new commands above here */
+
+ /* used to define NL802154_CMD_MAX below */
+ __NL802154_CMD_AFTER_LAST,
+ NL802154_CMD_MAX = __NL802154_CMD_AFTER_LAST - 1
+};
+
+enum nl802154_attrs {
+/* don't change the order or add anything between, this is ABI! */
+/* currently we don't shipping this file via uapi, ignore the above one */
+ NL802154_ATTR_UNSPEC,
+
+ NL802154_ATTR_WPAN_PHY,
+ NL802154_ATTR_WPAN_PHY_NAME,
+
+ NL802154_ATTR_IFINDEX,
+ NL802154_ATTR_IFNAME,
+ NL802154_ATTR_IFTYPE,
+
+ NL802154_ATTR_WPAN_DEV,
+
+ NL802154_ATTR_PAGE,
+ NL802154_ATTR_CHANNEL,
+
+ NL802154_ATTR_PAN_ID,
+ NL802154_ATTR_SHORT_ADDR,
+
+ NL802154_ATTR_TX_POWER,
+
+ NL802154_ATTR_CCA_MODE,
+ NL802154_ATTR_CCA_MODE3_AND,
+ NL802154_ATTR_CCA_ED_LEVEL,
+
+ NL802154_ATTR_MAX_FRAME_RETRIES,
+
+ NL802154_ATTR_MAX_BE,
+ NL802154_ATTR_MIN_BE,
+ NL802154_ATTR_MAX_CSMA_BACKOFFS,
+
+ NL802154_ATTR_LBT_MODE,
+
+ NL802154_ATTR_GENERATION,
+
+ NL802154_ATTR_CHANNELS_SUPPORTED,
+ NL802154_ATTR_SUPPORTED_CHANNEL,
+
+ NL802154_ATTR_EXTENDED_ADDR,
+
+ /* add attributes here, update the policy in nl802154.c */
+
+ __NL802154_ATTR_AFTER_LAST,
+ NL802154_ATTR_MAX = __NL802154_ATTR_AFTER_LAST - 1
+};
+
+enum nl802154_iftype {
+ /* for backwards compatibility TODO */
+ NL802154_IFTYPE_UNSPEC = -1,
+
+ NL802154_IFTYPE_NODE,
+ NL802154_IFTYPE_MONITOR,
+ NL802154_IFTYPE_COORD,
+
+ /* keep last */
+ NUM_NL802154_IFTYPES,
+ NL802154_IFTYPE_MAX = NUM_NL802154_IFTYPES - 1
+};
+
+#endif /* __NL802154_H */
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 09/15] ieee802154: add nl802154 framework
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (7 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 08/15] ieee802154: add new nl802154 header Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 10/15] ieee802154: add wpan_phy dump support Alexander Aring
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds a basic nl802154 framework. Most of this code was
grabbed from nl80211 framework.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
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
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 38354d4..9f6970f 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -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__
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 3ee00bf..ae5ecbc 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -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();
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index e708d9d..c8319bf 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -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 */
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
index 42ae63a..a5d7515 100644
--- a/net/ieee802154/ieee802154.h
+++ b/net/ieee802154/ieee802154.h
@@ -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) \
{ \
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 6c3c259..63ee7d6 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -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);
}
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
new file mode 100644
index 0000000..5dec0bb
--- /dev/null
+++ b/net/ieee802154/nl802154.c
@@ -0,0 +1,309 @@
+/* This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Authors:
+ * Alexander Aring <aar@pengutronix.de>
+ *
+ * Based on: net/wireless/nl80211.c
+ */
+
+#include <linux/rtnetlink.h>
+
+#include <net/cfg802154.h>
+#include <net/genetlink.h>
+#include <net/mac802154.h>
+#include <net/netlink.h>
+#include <net/nl802154.h>
+#include <net/sock.h>
+
+#include "nl802154.h"
+#include "core.h"
+
+static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
+ struct genl_info *info);
+
+static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
+ struct genl_info *info);
+
+/* the netlink family */
+static struct genl_family nl802154_fam = {
+ .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
+ .name = NL802154_GENL_NAME, /* have users key off the name instead */
+ .hdrsize = 0, /* no private header */
+ .version = 1, /* no particular meaning now */
+ .maxattr = NL802154_ATTR_MAX,
+ .netnsok = true,
+ .pre_doit = nl802154_pre_doit,
+ .post_doit = nl802154_post_doit,
+};
+
+/* multicast groups */
+enum nl802154_multicast_groups {
+ NL802154_MCGRP_CONFIG,
+};
+
+static const struct genl_multicast_group nl802154_mcgrps[] = {
+ [NL802154_MCGRP_CONFIG] = { .name = "config", },
+};
+
+/* returns ERR_PTR values */
+static struct wpan_dev *
+__cfg802154_wpan_dev_from_attrs(struct net *netns, struct nlattr **attrs)
+{
+ struct cfg802154_registered_device *rdev;
+ struct wpan_dev *result = NULL;
+ bool have_ifidx = attrs[NL802154_ATTR_IFINDEX];
+ bool have_wpan_dev_id = attrs[NL802154_ATTR_WPAN_DEV];
+ u64 wpan_dev_id;
+ int wpan_phy_idx = -1;
+ int ifidx = -1;
+
+ ASSERT_RTNL();
+
+ if (!have_ifidx && !have_wpan_dev_id)
+ return ERR_PTR(-EINVAL);
+
+ if (have_ifidx)
+ ifidx = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
+ if (have_wpan_dev_id) {
+ wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
+ wpan_phy_idx = wpan_dev_id >> 32;
+ }
+
+ list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
+ struct wpan_dev *wpan_dev;
+
+ /* TODO netns compare */
+
+ if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
+ continue;
+
+ list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
+ if (have_ifidx && wpan_dev->netdev &&
+ wpan_dev->netdev->ifindex == ifidx) {
+ result = wpan_dev;
+ break;
+ }
+ if (have_wpan_dev_id &&
+ wpan_dev->identifier == (u32)wpan_dev_id) {
+ result = wpan_dev;
+ break;
+ }
+ }
+
+ if (result)
+ break;
+ }
+
+ if (result)
+ return result;
+
+ return ERR_PTR(-ENODEV);
+}
+
+static struct cfg802154_registered_device *
+__cfg802154_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
+{
+ struct cfg802154_registered_device *rdev = NULL, *tmp;
+ struct net_device *netdev;
+
+ ASSERT_RTNL();
+
+ if (!attrs[NL802154_ATTR_WPAN_PHY] &&
+ !attrs[NL802154_ATTR_IFINDEX] &&
+ !attrs[NL802154_ATTR_WPAN_DEV])
+ return ERR_PTR(-EINVAL);
+
+ if (attrs[NL802154_ATTR_WPAN_PHY])
+ rdev = cfg802154_rdev_by_wpan_phy_idx(
+ nla_get_u32(attrs[NL802154_ATTR_WPAN_PHY]));
+
+ if (attrs[NL802154_ATTR_WPAN_DEV]) {
+ u64 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
+ struct wpan_dev *wpan_dev;
+ bool found = false;
+
+ tmp = cfg802154_rdev_by_wpan_phy_idx(wpan_dev_id >> 32);
+ if (tmp) {
+ /* make sure wpan_dev exists */
+ list_for_each_entry(wpan_dev, &tmp->wpan_dev_list, list) {
+ if (wpan_dev->identifier != (u32)wpan_dev_id)
+ continue;
+ found = true;
+ break;
+ }
+
+ if (!found)
+ tmp = NULL;
+
+ if (rdev && tmp != rdev)
+ return ERR_PTR(-EINVAL);
+ rdev = tmp;
+ }
+ }
+
+ if (attrs[NL802154_ATTR_IFINDEX]) {
+ int ifindex = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
+
+ netdev = __dev_get_by_index(netns, ifindex);
+ if (netdev) {
+ if (netdev->ieee802154_ptr)
+ tmp = wpan_phy_to_rdev(
+ netdev->ieee802154_ptr->wpan_phy);
+ else
+ tmp = NULL;
+
+ /* not wireless device -- return error */
+ if (!tmp)
+ return ERR_PTR(-EINVAL);
+
+ /* mismatch -- return error */
+ if (rdev && tmp != rdev)
+ return ERR_PTR(-EINVAL);
+
+ rdev = tmp;
+ }
+ }
+
+ if (!rdev)
+ return ERR_PTR(-ENODEV);
+
+ /* TODO netns compare */
+
+ return rdev;
+}
+
+/* This function returns a pointer to the driver
+ * that the genl_info item that is passed refers to.
+ *
+ * The result of this can be a PTR_ERR and hence must
+ * be checked with IS_ERR() for errors.
+ */
+static struct cfg802154_registered_device *
+cfg802154_get_dev_from_info(struct net *netns, struct genl_info *info)
+{
+ return __cfg802154_rdev_from_attrs(netns, info->attrs);
+}
+
+/* policy for the attributes */
+static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
+};
+
+/* message building helper */
+static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
+ int flags, u8 cmd)
+{
+ /* since there is no private header just add the generic one */
+ return genlmsg_put(skb, portid, seq, &nl802154_fam, flags, cmd);
+}
+
+#define NL802154_FLAG_NEED_WPAN_PHY 0x01
+#define NL802154_FLAG_NEED_NETDEV 0x02
+#define NL802154_FLAG_NEED_RTNL 0x04
+#define NL802154_FLAG_CHECK_NETDEV_UP 0x08
+#define NL802154_FLAG_NEED_NETDEV_UP (NL802154_FLAG_NEED_NETDEV |\
+ NL802154_FLAG_CHECK_NETDEV_UP)
+#define NL802154_FLAG_NEED_WPAN_DEV 0x10
+#define NL802154_FLAG_NEED_WPAN_DEV_UP (NL802154_FLAG_NEED_WPAN_DEV |\
+ NL802154_FLAG_CHECK_NETDEV_UP)
+
+static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
+ struct genl_info *info)
+{
+ struct cfg802154_registered_device *rdev;
+ struct wpan_dev *wpan_dev;
+ struct net_device *dev;
+ bool rtnl = ops->internal_flags & NL802154_FLAG_NEED_RTNL;
+
+ if (rtnl)
+ rtnl_lock();
+
+ if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_PHY) {
+ rdev = cfg802154_get_dev_from_info(genl_info_net(info), info);
+ if (IS_ERR(rdev)) {
+ if (rtnl)
+ rtnl_unlock();
+ return PTR_ERR(rdev);
+ }
+ info->user_ptr[0] = rdev;
+ } else if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV ||
+ ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
+ ASSERT_RTNL();
+ wpan_dev = __cfg802154_wpan_dev_from_attrs(genl_info_net(info),
+ info->attrs);
+ if (IS_ERR(wpan_dev)) {
+ if (rtnl)
+ rtnl_unlock();
+ return PTR_ERR(wpan_dev);
+ }
+
+ dev = wpan_dev->netdev;
+ rdev = wpan_phy_to_rdev(wpan_dev->wpan_phy);
+
+ if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV) {
+ if (!dev) {
+ if (rtnl)
+ rtnl_unlock();
+ return -EINVAL;
+ }
+
+ info->user_ptr[1] = dev;
+ } else {
+ info->user_ptr[1] = wpan_dev;
+ }
+
+ if (dev) {
+ if (ops->internal_flags & NL802154_FLAG_CHECK_NETDEV_UP &&
+ !netif_running(dev)) {
+ if (rtnl)
+ rtnl_unlock();
+ return -ENETDOWN;
+ }
+
+ dev_hold(dev);
+ }
+
+ info->user_ptr[0] = rdev;
+ }
+
+ return 0;
+}
+
+static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
+ struct genl_info *info)
+{
+ if (info->user_ptr[1]) {
+ if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
+ struct wpan_dev *wpan_dev = info->user_ptr[1];
+
+ if (wpan_dev->netdev)
+ dev_put(wpan_dev->netdev);
+ } else {
+ dev_put(info->user_ptr[1]);
+ }
+ }
+
+ if (ops->internal_flags & NL802154_FLAG_NEED_RTNL)
+ rtnl_unlock();
+}
+
+static const struct genl_ops nl802154_ops[] = {
+};
+
+/* initialisation/exit functions */
+int nl802154_init(void)
+{
+ return genl_register_family_with_ops_groups(&nl802154_fam, nl802154_ops,
+ nl802154_mcgrps);
+}
+
+void nl802154_exit(void)
+{
+ genl_unregister_family(&nl802154_fam);
+}
diff --git a/net/ieee802154/nl802154.h b/net/ieee802154/nl802154.h
new file mode 100644
index 0000000..3846a89
--- /dev/null
+++ b/net/ieee802154/nl802154.h
@@ -0,0 +1,7 @@
+#ifndef __IEEE802154_NL802154_H
+#define __IEEE802154_NL802154_H
+
+int nl802154_init(void);
+void nl802154_exit(void);
+
+#endif /* __IEEE802154_NL802154_H */
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 10/15] ieee802154: add wpan_phy dump support
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (8 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 09/15] ieee802154: add nl802154 framework Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 11/15] ieee802154: add wpan_dev " Alexander Aring
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for dumping wpan_phy attributes via nl802154.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/core.c | 2 +-
net/ieee802154/core.h | 1 +
net/ieee802154/nl802154.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 223 insertions(+), 1 deletion(-)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index ae5ecbc..18bc7e7 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -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)
{
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index c8319bf..f3e9558 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -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);
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 5dec0bb..32e8847 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -193,6 +193,22 @@ cfg802154_get_dev_from_info(struct net *netns, struct genl_info *info)
/* policy for the attributes */
static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
+ [NL802154_ATTR_WPAN_PHY] = { .type = NLA_U32 },
+ [NL802154_ATTR_WPAN_PHY_NAME] = { .type = NLA_NUL_STRING,
+ .len = 20-1 },
+
+ [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 },
+
+ [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 },
+
+ [NL802154_ATTR_PAGE] = { .type = NLA_U8, },
+ [NL802154_ATTR_CHANNEL] = { .type = NLA_U8, },
+
+ [NL802154_ATTR_TX_POWER] = { .type = NLA_S8, },
+
+ [NL802154_ATTR_CCA_MODE] = { .type = NLA_U8, },
+
+ [NL802154_ATTR_SUPPORTED_CHANNEL] = { .type = NLA_U32, },
};
/* message building helper */
@@ -203,6 +219,201 @@ static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
return genlmsg_put(skb, portid, seq, &nl802154_fam, flags, cmd);
}
+static int
+nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
+ struct sk_buff *msg)
+{
+ struct nlattr *nl_page;
+ unsigned long page;
+
+ nl_page = nla_nest_start(msg, NL802154_ATTR_CHANNELS_SUPPORTED);
+ if (!nl_page)
+ return -ENOBUFS;
+
+ for (page = 0; page < WPAN_NUM_PAGES; page++) {
+ if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
+ rdev->wpan_phy.channels_supported[page]))
+ return -ENOBUFS;
+ }
+ nla_nest_end(msg, nl_page);
+
+ return 0;
+}
+
+static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
+ enum nl802154_commands cmd,
+ struct sk_buff *msg, u32 portid, u32 seq,
+ int flags)
+{
+ void *hdr;
+
+ hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
+ if (!hdr)
+ return -ENOBUFS;
+
+ if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx) ||
+ nla_put_string(msg, NL802154_ATTR_WPAN_PHY_NAME,
+ wpan_phy_name(&rdev->wpan_phy)) ||
+ nla_put_u32(msg, NL802154_ATTR_GENERATION,
+ cfg802154_rdev_list_generation))
+ goto nla_put_failure;
+
+ if (cmd != NL802154_CMD_NEW_WPAN_PHY)
+ goto finish;
+
+ /* DUMP PHY PIB */
+
+ /* current channel settings */
+ if (nla_put_u8(msg, NL802154_ATTR_PAGE,
+ rdev->wpan_phy.current_page) ||
+ nla_put_u8(msg, NL802154_ATTR_CHANNEL,
+ rdev->wpan_phy.current_channel))
+ goto nla_put_failure;
+
+ /* supported channels array */
+ if (nl802154_send_wpan_phy_channels(rdev, msg))
+ goto nla_put_failure;
+
+ /* cca mode */
+ if (nla_put_u8(msg, NL802154_ATTR_CCA_MODE,
+ rdev->wpan_phy.cca_mode))
+ goto nla_put_failure;
+
+ if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
+ rdev->wpan_phy.transmit_power))
+ goto nla_put_failure;
+
+finish:
+ return genlmsg_end(msg, hdr);
+
+nla_put_failure:
+ genlmsg_cancel(msg, hdr);
+ return -EMSGSIZE;
+}
+
+struct nl802154_dump_wpan_phy_state {
+ s64 filter_wpan_phy;
+ long start;
+
+};
+
+static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
+ struct netlink_callback *cb,
+ struct nl802154_dump_wpan_phy_state *state)
+{
+ struct nlattr **tb = nl802154_fam.attrbuf;
+ int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize,
+ tb, nl802154_fam.maxattr, nl802154_policy);
+
+ /* TODO check if we can handle error here,
+ * we have no backward compatibility
+ */
+ if (ret)
+ return 0;
+
+ if (tb[NL802154_ATTR_WPAN_PHY])
+ state->filter_wpan_phy = nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]);
+ if (tb[NL802154_ATTR_WPAN_DEV])
+ state->filter_wpan_phy = nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]) >> 32;
+ if (tb[NL802154_ATTR_IFINDEX]) {
+ struct net_device *netdev;
+ struct cfg802154_registered_device *rdev;
+ int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
+
+ /* TODO netns */
+ netdev = __dev_get_by_index(&init_net, ifidx);
+ if (!netdev)
+ return -ENODEV;
+ if (netdev->ieee802154_ptr) {
+ rdev = wpan_phy_to_rdev(
+ netdev->ieee802154_ptr->wpan_phy);
+ state->filter_wpan_phy = rdev->wpan_phy_idx;
+ }
+ }
+
+ return 0;
+}
+
+static int
+nl802154_dump_wpan_phy(struct sk_buff *skb, struct netlink_callback *cb)
+{
+ int idx = 0, ret;
+ struct nl802154_dump_wpan_phy_state *state = (void *)cb->args[0];
+ struct cfg802154_registered_device *rdev;
+
+ rtnl_lock();
+ if (!state) {
+ state = kzalloc(sizeof(*state), GFP_KERNEL);
+ if (!state) {
+ rtnl_unlock();
+ return -ENOMEM;
+ }
+ state->filter_wpan_phy = -1;
+ ret = nl802154_dump_wpan_phy_parse(skb, cb, state);
+ if (ret) {
+ kfree(state);
+ rtnl_unlock();
+ return ret;
+ }
+ cb->args[0] = (long)state;
+ }
+
+ list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
+ /* TODO net ns compare */
+ if (++idx <= state->start)
+ continue;
+ if (state->filter_wpan_phy != -1 &&
+ state->filter_wpan_phy != rdev->wpan_phy_idx)
+ continue;
+ /* attempt to fit multiple wpan_phy data chunks into the skb */
+ ret = nl802154_send_wpan_phy(rdev,
+ NL802154_CMD_NEW_WPAN_PHY,
+ skb,
+ NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq, NLM_F_MULTI);
+ if (ret < 0) {
+ if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
+ !skb->len && cb->min_dump_alloc < 4096) {
+ cb->min_dump_alloc = 4096;
+ rtnl_unlock();
+ return 1;
+ }
+ idx--;
+ break;
+ }
+ break;
+ }
+ rtnl_unlock();
+
+ state->start = idx;
+
+ return skb->len;
+}
+
+static int nl802154_dump_wpan_phy_done(struct netlink_callback *cb)
+{
+ kfree((void *)cb->args[0]);
+ return 0;
+}
+
+static int nl802154_get_wpan_phy(struct sk_buff *skb, struct genl_info *info)
+{
+ struct sk_buff *msg;
+ struct cfg802154_registered_device *rdev = info->user_ptr[0];
+
+ msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+ if (!msg)
+ return -ENOMEM;
+
+ if (nl802154_send_wpan_phy(rdev, NL802154_CMD_NEW_WPAN_PHY, msg,
+ info->snd_portid, info->snd_seq, 0) < 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
@@ -294,6 +505,16 @@ static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
}
static const struct genl_ops nl802154_ops[] = {
+ {
+ .cmd = NL802154_CMD_GET_WPAN_PHY,
+ .doit = nl802154_get_wpan_phy,
+ .dumpit = nl802154_dump_wpan_phy,
+ .done = nl802154_dump_wpan_phy_done,
+ .policy = nl802154_policy,
+ /* can be retrieved by unprivileged users */
+ .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
+ NL802154_FLAG_NEED_RTNL,
+ },
};
/* initialisation/exit functions */
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 11/15] ieee802154: add wpan_dev dump support
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (9 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 10/15] ieee802154: add wpan_phy dump support Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 12/15] mac820154: don't set monitor dev_addr Alexander Aring
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds support for wpan_dev dump via nl802154 framework.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/nl802154.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 145 insertions(+)
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 32e8847..46df7dc 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -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 */
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 12/15] mac820154: don't set monitor dev_addr
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (10 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 11/15] ieee802154: add wpan_dev " Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 13/15] ieee802154: netlink add rtnl lock Alexander Aring
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/mac802154/iface.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 4630ceb..d635f36 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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;
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 13/15] ieee802154: netlink add rtnl lock
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (11 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 12/15] mac820154: don't set monitor dev_addr Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 14/15] ieee802154: fix iface dump with lowpan Alexander Aring
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This patch adds rtnl lock hold mechanism while accessing wpan_dev
attributes. Furthermore these attributes should be protected by rtnl
lock and netif_running only.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/nl-mac.c | 6 ++++++
net/mac802154/mac_cmd.c | 10 ++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 7127b9d..50e9863 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -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);
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index b8bd952..6aacb18 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -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 = {
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 14/15] ieee802154: fix iface dump with lowpan
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (12 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 13/15] ieee802154: netlink add rtnl lock Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 15/15] mac802154: protect address changes via ioctl Alexander Aring
2014-11-09 18:52 ` [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Marcel Holtmann
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/nl-mac.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 50e9863..fe77f0c 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -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);
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH bluetooth-next 15/15] mac802154: protect address changes via ioctl
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (13 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 14/15] ieee802154: fix iface dump with lowpan Alexander Aring
@ 2014-11-09 7:36 ` Alexander Aring
2014-11-09 18:52 ` [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Marcel Holtmann
15 siblings, 0 replies; 17+ messages in thread
From: Alexander Aring @ 2014-11-09 7:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, Alexander Aring
This 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.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
net/mac802154/iface.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index d635f36..83715b5 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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 ||
--
2.1.3
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
` (14 preceding siblings ...)
2014-11-09 7:36 ` [PATCH bluetooth-next 15/15] mac802154: protect address changes via ioctl Alexander Aring
@ 2014-11-09 18:52 ` Marcel Holtmann
15 siblings, 0 replies; 17+ messages in thread
From: Marcel Holtmann @ 2014-11-09 18:52 UTC (permalink / raw)
To: Alexander Aring; +Cc: linux-wpan, kernel
Hi Alex,
> 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
all 15 patches have been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2014-11-09 18:52 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-09 7:36 [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 01/15] mac802154: move mac pib attributes into wpan_dev Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 02/15] mac802154: remove mac_params in sdata Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 03/15] ieee802154: rename wpan_phy_alloc Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 04/15] ieee802154: add cfg802154_registered_device list Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 05/15] ieee802154: add iftype to wpan_dev Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 06/15] ieee802154: add wpan_dev_list Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 07/15] ieee802154: sysfs add wpan_phy index and name Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 08/15] ieee802154: add new nl802154 header Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 09/15] ieee802154: add nl802154 framework Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 10/15] ieee802154: add wpan_phy dump support Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 11/15] ieee802154: add wpan_dev " Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 12/15] mac820154: don't set monitor dev_addr Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 13/15] ieee802154: netlink add rtnl lock Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 14/15] ieee802154: fix iface dump with lowpan Alexander Aring
2014-11-09 7:36 ` [PATCH bluetooth-next 15/15] mac802154: protect address changes via ioctl Alexander Aring
2014-11-09 18:52 ` [PATCH bluetooth-next 00/15] ieee802154: introduce nl802154 framework Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).