* [PATCH wpan-tools 1/3] mac: add support for setting lbt mode
2014-09-26 8:06 [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
@ 2014-09-26 8:06 ` Alexander Aring
2014-09-26 8:06 ` [PATCH wpan-tools 2/3] info: add support to dump phy pib Alexander Aring
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2014-09-26 8:06 UTC (permalink / raw)
To: linux-wpan; +Cc: Alexander Aring
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
src/mac.c | 27 +++++++++++++++++++++++++++
src/nl802154.h | 4 ++++
2 files changed, 31 insertions(+)
diff --git a/src/mac.c b/src/mac.c
index 1d12a04..a6c456f 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -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);
diff --git a/src/nl802154.h b/src/nl802154.h
index ce6ae2a..a30e9c0 100644
--- a/src/nl802154.h
+++ b/src/nl802154.h
@@ -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,
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH wpan-tools 2/3] info: add support to dump phy pib
2014-09-26 8:06 [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
2014-09-26 8:06 ` [PATCH wpan-tools 1/3] mac: add support for setting lbt mode Alexander Aring
@ 2014-09-26 8:06 ` Alexander Aring
2014-09-26 8:06 ` [PATCH wpan-tools 3/3] interface: add dump for iface mac parameters Alexander Aring
2014-09-26 8:07 ` [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2014-09-26 8:06 UTC (permalink / raw)
To: linux-wpan; +Cc: Alexander Aring
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
src/Makefile.am | 1 +
src/info.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/iwpan.h | 3 ++
src/nl802154.h | 7 ++++
| 5 +++
5 files changed, 124 insertions(+)
create mode 100644 src/info.c
diff --git a/src/Makefile.am b/src/Makefile.am
index b702c91..26f73b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ bin_PROGRAMS = \
iwpan_SOURCES = \
iwpan.c \
sections.c \
+ info.c \
interface.c \
phy.c \
mac.c
diff --git a/src/info.c b/src/info.c
new file mode 100644
index 0000000..6bbe3f0
--- /dev/null
+++ b/src/info.c
@@ -0,0 +1,108 @@
+#include <stdbool.h>
+#include <errno.h>
+#include <net/if.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl802154.h"
+#include "nl_extras.h"
+#include "iwpan.h"
+
+static int print_phy_handler(struct nl_msg *msg, void *arg)
+{
+ struct nlattr *tb_msg[NL802154_ATTR_MAX + 1];
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ int rem_page, i;
+ int64_t phy_id = -1;
+ bool print_name = true;
+ struct nlattr *nl_page;
+ unsigned long cca_mode;
+
+ nla_parse(tb_msg, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+
+ if (tb_msg[NL802154_ATTR_WPAN_PHY]) {
+ if (nla_get_u32(tb_msg[NL802154_ATTR_WPAN_PHY]) == phy_id)
+ print_name = false;
+ phy_id = nla_get_u32(tb_msg[NL802154_ATTR_WPAN_PHY]);
+ }
+ if (print_name && tb_msg[NL802154_ATTR_WPAN_PHY_NAME])
+ printf("wpan_phy %s\n", nla_get_string(tb_msg[NL802154_ATTR_WPAN_PHY_NAME]));
+
+ if (tb_msg[NL802154_ATTR_CHANNELS_SUPPORTED]) {
+ unsigned char page = 0;
+ unsigned long channel;
+ printf("supported channels:\n");
+ nla_for_each_nested(nl_page,
+ tb_msg[NL802154_ATTR_CHANNELS_SUPPORTED],
+ rem_page) {
+ channel = nla_get_u32(nl_page);
+ if (channel) {
+ printf("\tpage %d: ", page, channel);
+ for (i = 0; i <= 31; i++) {
+ if (channel & 0x1)
+ printf("%d,", i);
+ channel >>= 1;
+ }
+ /* TODO hack use sprintf here */
+ printf("\b \b\n");
+ }
+ page++;
+ }
+ }
+
+ if (tb_msg[NL802154_ATTR_PAGE])
+ printf("current_page: %d\n", nla_get_u8(tb_msg[NL802154_ATTR_PAGE]));
+
+ if (tb_msg[NL802154_ATTR_CHANNEL])
+ printf("current_channel: %d\n", nla_get_u8(tb_msg[NL802154_ATTR_CHANNEL]));
+
+ if (tb_msg[NL802154_ATTR_CCA_MODE]) {
+ cca_mode = nla_get_u8(tb_msg[NL802154_ATTR_CCA_MODE]);
+ printf("cca_mode: %d", cca_mode);
+ if (cca_mode == 3) {
+ if (nla_get_u8(tb_msg[NL802154_ATTR_CCA_MODE3_AND]))
+ printf(" AND ");
+ else
+ printf(" OR ");
+ }
+ printf("\n");
+ }
+
+ if (tb_msg[NL802154_ATTR_TX_POWER])
+ printf("tx_power: %d\n", nla_get_s8(tb_msg[NL802154_ATTR_TX_POWER]));
+
+ return 0;
+}
+
+static bool nl802154_has_split_wiphy = false;
+
+static int handle_info(struct nl802154_state *state,
+ struct nl_cb *cb,
+ struct nl_msg *msg,
+ int argc, char **argv,
+ enum id_input id)
+{
+ char *feat_args[] = { "features", "-q" };
+ int err;
+
+ err = handle_cmd(state, CIB_NONE, 2, feat_args);
+ if (!err && nl802154_has_split_wiphy) {
+ nla_put_flag(msg, NL802154_ATTR_SPLIT_WPAN_PHY_DUMP);
+ nlmsg_hdr(msg)->nlmsg_flags |= NLM_F_DUMP;
+ }
+
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL);
+
+ return 0;
+}
+
+__COMMAND(NULL, info, "info", NULL, NL802154_CMD_GET_WPAN_PHY, 0, 0, CIB_PHY, handle_info,
+ "Show capabilities for the specified wireless device.", NULL);
+TOPLEVEL(list, NULL, NL802154_CMD_GET_WPAN_PHY, NLM_F_DUMP, CIB_NONE, handle_info,
+ "List all wireless devices and their capabilities.");
+TOPLEVEL(phy, NULL, NL802154_CMD_GET_WPAN_PHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL);
diff --git a/src/iwpan.h b/src/iwpan.h
index d35bd7a..867bb18 100644
--- a/src/iwpan.h
+++ b/src/iwpan.h
@@ -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);
diff --git a/src/nl802154.h b/src/nl802154.h
index a30e9c0..2e3ec28 100644
--- a/src/nl802154.h
+++ b/src/nl802154.h
@@ -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,
--git a/src/nl_extras.h b/src/nl_extras.h
index 39a97c6..a591461 100644
--- a/src/nl_extras.h
+++ b/src/nl_extras.h
@@ -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
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH wpan-tools 3/3] interface: add dump for iface mac parameters
2014-09-26 8:06 [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
2014-09-26 8:06 ` [PATCH wpan-tools 1/3] mac: add support for setting lbt mode Alexander Aring
2014-09-26 8:06 ` [PATCH wpan-tools 2/3] info: add support to dump phy pib Alexander Aring
@ 2014-09-26 8:06 ` Alexander Aring
2014-09-26 8:07 ` [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2014-09-26 8:06 UTC (permalink / raw)
To: linux-wpan; +Cc: Alexander Aring
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
src/interface.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/nl802154.h | 2 ++
2 files changed, 103 insertions(+)
diff --git a/src/interface.c b/src/interface.c
index e3253c4..808b246 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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.");
diff --git a/src/nl802154.h b/src/nl802154.h
index 2e3ec28..f799d59 100644
--- a/src/nl802154.h
+++ b/src/nl802154.h
@@ -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,
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH wpan-tools 0/3] mac: info: interface: add basic support
2014-09-26 8:06 [PATCH wpan-tools 0/3] mac: info: interface: add basic support Alexander Aring
` (2 preceding siblings ...)
2014-09-26 8:06 ` [PATCH wpan-tools 3/3] interface: add dump for iface mac parameters Alexander Aring
@ 2014-09-26 8:07 ` Alexander Aring
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2014-09-26 8:07 UTC (permalink / raw)
To: linux-wpan
On Fri, Sep 26, 2014 at 10:06:06AM +0200, Alexander Aring wrote:
> 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
>
ah command for this was "iwpan dev", like iw tool for wireless.
- Alex
^ permalink raw reply [flat|nested] 5+ messages in thread