Changeset 5248

Show
Ignore:
Timestamp:
08/09/09 15:24:43 (4 years ago)
Author:
jow
Message:

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

Location:
luci/trunk/libs/iwinfo/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/iwinfo/src/iwinfo_lualib.c

    r5244 r5248  
    7878/* Broadcom */ 
    7979LUA_WRAP_INT(wl,channel) 
     80LUA_WRAP_INT(wl,frequency) 
    8081LUA_WRAP_INT(wl,bitrate) 
    8182LUA_WRAP_INT(wl,signal) 
     
    9192/* Madwifi */ 
    9293LUA_WRAP_INT(madwifi,channel) 
     94LUA_WRAP_INT(madwifi,frequency) 
    9395LUA_WRAP_INT(madwifi,bitrate) 
    9496LUA_WRAP_INT(madwifi,signal) 
     
    104106/* Wext */ 
    105107LUA_WRAP_INT(wext,channel) 
     108LUA_WRAP_INT(wext,frequency) 
    106109LUA_WRAP_INT(wext,bitrate) 
    107110LUA_WRAP_INT(wext,signal) 
     
    118121static const luaL_reg R_wl[] = { 
    119122    LUA_REG(wl,channel), 
     123    LUA_REG(wl,frequency), 
    120124    LUA_REG(wl,bitrate), 
    121125    LUA_REG(wl,signal), 
     
    134138static const luaL_reg R_madwifi[] = { 
    135139    LUA_REG(madwifi,channel), 
     140    LUA_REG(madwifi,frequency), 
    136141    LUA_REG(madwifi,bitrate), 
    137142    LUA_REG(madwifi,signal), 
     
    150155static const luaL_reg R_wext[] = { 
    151156    LUA_REG(wext,channel), 
     157    LUA_REG(wext,frequency), 
    152158    LUA_REG(wext,bitrate), 
    153159    LUA_REG(wext,signal), 
  • luci/trunk/libs/iwinfo/src/iwinfo_madwifi.c

    r5244 r5248  
    128128} 
    129129 
     130int madwifi_get_frequency(const char *ifname, int *buf) 
     131{ 
     132    struct iwreq wrq; 
     133 
     134    if( madwifi_ioctl(&wrq, ifname, SIOCGIWFREQ, NULL, 0) >= 0 ) 
     135    { 
     136        *buf = (uint16_t)(wrq.u.freq.m / 100000); 
     137        return 0; 
     138    } 
     139 
     140    return -1; 
     141} 
     142 
    130143int madwifi_get_bitrate(const char *ifname, int *buf) 
    131144{ 
  • luci/trunk/libs/iwinfo/src/iwinfo_madwifi.h

    r5244 r5248  
    2828int madwifi_get_bssid(const char *ifname, char *buf); 
    2929int madwifi_get_channel(const char *ifname, int *buf); 
     30int madwifi_get_frequency(const char *ifname, int *buf); 
    3031int madwifi_get_bitrate(const char *ifname, int *buf); 
    3132int madwifi_get_signal(const char *ifname, int *buf); 
  • luci/trunk/libs/iwinfo/src/iwinfo_wext.c

    r5244 r5248  
    3333} 
    3434 
     35static int wext_freq2mhz(const struct iw_freq *in) 
     36{ 
     37    int i, mhz; 
     38 
     39    if( in->e == 6 ) 
     40    { 
     41        return in->m; 
     42    } 
     43    else 
     44    { 
     45        mhz = in->m; 
     46        for(i = 0; i < in->e; i++) 
     47            mhz *= 10; 
     48 
     49        return (int)(mhz / 100000); 
     50    } 
     51} 
     52 
    3553static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq) 
    3654{ 
     
    158176} 
    159177 
     178int wext_get_frequency(const char *ifname, int *buf) 
     179{ 
     180    struct iwreq wrq; 
     181    struct iw_range range; 
     182    int i, channel; 
     183 
     184    if(wext_ioctl(ifname, SIOCGIWFREQ, &wrq) >= 0) 
     185    { 
     186        /* We got a channel number instead ... */ 
     187        if( wrq.u.freq.m < 1000 ) 
     188        { 
     189            channel = wrq.u.freq.m; 
     190            wrq.u.data.pointer = (caddr_t) &range; 
     191            wrq.u.data.length  = sizeof(struct iw_range); 
     192            wrq.u.data.flags   = 0; 
     193 
     194            if(wext_ioctl(ifname, SIOCGIWRANGE, &wrq) >= 0) 
     195            { 
     196                for(i = 0; i < range.num_frequency; i++) 
     197                { 
     198                    if( range.freq[i].i == channel ) 
     199                    { 
     200                        *buf = wext_freq2mhz(&range.freq[i]); 
     201                        return 0; 
     202                    } 
     203                } 
     204            } 
     205        } 
     206        else 
     207        { 
     208            *buf = wext_freq2mhz(&wrq.u.freq); 
     209            return 0; 
     210        } 
     211    } 
     212 
     213    return -1;   
     214} 
     215 
    160216int wext_get_signal(const char *ifname, int *buf) 
    161217{ 
  • luci/trunk/libs/iwinfo/src/iwinfo_wext.h

    r5244 r5248  
    2020#define __IWINFO_WEXT_H_ 
    2121 
    22 #include <sys/types.h> 
    23 #include <sys/stat.h> 
    24 #include <unistd.h> 
    25 #include <stdio.h> 
    26 #include <stdlib.h> 
    27 #include <string.h> 
    28 #include <fcntl.h> 
    29 #include <glob.h> 
    30 #include <ctype.h> 
    31 #include <stdint.h> 
    32  
    33 #include <sys/ioctl.h> 
    34 #include <net/if.h> 
    35 #include <errno.h> 
    36  
     22#include "iwinfo.h" 
    3723#include "include/wext.h" 
    3824 
     
    4228int wext_get_bssid(const char *ifname, char *buf); 
    4329int wext_get_channel(const char *ifname, int *buf); 
     30int wext_get_frequency(const char *ifname, int *buf); 
    4431int wext_get_bitrate(const char *ifname, int *buf); 
    4532int wext_get_signal(const char *ifname, int *buf); 
  • luci/trunk/libs/iwinfo/src/iwinfo_wl.c

    r5245 r5248  
    127127{ 
    128128    return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf)); 
     129} 
     130 
     131int wl_get_frequency(const char *ifname, int *buf) 
     132{ 
     133    return wext_get_frequency(ifname, buf); 
    129134} 
    130135 
  • luci/trunk/libs/iwinfo/src/iwinfo_wl.h

    r5244 r5248  
    2828int wl_get_bssid(const char *ifname, char *buf); 
    2929int wl_get_channel(const char *ifname, int *buf); 
     30int wl_get_frequency(const char *ifname, int *buf); 
    3031int wl_get_bitrate(const char *ifname, int *buf); 
    3132int wl_get_signal(const char *ifname, int *buf);