*/
#include <sys/types.h>
+#include <ctype.h>
#include <dirent.h>
#include <libubus.h>
#include <iwinfo.h>
static void
rpc_iwinfo_call_int(const char *name, int (*func)(const char *, int *),
- const char **map)
+ const char * const *map)
{
int rv;
}
}
+static void
+rpc_iwinfo_lower(const char *src, char *dst, size_t len)
+{
+ size_t i;
+
+ for (i = 0; *src && i < len; i++)
+ *dst++ = tolower(*src++);
+
+ *dst = 0;
+}
+
+static void
+rpc_iwinfo_add_bit_array(const char *name, uint32_t bits,
+ const char * const values[], size_t len,
+ bool lower, uint32_t zero)
+{
+ void *c;
+ size_t i;
+ char l[128];
+ const char *v;
+
+ if (!bits)
+ bits = zero;
+
+ c = blobmsg_open_array(&buf, name);
+
+ for (i = 0; i < len; i++)
+ if (bits & 1 << i)
+ {
+ v = values[i];
+
+ if (lower)
+ {
+ rpc_iwinfo_lower(v, l, strlen(values[i]));
+ v = l;
+ }
+
+ blobmsg_add_string(&buf, NULL, v);
+ }
+
+ blobmsg_close_array(&buf, c);
+}
+
static void
rpc_iwinfo_add_encryption(const char *name, struct iwinfo_crypto_entry *e)
{
- int ciph, wpa_version;
+ int wpa_version;
void *c, *d;
c = blobmsg_open_table(&buf, name);
{
if (!e->wpa_version)
{
- d = blobmsg_open_array(&buf, "wep");
-
- if (e->auth_algs & IWINFO_AUTH_OPEN)
- blobmsg_add_string(&buf, NULL, "open");
-
- if (e->auth_algs & IWINFO_AUTH_SHARED)
- blobmsg_add_string(&buf, NULL, "shared");
-
- blobmsg_close_array(&buf, d);
+ rpc_iwinfo_add_bit_array("wep", e->auth_algs,
+ IWINFO_AUTH_NAMES,
+ IWINFO_AUTH_COUNT,
+ true, 0);
}
else
{
blobmsg_close_array(&buf, d);
-
- d = blobmsg_open_array(&buf, "authentication");
-
- if (e->auth_suites & IWINFO_KMGMT_PSK)
- blobmsg_add_string(&buf, NULL, "psk");
-
- if (e->auth_suites & IWINFO_KMGMT_8021x)
- blobmsg_add_string(&buf, NULL, "802.1x");
-
- if (e->auth_suites & IWINFO_KMGMT_SAE)
- blobmsg_add_string(&buf, NULL, "sae");
-
- if (e->auth_suites & IWINFO_KMGMT_OWE)
- blobmsg_add_string(&buf, NULL, "owe");
-
- if (!e->auth_suites ||
- (e->auth_suites & IWINFO_KMGMT_NONE))
- blobmsg_add_string(&buf, NULL, "none");
-
- blobmsg_close_array(&buf, d);
+ rpc_iwinfo_add_bit_array("authentication",
+ e->auth_suites,
+ IWINFO_KMGMT_NAMES,
+ IWINFO_KMGMT_COUNT,
+ true, IWINFO_KMGMT_NONE);
}
- d = blobmsg_open_array(&buf, "ciphers");
- ciph = e->pair_ciphers | e->group_ciphers;
-
- if (ciph & IWINFO_CIPHER_WEP40)
- blobmsg_add_string(&buf, NULL, "wep-40");
-
- if (ciph & IWINFO_CIPHER_WEP104)
- blobmsg_add_string(&buf, NULL, "wep-104");
-
- if (ciph & IWINFO_CIPHER_TKIP)
- blobmsg_add_string(&buf, NULL, "tkip");
-
- if (ciph & IWINFO_CIPHER_CCMP)
- blobmsg_add_string(&buf, NULL, "ccmp");
-
- if (ciph & IWINFO_CIPHER_WRAP)
- blobmsg_add_string(&buf, NULL, "wrap");
-
- if (ciph & IWINFO_CIPHER_AESOCB)
- blobmsg_add_string(&buf, NULL, "aes-ocb");
- if (ciph & IWINFO_CIPHER_CKIP)
- blobmsg_add_string(&buf, NULL, "ckip");
-
- if (!ciph || (ciph & IWINFO_CIPHER_NONE))
- blobmsg_add_string(&buf, NULL, "none");
-
- blobmsg_close_array(&buf, d);
+ rpc_iwinfo_add_bit_array("ciphers",
+ e->pair_ciphers | e->group_ciphers,
+ IWINFO_CIPHER_NAMES,
+ IWINFO_CIPHER_COUNT,
+ true, IWINFO_CIPHER_NONE);
}
blobmsg_close_table(&buf, c);
rpc_iwinfo_call_htmodes(const char *name)
{
int modes;
- void *c;
-
- if (!iw->htmodelist(ifname, &modes))
- {
- c = blobmsg_open_array(&buf, name);
-
- if (modes & IWINFO_HTMODE_HT20)
- blobmsg_add_string(&buf, NULL, "HT20");
-
- if (modes & IWINFO_HTMODE_HT40)
- blobmsg_add_string(&buf, NULL, "HT40");
-
- if (modes & IWINFO_HTMODE_VHT20)
- blobmsg_add_string(&buf, NULL, "VHT20");
-
- if (modes & IWINFO_HTMODE_VHT40)
- blobmsg_add_string(&buf, NULL, "VHT40");
- if (modes & IWINFO_HTMODE_VHT80)
- blobmsg_add_string(&buf, NULL, "VHT80");
+ if (iw->htmodelist(ifname, &modes))
+ return;
- if (modes & IWINFO_HTMODE_VHT80_80)
- blobmsg_add_string(&buf, NULL, "VHT80+80");
-
- if (modes & IWINFO_HTMODE_VHT160)
- blobmsg_add_string(&buf, NULL, "VHT160");
-
- blobmsg_close_array(&buf, c);
- }
+ rpc_iwinfo_add_bit_array(name, modes & ~IWINFO_HTMODE_NOHT,
+ IWINFO_HTMODE_NAMES, IWINFO_HTMODE_COUNT,
+ false, 0);
}
-static void
+static int
rpc_iwinfo_call_hwmodes(const char *name)
{
int modes;
- void *c;
- if (!iw->hwmodelist(ifname, &modes))
- {
- c = blobmsg_open_array(&buf, name);
+ if (iw->hwmodelist(ifname, &modes))
+ return -1;
- if (modes & IWINFO_80211_AC)
- blobmsg_add_string(&buf, NULL, "ac");
+ rpc_iwinfo_add_bit_array(name, modes,
+ IWINFO_80211_NAMES, IWINFO_80211_COUNT,
+ false, 0);
- if (modes & IWINFO_80211_A)
- blobmsg_add_string(&buf, NULL, "a");
-
- if (modes & IWINFO_80211_B)
- blobmsg_add_string(&buf, NULL, "b");
+ return modes;
+}
- if (modes & IWINFO_80211_G)
- blobmsg_add_string(&buf, NULL, "g");
+static void rpc_iwinfo_call_hw_ht_mode(int hwmodelist)
+{
+ char text[32];
+ const char *hwmode_str;
+ const char *htmode_str;
+ int htmode;
- if (modes & IWINFO_80211_N)
- blobmsg_add_string(&buf, NULL, "n");
+ if (iwinfo_format_hwmodes(hwmodelist, text, sizeof(text)) > 0)
+ blobmsg_add_string(&buf, "hwmodes_text", text);
- blobmsg_close_array(&buf, c);
+ if (hwmodelist == IWINFO_80211_AD)
+ {
+ blobmsg_add_string(&buf, "hwmode", "ad");
+ return;
}
+
+ if (iw->htmode(ifname, &htmode))
+ return;
+
+ htmode_str = iwinfo_htmode_name(htmode);
+ if (htmode_str)
+ {
+ if (iwinfo_htmode_is_ht(htmode))
+ hwmode_str = "n";
+ else if (iwinfo_htmode_is_vht(htmode))
+ hwmode_str = "ac";
+ else if (iwinfo_htmode_is_he(htmode))
+ hwmode_str = "ax";
+ else
+ hwmode_str = "a/g";
+ } else
+ htmode_str = hwmode_str = "unknown";
+
+ blobmsg_add_string(&buf, "hwmode", hwmode_str);
+ blobmsg_add_string(&buf, "htmode", htmode_str);
}
static void
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
- int rv;
+ int rv, hwmodes;
void *c;
rv = rpc_iwinfo_open(msg);
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);
rpc_iwinfo_call_encryption("encryption");
rpc_iwinfo_call_htmodes("htmodes");
- rpc_iwinfo_call_hwmodes("hwmodes");
+ hwmodes = rpc_iwinfo_call_hwmodes("hwmodes");
+
+ if (hwmodes > 0)
+ rpc_iwinfo_call_hw_ht_mode(hwmodes);
c = blobmsg_open_table(&buf, "hardware");
rpc_iwinfo_call_hardware_id("id");
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;
blobmsg_add_u32(&buf, "quality", e->quality);
blobmsg_add_u32(&buf, "quality_max", e->quality_max);
+ if (e->ht_chan_info.primary_chan) {
+ 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);
{
blobmsg_add_u8(&buf, "ht", r->is_ht);
blobmsg_add_u8(&buf, "vht", r->is_vht);
+ blobmsg_add_u8(&buf, "he", r->is_he);
blobmsg_add_u32(&buf, "mhz", r->mhz);
blobmsg_add_u32(&buf, "rate", r->rate);
blobmsg_add_u32(&buf, "nss", r->nss);
blobmsg_add_u8(&buf, "short_gi", r->is_short_gi);
}
+ else if (r->is_he) {
+ blobmsg_add_u32(&buf, "mcs", r->mcs);
+ blobmsg_add_u32(&buf, "nss", r->nss);
+ blobmsg_add_u32(&buf, "he_gi", r->he_gi);
+ blobmsg_add_u32(&buf, "he_dcm", r->he_dcm);
+ }
}
static int
char res[IWINFO_BUFSIZE];
struct iwinfo_assoclist_entry *a;
struct ether_addr *macaddr = NULL;
- void *c, *d, *e;
+ void *c = NULL, *d, *e;
struct blob_attr *tb[__RPC_A_MAX];
bool found = false;
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;
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);
};
static struct ubus_object_type iwinfo_type =
- UBUS_OBJECT_TYPE("luci-rpc-iwinfo", iwinfo_methods);
+ UBUS_OBJECT_TYPE("rpcd-plugin-iwinfo", iwinfo_methods);
static struct ubus_object obj = {
.name = "iwinfo",