libs/iwinfo: add *_get_freqlist()
This commit is contained in:
parent
2bfa17e6f4
commit
1b77a6f4c4
8 changed files with 109 additions and 0 deletions
|
@ -36,6 +36,11 @@ struct iwinfo_txpwrlist_entry {
|
|||
uint8_t mw;
|
||||
};
|
||||
|
||||
struct iwinfo_freqlist_entry {
|
||||
uint8_t channel;
|
||||
uint32_t mhz;
|
||||
};
|
||||
|
||||
struct iwinfo_crypto_entry {
|
||||
uint8_t enabled;
|
||||
uint8_t wpa_version;
|
||||
|
|
|
@ -210,6 +210,39 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* Wrapper for frequency list */
|
||||
static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
|
||||
{
|
||||
int i, x, len;
|
||||
char rv[IWINFO_BUFSIZE];
|
||||
const char *ifname = luaL_checkstring(L, 1);
|
||||
struct iwinfo_freqlist_entry *e;
|
||||
|
||||
lua_newtable(L);
|
||||
memset(rv, 0, sizeof(rv));
|
||||
|
||||
if( !(*func)(ifname, rv, &len) )
|
||||
{
|
||||
for( i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++ )
|
||||
{
|
||||
e = (struct iwinfo_freqlist_entry *) &rv[i];
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
/* MHz */
|
||||
lua_pushinteger(L, e->mhz);
|
||||
lua_setfield(L, -2, "mhz");
|
||||
|
||||
/* Channel */
|
||||
lua_pushinteger(L, e->channel);
|
||||
lua_setfield(L, -2, "channel");
|
||||
|
||||
lua_rawseti(L, -2, x);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Broadcom */
|
||||
LUA_WRAP_INT(wl,channel)
|
||||
|
@ -227,6 +260,7 @@ LUA_WRAP_STRING(wl,enctype)
|
|||
LUA_WRAP_LIST(wl,assoclist)
|
||||
LUA_WRAP_LIST(wl,txpwrlist)
|
||||
LUA_WRAP_LIST(wl,scanlist)
|
||||
LUA_WRAP_LIST(wl,freqlist)
|
||||
|
||||
/* Madwifi */
|
||||
LUA_WRAP_INT(madwifi,channel)
|
||||
|
@ -244,6 +278,7 @@ LUA_WRAP_STRING(madwifi,enctype)
|
|||
LUA_WRAP_LIST(madwifi,assoclist)
|
||||
LUA_WRAP_LIST(madwifi,txpwrlist)
|
||||
LUA_WRAP_LIST(madwifi,scanlist)
|
||||
LUA_WRAP_LIST(madwifi,freqlist)
|
||||
|
||||
/* Wext */
|
||||
LUA_WRAP_INT(wext,channel)
|
||||
|
@ -261,6 +296,7 @@ LUA_WRAP_STRING(wext,enctype)
|
|||
LUA_WRAP_LIST(wext,assoclist)
|
||||
LUA_WRAP_LIST(wext,txpwrlist)
|
||||
LUA_WRAP_LIST(wext,scanlist)
|
||||
LUA_WRAP_LIST(wext,freqlist)
|
||||
|
||||
/* Broadcom table */
|
||||
static const luaL_reg R_wl[] = {
|
||||
|
@ -278,6 +314,7 @@ static const luaL_reg R_wl[] = {
|
|||
LUA_REG(wl,assoclist),
|
||||
LUA_REG(wl,txpwrlist),
|
||||
LUA_REG(wl,scanlist),
|
||||
LUA_REG(wl,freqlist),
|
||||
LUA_REG(wl,mbssid_support),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
@ -298,6 +335,7 @@ static const luaL_reg R_madwifi[] = {
|
|||
LUA_REG(madwifi,assoclist),
|
||||
LUA_REG(madwifi,txpwrlist),
|
||||
LUA_REG(madwifi,scanlist),
|
||||
LUA_REG(madwifi,freqlist),
|
||||
LUA_REG(madwifi,mbssid_support),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
@ -318,6 +356,7 @@ static const luaL_reg R_wext[] = {
|
|||
LUA_REG(wext,assoclist),
|
||||
LUA_REG(wext,txpwrlist),
|
||||
LUA_REG(wext,scanlist),
|
||||
LUA_REG(wext,freqlist),
|
||||
LUA_REG(wext,mbssid_support),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -494,6 +494,32 @@ int madwifi_get_scanlist(const char *ifname, char *buf, int *len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int madwifi_get_freqlist(const char *ifname, char *buf, int *len)
|
||||
{
|
||||
int i, bl;
|
||||
struct ieee80211req_chaninfo chans;
|
||||
struct iwinfo_freqlist_entry entry;
|
||||
|
||||
if( get80211priv(ifname, IEEE80211_IOCTL_GETCHANINFO, &chans, sizeof(chans)) >= 0 )
|
||||
{
|
||||
bl = 0;
|
||||
|
||||
for( i = 0; i < chans.ic_nchans; i++ )
|
||||
{
|
||||
entry.mhz = (int)(chans.ic_chans[i].ic_freq / 1000);
|
||||
entry.channel = chans.ic_chans[i].ic_ieee;
|
||||
|
||||
memcpy(&buf[bl], &entry, sizeof(struct iwinfo_freqlist_entry));
|
||||
bl += sizeof(struct iwinfo_freqlist_entry);
|
||||
}
|
||||
|
||||
*len = bl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int madwifi_get_mbssid_support(const char *ifname, int *buf)
|
||||
{
|
||||
/* We assume that multi bssid is always possible */
|
||||
|
|
|
@ -37,6 +37,7 @@ int madwifi_get_enctype(const char *ifname, char *buf);
|
|||
int madwifi_get_assoclist(const char *ifname, char *buf, int *len);
|
||||
int madwifi_get_txpwrlist(const char *ifname, char *buf, int *len);
|
||||
int madwifi_get_scanlist(const char *ifname, char *buf, int *len);
|
||||
int madwifi_get_freqlist(const char *ifname, char *buf, int *len);
|
||||
int madwifi_get_mbssid_support(const char *ifname, int *buf);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -394,6 +394,37 @@ int wext_get_txpwrlist(const char *ifname, char *buf, int *len)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int wext_get_freqlist(const char *ifname, char *buf, int *len)
|
||||
{
|
||||
struct iwreq wrq;
|
||||
struct iw_range range;
|
||||
struct iwinfo_freqlist_entry entry;
|
||||
int i, bl;
|
||||
|
||||
wrq.u.data.pointer = (caddr_t) ⦥
|
||||
wrq.u.data.length = sizeof(struct iw_range);
|
||||
wrq.u.data.flags = 0;
|
||||
|
||||
if(wext_ioctl(ifname, SIOCGIWRANGE, &wrq) >= 0)
|
||||
{
|
||||
bl = 0;
|
||||
|
||||
for(i = 0; i < range.num_frequency; i++)
|
||||
{
|
||||
entry.mhz = wext_freq2mhz(&range.freq[i]);
|
||||
entry.channel = range.freq[i].i;
|
||||
|
||||
memcpy(&buf[bl], &entry, sizeof(struct iwinfo_freqlist_entry));
|
||||
bl += sizeof(struct iwinfo_freqlist_entry);
|
||||
}
|
||||
|
||||
*len = bl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wext_get_mbssid_support(const char *ifname, int *buf)
|
||||
{
|
||||
/* No multi bssid support atm */
|
||||
|
|
|
@ -38,6 +38,7 @@ int wext_get_enctype(const char *ifname, char *buf);
|
|||
int wext_get_assoclist(const char *ifname, char *buf, int *len);
|
||||
int wext_get_txpwrlist(const char *ifname, char *buf, int *len);
|
||||
int wext_get_scanlist(const char *ifname, char *buf, int *len);
|
||||
int wext_get_freqlist(const char *ifname, char *buf, int *len);
|
||||
int wext_get_mbssid_support(const char *ifname, int *buf);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -389,6 +389,11 @@ int wl_get_scanlist(const char *ifname, char *buf, int *len)
|
|||
return wext_get_scanlist(ifname, buf, len);
|
||||
}
|
||||
|
||||
int wl_get_freqlist(const char *ifname, char *buf, int *len)
|
||||
{
|
||||
return wext_get_freqlist(ifname, buf, len);
|
||||
}
|
||||
|
||||
int wl_get_mbssid_support(const char *ifname, int *buf)
|
||||
{
|
||||
wlc_rev_info_t revinfo;
|
||||
|
|
|
@ -37,6 +37,7 @@ int wl_get_enctype(const char *ifname, char *buf);
|
|||
int wl_get_assoclist(const char *ifname, char *buf, int *len);
|
||||
int wl_get_txpwrlist(const char *ifname, char *buf, int *len);
|
||||
int wl_get_scanlist(const char *ifname, char *buf, int *len);
|
||||
int wl_get_freqlist(const char *ifname, char *buf, int *len);
|
||||
int wl_get_mbssid_support(const char *ifname, int *buf);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue