📄 dls.c
字号:
//AsicUpdateRxWCIDTable(pAd, (USHORT)(i + 2), pAddr); // Add Pair-wise key to Asic#ifdef RTMP_MAC_USB { RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo; COPY_MAC_ADDR(KeyInfo.MacAddr,pAd->StaCfg.DLSEntry[i].MacAddr); KeyInfo.MacTabMatchWCID=pAd->StaCfg.DLSEntry[i].MacTabMatchWCID; NdisMoveMemory(&KeyInfo.CipherKey, &PairwiseKey,sizeof(CIPHER_KEY)); RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_KEY_TABLE, &KeyInfo, sizeof(RT_ADD_PAIRWISE_KEY_ENTRY)); } { PMAC_TABLE_ENTRY pDLSEntry; pDLSEntry = DlsEntryTableLookup(pAd, pAd->StaCfg.DLSEntry[i].MacAddr, TRUE); pDLSEntry->PairwiseKey.CipherAlg=PairwiseKey.CipherAlg; RTUSBEnqueueInternalCmd(pAd, RT_CMD_SET_RX_WCID_TABLE, pDLSEntry, sizeof(MAC_TABLE_ENTRY)); }#endif // RTMP_MAC_USB // NdisMoveMemory(&pEntry->PairwiseKey, &PairwiseKey, sizeof(CIPHER_KEY)); DBGPRINT(RT_DEBUG_TRACE,("DLS - Receive STAKey Message-1 (Initiator STA MAC Address STAKey)\n")); // If support WPA or WPA2, start STAKey hand shake, // If failed hand shake, just tear down peer DLS if (RTMPSendSTAKeyHandShake(pAd, pAddr) != NDIS_STATUS_SUCCESS) { MLME_DLS_REQ_STRUCT MlmeDlsReq; USHORT reason = REASON_QOS_CIPHER_NOT_SUPPORT; pAd->StaCfg.DLSEntry[i].Valid = FALSE; pAd->StaCfg.DLSEntry[i].Status = DLS_NONE; DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason); MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq); } else { DBGPRINT(RT_DEBUG_TRACE,("DLS - Finish STAKey handshake procedure (Peer side)\n")); } } else { // Data frame, update timeout value if (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) { pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut; } } bFindEntry = TRUE; } } return bSTAKeyFrame;}/* ======================================================================== Routine Description: Check if the frame can be sent through DLS direct link interface Arguments: pAd Pointer to adapter Return Value: DLS entry index Note: ========================================================================*/INT RTMPCheckDLSFrame( IN PRTMP_ADAPTER pAd, IN PUCHAR pDA){ INT rval = -1; INT i; if (!pAd->CommonCfg.bDLSCapable) return rval; if (!INFRA_ON(pAd)) return rval; do{ // check local dls table entry for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr)) { rval = i; break; } } // check peer dls table entry for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr)) { rval = i; break; } } } while (FALSE); return rval;}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ========================================================================== */VOID RTMPSendDLSTearDownFrame( IN PRTMP_ADAPTER pAd, IN PUCHAR pDA){ PUCHAR pOutBuffer = NULL; NDIS_STATUS NStatus; HEADER_802_11 DlsTearDownHdr; ULONG FrameLen = 0; USHORT Reason = REASON_QOS_QSTA_LEAVING_QBSS; UCHAR Category = CATEGORY_DLS; UCHAR Action = ACTION_DLS_TEARDOWN; UCHAR i = 0; if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) return; DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame \n")); NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_ERROR,("ASSOC - RTMPSendDLSTearDownFrame() allocate memory failed \n")); return; } ActHeaderInit(pAd, &DlsTearDownHdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->CommonCfg.Bssid); MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(HEADER_802_11), &DlsTearDownHdr, 1, &Category, 1, &Action, 6, pDA, 6, pAd->CurrentAddress, 2, &Reason, END_OF_ARGS); MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); MlmeFreeMemory(pAd, pOutBuffer); // Remove key in local dls table entry for (i = 0; i < MAX_NUM_OF_INIT_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr)) { MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr); } } // Remove key in peer dls table entry for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++) { if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && MAC_ADDR_EQUAL(pDA, pAd->StaCfg.DLSEntry[i].MacAddr)) { MacTableDeleteDlsEntry(pAd, pAd->StaCfg.DLSEntry[i].MacTabMatchWCID, pAd->StaCfg.DLSEntry[i].MacAddr); } } DBGPRINT(RT_DEBUG_TRACE, ("Send DLS TearDown Frame and remove key in (i=%d) \n", i));}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ========================================================================== */NDIS_STATUS RTMPSendSTAKeyRequest( IN PRTMP_ADAPTER pAd, IN PUCHAR pDA){ UCHAR Header802_3[14]; NDIS_STATUS NStatus; ULONG FrameLen = 0; EAPOL_PACKET Packet; UCHAR Mic[16]; UCHAR digest[80]; PUCHAR pOutBuffer = NULL; PNDIS_PACKET pNdisPacket; UCHAR temp[64]; UCHAR DlsPTK[80]; DBGPRINT(RT_DEBUG_TRACE,("DLS - RTMPSendSTAKeyRequest() to %02x:%02x:%02x:%02x:%02x:%02x\n", pDA[0], pDA[1], pDA[2], pDA[3], pDA[4], pDA[5])); pAd->Sequence ++; MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL); // Zero message body NdisZeroMemory(&Packet, sizeof(Packet)); Packet.ProVer = EAPOL_VER; Packet.ProType = EAPOLKey; Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE andPeer MAC address // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE) if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) { Packet.KeyDesc.Type = WPA1_KEY_DESC; } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) { Packet.KeyDesc.Type = WPA2_KEY_DESC; } // Key descriptor version Packet.KeyDesc.KeyInfo.KeyDescVer = (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP)); Packet.KeyDesc.KeyInfo.KeyMic = 1; Packet.KeyDesc.KeyInfo.Secure = 1; Packet.KeyDesc.KeyInfo.Request = 1; Packet.KeyDesc.KeyDataLen[1] = 12; // use our own OUI to distinguish proprietary with standard. Packet.KeyDesc.KeyData[0] = 0xDD; Packet.KeyDesc.KeyData[1] = 0x0A; Packet.KeyDesc.KeyData[2] = 0x00; Packet.KeyDesc.KeyData[3] = 0x0C; Packet.KeyDesc.KeyData[4] = 0x43; Packet.KeyDesc.KeyData[5] = 0x03; NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN); NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY); // Allocate buffer for transmitting message NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); if (NStatus != NDIS_STATUS_SUCCESS) return NStatus; // Prepare EAPOL frame for MIC calculation // Be careful, only EAPOL frame is counted for MIC calculation MakeOutgoingFrame(pOutBuffer, &FrameLen, Packet.Body_Len[1] + 4, &Packet, END_OF_ARGS); // use proprietary PTK NdisZeroMemory(temp, 64); NdisMoveMemory(temp, "IEEE802.11 WIRELESS ACCESS POINT", 32); WpaDerivePTK(pAd, temp, temp, pAd->CommonCfg.Bssid, temp, pAd->CurrentAddress, DlsPTK, LEN_PTK); // calculate MIC if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { // AES NdisZeroMemory(digest, sizeof(digest)); HMAC_SHA1(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, digest, SHA1_DIGEST_SIZE); NdisMoveMemory(Packet.KeyDesc.KeyMic, digest, LEN_KEY_DESC_MIC); } else { NdisZeroMemory(Mic, sizeof(Mic)); HMAC_MD5(DlsPTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic, MD5_DIGEST_SIZE); NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC); } MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(Header802_3), Header802_3, Packet.Body_Len[1] + 4, &Packet, END_OF_ARGS); NStatus = RTMPAllocateNdisPacket(pAd, &pNdisPacket, NULL, 0, pOutBuffer, FrameLen); if (NStatus == NDIS_STATUS_SUCCESS) { RTMP_SET_PACKET_WCID(pNdisPacket, BSSID_WCID); STASendPacket(pAd, pNdisPacket); RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); } MlmeFreeMemory(pAd, pOutBuffer); DBGPRINT(RT_DEBUG_TRACE, ("RTMPSendSTAKeyRequest- Send STAKey request (NStatus=%x, FrameLen=%ld)\n", NStatus, FrameLen)); return NStatus;}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ========================================================================== */NDIS_STATUS RTMPSendSTAKeyHandShake( IN PRTMP_ADAPTER pAd, IN PUCHAR pDA){ UCHAR Header802_3[14]; NDIS_STATUS NStatus; ULONG FrameLen = 0; EAPOL_PACKET Packet; UCHAR Mic[16]; UCHAR digest[80]; PUCHAR pOutBuffer = NULL; PNDIS_PACKET pNdisPacket; UCHAR temp[64]; UCHAR DlsPTK[80]; // Due to dirver can not get PTK, use proprietary PTK DBGPRINT(RT_DEBUG_TRACE,("DLS - RTMPSendSTAKeyHandShake() to %02x:%02x:%02x:%02x:%02x:%02x\n", pDA[0], pDA[1], pDA[2], pDA[3], pDA[4], pDA[5])); pAd->Sequence ++; MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL); // Zero message body NdisZeroMemory(&Packet, sizeof(Packet)); Packet.ProVer = EAPOL_VER; Packet.ProType = EAPOLKey; Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + 6 + MAC_ADDR_LEN; // data field contain KDE and Peer MAC address // STAKey Message is as EAPOL-Key(1,1,0,0,G/0,0,0, MIC, 0,Peer MAC KDE) if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) { Packet.KeyDesc.Type = WPA1_KEY_DESC; } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) { Packet.KeyDesc.Type = WPA2_KEY_DESC; } // Key descriptor version Packet.KeyDesc.KeyInfo.KeyDescVer = (((pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) || (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP)); Packet.KeyDesc.KeyInfo.KeyMic = 1; Packet.KeyDesc.KeyInfo.Secure = 1; Packet.KeyDesc.KeyDataLen[1] = 12; // use our own OUI to distinguish proprietary with standard. Packet.KeyDesc.KeyData[0] = 0xDD; Packet.KeyDesc.KeyData[1] = 0x0A; Packet.KeyDesc.KeyData[2] = 0x00; Packet.KeyDesc.KeyData[3] = 0x0C; Packet.KeyDesc.KeyData[4] = 0x43; Packet.KeyDesc.KeyData[5] = 0x03; NdisMoveMemory(&Packet.KeyDesc.KeyData[6], pDA, MAC_ADDR_LEN); NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.DlsReplayCounter, LEN_KEY_DESC_REPLAY); // Allocate buffer for transmitting message NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); if (NStatus != NDIS_STATUS_SUCCESS) return NStatus; // Prepare EAPOL frame for MIC calculation // Be careful,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -