linux-wpan.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [wpan-tools 0/7] IEEE 802.15.4 passive scan support
@ 2021-12-22 15:58 Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 1/7] iwpan: Fix the channels printing Miquel Raynal
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

Hello,

This series follows the work done in the Linux kernel stack: now that
the core knows about the different netlink commands and attributes in
order to support passive scan requests from end-to-end, here are the
userspace changes to be able to use it.

Here is a list of the new available features.

* Passively sending (or stopping) beacons. So far only intervals ranging
  from 0 to 14 are valid. Bigger values would request the PAN
  coordinator to answer to BEACONS_REQ (active scans), this is not
  supported yet.
  # iwpan dev wpan0 beacons send interval 2
  # iwpan dev wpan0 beacons stop

* Scanning all the channels or only a subset:
  # iwpan dev wpan1 scan type passive duration 3

* If a beacon is received during this operation the internal PAN list is
  updated and can be dumped or flushed with:
  # iwpan dev wpan1 pans dump
  PAN 0xffff (on wpan1)
	coordinator 0x2efefdd4cdbf9330
	page 0
	channel 13
	superframe spec. 0xcf22
	LQI 0
	seen 7156ms ago
  # iwpan dev wpan1 pans flush

* It is also possible to monitor the events with:
  # iwpan event

* As well as triggering a non blocking scan:
  # iwpan dev wpan1 scan trigger type passive duration 3
  # iwpan dev wpan1 scan done
  # iwpan dev wpan1 scan abort

Cheers,
Miquèl

David Girault (4):
  iwpan: Export iwpan_debug
  iwpan: Remove duplicated SECTION
  iwpan: Add full scan support
  iwpan: Add events support

Miquel Raynal (2):
  iwpan: Fix a comment
  iwpan: Synchronize nl802154 header with the Linux kernel

Romuald Despres (1):
  iwpan: Fix the channels printing

 DEST/usr/local/bin/iwpan      | Bin 0 -> 178448 bytes
 DEST/usr/local/bin/wpan-hwsim | Bin 0 -> 45056 bytes
 DEST/usr/local/bin/wpan-ping  | Bin 0 -> 47840 bytes
 src/Makefile.am               |   2 +
 src/event.c                   | 221 ++++++++++++++++
 src/info.c                    |   2 +-
 src/iwpan.c                   |   2 +-
 src/iwpan.h                   |  13 +-
 src/nl802154.h                |  95 +++++++
 src/scan.c                    | 471 ++++++++++++++++++++++++++++++++++
 10 files changed, 797 insertions(+), 9 deletions(-)
 create mode 100755 DEST/usr/local/bin/iwpan
 create mode 100755 DEST/usr/local/bin/wpan-hwsim
 create mode 100755 DEST/usr/local/bin/wpan-ping
 create mode 100644 src/event.c
 create mode 100644 src/scan.c

-- 
2.27.0


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

* [wpan-tools 1/7] iwpan: Fix the channels printing
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 2/7] iwpan: Export iwpan_debug Miquel Raynal
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Romuald Despres, Miquel Raynal

From: Romuald Despres <Romuald.Despres@qorvo.com>

The presence of a channel capability is checked against the tb_msg
netlink attributes array which is the root one, while here we are
looking for channel capabilities, themselves being nested and parsed
into tb_caps. Use tb_caps instead of tb_msg here otherwise we are
accessing a random index in the upper attributes list.

Signed-off-by: Romuald Despres <Romuald.Despres@qorvo.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/info.c b/src/info.c
index f85690c..8ed5e4f 100644
--- a/src/info.c
+++ b/src/info.c
@@ -342,7 +342,7 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
 			printf("\b \n");
 		}
 
-		if (tb_msg[NL802154_CAP_ATTR_CHANNELS]) {
+		if (tb_caps[NL802154_CAP_ATTR_CHANNELS]) {
 			int counter = 0;
 			int rem_pages;
 			struct nlattr *nl_pages;
-- 
2.27.0


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

* [wpan-tools 2/7] iwpan: Export iwpan_debug
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 1/7] iwpan: Fix the channels printing Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 3/7] iwpan: Fix a comment Miquel Raynal
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

From: David Girault <david.girault@qorvo.com>

This debug flag will be used later on in different files.

Signed-off-by: David Girault <david.girault@qorvo.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/iwpan.c | 2 +-
 src/iwpan.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/iwpan.c b/src/iwpan.c
index fb7bef1..3cf5fe2 100644
--- a/src/iwpan.c
+++ b/src/iwpan.c
@@ -21,7 +21,7 @@
 
 /* TODO libnl 1.x compatibility code */
 
-static int iwpan_debug = 0;
+int iwpan_debug = 0;
 
 static int nl802154_init(struct nl802154_state *state)
 {
diff --git a/src/iwpan.h b/src/iwpan.h
index 48c4f03..860dd37 100644
--- a/src/iwpan.h
+++ b/src/iwpan.h
@@ -120,4 +120,6 @@ DECLARE_SECTION(get);
 
 const char *iftype_name(enum nl802154_iftype iftype);
 
+extern int iwpan_debug;
+
 #endif /* __IWPAN_H */
-- 
2.27.0


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

* [wpan-tools 3/7] iwpan: Fix a comment
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 1/7] iwpan: Fix the channels printing Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 2/7] iwpan: Export iwpan_debug Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 4/7] iwpan: Remove duplicated SECTION Miquel Raynal
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

There are a couple of words missing, add them to clarify the comment.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/iwpan.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/iwpan.h b/src/iwpan.h
index 860dd37..9d265c6 100644
--- a/src/iwpan.h
+++ b/src/iwpan.h
@@ -43,7 +43,7 @@ struct cmd {
 	const enum command_identify_by idby;
 	/* The handler should return a negative error code,
 	 * zero on success, 1 if the arguments were wrong
-	 * and the usage message should and 2 otherwise.
+	 * and the usage message should be displayed, 2 otherwise.
 	 */
 	int (*handler)(struct nl802154_state *state,
 		       struct nl_cb *cb,
-- 
2.27.0


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

* [wpan-tools 4/7] iwpan: Remove duplicated SECTION
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
                   ` (2 preceding siblings ...)
  2021-12-22 15:58 ` [wpan-tools 3/7] iwpan: Fix a comment Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 5/7] iwpan: Synchronize nl802154 header with the Linux kernel Miquel Raynal
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

From: David Girault <david.girault@qorvo.com>

This section has been duplicated, drop one.

Signed-off-by: David Girault <david.girault@qorvo.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/iwpan.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/iwpan.h b/src/iwpan.h
index 9d265c6..406940a 100644
--- a/src/iwpan.h
+++ b/src/iwpan.h
@@ -90,12 +90,6 @@ struct cmd {
 		.handler = (_handler),					\
 		.help = (_help),					\
 	 }
-#define SECTION(_name)							\
-	struct cmd __section ## _ ## _name				\
-	__attribute__((used)) __attribute__((section("__cmd"))) = {	\
-		.name = (#_name),					\
-		.hidden = 1,						\
-	}
 
 #define SECTION(_name)							\
 	struct cmd __section ## _ ## _name				\
-- 
2.27.0


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

* [wpan-tools 5/7] iwpan: Synchronize nl802154 header with the Linux kernel
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
                   ` (3 preceding siblings ...)
  2021-12-22 15:58 ` [wpan-tools 4/7] iwpan: Remove duplicated SECTION Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
  2021-12-22 15:58 ` [wpan-tools 7/7] iwpan: Add events support Miquel Raynal
       [not found] ` <20211222155816.256405-7-miquel.raynal@bootlin.com>
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

The content of this file as evolved, reflect the changes accepted in the
mainline Linux kernel here.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/nl802154.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/src/nl802154.h b/src/nl802154.h
index ddcee12..73295bc 100644
--- a/src/nl802154.h
+++ b/src/nl802154.h
@@ -56,6 +56,14 @@ enum nl802154_commands {
 
 	NL802154_CMD_SET_WPAN_PHY_NETNS,
 
+	NL802154_CMD_TRIGGER_SCAN,
+	NL802154_CMD_ABORT_SCAN,
+	NL802154_CMD_SCAN_DONE,
+	NL802154_CMD_DUMP_PANS,
+	NL802154_CMD_FLUSH_PANS,
+	NL802154_CMD_SEND_BEACONS,
+	NL802154_CMD_STOP_BEACONS,
+
 	/* add new commands above here */
 
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
@@ -131,6 +139,13 @@ enum nl802154_attrs {
 	NL802154_ATTR_PID,
 	NL802154_ATTR_NETNS_FD,
 
+	NL802154_ATTR_SCAN_TYPE,
+	NL802154_ATTR_SCAN_FLAGS,
+	NL802154_ATTR_SCAN_CHANNELS,
+	NL802154_ATTR_SCAN_DURATION,
+	NL802154_ATTR_PAN,
+	NL802154_ATTR_BEACON_INTERVAL,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
@@ -217,6 +232,86 @@ enum nl802154_wpan_phy_capability_attr {
 	NL802154_CAP_ATTR_MAX = __NL802154_CAP_ATTR_AFTER_LAST - 1
 };
 
+/**
+ * enum nl802154_scan_types - Scan types
+ *
+ * @__NL802154_SCAN_INVALID: scan type number 0 is reserved
+ * @NL802154_SCAN_ED: An ED scan allows a device to obtain a measure of the peak
+ *	energy in each requested channel
+ * @NL802154_SCAN_ACTIVE: Locate any coordinator transmitting Beacon frames using
+ *	a Beacon Request command
+ * @NL802154_SCAN_PASSIVE: Locate any coordinator transmitting Beacon frames
+ * @NL802154_SCAN_ORPHAN: Relocate coordinator following a loss of synchronisation
+ * @NL802154_SCAN_ENHANCED_ACTIVE: Same as Active using Enhanced Beacon Request
+ *	command instead of Beacon Request command
+ * @NL802154_SCAN_RIT_PASSIVE: Passive scan for RIT Data Request command frames
+ *	instead of Beacon frames
+ * @NL802154_SCAN_ATTR_MAX: Maximum SCAN attribute number
+ */
+enum nl802154_scan_types {
+	__NL802154_SCAN_INVALID,
+	NL802154_SCAN_ED,
+	NL802154_SCAN_ACTIVE,
+	NL802154_SCAN_PASSIVE,
+	NL802154_SCAN_ORPHAN,
+	NL802154_SCAN_ENHANCED_ACTIVE,
+	NL802154_SCAN_RIT_PASSIVE,
+
+	/* keep last */
+	NL802154_SCAN_ATTR_MAX,
+};
+
+/**
+ * enum nl802154_scan_flags - Scan request control flags
+ *
+ * @NL802154_SCAN_FLAG_RANDOM_ADDR: use a random MAC address for this scan (ie.
+ *	a different one for every scan iteration). When the flag is set, full
+ *	randomisation is assumed.
+ */
+enum nl802154_scan_flags {
+	NL802154_SCAN_FLAG_RANDOM_ADDR = 1 << 0,
+};
+
+/**
+ * enum nl802154_pan - Netlink attributes for a PAN
+ *
+ * @__NL802154_PAN_INVALID: invalid
+ * @NL802154_PAN_PANID: PANID of the PAN (2 bytes)
+ * @NL802154_PAN_COORD_ADDR: Coordinator address, (8 bytes or 2 bytes)
+ * @NL802154_PAN_CHANNEL: channel number, related to @NL802154_PAN_PAGE (u8)
+ * @NL802154_PAN_PAGE: channel page, related to @NL802154_PAN_CHANNEL (u8)
+ * @NL802154_PAN_PREAMBLE_CODE: Preamble code while the beacon was received,
+ *	this is PHY dependent and optional (4 bytes)
+ * @NL802154_PAN_SUPERFRAME_SPEC: superframe specification of the PAN (u16)
+ * @NL802154_PAN_LINK_QUALITY: signal quality of beacon in unspecified units,
+ *	scaled to 0..255 (u8)
+ * @NL802154_PAN_GTS_PERMIT: set to true if GTS is permitted on this PAN
+ * @NL802154_PAN_PAYLOAD_DATA: binary data containing the raw data from the
+ *	frame payload, (only if beacon or probe response had data)
+ * @NL802154_PAN_STATUS: status, if this PAN is "used"
+ * @NL802154_PAN_SEEN_MS_AGO: age of this PAN entry in ms
+ * @NL802154_PAN_PAD: attribute used for padding for 64-bit alignment
+ * @NL802154_PAN_MAX: highest PAN attribute
+ */
+enum nl802154_pan {
+	__NL802154_PAN_INVALID,
+	NL802154_PAN_PANID,
+	NL802154_PAN_COORD_ADDR,
+	NL802154_PAN_CHANNEL,
+	NL802154_PAN_PAGE,
+	NL802154_PAN_PREAMBLE_CODE,
+	NL802154_PAN_SUPERFRAME_SPEC,
+	NL802154_PAN_LINK_QUALITY,
+	NL802154_PAN_GTS_PERMIT,
+	NL802154_PAN_PAYLOAD_DATA,
+	NL802154_PAN_STATUS,
+	NL802154_PAN_SEEN_MS_AGO,
+	NL802154_PAN_PAD,
+
+	/* keep last */
+	NL802154_PAN_MAX,
+};
+
 /**
  * enum nl802154_cca_modes - cca modes
  *
-- 
2.27.0


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

* [wpan-tools 7/7] iwpan: Add events support
  2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
                   ` (4 preceding siblings ...)
  2021-12-22 15:58 ` [wpan-tools 5/7] iwpan: Synchronize nl802154 header with the Linux kernel Miquel Raynal
@ 2021-12-22 15:58 ` Miquel Raynal
       [not found] ` <20211222155816.256405-7-miquel.raynal@bootlin.com>
  6 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2021-12-22 15:58 UTC (permalink / raw)
  To: Alexander Aring, Stefan Schmidt, linux-wpan
  Cc: David Girault, Romuald Despres, Frederic Blain, Thomas Petazzoni,
	netdev, Miquel Raynal

From: David Girault <david.girault@qorvo.com>

Add the possibility to listen to the scan multicast netlink family in
order to print all the events happening in the 802.15.4 stack.

Signed-off-by: David Girault <david.girault@qorvo.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 src/Makefile.am |   1 +
 src/event.c     | 221 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/iwpan.h     |   3 +
 src/scan.c      |   4 +-
 4 files changed, 227 insertions(+), 2 deletions(-)
 create mode 100644 src/event.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 18b3569..7933daf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ iwpan_SOURCES = \
 	phy.c \
 	mac.c \
 	scan.c \
+	event.c \
 	nl_extras.h \
 	nl802154.h
 
diff --git a/src/event.c b/src/event.c
new file mode 100644
index 0000000..0c5450b
--- /dev/null
+++ b/src/event.c
@@ -0,0 +1,221 @@
+#include <net/if.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <inttypes.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"
+
+struct print_event_args {
+	struct timeval ts; /* internal */
+	bool have_ts; /* must be set false */
+	bool frame, time, reltime;
+};
+
+static void parse_scan_terminated(struct nlattr **tb)
+{
+	struct nlattr *a;
+	if ((a = tb[NL802154_ATTR_SCAN_TYPE])) {
+		enum nl802154_scan_types st =
+			(enum nl802154_scan_types)nla_get_u8(a);
+		const char *stn = scantype_name(st);
+		printf(" type %s,", stn);
+	}
+	if ((a = tb[NL802154_ATTR_SCAN_FLAGS])) {
+		printf(" flags 0x%x,", nla_get_u32(a));
+	}
+	if ((a = tb[NL802154_ATTR_PAGE])) {
+		printf(" page %u,", nla_get_u8(a));
+	}
+	if ((a = tb[NL802154_ATTR_SCAN_CHANNELS])) {
+		printf(" channels mask 0x%x,", nla_get_u32(a));
+	}
+	/* TODO: show requested IEs */
+	if ((a = tb[NL802154_ATTR_PAN])) {
+		parse_scan_result_pan(a, tb[NL802154_ATTR_IFINDEX]);
+	}
+}
+
+static int print_event(struct nl_msg *msg, void *arg)
+{
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	struct nlattr *tb[NL802154_ATTR_MAX + 1], *nst;
+	struct print_event_args *args = arg;
+	char ifname[100];
+
+	uint8_t reg_type;
+	uint32_t wpan_phy_idx = 0;
+	int rem_nst;
+	uint16_t status;
+
+	if (args->time || args->reltime) {
+		unsigned long long usecs, previous;
+
+		previous = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec;
+		gettimeofday(&args->ts, NULL);
+		usecs = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec;
+		if (args->reltime) {
+			if (!args->have_ts) {
+				usecs = 0;
+				args->have_ts = true;
+			} else
+				usecs -= previous;
+		}
+		printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000);
+	}
+
+	nla_parse(tb, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+		  genlmsg_attrlen(gnlh, 0), NULL);
+
+	if (tb[NL802154_ATTR_IFINDEX] && tb[NL802154_ATTR_WPAN_PHY]) {
+		if_indextoname(nla_get_u32(tb[NL802154_ATTR_IFINDEX]), ifname);
+		printf("%s (phy #%d): ", ifname, nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]));
+	} else if (tb[NL802154_ATTR_WPAN_DEV] && tb[NL802154_ATTR_WPAN_PHY]) {
+		printf("wdev 0x%llx (phy #%d): ",
+			(unsigned long long)nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]),
+			nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]));
+	} else if (tb[NL802154_ATTR_IFINDEX]) {
+		if_indextoname(nla_get_u32(tb[NL802154_ATTR_IFINDEX]), ifname);
+		printf("%s: ", ifname);
+	} else if (tb[NL802154_ATTR_WPAN_DEV]) {
+		printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]));
+	} else if (tb[NL802154_ATTR_WPAN_PHY]) {
+		printf("phy #%d: ", nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]));
+	}
+
+	switch (gnlh->cmd) {
+	case NL802154_CMD_NEW_WPAN_PHY:
+		printf("renamed to %s\n", nla_get_string(tb[NL802154_ATTR_WPAN_PHY_NAME]));
+		break;
+	case NL802154_CMD_DEL_WPAN_PHY:
+		printf("delete wpan_phy\n");
+		break;
+	case NL802154_CMD_TRIGGER_SCAN:
+		printf("scan started\n");
+		break;
+	case NL802154_CMD_SCAN_DONE:
+		printf("scan finished:");
+		parse_scan_terminated(tb);
+		printf("\n");
+		break;
+	default:
+		printf("unknown event %d\n", gnlh->cmd);
+		break;
+	}
+	fflush(stdout);
+	return NL_SKIP;
+}
+
+static int __prepare_listen_events(struct nl802154_state *state)
+{
+	int mcid, ret;
+
+	/* Configuration multicast group */
+	mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME,
+				     "config");
+	if (mcid < 0)
+		return mcid;
+	ret = nl_socket_add_membership(state->nl_sock, mcid);
+	if (ret)
+		return ret;
+
+	/* Scan multicast group */
+	mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME,
+				     "scan");
+	if (mcid >= 0) {
+		ret = nl_socket_add_membership(state->nl_sock, mcid);
+		if (ret)
+			return ret;
+	}
+
+	/* MLME multicast group */
+	mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME,
+				     "mlme");
+	if (mcid >= 0) {
+		ret = nl_socket_add_membership(state->nl_sock, mcid);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int __do_listen_events(struct nl802154_state *state,
+			      struct print_event_args *args)
+{
+	struct nl_cb *cb = nl_cb_alloc(iwpan_debug ? NL_CB_DEBUG : NL_CB_DEFAULT);
+	if (!cb) {
+		fprintf(stderr, "failed to allocate netlink callbacks\n");
+		return -ENOMEM;
+	}
+	nl_socket_set_cb(state->nl_sock, cb);
+	/* No sequence checking for multicast messages */
+	nl_socket_disable_seq_check(state->nl_sock);
+	/* Install print_event message handler */
+	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_event, args);
+
+	/* Loop waiting until interrupted by signal */
+	while (1) {
+		int ret = nl_recvmsgs(state->nl_sock, cb);
+		if (ret) {
+			fprintf(stderr, "nl_recvmsgs return error %d\n", ret);
+			break;
+		}
+	}
+	/* Free allocated nl_cb structure */
+	nl_cb_put(cb);
+	return 0;
+}
+
+static int print_events(struct nl802154_state *state,
+			struct nl_cb *cb,
+			struct nl_msg *msg,
+			int argc, char **argv,
+			enum id_input id)
+{
+	struct print_event_args args;
+	int ret;
+
+	memset(&args, 0, sizeof(args));
+
+	argc--;
+	argv++;
+
+	while (argc > 0) {
+		if (strcmp(argv[0], "-f") == 0)
+			args.frame = true;
+		else if (strcmp(argv[0], "-t") == 0)
+			args.time = true;
+		else if (strcmp(argv[0], "-r") == 0)
+			args.reltime = true;
+		else
+			return 1;
+		argc--;
+		argv++;
+	}
+	if (args.time && args.reltime)
+		return 1;
+	if (argc)
+		return 1;
+
+	/* Prepare reception of all multicast messages */
+	ret = __prepare_listen_events(state);
+	if (ret)
+		return ret;
+
+	/* Read message loop */
+	return __do_listen_events(state, &args);
+}
+TOPLEVEL(event, "[-t|-r] [-f]", 0, 0, CIB_NONE, print_events,
+	"Monitor events from the kernel.\n"
+	"-t - print timestamp\n"
+	"-r - print relative timestamp\n"
+	"-f - print full frame for auth/assoc etc.");
diff --git a/src/iwpan.h b/src/iwpan.h
index 406940a..a71b991 100644
--- a/src/iwpan.h
+++ b/src/iwpan.h
@@ -114,6 +114,9 @@ DECLARE_SECTION(get);
 
 const char *iftype_name(enum nl802154_iftype iftype);
 
+const char *scantype_name(enum nl802154_scan_types scantype);
+int parse_scan_result_pan(struct nlattr *nestedpan, struct nlattr *ifattr);
+
 extern int iwpan_debug;
 
 #endif /* __IWPAN_H */
diff --git a/src/scan.c b/src/scan.c
index ec91c7c..a557e09 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -16,7 +16,7 @@
 
 static char scantypebuf[100];
 
-static const char *scantype_name(enum nl802154_scan_types scantype)
+const char *scantype_name(enum nl802154_scan_types scantype)
 {
 	switch (scantype) {
 	case NL802154_SCAN_ED:
@@ -168,7 +168,7 @@ static int scan_abort_handler(struct nl802154_state *state,
 }
 
 
-static int parse_scan_result_pan(struct nlattr *nestedpan, struct nlattr *ifattr)
+int parse_scan_result_pan(struct nlattr *nestedpan, struct nlattr *ifattr)
 {
 	struct nlattr *pan[NL802154_PAN_MAX + 1];
 	static struct nla_policy pan_policy[NL802154_PAN_MAX + 1] = {
-- 
2.27.0


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

* Re: [wpan-tools 6/7] iwpan: Add full scan support
       [not found] ` <20211222155816.256405-7-miquel.raynal@bootlin.com>
@ 2021-12-22 17:19   ` Alexander Aring
  2022-01-04 10:17     ` Miquel Raynal
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Aring @ 2021-12-22 17:19 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Stefan Schmidt, linux-wpan - ML, David Girault, Romuald Despres,
	Frederic Blain, Thomas Petazzoni, open list:NETWORKING [GENERAL]

Hi,

I did a quick overlook of those patches and I am very happy to see
such patches and I will try them out in the next few days! Thanks.

On Wed, 22 Dec 2021 at 10:58, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> From: David Girault <david.girault@qorvo.com>
>
> Bring support for different scanning operations, such as starting or
> aborting a scan operation with a given configuration, dumping the list
> of discovered PANs, and flushing the list.
>
> It also brings support for a couple of semi-debug features, such as a
> manual beacon request to ask sending or stopping beacons out of a
> particular interface. This is particularly useful when trying to
> validate the scanning support without proper hardware.
>
> Signed-off-by: David Girault <david.girault@qorvo.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  DEST/usr/local/bin/iwpan      | Bin 0 -> 178448 bytes
>  DEST/usr/local/bin/wpan-hwsim | Bin 0 -> 45056 bytes
>  DEST/usr/local/bin/wpan-ping  | Bin 0 -> 47840 bytes

I think those binaries were added by accident, or?

- Alex

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

* Re: [wpan-tools 6/7] iwpan: Add full scan support
  2021-12-22 17:19   ` [wpan-tools 6/7] iwpan: Add full scan support Alexander Aring
@ 2022-01-04 10:17     ` Miquel Raynal
  0 siblings, 0 replies; 9+ messages in thread
From: Miquel Raynal @ 2022-01-04 10:17 UTC (permalink / raw)
  To: Alexander Aring
  Cc: Stefan Schmidt, linux-wpan - ML, David Girault, Romuald Despres,
	Frederic Blain, Thomas Petazzoni, open list:NETWORKING [GENERAL]

Hi Alexander,

alex.aring@gmail.com wrote on Wed, 22 Dec 2021 12:19:36 -0500:

> Hi,
> 
> I did a quick overlook of those patches and I am very happy to see
> such patches and I will try them out in the next few days! Thanks.

Sure, thanks for the feedback all along this series, I'll try to
discuss and address all the points you raised.

> On Wed, 22 Dec 2021 at 10:58, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >
> > From: David Girault <david.girault@qorvo.com>
> >
> > Bring support for different scanning operations, such as starting or
> > aborting a scan operation with a given configuration, dumping the list
> > of discovered PANs, and flushing the list.
> >
> > It also brings support for a couple of semi-debug features, such as a
> > manual beacon request to ask sending or stopping beacons out of a
> > particular interface. This is particularly useful when trying to
> > validate the scanning support without proper hardware.
> >
> > Signed-off-by: David Girault <david.girault@qorvo.com>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  DEST/usr/local/bin/iwpan      | Bin 0 -> 178448 bytes
> >  DEST/usr/local/bin/wpan-hwsim | Bin 0 -> 45056 bytes
> >  DEST/usr/local/bin/wpan-ping  | Bin 0 -> 47840 bytes  
> 
> I think those binaries were added by accident, or?

Oops! Of course I'll drop them all.

Thanks,
Miquèl

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

end of thread, other threads:[~2022-01-04 10:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-22 15:58 [wpan-tools 0/7] IEEE 802.15.4 passive scan support Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 1/7] iwpan: Fix the channels printing Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 2/7] iwpan: Export iwpan_debug Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 3/7] iwpan: Fix a comment Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 4/7] iwpan: Remove duplicated SECTION Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 5/7] iwpan: Synchronize nl802154 header with the Linux kernel Miquel Raynal
2021-12-22 15:58 ` [wpan-tools 7/7] iwpan: Add events support Miquel Raynal
     [not found] ` <20211222155816.256405-7-miquel.raynal@bootlin.com>
2021-12-22 17:19   ` [wpan-tools 6/7] iwpan: Add full scan support Alexander Aring
2022-01-04 10:17     ` Miquel Raynal

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).