From 1b77a6f4c49b29b83e3063d9deca1a38e97ad897 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 15 Nov 2009 15:21:03 +0000 Subject: libs/iwinfo: add *_get_freqlist() --- libs/iwinfo/src/iwinfo.h | 5 +++++ libs/iwinfo/src/iwinfo_lualib.c | 39 +++++++++++++++++++++++++++++++++++++++ libs/iwinfo/src/iwinfo_madwifi.c | 26 ++++++++++++++++++++++++++ libs/iwinfo/src/iwinfo_madwifi.h | 1 + libs/iwinfo/src/iwinfo_wext.c | 31 +++++++++++++++++++++++++++++++ libs/iwinfo/src/iwinfo_wext.h | 1 + libs/iwinfo/src/iwinfo_wl.c | 5 +++++ libs/iwinfo/src/iwinfo_wl.h | 1 + 8 files changed, 109 insertions(+) (limited to 'libs') diff --git a/libs/iwinfo/src/iwinfo.h b/libs/iwinfo/src/iwinfo.h index eebe6b419..f15e38327 100644 --- a/libs/iwinfo/src/iwinfo.h +++ b/libs/iwinfo/src/iwinfo.h @@ -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; diff --git a/libs/iwinfo/src/iwinfo_lualib.c b/libs/iwinfo/src/iwinfo_lualib.c index 8eb4ad5dc..61ad5d325 100644 --- a/libs/iwinfo/src/iwinfo_lualib.c +++ b/libs/iwinfo/src/iwinfo_lualib.c @@ -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 } }; diff --git a/libs/iwinfo/src/iwinfo_madwifi.c b/libs/iwinfo/src/iwinfo_madwifi.c index 1fe777f1d..99c02dcd0 100644 --- a/libs/iwinfo/src/iwinfo_madwifi.c +++ b/libs/iwinfo/src/iwinfo_madwifi.c @@ -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 */ diff --git a/libs/iwinfo/src/iwinfo_madwifi.h b/libs/iwinfo/src/iwinfo_madwifi.h index 9c5b7fa58..18511c80c 100644 --- a/libs/iwinfo/src/iwinfo_madwifi.h +++ b/libs/iwinfo/src/iwinfo_madwifi.h @@ -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 diff --git a/libs/iwinfo/src/iwinfo_wext.c b/libs/iwinfo/src/iwinfo_wext.c index 387cb13b4..eebaea6af 100644 --- a/libs/iwinfo/src/iwinfo_wext.c +++ b/libs/iwinfo/src/iwinfo_wext.c @@ -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 */ diff --git a/libs/iwinfo/src/iwinfo_wext.h b/libs/iwinfo/src/iwinfo_wext.h index dd1922fc8..7861fdc9f 100644 --- a/libs/iwinfo/src/iwinfo_wext.h +++ b/libs/iwinfo/src/iwinfo_wext.h @@ -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 diff --git a/libs/iwinfo/src/iwinfo_wl.c b/libs/iwinfo/src/iwinfo_wl.c index 8519dbc56..f8ee4f3e3 100644 --- a/libs/iwinfo/src/iwinfo_wl.c +++ b/libs/iwinfo/src/iwinfo_wl.c @@ -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; diff --git a/libs/iwinfo/src/iwinfo_wl.h b/libs/iwinfo/src/iwinfo_wl.h index 31832d985..2892715cd 100644 --- a/libs/iwinfo/src/iwinfo_wl.h +++ b/libs/iwinfo/src/iwinfo_wl.h @@ -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 -- cgit v1.2.3