iwinfo: expose txpower and frequency offset information

SVN-Revision: 29425
This commit is contained in:
Jo-Philipp Wich 2011-12-04 20:37:01 +00:00
parent 33750dc3e9
commit 3a9d303059
13 changed files with 281 additions and 108 deletions

View File

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=libiwinfo
PKG_RELEASE:=19
PKG_RELEASE:=20
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

View File

@ -120,7 +120,9 @@ extern const struct iwinfo_hardware_entry IWINFO_HARDWARE_ENTRIES[];
struct iwinfo_ops {
int (*channel)(const char *, int *);
int (*frequency)(const char *, int *);
int (*frequency_offset)(const char *, int *);
int (*txpower)(const char *, int *);
int (*txpower_offset)(const char *, int *);
int (*bitrate)(const char *, int *);
int (*signal)(const char *, int *);
int (*noise)(const char *, int *);

View File

@ -32,7 +32,9 @@ int madwifi_get_bssid(const char *ifname, char *buf);
int madwifi_get_country(const char *ifname, char *buf);
int madwifi_get_channel(const char *ifname, int *buf);
int madwifi_get_frequency(const char *ifname, int *buf);
int madwifi_get_frequency_offset(const char *ifname, int *buf);
int madwifi_get_txpower(const char *ifname, int *buf);
int madwifi_get_txpower_offset(const char *ifname, int *buf);
int madwifi_get_bitrate(const char *ifname, int *buf);
int madwifi_get_signal(const char *ifname, int *buf);
int madwifi_get_noise(const char *ifname, int *buf);
@ -51,29 +53,31 @@ int madwifi_get_hardware_name(const char *ifname, char *buf);
void madwifi_close(void);
static const struct iwinfo_ops madwifi_ops = {
.channel = madwifi_get_channel,
.frequency = madwifi_get_frequency,
.txpower = madwifi_get_txpower,
.bitrate = madwifi_get_bitrate,
.signal = madwifi_get_signal,
.noise = madwifi_get_noise,
.quality = madwifi_get_quality,
.quality_max = madwifi_get_quality_max,
.mbssid_support = madwifi_get_mbssid_support,
.hwmodelist = madwifi_get_hwmodelist,
.mode = madwifi_get_mode,
.ssid = madwifi_get_ssid,
.bssid = madwifi_get_bssid,
.country = madwifi_get_country,
.hardware_id = madwifi_get_hardware_id,
.hardware_name = madwifi_get_hardware_name,
.encryption = madwifi_get_encryption,
.assoclist = madwifi_get_assoclist,
.txpwrlist = madwifi_get_txpwrlist,
.scanlist = madwifi_get_scanlist,
.freqlist = madwifi_get_freqlist,
.countrylist = madwifi_get_countrylist,
.close = madwifi_close
.channel = madwifi_get_channel,
.frequency = madwifi_get_frequency,
.frequency_offset = madwifi_get_frequency_offset,
.txpower = madwifi_get_txpower,
.txpower_offset = madwifi_get_txpower_offset,
.bitrate = madwifi_get_bitrate,
.signal = madwifi_get_signal,
.noise = madwifi_get_noise,
.quality = madwifi_get_quality,
.quality_max = madwifi_get_quality_max,
.mbssid_support = madwifi_get_mbssid_support,
.hwmodelist = madwifi_get_hwmodelist,
.mode = madwifi_get_mode,
.ssid = madwifi_get_ssid,
.bssid = madwifi_get_bssid,
.country = madwifi_get_country,
.hardware_id = madwifi_get_hardware_id,
.hardware_name = madwifi_get_hardware_name,
.encryption = madwifi_get_encryption,
.assoclist = madwifi_get_assoclist,
.txpwrlist = madwifi_get_txpwrlist,
.scanlist = madwifi_get_scanlist,
.freqlist = madwifi_get_freqlist,
.countrylist = madwifi_get_countrylist,
.close = madwifi_close
};
#endif

View File

@ -63,7 +63,9 @@ int nl80211_get_bssid(const char *ifname, char *buf);
int nl80211_get_country(const char *ifname, char *buf);
int nl80211_get_channel(const char *ifname, int *buf);
int nl80211_get_frequency(const char *ifname, int *buf);
int nl80211_get_frequency_offset(const char *ifname, int *buf);
int nl80211_get_txpower(const char *ifname, int *buf);
int nl80211_get_txpower_offset(const char *ifname, int *buf);
int nl80211_get_bitrate(const char *ifname, int *buf);
int nl80211_get_signal(const char *ifname, int *buf);
int nl80211_get_noise(const char *ifname, int *buf);
@ -82,29 +84,31 @@ int nl80211_get_hardware_name(const char *ifname, char *buf);
void nl80211_close(void);
static const struct iwinfo_ops nl80211_ops = {
.channel = nl80211_get_channel,
.frequency = nl80211_get_frequency,
.txpower = nl80211_get_txpower,
.bitrate = nl80211_get_bitrate,
.signal = nl80211_get_signal,
.noise = nl80211_get_noise,
.quality = nl80211_get_quality,
.quality_max = nl80211_get_quality_max,
.mbssid_support = nl80211_get_mbssid_support,
.hwmodelist = nl80211_get_hwmodelist,
.mode = nl80211_get_mode,
.ssid = nl80211_get_ssid,
.bssid = nl80211_get_bssid,
.country = nl80211_get_country,
.hardware_id = nl80211_get_hardware_id,
.hardware_name = nl80211_get_hardware_name,
.encryption = nl80211_get_encryption,
.assoclist = nl80211_get_assoclist,
.txpwrlist = nl80211_get_txpwrlist,
.scanlist = nl80211_get_scanlist,
.freqlist = nl80211_get_freqlist,
.countrylist = nl80211_get_countrylist,
.close = nl80211_close
.channel = nl80211_get_channel,
.frequency = nl80211_get_frequency,
.frequency_offset = nl80211_get_frequency_offset,
.txpower = nl80211_get_txpower,
.txpower_offset = nl80211_get_txpower_offset,
.bitrate = nl80211_get_bitrate,
.signal = nl80211_get_signal,
.noise = nl80211_get_noise,
.quality = nl80211_get_quality,
.quality_max = nl80211_get_quality_max,
.mbssid_support = nl80211_get_mbssid_support,
.hwmodelist = nl80211_get_hwmodelist,
.mode = nl80211_get_mode,
.ssid = nl80211_get_ssid,
.bssid = nl80211_get_bssid,
.country = nl80211_get_country,
.hardware_id = nl80211_get_hardware_id,
.hardware_name = nl80211_get_hardware_name,
.encryption = nl80211_get_encryption,
.assoclist = nl80211_get_assoclist,
.txpwrlist = nl80211_get_txpwrlist,
.scanlist = nl80211_get_scanlist,
.freqlist = nl80211_get_freqlist,
.countrylist = nl80211_get_countrylist,
.close = nl80211_close
};
#endif

View File

@ -33,7 +33,9 @@ int wext_get_bssid(const char *ifname, char *buf);
int wext_get_country(const char *ifname, char *buf);
int wext_get_channel(const char *ifname, int *buf);
int wext_get_frequency(const char *ifname, int *buf);
int wext_get_frequency_offset(const char *ifname, int *buf);
int wext_get_txpower(const char *ifname, int *buf);
int wext_get_txpower_offset(const char *ifname, int *buf);
int wext_get_bitrate(const char *ifname, int *buf);
int wext_get_signal(const char *ifname, int *buf);
int wext_get_noise(const char *ifname, int *buf);
@ -52,29 +54,31 @@ int wext_get_hardware_name(const char *ifname, char *buf);
void wext_close(void);
static const struct iwinfo_ops wext_ops = {
.channel = wext_get_channel,
.frequency = wext_get_frequency,
.txpower = wext_get_txpower,
.bitrate = wext_get_bitrate,
.signal = wext_get_signal,
.noise = wext_get_noise,
.quality = wext_get_quality,
.quality_max = wext_get_quality_max,
.mbssid_support = wext_get_mbssid_support,
.hwmodelist = wext_get_hwmodelist,
.mode = wext_get_mode,
.ssid = wext_get_ssid,
.bssid = wext_get_bssid,
.country = wext_get_country,
.hardware_id = wext_get_hardware_id,
.hardware_name = wext_get_hardware_name,
.encryption = wext_get_encryption,
.assoclist = wext_get_assoclist,
.txpwrlist = wext_get_txpwrlist,
.scanlist = wext_get_scanlist,
.freqlist = wext_get_freqlist,
.countrylist = wext_get_countrylist,
.close = wext_close
.channel = wext_get_channel,
.frequency = wext_get_frequency,
.frequency_offset = wext_get_frequency_offset,
.txpower = wext_get_txpower,
.txpower_offset = wext_get_txpower_offset,
.bitrate = wext_get_bitrate,
.signal = wext_get_signal,
.noise = wext_get_noise,
.quality = wext_get_quality,
.quality_max = wext_get_quality_max,
.mbssid_support = wext_get_mbssid_support,
.hwmodelist = wext_get_hwmodelist,
.mode = wext_get_mode,
.ssid = wext_get_ssid,
.bssid = wext_get_bssid,
.country = wext_get_country,
.hardware_id = wext_get_hardware_id,
.hardware_name = wext_get_hardware_name,
.encryption = wext_get_encryption,
.assoclist = wext_get_assoclist,
.txpwrlist = wext_get_txpwrlist,
.scanlist = wext_get_scanlist,
.freqlist = wext_get_freqlist,
.countrylist = wext_get_countrylist,
.close = wext_close
};
#endif

View File

@ -32,7 +32,9 @@ int wl_get_bssid(const char *ifname, char *buf);
int wl_get_country(const char *ifname, char *buf);
int wl_get_channel(const char *ifname, int *buf);
int wl_get_frequency(const char *ifname, int *buf);
int wl_get_frequency_offset(const char *ifname, int *buf);
int wl_get_txpower(const char *ifname, int *buf);
int wl_get_txpower_offset(const char *ifname, int *buf);
int wl_get_bitrate(const char *ifname, int *buf);
int wl_get_signal(const char *ifname, int *buf);
int wl_get_noise(const char *ifname, int *buf);
@ -52,29 +54,31 @@ int wl_get_hardware_name(const char *ifname, char *buf);
void wl_close(void);
static const struct iwinfo_ops wl_ops = {
.channel = wl_get_channel,
.frequency = wl_get_frequency,
.txpower = wl_get_txpower,
.bitrate = wl_get_bitrate,
.signal = wl_get_signal,
.noise = wl_get_noise,
.quality = wl_get_quality,
.quality_max = wl_get_quality_max,
.mbssid_support = wl_get_mbssid_support,
.hwmodelist = wl_get_hwmodelist,
.mode = wl_get_mode,
.ssid = wl_get_ssid,
.bssid = wl_get_bssid,
.country = wl_get_country,
.hardware_id = wl_get_hardware_id,
.hardware_name = wl_get_hardware_name,
.encryption = wl_get_encryption,
.assoclist = wl_get_assoclist,
.txpwrlist = wl_get_txpwrlist,
.scanlist = wl_get_scanlist,
.freqlist = wl_get_freqlist,
.countrylist = wl_get_countrylist,
.close = wl_close
.channel = wl_get_channel,
.frequency = wl_get_frequency,
.frequency_offset = wl_get_frequency_offset,
.txpower = wl_get_txpower,
.txpower_offset = wl_get_txpower_offset,
.bitrate = wl_get_bitrate,
.signal = wl_get_signal,
.noise = wl_get_noise,
.quality = wl_get_quality,
.quality_max = wl_get_quality_max,
.mbssid_support = wl_get_mbssid_support,
.hwmodelist = wl_get_hwmodelist,
.mode = wl_get_mode,
.ssid = wl_get_ssid,
.bssid = wl_get_bssid,
.country = wl_get_country,
.hardware_id = wl_get_hardware_id,
.hardware_name = wl_get_hardware_name,
.encryption = wl_get_encryption,
.assoclist = wl_get_assoclist,
.txpwrlist = wl_get_txpwrlist,
.scanlist = wl_get_scanlist,
.freqlist = wl_get_freqlist,
.countrylist = wl_get_countrylist,
.close = wl_close
};
#endif

View File

@ -311,6 +311,36 @@ static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifnam
return buf;
}
static char * print_txpower_offset(const struct iwinfo_ops *iw, const char *ifname)
{
int off;
static char buf[12];
if (iw->txpower_offset(ifname, &off))
snprintf(buf, sizeof(buf), "unknown");
else if (off != 0)
snprintf(buf, sizeof(buf), "%d dB", off);
else
snprintf(buf, sizeof(buf), "none");
return buf;
}
static char * print_frequency_offset(const struct iwinfo_ops *iw, const char *ifname)
{
int off;
static char buf[12];
if (iw->frequency_offset(ifname, &off))
snprintf(buf, sizeof(buf), "unknown");
else if (off != 0)
snprintf(buf, sizeof(buf), "%.3f GHz", ((float)off / 1000.0));
else
snprintf(buf, sizeof(buf), "none");
return buf;
}
static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
{
char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
@ -473,6 +503,10 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
printf(" Hardware: %s [%s]\n",
print_hardware_id(iw, ifname),
print_hardware_name(iw, ifname));
printf(" TX power offset: %s\n",
print_txpower_offset(iw, ifname));
printf(" Frequency offset: %s\n",
print_frequency_offset(iw, ifname));
printf(" Supports VAPs: %s\n",
print_mbssid_supp(iw, ifname));
}

View File

@ -347,7 +347,7 @@ const struct iwinfo_hardware_entry IWINFO_HARDWARE_ENTRIES[] = {
{ VENDOR_UBNT, "SR71A", 0x168c, 0x0027, 0x168c, 0x2082, 10, 0 },
{ VENDOR_UBNT, "SR71", 0x168c, 0x0027, 0x0777, 0x4082, 10, 0 },
#endif
#ifdef NL80211
#ifdef USE_NL80211
{ VENDOR_UBNT, "NanoStation M2", 0x168c, 0x002a, 0x0777, 0xe012, 10, 0 }, /* ToDo: confirm offset */
{ VENDOR_UBNT, "NanoStation M5", 0x168c, 0x002a, 0x0777, 0xe005, 5, 0 }, /* ToDo: confirm offset */
{ VENDOR_UBNT, "Bullet M2", 0x168c, 0x002a, 0x0777, 0xe202, 12, 0 },

View File

@ -558,7 +558,9 @@ static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *,
/* Broadcom */
LUA_WRAP_INT(wl,channel)
LUA_WRAP_INT(wl,frequency)
LUA_WRAP_INT(wl,frequency_offset)
LUA_WRAP_INT(wl,txpower)
LUA_WRAP_INT(wl,txpower_offset)
LUA_WRAP_INT(wl,bitrate)
LUA_WRAP_INT(wl,signal)
LUA_WRAP_INT(wl,noise)
@ -584,7 +586,9 @@ LUA_WRAP_STRUCT(wl,hardware_id)
/* Madwifi */
LUA_WRAP_INT(madwifi,channel)
LUA_WRAP_INT(madwifi,frequency)
LUA_WRAP_INT(madwifi,frequency_offset)
LUA_WRAP_INT(madwifi,txpower)
LUA_WRAP_INT(madwifi,txpower_offset)
LUA_WRAP_INT(madwifi,bitrate)
LUA_WRAP_INT(madwifi,signal)
LUA_WRAP_INT(madwifi,noise)
@ -610,7 +614,9 @@ LUA_WRAP_STRUCT(madwifi,hardware_id)
/* NL80211 */
LUA_WRAP_INT(nl80211,channel)
LUA_WRAP_INT(nl80211,frequency)
LUA_WRAP_INT(nl80211,frequency_offset)
LUA_WRAP_INT(nl80211,txpower)
LUA_WRAP_INT(nl80211,txpower_offset)
LUA_WRAP_INT(nl80211,bitrate)
LUA_WRAP_INT(nl80211,signal)
LUA_WRAP_INT(nl80211,noise)
@ -635,7 +641,9 @@ LUA_WRAP_STRUCT(nl80211,hardware_id)
/* Wext */
LUA_WRAP_INT(wext,channel)
LUA_WRAP_INT(wext,frequency)
LUA_WRAP_INT(wext,frequency_offset)
LUA_WRAP_INT(wext,txpower)
LUA_WRAP_INT(wext,txpower_offset)
LUA_WRAP_INT(wext,bitrate)
LUA_WRAP_INT(wext,signal)
LUA_WRAP_INT(wext,noise)
@ -661,7 +669,9 @@ LUA_WRAP_STRUCT(wext,hardware_id)
static const luaL_reg R_wl[] = {
LUA_REG(wl,channel),
LUA_REG(wl,frequency),
LUA_REG(wl,frequency_offset),
LUA_REG(wl,txpower),
LUA_REG(wl,txpower_offset),
LUA_REG(wl,bitrate),
LUA_REG(wl,signal),
LUA_REG(wl,noise),
@ -690,7 +700,9 @@ static const luaL_reg R_wl[] = {
static const luaL_reg R_madwifi[] = {
LUA_REG(madwifi,channel),
LUA_REG(madwifi,frequency),
LUA_REG(madwifi,frequency_offset),
LUA_REG(madwifi,txpower),
LUA_REG(madwifi,txpower_offset),
LUA_REG(madwifi,bitrate),
LUA_REG(madwifi,signal),
LUA_REG(madwifi,noise),
@ -719,7 +731,9 @@ static const luaL_reg R_madwifi[] = {
static const luaL_reg R_nl80211[] = {
LUA_REG(nl80211,channel),
LUA_REG(nl80211,frequency),
LUA_REG(nl80211,frequency_offset),
LUA_REG(nl80211,txpower),
LUA_REG(nl80211,txpower_offset),
LUA_REG(nl80211,bitrate),
LUA_REG(nl80211,signal),
LUA_REG(nl80211,noise),
@ -747,7 +761,9 @@ static const luaL_reg R_nl80211[] = {
static const luaL_reg R_wext[] = {
LUA_REG(wext,channel),
LUA_REG(wext,frequency),
LUA_REG(wext,frequency_offset),
LUA_REG(wext,txpower),
LUA_REG(wext,txpower_offset),
LUA_REG(wext,bitrate),
LUA_REG(wext,signal),
LUA_REG(wext,noise),

View File

@ -1060,20 +1060,59 @@ int madwifi_get_hardware_id(const char *ifname, char *buf)
return 0;
}
int madwifi_get_hardware_name(const char *ifname, char *buf)
static const struct iwinfo_hardware_entry *
madwifi_get_hardware_entry(const char *ifname)
{
struct iwinfo_hardware_id id;
struct iwinfo_hardware_entry *hw;
if (madwifi_get_hardware_id(ifname, (char *)&id))
return -1;
return NULL;
hw = iwinfo_hardware(&id);
return iwinfo_hardware(&id);
}
if (hw)
sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
int madwifi_get_hardware_name(const char *ifname, char *buf)
{
char vendor[64];
char device[64];
const struct iwinfo_hardware_entry *hw;
if (!(hw = madwifi_get_hardware_entry(ifname)))
{
madwifi_proc_file(ifname, "dev_vendor", vendor, sizeof(vendor));
madwifi_proc_file(ifname, "dev_name", device, sizeof(device));
if (vendor[0] && device[0])
sprintf(buf, "%s %s", vendor, device);
else
sprintf(buf, "Generic Atheros");
}
else
sprintf(buf, "Generic Atheros");
{
sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
}
return 0;
}
int madwifi_get_txpower_offset(const char *ifname, int *buf)
{
const struct iwinfo_hardware_entry *hw;
if (!(hw = madwifi_get_hardware_entry(ifname)))
return -1;
*buf = hw->txpower_offset;
return 0;
}
int madwifi_get_frequency_offset(const char *ifname, int *buf)
{
const struct iwinfo_hardware_entry *hw;
if (!(hw = madwifi_get_hardware_entry(ifname)))
return -1;
*buf = hw->frequency_offset;
return 0;
}

View File

@ -1634,20 +1634,47 @@ int nl80211_get_hardware_id(const char *ifname, char *buf)
return wext_get_hardware_id(ifname, buf);
}
int nl80211_get_hardware_name(const char *ifname, char *buf)
static const struct iwinfo_hardware_entry *
nl80211_get_hardware_entry(const char *ifname)
{
struct iwinfo_hardware_id id;
struct iwinfo_hardware_entry *hw;
if (nl80211_get_hardware_id(ifname, (char *)&id))
return -1;
return NULL;
hw = iwinfo_hardware(&id);
return iwinfo_hardware(&id);
}
if (hw)
sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
else
int nl80211_get_hardware_name(const char *ifname, char *buf)
{
const struct iwinfo_hardware_entry *hw;
if (!(hw = nl80211_get_hardware_entry(ifname)))
sprintf(buf, "Generic MAC80211");
else
sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
return 0;
}
int nl80211_get_txpower_offset(const char *ifname, int *buf)
{
const struct iwinfo_hardware_entry *hw;
if (!(hw = nl80211_get_hardware_entry(ifname)))
return -1;
*buf = hw->txpower_offset;
return 0;
}
int nl80211_get_frequency_offset(const char *ifname, int *buf)
{
const struct iwinfo_hardware_entry *hw;
if (!(hw = nl80211_get_hardware_entry(ifname)))
return -1;
*buf = hw->frequency_offset;
return 0;
}

View File

@ -515,3 +515,17 @@ int wext_get_hardware_name(const char *ifname, char *buf)
sprintf(buf, "Generic WEXT");
return 0;
}
int wext_get_txpower_offset(const char *ifname, int *buf)
{
/* Stub */
*buf = 0;
return -1;
}
int wext_get_frequency_offset(const char *ifname, int *buf)
{
/* Stub */
*buf = 0;
return -1;
}

View File

@ -585,3 +585,28 @@ int wl_get_hardware_name(const char *ifname, char *buf)
return 0;
}
int wl_get_txpower_offset(const char *ifname, int *buf)
{
FILE *p;
char off[8];
*buf = 0;
if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
{
if (fread(off, 1, sizeof(off), p))
*buf = strtoul(off, NULL, 16);
pclose(p);
}
return 0;
}
int wl_get_frequency_offset(const char *ifname, int *buf)
{
/* Stub */
*buf = 0;
return -1;
}