rpcd-mod-luci: reuse infos provided by libiwinfo
Don't hardcode bit/name pairs, instead iterate over what's known to the library and use that instead. This automatically adds the missing ad hwmode and HE80+80 htmode - and any future ones. The only difference in the output is the order of the 'hwmodes' array. Signed-off-by: Andre Heider <a.heider@gmail.com>
This commit is contained in:
parent
938e54df17
commit
eae86ee9bd
1 changed files with 72 additions and 131 deletions
|
@ -76,7 +76,9 @@ struct invoke_context {
|
||||||
void *priv;
|
void *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char **iw_modenames;
|
typedef const char * const iw_text_t;
|
||||||
|
static iw_text_t *iw_modenames, *iw_authnames, *iw_kmgmtnames,
|
||||||
|
*iw_ciphernames, *iw_htmodenames, *iw_80211names;
|
||||||
static struct iwinfo_ops *(*iw_backend)(const char *);
|
static struct iwinfo_ops *(*iw_backend)(const char *);
|
||||||
static void (*iw_close)(void);
|
static void (*iw_close)(void);
|
||||||
|
|
||||||
|
@ -884,6 +886,48 @@ iw_call_num(int (*method)(const char *, int *), const char *dev,
|
||||||
blobmsg_add_u32(blob, field, val);
|
blobmsg_add_u32(blob, field, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iw_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
|
||||||
|
iw_add_bit_array(struct blob_buf *buf, const char *name, uint32_t bits,
|
||||||
|
iw_text_t 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)
|
||||||
|
{
|
||||||
|
iw_lower(v, l, strlen(values[i]));
|
||||||
|
v = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
blobmsg_add_string(buf, NULL, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
blobmsg_close_array(buf, c);
|
||||||
|
}
|
||||||
|
|
||||||
static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
bool phy_only)
|
bool phy_only)
|
||||||
{
|
{
|
||||||
|
@ -895,7 +939,8 @@ static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
glob_t paths;
|
glob_t paths;
|
||||||
int nret, i;
|
int nret, i;
|
||||||
|
|
||||||
if (!iw_backend || !iw_close || !iw_modenames) {
|
if (!iw_backend || !iw_close || !iw_modenames || !iw_80211names ||
|
||||||
|
!iw_htmodenames || !iw_authnames || !iw_kmgmtnames || !iw_ciphernames) {
|
||||||
if (glob("/usr/lib/libiwinfo.so*", 0, NULL, &paths) != 0)
|
if (glob("/usr/lib/libiwinfo.so*", 0, NULL, &paths) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -910,8 +955,14 @@ static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
iw_backend = dlsym(iwlib, "iwinfo_backend");
|
iw_backend = dlsym(iwlib, "iwinfo_backend");
|
||||||
iw_close = dlsym(iwlib, "iwinfo_close");
|
iw_close = dlsym(iwlib, "iwinfo_close");
|
||||||
iw_modenames = dlsym(iwlib, "IWINFO_OPMODE_NAMES");
|
iw_modenames = dlsym(iwlib, "IWINFO_OPMODE_NAMES");
|
||||||
|
iw_80211names = dlsym(iwlib, "IWINFO_80211_NAMES");
|
||||||
|
iw_htmodenames = dlsym(iwlib, "IWINFO_HTMODE_NAMES");
|
||||||
|
iw_authnames = dlsym(iwlib, "IWINFO_AUTH_NAMES");
|
||||||
|
iw_kmgmtnames = dlsym(iwlib, "IWINFO_KMGMT_NAMES");
|
||||||
|
iw_ciphernames = dlsym(iwlib, "IWINFO_CIPHER_NAMES");
|
||||||
|
|
||||||
if (!iw_backend || !iw_close || !iw_modenames)
|
if (!iw_backend || !iw_close || !iw_modenames || !iw_80211names ||
|
||||||
|
!iw_htmodenames || !iw_authnames || !iw_kmgmtnames || !iw_ciphernames)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,68 +983,13 @@ static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
iw_call_num(iw->frequency, devname, buf, "frequency");
|
iw_call_num(iw->frequency, devname, buf, "frequency");
|
||||||
iw_call_num(iw->frequency_offset, devname, buf, "frequency_offset");
|
iw_call_num(iw->frequency_offset, devname, buf, "frequency_offset");
|
||||||
|
|
||||||
if (!iw->hwmodelist(devname, &nret)) {
|
if (!iw->hwmodelist(devname, &nret))
|
||||||
a = blobmsg_open_array(buf, "hwmodes");
|
iw_add_bit_array(buf, "hwmodes", nret,
|
||||||
|
iw_80211names, IWINFO_80211_COUNT, true, 0);
|
||||||
|
|
||||||
if (nret & IWINFO_80211_AX)
|
if (!iw->htmodelist(devname, &nret))
|
||||||
blobmsg_add_string(buf, NULL, "ax");
|
iw_add_bit_array(buf, "htmodes", nret & ~IWINFO_HTMODE_NOHT,
|
||||||
|
iw_htmodenames, IWINFO_HTMODE_COUNT, false, 0);
|
||||||
if (nret & IWINFO_80211_AC)
|
|
||||||
blobmsg_add_string(buf, NULL, "ac");
|
|
||||||
|
|
||||||
if (nret & IWINFO_80211_A)
|
|
||||||
blobmsg_add_string(buf, NULL, "a");
|
|
||||||
|
|
||||||
if (nret & IWINFO_80211_B)
|
|
||||||
blobmsg_add_string(buf, NULL, "b");
|
|
||||||
|
|
||||||
if (nret & IWINFO_80211_G)
|
|
||||||
blobmsg_add_string(buf, NULL, "g");
|
|
||||||
|
|
||||||
if (nret & IWINFO_80211_N)
|
|
||||||
blobmsg_add_string(buf, NULL, "n");
|
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!iw->htmodelist(devname, &nret)) {
|
|
||||||
a = blobmsg_open_array(buf, "htmodes");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HT20)
|
|
||||||
blobmsg_add_string(buf, NULL, "HT20");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HT40)
|
|
||||||
blobmsg_add_string(buf, NULL, "HT40");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_VHT20)
|
|
||||||
blobmsg_add_string(buf, NULL, "VHT20");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_VHT40)
|
|
||||||
blobmsg_add_string(buf, NULL, "VHT40");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_VHT80)
|
|
||||||
blobmsg_add_string(buf, NULL, "VHT80");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_VHT80_80)
|
|
||||||
blobmsg_add_string(buf, NULL, "VHT80+80");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_VHT160)
|
|
||||||
blobmsg_add_string(buf, NULL, "VHT160");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HE20)
|
|
||||||
blobmsg_add_string(buf, NULL, "HE20");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HE40)
|
|
||||||
blobmsg_add_string(buf, NULL, "HE40");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HE80)
|
|
||||||
blobmsg_add_string(buf, NULL, "HE80");
|
|
||||||
|
|
||||||
if (nret & IWINFO_HTMODE_HE160)
|
|
||||||
blobmsg_add_string(buf, NULL, "HE160");
|
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!iw->hardware_id(devname, (char *)&ids)) {
|
if (!iw->hardware_id(devname, (char *)&ids)) {
|
||||||
o2 = blobmsg_open_table(buf, "hardware");
|
o2 = blobmsg_open_table(buf, "hardware");
|
||||||
|
@ -1028,17 +1024,10 @@ static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
|
|
||||||
if (crypto.enabled) {
|
if (crypto.enabled) {
|
||||||
if (!crypto.wpa_version) {
|
if (!crypto.wpa_version) {
|
||||||
a = blobmsg_open_array(buf, "wep");
|
iw_add_bit_array(buf, "wep", crypto.auth_algs,
|
||||||
|
iw_authnames, IWINFO_AUTH_COUNT,
|
||||||
if (crypto.auth_algs & IWINFO_AUTH_OPEN)
|
true, 0);
|
||||||
blobmsg_add_string(buf, NULL, "open");
|
} else {
|
||||||
|
|
||||||
if (crypto.auth_algs & IWINFO_AUTH_SHARED)
|
|
||||||
blobmsg_add_string(buf, NULL, "shared");
|
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a = blobmsg_open_array(buf, "wpa");
|
a = blobmsg_open_array(buf, "wpa");
|
||||||
|
|
||||||
for (nret = 1; nret <= 3; nret++)
|
for (nret = 1; nret <= 3; nret++)
|
||||||
|
@ -1047,64 +1036,16 @@ static bool rpc_luci_get_iwinfo(struct blob_buf *buf, const char *devname,
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
blobmsg_close_array(buf, a);
|
||||||
|
|
||||||
a = blobmsg_open_array(buf, "authentication");
|
iw_add_bit_array(buf, "authentication",
|
||||||
|
crypto.auth_suites,
|
||||||
if (crypto.auth_suites & IWINFO_KMGMT_PSK)
|
iw_kmgmtnames, IWINFO_KMGMT_COUNT,
|
||||||
blobmsg_add_string(buf, NULL, "psk");
|
true, IWINFO_KMGMT_NONE);
|
||||||
|
|
||||||
if (crypto.auth_suites & IWINFO_KMGMT_8021x)
|
|
||||||
blobmsg_add_string(buf, NULL, "802.1x");
|
|
||||||
|
|
||||||
if (crypto.auth_suites & IWINFO_KMGMT_SAE)
|
|
||||||
blobmsg_add_string(buf, NULL, "sae");
|
|
||||||
|
|
||||||
if (crypto.auth_suites & IWINFO_KMGMT_OWE)
|
|
||||||
blobmsg_add_string(buf, NULL, "owe");
|
|
||||||
|
|
||||||
if (!crypto.auth_suites ||
|
|
||||||
(crypto.auth_suites & IWINFO_KMGMT_NONE))
|
|
||||||
blobmsg_add_string(buf, NULL, "none");
|
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a = blobmsg_open_array(buf, "ciphers");
|
iw_add_bit_array(buf, "ciphers",
|
||||||
nret = crypto.pair_ciphers | crypto.group_ciphers;
|
crypto.pair_ciphers | crypto.group_ciphers,
|
||||||
|
iw_ciphernames, IWINFO_CIPHER_COUNT,
|
||||||
if (nret & IWINFO_CIPHER_WEP40)
|
true, IWINFO_CIPHER_NONE);
|
||||||
blobmsg_add_string(buf, NULL, "wep-40");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_WEP104)
|
|
||||||
blobmsg_add_string(buf, NULL, "wep-104");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_TKIP)
|
|
||||||
blobmsg_add_string(buf, NULL, "tkip");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_CCMP)
|
|
||||||
blobmsg_add_string(buf, NULL, "ccmp");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_CCMP256)
|
|
||||||
blobmsg_add_string(buf, NULL, "ccmp-256");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_GCMP)
|
|
||||||
blobmsg_add_string(buf, NULL, "gcmp");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_GCMP256)
|
|
||||||
blobmsg_add_string(buf, NULL, "gcmp-256");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_WRAP)
|
|
||||||
blobmsg_add_string(buf, NULL, "wrap");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_AESOCB)
|
|
||||||
blobmsg_add_string(buf, NULL, "aes-ocb");
|
|
||||||
|
|
||||||
if (nret & IWINFO_CIPHER_CKIP)
|
|
||||||
blobmsg_add_string(buf, NULL, "ckip");
|
|
||||||
|
|
||||||
if (!nret || (nret & IWINFO_CIPHER_NONE))
|
|
||||||
blobmsg_add_string(buf, NULL, "none");
|
|
||||||
|
|
||||||
blobmsg_close_array(buf, a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blobmsg_close_table(buf, o2);
|
blobmsg_close_table(buf, o2);
|
||||||
|
|
Loading…
Reference in a new issue