Changeset 6606

Show
Ignore:
Timestamp:
12/05/10 00:25:14 (2 years ago)
Author:
jow
Message:

libiwinfo: fix scan issues in nl80211, encryption detection fixes for madwifi

Location:
luci/trunk/contrib/package/iwinfo
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/contrib/package/iwinfo/Makefile

    r6590 r6606  
    88 
    99PKG_NAME:=libiwinfo 
    10 PKG_RELEASE:=12 
     10PKG_RELEASE:=13 
    1111 
    1212PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) 
  • luci/trunk/contrib/package/iwinfo/src/iwinfo_madwifi.c

    r6565 r6606  
    550550{ 
    551551    int ciphers = 0, key_len = 0; 
     552    char keybuf[IW_ENCODING_TOKEN_MAX]; 
    552553    struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf; 
    553554    struct iwreq wrq; 
     
    555556 
    556557    memset(&wrq, 0, sizeof(wrq)); 
    557     memset(&wk, 0, sizeof(wk)); 
    558     memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); 
     558 
     559    /* Obtain key info */ 
     560    if( madwifi_wrq(&wrq, ifname, SIOCGIWENCODE, keybuf, sizeof(keybuf)) < 0 ) 
     561        return -1; 
     562 
     563    /* Have any encryption? */ 
     564    if( (wrq.u.data.flags & IW_ENCODE_DISABLED) || (wrq.u.data.length == 0) ) 
     565        return 0; 
     566 
     567    /* Save key len */ 
     568    key_len = wrq.u.data.length; 
    559569 
    560570    /* Get wpa protocol version */ 
     
    590600    } 
    591601 
     602    memset(&wk, 0, sizeof(wk)); 
     603    memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); 
     604 
    592605    /* Get key information */ 
    593606    if( get80211priv(ifname, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk)) >= 0 ) 
     
    598611    } 
    599612 
    600     /* Get group key length */ 
    601     wrq.u.mode = IEEE80211_PARAM_MCASTKEYLEN; 
    602     if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 ) 
    603         key_len = wrq.u.mode; 
    604  
    605613    /* Get used pairwise ciphers */ 
    606614    wrq.u.mode = IEEE80211_PARAM_UCASTCIPHERS; 
     
    609617        ciphers = wrq.u.mode; 
    610618 
    611         if( ciphers & (1 << IEEE80211_CIPHER_TKIP) ) 
     619        if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_TKIP) ) 
    612620            c->pair_ciphers |= IWINFO_CIPHER_TKIP; 
    613621 
    614         if( ciphers & (1 << IEEE80211_CIPHER_AES_CCM) ) 
     622        if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_AES_CCM) ) 
    615623            c->pair_ciphers |= IWINFO_CIPHER_CCMP; 
    616624 
    617         if( ciphers & (1 << IEEE80211_CIPHER_AES_OCB) ) 
     625        if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_AES_OCB) ) 
    618626            c->pair_ciphers |= IWINFO_CIPHER_AESOCB; 
    619627 
    620         if( ciphers & (1 << IEEE80211_CIPHER_CKIP) ) 
     628        if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_CKIP) ) 
    621629            c->pair_ciphers |= IWINFO_CIPHER_CKIP; 
    622630 
     
    633641 
    634642                default: 
     643                    c->pair_ciphers = IWINFO_CIPHER_WEP40 | 
     644                        IWINFO_CIPHER_WEP104; 
    635645                    break; 
    636646            } 
     
    645655    if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 ) 
    646656    { 
    647         ciphers = wrq.u.mode; 
    648  
    649         switch(wrq.u.mode) { 
     657        ciphers = c->wpa_version ? wrq.u.mode : IEEE80211_CIPHER_WEP; 
     658 
     659        switch(ciphers) { 
    650660            case IEEE80211_CIPHER_TKIP: 
    651661                c->group_ciphers |= IWINFO_CIPHER_TKIP; 
  • luci/trunk/contrib/package/iwinfo/src/iwinfo_nl80211.c

    r6590 r6606  
    334334} 
    335335 
    336 static char * nl80211_wpasupp_info(const char *ifname, const char *cmd) 
    337 { 
    338     int sock = -1, len; 
     336static inline int nl80211_wpactl_recv(int sock, char *buf, int blen) 
     337{ 
     338    fd_set rfds; 
     339    struct timeval tv = { 2, 0 }; 
     340 
     341    FD_ZERO(&rfds); 
     342    FD_SET(sock, &rfds); 
     343 
     344    memset(buf, 0, blen); 
     345 
     346 
     347    if( select(sock + 1, &rfds, NULL, NULL, &tv) < 0 ) 
     348        return -1; 
     349 
     350    if( !FD_ISSET(sock, &rfds) ) 
     351        return -1; 
     352 
     353    return recv(sock, buf, blen, 0); 
     354} 
     355 
     356static char * nl80211_wpactl_info(const char *ifname, const char *cmd, 
     357                                   const char *event) 
     358{ 
     359    int sock = -1; 
    339360    char *rv = NULL; 
    340361    size_t remote_length, local_length; 
    341     static char buffer[1024] = { 0 }; 
    342  
    343     struct timeval tv = { 2, 0 }; 
     362    static char buffer[10240] = { 0 }; 
     363 
    344364    struct sockaddr_un local = { 0 }; 
    345365    struct sockaddr_un remote = { 0 }; 
    346366 
    347     fd_set rfds; 
    348367 
    349368    sock = socket(PF_UNIX, SOCK_DGRAM, 0); 
     
    368387        goto out; 
    369388 
     389 
     390    send(sock, "ATTACH", 6, 0); 
     391 
     392    if( nl80211_wpactl_recv(sock, buffer, sizeof(buffer)) <= 0 ) 
     393        goto out; 
     394 
     395 
    370396    send(sock, cmd, strlen(cmd), 0); 
    371397 
    372398    while( 1 ) 
    373399    { 
    374         FD_ZERO(&rfds); 
    375         FD_SET(sock, &rfds); 
    376  
    377         if( select(sock + 1, &rfds, NULL, NULL, &tv) < 0 ) 
    378             goto out; 
    379  
    380         if( !FD_ISSET(sock, &rfds) ) 
     400        if( nl80211_wpactl_recv(sock, buffer, sizeof(buffer)) <= 0 ) 
     401        { 
     402            if( event ) 
     403                continue; 
     404 
    381405            break; 
    382  
    383         if( (len = recv(sock, buffer, sizeof(buffer), 0)) <= 0 ) 
    384             goto out; 
    385  
    386         buffer[len] = 0; 
    387  
    388         if( buffer[0] != '<' ) 
     406        } 
     407 
     408        if( (!event && buffer[0] != '<') || strstr(buffer, event) ) 
    389409            break; 
    390410    } 
     
    934954 
    935955    /* WPA supplicant */ 
    936     else if( (res = nl80211_wpasupp_info(ifname, "STATUS")) && 
     956    else if( (res = nl80211_wpactl_info(ifname, "STATUS", NULL)) && 
    937957             (val = nl80211_getval(NULL, res, "pairwise_cipher")) ) 
    938958    { 
     
    12501270 
    12511271    /* WPA supplicant */ 
    1252     if( (res = nl80211_wpasupp_info(ifname, "SCAN")) && !strcmp(res, "OK\n") ) 
    1253     { 
    1254         sleep(2); 
    1255  
    1256         if( (res = nl80211_wpasupp_info(ifname, "SCAN_RESULTS")) ) 
     1272    if( (res = nl80211_wpactl_info(ifname, "SCAN", "CTRL-EVENT-SCAN-RESULTS")) ) 
     1273    { 
     1274        if( (res = nl80211_wpactl_info(ifname, "SCAN_RESULTS", NULL)) ) 
    12571275        { 
    12581276            nl80211_get_quality_max(ifname, &qmax); 
     
    12631281            count = 0; 
    12641282 
    1265             while( sscanf(res, "%17s %d %d %255s %127[^\n]\n", 
     1283            while( sscanf(res, "%17s %d %d %255s%*[ \t]%127[^\n]\n", 
    12661284                          bssid, &freq, &rssi, cipher, ssid) > 0 ) 
    12671285            { 
     
    13161334                count++; 
    13171335                e++; 
     1336 
     1337                memset(ssid, 0, sizeof(ssid)); 
     1338                memset(bssid, 0, sizeof(bssid)); 
     1339                memset(cipher, 0, sizeof(cipher)); 
    13181340            } 
    13191341