diff mbox series

[RPCD,v4,4/4] iwinfo: export center channel for info ubus call

Message ID 20201206011827.20782-5-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 export the center channel sued by the wifi. Include this data in
the ubus info call to better know the channel utilizzation of the wifi.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 iwinfo.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

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

comment below.

> [...]
> diff --git a/iwinfo.c b/iwinfo.c
> index 45ca784..94fa822 100644
> --- a/iwinfo.c
> +++ b/iwinfo.c
> @@ -364,6 +364,8 @@ rpc_iwinfo_info(struct ubus_context *ctx, struct ubus_object *obj,
>  
>  	rpc_iwinfo_call_int("mode", iw->mode, IWINFO_OPMODE_NAMES);
>  	rpc_iwinfo_call_int("channel", iw->channel, NULL);

You need to check `iw->center_chan1` and `iw->center_chan2` for non-null
before calling them, otherwise rpcd will crash when querying wifi interfaces
not using the nl80211 backend.

Wrapping the next two lines into `if (iw->center_chan1) { ... }` should do.
Even better would be adding stubs returning `-1` to the other iwinfo backends
(madwifi, wl, wext).

> +	rpc_iwinfo_call_int("center_chan1", iw->center_chan1, NULL);
> +	rpc_iwinfo_call_int("center_chan2", iw->center_chan2, NULL);
>  
>  	rpc_iwinfo_call_int("frequency", iw->frequency, NULL);
>  	rpc_iwinfo_call_int("frequency_offset", iw->frequency_offset, NULL);
> 

~ Jo
Ansuel Smith Jan. 6, 2021, 3:30 p.m. UTC | #2
> Hi,
> 
> comment below.
> 
> > [...]
> > diff --git a/iwinfo.c b/iwinfo.c
> > index 45ca784..94fa822 100644
> > --- a/iwinfo.c
> > +++ b/iwinfo.c
> > @@ -364,6 +364,8 @@ rpc_iwinfo_info(struct ubus_context *ctx, struct
> ubus_object *obj,
> >
> >  	rpc_iwinfo_call_int("mode", iw->mode, IWINFO_OPMODE_NAMES);
> >  	rpc_iwinfo_call_int("channel", iw->channel, NULL);
> 
> You need to check `iw->center_chan1` and `iw->center_chan2` for non-null
> before calling them, otherwise rpcd will crash when querying wifi interfaces
> not using the nl80211 backend.
> 
> Wrapping the next two lines into `if (iw->center_chan1) { ... }` should do.
> Even better would be adding stubs returning `-1` to the other iwinfo backends
> (madwifi, wl, wext).
> 

Looking at [0], in theory we should be able to skip this check. Also about the
wrapper, I think it's better to directly skip the data instead of providing -1.
Am I wrong?

[0] https://github.com/mkschreder/openwrt-rpcd/blob/master/iwinfo.c

> > +	rpc_iwinfo_call_int("center_chan1", iw->center_chan1, NULL);
> > +	rpc_iwinfo_call_int("center_chan2", iw->center_chan2, NULL);
> >
> >  	rpc_iwinfo_call_int("frequency", iw->frequency, NULL);
> >  	rpc_iwinfo_call_int("frequency_offset", iw->frequency_offset, NULL);
> >
> 
> ~ Jo
diff mbox series

Patch

diff --git a/iwinfo.c b/iwinfo.c
index 45ca784..94fa822 100644
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -364,6 +364,8 @@  rpc_iwinfo_info(struct ubus_context *ctx, struct ubus_object *obj,
 
 	rpc_iwinfo_call_int("mode", iw->mode, IWINFO_OPMODE_NAMES);
 	rpc_iwinfo_call_int("channel", iw->channel, NULL);
+	rpc_iwinfo_call_int("center_chan1", iw->center_chan1, NULL);
+	rpc_iwinfo_call_int("center_chan2", iw->center_chan2, NULL);
 
 	rpc_iwinfo_call_int("frequency", iw->frequency, NULL);
 	rpc_iwinfo_call_int("frequency_offset", iw->frequency_offset, NULL);