Skip to contentSkip to conversation

ieee802154: interface registration and perm address support

PATCH In review Alexander Aring 3 participants 26 messages Nov 5, 2014 – Dec 13, 2014 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover ieee802154: interface registration and perm address support

This patch series contains various changes to make the 802.15.4 implementation similar like wireless/mac80211 implementation. Mainly changes are a complete rework for interface registration handling and supporting for perm address. The perm address can be set by driver layer and is the default "unique" extended address for the wpan_phy. Also we have now a default interface registration. This means a driver registrate a default wpan interface while registration the wpan_phy. No extra interface add handling via userspace tool is needed anymore.

Cc Varka Bhadram <[email protected]>

Alexander Aring (18):
ieee802154: rework wpan_phy index assignment
ieee802154: remove nl802154 unused functions
mac802154: move interface del handling in iface
mac802154: move interface add handling in iface
mac802154: move dev_hold out of ieee802154_if_add
ieee802154: rework interface registration
ieee802154: remove mlme get_phy callback
mac802154: add default interface registration
mac802154: add ieee802154_vif struct
ieee802154: add IEEE802154_EXTENDED_ADDR_LEN
ieee802154: add ieee802154_random_extended_addr
mac802154: add ieee802154_le64_to_be64
mac802154: cleanup ieee802154_netdev_to_extended_addr
mac802154: add support for perm_extended_addr
at86rf230: generate random perm extended address
at86rf230: add force slotted operation bit
mac802154: use IEEE802154_EXTENDED_ADDR_LEN
mac802154: fix typo promisuous to promiscuous

 MAINTAINERS                        |   1 -
 drivers/net/ieee802154/at86rf230.c |  10 ++
 drivers/net/ieee802154/cc2520.c    |   1 +
 include/linux/ieee802154.h         |  16 +++
 include/net/cfg802154.h            |   7 +-
 include/net/ieee802154_netdev.h    |  12 ---
 include/net/mac802154.h            |  32 +++++-
 include/net/nl802154.h             | 122 -----------------------
 net/ieee802154/6lowpan_rtnl.c      |   8 --
 net/ieee802154/core.c              |  30 +++---
 net/ieee802154/core.h              |   3 +
 net/ieee802154/nl-mac.c            | 193 ++-----------------------------------
 net/ieee802154/nl-phy.c            |   4 +-
 net/mac802154/cfg.c                |  14 ++-
 net/mac802154/ieee802154_i.h       |  14 ++-
 net/mac802154/iface.c              | 148 +++++++++++++++++++++-------
 net/mac802154/mac_cmd.c            |  20 ----
 net/mac802154/main.c               |  95 +++---------------
 net/mac802154/rx.c                 |   4 +-
 19 files changed, 237 insertions(+), 497 deletions(-)
 delete mode 100644 include/net/nl802154.h
Signature · 1 line
2.1.3
author maintainer
#1 lore raw

PATCH 1/18 ieee802154: rework wpan_phy index assignment

This patch reworks the wpan_phy index incrementation. It's now similar like wireless wiphy index incrementation. We move the wpan_phy index attribute inside of cfg802154_registered_device and use atomic operations instead locking mechanism via wpan_phy_mutex.

---
 include/net/cfg802154.h |  1 -
 net/ieee802154/core.c   | 30 +++++++++++-------------------
 net/ieee802154/core.h   |  3 +++
 3 files changed, 14 insertions(+), 20 deletions(-)
include/net/cfg802154.h +0 -1
index 864bce2..29c6de5 100644
@@ -61,7 +61,6 @@ struct wpan_phy {
 	s32 cca_ed_level;
 
 	struct device dev;
-	int idx;
 
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
net/ieee802154/core.c +11 -19
index ed5b014..d1cd0ed 100644
@@ -23,9 +23,6 @@
 #include "sysfs.h"
 #include "core.h"
 
-static DEFINE_MUTEX(wpan_phy_mutex);
-static int wpan_phy_idx;
-
 static int wpan_phy_match(struct device *dev, const void *data)
 {
 	return !strcmp(dev_name(dev), (const char *)data);
@@ -72,14 +69,10 @@ int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data),
 }
 EXPORT_SYMBOL(wpan_phy_for_each);
 
-static int wpan_phy_idx_valid(int idx)
-{
-	return idx >= 0;
-}
-
 struct wpan_phy *
 wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size)
 {
+	static atomic_t wpan_phy_counter = ATOMIC_INIT(0);
 	struct cfg802154_registered_device *rdev;
 	size_t alloc_size;
 
@@ -90,28 +83,27 @@ wpan_phy_alloc(const struct cfg802154_ops *ops, size_t priv_size)
 
 	rdev->ops = ops;
 
-	mutex_lock(&wpan_phy_mutex);
-	rdev->wpan_phy.idx = wpan_phy_idx++;
-	if (unlikely(!wpan_phy_idx_valid(rdev->wpan_phy.idx))) {
-		wpan_phy_idx--;
-		mutex_unlock(&wpan_phy_mutex);
+	rdev->wpan_phy_idx = atomic_inc_return(&wpan_phy_counter);
+
+	if (unlikely(rdev->wpan_phy_idx < 0)) {
+		/* ugh, wrapped! */
+		atomic_dec(&wpan_phy_counter);
 		kfree(rdev);
-		goto out;
+		return NULL;
 	}
-	mutex_unlock(&wpan_phy_mutex);
+
+	/* atomic_inc_return makes it start at 1, make it start at 0 */
+	rdev->wpan_phy_idx--;
 
 	mutex_init(&rdev->wpan_phy.pib_lock);
 
 	device_initialize(&rdev->wpan_phy.dev);
-	dev_set_name(&rdev->wpan_phy.dev, "wpan-phy%d", rdev->wpan_phy.idx);
+	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;
 
 	return &rdev->wpan_phy;
-
-out:
-	return NULL;
 }
 EXPORT_SYMBOL(wpan_phy_alloc);
 
net/ieee802154/core.h +3 -0
index 1bc1725..fea60b3 100644
@@ -6,6 +6,9 @@
 struct cfg802154_registered_device {
 	const struct cfg802154_ops *ops;
 
+	/* wpan_phy index, internal only */
+	int wpan_phy_idx;
+
 	/* 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
author maintainer
#2 lore raw

PATCH 2/18 ieee802154: remove nl802154 unused functions

In reply to Alexander Aring

The include/net/nl802154.h file contains a lot of prototypes which are not used inside of ieee802154 subsystem. This patch removes this file and make the only one used prototype "ieee802154_nl_start_confirm" as static declaration in ieee802154/nl-mac.c

---
 MAINTAINERS             |   1 -
 include/net/nl802154.h  | 122 -------------------------------
 net/ieee802154/nl-mac.c | 187 ++----------------------------------------------
 net/mac802154/mac_cmd.c |   6 --
 4 files changed, 6 insertions(+), 310 deletions(-)
 delete mode 100644 include/net/nl802154.h
MAINTAINERS +0 -1
index 7ec37a3..b42eb50 100644
@@ -4699,7 +4699,6 @@ 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 deleted +0 -122

122 lines not on this page · raw message

net/ieee802154/nl-mac.c +6 -181

205 lines not on this page · raw message

net/mac802154/mac_cmd.c +0 -6
index 9c2d6f6..e1ad83e 100644
@@ -25,7 +25,6 @@
 #include <net/ieee802154_netdev.h>
 #include <net/cfg802154.h>
 #include <net/mac802154.h>
-#include <net/nl802154.h>
 
 #include "ieee802154_i.h"
 #include "driver-ops.h"
@@ -65,11 +64,6 @@ static int mac802154_mlme_start_req(struct net_device *dev,
 		rc = ops->llsec->set_params(dev, &params, changed);
 	}
 
-	/* FIXME: add validation for unused parameters to be sane
-	 * for SoftMAC
-	 */
-	ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
-
 	return rc;
 }
 
Signature · 1 line
2.1.3
author maintainer
#3 lore raw

PATCH 3/18 mac802154: move interface del handling in iface

In reply to Alexander Aring

This patch moves and rename the mac802154_del_iface function into iface.c and rename the function to ieee802154_if_remove which is a similar naming convention like mac80211.

---
 net/mac802154/cfg.c          |  4 +++-
 net/mac802154/ieee802154_i.h |  2 +-
 net/mac802154/iface.c        | 12 ++++++++++++
 net/mac802154/main.c         | 16 ----------------
 4 files changed, 16 insertions(+), 18 deletions(-)
net/mac802154/cfg.c +3 -1
index 0c69b44..3f9afad 100644
@@ -28,7 +28,9 @@ ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
 					    struct net_device *dev)
 {
-	mac802154_del_iface(wpan_phy, dev);
+	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
+
+	ieee802154_if_remove(sdata);
 }
 
 const struct cfg802154_ops mac802154_config_ops = {
net/mac802154/ieee802154_i.h +1 -1
index 27e17e6..61a6a0f 100644
@@ -175,6 +175,6 @@ void mac802154_unlock_table(struct net_device *dev);
 
 struct net_device *
 mac802154_add_iface(struct wpan_phy *phy, const char *name, int type);
-void mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev);
+void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
 
 #endif /* __IEEE802154_I_H */
net/mac802154/iface.c +12 -0
index 0c9d00c..9d6012e 100644
@@ -443,3 +443,15 @@ void mac802154_monitor_setup(struct net_device *dev)
 
 	sdata->promisuous_mode = true;
 }
+
+void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
+{
+	ASSERT_RTNL();
+
+	mutex_lock(&sdata->local->iflist_mtx);
+	list_del_rcu(&sdata->list);
+	mutex_unlock(&sdata->local->iflist_mtx);
+
+	synchronize_rcu();
+	unregister_netdevice(sdata->dev);
+}
net/mac802154/main.c +0 -16
index b34ddbf..333d33d 100644
@@ -59,22 +59,6 @@ mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
 	return 0;
 }
 
-void mac802154_del_iface(struct wpan_phy *phy, struct net_device *dev)
-{
-	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-
-	ASSERT_RTNL();
-
-	BUG_ON(sdata->local->phy != phy);
-
-	mutex_lock(&sdata->local->iflist_mtx);
-	list_del_rcu(&sdata->list);
-	mutex_unlock(&sdata->local->iflist_mtx);
-
-	synchronize_rcu();
-	unregister_netdevice(sdata->dev);
-}
-
 struct net_device *
 mac802154_add_iface(struct wpan_phy *phy, const char *name, int type)
 {
Signature · 1 line
2.1.3
author maintainer
#4 lore raw

PATCH 4/18 mac802154: move interface add handling in iface

In reply to Alexander Aring

This patch moves and renames the mac802154_add_iface and mac802154_netdev_register functions into iface.c. The function mac802154_add_iface is renamed to ieee802154_if_add which is a similar naming convention like mac80211.

---
 net/mac802154/cfg.c          |  4 ++-
 net/mac802154/ieee802154_i.h |  3 ++
 net/mac802154/iface.c        | 66 +++++++++++++++++++++++++++++++++++++++++++
 net/mac802154/main.c         | 67 --------------------------------------------
 4 files changed, 72 insertions(+), 68 deletions(-)
net/mac802154/cfg.c +3 -1
index 3f9afad..0a08f66 100644
@@ -22,7 +22,9 @@ static struct net_device *
 ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 				const char *name, int type)
 {
-	return mac802154_add_iface(wpan_phy, name, type);
+	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+
+	return ieee802154_if_add(local, name, NULL, type);
 }
 
 static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
net/mac802154/ieee802154_i.h +3 -0
index 61a6a0f..3ad8540 100644
@@ -176,5 +176,8 @@ void mac802154_unlock_table(struct net_device *dev);
 struct net_device *
 mac802154_add_iface(struct wpan_phy *phy, const char *name, int type);
 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
+struct net_device *
+ieee802154_if_add(struct ieee802154_local *local, const char *name,
+		  struct wpan_dev **new_wpan_dev, int type);
 
 #endif /* __IEEE802154_I_H */
net/mac802154/iface.c +66 -0

72 lines not on this page · raw message

net/mac802154/main.c +0 -67

73 lines not on this page · raw message

Signature · 1 line
2.1.3
author maintainer
#5 lore raw

PATCH 5/18 mac802154: move dev_hold out of ieee802154_if_add

In reply to Alexander Aring

This patch moves the dev_hold call inside of nl-phy ieee802154_add_iface function. The ieee802154_add_iface is the only one function which use the ieee802154_if_add function and contains the corresponding dev_put call.

---
 net/ieee802154/nl-phy.c | 1 +
 net/mac802154/iface.c   | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/nl-phy.c +1 -0
index 5d914d3..397ca126 100644
@@ -226,6 +226,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
 		rc = PTR_ERR(dev);
 		goto nla_put_failure;
 	}
+	dev_hold(dev);
 
 	if (info->attrs[IEEE802154_ATTR_HW_ADDR]) {
 		struct sockaddr addr;
net/mac802154/iface.c +0 -1
index fced04b..78cb381 100644
@@ -501,7 +501,6 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 	if (err)
 		goto err_free;
 
-	dev_hold(dev); /* we return an incremented device refcount */
 	return dev;
 
 err_free:
Signature · 1 line
2.1.3
author maintainer
#6 lore raw

PATCH 6/18 ieee802154: rework interface registration

In reply to Alexander Aring

This patch meld mac802154_netdev_register into ieee802154_if_add function. Also we have now only one alloc_netdev call with one interface setup routine "ieee802154_if_setup" instead two different one for each interface type. This patch checks via runtime the interface type and do different handling now. Additional we add the wpan_dev struct in ieee802154_sub_if_data and set the new ieee802154_ptr while netdev registration. This behaviour is very similar the mac80211 netdev registration functionality.

---
 include/net/cfg802154.h      |   4 ++
 net/mac802154/cfg.c          |   8 ++-
 net/mac802154/ieee802154_i.h |   4 ++
 net/mac802154/iface.c        | 158 +++++++++++++++++++++----------------------
 4 files changed, 92 insertions(+), 82 deletions(-)
include/net/cfg802154.h +4 -0
index 29c6de5..57333f1 100644
@@ -65,6 +65,10 @@ struct wpan_phy {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct wpan_dev {
+	struct wpan_phy *wpan_phy;
+};
+
 #define to_phy(_dev)	container_of(_dev, struct wpan_phy, dev)
 
 struct wpan_phy *
net/mac802154/cfg.c +7 -1
index 0a08f66..d2c4e8f 100644
@@ -13,6 +13,7 @@
  * Based on: net/mac80211/cfg.c
  */
 
+#include <net/rtnetlink.h>
 #include <net/cfg802154.h>
 
 #include "ieee802154_i.h"
@@ -23,8 +24,13 @@ ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 				const char *name, int type)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+	struct net_device *dev;
 
-	return ieee802154_if_add(local, name, NULL, type);
+	rtnl_lock();
+	dev = ieee802154_if_add(local, name, NULL, type);
+	rtnl_unlock();
+
+	return dev;
 }
 
 static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
net/mac802154/ieee802154_i.h +4 -0
index 3ad8540..748dc5a 100644
@@ -20,6 +20,7 @@
 #define __IEEE802154_I_H
 
 #include <linux/mutex.h>
+#include <net/cfg802154.h>
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
 
@@ -73,11 +74,14 @@ enum ieee802154_sdata_state_bits {
 struct ieee802154_sub_if_data {
 	struct list_head list; /* the ieee802154_priv->slaves list */
 
+	struct wpan_dev wpan_dev;
+
 	struct ieee802154_local *local;
 	struct net_device *dev;
 
 	int type;
 	unsigned long state;
+	char name[IFNAMSIZ];
 
 	spinlock_t mib_lock;
 
net/mac802154/iface.c +77 -81

199 lines not on this page · raw message

Signature · 1 line
2.1.3
author maintainer
#7 lore raw

PATCH 7/18 ieee802154: remove mlme get_phy callback

In reply to Alexander Aring

This patch removes the get_phy callback from mlme ops structure. Instead we doing a dereference via ieee802154_ptr dev pointer. For backwards compatibility we need to run get_device after dereference wpan_phy via ieee802154_ptr.

---
 include/net/ieee802154_netdev.h | 12 ------------
 net/ieee802154/6lowpan_rtnl.c   |  8 --------
 net/ieee802154/nl-mac.c         |  6 ++++--
 net/ieee802154/nl-phy.c         |  3 ++-
 net/mac802154/iface.c           |  1 -
 net/mac802154/mac_cmd.c         | 14 --------------
 6 files changed, 6 insertions(+), 38 deletions(-)
include/net/ieee802154_netdev.h +0 -12
index 5e62d75..83bb8a73 100644
@@ -423,8 +423,6 @@ struct ieee802154_mlme_ops {
 
 	/* The fields below are required. */
 
-	struct wpan_phy *(*get_phy)(const struct net_device *dev);
-
 	/*
 	 * FIXME: these should become the part of PIB/MIB interface.
 	 * However we still don't have IB interface of any kind
@@ -434,16 +432,6 @@ struct ieee802154_mlme_ops {
 	u8 (*get_dsn)(const struct net_device *dev);
 };
 
-/* The IEEE 802.15.4 standard defines 2 type of the devices:
- * - FFD - full functionality device
- * - RFD - reduce functionality device
- *
- * So 2 sets of mlme operations are needed
- */
-struct ieee802154_reduced_mlme_ops {
-	struct wpan_phy *(*get_phy)(const struct net_device *dev);
-};
-
 static inline struct ieee802154_mlme_ops *
 ieee802154_mlme_ops(const struct net_device *dev)
 {
net/ieee802154/6lowpan_rtnl.c +0 -8
index 659f7b2..a96b64c 100644
@@ -407,13 +407,6 @@ static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 }
 
-static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
-{
-	struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
-
-	return ieee802154_mlme_ops(real_dev)->get_phy(real_dev);
-}
-
 static __le16 lowpan_get_pan_id(const struct net_device *dev)
 {
 	struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
@@ -465,7 +458,6 @@ static const struct net_device_ops lowpan_netdev_ops = {
 
 static struct ieee802154_mlme_ops lowpan_mlme = {
 	.get_pan_id = lowpan_get_pan_id,
-	.get_phy = lowpan_get_phy,
 	.get_short_addr = lowpan_get_short_addr,
 	.get_dsn = lowpan_get_dsn,
 };
net/ieee802154/nl-mac.c +4 -2
index 91a1855..7127b9d 100644
@@ -94,8 +94,9 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
 		goto out;
 
 	ops = ieee802154_mlme_ops(dev);
-	phy = ops->get_phy(dev);
+	phy = dev->ieee802154_ptr->wpan_phy;
 	BUG_ON(!phy);
+	get_device(&phy->dev);
 
 	short_addr = ops->get_short_addr(dev);
 	pan_id = ops->get_pan_id(dev);
@@ -493,7 +494,8 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
 	    !info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
 		goto out;
 
-	phy = ops->get_phy(dev);
+	phy = dev->ieee802154_ptr->wpan_phy;
+	get_device(&phy->dev);
 
 	ops->get_mac_params(dev, &params);
 
net/ieee802154/nl-phy.c +2 -1
index 397ca126..80a946d 100644
@@ -287,8 +287,9 @@ int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
 	if (!dev)
 		return -ENODEV;
 
-	phy = ieee802154_mlme_ops(dev)->get_phy(dev);
+	phy = dev->ieee802154_ptr->wpan_phy;
 	BUG_ON(!phy);
+	get_device(&phy->dev);
 
 	rc = -EINVAL;
 	/* phy name is optional, but should be checked if it's given */
net/mac802154/iface.c +0 -1
index f9ed608..2e2638e 100644
@@ -428,7 +428,6 @@ 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->dev->ml_priv = &mac802154_mlme_reduced;
 		sdata->promisuous_mode = true;
 		break;
 	default:
net/mac802154/mac_cmd.c +0 -14
index e1ad83e..00b2b21 100644
@@ -67,15 +67,6 @@ static int mac802154_mlme_start_req(struct net_device *dev,
 	return rc;
 }
 
-static struct wpan_phy *mac802154_get_phy(const struct net_device *dev)
-{
-	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-
-	BUG_ON(dev->type != ARPHRD_IEEE802154);
-
-	return to_phy(get_device(&sdata->local->phy->dev));
-}
-
 static int mac802154_set_mac_params(struct net_device *dev,
 				    const struct ieee802154_mac_params *params)
 {
@@ -134,12 +125,7 @@ static struct ieee802154_llsec_ops mac802154_llsec_ops = {
 	.unlock_table = mac802154_unlock_table,
 };
 
-struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced = {
-	.get_phy = mac802154_get_phy,
-};
-
 struct ieee802154_mlme_ops mac802154_mlme_wpan = {
-	.get_phy = mac802154_get_phy,
 	.start_req = mac802154_mlme_start_req,
 	.get_pan_id = mac802154_dev_get_pan_id,
 	.get_short_addr = mac802154_dev_get_short_addr,
Signature · 1 line
2.1.3
author maintainer
#8 lore raw

PATCH 8/18 mac802154: add default interface registration

In reply to Alexander Aring

This patch adds a default interface registration for a wpan interface type. Currently the 802.15.4 subsystem need to call userspace tools to add an interface. This patch is like mac80211 handling for registration a station interface type by default.

---
 net/mac802154/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
net/mac802154/main.c +12 -0
index a371eb5..7d0ff7f 100644
@@ -126,6 +126,7 @@ EXPORT_SYMBOL(ieee802154_free_hw);
 int ieee802154_register_hw(struct ieee802154_hw *hw)
 {
 	struct ieee802154_local *local = hw_to_local(hw);
+	struct net_device *dev;
 	int rc = -ENOSYS;
 
 	local->workqueue =
@@ -141,6 +142,17 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
 	if (rc < 0)
 		goto out_wq;
 
+	rtnl_lock();
+
+	dev = ieee802154_if_add(local, "wpan%d", NULL, IEEE802154_DEV_WPAN);
+	if (IS_ERR(dev)) {
+		rtnl_unlock();
+		rc = PTR_ERR(dev);
+		goto out_wq;
+	}
+
+	rtnl_unlock();
+
 	return 0;
 
 out_wq:
Signature · 1 line
2.1.3
author maintainer
#9 lore raw

PATCH 9/18 mac802154: add ieee802154_vif struct

In reply to Alexander Aring

This patch adds an ieee802154_vif similar like the ieee80211_vif which holds the interface type and maybe further more attributes like the ieee80211_vif structure.

---
 drivers/net/ieee802154/at86rf230.c |  1 +
 drivers/net/ieee802154/cc2520.c    |  1 +
 include/net/mac802154.h            |  8 ++++++++
 net/mac802154/ieee802154_i.h       |  3 ++-
 net/mac802154/iface.c              | 11 ++++++-----
 net/mac802154/rx.c                 |  4 ++--
 6 files changed, 20 insertions(+), 8 deletions(-)
drivers/net/ieee802154/at86rf230.c +1 -0
index f68ebba..bf47785 100644
@@ -1533,6 +1533,7 @@ static int at86rf230_probe(struct spi_device *spi)
 	lp->hw = hw;
 	lp->spi = spi;
 	hw->parent = &spi->dev;
+	hw->vif_data_size = sizeof(*lp);
 
 	lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
 	if (IS_ERR(lp->regmap)) {
drivers/net/ieee802154/cc2520.c +1 -0
index 340671b..ccbb082 100644
@@ -651,6 +651,7 @@ static int cc2520_register(struct cc2520_private *priv)
 	priv->hw->priv = priv;
 	priv->hw->parent = &priv->spi->dev;
 	priv->hw->extra_tx_headroom = 0;
+	priv->hw->vif_data_size = sizeof(*priv);
 
 	/* We do support only 2.4 Ghz */
 	priv->hw->phy->channels_supported[0] = 0x7FFF800;
include/net/mac802154.h +8 -0
index 8b0c26b..10711a6 100644
@@ -52,6 +52,13 @@ struct ieee802154_hw_addr_filt {
 	u8	pan_coord;
 };
 
+struct ieee802154_vif {
+	int type;
+
+	/* must be last */
+	u8 drv_priv[0] __aligned(sizeof(void *));
+};
+
 struct ieee802154_hw {
 	/* filled by the driver */
 	int	extra_tx_headroom;
@@ -62,6 +69,7 @@ struct ieee802154_hw {
 	struct	ieee802154_hw_addr_filt hw_filt;
 	void	*priv;
 	struct	wpan_phy *phy;
+	size_t vif_data_size;
 };
 
 /* Checksum is in hardware and is omitted from a packet
net/mac802154/ieee802154_i.h +2 -1
index 748dc5a..931f851 100644
@@ -79,7 +79,6 @@ struct ieee802154_sub_if_data {
 	struct ieee802154_local *local;
 	struct net_device *dev;
 
-	int type;
 	unsigned long state;
 	char name[IFNAMSIZ];
 
@@ -103,6 +102,8 @@ struct ieee802154_sub_if_data {
 	struct mutex sec_mtx;
 
 	struct mac802154_llsec sec;
+	/* must be last, dynamically sized area in this! */
+	struct ieee802154_vif vif;
 };
 
 #define MAC802154_CHAN_NONE		0xff /* No channel is assigned */
net/mac802154/iface.c +6 -5
index 2e2638e..764ce49 100644
@@ -136,10 +136,11 @@ static int mac802154_slave_open(struct net_device *dev)
 
 	ASSERT_RTNL();
 
-	if (sdata->type == IEEE802154_DEV_WPAN) {
+	if (sdata->vif.type == IEEE802154_DEV_WPAN) {
 		mutex_lock(&sdata->local->iflist_mtx);
 		list_for_each_entry(subif, &sdata->local->interfaces, list) {
-			if (subif != sdata && subif->type == sdata->type &&
+			if (subif != sdata &&
+			    subif->vif.type == sdata->vif.type &&
 			    ieee802154_sdata_running(subif)) {
 				mutex_unlock(&sdata->local->iflist_mtx);
 				return -EBUSY;
@@ -397,7 +398,7 @@ static int
 ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
 {
 	/* set some type-dependent values */
-	sdata->type = type;
+	sdata->vif.type = type;
 
 	get_random_bytes(&sdata->bsn, 1);
 	get_random_bytes(&sdata->dsn, 1);
@@ -447,8 +448,8 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 
 	ASSERT_RTNL();
 
-	ndev = alloc_netdev(sizeof(*sdata), name, NET_NAME_UNKNOWN,
-			    ieee802154_if_setup);
+	ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, name,
+			    NET_NAME_UNKNOWN, ieee802154_if_setup);
 	if (!ndev)
 		return ERR_PTR(-ENOMEM);
 
net/mac802154/rx.c +2 -2
index 95961cc..4b54cf3 100644
@@ -208,7 +208,7 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local,
 	}
 
 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
-		if (sdata->type != IEEE802154_DEV_WPAN ||
+		if (sdata->vif.type != IEEE802154_DEV_WPAN ||
 		    !netif_running(sdata->dev))
 			continue;
 
@@ -233,7 +233,7 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 	skb->protocol = htons(ETH_P_IEEE802154);
 
 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
-		if (sdata->type != IEEE802154_DEV_MONITOR)
+		if (sdata->vif.type != IEEE802154_DEV_MONITOR)
 			continue;
 
 		if (!ieee802154_sdata_running(sdata))
Signature · 1 line
2.1.3
author maintainer
#10 lore raw

PATCH 10/18 ieee802154: add IEEE802154_EXTENDED_ADDR_LEN

In reply to Alexander Aring

This patch adds a new define for getting the length of an extended address.

---
 include/linux/ieee802154.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/ieee802154.h +2 -0
index 4c03286..a907fe5 100644
@@ -29,6 +29,8 @@
 #define IEEE802154_MTU			127
 #define IEEE802154_MIN_PSDU_LEN		5
 
+#define IEEE802154_EXTENDED_ADDR_LEN	8
+
 #define IEEE802154_FC_TYPE_BEACON	0x0	/* Frame is beacon */
 #define	IEEE802154_FC_TYPE_DATA		0x1	/* Frame is data */
 #define IEEE802154_FC_TYPE_ACK		0x2	/* Frame is acknowledgment */
Signature · 1 line
2.1.3
author maintainer
#11 lore raw

PATCH 11/18 ieee802154: add ieee802154_random_extended_addr

In reply to Alexander Aring

This patch adds a new function to generate a random IEEE 802.15.4 extended address.

---
 include/linux/ieee802154.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/ieee802154.h +14 -0
index a907fe5..d043449 100644
@@ -24,6 +24,7 @@
 #define LINUX_IEEE802154_H
 
 #include <linux/types.h>
+#include <linux/random.h>
 #include <asm/byteorder.h>
 
 #define IEEE802154_MTU			127
@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
 		(addr != cpu_to_le64(0xffffffffffffffffULL)));
 }
 
+/**
+ * ieee802154_random_extended_addr - generates a random extended address
+ * @addr: extended addr pointer to place the random address
+ */
+static inline void ieee802154_random_extended_addr(__le64 *addr)
+{
+	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
+
+	/* toggle some bit if we hit an invalid extended addr */
+	if (!ieee802154_is_valid_extended_addr(*addr))
+		((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;
+}
+
 #endif /* LINUX_IEEE802154_H */
Signature · 1 line
2.1.3
#12 lore raw

Re: [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr

Hi Alex,

I have few doubts on this patch.

Quoted 21 lines · Alexander Aring

This patch adds a new function to generate a random IEEE 802.15.4 extended address.

---
  include/linux/ieee802154.h | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
include/linux/ieee802154.h +1 -0
index a907fe5..d043449 100644
@@ -24,6 +24,7 @@
  #define LINUX_IEEE802154_H
 
  #include <linux/types.h>
+#include <linux/random.h>
  #include <asm/byteorder.h>
 
  #define IEEE802154_MTU			127

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 223

Quoted 8 lines
include/linux/ieee802154.h +5 -0
@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
  		(addr != cpu_to_le64(0xffffffffffffffffULL)));
  }
 
+/**
+ * ieee802154_random_extended_addr - generates a random extended address
+ * @addr: extended addr pointer to place the random address
+ */
+static inline void ieee802154_random_extended_addr(__le64 *addr)

First of all why do we need this functionality. Extended address will be configured by the user by using iz ..?

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 226

Quoted 3 lines
include/linux/ieee802154.h +3 -0
+{
+	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
+

Here we are getting random bytes of 8.

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 229

Quoted 3 lines
include/linux/ieee802154.h +3 -0
+	/* toggle some bit if we hit an invalid extended addr */
+	if (!ieee802154_is_valid_extended_addr(*addr))
+		((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;

If those 8 bytes not a valid addr, then you are toggling last bit, Why..?

Quoted 4 lines
include/linux/ieee802154.h +2 -0
+}
+
  #endif /* LINUX_IEEE802154_H */
Signature · 2 lines
Thanks and Regards,
Varka Bhadram.
author maintainer
#13 lore raw

Re: [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr

Hi,

Quoted 4 lines · Varka Bhadram

Hi Alex,

I have few doubts on this patch.

ok.

Quoted 23 lines · Alexander Aring
Quoted 22 lines

This patch adds a new function to generate a random IEEE 802.15.4 extended address.

---
 include/linux/ieee802154.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/ieee802154.h +1 -0
index a907fe5..d043449 100644
@@ -24,6 +24,7 @@
 #define LINUX_IEEE802154_H
 #include <linux/types.h>
+#include <linux/random.h>
 #include <asm/byteorder.h>
 #define IEEE802154_MTU			127
@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
 		(addr != cpu_to_le64(0xffffffffffffffffULL)));
 }
Quoted 9 lines

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 223

Quoted 5 lines
include/linux/ieee802154.h +5 -0
+/**
+ * ieee802154_random_extended_addr - generates a random extended address
+ * @addr: extended addr pointer to place the random address
+ */
+static inline void ieee802154_random_extended_addr(__le64 *addr)

First of all why do we need this functionality. Extended address will be configured by the user by using iz ..?

We need such function for the perm extended address. The extended address is some unique number. It's an EUI-64 address this should be unique and hardware companies can allocate OUI. The EUI-64 is some combine OUI and device identifier. The perm address can be used that the driver ask the transceiver for serial id or eeprom and set the unique extended address. Also the IEEE 802.15.4-2011 standard describes the default value for an extended address as "Implementation specific". The perm address is now the "Implementation specific" behaviour.

The iz tool sets no perm address, it's just another address than the perm address if you want that. This is also only an optional parameter if this is zero the perm address will be used.

Also we have now a default registration for a wpan interface, this will always use the perm address which is a random extended address now.

We need this function like a random ethernet address. If a transceiver doesn't support some serial id or eeprom where we can generate an EUI-64 address, then we will generate a valid random extended address.

In case of short address the default value is 0xffff. Short address will be assign from coordinators... but we are far away from that to support such behaviour.

Quoted 6 lines

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 226

Quoted 3 lines
include/linux/ieee802154.h +3 -0
+{
+	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
+

Here we are getting random bytes of 8.

correct.

Quoted 6 lines

include/linux/ieee802154.h static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) · line 229

Quoted 3 lines
include/linux/ieee802154.h +3 -0
+	/* toggle some bit if we hit an invalid extended addr */
+	if (!ieee802154_is_valid_extended_addr(*addr))
+		((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;

If those 8 bytes not a valid addr, then you are toggling last bit, Why..?

EUI-64 values 0xff..ff and 0x00..00 are owned by IEEE [0]. The function "ieee802154_is_valid_extended_addr" will return "false" when we hit such address. Now we flip some bit to get out of an invalid IEEE address...

btw. the 0xff..ff will be used as mapping for short broadcast address and 0x00..00 should be the default monitor interface address. (This should be not be changed at runtime, I have patches for this but there is alot of other things where I have patches for it).

[0] https://standards.ieee.org/develop/regauth/tut/eui64.pdf

- Alex

author maintainer
#14 lore raw

PATCH 12/18 mac802154: add ieee802154_le64_to_be64

In reply to Alexander Aring

This patch adds a new function to convert a le64 to a be64. This is useful to translate an extended address to a netdev dev_addr.

---
 include/net/mac802154.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/net/mac802154.h +13 -0
index 10711a6..cc188cb 100644
@@ -17,6 +17,7 @@
 #define NET_MAC802154_H
 
 #include <net/af_ieee802154.h>
+#include <linux/ieee802154.h>
 #include <linux/skbuff.h>
 
 /* General MAC frame format:
@@ -231,6 +232,18 @@ static inline __le64 ieee802154_netdev_to_extended_addr(const void *dev_addr)
 	return (__force __le64)swab64p(dev_addr);
 }
 
+/**
+ * ieee802154_le64_to_be64 - copies and convert le64 to be64
+ * @be64_dst: be64 destination pointer
+ * @le64_src: le64 source pointer
+ */
+static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
+{
+	__be64 tmp = (__force __be64)swab64p(le64_src);
+
+	memcpy(be64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
+}
+
 /* Basic interface to register ieee802154 hwice */
 struct ieee802154_hw *
 ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
Signature · 1 line
2.1.3
author maintainer
#15 lore raw

PATCH 13/18 mac802154: cleanup ieee802154_netdev_to_extended_addr

In reply to Alexander Aring

This patch cleanups the ieee802154_be64_to_le64 to have a similar function like ieee802154_le64_to_be64 only with switched source and destionation types.

---
 include/net/mac802154.h | 11 +++++++----
 net/mac802154/iface.c   |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
include/net/mac802154.h +7 -4
index cc188cb..632f656 100644
@@ -224,12 +224,15 @@ struct ieee802154_ops {
 };
 
 /**
- * ieee802154_netdev_to_extended_addr - convert big endian 64 byte void pointer to __le64
- * @dev_addr: big endian address pointer like netdevice dev_addr attribute
+ * ieee802154_be64_to_le64 - copies and convert be64 to le64
+ * @le64_dst: le64 destination pointer
+ * @be64_src: be64 source pointer
  */
-static inline __le64 ieee802154_netdev_to_extended_addr(const void *dev_addr)
+static inline void ieee802154_be64_to_le64(void *le64_dst, const void *be64_src)
 {
-	return (__force __le64)swab64p(dev_addr);
+	__le64 tmp = (__force __le64)swab64p(be64_src);
+
+	memcpy(le64_dst, &tmp, IEEE802154_EXTENDED_ADDR_LEN);
 }
 
 /**
net/mac802154/iface.c +1 -1
index 764ce49..a1aa09b 100644
@@ -117,7 +117,7 @@ static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
 	if (netif_running(dev))
 		return -EBUSY;
 
-	extended_addr = ieee802154_netdev_to_extended_addr(addr->sa_data);
+	ieee802154_be64_to_le64(&extended_addr, addr->sa_data);
 	if (!ieee802154_is_valid_extended_addr(extended_addr))
 		return -EINVAL;
 
Signature · 1 line
2.1.3
author maintainer
#16 lore raw

PATCH 14/18 mac802154: add support for perm_extended_addr

In reply to Alexander Aring

This patch adding support for a perm extended address. This is useful when a device supports an eeprom with a programmed static extended address. If a device doesn't support such eeprom or serial registers then the driver should generate a random extended address.

---
 include/net/cfg802154.h | 2 ++
 net/mac802154/iface.c   | 4 ++++
 2 files changed, 6 insertions(+)
include/net/cfg802154.h +2 -0
index 57333f1..9d99b96 100644
@@ -57,6 +57,8 @@ struct wpan_phy {
 	u8 csma_retries;
 	s8 frame_retries;
 
+	__le64 perm_extended_addr;
+
 	bool lbt;
 	s32 cca_ed_level;
 
net/mac802154/iface.c +4 -0
index a1aa09b..97e5bed 100644
@@ -410,6 +410,7 @@ 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);
 
@@ -471,6 +472,9 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 		goto err;
 	}
 
+	ieee802154_le64_to_be64(ndev->perm_addr,
+				&local->hw.phy->perm_extended_addr);
+	memcpy(ndev->dev_addr, ndev->perm_addr, IEEE802154_EXTENDED_ADDR_LEN);
 	/* TODO check this */
 	SET_NETDEV_DEV(ndev, &local->phy->dev);
 	sdata = netdev_priv(ndev);
Signature · 1 line
2.1.3
author maintainer
#17 lore raw

PATCH 15/18 at86rf230: generate random perm extended address

In reply to Alexander Aring

This patch adds support for a random generated perm extended address for the at86rf230 driver.

---
 drivers/net/ieee802154/at86rf230.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ieee802154/at86rf230.c +1 -0
index bf47785..a6db768 100644
@@ -1534,6 +1534,7 @@ static int at86rf230_probe(struct spi_device *spi)
 	lp->spi = spi;
 	hw->parent = &spi->dev;
 	hw->vif_data_size = sizeof(*lp);
+	ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
 
 	lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
 	if (IS_ERR(lp->regmap)) {
Signature · 1 line
2.1.3
#18 lore raw

Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address

Quoted 13 lines · Alexander Aring

This patch adds support for a random generated perm extended address for the at86rf230 driver.

---
  drivers/net/ieee802154/at86rf230.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ieee802154/at86rf230.c +0 -0
index bf47785..a6db768 100644

drivers/net/ieee802154/at86rf230.c static int at86rf230_probe(struct spi_device *spi) · line 1540

Quoted 7 lines
drivers/net/ieee802154/at86rf230.c +1 -0
@@ -1534,6 +1534,7 @@ static int at86rf230_probe(struct spi_device *spi)
  lp->spi = spi;
  hw->parent = &spi->dev;
  hw->vif_data_size = sizeof(*lp);
+ ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
 
  lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
  if (IS_ERR(lp->regmap)) {

You are getting this extended address here and configuring at the time of iface add.

This change should be there for other drivers ( CC2520 & MRF24J40 ) also ..?

Signature · 2 lines
Thanks and Regards,
Varka Bhadram.
author maintainer
#19 lore raw

Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address

Quoted 19 lines · Varka Bhadram
Quoted 18 lines · Alexander Aring

This patch adds support for a random generated perm extended address for the at86rf230 driver.

---
  drivers/net/ieee802154/at86rf230.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ieee802154/at86rf230.c +1 -0
index bf47785..a6db768 100644
@@ -1534,6 +1534,7 @@ static int at86rf230_probe(struct spi_device *spi)
  lp->spi = spi;
  hw->parent = &spi->dev;
  hw->vif_data_size = sizeof(*lp);
+ ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
 
Quoted 8 lines

drivers/net/ieee802154/at86rf230.c static int at86rf230_probe(struct spi_device *spi) · line 1540

Quoted 2 lines
drivers/net/ieee802154/at86rf230.c +0 -0
  lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
  if (IS_ERR(lp->regmap)) {

You are getting this extended address here and configuring at the time of iface add.

This change should be there for other drivers ( CC2520 & MRF24J40 ) also ..?

yes, but please refer before if these transceivers supports some eeprom or serial id where the extended addr could be generated from.

Otherwise we need to generate a random one. This value can also get from device tree or extended addr, but we are far away to support such behaviour. If somebody wants to implement this, please send patches to me and device tree ml.

- Alex

author maintainer
#20 lore raw

Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address

Varka,

Quoted 29 lines · Alexander Aring
Quoted 19 lines · Varka Bhadram
Quoted 18 lines · Alexander Aring

This patch adds support for a random generated perm extended address for the at86rf230 driver.

---
  drivers/net/ieee802154/at86rf230.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ieee802154/at86rf230.c +1 -0
index bf47785..a6db768 100644
@@ -1534,6 +1534,7 @@ static int at86rf230_probe(struct spi_device *spi)
  lp->spi = spi;
  hw->parent = &spi->dev;
  hw->vif_data_size = sizeof(*lp);
+ ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
 
Quoted 8 lines

drivers/net/ieee802154/at86rf230.c static int at86rf230_probe(struct spi_device *spi) · line 1540

Quoted 2 lines
drivers/net/ieee802154/at86rf230.c +0 -0
  lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
  if (IS_ERR(lp->regmap)) {

You are getting this extended address here and configuring at the time of iface add.

This change should be there for other drivers ( CC2520 & MRF24J40 ) also ..?

Quoted 8 lines

yes, but please refer before if these transceivers supports some eeprom or serial id where the extended addr could be generated from.

Otherwise we need to generate a random one. This value can also get from device tree or extended addr, but we are far away to support such behaviour. If somebody wants to implement this, please send patches to me and device tree ml.

what's about this, to having a zero address perm_extended_addr address is defintly a bug in your driver.

My respone here was more a (this is not really c, but mention what I meant here):

switch (CC2520_supports)
case EEPROM_FOR_EUI64:

	perm_extended_addr = readout_eeprom;
	break;
case SERIAL_ID_REGISTERS_FOR_EUI64:
	perm_extended_addr = readout_registers;
	break;
default:
	perm_extended_addr = generate_random_one;
}

So if you don't have case 1 and 2, then generate a random one.

Also please check for reset values for phy settings like current_channel, current_page...

Maybe wait some time when cca handling patches are in then you can changes also the cca mode to the default value after reset.

- Alex

A message that is not in the archive (sent off-list or not yet received): CAEUmHya_1iG9Rs-Wq+bq8MT2rwjgG_zUvr8wB-zTLnSCyj-StA@mail.gmail.com

author maintainer
#22 lore raw

Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address

Hi Varka,

Quoted 5 lines · Varka Bhadram

For CC2520 the extended address is software defined. So the default case is possible for CC2520.

We may need to add ieee802154_random_extended_addr().

ok, this sounds good.

I think if the transceiver chip doesn't support such function it could be that some board designer for the transceiver place some eeprom on it.

What I mean is somebody builds a CC2520 transceiver board with an eeprom. The eeprom contains the EUI-64 address. Then we need some mechanism to connect them (I think the common way is devicetree) to readout the eeprom and set the perm address.

I think this should not touch the driver layer, so random extended addr should be fine. The same is for an eeprom which is placed on the dev board and contains the necessary EUI-64 address information.

This is for some further 802.15.4 work.

- Alex

author maintainer
#23 lore raw

PATCH 16/18 at86rf230: add force slotted operation bit

In reply to Alexander Aring

This patch adds a force setting of slotted operation bit. The atben chips sometimes set these bit. The reason is unknown. Nevertheless we don't support slotted operation so we set this bit now force while probing.

---
 drivers/net/ieee802154/at86rf230.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ieee802154/at86rf230.c +8 -0
index a6db768..a3cc7d9 100644
@@ -1358,6 +1358,14 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 		return -EINVAL;
 	}
 
+	/* Force setting slotted operation bit to 0. Sometimes the atben
+	 * sets this bit and I don't know why. We set this always force
+	 * to zero while probing.
+	 */
+	rc = at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0);
+	if (rc)
+		return rc;
+
 	return 0;
 }
 
Signature · 1 line
2.1.3
author maintainer
#24 lore raw

PATCH 17/18 mac802154: use IEEE802154_EXTENDED_ADDR_LEN

In reply to Alexander Aring

This patch removes the af_ieee802154 defines and use the IEEE802154_EXTENDED_ADDR_LEN. We should do this everywhere in the 802.15.4 subsystem because af_ieee802154 should be normally an uapi header.

---
 net/mac802154/iface.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/mac802154/iface.c +2 -3
index 97e5bed..51abe05 100644
@@ -24,7 +24,6 @@
 
 #include <net/rtnetlink.h>
 #include <linux/nl802154.h>
-#include <net/af_ieee802154.h>
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
 #include <net/cfg802154.h>
@@ -384,8 +383,8 @@ static void mac802154_wpan_free(struct net_device *dev)
 
 static void ieee802154_if_setup(struct net_device *dev)
 {
-	dev->addr_len		= IEEE802154_ADDR_LEN;
-	memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
+	dev->addr_len		= IEEE802154_EXTENDED_ADDR_LEN;
+	memset(dev->broadcast, 0xff, IEEE802154_EXTENDED_ADDR_LEN);
 
 	dev->hard_header_len	= MAC802154_FRAME_HARD_HEADER_LEN;
 	dev->needed_tailroom	= 2 + 16; /* FCS + MIC */
Signature · 1 line
2.1.3
author maintainer
#25 lore raw

PATCH 18/18 mac802154: fix typo promisuous to promiscuous

In reply to Alexander Aring
---
 net/mac802154/ieee802154_i.h | 2 +-
 net/mac802154/iface.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
net/mac802154/ieee802154_i.h +1 -1
index 931f851..4acacea 100644
@@ -87,7 +87,7 @@ struct ieee802154_sub_if_data {
 	__le16 pan_id;
 	__le16 short_addr;
 	__le64 extended_addr;
-	bool promisuous_mode;
+	bool promiscuous_mode;
 
 	struct ieee802154_mac_params mac_params;
 
net/mac802154/iface.c +3 -3
index 51abe05..384f4bb 100644
@@ -181,7 +181,7 @@ 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->promisuous_mode);
+		rc = drv_set_promiscuous_mode(local, sdata->promiscuous_mode);
 		if (rc < 0)
 			goto out;
 	}
@@ -419,7 +419,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->promisuous_mode = false;
+		sdata->promiscuous_mode = false;
 
 		spin_lock_init(&sdata->mib_lock);
 		mutex_init(&sdata->sec_mtx);
@@ -429,7 +429,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->promisuous_mode = true;
+		sdata->promiscuous_mode = true;
 		break;
 	default:
 		BUG();
Signature · 1 line
2.1.3
#26 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 51 lines

This patch series contains various changes to make the 802.15.4 implementation similar like wireless/mac80211 implementation. Mainly changes are a complete rework for interface registration handling and supporting for perm address. The perm address can be set by driver layer and is the default "unique" extended address for the wpan_phy. Also we have now a default interface registration. This means a driver registrate a default wpan interface while registration the wpan_phy. No extra interface add handling via userspace tool is needed anymore.

Cc Varka Bhadram <[email protected]>

Alexander Aring (18):
ieee802154: rework wpan_phy index assignment
ieee802154: remove nl802154 unused functions
mac802154: move interface del handling in iface
mac802154: move interface add handling in iface
mac802154: move dev_hold out of ieee802154_if_add
ieee802154: rework interface registration
ieee802154: remove mlme get_phy callback
mac802154: add default interface registration
mac802154: add ieee802154_vif struct
ieee802154: add IEEE802154_EXTENDED_ADDR_LEN
ieee802154: add ieee802154_random_extended_addr
mac802154: add ieee802154_le64_to_be64
mac802154: cleanup ieee802154_netdev_to_extended_addr
mac802154: add support for perm_extended_addr
at86rf230: generate random perm extended address
at86rf230: add force slotted operation bit
mac802154: use IEEE802154_EXTENDED_ADDR_LEN
mac802154: fix typo promisuous to promiscuous

MAINTAINERS                        |   1 -
drivers/net/ieee802154/at86rf230.c |  10 ++
drivers/net/ieee802154/cc2520.c    |   1 +
include/linux/ieee802154.h         |  16 +++
include/net/cfg802154.h            |   7 +-
include/net/ieee802154_netdev.h    |  12 ---
include/net/mac802154.h            |  32 +++++-
include/net/nl802154.h             | 122 -----------------------
net/ieee802154/6lowpan_rtnl.c      |   8 --
net/ieee802154/core.c              |  30 +++---
net/ieee802154/core.h              |   3 +
net/ieee802154/nl-mac.c            | 193 ++-----------------------------------
net/ieee802154/nl-phy.c            |   4 +-
net/mac802154/cfg.c                |  14 ++-
net/mac802154/ieee802154_i.h       |  14 ++-
net/mac802154/iface.c              | 148 +++++++++++++++++++++-------
net/mac802154/mac_cmd.c            |  20 ----
net/mac802154/main.c               |  95 +++---------------
net/mac802154/rx.c                 |   4 +-
19 files changed, 237 insertions(+), 497 deletions(-)
Quoted 1 line

delete mode 100644 include/net/nl802154.h

all 18 patches have been applied to bluetooth-next tree.

Regards

Marcel