linux-wpan.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support
@ 2014-11-05 19:51 Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 01/18] ieee802154: rework wpan_phy index assignment Alexander Aring
                   ` (18 more replies)
  0 siblings, 19 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring, Varka Bhadram

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 <varkabhadram@gmail.com>

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

-- 
2.1.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 01/18] ieee802154: rework wpan_phy index assignment
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 02/18] ieee802154: remove nl802154 unused functions Alexander Aring
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/net/cfg802154.h |  1 -
 net/ieee802154/core.c   | 30 +++++++++++-------------------
 net/ieee802154/core.h   |  3 +++
 3 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 864bce2..29c6de5 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -61,7 +61,6 @@ struct wpan_phy {
 	s32 cca_ed_level;
 
 	struct device dev;
-	int idx;
 
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index ed5b014..d1cd0ed 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -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);
 
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index 1bc1725..fea60b3 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -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
 	 */
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 02/18] ieee802154: remove nl802154 unused functions
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 01/18] ieee802154: rework wpan_phy index assignment Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 03/18] mac802154: move interface del handling in iface Alexander Aring
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 7ec37a3..b42eb50 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
deleted file mode 100644
index b5cdea2..0000000
--- a/include/net/nl802154.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * nl802154.h
- *
- * Copyright (C) 2007, 2008, 2009 Siemens AG
- *
- * 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.
- *
- */
-
-#ifndef IEEE802154_NL_H
-#define IEEE802154_NL_H
-
-struct net_device;
-struct ieee802154_addr;
-
-/**
- * ieee802154_nl_assoc_indic - Notify userland of an association request.
- * @dev: The network device on which this association request was
- *       received.
- * @addr: The address of the device requesting association.
- * @cap: The capability information field from the device.
- *
- * This informs a userland coordinator of a device requesting to
- * associate with the PAN controlled by the coordinator.
- *
- * Note: This is in section 7.3.1 of the IEEE 802.15.4-2006 document.
- */
-int ieee802154_nl_assoc_indic(struct net_device *dev,
-		struct ieee802154_addr *addr, u8 cap);
-
-/**
- * ieee802154_nl_assoc_confirm - Notify userland of association.
- * @dev: The device which has completed association.
- * @short_addr: The short address assigned to the device.
- * @status: The status of the association.
- *
- * Inform userland of the result of an association request. If the
- * association request included asking the coordinator to allocate
- * a short address then it is returned in @short_addr.
- *
- * Note: This is in section 7.3.2 of the IEEE 802.15.4 document.
- */
-int ieee802154_nl_assoc_confirm(struct net_device *dev,
-		__le16 short_addr, u8 status);
-
-/**
- * ieee802154_nl_disassoc_indic - Notify userland of disassociation.
- * @dev: The device on which disassociation was indicated.
- * @addr: The device which is disassociating.
- * @reason: The reason for the disassociation.
- *
- * Inform userland that a device has disassociated from the network.
- *
- * Note: This is in section 7.3.3 of the IEEE 802.15.4 document.
- */
-int ieee802154_nl_disassoc_indic(struct net_device *dev,
-		struct ieee802154_addr *addr, u8 reason);
-
-/**
- * ieee802154_nl_disassoc_confirm - Notify userland of disassociation
- * completion.
- * @dev: The device on which disassociation was ordered.
- * @status: The result of the disassociation.
- *
- * Inform userland of the result of requesting that a device
- * disassociate, or the result of requesting that we disassociate from
- * a PAN managed by another coordinator.
- *
- * Note: This is in section 7.1.4.3 of the IEEE 802.15.4 document.
- */
-int ieee802154_nl_disassoc_confirm(struct net_device *dev,
-		u8 status);
-
-/**
- * ieee802154_nl_scan_confirm - Notify userland of completion of scan.
- * @dev: The device which was instructed to scan.
- * @status: The status of the scan operation.
- * @scan_type: What type of scan was performed.
- * @unscanned: Any channels that the device was unable to scan.
- * @edl: The energy levels (if a passive scan).
- *
- *
- * Note: This is in section 7.1.11 of the IEEE 802.15.4 document.
- * Note: This API does not permit the return of an active scan result.
- */
-int ieee802154_nl_scan_confirm(struct net_device *dev,
-		u8 status, u8 scan_type, u32 unscanned, u8 page,
-		u8 *edl/*, struct list_head *pan_desc_list */);
-
-/**
- * ieee802154_nl_beacon_indic - Notify userland of a received beacon.
- * @dev: The device on which a beacon was received.
- * @panid: The PAN of the coordinator.
- * @coord_addr: The short address of the coordinator on that PAN.
- *
- * Note: This is in section 7.1.5 of the IEEE 802.15.4 document.
- * Note: This API does not provide extended information such as what
- * channel the PAN is on or what the LQI of the beacon frame was on
- * receipt.
- * Note: This API cannot indicate a beacon frame for a coordinator
- *       operating in long addressing mode.
- */
-int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
-		__le16 coord_addr);
-
-/**
- * ieee802154_nl_start_confirm - Notify userland of completion of start.
- * @dev: The device which was instructed to scan.
- * @status: The status of the scan operation.
- *
- * Note: This is in section 7.1.14 of the IEEE 802.15.4 document.
- */
-int ieee802154_nl_start_confirm(struct net_device *dev, u8 status);
-
-#endif
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index cc2919d..91a1855 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -29,7 +29,6 @@
 #include <linux/nl802154.h>
 #include <linux/export.h>
 #include <net/af_ieee802154.h>
-#include <net/nl802154.h>
 #include <net/ieee802154_netdev.h>
 #include <net/cfg802154.h>
 
@@ -55,186 +54,7 @@ static __le16 nla_get_shortaddr(const struct nlattr *nla)
 	return cpu_to_le16(nla_get_u16(nla));
 }
 
-int ieee802154_nl_assoc_indic(struct net_device *dev,
-			      struct ieee802154_addr *addr,
-			      u8 cap)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	if (addr->mode != IEEE802154_ADDR_LONG) {
-		pr_err("%s: received non-long source address!\n", __func__);
-		return -EINVAL;
-	}
-
-	msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr) ||
-	    nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
-			   addr->extended_addr) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
-		goto nla_put_failure;
-
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
-
-int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
-				u8 status)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr) ||
-	    nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
-		goto nla_put_failure;
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
-
-int ieee802154_nl_disassoc_indic(struct net_device *dev,
-				 struct ieee802154_addr *addr,
-				 u8 reason)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr))
-		goto nla_put_failure;
-	if (addr->mode == IEEE802154_ADDR_LONG) {
-		if (nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
-				   addr->extended_addr))
-			goto nla_put_failure;
-	} else {
-		if (nla_put_shortaddr(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
-				      addr->short_addr))
-			goto nla_put_failure;
-	}
-	if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
-		goto nla_put_failure;
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
-
-int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
-		goto nla_put_failure;
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
-
-int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
-			       __le16 coord_addr)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr) ||
-	    nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_SHORT_ADDR,
-			      coord_addr) ||
-	    nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
-		goto nla_put_failure;
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
-
-int ieee802154_nl_scan_confirm(struct net_device *dev,
-			       u8 status, u8 scan_type,
-			       u32 unscanned, u8 page,
-			       u8 *edl/* , struct list_head *pan_desc_list */)
-{
-	struct sk_buff *msg;
-
-	pr_debug("%s\n", __func__);
-
-	msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
-	if (!msg)
-		return -ENOBUFS;
-
-	if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
-	    nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
-		    dev->dev_addr) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) ||
-	    nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) ||
-	    nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) ||
-	    (edl &&
-	     nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
-		goto nla_put_failure;
-	return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
-
-nla_put_failure:
-	nlmsg_free(msg);
-	return -ENOBUFS;
-}
-EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
-
-int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
+static int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
 {
 	struct sk_buff *msg;
 
@@ -530,6 +350,11 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
 	ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
 		bcn_ord, sf_ord, pan_coord, blx, coord_realign);
 
+	/* FIXME: add validation for unused parameters to be sane
+	 * for SoftMAC
+	 */
+	ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
+
 out:
 	dev_put(dev);
 	return ret;
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index 9c2d6f6..e1ad83e 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -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;
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 03/18] mac802154: move interface del handling in iface
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 01/18] ieee802154: rework wpan_phy index assignment Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 02/18] ieee802154: remove nl802154 unused functions Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 04/18] mac802154: move interface add " Alexander Aring
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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(-)

diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 0c69b44..3f9afad 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -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 = {
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 27e17e6..61a6a0f 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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 */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 0c9d00c..9d6012e 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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);
+}
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index b34ddbf..333d33d 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -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)
 {
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 04/18] mac802154: move interface add handling in iface
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (2 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 03/18] mac802154: move interface del handling in iface Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 05/18] mac802154: move dev_hold out of ieee802154_if_add Alexander Aring
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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(-)

diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 3f9afad..0a08f66 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -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,
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 61a6a0f..3ad8540 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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 */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 9d6012e..fced04b 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -444,6 +444,72 @@ void mac802154_monitor_setup(struct net_device *dev)
 	sdata->promisuous_mode = true;
 }
 
+static int
+mac802154_netdev_register(struct ieee802154_local *local,
+			  struct net_device *dev)
+{
+	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
+	int err;
+
+	sdata->dev = dev;
+	sdata->local = local;
+
+	dev->needed_headroom = local->hw.extra_tx_headroom;
+
+	SET_NETDEV_DEV(dev, &local->phy->dev);
+
+	err = register_netdev(dev);
+	if (err < 0)
+		return err;
+
+	rtnl_lock();
+	mutex_lock(&local->iflist_mtx);
+	list_add_tail_rcu(&sdata->list, &local->interfaces);
+	mutex_unlock(&local->iflist_mtx);
+	rtnl_unlock();
+
+	return 0;
+}
+
+struct net_device *
+ieee802154_if_add(struct ieee802154_local *local, const char *name,
+		  struct wpan_dev **new_wpan_dev, int type)
+{
+	struct net_device *dev;
+	int err = -ENOMEM;
+
+	switch (type) {
+	case IEEE802154_DEV_MONITOR:
+		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
+				   name, NET_NAME_UNKNOWN,
+				   mac802154_monitor_setup);
+		break;
+	case IEEE802154_DEV_WPAN:
+		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
+				   name, NET_NAME_UNKNOWN,
+				   mac802154_wpan_setup);
+		break;
+	default:
+		dev = NULL;
+		err = -EINVAL;
+		break;
+	}
+	if (!dev)
+		goto err;
+
+	err = mac802154_netdev_register(local, dev);
+	if (err)
+		goto err_free;
+
+	dev_hold(dev); /* we return an incremented device refcount */
+	return dev;
+
+err_free:
+	free_netdev(dev);
+err:
+	return ERR_PTR(err);
+}
+
 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
 {
 	ASSERT_RTNL();
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 333d33d..a371eb5 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -30,73 +30,6 @@
 #include "ieee802154_i.h"
 #include "cfg.h"
 
-static int
-mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
-{
-	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-	struct ieee802154_local *local;
-	int err;
-
-	local = wpan_phy_priv(phy);
-
-	sdata->dev = dev;
-	sdata->local = local;
-
-	dev->needed_headroom = local->hw.extra_tx_headroom;
-
-	SET_NETDEV_DEV(dev, &local->phy->dev);
-
-	err = register_netdev(dev);
-	if (err < 0)
-		return err;
-
-	rtnl_lock();
-	mutex_lock(&local->iflist_mtx);
-	list_add_tail_rcu(&sdata->list, &local->interfaces);
-	mutex_unlock(&local->iflist_mtx);
-	rtnl_unlock();
-
-	return 0;
-}
-
-struct net_device *
-mac802154_add_iface(struct wpan_phy *phy, const char *name, int type)
-{
-	struct net_device *dev;
-	int err = -ENOMEM;
-
-	switch (type) {
-	case IEEE802154_DEV_MONITOR:
-		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
-				   name, NET_NAME_UNKNOWN,
-				   mac802154_monitor_setup);
-		break;
-	case IEEE802154_DEV_WPAN:
-		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
-				   name, NET_NAME_UNKNOWN,
-				   mac802154_wpan_setup);
-		break;
-	default:
-		dev = NULL;
-		err = -EINVAL;
-		break;
-	}
-	if (!dev)
-		goto err;
-
-	err = mac802154_netdev_register(phy, dev);
-	if (err)
-		goto err_free;
-
-	dev_hold(dev); /* we return an incremented device refcount */
-	return dev;
-
-err_free:
-	free_netdev(dev);
-err:
-	return ERR_PTR(err);
-}
-
 static void ieee802154_tasklet_handler(unsigned long data)
 {
 	struct ieee802154_local *local = (struct ieee802154_local *)data;
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 05/18] mac802154: move dev_hold out of ieee802154_if_add
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (3 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 04/18] mac802154: move interface add " Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 06/18] ieee802154: rework interface registration Alexander Aring
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/nl-phy.c | 1 +
 net/mac802154/iface.c   | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 5d914d3..397ca126 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -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;
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index fced04b..78cb381 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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:
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 06/18] ieee802154: rework interface registration
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (4 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 05/18] mac802154: move dev_hold out of ieee802154_if_add Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 07/18] ieee802154: remove mlme get_phy callback Alexander Aring
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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(-)

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 29c6de5..57333f1 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -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 *
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 0a08f66..d2c4e8f 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -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,
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 3ad8540..748dc5a 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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;
 
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 78cb381..f9ed608 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -381,30 +381,23 @@ static void mac802154_wpan_free(struct net_device *dev)
 	free_netdev(dev);
 }
 
-void mac802154_wpan_setup(struct net_device *dev)
+static void ieee802154_if_setup(struct net_device *dev)
 {
-	struct ieee802154_sub_if_data *sdata;
-
 	dev->addr_len		= IEEE802154_ADDR_LEN;
 	memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
 
 	dev->hard_header_len	= MAC802154_FRAME_HARD_HEADER_LEN;
-	dev->header_ops		= &mac802154_header_ops;
 	dev->needed_tailroom	= 2 + 16; /* FCS + MIC */
 	dev->mtu		= IEEE802154_MTU;
 	dev->tx_queue_len	= 300;
-	dev->type		= ARPHRD_IEEE802154;
 	dev->flags		= IFF_NOARP | IFF_BROADCAST;
+}
 
-	dev->destructor		= mac802154_wpan_free;
-	dev->netdev_ops		= &mac802154_wpan_ops;
-	dev->ml_priv		= &mac802154_mlme_wpan;
-
-	sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-	sdata->type = IEEE802154_DEV_WPAN;
-
-	spin_lock_init(&sdata->mib_lock);
-	mutex_init(&sdata->sec_mtx);
+static int
+ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
+{
+	/* set some type-dependent values */
+	sdata->type = type;
 
 	get_random_bytes(&sdata->bsn, 1);
 	get_random_bytes(&sdata->dsn, 1);
@@ -419,54 +412,28 @@ void mac802154_wpan_setup(struct net_device *dev)
 	sdata->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
 	sdata->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
 
-	sdata->promisuous_mode = false;
-
-	mac802154_llsec_init(&sdata->sec);
-}
-
-void mac802154_monitor_setup(struct net_device *dev)
-{
-	struct ieee802154_sub_if_data *sdata;
-
-	dev->needed_tailroom	= 2; /* room for FCS */
-	dev->mtu		= IEEE802154_MTU;
-	dev->tx_queue_len	= 10;
-	dev->type		= ARPHRD_IEEE802154_MONITOR;
-	dev->flags		= IFF_NOARP | IFF_BROADCAST;
-
-	dev->destructor		= free_netdev;
-	dev->netdev_ops		= &mac802154_monitor_ops;
-	dev->ml_priv		= &mac802154_mlme_reduced;
-
-	sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-	sdata->type = IEEE802154_DEV_MONITOR;
-
-	sdata->promisuous_mode = true;
-}
-
-static int
-mac802154_netdev_register(struct ieee802154_local *local,
-			  struct net_device *dev)
-{
-	struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
-	int err;
-
-	sdata->dev = dev;
-	sdata->local = local;
-
-	dev->needed_headroom = local->hw.extra_tx_headroom;
-
-	SET_NETDEV_DEV(dev, &local->phy->dev);
+	switch (type) {
+	case IEEE802154_DEV_WPAN:
+		sdata->dev->header_ops = &mac802154_header_ops;
+		sdata->dev->destructor = mac802154_wpan_free;
+		sdata->dev->netdev_ops = &mac802154_wpan_ops;
+		sdata->dev->ml_priv = &mac802154_mlme_wpan;
+		sdata->promisuous_mode = false;
 
-	err = register_netdev(dev);
-	if (err < 0)
-		return err;
+		spin_lock_init(&sdata->mib_lock);
+		mutex_init(&sdata->sec_mtx);
 
-	rtnl_lock();
-	mutex_lock(&local->iflist_mtx);
-	list_add_tail_rcu(&sdata->list, &local->interfaces);
-	mutex_unlock(&local->iflist_mtx);
-	rtnl_unlock();
+		mac802154_llsec_init(&sdata->sec);
+		break;
+	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:
+		BUG();
+	}
 
 	return 0;
 }
@@ -475,38 +442,67 @@ struct net_device *
 ieee802154_if_add(struct ieee802154_local *local, const char *name,
 		  struct wpan_dev **new_wpan_dev, int type)
 {
-	struct net_device *dev;
-	int err = -ENOMEM;
+	struct net_device *ndev = NULL;
+	struct ieee802154_sub_if_data *sdata = NULL;
+	int ret = -ENOMEM;
+
+	ASSERT_RTNL();
+
+	ndev = alloc_netdev(sizeof(*sdata), name, NET_NAME_UNKNOWN,
+			    ieee802154_if_setup);
+	if (!ndev)
+		return ERR_PTR(-ENOMEM);
+
+	ndev->needed_headroom = local->hw.extra_tx_headroom;
+
+	ret = dev_alloc_name(ndev, ndev->name);
+	if (ret < 0)
+		goto err;
 
 	switch (type) {
-	case IEEE802154_DEV_MONITOR:
-		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
-				   name, NET_NAME_UNKNOWN,
-				   mac802154_monitor_setup);
-		break;
 	case IEEE802154_DEV_WPAN:
-		dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data),
-				   name, NET_NAME_UNKNOWN,
-				   mac802154_wpan_setup);
+		ndev->type = ARPHRD_IEEE802154;
 		break;
-	default:
-		dev = NULL;
-		err = -EINVAL;
+	case IEEE802154_DEV_MONITOR:
+		ndev->type = ARPHRD_IEEE802154_MONITOR;
 		break;
+	default:
+		ret = -EINVAL;
+		goto err;
 	}
-	if (!dev)
+
+	/* TODO check this */
+	SET_NETDEV_DEV(ndev, &local->phy->dev);
+	sdata = netdev_priv(ndev);
+	ndev->ieee802154_ptr = &sdata->wpan_dev;
+	memcpy(sdata->name, ndev->name, IFNAMSIZ);
+	sdata->dev = ndev;
+	sdata->wpan_dev.wpan_phy = local->hw.phy;
+	sdata->local = local;
+
+	/* setup type-dependent data */
+	ret = ieee802154_setup_sdata(sdata, type);
+	if (ret)
 		goto err;
 
-	err = mac802154_netdev_register(local, dev);
-	if (err)
-		goto err_free;
+	if (ndev) {
+		ret = register_netdevice(ndev);
+		if (ret < 0)
+			goto err;
+	}
+
+	mutex_lock(&local->iflist_mtx);
+	list_add_tail_rcu(&sdata->list, &local->interfaces);
+	mutex_unlock(&local->iflist_mtx);
 
-	return dev;
+	if (new_wpan_dev)
+		*new_wpan_dev = &sdata->wpan_dev;
+
+	return ndev;
 
-err_free:
-	free_netdev(dev);
 err:
-	return ERR_PTR(err);
+	free_netdev(ndev);
+	return ERR_PTR(ret);
 }
 
 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 07/18] ieee802154: remove mlme get_phy callback
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (5 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 06/18] ieee802154: rework interface registration Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 08/18] mac802154: add default interface registration Alexander Aring
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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(-)

diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h
index 5e62d75..83bb8a73 100644
--- a/include/net/ieee802154_netdev.h
+++ b/include/net/ieee802154_netdev.h
@@ -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)
 {
diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
index 659f7b2..a96b64c 100644
--- a/net/ieee802154/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan_rtnl.c
@@ -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,
 };
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 91a1855..7127b9d 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -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);
 
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 397ca126..80a946d 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -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 */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index f9ed608..2e2638e 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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:
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index e1ad83e..00b2b21 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -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,
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 08/18] mac802154: add default interface registration
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (6 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 07/18] ieee802154: remove mlme get_phy callback Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 09/18] mac802154: add ieee802154_vif struct Alexander Aring
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/mac802154/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index a371eb5..7d0ff7f 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -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:
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 09/18] mac802154: add ieee802154_vif struct
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (7 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 08/18] mac802154: add default interface registration Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 10/18] ieee802154: add IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring, Varka Bhadram

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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Cc: Varka Bhadram <varkabhadram@gmail.com>
---
 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(-)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index f68ebba..bf47785 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -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)) {
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
index 340671b..ccbb082 100644
--- a/drivers/net/ieee802154/cc2520.c
+++ b/drivers/net/ieee802154/cc2520.c
@@ -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;
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 8b0c26b..10711a6 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -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
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 748dc5a..931f851 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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 */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 2e2638e..764ce49 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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);
 
diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c
index 95961cc..4b54cf3 100644
--- a/net/mac802154/rx.c
+++ b/net/mac802154/rx.c
@@ -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))
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 10/18] ieee802154: add IEEE802154_EXTENDED_ADDR_LEN
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (8 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 09/18] mac802154: add ieee802154_vif struct Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr Alexander Aring
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

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

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/linux/ieee802154.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
index 4c03286..a907fe5 100644
--- a/include/linux/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -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 */
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (9 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 10/18] ieee802154: add IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-06  1:54   ` Varka Bhadram
  2014-11-05 19:51 ` [PATCH bluetooth-next 12/18] mac802154: add ieee802154_le64_to_be64 Alexander Aring
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

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

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/linux/ieee802154.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
index a907fe5..d043449 100644
--- a/include/linux/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -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 */
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 12/18] mac802154: add ieee802154_le64_to_be64
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (10 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 13/18] mac802154: cleanup ieee802154_netdev_to_extended_addr Alexander Aring
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/net/mac802154.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index 10711a6..cc188cb 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -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);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 13/18] mac802154: cleanup ieee802154_netdev_to_extended_addr
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (11 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 12/18] mac802154: add ieee802154_le64_to_be64 Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 14/18] mac802154: add support for perm_extended_addr Alexander Aring
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/net/mac802154.h | 11 +++++++----
 net/mac802154/iface.c   |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index cc188cb..632f656 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -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);
 }
 
 /**
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 764ce49..a1aa09b 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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;
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 14/18] mac802154: add support for perm_extended_addr
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (12 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 13/18] mac802154: cleanup ieee802154_netdev_to_extended_addr Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address Alexander Aring
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 include/net/cfg802154.h | 2 ++
 net/mac802154/iface.c   | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 57333f1..9d99b96 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -57,6 +57,8 @@ struct wpan_phy {
 	u8 csma_retries;
 	s8 frame_retries;
 
+	__le64 perm_extended_addr;
+
 	bool lbt;
 	s32 cca_ed_level;
 
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index a1aa09b..97e5bed 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (13 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 14/18] mac802154: add support for perm_extended_addr Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-06  5:52   ` Varka Bhadram
  2014-11-05 19:51 ` [PATCH bluetooth-next 16/18] at86rf230: add force slotted operation bit Alexander Aring
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

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

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 drivers/net/ieee802154/at86rf230.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index bf47785..a6db768 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -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)) {
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 16/18] at86rf230: add force slotted operation bit
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (14 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 17/18] mac802154: use IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 drivers/net/ieee802154/at86rf230.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index a6db768..a3cc7d9 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -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;
 }
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 17/18] mac802154: use IEEE802154_EXTENDED_ADDR_LEN
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (15 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 16/18] at86rf230: add force slotted operation bit Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 19:51 ` [PATCH bluetooth-next 18/18] mac802154: fix typo promisuous to promiscuous Alexander Aring
  2014-11-05 20:54 ` [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Marcel Holtmann
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/mac802154/iface.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 97e5bed..51abe05 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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 */
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH bluetooth-next 18/18] mac802154: fix typo promisuous to promiscuous
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (16 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 17/18] mac802154: use IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
@ 2014-11-05 19:51 ` Alexander Aring
  2014-11-05 20:54 ` [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Marcel Holtmann
  18 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-05 19:51 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/mac802154/ieee802154_i.h | 2 +-
 net/mac802154/iface.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index 931f851..4acacea 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -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;
 
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 51abe05..384f4bb 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -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();
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support
  2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
                   ` (17 preceding siblings ...)
  2014-11-05 19:51 ` [PATCH bluetooth-next 18/18] mac802154: fix typo promisuous to promiscuous Alexander Aring
@ 2014-11-05 20:54 ` Marcel Holtmann
  18 siblings, 0 replies; 26+ messages in thread
From: Marcel Holtmann @ 2014-11-05 20:54 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-wpan, kernel, Varka Bhadram

Hi Alex,

> 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 <varkabhadram@gmail.com>
> 
> 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

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

Regards

Marcel


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr
  2014-11-05 19:51 ` [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr Alexander Aring
@ 2014-11-06  1:54   ` Varka Bhadram
  2014-11-06 10:03     ` Alexander Aring
  0 siblings, 1 reply; 26+ messages in thread
From: Varka Bhadram @ 2014-11-06  1:54 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan; +Cc: kernel

Hi Alex,

I have few doubts on this patch.

On Thursday 06 November 2014 01:21 AM, Alexander Aring wrote:

> This patch adds a new function to generate a random IEEE 802.15.4
> extended address.
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
>   include/linux/ieee802154.h | 14 ++++++++++++++
>   1 file changed, 14 insertions(+)
>
> diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
> index a907fe5..d043449 100644
> --- a/include/linux/ieee802154.h
> +++ b/include/linux/ieee802154.h
> @@ -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)

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

> +{
> +	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
> +

Here we are getting random bytes of 8.

> +	/* 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..?

> +}
> +
>   #endif /* LINUX_IEEE802154_H */
>

-- 
Thanks and Regards,
Varka Bhadram.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address
  2014-11-05 19:51 ` [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address Alexander Aring
@ 2014-11-06  5:52   ` Varka Bhadram
  2014-11-06 10:05     ` Alexander Aring
  0 siblings, 1 reply; 26+ messages in thread
From: Varka Bhadram @ 2014-11-06  5:52 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan - ML; +Cc: kernel

On Thursday 06 November 2014 01:21 AM, Alexander Aring wrote:
> This patch adds support for a random generated perm extended address for
> the at86rf230 driver.
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
>   drivers/net/ieee802154/at86rf230.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
> index bf47785..a6db768 100644
> --- a/drivers/net/ieee802154/at86rf230.c
> +++ b/drivers/net/ieee802154/at86rf230.c
> @@ -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 ..?

-- 
Thanks and Regards,
Varka Bhadram.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr
  2014-11-06  1:54   ` Varka Bhadram
@ 2014-11-06 10:03     ` Alexander Aring
  0 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-11-06 10:03 UTC (permalink / raw)
  To: Varka Bhadram; +Cc: linux-wpan, kernel

Hi,

On Thu, Nov 06, 2014 at 07:24:37AM +0530, Varka Bhadram wrote:
> Hi Alex,
> 
> I have few doubts on this patch.
> 

ok.

> On Thursday 06 November 2014 01:21 AM, Alexander Aring wrote:
> 
> >This patch adds a new function to generate a random IEEE 802.15.4
> >extended address.
> >
> >Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> >---
> >  include/linux/ieee802154.h | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> >diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
> >index a907fe5..d043449 100644
> >--- a/include/linux/ieee802154.h
> >+++ b/include/linux/ieee802154.h
> >@@ -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)
> 
> 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.

> >+{
> >+	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
> >+
> 
> Here we are getting random bytes of 8.
> 

correct.

> >+	/* 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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address
  2014-11-06  5:52   ` Varka Bhadram
@ 2014-11-06 10:05     ` Alexander Aring
  2014-12-12 14:56       ` Alexander Aring
  0 siblings, 1 reply; 26+ messages in thread
From: Alexander Aring @ 2014-11-06 10:05 UTC (permalink / raw)
  To: Varka Bhadram; +Cc: linux-wpan - ML, kernel

On Thu, Nov 06, 2014 at 11:22:45AM +0530, Varka Bhadram wrote:
> On Thursday 06 November 2014 01:21 AM, Alexander Aring wrote:
> > This patch adds support for a random generated perm extended address for
> > the at86rf230 driver.
> >
> > Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> > ---
> >   drivers/net/ieee802154/at86rf230.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
> > index bf47785..a6db768 100644
> > --- a/drivers/net/ieee802154/at86rf230.c
> > +++ b/drivers/net/ieee802154/at86rf230.c
> > @@ -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 ..?
> 

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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address
  2014-11-06 10:05     ` Alexander Aring
@ 2014-12-12 14:56       ` Alexander Aring
       [not found]         ` <CAEUmHya_1iG9Rs-Wq+bq8MT2rwjgG_zUvr8wB-zTLnSCyj-StA@mail.gmail.com>
  0 siblings, 1 reply; 26+ messages in thread
From: Alexander Aring @ 2014-12-12 14:56 UTC (permalink / raw)
  To: Varka Bhadram; +Cc: linux-wpan - ML, kernel

Varka,

On Thu, Nov 06, 2014 at 11:05:52AM +0100, Alexander Aring wrote:
> On Thu, Nov 06, 2014 at 11:22:45AM +0530, Varka Bhadram wrote:
> > On Thursday 06 November 2014 01:21 AM, Alexander Aring wrote:
> > > This patch adds support for a random generated perm extended address for
> > > the at86rf230 driver.
> > >
> > > Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> > > ---
> > >   drivers/net/ieee802154/at86rf230.c | 1 +
> > >   1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
> > > index bf47785..a6db768 100644
> > > --- a/drivers/net/ieee802154/at86rf230.c
> > > +++ b/drivers/net/ieee802154/at86rf230.c
> > > @@ -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 ..?
> > 
> 
> 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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address
       [not found]         ` <CAEUmHya_1iG9Rs-Wq+bq8MT2rwjgG_zUvr8wB-zTLnSCyj-StA@mail.gmail.com>
@ 2014-12-13  9:08           ` Alexander Aring
  0 siblings, 0 replies; 26+ messages in thread
From: Alexander Aring @ 2014-12-13  9:08 UTC (permalink / raw)
  To: Varka Bhadram; +Cc: linux-wpan - ML, kernel

Hi Varka,

On Sat, Dec 13, 2014 at 10:28:24AM +0530, Varka Bhadram wrote:
> 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

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2014-12-13  9:08 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-05 19:51 [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 01/18] ieee802154: rework wpan_phy index assignment Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 02/18] ieee802154: remove nl802154 unused functions Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 03/18] mac802154: move interface del handling in iface Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 04/18] mac802154: move interface add " Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 05/18] mac802154: move dev_hold out of ieee802154_if_add Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 06/18] ieee802154: rework interface registration Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 07/18] ieee802154: remove mlme get_phy callback Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 08/18] mac802154: add default interface registration Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 09/18] mac802154: add ieee802154_vif struct Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 10/18] ieee802154: add IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 11/18] ieee802154: add ieee802154_random_extended_addr Alexander Aring
2014-11-06  1:54   ` Varka Bhadram
2014-11-06 10:03     ` Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 12/18] mac802154: add ieee802154_le64_to_be64 Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 13/18] mac802154: cleanup ieee802154_netdev_to_extended_addr Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 14/18] mac802154: add support for perm_extended_addr Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 15/18] at86rf230: generate random perm extended address Alexander Aring
2014-11-06  5:52   ` Varka Bhadram
2014-11-06 10:05     ` Alexander Aring
2014-12-12 14:56       ` Alexander Aring
     [not found]         ` <CAEUmHya_1iG9Rs-Wq+bq8MT2rwjgG_zUvr8wB-zTLnSCyj-StA@mail.gmail.com>
2014-12-13  9:08           ` Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 16/18] at86rf230: add force slotted operation bit Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 17/18] mac802154: use IEEE802154_EXTENDED_ADDR_LEN Alexander Aring
2014-11-05 19:51 ` [PATCH bluetooth-next 18/18] mac802154: fix typo promisuous to promiscuous Alexander Aring
2014-11-05 20:54 ` [PATCH bluetooth-next 00/18] ieee802154: interface registration and perm address support 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).