iwinfo: add "band" to the freqlist output
[project/rpcd.git] / iwinfo.c
index d4177297e9acfa42ae777778e377de7b21fde5c2..904b268394e742faec8be0f48e3bb316ab5c0aa9 100644 (file)
--- a/iwinfo.c
+++ b/iwinfo.c
@@ -241,30 +241,32 @@ rpc_iwinfo_call_htmodes(const char *name)
                                false, 0);
 }
 
-static void
+static int
 rpc_iwinfo_call_hwmodes(const char *name)
 {
        int modes;
 
        if (iw->hwmodelist(ifname, &modes))
-               return;
+               return -1;
 
        rpc_iwinfo_add_bit_array(name, modes,
                                IWINFO_80211_NAMES, IWINFO_80211_COUNT,
                                false, 0);
+
+       return modes;
 }
 
-static void rpc_iwinfo_call_hw_ht_mode()
+static void rpc_iwinfo_call_hw_ht_mode(int hwmodelist)
 {
+       char text[32];
        const char *hwmode_str;
        const char *htmode_str;
-       int32_t htmode = 0;
-       int modes;
+       int htmode;
 
-       if (iw->hwmodelist(ifname, &modes))
-               return;
+       if (iwinfo_format_hwmodes(hwmodelist, text, sizeof(text)) > 0)
+               blobmsg_add_string(&buf, "hwmodes_text", text);
 
-       if (modes == IWINFO_80211_AD)
+       if (hwmodelist == IWINFO_80211_AD)
        {
                blobmsg_add_string(&buf, "hwmode", "ad");
                return;
@@ -305,7 +307,7 @@ rpc_iwinfo_info(struct ubus_context *ctx, struct ubus_object *obj,
                 struct ubus_request_data *req, const char *method,
                 struct blob_attr *msg)
 {
-       int rv;
+       int rv, hwmodes;
        void *c;
 
        rv = rpc_iwinfo_open(msg);
@@ -342,9 +344,10 @@ rpc_iwinfo_info(struct ubus_context *ctx, struct ubus_object *obj,
 
        rpc_iwinfo_call_encryption("encryption");
        rpc_iwinfo_call_htmodes("htmodes");
-       rpc_iwinfo_call_hwmodes("hwmodes");
+       hwmodes = rpc_iwinfo_call_hwmodes("hwmodes");
 
-       rpc_iwinfo_call_hw_ht_mode();
+       if (hwmodes > 0)
+               rpc_iwinfo_call_hw_ht_mode(hwmodes);
 
        c = blobmsg_open_table(&buf, "hardware");
        rpc_iwinfo_call_hardware_id("id");
@@ -604,7 +607,7 @@ rpc_iwinfo_freqlist(struct ubus_context *ctx, struct ubus_object *obj,
                     struct ubus_request_data *req, const char *method,
                     struct blob_attr *msg)
 {
-       int i, rv, len, ch;
+       int i, rv, len, ch, band;
        char res[IWINFO_BUFSIZE];
        struct iwinfo_freqlist_entry *f;
        void *c, *d;
@@ -628,10 +631,18 @@ rpc_iwinfo_freqlist(struct ubus_context *ctx, struct ubus_object *obj,
                        f = (struct iwinfo_freqlist_entry *)&res[i];
                        d = blobmsg_open_table(&buf, NULL);
 
+                       band = iwinfo_band2ghz(f->band);
+                       if (band > 0)
+                               blobmsg_add_u32(&buf, "band", band);
                        blobmsg_add_u32(&buf, "channel", f->channel);
                        blobmsg_add_u32(&buf, "mhz", f->mhz);
                        blobmsg_add_u8(&buf, "restricted", f->restricted);
 
+                       rpc_iwinfo_add_bit_array("flags", f->flags,
+                                               IWINFO_FREQ_FLAG_NAMES,
+                                               IWINFO_FREQ_FLAG_COUNT,
+                                               true, 0);
+
                        if (ch > -1)
                                blobmsg_add_u8(&buf, "active", f->channel == ch);