iwinfo: replace internal constant mode strings with enums

SVN-Revision: 30692
master
Jo-Philipp Wich 13 years ago
parent b1af9a779f
commit 76bb0f3309
  1. 15
      package/iwinfo/src/include/iwinfo.h
  2. 2
      package/iwinfo/src/include/iwinfo/madwifi.h
  3. 2
      package/iwinfo/src/include/iwinfo/nl80211.h
  4. 2
      package/iwinfo/src/include/iwinfo/wext.h
  5. 2
      package/iwinfo/src/include/iwinfo/wl.h
  6. 9
      package/iwinfo/src/iwinfo_cli.c
  7. 8
      package/iwinfo/src/iwinfo_lib.c
  8. 23
      package/iwinfo/src/iwinfo_lua.c
  9. 2
      package/iwinfo/src/iwinfo_madwifi.c
  10. 16
      package/iwinfo/src/iwinfo_nl80211.c
  11. 25
      package/iwinfo/src/iwinfo_wext.c
  12. 7
      package/iwinfo/src/iwinfo_wext_scan.c
  13. 10
      package/iwinfo/src/iwinfo_wl.c

@ -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 *);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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),

@ -44,6 +44,14 @@ const char *IWINFO_AUTH_NAMES[] = {
"SHARED",
};
const char *IWINFO_OPMODE_NAMES[] = {
"Unknown",
"Master",
"Ad-Hoc",
"Client",
"Monitor",
};
/*
* ISO3166 country labels

@ -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)

@ -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);
}

@ -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++;

@ -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;

@ -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;

@ -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;
}

Loading…
Cancel
Save