Skip to contentSkip to conversation

mac: info: interface: add basic support

PATCH In review Alexander Aring 1 participant 5 messages Sep 26, 2014 IEEE 802.15.4

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover mac: info: interface: add basic support

Hi,

this patch series add support for setting lbt mode and dump phy parameters and mac interface parameters.

Each interface "could" have different mac parameters, because the mac sublayer means mac algorithmn which are done by phy. These parameters need to be the same on each interface. There are couple of mac sublayer parameters like ARET, CSMA, promiscuous mode, etc... These parameters will be changed if an interface will comming up, otherwise it's there but not running. Solution to run this device with different parameter is first down all others interfaces and then up the interface with the different parameters. (Difficult to explain maybe it's clear when you play a little bit with that).

PHY settings will directly set registers to the driver. There is no mac functionality. Only physical changes in radio frequency handling.

dump example for phy pib:

root@DistroKit:~ iwpan phy
wpan_phy phy0
supported channels:

        page 0: 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 

current_page: 0
current_channel: 26
cca_mode: 1
tx_power: 3

dump example for mac pib:

phy#0

        Interface mon0
                ifindex 5
                wpan_dev 0x2
                extended_addr 0x0000000000000000
                short_addr 0xffff
                pan_id 0xffff
                type monitor
                max_frame_retries 3
                max_be 5
                max_csma_backoffs 4
                min_be 3
                lbt 0
        Interface wpan0
                ifindex 2
                wpan_dev 0x1
                extended_addr 0xaaaaaaaaaaaaaaaa
                short_addr 0xffff
                pan_id 0xabcd
                type node
                max_frame_retries 3
                max_be 5
                max_csma_backoffs 4
                min_be 3
                lbt 0

I know there are a lot of other pib values. I don't forget these but it need time to support it. I am still getting a state in the rework like mainline state.

Also it looks a little bit ugly but we can still change it for the wpan-tools. :-)

- Alex

Alexander Aring (3):
mac: add support for setting lbt mode
info: add support to dump phy pib
interface: add dump for iface mac parameters

 src/Makefile.am |   1 +
 src/info.c      | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/interface.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/iwpan.h     |   3 ++
 src/mac.c       |  27 ++++++++++++++
 src/nl802154.h  |  13 +++++++
 src/nl_extras.h |   5 +++
 7 files changed, 258 insertions(+)
 create mode 100644 src/info.c
Signature · 1 line
2.1.0
author maintainer
#1 lore raw

PATCH 1/3 mac: add support for setting lbt mode

---
 src/mac.c      | 27 +++++++++++++++++++++++++++
 src/nl802154.h |  4 ++++
 2 files changed, 31 insertions(+)
src/mac.c +27 -0
index 1d12a04..a6c456f 100644
@@ -178,3 +178,30 @@ nla_put_failure:
 COMMAND(set, min_be, "<min_be>",
 	NL802154_CMD_SET_MIN_BE, 0, CIB_NETDEV,
 	handle_min_be, NULL);
+
+static int handle_lbt_mode(struct nl802154_state *state,
+			   struct nl_cb *cb,
+			   struct nl_msg *msg,
+			   int argc, char **argv,
+			   enum id_input id)
+{
+	unsigned long mode;
+	char *end;
+
+	if (argc < 1)
+		return 1;
+
+	/* LBT_MODE */
+	mode = strtoul(argv[0], &end, 0);
+	if (*end != '\0')
+		return 1;
+
+	NLA_PUT_U8(msg, NL802154_ATTR_LBT_MODE, mode);
+
+	return 0;
+
+nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(set, lbt, "<1|0>",
+	NL802154_CMD_SET_LBT_MODE, 0, CIB_NETDEV, handle_lbt_mode, NULL);
src/nl802154.h +4 -0
index ce6ae2a..a30e9c0 100644
@@ -54,6 +54,8 @@ enum nl802154_commands {
 	NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
 	NL802154_CMD_SET_MIN_BE,
 
+	NL802154_CMD_SET_LBT_MODE,
+
 	/* add new commands above here */
 
 	/* used to define NL802154_CMD_MAX below */
@@ -95,6 +97,8 @@ enum nl802154_attrs {
 	NL802154_ATTR_MAX_CSMA_BACKOFFS,
 	NL802154_ATTR_MIN_BE,
 
+	NL802154_ATTR_LBT_MODE,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/3 info: add support to dump phy pib

In reply to Alexander Aring
---
 src/Makefile.am |   1 +
 src/info.c      | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/iwpan.h     |   3 ++
 src/nl802154.h  |   7 ++++
 src/nl_extras.h |   5 +++
 5 files changed, 124 insertions(+)
 create mode 100644 src/info.c
src/Makefile.am +1 -0
index b702c91..26f73b8 100644
@@ -4,6 +4,7 @@ bin_PROGRAMS = \
 iwpan_SOURCES = \
 	iwpan.c \
 	sections.c \
+	info.c \
 	interface.c \
 	phy.c \
 	mac.c
src/info.c new file +108 -0

108 lines not on this page · raw message

src/iwpan.h +3 -0
index d35bd7a..867bb18 100644
@@ -107,6 +107,9 @@ struct cmd {
 #define DECLARE_SECTION(_name)						\
 	extern struct cmd __section ## _ ## _name;
 
+int handle_cmd(struct nl802154_state *state, enum id_input idby,
+	       int argc, char **argv);
+
 DECLARE_SECTION(set);
 DECLARE_SECTION(get);
 
src/nl802154.h +7 -0
index a30e9c0..2e3ec28 100644
@@ -79,6 +79,8 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_IFACE_SOCKET_OWNER,
 
+	NL802154_ATTR_SPLIT_WPAN_PHY_DUMP,
+
 	NL802154_ATTR_PAGE,
 	NL802154_ATTR_CHANNEL,
 
@@ -99,6 +101,11 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_LBT_MODE,
 
+	NL802154_ATTR_GENERATION,
+
+	NL802154_ATTR_CHANNELS_SUPPORTED,
+	NL802154_ATTR_SUPPORTED_CHANNEL,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
src/nl_extras.h +5 -0
index 39a97c6..a591461 100644
@@ -7,6 +7,11 @@
 #define NLA_PUT_S8(n, attrtype, value) \
 	NLA_PUT_TYPE(n, int8_t, attrtype, value)
 
+static inline int8_t nla_get_s8(struct nlattr *nla)
+{
+	return *(int8_t *) nla_data(nla);
+}
+
 #endif /* NLA_S8 */
 
 #ifndef NLA_S16
Signature · 1 line
2.1.0
author maintainer
#3 lore raw

PATCH 3/3 interface: add dump for iface mac parameters

In reply to Alexander Aring
---
 src/interface.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nl802154.h  |   2 ++
 2 files changed, 103 insertions(+)
src/interface.c +101 -0
index e3253c4..808b246 100644
@@ -10,10 +10,28 @@
 #include <netlink/attr.h>
 
 #include "nl802154.h"
+#include "nl_extras.h"
 #include "iwpan.h"
 
 SECTION(interface);
 
+static char modebuf[100];
+
+const char *iftype_name(enum nl802154_iftype iftype)
+{
+	switch (iftype) {
+	case NL802154_IFTYPE_MONITOR:
+		return "monitor";
+	case NL802154_IFTYPE_NODE:
+		return "node";
+	case NL802154_IFTYPE_COORD:
+		return "coordinator";
+	default:
+		sprintf(modebuf, "Unknown mode (%d)", iftype);
+		return modebuf;
+	}
+}
+
 /* for help */
 #define IFACE_TYPES "Valid interface types are: node, monitor, coordinator."
 
@@ -98,3 +116,86 @@ static int handle_interface_del(struct nl802154_state *state,
 TOPLEVEL(del, NULL, NL802154_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_del,
 	 "Remove this virtual interface");
 HIDDEN(interface, del, NULL, NL802154_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_del);
+
+static int print_iface_handler(struct nl_msg *msg, void *arg)
+{
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	struct nlattr *tb_msg[NL802154_ATTR_MAX + 1];
+	unsigned int *wpan_phy = arg;
+	const char *indent = "";
+
+	nla_parse(tb_msg, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+		  genlmsg_attrlen(gnlh, 0), NULL);
+
+	if (wpan_phy && tb_msg[NL802154_ATTR_WPAN_PHY]) {
+		unsigned int thiswpan_phy = nla_get_u32(tb_msg[NL802154_ATTR_WPAN_PHY]);
+		indent = "\t";
+		if (*wpan_phy != thiswpan_phy)
+			printf("phy#%d\n", thiswpan_phy);
+		*wpan_phy = thiswpan_phy;
+	}
+
+	if (tb_msg[NL802154_ATTR_IFNAME])
+		printf("%sInterface %s\n", indent, nla_get_string(tb_msg[NL802154_ATTR_IFNAME]));
+	else
+		printf("%sUnnamed/non-netdev interface\n", indent);
+
+	if (tb_msg[NL802154_ATTR_IFINDEX])
+		printf("%s\tifindex %d\n", indent, nla_get_u32(tb_msg[NL802154_ATTR_IFINDEX]));
+	if (tb_msg[NL802154_ATTR_WPAN_DEV])
+		printf("%s\twpan_dev 0x%llx\n", indent,
+		       (unsigned long long)nla_get_u64(tb_msg[NL802154_ATTR_WPAN_DEV]));
+	/* TODO byteorder? */
+	if (tb_msg[NL802154_ATTR_EXTENDED_ADDR])
+		printf("%s\textended_addr 0x%016llx\n", indent, nla_get_u64(tb_msg[NL802154_ATTR_EXTENDED_ADDR]));
+	/* TODO byteorder? */
+	if (tb_msg[NL802154_ATTR_SHORT_ADDR])
+		printf("%s\tshort_addr 0x%04x\n", indent, nla_get_u16(tb_msg[NL802154_ATTR_SHORT_ADDR]));
+	/* TODO byteorder? */
+	if (tb_msg[NL802154_ATTR_PAN_ID])
+		printf("%s\tpan_id 0x%04x\n", indent, nla_get_u16(tb_msg[NL802154_ATTR_PAN_ID]));
+	if (tb_msg[NL802154_ATTR_IFTYPE])
+		printf("%s\ttype %s\n", indent, iftype_name(nla_get_u32(tb_msg[NL802154_ATTR_IFTYPE])));
+	if (!wpan_phy && tb_msg[NL802154_ATTR_WPAN_PHY])
+		printf("%s\twpan_phy %d\n", indent, nla_get_u32(tb_msg[NL802154_ATTR_WPAN_PHY]));
+	if (tb_msg[NL802154_ATTR_MAX_FRAME_RETRIES])
+		printf("%s\tmax_frame_retries %d\n", indent, nla_get_s8(tb_msg[NL802154_ATTR_MAX_FRAME_RETRIES]));
+	if (tb_msg[NL802154_ATTR_MAX_BE])
+		printf("%s\tmax_be %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MAX_BE]));
+	if (tb_msg[NL802154_ATTR_MAX_CSMA_BACKOFFS])
+		printf("%s\tmax_csma_backoffs %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MAX_CSMA_BACKOFFS]));
+	if (tb_msg[NL802154_ATTR_MIN_BE])
+		printf("%s\tmin_be %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MIN_BE]));
+	if (tb_msg[NL802154_ATTR_LBT_MODE])
+		printf("%s\tlbt %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_LBT_MODE]));
+
+	return NL_SKIP;
+}
+
+static int handle_interface_info(struct nl802154_state *state,
+				 struct nl_cb *cb,
+				 struct nl_msg *msg,
+				 int argc, char **argv,
+				 enum id_input id)
+{
+	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_iface_handler, NULL);
+	return 0;
+}
+
+TOPLEVEL(info, NULL, NL802154_CMD_GET_INTERFACE, 0, CIB_NETDEV, handle_interface_info,
+	 "Show information for this interface.");
+
+static unsigned int dev_dump_wpan_phy;
+
+static int handle_dev_dump(struct nl802154_state *state,
+			   struct nl_cb *cb,
+			   struct nl_msg *msg,
+			   int argc, char **argv,
+			   enum id_input id)
+{
+	dev_dump_wpan_phy = -1;
+	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_iface_handler, &dev_dump_wpan_phy);
+	return 0;
+}
+TOPLEVEL(dev, NULL, NL802154_CMD_GET_INTERFACE, NLM_F_DUMP, CIB_NONE, handle_dev_dump,
+	 "List all network interfaces for wireless hardware.");
src/nl802154.h +2 -0
index 2e3ec28..f799d59 100644
@@ -106,6 +106,8 @@ enum nl802154_attrs {
 	NL802154_ATTR_CHANNELS_SUPPORTED,
 	NL802154_ATTR_SUPPORTED_CHANNEL,
 
+	NL802154_ATTR_EXTENDED_ADDR,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 	__NL802154_ATTR_AFTER_LAST,
Signature · 1 line
2.1.0
author maintainer
#4 lore raw
In reply to Alexander Aring
Quoted 47 lines · Alexander Aring

Hi,

this patch series add support for setting lbt mode and dump phy parameters and mac interface parameters.

Each interface "could" have different mac parameters, because the mac sublayer means mac algorithmn which are done by phy. These parameters need to be the same on each interface. There are couple of mac sublayer parameters like ARET, CSMA, promiscuous mode, etc... These parameters will be changed if an interface will comming up, otherwise it's there but not running. Solution to run this device with different parameter is first down all others interfaces and then up the interface with the different parameters. (Difficult to explain maybe it's clear when you play a little bit with that).

PHY settings will directly set registers to the driver. There is no mac functionality. Only physical changes in radio frequency handling.

dump example for phy pib:

root@DistroKit:~ iwpan phy
wpan_phy phy0
supported channels:

        page 0: 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 

current_page: 0
current_channel: 26
cca_mode: 1
tx_power: 3

dump example for mac pib:

phy#0

        Interface mon0
                ifindex 5
                wpan_dev 0x2
                extended_addr 0x0000000000000000
                short_addr 0xffff
                pan_id 0xffff
                type monitor
                max_frame_retries 3
                max_be 5
                max_csma_backoffs 4
                min_be 3
                lbt 0
        Interface wpan0
                ifindex 2
                wpan_dev 0x1
                extended_addr 0xaaaaaaaaaaaaaaaa
Quoted 9 lines
                short_addr 0xffff
                pan_id 0xabcd
                type node
                max_frame_retries 3
                max_be 5
                max_csma_backoffs 4
                min_be 3
                lbt 0

ah command for this was "iwpan dev", like iw tool for wireless.

- Alex