diff mbox series

[RPCD,RFC,2/2] iwinfo: add ht and vht operation info to wifi scan

Message ID 20201115225321.31277-1-ansuelsmth@gmail.com
State Superseded
Headers show
Series [IWINFO,RFC,1/2] iwinfo: export ht and vht operation in scan results | expand

Commit Message

Christian Marangi Nov. 15, 2020, 10:53 p.m. UTC
Iwinfo exports ht and vht operation info useful to get channel info of
nearby stations. Add these new info to ubus output.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 iwinfo.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/iwinfo.c b/iwinfo.c
index 7780e69..182db2d 100644
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -403,11 +403,30 @@  rpc_iwinfo_scan(struct ubus_context *ctx, struct ubus_object *obj,
                 struct blob_attr *msg)
 {
 	int i, rv, len;
-	void *c, *d;
+	void *c, *d, *t;
 	char mac[18];
 	char res[IWINFO_BUFSIZE];
 	struct iwinfo_scanlist_entry *e;
 
+	const char *ht_secondary_offset[4] = {
+		"no secondary",
+		"above",
+		"[reserved!]",
+		"below",
+	};
+
+	const char *ht_chan_width[2] = {
+		"20 MHz",
+		"any",
+	};
+
+	const char *vht_chan_width[] = {
+		[0] = "20 or 40 MHz",
+		[1] = "80 MHz",
+		[3] = "80+80 MHz",
+		[2] = "160 MHz",
+	};
+
 	rv = rpc_iwinfo_open(msg);
 
 	if (rv)
@@ -441,6 +460,20 @@  rpc_iwinfo_scan(struct ubus_context *ctx, struct ubus_object *obj,
 			blobmsg_add_u32(&buf, "quality", e->quality);
 			blobmsg_add_u32(&buf, "quality_max", e->quality_max);
 
+			t = blobmsg_open_table(&buf, "ht_operation");
+			blobmsg_add_u32(&buf, "primary_channel", e->ht_chan_info.primary_chan);
+			blobmsg_add_string(&buf, "secondary_channel_offset", ht_secondary_offset[e->ht_chan_info.secondary_chan_off]);
+			blobmsg_add_string(&buf, "channel_width", ht_chan_width[e->ht_chan_info.chan_width]);
+			blobmsg_close_table(&buf, t);
+
+			if (e->vht_chan_info.center_chan_1) {
+				t = blobmsg_open_table(&buf, "vht_operation");
+				blobmsg_add_string(&buf, "channel_width", vht_chan_width[e->vht_chan_info.chan_width]);
+				blobmsg_add_u32(&buf, "center_freq_1", e->vht_chan_info.center_chan_1);
+				blobmsg_add_u32(&buf, "center_freq_2", e->vht_chan_info.center_chan_2);
+				blobmsg_close_table(&buf, t);
+			}
+
 			rpc_iwinfo_add_encryption("encryption", &e->crypto);
 
 			blobmsg_close_table(&buf, d);