Skip to contentSkip to conversation

wpan-tools: new netlink interfaces calls

PATCH Superseded Alexander Aring 1 participant 9 messages Sep 4, 2014 IEEE 802.15.4

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover wpan-tools: new netlink interfaces calls

Hi all,

this patch series adds support for new netlink interfaces. For all new users on this mailinglist. This is the new userspace tool for the wpan rework [0] branch.

I removed the mib lock in the rework. Now you can only set the pan_id or short address (don't implement the setting of short address now) when the netdevice is _down_.

Then we don't need the the mib lock anymore. It's protected by RTNL if netdevice is down. When it's up it's a read only variable and we can use the variable in hot path like tx/rx without locking. (This is like setting and use of dev_addr of an netdev device).

I disabled the af802154 and security layer for now, but I will add this later at the end of the rework.

I also detected that our cca_mode handling is a driver specific netlink call. This is... not good. :-) And this is the current mainline behaviour...

In the rework I added enums for the 802.15.4 CCA_MODE numbers and now the at86rf231 makes a mapping from 802.15.4 specifc CCA_MODE to driver cca_mode( which is the register value).

I need to begin to write more text about the new behaviour, is there anybody outside who already test something?

We don't have the multiple phy layer, I dropped them. This was needed for the channel hoping. We need some new idea to provide a channel hoping logic, or simple but the logic for this in userspace. (You can change the channel while netdev is up).

There are several other netlink interfaces (setting short_address,setting energy detection value of phy)

The energy detection level is not part of the 802.15.4 pib, so this will be a direct call to the driver (not saving any value of this in the pib).

- Alex

[0] https://github.com/linux-wpan/linux-wpan-next/tree/wpan_rework_rfc

Alexander Aring (6):
nl_updates: initial commit of nl_updates
phy: add support for tx power pib attribute
phy: add support for setting cca_mode
mac: add support for setting max_frame_retries
mac: initial support for setting csma params
phy: add support for cca mode 3 and/or handling

 src/mac.c        | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nl802154.h   |  20 ++++++++++
 src/nl_updates.h |  75 ++++++++++++++++++++++++++++++++++++
 src/phy.c        |  67 +++++++++++++++++++++++++++++++++
 4 files changed, 275 insertions(+)
 create mode 100644 src/nl_updates.h
Signature · 1 line
2.1.0
author maintainer
#1 lore raw

PATCH 1/6 nl_updates: initial commit of nl_updates

This patch adds a nl_updates header file to handle signed integer types via netlink.

These types are support mainline at linux kernel but not supported by current netlink library, this is a workaround to add these types.

It's protected by an ifdef, so it's safe when new netlink libraries will add these functions.

---
 src/nl_updates.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 src/nl_updates.h
src/nl_updates.h new file +75 -0
new file mode 100644
index 0000000..066d5bb
@@ -0,0 +1,75 @@
+/*
+ *   lib/nl_updates.h - Updates to libnl which are not synced from kernel yet
+ *   Copyright (C) 2012-2013 Jiri Pirko <[email protected]>
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public
+ *   License as published by the Free Software Foundation; either
+ *   version 2.1 of the License, or (at your option) any later version.
+ *
+ *   This library 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
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _NL_UPDATES_H_
+#define _NL_UPDATES_H_
+
+#ifndef NLA_BINARY
+#define NLA_BINARY 11
+#endif
+
+#ifndef NLA_S8
+/*
+ * Presume that libnl will add all types and relevant puts/gets at once
+ * so check only for NLA_S8.
+ */
+#define NLA_S8 12
+#define NLA_S16 13
+#define NLA_S32 14
+#define NLA_S64 15
+
+/**
+ * Add 8 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S8(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int8_t, attrtype, value)
+
+/**
+ * Add 16 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S16(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int16_t, attrtype, value)
+
+/**
+ * Add 32 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S32(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int32_t, attrtype, value)
+
+/**
+ * Add 64 bit signed integer attribute to netlink message.
+ * @arg msg		Netlink message.
+ * @arg attrtype	Attribute type.
+ * @arg value		Numeric value.
+ */
+#define NLA_PUT_S64(msg, attrtype, value) \
+	NLA_PUT_TYPE(msg, int64_t, attrtype, value)
+
+#endif
+
+#endif /* _NL_UPDATES_H_ */
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

Re: [PATCH wpan-tools 1/6] nl_updates: initial commit of nl_updates

Quoted 21 lines · Alexander Aring

This patch adds a nl_updates header file to handle signed integer types via netlink.

These types are support mainline at linux kernel but not supported by current netlink library, this is a workaround to add these types.

It's protected by an ifdef, so it's safe when new netlink libraries will add these functions.

---
 src/nl_updates.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 src/nl_updates.h
src/nl_updates.h new file +0 -0
new file mode 100644
index 0000000..066d5bb

src/nl_updates.h line 6

Quoted 6 lines
src/nl_updates.h new file +6 -0
@@ -0,0 +1,75 @@
+/*
+ *   lib/nl_updates.h - Updates to libnl which are not synced from kernel yet
+ *   Copyright (C) 2012-2013 Jiri Pirko <[email protected]>
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public

oh, I can't use this code it's LGPL. Sorry. I will remove it now, grml.

- Alex

author maintainer
#3 lore raw

Re: [PATCH wpan-tools 1/6] nl_updates: initial commit of nl_updates

Quoted 16 lines · Alexander Aring
Quoted 15 lines · Alexander Aring

This patch adds a nl_updates header file to handle signed integer types via netlink.

These types are support mainline at linux kernel but not supported by current netlink library, this is a workaround to add these types.

It's protected by an ifdef, so it's safe when new netlink libraries will add these functions.

---
 src/nl_updates.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 src/nl_updates.h
Quoted 15 lines

src/nl_updates.h line 6

Quoted 12 lines
src/nl_updates.h new file +6 -0
new file mode 100644
index 0000000..066d5bb
@@ -0,0 +1,75 @@
+/*
+ *   lib/nl_updates.h - Updates to libnl which are not synced from kernel yet
+ *   Copyright (C) 2012-2013 Jiri Pirko <[email protected]>
+ *
+ *   This library is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU Lesser General Public

oh, I can't use this code it's LGPL. Sorry. I will remove it now, grml.

I will reimplement it to avoid any of license issues. What should I say about it? It should be the same code like this one, I also will follow the coding style of netlink and grab the necessary values from kernel interface.

- Alex

author maintainer
#4 lore raw

PATCH 2/6 phy: add support for tx power pib attribute

In reply to Alexander Aring
---
 src/nl802154.h |  4 ++++
 src/phy.c      | 28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
src/nl802154.h +4 -0
index 51d08b0..1af09ac 100644
@@ -43,6 +43,8 @@ enum nl802154_commands {
 
 	NL802154_CMD_SET_PAN_ID,
 
+	NL802154_CMD_SET_TX_POWER,
+
 	/* add new commands above here */
 
 	/* used to define NL802154_CMD_MAX below */
@@ -71,6 +73,8 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_PAN_ID,
 
+	NL802154_ATTR_TX_POWER,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
src/phy.c +28 -0
index 33365dd..811fc35 100644
@@ -9,6 +9,7 @@
 #include <netlink/msg.h>
 #include <netlink/attr.h>
 
+#include "nl_updates.h"
 #include "nl802154.h"
 #include "iwpan.h"
 
@@ -65,3 +66,30 @@ nla_put_failure:
 }
 COMMAND(set, channel, "<channel>",
 	NL802154_CMD_SET_CHANNEL, 0, CIB_PHY, handle_channel_set, NULL);
+
+static int handle_tx_power_set(struct nl802154_state *state,
+			       struct nl_cb *cb,
+			       struct nl_msg *msg,
+			       int argc, char **argv,
+			       enum id_input id)
+{
+	long dbm;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* TX_POWER */
+	dbm = strtol(argv[0], &end, 10);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_S8(msg, NL802154_ATTR_TX_POWER, dbm);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, tx_power, "<dBm>",
+	NL802154_CMD_SET_TX_POWER, 0, CIB_PHY, handle_tx_power_set, NULL);
Signature · 1 line
2.1.0
author maintainer
#5 lore raw

PATCH 3/6 phy: add support for setting cca_mode

In reply to Alexander Aring
---
 src/nl802154.h |  3 +++
 src/phy.c      | 27 +++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
src/nl802154.h +3 -0
index 1af09ac..762fc38 100644
@@ -44,6 +44,7 @@ enum nl802154_commands {
 	NL802154_CMD_SET_PAN_ID,
 
 	NL802154_CMD_SET_TX_POWER,
+	NL802154_CMD_SET_CCA_MODE,
 
 	/* add new commands above here */
 
@@ -75,6 +76,8 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_TX_POWER,
 
+	NL802154_ATTR_CCA_MODE,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
src/phy.c +27 -0
index 811fc35..cfdf056 100644
@@ -93,3 +93,30 @@ nla_put_failure:
 }
 COMMAND(set, tx_power, "<dBm>",
 	NL802154_CMD_SET_TX_POWER, 0, CIB_PHY, handle_tx_power_set, NULL);
+
+static int handle_cca_mode_set(struct nl802154_state *state,
+			       struct nl_cb *cb,
+			       struct nl_msg *msg,
+			       int argc, char **argv,
+			       enum id_input id)
+{
+	unsigned long cca_mode;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* CCA_MODE */
+	cca_mode = strtoul(argv[0], &end, 10);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_U8(msg, NL802154_ATTR_CCA_MODE, cca_mode);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, cca_mode, "<mode>",
+	NL802154_CMD_SET_CCA_MODE, 0, CIB_PHY, handle_cca_mode_set, NULL);
Signature · 1 line
2.1.0
author maintainer
#6 lore raw

PATCH 4/6 mac: add support for setting max_frame_retries

In reply to Alexander Aring
---
 src/mac.c      | 29 +++++++++++++++++++++++++++++
 src/nl802154.h |  4 ++++
 2 files changed, 33 insertions(+)
src/mac.c +29 -0
index 5fa1111..16d1156 100644
@@ -9,6 +9,7 @@
 #include <netlink/msg.h>
 #include <netlink/attr.h>
 
+#include "nl_updates.h"
 #include "nl802154.h"
 #include "iwpan.h"
 
@@ -38,3 +39,31 @@ nla_put_failure:
 }
 COMMAND(set, pan_id, "<pan_id>",
 	NL802154_CMD_SET_PAN_ID, 0, CIB_NETDEV, handle_pan_id_set, NULL);
+
+static int handle_max_frame_retries_set(struct nl802154_state *state,
+					struct nl_cb *cb,
+					struct nl_msg *msg,
+					int argc, char **argv,
+					enum id_input id)
+{
+	long retries;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* RETRIES */
+	retries = strtol(argv[0], &end, 0);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_S8(msg, NL802154_ATTR_MAX_FRAME_RETRIES, retries);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, max_frame_retries, "<retries>",
+	NL802154_CMD_SET_MAX_FRAME_RETRIES, 0, CIB_NETDEV,
+	handle_max_frame_retries_set, NULL);
src/nl802154.h +4 -0
index 762fc38..a23c34f 100644
@@ -46,6 +46,8 @@ enum nl802154_commands {
 	NL802154_CMD_SET_TX_POWER,
 	NL802154_CMD_SET_CCA_MODE,
 
+	NL802154_CMD_SET_MAX_FRAME_RETRIES,
+
 	/* add new commands above here */
 
 	/* used to define NL802154_CMD_MAX below */
@@ -78,6 +80,8 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_CCA_MODE,
 
+	NL802154_ATTR_MAX_FRAME_RETRIES,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
Signature · 1 line
2.1.0
author maintainer
#7 lore raw

PATCH 5/6 mac: initial support for setting csma params

In reply to Alexander Aring
---
 src/mac.c      | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nl802154.h |  8 ++++++
 2 files changed, 92 insertions(+)
src/mac.c +84 -0
index 16d1156..233bdf4 100644
@@ -67,3 +67,87 @@ nla_put_failure:
 COMMAND(set, max_frame_retries, "<retries>",
 	NL802154_CMD_SET_MAX_FRAME_RETRIES, 0, CIB_NETDEV,
 	handle_max_frame_retries_set, NULL);
+
+static int handle_max_be(struct nl802154_state *state,
+			 struct nl_cb *cb,
+			 struct nl_msg *msg,
+			 int argc, char **argv,
+			 enum id_input id)
+{
+	unsigned long max_be;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* MAX_BE */
+	max_be = strtoul(argv[0], &end, 0);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_U8(msg, NL802154_ATTR_MAX_BE, max_be);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, max_be, "<max_be>",
+	NL802154_CMD_SET_MAX_BE, 0, CIB_NETDEV,
+	handle_max_be, NULL);
+
+static int handle_max_csma_backoffs(struct nl802154_state *state,
+				    struct nl_cb *cb,
+				    struct nl_msg *msg,
+				    int argc, char **argv,
+				    enum id_input id)
+{
+	unsigned long backoffs;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* BACKOFFS */
+	backoffs = strtoul(argv[0], &end, 0);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_U8(msg, NL802154_ATTR_MAX_CSMA_BACKOFFS, backoffs);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, max_csma_backoffs, "<backoffs>",
+	NL802154_CMD_SET_MAX_CSMA_BACKOFFS, 0, CIB_NETDEV,
+	handle_max_csma_backoffs, NULL);
+
+static int handle_min_be(struct nl802154_state *state,
+			 struct nl_cb *cb,
+			 struct nl_msg *msg,
+			 int argc, char **argv,
+			 enum id_input id)
+{
+	unsigned long min_be;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* MIN_BE */
+	min_be = strtoul(argv[0], &end, 0);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_U8(msg, NL802154_ATTR_MIN_BE, min_be);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, min_be, "<min_be>",
+	NL802154_CMD_SET_MIN_BE, 0, CIB_NETDEV,
+	handle_min_be, NULL);
src/nl802154.h +8 -0
index a23c34f..963feda 100644
@@ -48,6 +48,10 @@ enum nl802154_commands {
 
 	NL802154_CMD_SET_MAX_FRAME_RETRIES,
 
+	NL802154_CMD_SET_MAX_BE,
+	NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
+	NL802154_CMD_SET_MIN_BE,
+
 	/* add new commands above here */
 
 	/* used to define NL802154_CMD_MAX below */
@@ -82,6 +86,10 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_MAX_FRAME_RETRIES,
 
+	NL802154_ATTR_MAX_BE,
+	NL802154_ATTR_MAX_CSMA_BACKOFFS,
+	NL802154_ATTR_MIN_BE,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
Signature · 1 line
2.1.0
author maintainer
#8 lore raw

PATCH 6/6 phy: add support for cca mode 3 and/or handling

In reply to Alexander Aring
---
 src/nl802154.h |  1 +
 src/phy.c      | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
src/nl802154.h +1 -0
index 963feda..904bebb 100644
@@ -83,6 +83,7 @@ enum nl802154_attrs {
 	NL802154_ATTR_TX_POWER,
 
 	NL802154_ATTR_CCA_MODE,
+	NL802154_ATTR_CCA_MODE3_AND,
 
 	NL802154_ATTR_MAX_FRAME_RETRIES,
 
src/phy.c +14 -2
index cfdf056..1698cc2 100644
@@ -100,7 +100,7 @@ static int handle_cca_mode_set(struct nl802154_state *state,
 			       int argc, char **argv,
 			       enum id_input id)
 {
-	unsigned long cca_mode;
+	unsigned long cca_mode, cca_mode3_and;
 	char *end;
 
 	if (argc < 1)
@@ -111,6 +111,18 @@ static int handle_cca_mode_set(struct nl802154_state *state,
 	if (*end != '\0')
 		return 1;
 
+	if (cca_mode == 3) {
+		if (argc < 2)
+			return 1;
+
+		/* CCA_MODE */
+		cca_mode3_and = strtoul(argv[1], &end, 10);
+		if (*end != '\0')
+			return 1;
+
+		NLA_PUT_U8(msg, NL802154_ATTR_CCA_MODE3_AND, cca_mode3_and);
+	}
+
 	NLA_PUT_U8(msg, NL802154_ATTR_CCA_MODE, cca_mode);
 
 	return 0;
@@ -118,5 +130,5 @@ static int handle_cca_mode_set(struct nl802154_state *state,
 nla_put_failure:
 	return -ENOBUFS;
 }
-COMMAND(set, cca_mode, "<mode>",
+COMMAND(set, cca_mode, "<mode|3 <1|0>>",
 	NL802154_CMD_SET_CCA_MODE, 0, CIB_PHY, handle_cca_mode_set, NULL);
Signature · 1 line
2.1.0