diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-02-23 13:16:09 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-02-23 13:16:09 +0000 |
commit | 76bb0f3309862e021d454783a957306b63613a9a (patch) | |
tree | c23c154a552ba0fd7f2e2d2a2eff3ea72dc7708d /package/iwinfo | |
parent | b1af9a779fda99262632d69c085aea16e17ac809 (diff) | |
download | mtk-20170518-76bb0f3309862e021d454783a957306b63613a9a.zip mtk-20170518-76bb0f3309862e021d454783a957306b63613a9a.tar.gz mtk-20170518-76bb0f3309862e021d454783a957306b63613a9a.tar.bz2 |
iwinfo: replace internal constant mode strings with enums
SVN-Revision: 30692
Diffstat (limited to 'package/iwinfo')
-rw-r--r-- | package/iwinfo/src/include/iwinfo.h | 15 | ||||
-rw-r--r-- | package/iwinfo/src/include/iwinfo/madwifi.h | 2 | ||||
-rw-r--r-- | package/iwinfo/src/include/iwinfo/nl80211.h | 2 | ||||
-rw-r--r-- | package/iwinfo/src/include/iwinfo/wext.h | 2 | ||||
-rw-r--r-- | package/iwinfo/src/include/iwinfo/wl.h | 2 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_cli.c | 9 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_lib.c | 8 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_lua.c | 23 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_madwifi.c | 2 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_nl80211.c | 16 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_wext.c | 25 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_wext_scan.c | 7 | ||||
-rw-r--r-- | package/iwinfo/src/iwinfo_wl.c | 10 |
13 files changed, 71 insertions, 52 deletions
diff --git a/package/iwinfo/src/include/iwinfo.h b/package/iwinfo/src/include/iwinfo.h index 72e2333..3c8b418 100644 --- a/package/iwinfo/src/include/iwinfo.h +++ b/package/iwinfo/src/include/iwinfo.h @@ -49,6 +49,17 @@ extern const char *IWINFO_KMGMT_NAMES[]; extern const char *IWINFO_AUTH_NAMES[]; +enum iwinfo_opmode { + IWINFO_OPMODE_UNKNOWN = 0, + IWINFO_OPMODE_MASTER = 1, + IWINFO_OPMODE_ADHOC = 2, + IWINFO_OPMODE_CLIENT = 3, + IWINFO_OPMODE_MONITOR = 4, +}; + +extern const char *IWINFO_OPMODE_NAMES[]; + + struct iwinfo_rate_entry { uint16_t rate; uint8_t mcs; @@ -90,7 +101,7 @@ struct iwinfo_crypto_entry { struct iwinfo_scanlist_entry { uint8_t mac[6]; uint8_t ssid[IWINFO_ESSID_MAX_SIZE+1]; - uint8_t mode[8]; + enum iwinfo_opmode mode; uint8_t channel; uint8_t signal; uint8_t quality; @@ -131,6 +142,7 @@ extern const struct iwinfo_hardware_entry IWINFO_HARDWARE_ENTRIES[]; struct iwinfo_ops { + int (*mode)(const char *, int *); int (*channel)(const char *, int *); int (*frequency)(const char *, int *); int (*frequency_offset)(const char *, int *); @@ -143,7 +155,6 @@ struct iwinfo_ops { int (*quality_max)(const char *, int *); int (*mbssid_support)(const char *, int *); int (*hwmodelist)(const char *, int *); - int (*mode)(const char *, char *); int (*ssid)(const char *, char *); int (*bssid)(const char *, char *); int (*country)(const char *, char *); diff --git a/package/iwinfo/src/include/iwinfo/madwifi.h b/package/iwinfo/src/include/iwinfo/madwifi.h index 9acbc36..14d8135 100644 --- a/package/iwinfo/src/include/iwinfo/madwifi.h +++ b/package/iwinfo/src/include/iwinfo/madwifi.h @@ -26,7 +26,7 @@ #include "iwinfo/api/madwifi.h" int madwifi_probe(const char *ifname); -int madwifi_get_mode(const char *ifname, char *buf); +int madwifi_get_mode(const char *ifname, int *buf); int madwifi_get_ssid(const char *ifname, char *buf); int madwifi_get_bssid(const char *ifname, char *buf); int madwifi_get_country(const char *ifname, char *buf); diff --git a/package/iwinfo/src/include/iwinfo/nl80211.h b/package/iwinfo/src/include/iwinfo/nl80211.h index 7bbf0ef..2854514 100644 --- a/package/iwinfo/src/include/iwinfo/nl80211.h +++ b/package/iwinfo/src/include/iwinfo/nl80211.h @@ -68,7 +68,7 @@ struct nl80211_array_buf { }; int nl80211_probe(const char *ifname); -int nl80211_get_mode(const char *ifname, char *buf); +int nl80211_get_mode(const char *ifname, int *buf); int nl80211_get_ssid(const char *ifname, char *buf); int nl80211_get_bssid(const char *ifname, char *buf); int nl80211_get_country(const char *ifname, char *buf); diff --git a/package/iwinfo/src/include/iwinfo/wext.h b/package/iwinfo/src/include/iwinfo/wext.h index 8412ef3..68b596e 100644 --- a/package/iwinfo/src/include/iwinfo/wext.h +++ b/package/iwinfo/src/include/iwinfo/wext.h @@ -27,7 +27,7 @@ int wext_probe(const char *ifname); -int wext_get_mode(const char *ifname, char *buf); +int wext_get_mode(const char *ifname, int *buf); int wext_get_ssid(const char *ifname, char *buf); int wext_get_bssid(const char *ifname, char *buf); int wext_get_country(const char *ifname, char *buf); diff --git a/package/iwinfo/src/include/iwinfo/wl.h b/package/iwinfo/src/include/iwinfo/wl.h index 47dda47..db37e37 100644 --- a/package/iwinfo/src/include/iwinfo/wl.h +++ b/package/iwinfo/src/include/iwinfo/wl.h @@ -26,7 +26,7 @@ #include "iwinfo/api/broadcom.h" int wl_probe(const char *ifname); -int wl_get_mode(const char *ifname, char *buf); +int wl_get_mode(const char *ifname, int *buf); int wl_get_ssid(const char *ifname, char *buf); int wl_get_bssid(const char *ifname, char *buf); int wl_get_country(const char *ifname, char *buf); diff --git a/package/iwinfo/src/iwinfo_cli.c b/package/iwinfo/src/iwinfo_cli.c index 186cce1..0fdb21e 100644 --- a/package/iwinfo/src/iwinfo_cli.c +++ b/package/iwinfo/src/iwinfo_cli.c @@ -391,10 +391,13 @@ static char * print_bssid(const struct iwinfo_ops *iw, const char *ifname) static char * print_mode(const struct iwinfo_ops *iw, const char *ifname) { + int mode; static char buf[128]; - if (iw->mode(ifname, buf)) - snprintf(buf, sizeof(buf), "unknown"); + if (iw->mode(ifname, &mode)) + mode = IWINFO_OPMODE_UNKNOWN; + + snprintf(buf, sizeof(buf), "%s", IWINFO_OPMODE_NAMES[mode]); return buf; } @@ -572,7 +575,7 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname) printf(" ESSID: %s\n", format_ssid(e->ssid)); printf(" Mode: %s Channel: %s\n", - e->mode ? (char *)e->mode : "unknown", + IWINFO_OPMODE_NAMES[e->mode], format_channel(e->channel)); printf(" Signal: %s Quality: %s/%s\n", format_signal(e->signal - 0x100), diff --git a/package/iwinfo/src/iwinfo_lib.c b/package/iwinfo/src/iwinfo_lib.c index a28d985..98bd1ec 100644 --- a/package/iwinfo/src/iwinfo_lib.c +++ b/package/iwinfo/src/iwinfo_lib.c @@ -44,6 +44,14 @@ const char *IWINFO_AUTH_NAMES[] = { "SHARED", }; +const char *IWINFO_OPMODE_NAMES[] = { + "Unknown", + "Master", + "Ad-Hoc", + "Client", + "Monitor", +}; + /* * ISO3166 country labels diff --git a/package/iwinfo/src/iwinfo_lua.c b/package/iwinfo/src/iwinfo_lua.c index 6b78cb7..e4435c1 100644 --- a/package/iwinfo/src/iwinfo_lua.c +++ b/package/iwinfo/src/iwinfo_lua.c @@ -235,6 +235,19 @@ static void iwinfo_L_cryptotable(lua_State *L, struct iwinfo_crypto_entry *c) } +/* Wrapper for mode */ +static int iwinfo_L_mode(lua_State *L, int (*func)(const char *, int *)) +{ + int mode; + const char *ifname = luaL_checkstring(L, 1); + + if ((*func)(ifname, &mode)) + mode = IWINFO_OPMODE_UNKNOWN; + + lua_pushstring(L, IWINFO_OPMODE_NAMES[mode]); + return 1; +} + /* Wrapper for assoclist */ static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *)) { @@ -383,7 +396,7 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int lua_setfield(L, -2, "channel"); /* Mode */ - lua_pushstring(L, (char *) e->mode); + lua_pushstring(L, IWINFO_OPMODE_NAMES[e->mode]); lua_setfield(L, -2, "mode"); /* Quality, Signal */ @@ -605,11 +618,11 @@ LUA_WRAP_INT(wl,signal) LUA_WRAP_INT(wl,noise) LUA_WRAP_INT(wl,quality) LUA_WRAP_INT(wl,quality_max) -LUA_WRAP_STRING(wl,mode) LUA_WRAP_STRING(wl,ssid) LUA_WRAP_STRING(wl,bssid) LUA_WRAP_STRING(wl,country) LUA_WRAP_STRING(wl,hardware_name) +LUA_WRAP_STRUCT(wl,mode) LUA_WRAP_STRUCT(wl,assoclist) LUA_WRAP_STRUCT(wl,txpwrlist) LUA_WRAP_STRUCT(wl,scanlist) @@ -633,11 +646,11 @@ LUA_WRAP_INT(madwifi,signal) LUA_WRAP_INT(madwifi,noise) LUA_WRAP_INT(madwifi,quality) LUA_WRAP_INT(madwifi,quality_max) -LUA_WRAP_STRING(madwifi,mode) LUA_WRAP_STRING(madwifi,ssid) LUA_WRAP_STRING(madwifi,bssid) LUA_WRAP_STRING(madwifi,country) LUA_WRAP_STRING(madwifi,hardware_name) +LUA_WRAP_STRUCT(madwifi,mode) LUA_WRAP_STRUCT(madwifi,assoclist) LUA_WRAP_STRUCT(madwifi,txpwrlist) LUA_WRAP_STRUCT(madwifi,scanlist) @@ -661,11 +674,11 @@ LUA_WRAP_INT(nl80211,signal) LUA_WRAP_INT(nl80211,noise) LUA_WRAP_INT(nl80211,quality) LUA_WRAP_INT(nl80211,quality_max) -LUA_WRAP_STRING(nl80211,mode) LUA_WRAP_STRING(nl80211,ssid) LUA_WRAP_STRING(nl80211,bssid) LUA_WRAP_STRING(nl80211,country) LUA_WRAP_STRING(nl80211,hardware_name) +LUA_WRAP_STRUCT(nl80211,mode) LUA_WRAP_STRUCT(nl80211,assoclist) LUA_WRAP_STRUCT(nl80211,txpwrlist) LUA_WRAP_STRUCT(nl80211,scanlist) @@ -688,11 +701,11 @@ LUA_WRAP_INT(wext,signal) LUA_WRAP_INT(wext,noise) LUA_WRAP_INT(wext,quality) LUA_WRAP_INT(wext,quality_max) -LUA_WRAP_STRING(wext,mode) LUA_WRAP_STRING(wext,ssid) LUA_WRAP_STRING(wext,bssid) LUA_WRAP_STRING(wext,country) LUA_WRAP_STRING(wext,hardware_name) +LUA_WRAP_STRUCT(wext,mode) LUA_WRAP_STRUCT(wext,assoclist) LUA_WRAP_STRUCT(wext,txpwrlist) LUA_WRAP_STRUCT(wext,scanlist) diff --git a/package/iwinfo/src/iwinfo_madwifi.c b/package/iwinfo/src/iwinfo_madwifi.c index 043cf53..50efcbf 100644 --- a/package/iwinfo/src/iwinfo_madwifi.c +++ b/package/iwinfo/src/iwinfo_madwifi.c @@ -333,7 +333,7 @@ void madwifi_close(void) /* Nop */ } -int madwifi_get_mode(const char *ifname, char *buf) +int madwifi_get_mode(const char *ifname, int *buf) { return wext_get_mode(ifname, buf); } diff --git a/package/iwinfo/src/iwinfo_nl80211.c b/package/iwinfo/src/iwinfo_nl80211.c index 5286150..bd3a60b 100644 --- a/package/iwinfo/src/iwinfo_nl80211.c +++ b/package/iwinfo/src/iwinfo_nl80211.c @@ -700,7 +700,7 @@ void nl80211_close(void) } } -int nl80211_get_mode(const char *ifname, char *buf) +int nl80211_get_mode(const char *ifname, int *buf) { return wext_get_mode(ifname, buf); } @@ -1525,9 +1525,9 @@ static int nl80211_get_scanlist_cb(struct nl_msg *msg, void *arg) memcpy(sl->e->mac, nla_data(bss[NL80211_BSS_BSSID]), 6); if (caps & (1<<1)) - memcpy(sl->e->mode, "Ad-Hoc", 6); + sl->e->mode = IWINFO_OPMODE_ADHOC; else - memcpy(sl->e->mode, "Master", 6); + sl->e->mode = IWINFO_OPMODE_MASTER; if (caps & (1<<4)) sl->e->crypto.enabled = 1; @@ -1568,7 +1568,6 @@ static int nl80211_get_scanlist_cb(struct nl_msg *msg, void *arg) static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len) { - struct nl_msg *ssids = NULL; struct nl80211_msg_conveyor *req; struct nl80211_scanlist sl = { .e = (struct iwinfo_scanlist_entry *)buf }; @@ -1590,11 +1589,6 @@ static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len) *len = sl.len * sizeof(struct iwinfo_scanlist_entry); return *len ? 0 : -1; - -nla_put_failure: - if (ssids) - nlmsg_free(ssids); - return -1; } int nl80211_get_scanlist(const char *ifname, char *buf, int *len) @@ -1652,7 +1646,7 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len) memcpy(e->ssid, ssid, min(strlen(ssid), sizeof(e->ssid) - 1)); /* Mode (assume master) */ - sprintf((char *)e->mode, "Master"); + e->mode = IWINFO_OPMODE_MASTER; /* Channel */ e->channel = nl80211_freq2channel(freq); @@ -1685,7 +1679,7 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len) nl80211_get_scancrypto(cipher, &e->crypto); /* advance to next line */ - while( *res && *res++ != '\n' ); + while (*res && *res++ != '\n'); count++; e++; diff --git a/package/iwinfo/src/iwinfo_wext.c b/package/iwinfo/src/iwinfo_wext.c index c74785f..cf3dccc 100644 --- a/package/iwinfo/src/iwinfo_wext.c +++ b/package/iwinfo/src/iwinfo_wext.c @@ -70,7 +70,7 @@ void wext_close(void) /* Nop */ } -int wext_get_mode(const char *ifname, char *buf) +int wext_get_mode(const char *ifname, int *buf) { struct iwreq wrq; @@ -78,36 +78,25 @@ int wext_get_mode(const char *ifname, char *buf) { switch(wrq.u.mode) { - case 0: - sprintf(buf, "Auto"); - break; - case 1: - sprintf(buf, "Ad-Hoc"); + *buf = IWINFO_OPMODE_ADHOC; break; case 2: - sprintf(buf, "Client"); + *buf = IWINFO_OPMODE_CLIENT; break; case 3: - sprintf(buf, "Master"); - break; - - case 4: - sprintf(buf, "Repeater"); - break; - - case 5: - sprintf(buf, "Secondary"); + *buf = IWINFO_OPMODE_MASTER; break; case 6: - sprintf(buf, "Monitor"); + *buf = IWINFO_OPMODE_MONITOR; break; default: - sprintf(buf, "Unknown"); + *buf = IWINFO_OPMODE_UNKNOWN; + break; } return 0; diff --git a/package/iwinfo/src/iwinfo_wext_scan.c b/package/iwinfo/src/iwinfo_wext_scan.c index 0a00933..ecd40d7 100644 --- a/package/iwinfo/src/iwinfo_wext_scan.c +++ b/package/iwinfo/src/iwinfo_wext_scan.c @@ -277,16 +277,17 @@ static inline void wext_fill_entry(struct stream_descr *stream, struct iw_event switch(event->u.mode) { case 1: - sprintf((char *) e->mode, "Ad-Hoc"); + e->mode = IWINFO_OPMODE_ADHOC; break; case 2: case 3: - sprintf((char *) e->mode, "Master"); + e->mode = IWINFO_OPMODE_MASTER; break; default: - sprintf((char *) e->mode, "Unknown"); + e->mode = IWINFO_OPMODE_UNKNOWN; + break; } break; diff --git a/package/iwinfo/src/iwinfo_wl.c b/package/iwinfo/src/iwinfo_wl.c index 038361f..b7e5d19 100644 --- a/package/iwinfo/src/iwinfo_wl.c +++ b/package/iwinfo/src/iwinfo_wl.c @@ -82,7 +82,7 @@ void wl_close(void) /* Nop */ } -int wl_get_mode(const char *ifname, char *buf) +int wl_get_mode(const char *ifname, int *buf) { int ret = -1; int ap, infra, passive; @@ -97,13 +97,13 @@ int wl_get_mode(const char *ifname, char *buf) return ret; if (passive) - sprintf(buf, "Monitor"); + *buf = IWINFO_OPMODE_MONITOR; else if (!infra) - sprintf(buf, "Ad-Hoc"); + *buf = IWINFO_OPMODE_ADHOC; else if (ap) - sprintf(buf, "Master"); + *buf = IWINFO_OPMODE_MASTER; else - sprintf(buf, "Client"); + *buf = IWINFO_OPMODE_CLIENT; return 0; } |