Ticket #132: madwifi-ng.wpa+rsn.patch

File madwifi-ng.wpa+rsn.patch, 12.1 kB (added by Charles Bovy <charles@bovy.nl>, 6 years ago)

Possible fix to get both WPA and RSN IE reported

  • net80211/ieee80211_node.c

    old new  
    646646        ni->ni_rssi = se->se_rssi; 
    647647        if (se->se_wpa_ie != NULL) 
    648648                ieee80211_saveie(&ni->ni_wpa_ie, se->se_wpa_ie); 
     649        if (se->se_rsn_ie != NULL) 
     650                ieee80211_saveie(&ni->ni_rsn_ie, se->se_rsn_ie); 
    649651        if (se->se_wme_ie != NULL) 
    650652                ieee80211_saveie(&ni->ni_wme_ie, se->se_wme_ie); 
    651653        if (se->se_ath_ie != NULL) 
     
    791793        ic->ic_node_cleanup(ni); 
    792794        if (ni->ni_wpa_ie != NULL) 
    793795                FREE(ni->ni_wpa_ie, M_DEVBUF); 
     796        if (ni->ni_rsn_ie != NULL) 
     797                FREE(ni->ni_rsn_ie, M_DEVBUF); 
    794798        if (ni->ni_wme_ie != NULL) 
    795799                FREE(ni->ni_wme_ie, M_DEVBUF); 
    796800        if (ni->ni_ath_ie != NULL) 
     
    11771181                        ieee80211_saveie(&ni->ni_wme_ie, sp->wme); 
    11781182                if (sp->wpa != NULL) 
    11791183                        ieee80211_saveie(&ni->ni_wpa_ie, sp->wpa); 
     1184                if (sp->rsn != NULL) 
     1185                        ieee80211_saveie(&ni->ni_rsn_ie, sp->rsn); 
    11801186                if (sp->ath != NULL) 
    11811187                        ieee80211_saveath(ni, sp->ath); 
    11821188 
  • net80211/ieee80211_scan.h

    old new  
    144144        u_int8_t        *xrates; 
    145145        u_int8_t        *doth; 
    146146        u_int8_t        *wpa; 
     147        u_int8_t        *rsn; 
    147148        u_int8_t        *wme; 
    148149        u_int8_t        *ath; 
    149150}; 
     
    172173        u_int8_t        se_erp;         /* ERP from beacon/probe resp */ 
    173174        int8_t          se_rssi;        /* avg'd recv ssi */ 
    174175        u_int8_t        se_dtimperiod;  /* DTIM period */ 
    175         u_int8_t        *se_wpa_ie;     /* captured WPA/RSN ie */ 
     176        u_int8_t        *se_wpa_ie;     /* captured WPA ie */ 
     177        u_int8_t        *se_rsn_ie;     /* captured RSN ie */ 
    176178        u_int8_t        *se_wme_ie;     /* captured WME ie */ 
    177179        u_int8_t        *se_ath_ie;     /* captured Atheros ie */ 
    178180        u_int           se_age;         /* age of entry (0 on create) */ 
  • net80211/ieee80211_node.h

    old new  
    122122        u_int16_t               ni_txpower;     /* current transmit power */ 
    123123        u_int16_t               ni_vlan;        /* vlan tag */ 
    124124        u_int32_t               *ni_challenge;  /* shared-key challenge */ 
    125         u_int8_t                *ni_wpa_ie;     /* captured WPA/RSN ie */ 
     125        u_int8_t                *ni_wpa_ie;     /* captured WPA ie */ 
     126        u_int8_t                *ni_rsn_ie;     /* captured RSN ie */ 
    126127        u_int8_t                *ni_wme_ie;     /* captured WME ie */ 
    127128        u_int8_t                *ni_ath_ie;     /* captured Atheros ie */ 
    128129        u_int16_t               ni_txseqs[17];  /* tx seq per-tid */ 
  • net80211/ieee80211_scan_sta.c

    old new  
    272272        } 
    273273        saveie(&ise->se_wme_ie, sp->wme); 
    274274        saveie(&ise->se_wpa_ie, sp->wpa); 
     275        saveie(&ise->se_rsn_ie, sp->rsn); 
    275276        saveie(&ise->se_ath_ie, sp->ath); 
    276277 
    277278        /* clear failure count after STA_FAIL_AGE passes */ 
  • net80211/ieee80211_wireless.c

    old new  
    14321432        iwe.u.data.length = strlen(buf); 
    14331433        current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf); 
    14341434 
    1435         if (se->se_wpa_ie != NULL) { 
     1435        if (se->se_rsn_ie != NULL) { 
    14361436                static const char rsn_leader[] = "rsn_ie="; 
    1437                 static const char wpa_leader[] = "wpa_ie="; 
    14381437 
    14391438                memset(&iwe, 0, sizeof(iwe)); 
    14401439                iwe.cmd = IWEVCUSTOM; 
    1441                 if (se->se_wpa_ie[0] == IEEE80211_ELEMID_RSN) 
     1440                if (se->se_rsn_ie[0] == IEEE80211_ELEMID_RSN) 
    14421441                        iwe.u.data.length = encode_ie(buf, sizeof(buf), 
    1443                                 se->se_wpa_ie, se->se_wpa_ie[1]+2, 
     1442                                se->se_rsn_ie, se->se_rsn_ie[1]+2, 
    14441443                                rsn_leader, sizeof(rsn_leader)-1); 
    1445                 else 
     1444                if (iwe.u.data.length != 0) 
     1445                        current_ev = iwe_stream_add_point(current_ev, end_buf, 
     1446                                &iwe, buf); 
     1447        } 
     1448        if (se->se_wpa_ie != NULL) { 
     1449                static const char wpa_leader[] = "wpa_ie="; 
     1450 
     1451                memset(&iwe, 0, sizeof(iwe)); 
     1452                iwe.cmd = IWEVCUSTOM; 
    14461453                        iwe.u.data.length = encode_ie(buf, sizeof(buf), 
    14471454                                se->se_wpa_ie, se->se_wpa_ie[1]+2, 
    14481455                                wpa_leader, sizeof(wpa_leader)-1); 
  • net80211/ieee80211_input.c

    old new  
    16401640 */ 
    16411641static int 
    16421642ieee80211_parse_wpa(struct ieee80211vap *vap, u_int8_t *frm, 
    1643         struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 
     1643        struct ieee80211_rsnparms *rsn_parm, const struct ieee80211_frame *wh) 
    16441644{ 
    16451645        u_int8_t len = frm[1]; 
    16461646        u_int32_t w; 
     
    16761676        frm += 2, len -= 2; 
    16771677 
    16781678        /* multicast/group cipher */ 
    1679         w = wpa_cipher(frm, &rsn->rsn_mcastkeylen); 
    1680         if (w != rsn->rsn_mcastcipher) { 
     1679        w = wpa_cipher(frm, &rsn_parm->rsn_mcastkeylen); 
     1680        if (w != rsn_parm->rsn_mcastcipher) { 
    16811681                IEEE80211_DISCARD_IE(vap, 
    16821682                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
    16831683                    wh, "WPA", "mcast cipher mismatch; got %u, expected %u", 
    1684                     w, rsn->rsn_mcastcipher); 
     1684                    w, rsn_parm->rsn_mcastcipher); 
    16851685                return IEEE80211_REASON_IE_INVALID; 
    16861686        } 
    16871687        frm += 4, len -= 4; 
     
    16981698        } 
    16991699        w = 0; 
    17001700        for (; n > 0; n--) { 
    1701                 w |= 1<<wpa_cipher(frm, &rsn->rsn_ucastkeylen); 
     1701                w |= 1<<wpa_cipher(frm, &rsn_parm->rsn_ucastkeylen); 
    17021702                frm += 4, len -= 4; 
    17031703        } 
    1704         w &= rsn->rsn_ucastcipherset; 
     1704        w &= rsn_parm->rsn_ucastcipherset; 
    17051705        if (w == 0) { 
    17061706                IEEE80211_DISCARD_IE(vap, 
    17071707                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
     
    17091709                return IEEE80211_REASON_IE_INVALID; 
    17101710        } 
    17111711        if (w & (1<<IEEE80211_CIPHER_TKIP)) 
    1712                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
     1712                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
    17131713        else 
    1714                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
     1714                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
    17151715 
    17161716        /* key management algorithms */ 
    17171717        n = LE_READ_2(frm); 
     
    17281728                w |= wpa_keymgmt(frm); 
    17291729                frm += 4, len -= 4; 
    17301730        } 
    1731         w &= rsn->rsn_keymgmtset; 
     1731        w &= rsn_parm->rsn_keymgmtset; 
    17321732        if (w == 0) { 
    17331733                IEEE80211_DISCARD_IE(vap, 
    17341734                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
     
    17361736                return IEEE80211_REASON_IE_INVALID; 
    17371737        } 
    17381738        if (w & WPA_ASE_8021X_UNSPEC) 
    1739                 rsn->rsn_keymgmt = WPA_ASE_8021X_UNSPEC; 
     1739                rsn_parm->rsn_keymgmt = WPA_ASE_8021X_UNSPEC; 
    17401740        else 
    1741                 rsn->rsn_keymgmt = WPA_ASE_8021X_PSK; 
     1741                rsn_parm->rsn_keymgmt = WPA_ASE_8021X_PSK; 
    17421742 
    17431743        if (len > 2)            /* optional capabilities */ 
    1744                 rsn->rsn_caps = LE_READ_2(frm); 
     1744                rsn_parm->rsn_caps = LE_READ_2(frm); 
    17451745 
    17461746        return 0; 
    17471747} 
     
    18081808 */ 
    18091809static int 
    18101810ieee80211_parse_rsn(struct ieee80211vap *vap, u_int8_t *frm, 
    1811         struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 
     1811        struct ieee80211_rsnparms *rsn_parm, const struct ieee80211_frame *wh) 
    18121812{ 
    18131813        u_int8_t len = frm[1]; 
    18141814        u_int32_t w; 
     
    18431843        frm += 2, len -= 2; 
    18441844 
    18451845        /* multicast/group cipher */ 
    1846         w = rsn_cipher(frm, &rsn->rsn_mcastkeylen); 
    1847         if (w != rsn->rsn_mcastcipher) { 
     1846        w = rsn_cipher(frm, &rsn_parm->rsn_mcastkeylen); 
     1847        if (w != rsn_parm->rsn_mcastcipher) { 
    18481848                IEEE80211_DISCARD_IE(vap, 
    18491849                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
    18501850                    wh, "RSN", "mcast cipher mismatch; got %u, expected %u", 
    1851                     w, rsn->rsn_mcastcipher); 
     1851                    w, rsn_parm->rsn_mcastcipher); 
    18521852                return IEEE80211_REASON_IE_INVALID; 
    18531853        } 
    18541854        frm += 4, len -= 4; 
     
    18651865        } 
    18661866        w = 0; 
    18671867        for (; n > 0; n--) { 
    1868                 w |= 1<<rsn_cipher(frm, &rsn->rsn_ucastkeylen); 
     1868                w |= 1<<rsn_cipher(frm, &rsn_parm->rsn_ucastkeylen); 
    18691869                frm += 4, len -= 4; 
    18701870        } 
    1871         w &= rsn->rsn_ucastcipherset; 
     1871        w &= rsn_parm->rsn_ucastcipherset; 
    18721872        if (w == 0) { 
    18731873                IEEE80211_DISCARD_IE(vap, 
    18741874                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
     
    18761876                return IEEE80211_REASON_IE_INVALID; 
    18771877        } 
    18781878        if (w & (1<<IEEE80211_CIPHER_TKIP)) 
    1879                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
     1879                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 
    18801880        else 
    1881                 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
     1881                rsn_parm->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 
    18821882 
    18831883        /* key management algorithms */ 
    18841884        n = LE_READ_2(frm); 
     
    18951895                w |= rsn_keymgmt(frm); 
    18961896                frm += 4, len -= 4; 
    18971897        } 
    1898         w &= rsn->rsn_keymgmtset; 
     1898        w &= rsn_parm->rsn_keymgmtset; 
    18991899        if (w == 0) { 
    19001900                IEEE80211_DISCARD_IE(vap, 
    19011901                    IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 
     
    19031903                return IEEE80211_REASON_IE_INVALID; 
    19041904        } 
    19051905        if (w & RSN_ASE_8021X_UNSPEC) 
    1906                 rsn->rsn_keymgmt = RSN_ASE_8021X_UNSPEC; 
     1906                rsn_parm->rsn_keymgmt = RSN_ASE_8021X_UNSPEC; 
    19071907        else 
    1908                 rsn->rsn_keymgmt = RSN_ASE_8021X_PSK; 
     1908                rsn_parm->rsn_keymgmt = RSN_ASE_8021X_PSK; 
    19091909 
    19101910        /* optional RSN capabilities */ 
    19111911        if (len > 2) 
    1912                 rsn->rsn_caps = LE_READ_2(frm); 
     1912                rsn_parm->rsn_caps = LE_READ_2(frm); 
    19131913        /* XXXPMKID */ 
    19141914 
    19151915        return 0; 
     
    22002200        struct ieee80211com *ic = vap->iv_ic; 
    22012201        struct ieee80211_frame *wh; 
    22022202        u_int8_t *frm, *efrm; 
    2203         u_int8_t *ssid, *rates, *xrates, *wpa, *wme, *ath; 
     2203        u_int8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath; 
    22042204        u_int8_t rate; 
    22052205        int reassoc, resp, allocbs; 
    22062206        u_int8_t qosinfo; 
     
    22982298                                scan.erp = frm[2]; 
    22992299                                break; 
    23002300                        case IEEE80211_ELEMID_RSN: 
    2301                                 scan.wpa = frm; 
     2301                                scan.rsn = frm; 
    23022302                                break; 
    23032303                        case IEEE80211_ELEMID_VENDOR: 
    23042304                                if (iswpaoui(frm)) 
     
    26732673        case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 
    26742674        case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: { 
    26752675                u_int16_t capinfo, bintval; 
    2676                 struct ieee80211_rsnparms rsn
     2676                struct ieee80211_rsnparms rsn_parm
    26772677                u_int8_t reason; 
    26782678 
    26792679                if (vap->iv_opmode != IEEE80211_M_HOSTAP || 
     
    27152715                bintval = le16toh(*(u_int16_t *)frm);   frm += 2; 
    27162716                if (reassoc) 
    27172717                        frm += 6;       /* ignore current AP info */ 
    2718                 ssid = rates = xrates = wpa = wme = ath = NULL; 
     2718                ssid = rates = xrates = wpa = rsn = wme = ath = NULL; 
    27192719                while (frm < efrm) { 
    27202720                        switch (*frm) { 
    27212721                        case IEEE80211_ELEMID_SSID: 
     
    27302730                        /* XXX verify only one of RSN and WPA ie's? */ 
    27312731                        case IEEE80211_ELEMID_RSN: 
    27322732                                if (vap->iv_flags & IEEE80211_F_WPA2) 
    2733                                         wpa = frm; 
     2733                                        rsn = frm; 
    27342734                                else 
    27352735                                        IEEE80211_DPRINTF(vap, 
    27362736                                                IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, 
     
    27892789                        return;  
    27902790                } 
    27912791                                 
    2792                 if (wpa != NULL) { 
     2792                if (rsn != NULL) { 
    27932793                        /* 
    27942794                         * Parse WPA information element.  Note that 
    27952795                         * we initialize the param block from the node 
     
    27972797                         * our defaults.  The resulting parameters are 
    27982798                         * installed below after the association is assured. 
    27992799                         */ 
    2800                         rsn = ni->ni_rsn; 
    2801                         if (wpa[0] != IEEE80211_ELEMID_RSN) 
    2802                                 reason = ieee80211_parse_wpa(vap, wpa, &rsn, wh); 
     2800                        rsn_parm = ni->ni_rsn; 
     2801                        if (rsn[0] != IEEE80211_ELEMID_RSN) 
     2802                                reason = ieee80211_parse_wpa(vap, rsn, &rsn_parm, wh); 
    28032803                        else 
    2804                                 reason = ieee80211_parse_rsn(vap, wpa, &rsn, wh); 
     2804                                reason = ieee80211_parse_rsn(vap, rsn, &rsn_parm, wh); 
    28052805                        if (reason != 0) { 
    28062806                                IEEE80211_SEND_MGMT(ni, 
    28072807                                    IEEE80211_FC0_SUBTYPE_DEAUTH, reason); 
     
    28142814                            IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, 
    28152815                            wh->i_addr2, 
    28162816                            "%s ie: mc %u/%u uc %u/%u key %u caps 0x%x", 
    2817                             wpa[0] != IEEE80211_ELEMID_RSN ?  "WPA" : "RSN", 
    2818                             rsn.rsn_mcastcipher, rsn.rsn_mcastkeylen, 
    2819                             rsn.rsn_ucastcipher, rsn.rsn_ucastkeylen, 
    2820                             rsn.rsn_keymgmt, rsn.rsn_caps); 
     2817                            rsn[0] != IEEE80211_ELEMID_RSN ?  "WPA" : "RSN", 
     2818                            rsn_parm.rsn_mcastcipher, rsn_parm.rsn_mcastkeylen, 
     2819                            rsn_parm.rsn_ucastcipher, rsn_parm.rsn_ucastkeylen, 
     2820                            rsn_parm.rsn_keymgmt, rsn_parm.rsn_caps); 
    28212821                } 
    28222822                /* discard challenge after association */ 
    28232823                if (ni->ni_challenge != NULL) { 
     
    28862886                         * node as using WPA and record information element 
    28872887                         * for applications that require it. 
    28882888                         */ 
    2889                         ni->ni_rsn = rsn; 
    28902889                        ieee80211_saveie(&ni->ni_wpa_ie, wpa); 
    28912890                } else if (ni->ni_wpa_ie != NULL) { 
    28922891                        /* 
     
    28952894                        FREE(ni->ni_wpa_ie, M_DEVBUF); 
    28962895                        ni->ni_wpa_ie = NULL; 
    28972896                } 
     2897                if (rsn != NULL) { 
     2898                        /* 
     2899                         * Record WPA/RSN parameters for station, mark 
     2900                         * node as using WPA and record information element 
     2901                         * for applications that require it. 
     2902                         */ 
     2903                        ni->ni_rsn = rsn_parm; 
     2904                        ieee80211_saveie(&ni->ni_rsn_ie, rsn); 
     2905                } else if (ni->ni_rsn_ie != NULL) { 
     2906                        /* 
     2907                         * Flush any state from a previous association. 
     2908                         */ 
     2909                        FREE(ni->ni_rsn_ie, M_DEVBUF); 
     2910                        ni->ni_rsn_ie = NULL; 
     2911                } 
    28982912                if (wme != NULL) { 
    28992913                        /* 
    29002914                         * Record WME parameters for station, mark node