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;
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;
struct iwinfo_ops {
+ int (*mode)(const char *, int *);
int (*channel)(const char *, int *);
int (*frequency)(const char *, int *);
int (*frequency_offset)(const char *, int *);
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 *);
#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);
};
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);
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);
#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);
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;
}
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),
"SHARED",
};
+const char *IWINFO_OPMODE_NAMES[] = {
+ "Unknown",
+ "Master",
+ "Ad-Hoc",
+ "Client",
+ "Monitor",
+};
+
/*
* ISO3166 country labels
}
+/* 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 *))
{
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 */
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)
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)
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)
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)
/* 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);
}
}
}
-int nl80211_get_mode(const char *ifname, char *buf)
+int nl80211_get_mode(const char *ifname, int *buf)
{
return wext_get_mode(ifname, buf);
}
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;
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 };
*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)
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);
nl80211_get_scancrypto(cipher, &e->crypto);
/* advance to next line */
- while( *res && *res++ != '\n' );
+ while (*res && *res++ != '\n');
count++;
e++;
/* Nop */
}
-int wext_get_mode(const char *ifname, char *buf)
+int wext_get_mode(const char *ifname, int *buf)
{
struct iwreq wrq;
{
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;
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;
/* 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;
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;
}