libs/iwinfo: implement *_get_frequency() - operating freq in mhz
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 9 Aug 2009 14:24:43 +0000 (14:24 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 9 Aug 2009 14:24:43 +0000 (14:24 +0000)
libs/iwinfo/src/iwinfo_lualib.c
libs/iwinfo/src/iwinfo_madwifi.c
libs/iwinfo/src/iwinfo_madwifi.h
libs/iwinfo/src/iwinfo_wext.c
libs/iwinfo/src/iwinfo_wext.h
libs/iwinfo/src/iwinfo_wl.c
libs/iwinfo/src/iwinfo_wl.h

index 4663d34..0b007c6 100644 (file)
@@ -77,6 +77,7 @@ int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
 
 /* Broadcom */
 LUA_WRAP_INT(wl,channel)
 
 /* 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)
 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)
 
 /* 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)
 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)
 
 /* 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)
 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),
 /* 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),
        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),
 /* 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),
        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),
 /* 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),
        LUA_REG(wext,bitrate),
        LUA_REG(wext,signal),
        LUA_REG(wext,noise),
index 85b5857..7869b34 100644 (file)
@@ -127,6 +127,19 @@ int madwifi_get_channel(const char *ifname, int *buf)
        return -1;
 }
 
        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;
 int madwifi_get_bitrate(const char *ifname, int *buf)
 {
        unsigned int mode, len, rate, rate_count;
index 4b0472e..57a273c 100644 (file)
@@ -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_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);
 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);
index 7f44fd0..76062ba 100644 (file)
@@ -32,6 +32,24 @@ static double wext_freq2float(const struct iw_freq *in)
        return res;
 }
 
        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 */
 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;      
 }
 
        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;
 int wext_get_signal(const char *ifname, int *buf)
 {
        struct iwreq wrq;
index d4914ff..bd0a66f 100644 (file)
 #ifndef __IWINFO_WEXT_H_
 #define __IWINFO_WEXT_H_
 
 #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);
 #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_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);
 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);
index 3362475..a29cf84 100644 (file)
@@ -128,6 +128,11 @@ int wl_get_channel(const char *ifname, int *buf)
        return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(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;
 int wl_get_bitrate(const char *ifname, int *buf)
 {
        int ret = -1;
index 77d8d8f..5df8939 100644 (file)
@@ -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_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);
 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);