8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / core / rtw_security.c
index 9841568494ecf248916e632c668c841a517f57d6..874ab1ad2e4368039c11e4d1a65311231f6f67ff 100755 (executable)
@@ -1733,8 +1733,9 @@ _func_enter_;
                                prwskey=pattrib->dot118021x_UncstKey.skey;
                        }
 
-#ifdef CONFIG_TDLS     //swencryption
+#ifdef CONFIG_TDLS
                        {
+                               /* Swencryption */
                                struct  sta_info                *ptdls_sta;
                                ptdls_sta=rtw_get_stainfo(&padapter->stapriv ,&pattrib->dst[0] );
                                if((ptdls_sta != NULL) && (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE) )
@@ -3029,12 +3030,12 @@ void wpa_tdls_generate_tpk(_adapter *padapter, PVOID sta)
         * added by the KDF anyway..
         */
 
-       if (os_memcmp(myid(&(padapter->eeprompriv)), psta->hwaddr, ETH_ALEN) < 0) {
-               _rtw_memcpy(data, myid(&(padapter->eeprompriv)), ETH_ALEN);
+       if (os_memcmp(adapter_mac_addr(padapter), psta->hwaddr, ETH_ALEN) < 0) {
+               _rtw_memcpy(data, adapter_mac_addr(padapter), ETH_ALEN);
                _rtw_memcpy(data + ETH_ALEN, psta->hwaddr, ETH_ALEN);
        } else {
                _rtw_memcpy(data, psta->hwaddr, ETH_ALEN);
-               _rtw_memcpy(data + ETH_ALEN, myid(&(padapter->eeprompriv)), ETH_ALEN);
+               _rtw_memcpy(data + ETH_ALEN, adapter_mac_addr(padapter), ETH_ALEN);
        }
        _rtw_memcpy(data + 2 * ETH_ALEN, get_bssid(pmlmepriv), ETH_ALEN);
 
@@ -3101,6 +3102,55 @@ int wpa_tdls_ftie_mic(u8 *kck, u8 trans_seq,
 
 }
 
+/**
+ * wpa_tdls_teardown_ftie_mic - Calculate TDLS TEARDOWN FTIE MIC
+ * @kck: TPK-KCK
+ * @lnkid: Pointer to the beginning of Link Identifier IE
+ * @reason: Reason code of TDLS Teardown
+ * @dialog_token: Dialog token that was used in the MIC calculation for TPK Handshake Message 3
+ * @trans_seq: Transaction Sequence number (1 octet) which shall be set to the value 4
+ * @ftie: Pointer to the beginning of FT IE
+ * @mic: Pointer for writing MIC
+ *
+ * Calculate MIC for TDLS TEARDOWN frame according to Section 10.22.5 in IEEE 802.11 - 2012.
+ */
+int wpa_tdls_teardown_ftie_mic(u8 *kck, u8 *lnkid, u16 reason, 
+       u8 dialog_token, u8 trans_seq, u8 *ftie, u8 *mic)
+{
+       u8 *buf, *pos;
+       struct wpa_tdls_ftie *_ftie;
+       int ret;
+       int len = 2 + lnkid[1] + 2 + 1 + 1 + 2 + ftie[1];
+       
+       buf = rtw_zmalloc(len);
+       if (!buf) {
+               DBG_871X("TDLS: No memory for MIC calculation\n");
+               return -1;
+       }
+
+       pos = buf;
+       /* 1) Link Identifier IE */
+       _rtw_memcpy(pos, lnkid, 2 + lnkid[1]);
+       pos += 2 + lnkid[1];
+       /* 2) Reason Code */
+       _rtw_memcpy(pos, (u8 *)&reason, 2);
+       pos += 2;
+       /* 3) Dialog Token */
+       *pos++ = dialog_token;
+       /* 4) Transaction Sequence number */
+       *pos++ = trans_seq;
+       /* 5) FTIE, with the MIC field of the FTIE set to 0 */
+       _rtw_memcpy(pos, ftie, 2 + ftie[1]);
+       _ftie = (struct wpa_tdls_ftie *) pos;
+       _rtw_memset(_ftie->mic, 0, TDLS_MIC_LEN);
+       pos += 2 + ftie[1];
+
+       ret = omac1_aes_128(kck, buf, pos - buf, mic);
+       rtw_mfree(buf, len);
+       return ret;
+
+}
+
 int tdls_verify_mic(u8 *kck, u8 trans_seq,
                                                        u8 *lnkid, u8 *rsnie, u8 *timeoutie, u8 *ftie)
 {
@@ -3112,14 +3162,14 @@ int tdls_verify_mic(u8 *kck, u8 trans_seq,
 
        if (lnkid == NULL || rsnie == NULL ||
            timeoutie == NULL || ftie == NULL){
-               return 0;
+               return _FAIL;
        }
        
        len = 2 * ETH_ALEN + 1 + 2 + 18 + 2 + *(rsnie+1) + 2 + *(timeoutie+1) + 2 + *(ftie+1);
 
        buf = rtw_zmalloc(len);
        if (buf == NULL)
-               return 0;
+               return _FAIL;
 
        pos = buf;
        /* 1) TDLS initiator STA MAC address */
@@ -3149,17 +3199,17 @@ int tdls_verify_mic(u8 *kck, u8 trans_seq,
        ret = omac1_aes_128(kck, buf, pos - buf, mic);
        rtw_mfree(buf, len);
        if (ret)
-               return 0;
+               return _FAIL;
        rx_ftie = ftie+4;
 
        if (os_memcmp(mic, rx_ftie, 16) == 0) {
                //Valid MIC
-               return 1;
+               return _SUCCESS;
        }
 
        //Invalid MIC
        DBG_871X( "[%s] Invalid MIC\n", __FUNCTION__);
-       return 0;
+       return _FAIL;
 
 }
 #endif //CONFIG_TDLS