libs/iwinfo: implement *_get_frequency() - operating freq in mhz

This commit is contained in:
Jo-Philipp Wich 2009-08-09 14:24:43 +00:00
parent 398c125336
commit 2a9a87e891
7 changed files with 84 additions and 15 deletions

View file

@ -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),

View file

@ -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;

View 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_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);

View file

@ -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;

View file

@ -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);

View file

@ -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;

View 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_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);