summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-08-09 14:24:43 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-08-09 14:24:43 +0000
commit2a9a87e89172c147c1dc222f67221f825755e9aa (patch)
treedd26bfe841ea6ff2d0a78d8e8e080fae4f277cc5
parent398c125336f035a9a5a23b476f597b2e22fb672a (diff)
libs/iwinfo: implement *_get_frequency() - operating freq in mhz
-rw-r--r--libs/iwinfo/src/iwinfo_lualib.c6
-rw-r--r--libs/iwinfo/src/iwinfo_madwifi.c13
-rw-r--r--libs/iwinfo/src/iwinfo_madwifi.h1
-rw-r--r--libs/iwinfo/src/iwinfo_wext.c56
-rw-r--r--libs/iwinfo/src/iwinfo_wext.h17
-rw-r--r--libs/iwinfo/src/iwinfo_wl.c5
-rw-r--r--libs/iwinfo/src/iwinfo_wl.h1
7 files changed, 84 insertions, 15 deletions
diff --git a/libs/iwinfo/src/iwinfo_lualib.c b/libs/iwinfo/src/iwinfo_lualib.c
index 4663d3414..0b007c6af 100644
--- a/libs/iwinfo/src/iwinfo_lualib.c
+++ b/libs/iwinfo/src/iwinfo_lualib.c
@@ -77,6 +77,7 @@ int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
/* Broadcom */
LUA_WRAP_INT(wl,channel)
+LUA_WRAP_INT(wl,frequency)
LUA_WRAP_INT(wl,bitrate)
LUA_WRAP_INT(wl,signal)
LUA_WRAP_INT(wl,noise)
@@ -90,6 +91,7 @@ LUA_WRAP_ASSOCLIST(wl)
/* Madwifi */
LUA_WRAP_INT(madwifi,channel)
+LUA_WRAP_INT(madwifi,frequency)
LUA_WRAP_INT(madwifi,bitrate)
LUA_WRAP_INT(madwifi,signal)
LUA_WRAP_INT(madwifi,noise)
@@ -103,6 +105,7 @@ LUA_WRAP_ASSOCLIST(madwifi)
/* Wext */
LUA_WRAP_INT(wext,channel)
+LUA_WRAP_INT(wext,frequency)
LUA_WRAP_INT(wext,bitrate)
LUA_WRAP_INT(wext,signal)
LUA_WRAP_INT(wext,noise)
@@ -117,6 +120,7 @@ LUA_WRAP_ASSOCLIST(wext)
/* Broadcom table */
static const luaL_reg R_wl[] = {
LUA_REG(wl,channel),
+ LUA_REG(wl,frequency),
LUA_REG(wl,bitrate),
LUA_REG(wl,signal),
LUA_REG(wl,noise),
@@ -133,6 +137,7 @@ static const luaL_reg R_wl[] = {
/* Madwifi table */
static const luaL_reg R_madwifi[] = {
LUA_REG(madwifi,channel),
+ LUA_REG(madwifi,frequency),
LUA_REG(madwifi,bitrate),
LUA_REG(madwifi,signal),
LUA_REG(madwifi,noise),
@@ -149,6 +154,7 @@ static const luaL_reg R_madwifi[] = {
/* Wext table */
static const luaL_reg R_wext[] = {
LUA_REG(wext,channel),
+ LUA_REG(wext,frequency),
LUA_REG(wext,bitrate),
LUA_REG(wext,signal),
LUA_REG(wext,noise),
diff --git a/libs/iwinfo/src/iwinfo_madwifi.c b/libs/iwinfo/src/iwinfo_madwifi.c
index 85b5857c7..7869b34c7 100644
--- a/libs/iwinfo/src/iwinfo_madwifi.c
+++ b/libs/iwinfo/src/iwinfo_madwifi.c
@@ -127,6 +127,19 @@ int madwifi_get_channel(const char *ifname, int *buf)
return -1;
}
+int madwifi_get_frequency(const char *ifname, int *buf)
+{
+ struct iwreq wrq;
+
+ if( madwifi_ioctl(&wrq, ifname, SIOCGIWFREQ, NULL, 0) >= 0 )
+ {
+ *buf = (uint16_t)(wrq.u.freq.m / 100000);
+ return 0;
+ }
+
+ return -1;
+}
+
int madwifi_get_bitrate(const char *ifname, int *buf)
{
unsigned int mode, len, rate, rate_count;
diff --git a/libs/iwinfo/src/iwinfo_madwifi.h b/libs/iwinfo/src/iwinfo_madwifi.h
index 4b0472ef1..57a273c0d 100644
--- a/libs/iwinfo/src/iwinfo_madwifi.h
+++ b/libs/iwinfo/src/iwinfo_madwifi.h
@@ -27,6 +27,7 @@ int madwifi_get_mode(const char *ifname, char *buf);
int madwifi_get_ssid(const char *ifname, char *buf);
int madwifi_get_bssid(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_bitrate(const char *ifname, int *buf);
int madwifi_get_signal(const char *ifname, int *buf);
int madwifi_get_noise(const char *ifname, int *buf);
diff --git a/libs/iwinfo/src/iwinfo_wext.c b/libs/iwinfo/src/iwinfo_wext.c
index 7f44fd0d2..76062ba0a 100644
--- a/libs/iwinfo/src/iwinfo_wext.c
+++ b/libs/iwinfo/src/iwinfo_wext.c
@@ -32,6 +32,24 @@ static double wext_freq2float(const struct iw_freq *in)
return res;
}
+static int wext_freq2mhz(const struct iw_freq *in)
+{
+ int i, mhz;
+
+ if( in->e == 6 )
+ {
+ return in->m;
+ }
+ else
+ {
+ mhz = in->m;
+ for(i = 0; i < in->e; i++)
+ mhz *= 10;
+
+ return (int)(mhz / 100000);
+ }
+}
+
static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq)
{
/* prepare socket */
@@ -157,6 +175,44 @@ int wext_get_channel(const char *ifname, int *buf)
return -1;
}
+int wext_get_frequency(const char *ifname, int *buf)
+{
+ struct iwreq wrq;
+ struct iw_range range;
+ int i, channel;
+
+ if(wext_ioctl(ifname, SIOCGIWFREQ, &wrq) >= 0)
+ {
+ /* We got a channel number instead ... */
+ if( wrq.u.freq.m < 1000 )
+ {
+ channel = wrq.u.freq.m;
+ wrq.u.data.pointer = (caddr_t) &range;
+ wrq.u.data.length = sizeof(struct iw_range);
+ wrq.u.data.flags = 0;
+
+ if(wext_ioctl(ifname, SIOCGIWRANGE, &wrq) >= 0)
+ {
+ for(i = 0; i < range.num_frequency; i++)
+ {
+ if( range.freq[i].i == channel )
+ {
+ *buf = wext_freq2mhz(&range.freq[i]);
+ return 0;
+ }
+ }
+ }
+ }
+ else
+ {
+ *buf = wext_freq2mhz(&wrq.u.freq);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
int wext_get_signal(const char *ifname, int *buf)
{
struct iwreq wrq;
diff --git a/libs/iwinfo/src/iwinfo_wext.h b/libs/iwinfo/src/iwinfo_wext.h
index d4914ff2e..bd0a66f1e 100644
--- a/libs/iwinfo/src/iwinfo_wext.h
+++ b/libs/iwinfo/src/iwinfo_wext.h
@@ -19,21 +19,7 @@
#ifndef __IWINFO_WEXT_H_
#define __IWINFO_WEXT_H_
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <glob.h>
-#include <ctype.h>
-#include <stdint.h>
-
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <errno.h>
-
+#include "iwinfo.h"
#include "include/wext.h"
int wext_probe(const char *ifname);
@@ -41,6 +27,7 @@ int wext_get_mode(const char *ifname, char *buf);
int wext_get_ssid(const char *ifname, char *buf);
int wext_get_bssid(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_bitrate(const char *ifname, int *buf);
int wext_get_signal(const char *ifname, int *buf);
int wext_get_noise(const char *ifname, int *buf);
diff --git a/libs/iwinfo/src/iwinfo_wl.c b/libs/iwinfo/src/iwinfo_wl.c
index 336247501..a29cf84ee 100644
--- a/libs/iwinfo/src/iwinfo_wl.c
+++ b/libs/iwinfo/src/iwinfo_wl.c
@@ -128,6 +128,11 @@ int wl_get_channel(const char *ifname, int *buf)
return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf));
}
+int wl_get_frequency(const char *ifname, int *buf)
+{
+ return wext_get_frequency(ifname, buf);
+}
+
int wl_get_bitrate(const char *ifname, int *buf)
{
int ret = -1;
diff --git a/libs/iwinfo/src/iwinfo_wl.h b/libs/iwinfo/src/iwinfo_wl.h
index 77d8d8f0f..5df893994 100644
--- a/libs/iwinfo/src/iwinfo_wl.h
+++ b/libs/iwinfo/src/iwinfo_wl.h
@@ -27,6 +27,7 @@ int wl_get_mode(const char *ifname, char *buf);
int wl_get_ssid(const char *ifname, char *buf);
int wl_get_bssid(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_bitrate(const char *ifname, int *buf);
int wl_get_signal(const char *ifname, int *buf);
int wl_get_noise(const char *ifname, int *buf);