Changeset 5304

Show
Ignore:
Timestamp:
08/24/09 06:54:38 (4 years ago)
Author:
jow
Message:

libs/iwinfo: implement wifi scans

Location:
luci/trunk/libs/iwinfo
Files:
2 added
10 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/iwinfo/Makefile

    r5289 r5304  
    1111IWINFO_SO         = iwinfo.so 
    1212IWINFO_LUA        = iwinfo.lua 
    13 IWINFO_OBJ        = src/iwinfo_wl.o src/iwinfo_madwifi.o src/iwinfo_wext.o src/iwinfo_lualib.o 
     13IWINFO_OBJ        = src/iwinfo_wl.o src/iwinfo_madwifi.o \ 
     14    src/iwinfo_wext.o src/iwinfo_wext_scan.o src/iwinfo_lualib.o 
    1415 
    1516%.o: %.c 
  • luci/trunk/libs/iwinfo/src/iwinfo.h

    r5292 r5304  
    3535}; 
    3636 
     37struct iwinfo_crypto_entry { 
     38    uint8_t enabled; 
     39    uint8_t wpa_version; 
     40    uint8_t group_ciphers[8]; 
     41    uint8_t pair_ciphers[8]; 
     42    uint8_t auth_suites[8]; 
     43}; 
     44 
     45struct iwinfo_scanlist_entry { 
     46    uint8_t mac[6]; 
     47    uint8_t ssid[IW_ESSID_MAX_SIZE+1]; 
     48    uint8_t mode[8]; 
     49    uint8_t channel; 
     50    struct iwinfo_crypto_entry crypto; 
     51}; 
     52 
    3753#endif 
    3854 
  • luci/trunk/libs/iwinfo/src/iwinfo_lualib.c

    r5294 r5304  
    108108} 
    109109 
     110/* Wrapper for scan list */ 
     111static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *)) 
     112{ 
     113    int i, j, x, y, len; 
     114    char rv[IWINFO_BUFSIZE]; 
     115    char macstr[18]; 
     116    const char *ifname = luaL_checkstring(L, 1); 
     117    struct iwinfo_scanlist_entry *e; 
     118 
     119    lua_newtable(L); 
     120    memset(rv, 0, sizeof(rv)); 
     121 
     122    if( !(*func)(ifname, rv, &len) ) 
     123    { 
     124        for( i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++ ) 
     125        { 
     126            e = (struct iwinfo_scanlist_entry *) &rv[i]; 
     127 
     128            lua_newtable(L); 
     129 
     130            /* BSSID */ 
     131            sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X", 
     132                e->mac[0], e->mac[1], e->mac[2], 
     133                e->mac[3], e->mac[4], e->mac[5]); 
     134 
     135            lua_pushstring(L, macstr); 
     136            lua_setfield(L, -2, "mac"); 
     137 
     138            /* ESSID */ 
     139            if( e->ssid[0] ) 
     140            { 
     141                lua_pushstring(L, (char *) e->ssid); 
     142                lua_setfield(L, -2, "ssid"); 
     143            } 
     144 
     145            /* Channel */ 
     146            lua_pushinteger(L, e->channel); 
     147            lua_setfield(L, -2, "channel"); 
     148 
     149            /* Mode */ 
     150            lua_pushstring(L, (char *) e->mode); 
     151            lua_setfield(L, -2, "mode"); 
     152 
     153            /* Crypto */ 
     154            lua_pushinteger(L, e->crypto.wpa_version); 
     155            lua_setfield(L, -2, "wpa_version"); 
     156 
     157            lua_newtable(L); 
     158            for( j = 0, y = 1; j < sizeof(e->crypto.group_ciphers); j++ ) 
     159            { 
     160                if( e->crypto.group_ciphers[j] ) 
     161                { 
     162                    lua_pushstring(L, (j < IW_IE_CYPHER_NUM) 
     163                        ? iw_ie_cypher_name[j] : "Proprietary"); 
     164 
     165                    lua_rawseti(L, -2, y++); 
     166                } 
     167            } 
     168            lua_setfield(L, -2, "group_ciphers"); 
     169 
     170            lua_newtable(L); 
     171            for( j = 0, y = 1; j < sizeof(e->crypto.pair_ciphers); j++ ) 
     172            { 
     173                if( e->crypto.pair_ciphers[j] ) 
     174                { 
     175                    lua_pushstring(L, (j < IW_IE_CYPHER_NUM) 
     176                        ? iw_ie_cypher_name[j] : "Proprietary"); 
     177 
     178                    lua_rawseti(L, -2, y++); 
     179                } 
     180            } 
     181            lua_setfield(L, -2, "pair_ciphers"); 
     182 
     183            lua_newtable(L); 
     184            for( j = 0, y = 1; j < sizeof(e->crypto.auth_suites); j++ ) 
     185            { 
     186                if( e->crypto.auth_suites[j] ) 
     187                { 
     188                    lua_pushstring(L, (j < IW_IE_KEY_MGMT_NUM) 
     189                        ? iw_ie_key_mgmt_name[j] : "Proprietary"); 
     190 
     191                    lua_rawseti(L, -2, y++); 
     192                } 
     193            } 
     194            lua_setfield(L, -2, "auth_suites"); 
     195 
     196            lua_rawseti(L, -2, x); 
     197        } 
     198    } 
     199 
     200    return 1; 
     201} 
     202 
     203 
    110204/* Broadcom */ 
    111205LUA_WRAP_INT(wl,channel) 
     
    123217LUA_WRAP_LIST(wl,assoclist) 
    124218LUA_WRAP_LIST(wl,txpwrlist) 
     219LUA_WRAP_LIST(wl,scanlist) 
    125220 
    126221/* Madwifi */ 
     
    139234LUA_WRAP_LIST(madwifi,assoclist) 
    140235LUA_WRAP_LIST(madwifi,txpwrlist) 
     236LUA_WRAP_LIST(madwifi,scanlist) 
    141237 
    142238/* Wext */ 
     
    155251LUA_WRAP_LIST(wext,assoclist) 
    156252LUA_WRAP_LIST(wext,txpwrlist) 
     253LUA_WRAP_LIST(wext,scanlist) 
    157254 
    158255/* Broadcom table */ 
     
    171268    LUA_REG(wl,assoclist), 
    172269    LUA_REG(wl,txpwrlist), 
     270    LUA_REG(wl,scanlist), 
    173271    LUA_REG(wl,mbssid_support), 
    174272    { NULL, NULL } 
     
    190288    LUA_REG(madwifi,assoclist), 
    191289    LUA_REG(madwifi,txpwrlist), 
     290    LUA_REG(madwifi,scanlist), 
    192291    LUA_REG(madwifi,mbssid_support), 
    193292    { NULL, NULL } 
     
    209308    LUA_REG(wext,assoclist), 
    210309    LUA_REG(wext,txpwrlist), 
     310    LUA_REG(wext,scanlist), 
    211311    LUA_REG(wext,mbssid_support), 
    212312    { NULL, NULL } 
  • luci/trunk/libs/iwinfo/src/iwinfo_lualib.h

    r5294 r5304  
    2525 
    2626#include "iwinfo.h" 
     27#include "iwinfo_wext_scan.h" 
    2728 
    2829 
  • luci/trunk/libs/iwinfo/src/iwinfo_madwifi.c

    r5292 r5304  
    404404} 
    405405 
     406int madwifi_get_scanlist(const char *ifname, char *buf, int *len) 
     407{ 
     408    return wext_get_scanlist(ifname, buf, len); 
     409} 
     410 
    406411int madwifi_get_mbssid_support(const char *ifname, int *buf) 
    407412{ 
  • luci/trunk/libs/iwinfo/src/iwinfo_madwifi.h

    r5292 r5304  
    3737int madwifi_get_assoclist(const char *ifname, char *buf, int *len); 
    3838int madwifi_get_txpwrlist(const char *ifname, char *buf, int *len); 
     39int madwifi_get_scanlist(const char *ifname, char *buf, int *len); 
    3940int madwifi_get_mbssid_support(const char *ifname, int *buf); 
    4041 
  • luci/trunk/libs/iwinfo/src/iwinfo_wext.c

    r5292 r5304  
    190190    if(wext_ioctl(ifname, SIOCGIWRATE, &wrq) >= 0) 
    191191    { 
    192         *buf = wrq.u.bitrate.value; 
     192        *buf = (wrq.u.bitrate.value / 1000000); 
    193193        return 0; 
    194194    } 
     
    200200{ 
    201201    struct iwreq wrq; 
     202    struct iw_range range; 
     203    double freq; 
     204    int i; 
    202205 
    203206    if(wext_ioctl(ifname, SIOCGIWFREQ, &wrq) >= 0) 
    204207    { 
    205         /* FIXME: iwlib has some strange workarounds here, maybe we need them as well... */ 
    206         *buf = (int) wext_freq2float(&wrq.u.freq); 
    207         return 0; 
     208        if( wrq.u.freq.m >= 1000 ) 
     209        { 
     210            freq = wext_freq2float(&wrq.u.freq); 
     211            wrq.u.data.pointer = (caddr_t) &range; 
     212            wrq.u.data.length  = sizeof(struct iw_range); 
     213            wrq.u.data.flags   = 0; 
     214 
     215            if(wext_ioctl(ifname, SIOCGIWRANGE, &wrq) >= 0) 
     216            { 
     217                for(i = 0; i < range.num_frequency; i++) 
     218                { 
     219                    if( wext_freq2float(&range.freq[i]) == freq ) 
     220                    { 
     221                        *buf = range.freq[i].i; 
     222                        return 0; 
     223                    } 
     224                } 
     225            } 
     226        } 
     227        else 
     228        { 
     229            *buf = wrq.u.freq.m; 
     230            return 0; 
     231        } 
    208232    } 
    209233 
  • luci/trunk/libs/iwinfo/src/iwinfo_wext.h

    r5292 r5304  
    2323#include "include/wext.h" 
    2424 
     25 
    2526int wext_probe(const char *ifname); 
    2627int wext_get_mode(const char *ifname, char *buf); 
     
    3738int wext_get_assoclist(const char *ifname, char *buf, int *len); 
    3839int wext_get_txpwrlist(const char *ifname, char *buf, int *len); 
     40int wext_get_scanlist(const char *ifname, char *buf, int *len); 
    3941int wext_get_mbssid_support(const char *ifname, int *buf); 
    4042 
  • luci/trunk/libs/iwinfo/src/iwinfo_wl.c

    r5292 r5304  
    385385} 
    386386 
     387int wl_get_scanlist(const char *ifname, char *buf, int *len) 
     388{ 
     389    return wext_get_scanlist(ifname, buf, len); 
     390} 
     391 
    387392int wl_get_mbssid_support(const char *ifname, int *buf) 
    388393{ 
  • luci/trunk/libs/iwinfo/src/iwinfo_wl.h

    r5292 r5304  
    3737int wl_get_assoclist(const char *ifname, char *buf, int *len); 
    3838int wl_get_txpwrlist(const char *ifname, char *buf, int *len); 
     39int wl_get_scanlist(const char *ifname, char *buf, int *len); 
    3940int wl_get_mbssid_support(const char *ifname, int *buf); 
    4041