diff mbox series

[RPCD,v4,3/4] iwinfo: add ht and vht operation info to wifi scan

Message ID 20201206011827.20782-4-ansuelsmth@gmail.com
State New
Headers show
Series Add support channel with to iwinfo | expand

Commit Message

Ansuel Smith Dec. 6, 2020, 1:18 a.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 | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Jo-Philipp Wich Jan. 5, 2021, 10:31 p.m. UTC | #1
Hi,

comments below.

> [...]
> @@ -441,6 +441,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);
>  

Only add the "ht_operation" table if there actually is ht_operation. I guess
wrapping it into  if (e->ht_chan_info.primary_chan) { ... } should do it.

> +			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_u32(&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_u32(&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);
> 

~ Jo
Ansuel Smith Jan. 6, 2021, 3:27 p.m. UTC | #2
> Hi,
> 
> comments below.
> 
> > [...]
> > @@ -441,6 +441,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);
> >
> 
> Only add the "ht_operation" table if there actually is ht_operation. I guess
> wrapping it into  if (e->ht_chan_info.primary_chan) { ... } should do it.
> 

I didn't add the check here as we can assume that ht_operation are always present.
Should I add this anyway? 

> > +			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_u32(&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_u32(&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);
> >
> 
> ~ Jo
Jo-Philipp Wich Jan. 6, 2021, 4:52 p.m. UTC | #3
Hi,

> I didn't add the check here as we can assume that ht_operation are always present.
> Should I add this anyway? 

why can we assume it? They way I see it, HT info is only populated if IE type
61 was present, valid and parsed from BSS info, otherwise the structure mightr
be present but zero-initialized.

It is counter-intuitive to include a `"ht_operation": { ... }` object in the
JSON dump for legacy stations that do not present this information.

~ Jo
diff mbox series

Patch

diff --git a/iwinfo.c b/iwinfo.c
index 7780e69..45ca784 100644
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -403,7 +403,7 @@  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;
@@ -441,6 +441,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_u32(&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_u32(&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);