Skip to contentSkip to conversation

ieee802154: cleanups, nl802154 iface handling and byteorder fixes

PATCH In review Alexander Aring 2 participants 15 messages Nov 17, 2014

Subsystems (3)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover ieee802154: cleanups, nl802154 iface handling and byteorder fixes

This patch series contains various cleanups and adding new nl802154 commands for supporting interface handling. At least we fix some byteorder issues. The nl802154 interface uses little endian byteorder now. This is the same byteorder like 802.15.4 MAC layer. The nl802154 interface is new, so we should fix the byteorder issue now.

Alexander Aring (13):
mac802154: remove unused prototypes
at86rf230: fix commentation for symbol duration
mac802154: remove const for non pointer in driver-ops
mac802154: remove const for non pointer in cfg ops
mac802154: remove const for non pointer in rdev-ops
mac802154: remove deprecated linux-zigbee info
mac802154: use new nl802154 iftype types
mac802154: remove wpan_dev parameter in if_add
ieee802154: add new interface command
ieee802154: setting extended address while iface add
ieee802154: add del interface command
ieee802154: rename and move WPAN_NUM_ defines
ieee802154: fix byteorder for short address and panid

 drivers/net/ieee802154/at86rf230.c |  4 +-
 include/linux/ieee802154.h         |  3 ++
 include/net/cfg802154.h            | 21 +++++-----
 net/ieee802154/nl802154.c          | 80 +++++++++++++++++++++++++++++++++++---
 net/ieee802154/rdev-ops.h          | 33 ++++++++++------
 net/mac802154/cfg.c                | 69 ++++++++++++++++++++++----------
 net/mac802154/driver-ops.h         | 46 ++++++++++------------
 net/mac802154/ieee802154_i.h       | 15 +++----
 net/mac802154/iface.c              | 31 ++++++++-------
 net/mac802154/main.c               |  7 ++--
 net/mac802154/rx.c                 |  7 ++--
 11 files changed, 211 insertions(+), 105 deletions(-)
Signature · 1 line
2.1.3
author maintainer
#1 lore raw

PATCH 1/13 mac802154: remove unused prototypes

This patch removes some prototypes which are not used anymore.

---
 net/mac802154/ieee802154_i.h | 6 ------
 1 file changed, 6 deletions(-)
net/mac802154/ieee802154_i.h +0 -6
index c5b2310..593339a 100644
@@ -120,14 +120,10 @@ ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
 	return test_bit(SDATA_STATE_RUNNING, &sdata->state);
 }
 
-extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced;
 extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
 
-void mac802154_monitor_setup(struct net_device *dev);
 netdev_tx_t
 ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
-
-void mac802154_wpan_setup(struct net_device *dev);
 netdev_tx_t
 ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
 enum hrtimer_restart ieee802154_xmit_ifs_timer(struct hrtimer *timer);
@@ -176,8 +172,6 @@ void mac802154_unlock_table(struct net_device *dev);
 /* interface handling */
 int ieee802154_iface_init(void);
 void ieee802154_iface_exit(void);
-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,
Signature · 1 line
2.1.3
author maintainer
#2 lore raw

PATCH 2/13 at86rf230: fix commentation for symbol duration

In reply to Alexander Aring

This patch fix an copy&paste issue in the comment of setting symbol duration. These comments are more correct according the at86rf212 datasheet now.

---
 drivers/net/ieee802154/at86rf230.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ieee802154/at86rf230.c +2 -2
index 7278e18..1c01356 100644
@@ -1043,10 +1043,10 @@ at86rf212_set_channel(struct at86rf230_local *lp, u8 page, u8 channel)
 		}
 	} else {
 		if (page == 0)
-			/* SUB:0 and BPSK:1 -> BPSK-20 */
+			/* SUB:0 and BPSK:1 -> OQPSK-100/200/400 */
 			lp->hw->phy->symbol_duration = 40;
 		else
-			/* SUB:1 and BPSK:1 -> BPSK-20 */
+			/* SUB:1 and BPSK:1 -> OQPSK-250/500/1000 */
 			lp->hw->phy->symbol_duration = 16;
 	}
 
Signature · 1 line
2.1.3
author maintainer
#3 lore raw

PATCH 3/13 mac802154: remove const for non pointer in driver-ops

In reply to Alexander Aring

This patches removes the const keyword in variables which are non pointers. There is no sense to declare call by value parameters as const.

---
 net/mac802154/driver-ops.h | 46 +++++++++++++++++++++-------------------------
 1 file changed, 21 insertions(+), 25 deletions(-)
net/mac802154/driver-ops.h +21 -25
index dfd29ff..f21e864 100644
@@ -50,16 +50,15 @@ static inline void drv_stop(struct ieee802154_local *local)
 	local->started = false;
 }
 
-static inline int drv_set_channel(struct ieee802154_local *local,
-				  const u8 page, const u8 channel)
+static inline int
+drv_set_channel(struct ieee802154_local *local, u8 page, u8 channel)
 {
 	might_sleep();
 
 	return local->ops->set_channel(&local->hw, page, channel);
 }
 
-static inline int drv_set_tx_power(struct ieee802154_local *local,
-				   const s8 dbm)
+static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm)
 {
 	might_sleep();
 
@@ -71,8 +70,7 @@ static inline int drv_set_tx_power(struct ieee802154_local *local,
 	return local->ops->set_txpower(&local->hw, dbm);
 }
 
-static inline int drv_set_cca_mode(struct ieee802154_local *local,
-				   const u8 cca_mode)
+static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode)
 {
 	might_sleep();
 
@@ -84,8 +82,7 @@ static inline int drv_set_cca_mode(struct ieee802154_local *local,
 	return local->ops->set_cca_mode(&local->hw, cca_mode);
 }
 
-static inline int drv_set_lbt_mode(struct ieee802154_local *local,
-				   const bool mode)
+static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
 {
 	might_sleep();
 
@@ -97,8 +94,8 @@ static inline int drv_set_lbt_mode(struct ieee802154_local *local,
 	return local->ops->set_lbt(&local->hw, mode);
 }
 
-static inline int drv_set_cca_ed_level(struct ieee802154_local *local,
-				       const s32 ed_level)
+static inline int
+drv_set_cca_ed_level(struct ieee802154_local *local, s32 ed_level)
 {
 	might_sleep();
 
@@ -110,8 +107,7 @@ static inline int drv_set_cca_ed_level(struct ieee802154_local *local,
 	return local->ops->set_cca_ed_level(&local->hw, ed_level);
 }
 
-static inline int drv_set_pan_id(struct ieee802154_local *local,
-				 const __le16 pan_id)
+static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id)
 {
 	struct ieee802154_hw_addr_filt filt;
 
@@ -128,8 +124,8 @@ static inline int drv_set_pan_id(struct ieee802154_local *local,
 					    IEEE802154_AFILT_PANID_CHANGED);
 }
 
-static inline int drv_set_extended_addr(struct ieee802154_local *local,
-					const __le64 extended_addr)
+static inline int
+drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr)
 {
 	struct ieee802154_hw_addr_filt filt;
 
@@ -146,8 +142,8 @@ static inline int drv_set_extended_addr(struct ieee802154_local *local,
 					    IEEE802154_AFILT_IEEEADDR_CHANGED);
 }
 
-static inline int drv_set_short_addr(struct ieee802154_local *local,
-				     const __le16 short_addr)
+static inline int
+drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr)
 {
 	struct ieee802154_hw_addr_filt filt;
 
@@ -164,8 +160,8 @@ static inline int drv_set_short_addr(struct ieee802154_local *local,
 					    IEEE802154_AFILT_SADDR_CHANGED);
 }
 
-static inline int drv_set_pan_coord(struct ieee802154_local *local,
-				    const bool is_coord)
+static inline int
+drv_set_pan_coord(struct ieee802154_local *local, bool is_coord)
 {
 	struct ieee802154_hw_addr_filt filt;
 
@@ -182,9 +178,9 @@ static inline int drv_set_pan_coord(struct ieee802154_local *local,
 					    IEEE802154_AFILT_PANC_CHANGED);
 }
 
-static inline int drv_set_csma_params(struct ieee802154_local *local,
-				      u8 min_be, u8 max_be,
-				      u8 max_csma_backoffs)
+static inline int
+drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be,
+		    u8 max_csma_backoffs)
 {
 	might_sleep();
 
@@ -197,8 +193,8 @@ static inline int drv_set_csma_params(struct ieee802154_local *local,
 					   max_csma_backoffs);
 }
 
-static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
-					    s8 max_frame_retries)
+static inline int
+drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries)
 {
 	might_sleep();
 
@@ -210,8 +206,8 @@ static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
 	return local->ops->set_frame_retries(&local->hw, max_frame_retries);
 }
 
-static inline int drv_set_promiscuous_mode(struct ieee802154_local *local,
-					   const bool on)
+static inline int
+drv_set_promiscuous_mode(struct ieee802154_local *local, bool on)
 {
 	might_sleep();
 
Signature · 1 line
2.1.3
author maintainer
#4 lore raw

PATCH 4/13 mac802154: remove const for non pointer in cfg ops

In reply to Alexander Aring

This patches removes the const keyword in variables which are non pointers. There is no sense to declare call by value parameters as const.

---
 net/mac802154/cfg.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
net/mac802154/cfg.c +17 -15
index 5d669d8..2b3610c 100644
@@ -43,8 +43,7 @@ static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
 }
 
 static int
-ieee802154_set_channel(struct wpan_phy *wpan_phy, const u8 page,
-		       const u8 channel)
+ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 	int ret;
@@ -64,8 +63,9 @@ ieee802154_set_channel(struct wpan_phy *wpan_phy, const u8 page,
 	return ret;
 }
 
-static int ieee802154_set_pan_id(struct wpan_phy *wpan_phy,
-				 struct wpan_dev *wpan_dev, const u16 pan_id)
+static int
+ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
+		      u16 pan_id)
 {
 	ASSERT_RTNL();
 
@@ -86,7 +86,7 @@ static int ieee802154_set_pan_id(struct wpan_phy *wpan_phy,
 static int
 ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
 				struct wpan_dev *wpan_dev,
-				const u8 min_be, const u8 max_be)
+				u8 min_be, u8 max_be)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 
@@ -102,7 +102,7 @@ ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
 
 static int
 ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
-			  const u16 short_addr)
+			  u16 short_addr)
 {
 	ASSERT_RTNL();
 
@@ -125,9 +125,10 @@ ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
 	return 0;
 }
 
-static int ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
-					    struct wpan_dev *wpan_dev,
-					    const u8 max_csma_backoffs)
+static int
+ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
+				 struct wpan_dev *wpan_dev,
+				 u8 max_csma_backoffs)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 
@@ -140,9 +141,10 @@ static int ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy,
 	return 0;
 }
 
-static int ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
-					    struct wpan_dev *wpan_dev,
-					    const s8 max_frame_retries)
+static int
+ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
+				 struct wpan_dev *wpan_dev,
+				 s8 max_frame_retries)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 
@@ -155,9 +157,9 @@ static int ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy,
 	return 0;
 }
 
-static int ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy,
-				   struct wpan_dev *wpan_dev,
-				   const bool mode)
+static int
+ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
+			bool mode)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
 
Signature · 1 line
2.1.3
author maintainer
#5 lore raw

PATCH 5/13 mac802154: remove const for non pointer in rdev-ops

In reply to Alexander Aring

This patches removes the const keyword in variables which are non pointers. There is no sense to declare call by value parameters as const.

---
 net/ieee802154/rdev-ops.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
net/ieee802154/rdev-ops.h +5 -9
index a78f700..578bc41 100644
@@ -21,8 +21,7 @@ rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
 }
 
 static inline int
-rdev_set_channel(struct cfg802154_registered_device *rdev, const u8 page,
-		 const u8 channel)
+rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
 {
 	return rdev->ops->set_channel(&rdev->wpan_phy, page, channel);
 }
@@ -43,8 +42,7 @@ rdev_set_short_addr(struct cfg802154_registered_device *rdev,
 
 static inline int
 rdev_set_backoff_exponent(struct cfg802154_registered_device *rdev,
-			  struct wpan_dev *wpan_dev, const u8 min_be,
-			  const u8 max_be)
+			  struct wpan_dev *wpan_dev, u8 min_be, u8 max_be)
 {
 	return rdev->ops->set_backoff_exponent(&rdev->wpan_phy, wpan_dev,
 					       min_be, max_be);
@@ -52,8 +50,7 @@ rdev_set_backoff_exponent(struct cfg802154_registered_device *rdev,
 
 static inline int
 rdev_set_max_csma_backoffs(struct cfg802154_registered_device *rdev,
-			   struct wpan_dev *wpan_dev,
-			   const u8 max_csma_backoffs)
+			   struct wpan_dev *wpan_dev, u8 max_csma_backoffs)
 {
 	return rdev->ops->set_max_csma_backoffs(&rdev->wpan_phy, wpan_dev,
 						max_csma_backoffs);
@@ -61,8 +58,7 @@ rdev_set_max_csma_backoffs(struct cfg802154_registered_device *rdev,
 
 static inline int
 rdev_set_max_frame_retries(struct cfg802154_registered_device *rdev,
-			   struct wpan_dev *wpan_dev,
-			   const s8 max_frame_retries)
+			   struct wpan_dev *wpan_dev, s8 max_frame_retries)
 {
 	return rdev->ops->set_max_frame_retries(&rdev->wpan_phy, wpan_dev,
 						max_frame_retries);
@@ -70,7 +66,7 @@ rdev_set_max_frame_retries(struct cfg802154_registered_device *rdev,
 
 static inline int
 rdev_set_lbt_mode(struct cfg802154_registered_device *rdev,
-		  struct wpan_dev *wpan_dev, const bool mode)
+		  struct wpan_dev *wpan_dev, bool mode)
 {
 	return rdev->ops->set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode);
 }
Signature · 1 line
2.1.3
author maintainer
#6 lore raw

PATCH 6/13 mac802154: remove deprecated linux-zigbee info

In reply to Alexander Aring

We don't and we can't name it zigbee anymore. This patch removes deprecated information for project website.

---
 net/mac802154/main.c | 2 --
 1 file changed, 2 deletions(-)
net/mac802154/main.c +0 -2
index 0af1be6..5199f21 100644
@@ -4,8 +4,6 @@
  * Written by:
  * Alexander Smirnov <[email protected]>
  *
- * Based on the code from 'linux-zigbee.sourceforge.net' project.
- *
  * 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.
Signature · 1 line
2.1.3
author maintainer
#7 lore raw

PATCH 7/13 mac802154: use new nl802154 iftype types

In reply to Alexander Aring

This patch replace the depracted IEEE802154_DEV to the new introduced NL802154_IFTYPE_NODE types. There is a backwards compatibility to have the identical types for both enum definitions. Also remove some inlcude issue with "linux/nl802154.h", because the export nl_policy inside this header it was always necessary to have an include of "net/rtnetlink.h" before. The reason for this is more complicated. Nevertheless we removed this now, because "linux/nl802154.h" is the depracted netlink interface.

---
 net/mac802154/ieee802154_i.h |  3 ++-
 net/mac802154/iface.c        | 18 +++++++++---------
 net/mac802154/main.c         |  4 ++--
 net/mac802154/rx.c           |  7 +++----
 4 files changed, 16 insertions(+), 16 deletions(-)
net/mac802154/ieee802154_i.h +2 -1
index 593339a..6ad5e89 100644
@@ -23,6 +23,7 @@
 #include <linux/hrtimer.h>
 #include <net/cfg802154.h>
 #include <net/mac802154.h>
+#include <net/nl802154.h>
 #include <net/ieee802154_netdev.h>
 
 #include "llsec.h"
@@ -175,7 +176,7 @@ void ieee802154_iface_exit(void);
 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);
+		  struct wpan_dev **new_wpan_dev, enum nl802154_iftype type);
 void ieee802154_remove_interfaces(struct ieee802154_local *local);
 
 #endif /* __IEEE802154_I_H */
net/mac802154/iface.c +9 -9
index feb0647..cc992e8 100644
@@ -22,8 +22,7 @@
 #include <linux/if_arp.h>
 #include <linux/ieee802154.h>
 
-#include <net/rtnetlink.h>
-#include <linux/nl802154.h>
+#include <net/nl802154.h>
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
 #include <net/cfg802154.h>
@@ -144,7 +143,7 @@ static int mac802154_slave_open(struct net_device *dev)
 
 	ASSERT_RTNL();
 
-	if (sdata->vif.type == IEEE802154_DEV_WPAN) {
+	if (sdata->vif.type == NL802154_IFTYPE_NODE) {
 		mutex_lock(&sdata->local->iflist_mtx);
 		list_for_each_entry(subif, &sdata->local->interfaces, list) {
 			if (subif != sdata &&
@@ -407,7 +406,8 @@ static void ieee802154_if_setup(struct net_device *dev)
 }
 
 static int
-ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
+ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
+		       enum nl802154_iftype type)
 {
 	struct wpan_dev *wpan_dev = &sdata->wpan_dev;
 
@@ -429,7 +429,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
 	wpan_dev->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
 
 	switch (type) {
-	case IEEE802154_DEV_WPAN:
+	case NL802154_IFTYPE_NODE:
 		ieee802154_be64_to_le64(&wpan_dev->extended_addr,
 					sdata->dev->dev_addr);
 
@@ -444,7 +444,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
 
 		mac802154_llsec_init(&sdata->sec);
 		break;
-	case IEEE802154_DEV_MONITOR:
+	case NL802154_IFTYPE_MONITOR:
 		sdata->dev->destructor = free_netdev;
 		sdata->dev->netdev_ops = &mac802154_monitor_ops;
 		wpan_dev->promiscuous_mode = true;
@@ -458,7 +458,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, int type)
 
 struct net_device *
 ieee802154_if_add(struct ieee802154_local *local, const char *name,
-		  struct wpan_dev **new_wpan_dev, int type)
+		  struct wpan_dev **new_wpan_dev, enum nl802154_iftype type)
 {
 	struct net_device *ndev = NULL;
 	struct ieee802154_sub_if_data *sdata = NULL;
@@ -478,10 +478,10 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 		goto err;
 
 	switch (type) {
-	case IEEE802154_DEV_WPAN:
+	case NL802154_IFTYPE_NODE:
 		ndev->type = ARPHRD_IEEE802154;
 		break;
-	case IEEE802154_DEV_MONITOR:
+	case NL802154_IFTYPE_MONITOR:
 		ndev->type = ARPHRD_IEEE802154_MONITOR;
 		break;
 	default:
net/mac802154/main.c +2 -2
index 5199f21..2e42fc2 100644
@@ -19,7 +19,7 @@
 #include <linux/netdevice.h>
 
 #include <net/netlink.h>
-#include <linux/nl802154.h>
+#include <net/nl802154.h>
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
 #include <net/route.h>
@@ -161,7 +161,7 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
 
 	rtnl_lock();
 
-	dev = ieee802154_if_add(local, "wpan%d", NULL, IEEE802154_DEV_WPAN);
+	dev = ieee802154_if_add(local, "wpan%d", NULL, NL802154_IFTYPE_NODE);
 	if (IS_ERR(dev)) {
 		rtnl_unlock();
 		rc = PTR_ERR(dev);
net/mac802154/rx.c +3 -4
index b18e755..041dbd5 100644
@@ -25,8 +25,7 @@
 
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
-#include <net/rtnetlink.h>
-#include <linux/nl802154.h>
+#include <net/nl802154.h>
 
 #include "ieee802154_i.h"
 
@@ -209,7 +208,7 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local,
 	}
 
 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
-		if (sdata->vif.type != IEEE802154_DEV_WPAN ||
+		if (sdata->vif.type != NL802154_IFTYPE_NODE ||
 		    !netif_running(sdata->dev))
 			continue;
 
@@ -234,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->vif.type != IEEE802154_DEV_MONITOR)
+		if (sdata->vif.type != NL802154_IFTYPE_MONITOR)
 			continue;
 
 		if (!ieee802154_sdata_running(sdata))
Signature · 1 line
2.1.3
author maintainer
#8 lore raw

PATCH 8/13 mac802154: remove wpan_dev parameter in if_add

In reply to Alexander Aring

This parameter was grabbed from wireless implementation with the identically wireless dev struct. We don't need this right now and so we remove it. Maybe we will add it later again if we found any real reason to have such parameter.

---
 net/mac802154/cfg.c          | 2 +-
 net/mac802154/ieee802154_i.h | 2 +-
 net/mac802154/iface.c        | 5 +----
 net/mac802154/main.c         | 2 +-
 4 files changed, 4 insertions(+), 7 deletions(-)
net/mac802154/cfg.c +1 -1
index 2b3610c..2abe7e5 100644
@@ -28,7 +28,7 @@ ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 	struct net_device *dev;
 
 	rtnl_lock();
-	dev = ieee802154_if_add(local, name, NULL, type);
+	dev = ieee802154_if_add(local, name, type);
 	rtnl_unlock();
 
 	return dev;
net/mac802154/ieee802154_i.h +1 -1
index 6ad5e89..4655383 100644
@@ -176,7 +176,7 @@ void ieee802154_iface_exit(void);
 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, enum nl802154_iftype type);
+		  enum nl802154_iftype type);
 void ieee802154_remove_interfaces(struct ieee802154_local *local);
 
 #endif /* __IEEE802154_I_H */
net/mac802154/iface.c +1 -4
index cc992e8..ba63ac9 100644
@@ -458,7 +458,7 @@ ieee802154_setup_sdata(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, enum nl802154_iftype type)
+		  enum nl802154_iftype type)
 {
 	struct net_device *ndev = NULL;
 	struct ieee802154_sub_if_data *sdata = NULL;
@@ -516,9 +516,6 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 	list_add_tail_rcu(&sdata->list, &local->interfaces);
 	mutex_unlock(&local->iflist_mtx);
 
-	if (new_wpan_dev)
-		*new_wpan_dev = &sdata->wpan_dev;
-
 	return ndev;
 
 err:
net/mac802154/main.c +1 -1
index 2e42fc2..bbb19dd 100644
@@ -161,7 +161,7 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
 
 	rtnl_lock();
 
-	dev = ieee802154_if_add(local, "wpan%d", NULL, NL802154_IFTYPE_NODE);
+	dev = ieee802154_if_add(local, "wpan%d", NL802154_IFTYPE_NODE);
 	if (IS_ERR(dev)) {
 		rtnl_unlock();
 		rc = PTR_ERR(dev);
Signature · 1 line
2.1.3
author maintainer
#9 lore raw

PATCH 9/13 ieee802154: add new interface command

In reply to Alexander Aring

This patch adds a new nl802154 command for adding a new interface according to a wpan phy via nl802154.

---
 include/net/cfg802154.h   |  5 +++++
 net/ieee802154/nl802154.c | 34 ++++++++++++++++++++++++++++++++++
 net/ieee802154/rdev-ops.h |  7 +++++++
 net/mac802154/cfg.c       | 15 +++++++++++++++
 4 files changed, 61 insertions(+)
include/net/cfg802154.h +5 -0
index 17b4fc0..24c7321 100644
@@ -21,6 +21,8 @@
 #include <linux/mutex.h>
 #include <linux/bug.h>
 
+#include <net/nl802154.h>
+
 /* According to the IEEE 802.15.4 stadard the upper most significant bits of
  * the 32-bit channel bitmaps shall be used as an integer value to specify 32
  * possible channel pages. The lower 27 bits of the channel bit map shall be
@@ -37,6 +39,9 @@ struct cfg802154_ops {
 							   int type);
 	void	(*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
 					       struct net_device *dev);
+	int	(*add_virtual_intf)(struct wpan_phy *wpan_phy,
+				    const char *name,
+				    enum nl802154_iftype type);
 	int	(*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
 	int	(*set_pan_id)(struct wpan_phy *wpan_phy,
 			      struct wpan_dev *wpan_dev, u16 pan_id);
net/ieee802154/nl802154.c +34 -0
index ccdf33e..e7224f3 100644
@@ -551,6 +551,32 @@ static int nl802154_get_interface(struct sk_buff *skb, struct genl_info *info)
 	return genlmsg_reply(msg, info);
 }
 
+static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg802154_registered_device *rdev = info->user_ptr[0];
+	enum nl802154_iftype type = NL802154_IFTYPE_UNSPEC;
+
+	/* TODO avoid failing a new interface
+	 * creation due to pending removal?
+	 */
+
+	if (!info->attrs[NL802154_ATTR_IFNAME])
+		return -EINVAL;
+
+	if (info->attrs[NL802154_ATTR_IFTYPE]) {
+		type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
+		if (type > NL802154_IFTYPE_MAX)
+			return -EINVAL;
+	}
+
+	if (!rdev->ops->add_virtual_intf)
+		return -EOPNOTSUPP;
+
+	return rdev_add_virtual_intf(rdev,
+				     nla_data(info->attrs[NL802154_ATTR_IFNAME]),
+				     type);
+}
+
 static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
 {
 	struct cfg802154_registered_device *rdev = info->user_ptr[0];
@@ -819,6 +845,14 @@ static const struct genl_ops nl802154_ops[] = {
 				  NL802154_FLAG_NEED_RTNL,
 	},
 	{
+		.cmd = NL802154_CMD_NEW_INTERFACE,
+		.doit = nl802154_new_interface,
+		.policy = nl802154_policy,
+		.flags = GENL_ADMIN_PERM,
+		.internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
+				  NL802154_FLAG_NEED_RTNL,
+	},
+	{
 		.cmd = NL802154_CMD_SET_CHANNEL,
 		.doit = nl802154_set_channel,
 		.policy = nl802154_policy,
net/ieee802154/rdev-ops.h +7 -0
index 578bc41..d3a4f94 100644
@@ -21,6 +21,13 @@ rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
 }
 
 static inline int
+rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
+		      enum nl802154_iftype type)
+{
+	return rdev->ops->add_virtual_intf(&rdev->wpan_phy, name, type);
+}
+
+static inline int
 rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
 {
 	return rdev->ops->set_channel(&rdev->wpan_phy, page, channel);
net/mac802154/cfg.c +15 -0
index 2abe7e5..ae1a9ef 100644
@@ -43,6 +43,20 @@ static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
 }
 
 static int
+ieee802154_add_iface(struct wpan_phy *phy, const char *name,
+		     enum nl802154_iftype type)
+{
+	struct ieee802154_local *local = wpan_phy_priv(phy);
+	struct net_device *err;
+
+	err = ieee802154_if_add(local, name, type);
+	if (IS_ERR(err))
+		return PTR_ERR(err);
+
+	return 0;
+}
+
+static int
 ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
@@ -175,6 +189,7 @@ ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
 const struct cfg802154_ops mac802154_config_ops = {
 	.add_virtual_intf_deprecated = ieee802154_add_iface_deprecated,
 	.del_virtual_intf_deprecated = ieee802154_del_iface_deprecated,
+	.add_virtual_intf = ieee802154_add_iface,
 	.set_channel = ieee802154_set_channel,
 	.set_pan_id = ieee802154_set_pan_id,
 	.set_short_addr = ieee802154_set_short_addr,
Signature · 1 line
2.1.3
author maintainer
#10 lore raw

PATCH 10/13 ieee802154: setting extended address while iface add

In reply to Alexander Aring

This patch adds support for setting an extended address while registration a new interface. If ieee802154_is_valid_extended_addr getting as parameter and invalid extended address then the perm address is fallback. This is useful to make some default handling while for example default registration of a wpan interface while phy registration.

---
 include/net/cfg802154.h      |  3 ++-
 net/ieee802154/nl802154.c    |  8 +++++++-
 net/ieee802154/rdev-ops.h    |  5 +++--
 net/mac802154/cfg.c          |  7 ++++---
 net/mac802154/ieee802154_i.h |  2 +-
 net/mac802154/iface.c        | 12 ++++++++----
 net/mac802154/main.c         |  3 ++-
 7 files changed, 27 insertions(+), 13 deletions(-)
include/net/cfg802154.h +2 -1
index 24c7321..4a9bb0e 100644
@@ -41,7 +41,8 @@ struct cfg802154_ops {
 					       struct net_device *dev);
 	int	(*add_virtual_intf)(struct wpan_phy *wpan_phy,
 				    const char *name,
-				    enum nl802154_iftype type);
+				    enum nl802154_iftype type,
+				    __le64 extended_addr);
 	int	(*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
 	int	(*set_pan_id)(struct wpan_phy *wpan_phy,
 			      struct wpan_dev *wpan_dev, u16 pan_id);
net/ieee802154/nl802154.c +7 -1
index e7224f3..49c4d8a 100644
@@ -555,6 +555,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
 {
 	struct cfg802154_registered_device *rdev = info->user_ptr[0];
 	enum nl802154_iftype type = NL802154_IFTYPE_UNSPEC;
+	__le64 extended_addr = cpu_to_le64(0x0000000000000000ULL);
 
 	/* TODO avoid failing a new interface
 	 * creation due to pending removal?
@@ -569,12 +570,17 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
 			return -EINVAL;
 	}
 
+	/* TODO add nla_get_le64 to netlink */
+	if (info->attrs[NL802154_ATTR_EXTENDED_ADDR])
+		extended_addr = (__force __le64)nla_get_u64(
+				info->attrs[NL802154_ATTR_EXTENDED_ADDR]);
+
 	if (!rdev->ops->add_virtual_intf)
 		return -EOPNOTSUPP;
 
 	return rdev_add_virtual_intf(rdev,
 				     nla_data(info->attrs[NL802154_ATTR_IFNAME]),
-				     type);
+				     type, extended_addr);
 }
 
 static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
net/ieee802154/rdev-ops.h +3 -2
index d3a4f94..06e9754 100644
@@ -22,9 +22,10 @@ rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
 
 static inline int
 rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
-		      enum nl802154_iftype type)
+		      enum nl802154_iftype type, __le64 extended_addr)
 {
-	return rdev->ops->add_virtual_intf(&rdev->wpan_phy, name, type);
+	return rdev->ops->add_virtual_intf(&rdev->wpan_phy, name, type,
+					   extended_addr);
 }
 
 static inline int
net/mac802154/cfg.c +4 -3
index ae1a9ef..568d712 100644
@@ -28,7 +28,8 @@ ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 	struct net_device *dev;
 
 	rtnl_lock();
-	dev = ieee802154_if_add(local, name, type);
+	dev = ieee802154_if_add(local, name, type,
+				cpu_to_le64(0x0000000000000000ULL));
 	rtnl_unlock();
 
 	return dev;
@@ -44,12 +45,12 @@ static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
 
 static int
 ieee802154_add_iface(struct wpan_phy *phy, const char *name,
-		     enum nl802154_iftype type)
+		     enum nl802154_iftype type, __le64 extended_addr)
 {
 	struct ieee802154_local *local = wpan_phy_priv(phy);
 	struct net_device *err;
 
-	err = ieee802154_if_add(local, name, type);
+	err = ieee802154_if_add(local, name, type, extended_addr);
 	if (IS_ERR(err))
 		return PTR_ERR(err);
 
net/mac802154/ieee802154_i.h +1 -1
index 4655383..cc69163 100644
@@ -176,7 +176,7 @@ void ieee802154_iface_exit(void);
 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
 struct net_device *
 ieee802154_if_add(struct ieee802154_local *local, const char *name,
-		  enum nl802154_iftype type);
+		  enum nl802154_iftype type, __le64 extended_addr);
 void ieee802154_remove_interfaces(struct ieee802154_local *local);
 
 #endif /* __IEEE802154_I_H */
net/mac802154/iface.c +8 -4
index ba63ac9..38dfc72 100644
@@ -458,7 +458,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
 
 struct net_device *
 ieee802154_if_add(struct ieee802154_local *local, const char *name,
-		  enum nl802154_iftype type)
+		  enum nl802154_iftype type, __le64 extended_addr)
 {
 	struct net_device *ndev = NULL;
 	struct ieee802154_sub_if_data *sdata = NULL;
@@ -477,9 +477,16 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 	if (ret < 0)
 		goto err;
 
+	ieee802154_le64_to_be64(ndev->perm_addr,
+				&local->hw.phy->perm_extended_addr);
 	switch (type) {
 	case NL802154_IFTYPE_NODE:
 		ndev->type = ARPHRD_IEEE802154;
+		if (ieee802154_is_valid_extended_addr(extended_addr))
+			ieee802154_le64_to_be64(ndev->dev_addr, &extended_addr);
+		else
+			memcpy(ndev->dev_addr, ndev->perm_addr,
+			       IEEE802154_EXTENDED_ADDR_LEN);
 		break;
 	case NL802154_IFTYPE_MONITOR:
 		ndev->type = ARPHRD_IEEE802154_MONITOR;
@@ -489,9 +496,6 @@ 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);
net/mac802154/main.c +2 -1
index bbb19dd..8500378 100644
@@ -161,7 +161,8 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
 
 	rtnl_lock();
 
-	dev = ieee802154_if_add(local, "wpan%d", NL802154_IFTYPE_NODE);
+	dev = ieee802154_if_add(local, "wpan%d", NL802154_IFTYPE_NODE,
+				cpu_to_le64(0x0000000000000000ULL));
 	if (IS_ERR(dev)) {
 		rtnl_unlock();
 		rc = PTR_ERR(dev);
Signature · 1 line
2.1.3
author maintainer
#11 lore raw

PATCH 11/13 ieee802154: add del interface command

In reply to Alexander Aring

This patch adds support for deleting a wpan interface via nl802154.

---
 include/net/cfg802154.h      |  2 ++
 net/ieee802154/nl802154.c    | 28 ++++++++++++++++++++++++++++
 net/ieee802154/rdev-ops.h    |  7 +++++++
 net/mac802154/cfg.c          |  9 +++++++++
 net/mac802154/ieee802154_i.h |  6 ++++++
 5 files changed, 52 insertions(+)
include/net/cfg802154.h +2 -0
index 4a9bb0e..507ac9d 100644
@@ -43,6 +43,8 @@ struct cfg802154_ops {
 				    const char *name,
 				    enum nl802154_iftype type,
 				    __le64 extended_addr);
+	int	(*del_virtual_intf)(struct wpan_phy *wpan_phy,
+				    struct wpan_dev *wpan_dev);
 	int	(*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
 	int	(*set_pan_id)(struct wpan_phy *wpan_phy,
 			      struct wpan_dev *wpan_dev, u16 pan_id);
net/ieee802154/nl802154.c +28 -0
index 49c4d8a..6b9bc93 100644
@@ -583,6 +583,26 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
 				     type, extended_addr);
 }
 
+static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg802154_registered_device *rdev = info->user_ptr[0];
+	struct wpan_dev *wpan_dev = info->user_ptr[1];
+
+	if (!rdev->ops->del_virtual_intf)
+		return -EOPNOTSUPP;
+
+	/* If we remove a wpan device without a netdev then clear
+	 * user_ptr[1] so that nl802154_post_doit won't dereference it
+	 * to check if it needs to do dev_put(). Otherwise it crashes
+	 * since the wpan_dev has been freed, unlike with a netdev where
+	 * we need the dev_put() for the netdev to really be freed.
+	 */
+	if (!wpan_dev->netdev)
+		info->user_ptr[1] = NULL;
+
+	return rdev_del_virtual_intf(rdev, wpan_dev);
+}
+
 static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
 {
 	struct cfg802154_registered_device *rdev = info->user_ptr[0];
@@ -859,6 +879,14 @@ static const struct genl_ops nl802154_ops[] = {
 				  NL802154_FLAG_NEED_RTNL,
 	},
 	{
+		.cmd = NL802154_CMD_DEL_INTERFACE,
+		.doit = nl802154_del_interface,
+		.policy = nl802154_policy,
+		.flags = GENL_ADMIN_PERM,
+		.internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
+				  NL802154_FLAG_NEED_RTNL,
+	},
+	{
 		.cmd = NL802154_CMD_SET_CHANNEL,
 		.doit = nl802154_set_channel,
 		.policy = nl802154_policy,
net/ieee802154/rdev-ops.h +7 -0
index 06e9754..40ffbc0 100644
@@ -29,6 +29,13 @@ rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
 }
 
 static inline int
+rdev_del_virtual_intf(struct cfg802154_registered_device *rdev,
+		      struct wpan_dev *wpan_dev)
+{
+	return rdev->ops->del_virtual_intf(&rdev->wpan_phy, wpan_dev);
+}
+
+static inline int
 rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
 {
 	return rdev->ops->set_channel(&rdev->wpan_phy, page, channel);
net/mac802154/cfg.c +9 -0
index 568d712..7def262 100644
@@ -58,6 +58,14 @@ ieee802154_add_iface(struct wpan_phy *phy, const char *name,
 }
 
 static int
+ieee802154_del_iface(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev)
+{
+	ieee802154_if_remove(IEEE802154_WPAN_DEV_TO_SUB_IF(wpan_dev));
+
+	return 0;
+}
+
+static int
 ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
 {
 	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
@@ -191,6 +199,7 @@ const struct cfg802154_ops mac802154_config_ops = {
 	.add_virtual_intf_deprecated = ieee802154_add_iface_deprecated,
 	.del_virtual_intf_deprecated = ieee802154_del_iface_deprecated,
 	.add_virtual_intf = ieee802154_add_iface,
+	.del_virtual_intf = ieee802154_del_iface,
 	.set_channel = ieee802154_set_channel,
 	.set_pan_id = ieee802154_set_pan_id,
 	.set_short_addr = ieee802154_set_short_addr,
net/mac802154/ieee802154_i.h +6 -0
index cc69163..bebd70f 100644
@@ -115,6 +115,12 @@ IEEE802154_DEV_TO_SUB_IF(const struct net_device *dev)
 	return netdev_priv(dev);
 }
 
+static inline struct ieee802154_sub_if_data *
+IEEE802154_WPAN_DEV_TO_SUB_IF(struct wpan_dev *wpan_dev)
+{
+	return container_of(wpan_dev, struct ieee802154_sub_if_data, wpan_dev);
+}
+
 static inline bool
 ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
 {
Signature · 1 line
2.1.3
author maintainer
#12 lore raw

PATCH 12/13 ieee802154: rename and move WPAN_NUM_ defines

In reply to Alexander Aring

This patch moves the 802.15.4 constraints WPAN_NUM_ defines into "net/ieee802154.h" which should contain all necessary 802.15.4 related information. Also rename these defines to a common name which is IEEE802154_MAX_CHANNEL and IEEE802154_MAX_PAGE.

---
 include/linux/ieee802154.h |  3 +++
 include/net/cfg802154.h    | 11 ++---------
 net/ieee802154/nl802154.c  |  4 ++--
 3 files changed, 7 insertions(+), 11 deletions(-)
include/linux/ieee802154.h +3 -0
index 5a40c04..6e82d88 100644
@@ -39,6 +39,9 @@
 #define IEEE802154_LIFS_PERIOD		40
 #define IEEE802154_SIFS_PERIOD		12
 
+#define IEEE802154_MAX_CHANNEL		26
+#define IEEE802154_MAX_PAGE		31
+
 #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 */
include/net/cfg802154.h +2 -9
index 507ac9d..228f1f7 100644
@@ -17,20 +17,13 @@
 #ifndef __NET_CFG802154_H
 #define __NET_CFG802154_H
 
+#include <linux/ieee802154.h>
 #include <linux/netdevice.h>
 #include <linux/mutex.h>
 #include <linux/bug.h>
 
 #include <net/nl802154.h>
 
-/* According to the IEEE 802.15.4 stadard the upper most significant bits of
- * the 32-bit channel bitmaps shall be used as an integer value to specify 32
- * possible channel pages. The lower 27 bits of the channel bit map shall be
- * used as a bit mask to specify channel numbers within a channel page.
- */
-#define WPAN_NUM_CHANNELS	27
-#define WPAN_NUM_PAGES		32
-
 struct wpan_phy;
 
 struct cfg802154_ops {
@@ -81,7 +74,7 @@ struct wpan_phy {
 	 */
 	u8 current_channel;
 	u8 current_page;
-	u32 channels_supported[32];
+	u32 channels_supported[IEEE802154_MAX_PAGE + 1];
 	s8 transmit_power;
 	u8 cca_mode;
 
net/ieee802154/nl802154.c +2 -2
index 6b9bc93..b82b016 100644
@@ -245,7 +245,7 @@ nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
 	if (!nl_page)
 		return -ENOBUFS;
 
-	for (page = 0; page < WPAN_NUM_PAGES; page++) {
+	for (page = 0; page <= IEEE802154_MAX_PAGE; page++) {
 		if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
 				rdev->wpan_phy.channels_supported[page]))
 			return -ENOBUFS;
@@ -616,7 +616,7 @@ static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
 	channel = nla_get_u8(info->attrs[NL802154_ATTR_CHANNEL]);
 
 	/* check 802.15.4 constraints */
-	if (page >= WPAN_NUM_PAGES || channel >= WPAN_NUM_CHANNELS)
+	if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL)
 		return -EINVAL;
 
 	return rdev_set_channel(rdev, page, channel);
Signature · 1 line
2.1.3
author maintainer
#13 lore raw

PATCH 13/13 ieee802154: fix byteorder for short address and panid

In reply to Alexander Aring

This patch changes the byteorder handling for short and panid handling. We now except to get little endian in nl802154 for these attributes.

---
 include/net/cfg802154.h   |  4 ++--
 net/ieee802154/nl802154.c |  8 ++++----
 net/ieee802154/rdev-ops.h |  4 ++--
 net/mac802154/cfg.c       | 14 +++++++-------
 4 files changed, 15 insertions(+), 15 deletions(-)
include/net/cfg802154.h +2 -2
index 228f1f7..7f713ac 100644
@@ -40,9 +40,9 @@ struct cfg802154_ops {
 				    struct wpan_dev *wpan_dev);
 	int	(*set_channel)(struct wpan_phy *wpan_phy, u8 page, u8 channel);
 	int	(*set_pan_id)(struct wpan_phy *wpan_phy,
-			      struct wpan_dev *wpan_dev, u16 pan_id);
+			      struct wpan_dev *wpan_dev, __le16 pan_id);
 	int	(*set_short_addr)(struct wpan_phy *wpan_phy,
-				  struct wpan_dev *wpan_dev, u16 short_addr);
+				  struct wpan_dev *wpan_dev, __le16 short_addr);
 	int	(*set_backoff_exponent)(struct wpan_phy *wpan_phy,
 					struct wpan_dev *wpan_dev, u8 min_be,
 					u8 max_be);
net/ieee802154/nl802154.c +4 -4
index b82b016..8896477 100644
@@ -627,7 +627,7 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
 	struct cfg802154_registered_device *rdev = info->user_ptr[0];
 	struct net_device *dev = info->user_ptr[1];
 	struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
-	u16 pan_id;
+	__le16 pan_id;
 
 	/* conflict here while tx/rx calls */
 	if (netif_running(dev))
@@ -640,7 +640,7 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
 	if (!info->attrs[NL802154_ATTR_PAN_ID])
 		return -EINVAL;
 
-	pan_id = nla_get_u16(info->attrs[NL802154_ATTR_PAN_ID]);
+	pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]);
 
 	return rdev_set_pan_id(rdev, wpan_dev, pan_id);
 }
@@ -650,7 +650,7 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
 	struct cfg802154_registered_device *rdev = info->user_ptr[0];
 	struct net_device *dev = info->user_ptr[1];
 	struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
-	u16 short_addr;
+	__le16 short_addr;
 
 	/* conflict here while tx/rx calls */
 	if (netif_running(dev))
@@ -663,7 +663,7 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
 	if (!info->attrs[NL802154_ATTR_SHORT_ADDR])
 		return -EINVAL;
 
-	short_addr = nla_get_u16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
+	short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
 
 	return rdev_set_short_addr(rdev, wpan_dev, short_addr);
 }
net/ieee802154/rdev-ops.h +2 -2
index 40ffbc0..aff54fb 100644
@@ -43,14 +43,14 @@ rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
 
 static inline int
 rdev_set_pan_id(struct cfg802154_registered_device *rdev,
-		struct wpan_dev *wpan_dev, u16 pan_id)
+		struct wpan_dev *wpan_dev, __le16 pan_id)
 {
 	return rdev->ops->set_pan_id(&rdev->wpan_phy, wpan_dev, pan_id);
 }
 
 static inline int
 rdev_set_short_addr(struct cfg802154_registered_device *rdev,
-		    struct wpan_dev *wpan_dev, u16 short_addr)
+		    struct wpan_dev *wpan_dev, __le16 short_addr)
 {
 	return rdev->ops->set_short_addr(&rdev->wpan_phy, wpan_dev, short_addr);
 }
net/mac802154/cfg.c +7 -7
index 7def262..c035708 100644
@@ -88,7 +88,7 @@ ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)
 
 static int
 ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
-		      u16 pan_id)
+		      __le16 pan_id)
 {
 	ASSERT_RTNL();
 
@@ -99,10 +99,10 @@ ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
 	 *
 	 * This could useful to simple deassociate an device.
 	 */
-	if (pan_id == IEEE802154_PAN_ID_BROADCAST)
+	if (pan_id == cpu_to_le16(IEEE802154_PAN_ID_BROADCAST))
 		return -EINVAL;
 
-	wpan_dev->pan_id = cpu_to_le16(pan_id);
+	wpan_dev->pan_id = pan_id;
 	return 0;
 }
 
@@ -125,7 +125,7 @@ ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy,
 
 static int
 ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
-			  u16 short_addr)
+			  __le16 short_addr)
 {
 	ASSERT_RTNL();
 
@@ -140,11 +140,11 @@ ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
 	 * I think we should allow to set these settings but
 	 * don't allow to allow socket communication with it.
 	 */
-	if (short_addr == IEEE802154_ADDR_SHORT_UNSPEC ||
-	    short_addr == IEEE802154_ADDR_SHORT_BROADCAST)
+	if (short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC) ||
+	    short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST))
 		return -EINVAL;
 
-	wpan_dev->short_addr = cpu_to_le16(short_addr);
+	wpan_dev->short_addr = short_addr;
 	return 0;
 }
 
Signature · 1 line
2.1.3
#14 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 21 lines

This patch series contains various cleanups and adding new nl802154 commands for supporting interface handling. At least we fix some byteorder issues. The nl802154 interface uses little endian byteorder now. This is the same byteorder like 802.15.4 MAC layer. The nl802154 interface is new, so we should fix the byteorder issue now.

Alexander Aring (13):
mac802154: remove unused prototypes
at86rf230: fix commentation for symbol duration
mac802154: remove const for non pointer in driver-ops
mac802154: remove const for non pointer in cfg ops
mac802154: remove const for non pointer in rdev-ops
mac802154: remove deprecated linux-zigbee info
mac802154: use new nl802154 iftype types
mac802154: remove wpan_dev parameter in if_add
ieee802154: add new interface command
ieee802154: setting extended address while iface add
ieee802154: add del interface command
ieee802154: rename and move WPAN_NUM_ defines
ieee802154: fix byteorder for short address and panid

Quoted 12 lines
drivers/net/ieee802154/at86rf230.c |  4 +-
include/linux/ieee802154.h         |  3 ++
include/net/cfg802154.h            | 21 +++++-----
net/ieee802154/nl802154.c          | 80 +++++++++++++++++++++++++++++++++++---
net/ieee802154/rdev-ops.h          | 33 ++++++++++------
net/mac802154/cfg.c                | 69 ++++++++++++++++++++++----------
net/mac802154/driver-ops.h         | 46 ++++++++++------------
net/mac802154/ieee802154_i.h       | 15 +++----
net/mac802154/iface.c              | 31 ++++++++-------
net/mac802154/main.c               |  7 ++--
net/mac802154/rx.c                 |  7 ++--
11 files changed, 211 insertions(+), 105 deletions(-)

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

Regards

Marcel