What's new

Get radio status

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

bjan

New Around Here
Hi guys,

I'm currently running ASUS RT-AC68U with Asuswrt-Merlin 380.57 and I'm trying to find a way to fetch from the router the current WiFi status (on/off for each frequency) for some WiFi availability orchestration.

My personal preference is to get the information using shell and do a minimal amount of changes and addition to the firmware.
I found how one can check the radio status in code in src/router/shared/sysdeps/api-qca.c get_radio_status
and I could do some fancy grep work and get it from src/router/www/state.js that invokes router/httpd/web.c ej_radio_status function via asp (uses that same get_radio_status function) if there is not other way.

Going to the radio executable from src/router/rc/lan.c I see no hidden option to get the status (even though it's used) - BTW, that same executable does not document how to control a single interface, had to read the source for that.

Is there some ready made way to fetch the status of the radio from shell?

Any help will be appreciated, Thanks.
 
Code:
nvram get wl0_radio
nvram get_wl1_radio
 
Code:
nvram get wl0_radio
nvram get_wl1_radio

Thanks for your response.

I tried both previously, they always return 1 regardless of the value seen in the UI, not sure why, so I followed the UI path:

The function
Code:
int get_radio(int unit, int subunit)
{
    char tmp[100], prefix[] = "wlXXXXXXXXXXXXXX";

    if (subunit > 0)
        snprintf(prefix, sizeof(prefix), "wl%d.%d_", unit, subunit);
    else
        snprintf(prefix, sizeof(prefix), "wl%d_", unit);

    if (subunit > 0)
        return nvram_match(strcat_r(prefix, "radio", tmp), "1");
    else
        return get_radio_status(nvram_safe_get(strcat_r(prefix, "ifname", tmp)));
}

get's the radio status differently (ioctl with SIOCGIFFLAGS) when the subunit is 0.
Looking at what the UI checks, it indeed uses a 0 as the subunit for the get_radio call

Code:
static int
ej_radio_status(int eid, webs_t wp, int argc, char_t **argv)
{
    int retval = 0;

    retval += websWrite(wp, "radio_2=%d;\nradio_5=%d;", get_radio(0,0), get_radio(1,0));
    return retval;
}

Thanks
 
But you can't issue ioctl calls from a shell script, it's a C function.

Subunits are for guest networks. Subunit 0 is the primary interface.
 
I get that I can't invoke it from shell, that's why I'm asking if there's another way :)
The thing is, there is inconsistency between the values in nvram and the values ioctl return, not sure why.
I have the option of wgeting the state.js and greping the values injected there but it seems like the wrong way to do that.
I might try to create a fork with that additional capability in the radio command, just to see how it works... Now I need to read up on backing up all the configurations on my RT-AC68U :)

Thanks RMerlin for all your hard work! Asuswert-Merlin is awesome!
 
The only other way would be to see if the wl userspace tool provides any function to retrieve the current state.

I don't see why the nvram value wouldn't match the actual radio state however, unless the radio is being turned off in a particular way that bypasses the webui.
 
I'm using the radio command to turn of the radio like so:

radio off 0
radio off 1

So it might indeed be the problem, though it sounds strange that this method bypasses the nvram state yet the UI still reflects that change.
As I mentioned in the previous message, on each UI refresh (specifically the retrieval of state.js), the backend checks the ioctl per interface and not the nvram state:
Since the UI invokes ej_radio_status (state.js), that in turn invokes get_radio(0,0) & get_radio(1,0), each calling get_radio_status("eth1") & get_radio_status("eth2") respectively as the subunit in both cases is 0 - both get the right interface state from ioctl.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top