···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- aironet.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- Paul Lin 04-06-15 Initial3636-*/3737-#include "../rt_config.h"3838-3939-/*4040- ==========================================================================4141- Description:4242- association state machine init, including state transition and timer init4343- Parameters:4444- S - pointer to the association state machine4545- ==========================================================================4646- */4747-VOID AironetStateMachineInit(4848- IN PRTMP_ADAPTER pAd,4949- IN STATE_MACHINE *S,5050- OUT STATE_MACHINE_FUNC Trans[])5151-{5252- StateMachineInit(S, Trans, MAX_AIRONET_STATE, MAX_AIRONET_MSG, (STATE_MACHINE_FUNC)Drop, AIRONET_IDLE, AIRONET_MACHINE_BASE);5353- StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_MSG, (STATE_MACHINE_FUNC)AironetMsgAction);5454- StateMachineSetAction(S, AIRONET_IDLE, MT2_AIRONET_SCAN_REQ, (STATE_MACHINE_FUNC)AironetRequestAction);5555- StateMachineSetAction(S, AIRONET_SCANNING, MT2_AIRONET_SCAN_DONE, (STATE_MACHINE_FUNC)AironetReportAction);5656-}5757-5858-/*5959- ==========================================================================6060- Description:6161- This is state machine function.6262- When receiving EAPOL packets which is for 802.1x key management.6363- Use both in WPA, and WPAPSK case.6464- In this function, further dispatch to different functions according to the received packet. 3 categories are :6565- 1. normal 4-way pairwisekey and 2-way groupkey handshake6666- 2. MIC error (Countermeasures attack) report packet from STA.6767- 3. Request for pairwise/group key update from STA6868- Return:6969- ==========================================================================7070-*/7171-VOID AironetMsgAction(7272- IN PRTMP_ADAPTER pAd,7373- IN MLME_QUEUE_ELEM *Elem)7474-{7575- USHORT Length;7676- UCHAR Index, i;7777- PUCHAR pData;7878- PAIRONET_RM_REQUEST_FRAME pRMReq;7979- PRM_REQUEST_ACTION pReqElem;8080-8181- DBGPRINT(RT_DEBUG_TRACE, ("-----> AironetMsgAction\n"));8282-8383- // 0. Get Aironet IAPP header first8484- pRMReq = (PAIRONET_RM_REQUEST_FRAME) &Elem->Msg[LENGTH_802_11];8585- pData = (PUCHAR) &Elem->Msg[LENGTH_802_11];8686-8787- // 1. Change endian format form network to little endian8888- Length = be2cpu16(pRMReq->IAPP.Length);8989-9090- // 2.0 Sanity check, this should only happen when CCX 2.0 support is enabled9191- if (pAd->StaCfg.CCXEnable != TRUE)9292- return;9393-9494- // 2.1 Radio measurement must be on9595- if (pAd->StaCfg.CCXControl.field.RMEnable != 1)9696- return;9797-9898- // 2.2. Debug print all bit information9999- DBGPRINT(RT_DEBUG_TRACE, ("IAPP ID & Length %d\n", Length));100100- DBGPRINT(RT_DEBUG_TRACE, ("IAPP Type %x\n", pRMReq->IAPP.Type));101101- DBGPRINT(RT_DEBUG_TRACE, ("IAPP SubType %x\n", pRMReq->IAPP.SubType));102102- DBGPRINT(RT_DEBUG_TRACE, ("IAPP Dialog Token %x\n", pRMReq->IAPP.Token));103103- DBGPRINT(RT_DEBUG_TRACE, ("IAPP Activation Delay %x\n", pRMReq->Delay));104104- DBGPRINT(RT_DEBUG_TRACE, ("IAPP Measurement Offset %x\n", pRMReq->Offset));105105-106106- // 3. Check IAPP frame type, it must be 0x32 for Cisco Aironet extension107107- if (pRMReq->IAPP.Type != AIRONET_IAPP_TYPE)108108- {109109- DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP type for Cisco Aironet extension\n"));110110- return;111111- }112112-113113- // 4. Check IAPP frame subtype, it must be 0x01 for Cisco Aironet extension request.114114- // Since we are acting as client only, we will disregards reply subtype.115115- if (pRMReq->IAPP.SubType != AIRONET_IAPP_SUBTYPE_REQUEST)116116- {117117- DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP subtype for Cisco Aironet extension\n"));118118- return;119119- }120120-121121- // 5. Verify Destination MAC and Source MAC, both should be all zeros.122122- if (! MAC_ADDR_EQUAL(pRMReq->IAPP.DA, ZERO_MAC_ADDR))123123- {124124- DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP DA for Cisco Aironet extension, it's not Zero\n"));125125- return;126126- }127127-128128- if (! MAC_ADDR_EQUAL(pRMReq->IAPP.SA, ZERO_MAC_ADDR))129129- {130130- DBGPRINT(RT_DEBUG_ERROR, ("Wrong IAPP SA for Cisco Aironet extension, it's not Zero\n"));131131- return;132132- }133133-134134- // 6. Reinit all report related fields135135- NdisZeroMemory(pAd->StaCfg.FrameReportBuf, 2048);136136- NdisZeroMemory(pAd->StaCfg.BssReportOffset, sizeof(USHORT) * MAX_LEN_OF_BSS_TABLE);137137- NdisZeroMemory(pAd->StaCfg.MeasurementRequest, sizeof(RM_REQUEST_ACTION) * 4);138138-139139- // 7. Point to the start of first element report element140140- pAd->StaCfg.FrameReportLen = LENGTH_802_11 + sizeof(AIRONET_IAPP_HEADER);141141- DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));142142- pAd->StaCfg.LastBssIndex = 0xff;143143- pAd->StaCfg.RMReqCnt = 0;144144- pAd->StaCfg.ParallelReq = FALSE;145145- pAd->StaCfg.ParallelDuration = 0;146146- pAd->StaCfg.ParallelChannel = 0;147147- pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;148148- pAd->StaCfg.CurrentRMReqIdx = 0;149149- pAd->StaCfg.CLBusyBytes = 0;150150- // Reset the statistics151151- for (i = 0; i < 8; i++)152152- pAd->StaCfg.RPIDensity[i] = 0;153153-154154- Index = 0;155155-156156- // 8. Save dialog token for report157157- pAd->StaCfg.IAPPToken = pRMReq->IAPP.Token;158158-159159- // Save Activation delay & measurement offset, Not really needed160160-161161- // 9. Point to the first request element162162- pData += sizeof(AIRONET_RM_REQUEST_FRAME);163163- // Length should exclude the CISCO Aironet SNAP header164164- Length -= (sizeof(AIRONET_RM_REQUEST_FRAME) - LENGTH_802_1_H);165165-166166- // 10. Start Parsing the Measurement elements.167167- // Be careful about multiple MR elements within one frames.168168- while (Length > 0)169169- {170170- pReqElem = (PRM_REQUEST_ACTION) pData;171171- switch (pReqElem->ReqElem.Eid)172172- {173173- case IE_MEASUREMENT_REQUEST:174174- // From the example, it seems we only need to support one request in one frame175175- // There is no multiple request in one frame.176176- // Besides, looks like we need to take care the measurement request only.177177- // The measurement request is always 4 bytes.178178-179179- // Start parsing this type of request.180180- // 0. Eid is IE_MEASUREMENT_REQUEST181181- // 1. Length didn't include Eid and Length field, it always be 8.182182- // 2. Measurement Token, we nned to save it for the corresponding report.183183- // 3. Measurement Mode, Although there are definitions, but we din't see value other than184184- // 0 from test specs examples.185185- // 4. Measurement Type, this is what we need to do.186186- switch (pReqElem->ReqElem.Type)187187- {188188- case MSRN_TYPE_CHANNEL_LOAD_REQ:189189- case MSRN_TYPE_NOISE_HIST_REQ:190190- case MSRN_TYPE_BEACON_REQ:191191- // Check the Enable non-serving channel measurement control192192- if (pAd->StaCfg.CCXControl.field.DCRMEnable == 0)193193- {194194- // Check channel before enqueue the action195195- if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)196196- break;197197- }198198- else199199- {200200- // If off channel measurement, check the TU duration limit201201- if (pReqElem->Measurement.Channel != pAd->CommonCfg.Channel)202202- if (pReqElem->Measurement.Duration > pAd->StaCfg.CCXControl.field.TuLimit)203203- break;204204- }205205-206206- // Save requests and execute actions later207207- NdisMoveMemory(&pAd->StaCfg.MeasurementRequest[Index], pReqElem, sizeof(RM_REQUEST_ACTION));208208- Index += 1;209209- break;210210-211211- case MSRN_TYPE_FRAME_REQ:212212- // Since it's option, we will support later213213- // FrameRequestAction(pAd, pData);214214- break;215215-216216- default:217217- break;218218- }219219-220220- // Point to next Measurement request221221- pData += sizeof(RM_REQUEST_ACTION);222222- Length -= sizeof(RM_REQUEST_ACTION);223223- break;224224-225225- // We accept request only, all others are dropped226226- case IE_MEASUREMENT_REPORT:227227- case IE_AP_TX_POWER:228228- case IE_MEASUREMENT_CAPABILITY:229229- default:230230- return;231231- }232232- }233233-234234- // 11. Update some flags and index235235- pAd->StaCfg.RMReqCnt = Index;236236-237237- if (Index)238238- {239239- MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);240240- RT28XX_MLME_HANDLER(pAd);241241- }242242-243243- DBGPRINT(RT_DEBUG_TRACE, ("<----- AironetMsgAction\n"));244244-}245245-246246-/*247247- ========================================================================248248-249249- Routine Description:250250-251251- Arguments:252252-253253- Return Value:254254- None255255-256256- Note:257257-258258- ========================================================================259259-*/260260-VOID AironetRequestAction(261261- IN PRTMP_ADAPTER pAd,262262- IN MLME_QUEUE_ELEM *Elem)263263-{264264- PRM_REQUEST_ACTION pReq;265265-266266- // 1. Point to next request element267267- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];268268-269269- // 2. Parse measurement type and call appropriate functions270270- if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)271271- // Channel Load measurement request272272- ChannelLoadRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);273273- else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)274274- // Noise Histogram measurement request275275- NoiseHistRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);276276- else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)277277- // Beacon measurement request278278- BeaconRequestAction(pAd, pAd->StaCfg.CurrentRMReqIdx);279279- else280280- // Unknown. Do nothing and return, this should never happen281281- return;282282-283283- // 3. Peek into the next request, if it's parallel, we will update the scan time to the largest one284284- if ((pAd->StaCfg.CurrentRMReqIdx + 1) < pAd->StaCfg.RMReqCnt)285285- {286286- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx + 1];287287- // Check for parallel bit288288- if ((pReq->ReqElem.Mode & 0x01) && (pReq->Measurement.Channel == pAd->StaCfg.CCXScanChannel))289289- {290290- // Update parallel mode request information291291- pAd->StaCfg.ParallelReq = TRUE;292292- pAd->StaCfg.CCXScanTime = ((pReq->Measurement.Duration > pAd->StaCfg.CCXScanTime) ?293293- (pReq->Measurement.Duration) : (pAd->StaCfg.CCXScanTime));294294- }295295- }296296-297297- // 4. Call RT28XX_MLME_HANDLER to execute the request mlme commands, Scan request is the only one used298298- RT28XX_MLME_HANDLER(pAd);299299-300300-}301301-302302-303303-/*304304- ========================================================================305305-306306- Routine Description:307307- Prepare channel load report action, special scan operation added308308- to support309309-310310- Arguments:311311- pAd Pointer to our adapter312312- pData Start from element ID313313-314314- Return Value:315315- None316316-317317- Note:318318-319319- ========================================================================320320-*/321321-VOID ChannelLoadRequestAction(322322- IN PRTMP_ADAPTER pAd,323323- IN UCHAR Index)324324-{325325- PRM_REQUEST_ACTION pReq;326326- MLME_SCAN_REQ_STRUCT ScanReq;327327- UCHAR ZeroSsid[32];328328- NDIS_STATUS NStatus;329329- PUCHAR pOutBuffer = NULL;330330- PHEADER_802_11 pNullFrame;331331-332332- DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction ----->\n"));333333-334334- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];335335- NdisZeroMemory(ZeroSsid, 32);336336-337337- // Prepare for special scan request338338- // The scan definition is different with our Active, Passive scan definition.339339- // For CCX2, Active means send out probe request with broadcast BSSID.340340- // Passive means no probe request sent, only listen to the beacons.341341- // The channel scanned is fixed as specified, no need to scan all channels.342342- // The scan wait time is specified in the request too.343343- // Passive scan Mode344344-345345- // Control state machine is not idle, reject the request346346- if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))347347- return;348348-349349- // Fill out stuff for scan request350350- ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_CHANNEL_LOAD);351351- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);352352- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;353353-354354- // Reset some internal control flags to make sure this scan works.355355- BssTableInit(&pAd->StaCfg.CCXBssTab);356356- pAd->StaCfg.ScanCnt = 0;357357- pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;358358- pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;359359-360360- DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));361361-362362- // If it's non serving channel scan, send out a null frame with PSM bit on.363363- if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)364364- {365365- // Use MLME enqueue method366366- NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory367367- if (NStatus != NDIS_STATUS_SUCCESS)368368- return;369369-370370- pNullFrame = (PHEADER_802_11) pOutBuffer;;371371- // Make the power save Null frame with PSM bit on372372- MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);373373- pNullFrame->Duration = 0;374374- pNullFrame->FC.Type = BTYPE_DATA;375375- pNullFrame->FC.PwrMgmt = PWR_SAVE;376376-377377- // Send using priority queue378378- MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));379379- MlmeFreeMemory(pAd, pOutBuffer);380380- DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));381381- RTMPusecDelay(5000);382382- }383383-384384- pAd->StaCfg.CCXReqType = MSRN_TYPE_CHANNEL_LOAD_REQ;385385- pAd->StaCfg.CLBusyBytes = 0;386386- // Enable Rx with promiscuous reception387387- RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);388388-389389- // Set channel load measurement flag390390- RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);391391-392392- pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;393393-394394- DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadRequestAction <-----\n"));395395-}396396-397397-/*398398- ========================================================================399399-400400- Routine Description:401401- Prepare noise histogram report action, special scan operation added402402- to support403403-404404- Arguments:405405- pAd Pointer to our adapter406406- pData Start from element ID407407-408408- Return Value:409409- None410410-411411- Note:412412-413413- ========================================================================414414-*/415415-VOID NoiseHistRequestAction(416416- IN PRTMP_ADAPTER pAd,417417- IN UCHAR Index)418418-{419419- PRM_REQUEST_ACTION pReq;420420- MLME_SCAN_REQ_STRUCT ScanReq;421421- UCHAR ZeroSsid[32], i;422422- NDIS_STATUS NStatus;423423- PUCHAR pOutBuffer = NULL;424424- PHEADER_802_11 pNullFrame;425425-426426- DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction ----->\n"));427427-428428- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];429429- NdisZeroMemory(ZeroSsid, 32);430430-431431- // Prepare for special scan request432432- // The scan definition is different with our Active, Passive scan definition.433433- // For CCX2, Active means send out probe request with broadcast BSSID.434434- // Passive means no probe request sent, only listen to the beacons.435435- // The channel scanned is fixed as specified, no need to scan all channels.436436- // The scan wait time is specified in the request too.437437- // Passive scan Mode438438-439439- // Control state machine is not idle, reject the request440440- if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))441441- return;442442-443443- // Fill out stuff for scan request444444- ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_NOISE);445445- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);446446- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;447447-448448- // Reset some internal control flags to make sure this scan works.449449- BssTableInit(&pAd->StaCfg.CCXBssTab);450450- pAd->StaCfg.ScanCnt = 0;451451- pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;452452- pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;453453- pAd->StaCfg.CCXReqType = MSRN_TYPE_NOISE_HIST_REQ;454454-455455- DBGPRINT(RT_DEBUG_TRACE, ("Duration %d, Channel %d!\n", pReq->Measurement.Duration, pReq->Measurement.Channel));456456-457457- // If it's non serving channel scan, send out a null frame with PSM bit on.458458- if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)459459- {460460- // Use MLME enqueue method461461- NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory462462- if (NStatus != NDIS_STATUS_SUCCESS)463463- return;464464-465465- pNullFrame = (PHEADER_802_11) pOutBuffer;466466- // Make the power save Null frame with PSM bit on467467- MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);468468- pNullFrame->Duration = 0;469469- pNullFrame->FC.Type = BTYPE_DATA;470470- pNullFrame->FC.PwrMgmt = PWR_SAVE;471471-472472- // Send using priority queue473473- MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));474474- MlmeFreeMemory(pAd, pOutBuffer);475475- DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));476476- RTMPusecDelay(5000);477477- }478478-479479- // Reset the statistics480480- for (i = 0; i < 8; i++)481481- pAd->StaCfg.RPIDensity[i] = 0;482482-483483- // Enable Rx with promiscuous reception484484- RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, 0x1010);485485-486486- // Set channel load measurement flag487487- RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);488488-489489- pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;490490-491491- DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistRequestAction <-----\n"));492492-}493493-494494-/*495495- ========================================================================496496-497497- Routine Description:498498- Prepare Beacon report action, special scan operation added499499- to support500500-501501- Arguments:502502- pAd Pointer to our adapter503503- pData Start from element ID504504-505505- Return Value:506506- None507507-508508- Note:509509-510510- ========================================================================511511-*/512512-VOID BeaconRequestAction(513513- IN PRTMP_ADAPTER pAd,514514- IN UCHAR Index)515515-{516516- PRM_REQUEST_ACTION pReq;517517- NDIS_STATUS NStatus;518518- PUCHAR pOutBuffer = NULL;519519- PHEADER_802_11 pNullFrame;520520- MLME_SCAN_REQ_STRUCT ScanReq;521521- UCHAR ZeroSsid[32];522522-523523- DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction ----->\n"));524524-525525- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[Index];526526- NdisZeroMemory(ZeroSsid, 32);527527-528528- // Prepare for special scan request529529- // The scan definition is different with our Active, Passive scan definition.530530- // For CCX2, Active means send out probe request with broadcast BSSID.531531- // Passive means no probe request sent, only listen to the beacons.532532- // The channel scanned is fixed as specified, no need to scan all channels.533533- // The scan wait time is specified in the request too.534534- if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_PASSIVE)535535- {536536- // Passive scan Mode537537- DBGPRINT(RT_DEBUG_TRACE, ("Passive Scan Mode!\n"));538538-539539- // Control state machine is not idle, reject the request540540- if ((pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (Index == 0))541541- return;542542-543543- // Fill out stuff for scan request544544- ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_PASSIVE);545545- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);546546- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;547547-548548- // Reset some internal control flags to make sure this scan works.549549- BssTableInit(&pAd->StaCfg.CCXBssTab);550550- pAd->StaCfg.ScanCnt = 0;551551- pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;552552- pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;553553- pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;554554- DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));555555-556556- // If it's non serving channel scan, send out a null frame with PSM bit on.557557- if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)558558- {559559- // Use MLME enqueue method560560- NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory561561- if (NStatus != NDIS_STATUS_SUCCESS)562562- return;563563-564564- pNullFrame = (PHEADER_802_11) pOutBuffer;565565- // Make the power save Null frame with PSM bit on566566- MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);567567- pNullFrame->Duration = 0;568568- pNullFrame->FC.Type = BTYPE_DATA;569569- pNullFrame->FC.PwrMgmt = PWR_SAVE;570570-571571- // Send using priority queue572572- MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));573573- MlmeFreeMemory(pAd, pOutBuffer);574574- DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));575575- RTMPusecDelay(5000);576576- }577577-578578- pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;579579- }580580- else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_ACTIVE)581581- {582582- // Active scan Mode583583- DBGPRINT(RT_DEBUG_TRACE, ("Active Scan Mode!\n"));584584-585585- // Control state machine is not idle, reject the request586586- if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)587587- return;588588-589589- // Fill out stuff for scan request590590- ScanParmFill(pAd, &ScanReq, ZeroSsid, 0, BSS_ANY, SCAN_CISCO_ACTIVE);591591- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);592592- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;593593-594594- // Reset some internal control flags to make sure this scan works.595595- BssTableInit(&pAd->StaCfg.CCXBssTab);596596- pAd->StaCfg.ScanCnt = 0;597597- pAd->StaCfg.CCXScanChannel = pReq->Measurement.Channel;598598- pAd->StaCfg.CCXScanTime = pReq->Measurement.Duration;599599- pAd->StaCfg.CCXReqType = MSRN_TYPE_BEACON_REQ;600600- DBGPRINT(RT_DEBUG_TRACE, ("Duration %d!\n", pReq->Measurement.Duration));601601-602602- // If it's non serving channel scan, send out a null frame with PSM bit on.603603- if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)604604- {605605- // Use MLME enqueue method606606- NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory607607- if (NStatus != NDIS_STATUS_SUCCESS)608608- return;609609-610610- pNullFrame = (PHEADER_802_11) pOutBuffer;611611- // Make the power save Null frame with PSM bit on612612- MgtMacHeaderInit(pAd, pNullFrame, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);613613- pNullFrame->Duration = 0;614614- pNullFrame->FC.Type = BTYPE_DATA;615615- pNullFrame->FC.PwrMgmt = PWR_SAVE;616616-617617- // Send using priority queue618618- MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));619619- MlmeFreeMemory(pAd, pOutBuffer);620620- DBGPRINT(RT_DEBUG_TRACE, ("Send PSM Data frame for off channel RM\n"));621621- RTMPusecDelay(5000);622622- }623623-624624- pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;625625- }626626- else if (pReq->Measurement.ScanMode == MSRN_SCAN_MODE_BEACON_TABLE)627627- {628628- // Beacon report Mode, report all the APS in current bss table629629- DBGPRINT(RT_DEBUG_TRACE, ("Beacon Report Mode!\n"));630630-631631- // Copy current BSS table to CCX table, we can omit this step later on.632632- NdisMoveMemory(&pAd->StaCfg.CCXBssTab, &pAd->ScanTab, sizeof(BSS_TABLE));633633-634634- // Create beacon report from Bss table635635- AironetCreateBeaconReportFromBssTable(pAd);636636-637637- // Set state to scanning638638- pAd->Mlme.AironetMachine.CurrState = AIRONET_SCANNING;639639-640640- // Enqueue report request641641- // Cisco scan request is finished, prepare beacon report642642- MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);643643- }644644- else645645- {646646- // Wrong scan Mode647647- DBGPRINT(RT_DEBUG_TRACE, ("Wrong Scan Mode!\n"));648648- }649649-650650- DBGPRINT(RT_DEBUG_TRACE, ("BeaconRequestAction <-----\n"));651651-}652652-653653-/*654654- ========================================================================655655-656656- Routine Description:657657-658658- Arguments:659659-660660- Return Value:661661- None662662-663663- Note:664664-665665- ========================================================================666666-*/667667-VOID AironetReportAction(668668- IN PRTMP_ADAPTER pAd,669669- IN MLME_QUEUE_ELEM *Elem)670670-{671671- PRM_REQUEST_ACTION pReq;672672- ULONG Now32;673673-674674- NdisGetSystemUpTime(&Now32);675675- pAd->StaCfg.LastBeaconRxTime = Now32;676676-677677- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];678678-679679- DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction ----->\n"));680680-681681- // 1. Parse measurement type and call appropriate functions682682- if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)683683- // Channel Load measurement request684684- ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);685685- else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)686686- // Noise Histogram measurement request687687- NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);688688- else if (pReq->ReqElem.Type == MSRN_TYPE_BEACON_REQ)689689- // Beacon measurement request690690- BeaconReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);691691- else692692- // Unknown. Do nothing and return693693- ;694694-695695- // 2. Point to the correct index of action element, start from 0696696- pAd->StaCfg.CurrentRMReqIdx++;697697-698698- // 3. Check for parallel actions699699- if (pAd->StaCfg.ParallelReq == TRUE)700700- {701701- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];702702-703703- // Process next action right away704704- if (pReq->ReqElem.Type == MSRN_TYPE_CHANNEL_LOAD_REQ)705705- // Channel Load measurement request706706- ChannelLoadReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);707707- else if (pReq->ReqElem.Type == MSRN_TYPE_NOISE_HIST_REQ)708708- // Noise Histogram measurement request709709- NoiseHistReportAction(pAd, pAd->StaCfg.CurrentRMReqIdx);710710-711711- pAd->StaCfg.ParallelReq = FALSE;712712- pAd->StaCfg.CurrentRMReqIdx++;713713- }714714-715715- if (pAd->StaCfg.CurrentRMReqIdx >= pAd->StaCfg.RMReqCnt)716716- {717717- // 4. There is no more unprocessed measurement request, go for transmit this report718718- AironetFinalReportAction(pAd);719719- pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;720720- }721721- else722722- {723723- pReq = (PRM_REQUEST_ACTION) &pAd->StaCfg.MeasurementRequest[pAd->StaCfg.CurrentRMReqIdx];724724-725725- if (pReq->Measurement.Channel != pAd->CommonCfg.Channel)726726- {727727- RTMPusecDelay(100000);728728- }729729-730730- // 5. There are more requests to be measure731731- MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_REQ, 0, NULL);732732- RT28XX_MLME_HANDLER(pAd);733733- }734734-735735- DBGPRINT(RT_DEBUG_TRACE, ("AironetReportAction <-----\n"));736736-}737737-738738-/*739739- ========================================================================740740-741741- Routine Description:742742-743743- Arguments:744744-745745- Return Value:746746- None747747-748748- Note:749749-750750- ========================================================================751751-*/752752-VOID AironetFinalReportAction(753753- IN PRTMP_ADAPTER pAd)754754-{755755- PUCHAR pDest;756756- PAIRONET_IAPP_HEADER pIAPP;757757- PHEADER_802_11 pHeader;758758- UCHAR AckRate = RATE_2;759759- USHORT AckDuration = 0;760760- NDIS_STATUS NStatus;761761- PUCHAR pOutBuffer = NULL;762762- ULONG FrameLen = 0;763763-764764- DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction ----->\n"));765765-766766- // 0. Set up the frame pointer, Frame was inited at the end of message action767767- pDest = &pAd->StaCfg.FrameReportBuf[LENGTH_802_11];768768-769769- // 1. Update report IAPP fields770770- pIAPP = (PAIRONET_IAPP_HEADER) pDest;771771-772772- // 2. Copy Cisco SNAP header773773- NdisMoveMemory(pIAPP->CiscoSnapHeader, SNAP_AIRONET, LENGTH_802_1_H);774774-775775- // 3. network order for this 16bit length776776- pIAPP->Length = cpu2be16(pAd->StaCfg.FrameReportLen - LENGTH_802_11 - LENGTH_802_1_H);777777-778778- // 3.1 sanity check the report length, ignore it if there is nothing to report779779- if (be2cpu16(pIAPP->Length) <= 18)780780- return;781781-782782- // 4. Type must be 0x32783783- pIAPP->Type = AIRONET_IAPP_TYPE;784784-785785- // 5. SubType for report must be 0x81786786- pIAPP->SubType = AIRONET_IAPP_SUBTYPE_REPORT;787787-788788- // 6. DA is not used and must be zero, although the whole frame was cleared at the start of function789789- // We will do it again here. We can use BSSID instead790790- COPY_MAC_ADDR(pIAPP->DA, pAd->CommonCfg.Bssid);791791-792792- // 7. SA is the client reporting which must be our MAC793793- COPY_MAC_ADDR(pIAPP->SA, pAd->CurrentAddress);794794-795795- // 8. Copy the saved dialog token796796- pIAPP->Token = pAd->StaCfg.IAPPToken;797797-798798- // 9. Make the Report frame 802.11 header799799- // Reuse function in wpa.c800800- pHeader = (PHEADER_802_11) pAd->StaCfg.FrameReportBuf;801801- pAd->Sequence ++;802802- WpaMacHeaderInit(pAd, pHeader, 0, pAd->CommonCfg.Bssid);803803-804804- // ACK size is 14 include CRC, and its rate is based on real time information805805- AckRate = pAd->CommonCfg.ExpectedACKRate[pAd->CommonCfg.MlmeRate];806806- AckDuration = RTMPCalcDuration(pAd, AckRate, 14);807807- pHeader->Duration = pAd->CommonCfg.Dsifs + AckDuration;808808-809809- // Use MLME enqueue method810810- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory811811- if (NStatus != NDIS_STATUS_SUCCESS)812812- return;813813-814814- // 10. Prepare report frame with dynamic outbuffer. Just simply copy everything.815815- MakeOutgoingFrame(pOutBuffer, &FrameLen,816816- pAd->StaCfg.FrameReportLen, pAd->StaCfg.FrameReportBuf,817817- END_OF_ARGS);818818-819819- // 11. Send using priority queue820820- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);821821- MlmeFreeMemory(pAd, pOutBuffer);822822-823823- pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED;824824-825825- DBGPRINT(RT_DEBUG_TRACE, ("AironetFinalReportAction <-----\n"));826826-}827827-828828-/*829829- ========================================================================830830-831831- Routine Description:832832-833833- Arguments:834834-835835- Return Value:836836- None837837-838838- Note:839839-840840- ========================================================================841841-*/842842-VOID ChannelLoadReportAction(843843- IN PRTMP_ADAPTER pAd,844844- IN UCHAR Index)845845-{846846- PMEASUREMENT_REPORT_ELEMENT pReport;847847- PCHANNEL_LOAD_REPORT pLoad;848848- PUCHAR pDest;849849- UCHAR CCABusyFraction;850850-851851- DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction ----->\n"));852852-853853- // Disable Rx with promiscuous reception, make it back to normal854854- RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.855855-856856- // 0. Setup pointer for processing beacon & probe response857857- pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];858858- pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;859859-860860- // 1. Fill Measurement report element field.861861- pReport->Eid = IE_MEASUREMENT_REPORT;862862- // Fixed Length at 9, not include Eid and length fields863863- pReport->Length = 9;864864- pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;865865- pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;866866- pReport->Type = MSRN_TYPE_CHANNEL_LOAD_REQ;867867-868868- // 2. Fill channel report measurement data869869- pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);870870- pLoad = (PCHANNEL_LOAD_REPORT) pDest;871871- pLoad->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;872872- pLoad->Spare = 0;873873- pLoad->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;874874-875875- // 3. Calculate the CCA Busy Fraction876876- // (Bytes + ACK size) * 8 / Tx speed * 255 / 1000 / measurement duration, use 24 us Tx speed877877- // = (Bytes + ACK) / 12 / duration878878- // 9 is the good value for pAd->StaCfg.CLFactor879879- // CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 9 / pLoad->Duration);880880- CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / pAd->StaCfg.CLFactor / pLoad->Duration);881881- if (CCABusyFraction < 10)882882- CCABusyFraction = (UCHAR) (pAd->StaCfg.CLBusyBytes / 3 / pLoad->Duration) + 1;883883-884884- pLoad->CCABusy = CCABusyFraction;885885- DBGPRINT(RT_DEBUG_TRACE, ("CLBusyByte %ld, Duration %d, Result, %d\n", pAd->StaCfg.CLBusyBytes, pLoad->Duration, CCABusyFraction));886886-887887- DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));888888- pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(CHANNEL_LOAD_REPORT));889889- DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen %d\n", pAd->StaCfg.FrameReportLen));890890-891891- // 4. Clear channel load measurement flag892892- RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);893893-894894- // 5. reset to idle state895895- pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;896896-897897- DBGPRINT(RT_DEBUG_TRACE, ("ChannelLoadReportAction <-----\n"));898898-}899899-900900-/*901901- ========================================================================902902-903903- Routine Description:904904-905905- Arguments:906906-907907- Return Value:908908- None909909-910910- Note:911911-912912- ========================================================================913913-*/914914-VOID NoiseHistReportAction(915915- IN PRTMP_ADAPTER pAd,916916- IN UCHAR Index)917917-{918918- PMEASUREMENT_REPORT_ELEMENT pReport;919919- PNOISE_HIST_REPORT pNoise;920920- PUCHAR pDest;921921- UCHAR i,NoiseCnt;922922- USHORT TotalRPICnt, TotalRPISum;923923-924924- DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction ----->\n"));925925-926926- // 0. Disable Rx with promiscuous reception, make it back to normal927927- RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification.928928- // 1. Setup pointer for processing beacon & probe response929929- pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];930930- pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;931931-932932- // 2. Fill Measurement report element field.933933- pReport->Eid = IE_MEASUREMENT_REPORT;934934- // Fixed Length at 16, not include Eid and length fields935935- pReport->Length = 16;936936- pReport->Token = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Token;937937- pReport->Mode = pAd->StaCfg.MeasurementRequest[Index].ReqElem.Mode;938938- pReport->Type = MSRN_TYPE_NOISE_HIST_REQ;939939-940940- // 3. Fill noise histogram report measurement data941941- pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);942942- pNoise = (PNOISE_HIST_REPORT) pDest;943943- pNoise->Channel = pAd->StaCfg.MeasurementRequest[Index].Measurement.Channel;944944- pNoise->Spare = 0;945945- pNoise->Duration = pAd->StaCfg.MeasurementRequest[Index].Measurement.Duration;946946- // 4. Fill Noise histogram, the total RPI counts should be 0.4 * TU947947- // We estimate 4000 normal packets received durning 10 seconds test.948948- // Adjust it if required.949949- // 3 is a good value for pAd->StaCfg.NHFactor950950- // TotalRPICnt = pNoise->Duration * 3 / 10;951951- TotalRPICnt = pNoise->Duration * pAd->StaCfg.NHFactor / 10;952952- TotalRPISum = 0;953953-954954- for (i = 0; i < 8; i++)955955- {956956- TotalRPISum += pAd->StaCfg.RPIDensity[i];957957- DBGPRINT(RT_DEBUG_TRACE, ("RPI %d Conuts %d\n", i, pAd->StaCfg.RPIDensity[i]));958958- }959959-960960- // Double check if the counter is larger than our expectation.961961- // We will replace it with the total number plus a fraction.962962- if (TotalRPISum > TotalRPICnt)963963- TotalRPICnt = TotalRPISum + pNoise->Duration / 20;964964-965965- DBGPRINT(RT_DEBUG_TRACE, ("Total RPI Conuts %d\n", TotalRPICnt));966966-967967- // 5. Initialize noise count for the total summation of 0xff968968- NoiseCnt = 0;969969- for (i = 1; i < 8; i++)970970- {971971- pNoise->Density[i] = (UCHAR) (pAd->StaCfg.RPIDensity[i] * 255 / TotalRPICnt);972972- if ((pNoise->Density[i] == 0) && (pAd->StaCfg.RPIDensity[i] != 0))973973- pNoise->Density[i]++;974974- NoiseCnt += pNoise->Density[i];975975- DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[%d] = 0x%02x\n", i, pNoise->Density[i]));976976- }977977-978978- // 6. RPI[0] represents the rest of counts979979- pNoise->Density[0] = 0xff - NoiseCnt;980980- DBGPRINT(RT_DEBUG_TRACE, ("Reported RPI[0] = 0x%02x\n", pNoise->Density[0]));981981-982982- pAd->StaCfg.FrameReportLen += (sizeof(MEASUREMENT_REPORT_ELEMENT) + sizeof(NOISE_HIST_REPORT));983983-984984- // 7. Clear channel load measurement flag985985- RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT);986986-987987- // 8. reset to idle state988988- pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;989989-990990- DBGPRINT(RT_DEBUG_TRACE, ("NoiseHistReportAction <-----\n"));991991-}992992-993993-/*994994- ========================================================================995995-996996- Routine Description:997997- Prepare Beacon report action,998998-999999- Arguments:10001000- pAd Pointer to our adapter10011001-10021002- Return Value:10031003- None10041004-10051005- Note:10061006-10071007- ========================================================================10081008-*/10091009-VOID BeaconReportAction(10101010- IN PRTMP_ADAPTER pAd,10111011- IN UCHAR Index)10121012-{10131013- DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction ----->\n"));10141014-10151015- // Looks like we don't have anything thing need to do here.10161016- // All measurement report already finished in AddBeaconReport10171017- // The length is in the FrameReportLen10181018-10191019- // reset Beacon index for next beacon request10201020- pAd->StaCfg.LastBssIndex = 0xff;10211021-10221022- // reset to idle state10231023- pAd->Mlme.AironetMachine.CurrState = AIRONET_IDLE;10241024-10251025- DBGPRINT(RT_DEBUG_TRACE, ("BeaconReportAction <-----\n"));10261026-}10271027-10281028-/*10291029- ========================================================================10301030-10311031- Routine Description:10321032-10331033- Arguments:10341034- Index Current BSSID in CCXBsstab entry index10351035-10361036- Return Value:10371037-10381038- Note:10391039-10401040- ========================================================================10411041-*/10421042-VOID AironetAddBeaconReport(10431043- IN PRTMP_ADAPTER pAd,10441044- IN ULONG Index,10451045- IN PMLME_QUEUE_ELEM pElem)10461046-{10471047- PVOID pMsg;10481048- PUCHAR pSrc, pDest;10491049- UCHAR ReqIdx;10501050- ULONG MsgLen;10511051- USHORT Length;10521052- PFRAME_802_11 pFrame;10531053- PMEASUREMENT_REPORT_ELEMENT pReport;10541054- PEID_STRUCT pEid;10551055- PBEACON_REPORT pBeaconReport;10561056- PBSS_ENTRY pBss;10571057-10581058- // 0. Setup pointer for processing beacon & probe response10591059- pMsg = pElem->Msg;10601060- MsgLen = pElem->MsgLen;10611061- pFrame = (PFRAME_802_11) pMsg;10621062- pSrc = pFrame->Octet; // Start from AP TSF10631063- pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];10641064- ReqIdx = pAd->StaCfg.CurrentRMReqIdx;10651065-10661066- // 1 Check the Index, if we already create this entry, only update the average RSSI10671067- if ((Index <= pAd->StaCfg.LastBssIndex) && (pAd->StaCfg.LastBssIndex != 0xff))10681068- {10691069- pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.BssReportOffset[Index]];10701070- // Point to bss report information10711071- pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);10721072- pBeaconReport = (PBEACON_REPORT) pDest;10731073-10741074- // Update Rx power, in dBm10751075- // Get the original RSSI readback from BBP10761076- pBeaconReport->RxPower += pAd->BbpRssiToDbmDelta;10771077- // Average the Rssi reading10781078- pBeaconReport->RxPower = (pBeaconReport->RxPower + pBss->Rssi) / 2;10791079- // Get to dBm format10801080- pBeaconReport->RxPower -= pAd->BbpRssiToDbmDelta;10811081-10821082- DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",10831083- pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],10841084- pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));10851085- DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld] Rssi %d, Avg Rssi %d\n", Index, (pBss->Rssi - pAd->BbpRssiToDbmDelta), pBeaconReport->RxPower - 256));10861086- DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.BssReportOffset[Index]));10871087-10881088- // Update other information here10891089-10901090- // Done10911091- return;10921092- }10931093-10941094- // 2. Update reported Index10951095- pAd->StaCfg.LastBssIndex = Index;10961096-10971097- // 3. Setup the buffer address for copying this BSSID into reporting frame10981098- // The offset should start after 802.11 header and report frame header.10991099- pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];11001100-11011101- // 4. Save the start offset of each Bss in report frame11021102- pAd->StaCfg.BssReportOffset[Index] = pAd->StaCfg.FrameReportLen;11031103-11041104- // 5. Fill Measurement report fields11051105- pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;11061106- pReport->Eid = IE_MEASUREMENT_REPORT;11071107- pReport->Length = 0;11081108- pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;11091109- pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;11101110- pReport->Type = MSRN_TYPE_BEACON_REQ;11111111- Length = sizeof(MEASUREMENT_REPORT_ELEMENT);11121112- pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);11131113-11141114- // 6. Start thebeacon report format11151115- pBeaconReport = (PBEACON_REPORT) pDest;11161116- pDest += sizeof(BEACON_REPORT);11171117- Length += sizeof(BEACON_REPORT);11181118-11191119- // 7. Copy Channel number11201120- pBeaconReport->Channel = pBss->Channel;11211121- pBeaconReport->Spare = 0;11221122- pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;11231123- pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);11241124- // 8. Rx power, in dBm11251125- pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;11261126-11271127- DBGPRINT(RT_DEBUG_TRACE, ("Bssid %02x:%02x:%02x:%02x:%02x:%02x ",11281128- pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2],11291129- pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));11301130- DBGPRINT(RT_DEBUG_TRACE, ("RxPower[%ld], Rssi %d\n", Index, pBeaconReport->RxPower - 256));11311131- DBGPRINT(RT_DEBUG_TRACE, ("FrameReportLen = %d\n", pAd->StaCfg.FrameReportLen));11321132-11331133- pBeaconReport->BeaconInterval = pBss->BeaconPeriod;11341134- COPY_MAC_ADDR(pBeaconReport->BSSID, pFrame->Hdr.Addr3);11351135- NdisMoveMemory(pBeaconReport->ParentTSF, pSrc, 4);11361136- NdisMoveMemory(pBeaconReport->TargetTSF, &pElem->TimeStamp.u.LowPart, 4);11371137- NdisMoveMemory(&pBeaconReport->TargetTSF[4], &pElem->TimeStamp.u.HighPart, 4);11381138-11391139- // 9. Skip the beacon frame and offset to start of capabilityinfo since we already processed capabilityinfo11401140- pSrc += (TIMESTAMP_LEN + 2);11411141- pBeaconReport->CapabilityInfo = *(USHORT *)pSrc;11421142-11431143- // 10. Point to start of element ID11441144- pSrc += 2;11451145- pEid = (PEID_STRUCT) pSrc;11461146-11471147- // 11. Start process all variable Eid oayload and add the appropriate to the frame report11481148- while (((PUCHAR) pEid + pEid->Len + 1) < ((PUCHAR) pFrame + MsgLen))11491149- {11501150- // Only limited EID are required to report for CCX 2. It includes SSID, Supported rate,11511151- // FH paramenter set, DS parameter set, CF parameter set, IBSS parameter set,11521152- // TIM (report first 4 bytes only, radio measurement capability11531153- switch (pEid->Eid)11541154- {11551155- case IE_SSID:11561156- case IE_SUPP_RATES:11571157- case IE_FH_PARM:11581158- case IE_DS_PARM:11591159- case IE_CF_PARM:11601160- case IE_IBSS_PARM:11611161- NdisMoveMemory(pDest, pEid, pEid->Len + 2);11621162- pDest += (pEid->Len + 2);11631163- Length += (pEid->Len + 2);11641164- break;11651165-11661166- case IE_MEASUREMENT_CAPABILITY:11671167- // Since this IE is duplicated with WPA security IE, we has to do sanity check before11681168- // recognize it.11691169- // 1. It also has fixed 6 bytes IE length.11701170- if (pEid->Len != 6)11711171- break;11721172- // 2. Check the Cisco Aironet OUI11731173- if (NdisEqualMemory(CISCO_OUI, (pSrc + 2), 3))11741174- {11751175- // Matched, this is what we want11761176- NdisMoveMemory(pDest, pEid, pEid->Len + 2);11771177- pDest += (pEid->Len + 2);11781178- Length += (pEid->Len + 2);11791179- }11801180- break;11811181-11821182- case IE_TIM:11831183- if (pEid->Len > 4)11841184- {11851185- // May truncate and report the first 4 bytes only, with the eid & len, total should be 611861186- NdisMoveMemory(pDest, pEid, 6);11871187- pDest += 6;11881188- Length += 6;11891189- }11901190- else11911191- {11921192- NdisMoveMemory(pDest, pEid, pEid->Len + 2);11931193- pDest += (pEid->Len + 2);11941194- Length += (pEid->Len + 2);11951195- }11961196- break;11971197-11981198- default:11991199- break;12001200- }12011201- // 12. Move to next element ID12021202- pSrc += (2 + pEid->Len);12031203- pEid = (PEID_STRUCT) pSrc;12041204- }12051205-12061206- // 13. Update the length in the header, not include EID and length12071207- pReport->Length = Length - 4;12081208-12091209- // 14. Update the frame report buffer data length12101210- pAd->StaCfg.FrameReportLen += Length;12111211- DBGPRINT(RT_DEBUG_TRACE, ("FR len = %d\n", pAd->StaCfg.FrameReportLen));12121212-}12131213-12141214-/*12151215- ========================================================================12161216-12171217- Routine Description:12181218-12191219- Arguments:12201220- Index Current BSSID in CCXBsstab entry index12211221-12221222- Return Value:12231223-12241224- Note:12251225-12261226- ========================================================================12271227-*/12281228-VOID AironetCreateBeaconReportFromBssTable(12291229- IN PRTMP_ADAPTER pAd)12301230-{12311231- PMEASUREMENT_REPORT_ELEMENT pReport;12321232- PBEACON_REPORT pBeaconReport;12331233- UCHAR Index, ReqIdx;12341234- USHORT Length;12351235- PUCHAR pDest;12361236- PBSS_ENTRY pBss;12371237-12381238- // 0. setup base pointer12391239- ReqIdx = pAd->StaCfg.CurrentRMReqIdx;12401240-12411241- for (Index = 0; Index < pAd->StaCfg.CCXBssTab.BssNr; Index++)12421242- {12431243- // 1. Setup the buffer address for copying this BSSID into reporting frame12441244- // The offset should start after 802.11 header and report frame header.12451245- pDest = (PUCHAR) &pAd->StaCfg.FrameReportBuf[pAd->StaCfg.FrameReportLen];12461246- pBss = (PBSS_ENTRY) &pAd->StaCfg.CCXBssTab.BssEntry[Index];12471247- Length = 0;12481248-12491249- // 2. Fill Measurement report fields12501250- pReport = (PMEASUREMENT_REPORT_ELEMENT) pDest;12511251- pReport->Eid = IE_MEASUREMENT_REPORT;12521252- pReport->Length = 0;12531253- pReport->Token = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Token;12541254- pReport->Mode = pAd->StaCfg.MeasurementRequest[ReqIdx].ReqElem.Mode;12551255- pReport->Type = MSRN_TYPE_BEACON_REQ;12561256- Length = sizeof(MEASUREMENT_REPORT_ELEMENT);12571257- pDest += sizeof(MEASUREMENT_REPORT_ELEMENT);12581258-12591259- // 3. Start the beacon report format12601260- pBeaconReport = (PBEACON_REPORT) pDest;12611261- pDest += sizeof(BEACON_REPORT);12621262- Length += sizeof(BEACON_REPORT);12631263-12641264- // 4. Copy Channel number12651265- pBeaconReport->Channel = pBss->Channel;12661266- pBeaconReport->Spare = 0;12671267- pBeaconReport->Duration = pAd->StaCfg.MeasurementRequest[ReqIdx].Measurement.Duration;12681268- pBeaconReport->PhyType = ((pBss->SupRateLen+pBss->ExtRateLen > 4) ? PHY_ERP : PHY_DSS);12691269- pBeaconReport->RxPower = pBss->Rssi - pAd->BbpRssiToDbmDelta;12701270- pBeaconReport->BeaconInterval = pBss->BeaconPeriod;12711271- pBeaconReport->CapabilityInfo = pBss->CapabilityInfo;12721272- COPY_MAC_ADDR(pBeaconReport->BSSID, pBss->Bssid);12731273- NdisMoveMemory(pBeaconReport->ParentTSF, pBss->PTSF, 4);12741274- NdisMoveMemory(pBeaconReport->TargetTSF, pBss->TTSF, 8);12751275-12761276- // 5. Create SSID12771277- *pDest++ = 0x00;12781278- *pDest++ = pBss->SsidLen;12791279- NdisMoveMemory(pDest, pBss->Ssid, pBss->SsidLen);12801280- pDest += pBss->SsidLen;12811281- Length += (2 + pBss->SsidLen);12821282-12831283- // 6. Create SupportRates12841284- *pDest++ = 0x01;12851285- *pDest++ = pBss->SupRateLen;12861286- NdisMoveMemory(pDest, pBss->SupRate, pBss->SupRateLen);12871287- pDest += pBss->SupRateLen;12881288- Length += (2 + pBss->SupRateLen);12891289-12901290- // 7. DS Parameter12911291- *pDest++ = 0x03;12921292- *pDest++ = 1;12931293- *pDest++ = pBss->Channel;12941294- Length += 3;12951295-12961296- // 8. IBSS parameter if presents12971297- if (pBss->BssType == BSS_ADHOC)12981298- {12991299- *pDest++ = 0x06;13001300- *pDest++ = 2;13011301- *(PUSHORT) pDest = pBss->AtimWin;13021302- pDest += 2;13031303- Length += 4;13041304- }13051305-13061306- // 9. Update length field, not include EID and length13071307- pReport->Length = Length - 4;13081308-13091309- // 10. Update total frame size13101310- pAd->StaCfg.FrameReportLen += Length;13111311- }13121312-}11+#include "../../rt2870/sta/aironet.c"
+1-1733
drivers/staging/rt3070/sta/assoc.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- assoc.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John 2004-9-3 porting from RT25003636-*/3737-#include "../rt_config.h"3838-3939-UCHAR CipherWpaTemplate[] = {4040- 0xdd, // WPA IE4141- 0x16, // Length4242- 0x00, 0x50, 0xf2, 0x01, // oui4343- 0x01, 0x00, // Version4444- 0x00, 0x50, 0xf2, 0x02, // Multicast4545- 0x01, 0x00, // Number of unicast4646- 0x00, 0x50, 0xf2, 0x02, // unicast4747- 0x01, 0x00, // number of authentication method4848- 0x00, 0x50, 0xf2, 0x01 // authentication4949- };5050-5151-UCHAR CipherWpa2Template[] = {5252- 0x30, // RSN IE5353- 0x14, // Length5454- 0x01, 0x00, // Version5555- 0x00, 0x0f, 0xac, 0x02, // group cipher, TKIP5656- 0x01, 0x00, // number of pairwise5757- 0x00, 0x0f, 0xac, 0x02, // unicast5858- 0x01, 0x00, // number of authentication method5959- 0x00, 0x0f, 0xac, 0x02, // authentication6060- 0x00, 0x00, // RSN capability6161- };6262-6363-UCHAR Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02};6464-6565-/*6666- ==========================================================================6767- Description:6868- association state machine init, including state transition and timer init6969- Parameters:7070- S - pointer to the association state machine7171-7272- IRQL = PASSIVE_LEVEL7373-7474- ==========================================================================7575- */7676-VOID AssocStateMachineInit(7777- IN PRTMP_ADAPTER pAd,7878- IN STATE_MACHINE *S,7979- OUT STATE_MACHINE_FUNC Trans[])8080-{8181- StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, (STATE_MACHINE_FUNC)Drop, ASSOC_IDLE, ASSOC_MACHINE_BASE);8282-8383- // first column8484- StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)MlmeAssocReqAction);8585- StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)MlmeReassocReqAction);8686- StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)MlmeDisassocReqAction);8787- StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);8888-8989- // second column9090- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);9191- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);9292- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);9393- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);9494- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);9595- //9696- // Patch 3Com AP MOde:3CRWE454G729797- // We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp.9898- //9999- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);100100- StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, (STATE_MACHINE_FUNC)AssocTimeoutAction);101101-102102- // third column103103- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);104104- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);105105- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);106106- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);107107- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);108108- //109109- // Patch, AP doesn't send Reassociate Rsp frame to Station.110110- //111111- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);112112- StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, (STATE_MACHINE_FUNC)ReassocTimeoutAction);113113-114114- // fourth column115115- StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);116116- StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);117117- StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);118118- StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);119119- StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, (STATE_MACHINE_FUNC)DisassocTimeoutAction);120120-121121- // initialize the timer122122- RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer, GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);123123- RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer, GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);124124- RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer, GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);125125-}126126-127127-/*128128- ==========================================================================129129- Description:130130- Association timeout procedure. After association timeout, this function131131- will be called and it will put a message into the MLME queue132132- Parameters:133133- Standard timer parameters134134-135135- IRQL = DISPATCH_LEVEL136136-137137- ==========================================================================138138- */139139-VOID AssocTimeout(IN PVOID SystemSpecific1,140140- IN PVOID FunctionContext,141141- IN PVOID SystemSpecific2,142142- IN PVOID SystemSpecific3)143143-{144144- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;145145-146146- // Do nothing if the driver is starting halt state.147147- // This might happen when timer already been fired before cancel timer with mlmehalt148148- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))149149- return;150150-151151- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);152152- RT28XX_MLME_HANDLER(pAd);153153-}154154-155155-/*156156- ==========================================================================157157- Description:158158- Reassociation timeout procedure. After reassociation timeout, this159159- function will be called and put a message into the MLME queue160160- Parameters:161161- Standard timer parameters162162-163163- IRQL = DISPATCH_LEVEL164164-165165- ==========================================================================166166- */167167-VOID ReassocTimeout(IN PVOID SystemSpecific1,168168- IN PVOID FunctionContext,169169- IN PVOID SystemSpecific2,170170- IN PVOID SystemSpecific3)171171-{172172- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;173173-174174- // Do nothing if the driver is starting halt state.175175- // This might happen when timer already been fired before cancel timer with mlmehalt176176- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))177177- return;178178-179179- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);180180- RT28XX_MLME_HANDLER(pAd);181181-}182182-183183-/*184184- ==========================================================================185185- Description:186186- Disassociation timeout procedure. After disassociation timeout, this187187- function will be called and put a message into the MLME queue188188- Parameters:189189- Standard timer parameters190190-191191- IRQL = DISPATCH_LEVEL192192-193193- ==========================================================================194194- */195195-VOID DisassocTimeout(IN PVOID SystemSpecific1,196196- IN PVOID FunctionContext,197197- IN PVOID SystemSpecific2,198198- IN PVOID SystemSpecific3)199199-{200200- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;201201-202202- // Do nothing if the driver is starting halt state.203203- // This might happen when timer already been fired before cancel timer with mlmehalt204204- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))205205- return;206206-207207- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);208208- RT28XX_MLME_HANDLER(pAd);209209-}210210-211211-/*212212- ==========================================================================213213- Description:214214- mlme assoc req handling procedure215215- Parameters:216216- Adapter - Adapter pointer217217- Elem - MLME Queue Element218218- Pre:219219- the station has been authenticated and the following information is stored in the config220220- -# SSID221221- -# supported rates and their length222222- -# listen interval (Adapter->StaCfg.default_listen_count)223223- -# Transmit power (Adapter->StaCfg.tx_power)224224- Post :225225- -# An association request frame is generated and sent to the air226226- -# Association timer starts227227- -# Association state -> ASSOC_WAIT_RSP228228-229229- IRQL = DISPATCH_LEVEL230230-231231- ==========================================================================232232- */233233-VOID MlmeAssocReqAction(234234- IN PRTMP_ADAPTER pAd,235235- IN MLME_QUEUE_ELEM *Elem)236236-{237237- UCHAR ApAddr[6];238238- HEADER_802_11 AssocHdr;239239- UCHAR Ccx2Len = 5;240240- UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};241241- USHORT ListenIntv;242242- ULONG Timeout;243243- USHORT CapabilityInfo;244244- BOOLEAN TimerCancelled;245245- PUCHAR pOutBuffer = NULL;246246- NDIS_STATUS NStatus;247247- ULONG FrameLen = 0;248248- ULONG tmp;249249- USHORT VarIesOffset;250250- UCHAR CkipFlag;251251- UCHAR CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH];252252- UCHAR AironetCkipIe = IE_AIRONET_CKIP;253253- UCHAR AironetCkipLen = CKIP_NEGOTIATION_LENGTH;254254- UCHAR AironetIPAddressIE = IE_AIRONET_IPADDRESS;255255- UCHAR AironetIPAddressLen = AIRONET_IPADDRESS_LENGTH;256256- UCHAR AironetIPAddressBuffer[AIRONET_IPADDRESS_LENGTH] = {0x00, 0x40, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00};257257- USHORT Status;258258-259259- // Block all authentication request durning WPA block period260260- if (pAd->StaCfg.bBlockAssoc == TRUE)261261- {262262- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block Assoc request durning WPA block period!\n"));263263- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;264264- Status = MLME_STATE_MACHINE_REJECT;265265- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);266266- }267267- // check sanity first268268- else if (MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))269269- {270270- RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);271271- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);272272-273273- // Get an unused nonpaged memory274274- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);275275- if (NStatus != NDIS_STATUS_SUCCESS)276276- {277277- DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));278278- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;279279- Status = MLME_FAIL_NO_RESOURCE;280280- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);281281- return;282282- }283283-284284- // Add by James 03/06/27285285- pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);286286- // Association don't need to report MAC address287287- pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =288288- NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_LISTENINTERVAL;289289- pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities = CapabilityInfo;290290- pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval = ListenIntv;291291- // Only reassociate need this292292- //COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr);293293- pAd->StaCfg.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);294294-295295- NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);296296- // First add SSID297297- VarIesOffset = 0;298298- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe, 1);299299- VarIesOffset += 1;300300- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SsidLen, 1);301301- VarIesOffset += 1;302302- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);303303- VarIesOffset += pAd->MlmeAux.SsidLen;304304-305305- // Second add Supported rates306306- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe, 1);307307- VarIesOffset += 1;308308- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SupRateLen, 1);309309- VarIesOffset += 1;310310- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);311311- VarIesOffset += pAd->MlmeAux.SupRateLen;312312- // End Add by James313313-314314- if ((pAd->CommonCfg.Channel > 14) &&315315- (pAd->CommonCfg.bIEEE80211H == TRUE))316316- CapabilityInfo |= 0x0100;317317-318318- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));319319- MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, ApAddr);320320-321321- // Build basic frame first322322- MakeOutgoingFrame(pOutBuffer, &FrameLen,323323- sizeof(HEADER_802_11), &AssocHdr,324324- 2, &CapabilityInfo,325325- 2, &ListenIntv,326326- 1, &SsidIe,327327- 1, &pAd->MlmeAux.SsidLen,328328- pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,329329- 1, &SupRateIe,330330- 1, &pAd->MlmeAux.SupRateLen,331331- pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,332332- END_OF_ARGS);333333-334334- if (pAd->MlmeAux.ExtRateLen != 0)335335- {336336- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,337337- 1, &ExtRateIe,338338- 1, &pAd->MlmeAux.ExtRateLen,339339- pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,340340- END_OF_ARGS);341341- FrameLen += tmp;342342- }343343-344344- // HT345345- if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))346346- {347347- ULONG TmpLen;348348- UCHAR HtLen;349349- UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};350350- if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)351351- {352352- HtLen = SIZE_HT_CAP_IE + 4;353353- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,354354- 1, &WpaIe,355355- 1, &HtLen,356356- 4, &BROADCOM[0],357357- pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,358358- END_OF_ARGS);359359- }360360- else361361- {362362- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,363363- 1, &HtCapIe,364364- 1, &pAd->MlmeAux.HtCapabilityLen,365365- pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,366366- END_OF_ARGS);367367- }368368- FrameLen += TmpLen;369369- }370370-371371- // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION372372- // Case I: (Aggregation + Piggy-Back)373373- // 1. user enable aggregation, AND374374- // 2. Mac support piggy-back375375- // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON376376- // Case II: (Aggregation)377377- // 1. user enable aggregation, AND378378- // 2. AP annouces it's AGGREGATION-capable in BEACON379379- if (pAd->CommonCfg.bAggregationCapable)380380- {381381- if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))382382- {383383- ULONG TmpLen;384384- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};385385- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,386386- 9, RalinkIe,387387- END_OF_ARGS);388388- FrameLen += TmpLen;389389- }390390- else if (pAd->MlmeAux.APRalinkIe & 0x00000001)391391- {392392- ULONG TmpLen;393393- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};394394- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,395395- 9, RalinkIe,396396- END_OF_ARGS);397397- FrameLen += TmpLen;398398- }399399- }400400- else401401- {402402- ULONG TmpLen;403403- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06, 0x00, 0x00, 0x00};404404- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,405405- 9, RalinkIe,406406- END_OF_ARGS);407407- FrameLen += TmpLen;408408- }409409-410410- if (pAd->MlmeAux.APEdcaParm.bValid)411411- {412412- if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)413413- {414414- QBSS_STA_INFO_PARM QosInfo;415415-416416- NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));417417- QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;418418- QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;419419- QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;420420- QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;421421- QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;422422- WmeIe[8] |= *(PUCHAR)&QosInfo;423423- }424424- else425425- {426426- // The Parameter Set Count is set to ��0�� in the association request frames427427- // WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f);428428- }429429-430430- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,431431- 9, &WmeIe[0],432432- END_OF_ARGS);433433- FrameLen += tmp;434434- }435435-436436- //437437- // Let WPA(#221) Element ID on the end of this association frame.438438- // Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp.439439- // For example: Put Vendor Specific IE on the front of WPA IE.440440- // This happens on AP (Model No:Linksys WRK54G)441441- //442442- if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||443443- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||444444- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||445445- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)446446- )447447- )448448- {449449- UCHAR RSNIe = IE_WPA;450450-451451- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||452452- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))453453- {454454- RSNIe = IE_WPA2;455455- }456456-457457-#ifdef SIOCSIWGENIE458458- if (pAd->StaCfg.WpaSupplicantUP != 1)459459-#endif // SIOCSIWGENIE //460460- RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);461461-462462- // Check for WPA PMK cache list463463- if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)464464- {465465- INT idx;466466- BOOLEAN FoundPMK = FALSE;467467- // Search chched PMKID, append it if existed468468- for (idx = 0; idx < PMKID_NO; idx++)469469- {470470- if (NdisEqualMemory(ApAddr, &pAd->StaCfg.SavedPMK[idx].BSSID, 6))471471- {472472- FoundPMK = TRUE;473473- break;474474- }475475- }476476-477477- if (FoundPMK)478478- {479479- // Set PMK number480480- *(PUSHORT) &pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len] = 1;481481- NdisMoveMemory(&pAd->StaCfg.RSN_IE[pAd->StaCfg.RSNIE_Len + 2], &pAd->StaCfg.SavedPMK[idx].PMKID, 16);482482- pAd->StaCfg.RSNIE_Len += 18;483483- }484484- }485485-486486-#ifdef SIOCSIWGENIE487487- if (pAd->StaCfg.WpaSupplicantUP == 1)488488- {489489- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,490490- pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,491491- END_OF_ARGS);492492- }493493- else494494-#endif495495- {496496- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,497497- 1, &RSNIe,498498- 1, &pAd->StaCfg.RSNIE_Len,499499- pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,500500- END_OF_ARGS);501501- }502502-503503- FrameLen += tmp;504504-505505-#ifdef SIOCSIWGENIE506506- if (pAd->StaCfg.WpaSupplicantUP != 1)507507-#endif508508- {509509- // Append Variable IE510510- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &RSNIe, 1);511511- VarIesOffset += 1;512512- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->StaCfg.RSNIE_Len, 1);513513- VarIesOffset += 1;514514- }515515- NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);516516- VarIesOffset += pAd->StaCfg.RSNIE_Len;517517-518518- // Set Variable IEs Length519519- pAd->StaCfg.ReqVarIELen = VarIesOffset;520520- }521521-522522- // We have update that at PeerBeaconAtJoinRequest()523523- CkipFlag = pAd->StaCfg.CkipFlag;524524- if (CkipFlag != 0)525525- {526526- NdisZeroMemory(CkipNegotiationBuffer, CKIP_NEGOTIATION_LENGTH);527527- CkipNegotiationBuffer[2] = 0x66;528528- // Make it try KP & MIC, since we have to follow the result from AssocRsp529529- CkipNegotiationBuffer[8] = 0x18;530530- CkipNegotiationBuffer[CKIP_NEGOTIATION_LENGTH - 1] = 0x22;531531- CkipFlag = 0x18;532532-533533- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,534534- 1, &AironetCkipIe,535535- 1, &AironetCkipLen,536536- AironetCkipLen, CkipNegotiationBuffer,537537- END_OF_ARGS);538538- FrameLen += tmp;539539- }540540-541541- // Add CCX v2 request if CCX2 admin state is on542542- if (pAd->StaCfg.CCXControl.field.Enable == 1)543543- {544544-545545- //546546- // Add AironetIPAddressIE for Cisco CCX 2.X547547- // Add CCX Version548548- //549549- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,550550- 1, &AironetIPAddressIE,551551- 1, &AironetIPAddressLen,552552- AironetIPAddressLen, AironetIPAddressBuffer,553553- 1, &Ccx2Ie,554554- 1, &Ccx2Len,555555- Ccx2Len, Ccx2IeInfo,556556- END_OF_ARGS);557557- FrameLen += tmp;558558-559559- // Add by James 03/06/27560560- // Set Variable IEs Length561561- pAd->StaCfg.ReqVarIELen = VarIesOffset;562562- pAd->StaCfg.AssocInfo.RequestIELength = VarIesOffset;563563-564564- // OffsetResponseIEs follow ReqVarIE565565- pAd->StaCfg.AssocInfo.OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAd->StaCfg.ReqVarIELen;566566- // End Add by James567567- }568568-569569-570570- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);571571- MlmeFreeMemory(pAd, pOutBuffer);572572-573573- RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout);574574- pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;575575- }576576- else577577- {578578- DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!!!!!! \n"));579579- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;580580- Status = MLME_INVALID_FORMAT;581581- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);582582- }583583-584584-}585585-586586-/*587587- ==========================================================================588588- Description:589589- mlme reassoc req handling procedure590590- Parameters:591591- Elem -592592- Pre:593593- -# SSID (Adapter->StaCfg.ssid[])594594- -# BSSID (AP address, Adapter->StaCfg.bssid)595595- -# Supported rates (Adapter->StaCfg.supported_rates[])596596- -# Supported rates length (Adapter->StaCfg.supported_rates_len)597597- -# Tx power (Adapter->StaCfg.tx_power)598598-599599- IRQL = DISPATCH_LEVEL600600-601601- ==========================================================================602602- */603603-VOID MlmeReassocReqAction(604604- IN PRTMP_ADAPTER pAd,605605- IN MLME_QUEUE_ELEM *Elem)606606-{607607- UCHAR ApAddr[6];608608- HEADER_802_11 ReassocHdr;609609- UCHAR Ccx2Len = 5;610610- UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};611611- USHORT CapabilityInfo, ListenIntv;612612- ULONG Timeout;613613- ULONG FrameLen = 0;614614- BOOLEAN TimerCancelled;615615- NDIS_STATUS NStatus;616616- ULONG tmp;617617- PUCHAR pOutBuffer = NULL;618618- USHORT Status;619619-620620- // Block all authentication request durning WPA block period621621- if (pAd->StaCfg.bBlockAssoc == TRUE)622622- {623623- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block ReAssoc request durning WPA block period!\n"));624624- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;625625- Status = MLME_STATE_MACHINE_REJECT;626626- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);627627- }628628- // the parameters are the same as the association629629- else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))630630- {631631- RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);632632-633633- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory634634- if(NStatus != NDIS_STATUS_SUCCESS)635635- {636636- DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() allocate memory failed \n"));637637- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;638638- Status = MLME_FAIL_NO_RESOURCE;639639- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);640640- return;641641- }642642-643643- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);644644-645645- // make frame, use bssid as the AP address??646646- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send RE-ASSOC request...\n"));647647- MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0, ApAddr, ApAddr);648648- MakeOutgoingFrame(pOutBuffer, &FrameLen,649649- sizeof(HEADER_802_11), &ReassocHdr,650650- 2, &CapabilityInfo,651651- 2, &ListenIntv,652652- MAC_ADDR_LEN, ApAddr,653653- 1, &SsidIe,654654- 1, &pAd->MlmeAux.SsidLen,655655- pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,656656- 1, &SupRateIe,657657- 1, &pAd->MlmeAux.SupRateLen,658658- pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,659659- END_OF_ARGS);660660-661661- if (pAd->MlmeAux.ExtRateLen != 0)662662- {663663- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,664664- 1, &ExtRateIe,665665- 1, &pAd->MlmeAux.ExtRateLen,666666- pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,667667- END_OF_ARGS);668668- FrameLen += tmp;669669- }670670-671671- if (pAd->MlmeAux.APEdcaParm.bValid)672672- {673673- if (pAd->CommonCfg.bAPSDCapable && pAd->MlmeAux.APEdcaParm.bAPSDCapable)674674- {675675- QBSS_STA_INFO_PARM QosInfo;676676-677677- NdisZeroMemory(&QosInfo, sizeof(QBSS_STA_INFO_PARM));678678- QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;679679- QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;680680- QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;681681- QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;682682- QosInfo.MaxSPLength = pAd->CommonCfg.MaxSPLength;683683- WmeIe[8] |= *(PUCHAR)&QosInfo;684684- }685685-686686- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,687687- 9, &WmeIe[0],688688- END_OF_ARGS);689689- FrameLen += tmp;690690- }691691-692692- // HT693693- if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))694694- {695695- ULONG TmpLen;696696- UCHAR HtLen;697697- UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};698698- if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)699699- {700700- HtLen = SIZE_HT_CAP_IE + 4;701701- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,702702- 1, &WpaIe,703703- 1, &HtLen,704704- 4, &BROADCOM[0],705705- pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,706706- END_OF_ARGS);707707- }708708- else709709- {710710- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,711711- 1, &HtCapIe,712712- 1, &pAd->MlmeAux.HtCapabilityLen,713713- pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,714714- END_OF_ARGS);715715- }716716- FrameLen += TmpLen;717717- }718718-719719- // add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION720720- // Case I: (Aggregation + Piggy-Back)721721- // 1. user enable aggregation, AND722722- // 2. Mac support piggy-back723723- // 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON724724- // Case II: (Aggregation)725725- // 1. user enable aggregation, AND726726- // 2. AP annouces it's AGGREGATION-capable in BEACON727727- if (pAd->CommonCfg.bAggregationCapable)728728- {729729- if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))730730- {731731- ULONG TmpLen;732732- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00};733733- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,734734- 9, RalinkIe,735735- END_OF_ARGS);736736- FrameLen += TmpLen;737737- }738738- else if (pAd->MlmeAux.APRalinkIe & 0x00000001)739739- {740740- ULONG TmpLen;741741- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};742742- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,743743- 9, RalinkIe,744744- END_OF_ARGS);745745- FrameLen += TmpLen;746746- }747747- }748748- else749749- {750750- ULONG TmpLen;751751- UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04, 0x00, 0x00, 0x00};752752- MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,753753- 9, RalinkIe,754754- END_OF_ARGS);755755- FrameLen += TmpLen;756756- }757757-758758- // Add CCX v2 request if CCX2 admin state is on759759- if (pAd->StaCfg.CCXControl.field.Enable == 1)760760- {761761- //762762- // Add CCX Version763763- //764764- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,765765- 1, &Ccx2Ie,766766- 1, &Ccx2Len,767767- Ccx2Len, Ccx2IeInfo,768768- END_OF_ARGS);769769- FrameLen += tmp;770770- }771771-772772- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);773773- MlmeFreeMemory(pAd, pOutBuffer);774774-775775- RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */776776- pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;777777- }778778- else779779- {780780- DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!!!! \n"));781781- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;782782- Status = MLME_INVALID_FORMAT;783783- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);784784- }785785-}786786-787787-/*788788- ==========================================================================789789- Description:790790- Upper layer issues disassoc request791791- Parameters:792792- Elem -793793-794794- IRQL = PASSIVE_LEVEL795795-796796- ==========================================================================797797- */798798-VOID MlmeDisassocReqAction(799799- IN PRTMP_ADAPTER pAd,800800- IN MLME_QUEUE_ELEM *Elem)801801-{802802- PMLME_DISASSOC_REQ_STRUCT pDisassocReq;803803- HEADER_802_11 DisassocHdr;804804- PHEADER_802_11 pDisassocHdr;805805- PUCHAR pOutBuffer = NULL;806806- ULONG FrameLen = 0;807807- NDIS_STATUS NStatus;808808- BOOLEAN TimerCancelled;809809- ULONG Timeout = 0;810810- USHORT Status;811811-812812- // skip sanity check813813- pDisassocReq = (PMLME_DISASSOC_REQ_STRUCT)(Elem->Msg);814814-815815- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory816816- if (NStatus != NDIS_STATUS_SUCCESS)817817- {818818- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n"));819819- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;820820- Status = MLME_FAIL_NO_RESOURCE;821821- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);822822- return;823823- }824824-825825-826826-827827- RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled);828828-829829- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send DISASSOC request[BSSID::%02x:%02x:%02x:%02x:%02x:%02x (Reason=%d)\n",830830- pDisassocReq->Addr[0], pDisassocReq->Addr[1], pDisassocReq->Addr[2],831831- pDisassocReq->Addr[3], pDisassocReq->Addr[4], pDisassocReq->Addr[5], pDisassocReq->Reason));832832- MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); // patch peap ttls switching issue833833- MakeOutgoingFrame(pOutBuffer, &FrameLen,834834- sizeof(HEADER_802_11),&DisassocHdr,835835- 2, &pDisassocReq->Reason,836836- END_OF_ARGS);837837- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);838838-839839- // To patch Instance and Buffalo(N) AP840840- // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine841841- // Therefore, we send both of them.842842- pDisassocHdr = (PHEADER_802_11)pOutBuffer;843843- pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;844844- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);845845-846846- MlmeFreeMemory(pAd, pOutBuffer);847847-848848- pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;849849- COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr);850850-851851- RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */852852- pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;853853-854854- {855855- union iwreq_data wrqu;856856- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);857857- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);858858- }859859-}860860-861861-/*862862- ==========================================================================863863- Description:864864- peer sends assoc rsp back865865- Parameters:866866- Elme - MLME message containing the received frame867867-868868- IRQL = DISPATCH_LEVEL869869-870870- ==========================================================================871871- */872872-VOID PeerAssocRspAction(873873- IN PRTMP_ADAPTER pAd,874874- IN MLME_QUEUE_ELEM *Elem)875875-{876876- USHORT CapabilityInfo, Status, Aid;877877- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;878878- UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;879879- UCHAR Addr2[MAC_ADDR_LEN];880880- BOOLEAN TimerCancelled;881881- UCHAR CkipFlag;882882- EDCA_PARM EdcaParm;883883- HT_CAPABILITY_IE HtCapability;884884- ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE885885- UCHAR HtCapabilityLen;886886- UCHAR AddHtInfoLen;887887- UCHAR NewExtChannelOffset = 0xff;888888-889889- if (PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,890890- &HtCapability,&AddHtInfo, &HtCapabilityLen,&AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))891891- {892892- // The frame is for me ?893893- if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid))894894- {895895- DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n", Status));896896- DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspAction():MacTable [%d].AMsduSize = %d. ClientStatusFlags = 0x%lx \n",Elem->Wcid, pAd->MacTab.Content[BSSID_WCID].AMsduSize, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));897897- RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);898898- if(Status == MLME_SUCCESS)899899- {900900- UCHAR MaxSupportedRateIn500Kbps = 0;901901- UCHAR idx;902902-903903- // supported rates array may not be sorted. sort it and find the maximum rate904904- for (idx=0; idx<SupRateLen; idx++)905905- {906906- if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))907907- MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;908908- }909909-910910- for (idx=0; idx<ExtRateLen; idx++)911911- {912912- if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))913913- MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;914914- }915915- // go to procedure listed on page 376916916- AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,917917- &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);918918-919919- StaAddMacTableEntry(pAd, &pAd->MacTab.Content[BSSID_WCID], MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo);920920-921921- pAd->StaCfg.CkipFlag = CkipFlag;922922- if (CkipFlag & 0x18)923923- {924924- NdisZeroMemory(pAd->StaCfg.TxSEQ, 4);925925- NdisZeroMemory(pAd->StaCfg.RxSEQ, 4);926926- NdisZeroMemory(pAd->StaCfg.CKIPMIC, 4);927927- pAd->StaCfg.GIV[0] = RandomByte(pAd);928928- pAd->StaCfg.GIV[1] = RandomByte(pAd);929929- pAd->StaCfg.GIV[2] = RandomByte(pAd);930930- pAd->StaCfg.bCkipOn = TRUE;931931- DBGPRINT(RT_DEBUG_TRACE, ("<CCX> pAd->StaCfg.CkipFlag = 0x%02x\n", pAd->StaCfg.CkipFlag));932932- }933933- }934934- else935935- {936936- }937937- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;938938- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);939939- }940940- }941941- else942942- {943943- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerAssocRspAction() sanity check fail\n"));944944- }945945-}946946-947947-/*948948- ==========================================================================949949- Description:950950- peer sends reassoc rsp951951- Parametrs:952952- Elem - MLME message cntaining the received frame953953-954954- IRQL = DISPATCH_LEVEL955955-956956- ==========================================================================957957- */958958-VOID PeerReassocRspAction(959959- IN PRTMP_ADAPTER pAd,960960- IN MLME_QUEUE_ELEM *Elem)961961-{962962- USHORT CapabilityInfo;963963- USHORT Status;964964- USHORT Aid;965965- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;966966- UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;967967- UCHAR Addr2[MAC_ADDR_LEN];968968- UCHAR CkipFlag;969969- BOOLEAN TimerCancelled;970970- EDCA_PARM EdcaParm;971971- HT_CAPABILITY_IE HtCapability;972972- ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE973973- UCHAR HtCapabilityLen;974974- UCHAR AddHtInfoLen;975975- UCHAR NewExtChannelOffset = 0xff;976976-977977- if(PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen,978978- &HtCapability, &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen,&NewExtChannelOffset, &EdcaParm, &CkipFlag))979979- {980980- if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) // The frame is for me ?981981- {982982- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - receive REASSOC_RSP to me (status=%d)\n", Status));983983- RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);984984-985985- if(Status == MLME_SUCCESS)986986- {987987- // go to procedure listed on page 376988988- AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, SupRate, SupRateLen, ExtRate, ExtRateLen,989989- &EdcaParm, &HtCapability, HtCapabilityLen, &AddHtInfo);990990-991991- {992992- union iwreq_data wrqu;993993- wext_notify_event_assoc(pAd);994994-995995- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);996996- memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);997997- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);998998-999999- }10001000-10011001- }10021002-10031003- {10041004- // CkipFlag is no use for reassociate10051005- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;10061006- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);10071007- }10081008- }10091009- }10101010- else10111011- {10121012- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerReassocRspAction() sanity check fail\n"));10131013- }10141014-10151015-}10161016-10171017-/*10181018- ==========================================================================10191019- Description:10201020- procedures on IEEE 802.11/1999 p.37610211021- Parametrs:10221022-10231023- IRQL = DISPATCH_LEVEL10241024-10251025- ==========================================================================10261026- */10271027-VOID AssocPostProc(10281028- IN PRTMP_ADAPTER pAd,10291029- IN PUCHAR pAddr2,10301030- IN USHORT CapabilityInfo,10311031- IN USHORT Aid,10321032- IN UCHAR SupRate[],10331033- IN UCHAR SupRateLen,10341034- IN UCHAR ExtRate[],10351035- IN UCHAR ExtRateLen,10361036- IN PEDCA_PARM pEdcaParm,10371037- IN HT_CAPABILITY_IE *pHtCapability,10381038- IN UCHAR HtCapabilityLen,10391039- IN ADD_HT_INFO_IE *pAddHtInfo) // AP might use this additional ht info IE10401040-{10411041- ULONG Idx;10421042-10431043- pAd->MlmeAux.BssType = BSS_INFRA;10441044- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2);10451045- pAd->MlmeAux.Aid = Aid;10461046- pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;10471047-10481048- // Some HT AP might lost WMM IE. We add WMM ourselves. beacuase HT requires QoS on.10491049- if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE))10501050- {10511051- pEdcaParm->bValid = TRUE;10521052- pEdcaParm->Aifsn[0] = 3;10531053- pEdcaParm->Aifsn[1] = 7;10541054- pEdcaParm->Aifsn[2] = 2;10551055- pEdcaParm->Aifsn[3] = 2;10561056-10571057- pEdcaParm->Cwmin[0] = 4;10581058- pEdcaParm->Cwmin[1] = 4;10591059- pEdcaParm->Cwmin[2] = 3;10601060- pEdcaParm->Cwmin[3] = 2;10611061-10621062- pEdcaParm->Cwmax[0] = 10;10631063- pEdcaParm->Cwmax[1] = 10;10641064- pEdcaParm->Cwmax[2] = 4;10651065- pEdcaParm->Cwmax[3] = 3;10661066-10671067- pEdcaParm->Txop[0] = 0;10681068- pEdcaParm->Txop[1] = 0;10691069- pEdcaParm->Txop[2] = 96;10701070- pEdcaParm->Txop[3] = 48;10711071-10721072- }10731073-10741074- NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM));10751075-10761076- // filter out un-supported rates10771077- pAd->MlmeAux.SupRateLen = SupRateLen;10781078- NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);10791079- RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);10801080-10811081- // filter out un-supported rates10821082- pAd->MlmeAux.ExtRateLen = ExtRateLen;10831083- NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);10841084- RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);10851085-10861086- if (HtCapabilityLen > 0)10871087- {10881088- RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo);10891089- }10901090- DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n", pAd->MacTab.Content[BSSID_WCID].AMsduSize, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));10911091-10921092- DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n",10931093- pAd->MacTab.Content[BSSID_WCID].MmpsMode, pAd->MacTab.Content[BSSID_WCID].AMsduSize));10941094-10951095- // Set New WPA information10961096- Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);10971097- if (Idx == BSS_NOT_FOUND)10981098- {10991099- DBGPRINT_ERR(("ASSOC - Can't find BSS after receiving Assoc response\n"));11001100- }11011101- else11021102- {11031103- // Init variable11041104- pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;11051105- NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, MAX_LEN_OF_RSNIE);11061106-11071107- // Store appropriate RSN_IE for WPA SM negotiation later11081108- if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0))11091109- {11101110- PUCHAR pVIE;11111111- USHORT len;11121112- PEID_STRUCT pEid;11131113-11141114- pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs;11151115- len = pAd->ScanTab.BssEntry[Idx].VarIELen;11161116-11171117- while (len > 0)11181118- {11191119- pEid = (PEID_STRUCT) pVIE;11201120- // For WPA/WPAPSK11211121- if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))11221122- && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))11231123- {11241124- NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));11251125- pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);11261126- DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n"));11271127- }11281128- // For WPA2/WPA2PSK11291129- else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))11301130- && (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))11311131- {11321132- NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, pVIE, (pEid->Len + 2));11331133- pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = (pEid->Len + 2);11341134- DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n"));11351135- }11361136-11371137- pVIE += (pEid->Len + 2);11381138- len -= (pEid->Len + 2);11391139- }11401140- }11411141-11421142- if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0)11431143- {11441144- DBGPRINT(RT_DEBUG_TRACE, ("AssocPostProc===> no RSN_IE \n"));11451145- }11461146- else11471147- {11481148- hex_dump("RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);11491149- }11501150- }11511151-}11521152-11531153-/*11541154- ==========================================================================11551155- Description:11561156- left part of IEEE 802.11/1999 p.37411571157- Parameters:11581158- Elem - MLME message containing the received frame11591159-11601160- IRQL = DISPATCH_LEVEL11611161-11621162- ==========================================================================11631163- */11641164-VOID PeerDisassocAction(11651165- IN PRTMP_ADAPTER pAd,11661166- IN MLME_QUEUE_ELEM *Elem)11671167-{11681168- UCHAR Addr2[MAC_ADDR_LEN];11691169- USHORT Reason;11701170-11711171- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n"));11721172- if(PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))11731173- {11741174- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() Reason = %d\n", Reason));11751175- if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2))11761176- {11771177-11781178- if (pAd->CommonCfg.bWirelessEvent)11791179- {11801180- RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);11811181- }11821182-11831183- //11841184- // Get Current System time and Turn on AdjacentAPReport11851185- //11861186- NdisGetSystemUpTime(&pAd->StaCfg.CCXAdjacentAPLinkDownTime);11871187- pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE;11881188- LinkDown(pAd, TRUE);11891189- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;11901190-11911191- {11921192- union iwreq_data wrqu;11931193- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);11941194- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);11951195- }11961196- }11971197- }11981198- else11991199- {12001200- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction() sanity check fail\n"));12011201- }12021202-12031203-}12041204-12051205-/*12061206- ==========================================================================12071207- Description:12081208- what the state machine will do after assoc timeout12091209- Parameters:12101210- Elme -12111211-12121212- IRQL = DISPATCH_LEVEL12131213-12141214- ==========================================================================12151215- */12161216-VOID AssocTimeoutAction(12171217- IN PRTMP_ADAPTER pAd,12181218- IN MLME_QUEUE_ELEM *Elem)12191219-{12201220- USHORT Status;12211221- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n"));12221222- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12231223- Status = MLME_REJ_TIMEOUT;12241224- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);12251225-}12261226-12271227-/*12281228- ==========================================================================12291229- Description:12301230- what the state machine will do after reassoc timeout12311231-12321232- IRQL = DISPATCH_LEVEL12331233-12341234- ==========================================================================12351235- */12361236-VOID ReassocTimeoutAction(12371237- IN PRTMP_ADAPTER pAd,12381238- IN MLME_QUEUE_ELEM *Elem)12391239-{12401240- USHORT Status;12411241- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n"));12421242- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12431243- Status = MLME_REJ_TIMEOUT;12441244- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);12451245-}12461246-12471247-/*12481248- ==========================================================================12491249- Description:12501250- what the state machine will do after disassoc timeout12511251-12521252- IRQL = DISPATCH_LEVEL12531253-12541254- ==========================================================================12551255- */12561256-VOID DisassocTimeoutAction(12571257- IN PRTMP_ADAPTER pAd,12581258- IN MLME_QUEUE_ELEM *Elem)12591259-{12601260- USHORT Status;12611261- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n"));12621262- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12631263- Status = MLME_SUCCESS;12641264- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);12651265-}12661266-12671267-VOID InvalidStateWhenAssoc(12681268- IN PRTMP_ADAPTER pAd,12691269- IN MLME_QUEUE_ELEM *Elem)12701270-{12711271- USHORT Status;12721272- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n",12731273- pAd->Mlme.AssocMachine.CurrState));12741274- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12751275- Status = MLME_STATE_MACHINE_REJECT;12761276- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);12771277-}12781278-12791279-VOID InvalidStateWhenReassoc(12801280- IN PRTMP_ADAPTER pAd,12811281- IN MLME_QUEUE_ELEM *Elem)12821282-{12831283- USHORT Status;12841284- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n",12851285- pAd->Mlme.AssocMachine.CurrState));12861286- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12871287- Status = MLME_STATE_MACHINE_REJECT;12881288- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);12891289-}12901290-12911291-VOID InvalidStateWhenDisassociate(12921292- IN PRTMP_ADAPTER pAd,12931293- IN MLME_QUEUE_ELEM *Elem)12941294-{12951295- USHORT Status;12961296- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n",12971297- pAd->Mlme.AssocMachine.CurrState));12981298- pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;12991299- Status = MLME_STATE_MACHINE_REJECT;13001300- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status);13011301-}13021302-13031303-/*13041304- ==========================================================================13051305- Description:13061306- right part of IEEE 802.11/1999 page 37413071307- Note:13081308- This event should never cause ASSOC state machine perform state13091309- transition, and has no relationship with CNTL machine. So we separate13101310- this routine as a service outside of ASSOC state transition table.13111311-13121312- IRQL = DISPATCH_LEVEL13131313-13141314- ==========================================================================13151315- */13161316-VOID Cls3errAction(13171317- IN PRTMP_ADAPTER pAd,13181318- IN PUCHAR pAddr)13191319-{13201320- HEADER_802_11 DisassocHdr;13211321- PHEADER_802_11 pDisassocHdr;13221322- PUCHAR pOutBuffer = NULL;13231323- ULONG FrameLen = 0;13241324- NDIS_STATUS NStatus;13251325- USHORT Reason = REASON_CLS3ERR;13261326-13271327- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory13281328- if (NStatus != NDIS_STATUS_SUCCESS)13291329- return;13301330-13311331- DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Class 3 Error, Send DISASSOC frame\n"));13321332- MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); // patch peap ttls switching issue13331333- MakeOutgoingFrame(pOutBuffer, &FrameLen,13341334- sizeof(HEADER_802_11),&DisassocHdr,13351335- 2, &Reason,13361336- END_OF_ARGS);13371337- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);13381338-13391339- // To patch Instance and Buffalo(N) AP13401340- // Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine13411341- // Therefore, we send both of them.13421342- pDisassocHdr = (PHEADER_802_11)pOutBuffer;13431343- pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;13441344- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);13451345-13461346- MlmeFreeMemory(pAd, pOutBuffer);13471347-13481348- pAd->StaCfg.DisassocReason = REASON_CLS3ERR;13491349- COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr);13501350-}13511351-13521352- /*13531353- ==========================================================================13541354- Description:13551355- Switch between WEP and CKIP upon new association up.13561356- Parameters:13571357-13581358- IRQL = DISPATCH_LEVEL13591359-13601360- ==========================================================================13611361- */13621362-VOID SwitchBetweenWepAndCkip(13631363- IN PRTMP_ADAPTER pAd)13641364-{13651365- int i;13661366- SHAREDKEY_MODE_STRUC csr1;13671367-13681368- // if KP is required. change the CipherAlg in hardware shard key table from WEP13691369- // to CKIP. else remain as WEP13701370- if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10))13711371- {13721372- // modify hardware key table so that MAC use correct algorithm to decrypt RX13731373- RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);13741374- if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP64)13751375- csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP64;13761376- else if (csr1.field.Bss0Key0CipherAlg == CIPHER_WEP128)13771377- csr1.field.Bss0Key0CipherAlg = CIPHER_CKIP128;13781378-13791379- if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP64)13801380- csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP64;13811381- else if (csr1.field.Bss0Key1CipherAlg == CIPHER_WEP128)13821382- csr1.field.Bss0Key1CipherAlg = CIPHER_CKIP128;13831383-13841384- if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP64)13851385- csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP64;13861386- else if (csr1.field.Bss0Key2CipherAlg == CIPHER_WEP128)13871387- csr1.field.Bss0Key2CipherAlg = CIPHER_CKIP128;13881388-13891389- if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP64)13901390- csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP64;13911391- else if (csr1.field.Bss0Key3CipherAlg == CIPHER_WEP128)13921392- csr1.field.Bss0Key3CipherAlg = CIPHER_CKIP128;13931393- RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);13941394- DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));13951395-13961396- // modify software key table so that driver can specify correct algorithm in TXD upon TX13971397- for (i=0; i<SHARE_KEY_NUM; i++)13981398- {13991399- if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP64)14001400- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP64;14011401- else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_WEP128)14021402- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_CKIP128;14031403- }14041404- }14051405-14061406- // else if KP NOT inused. change the CipherAlg in hardware shard key table from CKIP14071407- // to WEP.14081408- else14091409- {14101410- // modify hardware key table so that MAC use correct algorithm to decrypt RX14111411- RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE, &csr1.word);14121412- if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP64)14131413- csr1.field.Bss0Key0CipherAlg = CIPHER_WEP64;14141414- else if (csr1.field.Bss0Key0CipherAlg == CIPHER_CKIP128)14151415- csr1.field.Bss0Key0CipherAlg = CIPHER_WEP128;14161416-14171417- if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP64)14181418- csr1.field.Bss0Key1CipherAlg = CIPHER_WEP64;14191419- else if (csr1.field.Bss0Key1CipherAlg == CIPHER_CKIP128)14201420- csr1.field.Bss0Key1CipherAlg = CIPHER_WEP128;14211421-14221422- if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP64)14231423- csr1.field.Bss0Key2CipherAlg = CIPHER_WEP64;14241424- else if (csr1.field.Bss0Key2CipherAlg == CIPHER_CKIP128)14251425- csr1.field.Bss0Key2CipherAlg = CIPHER_WEP128;14261426-14271427- if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP64)14281428- csr1.field.Bss0Key3CipherAlg = CIPHER_WEP64;14291429- else if (csr1.field.Bss0Key3CipherAlg == CIPHER_CKIP128)14301430- csr1.field.Bss0Key3CipherAlg = CIPHER_WEP128;14311431-14321432- // modify software key table so that driver can specify correct algorithm in TXD upon TX14331433- for (i=0; i<SHARE_KEY_NUM; i++)14341434- {14351435- if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP64)14361436- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP64;14371437- else if (pAd->SharedKey[BSS0][i].CipherAlg == CIPHER_CKIP128)14381438- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_WEP128;14391439- }14401440-14411441- //14421442- // On WPA-NONE, must update CipherAlg.14431443- // Because the OID_802_11_WEP_STATUS was been set after OID_802_11_ADD_KEY14441444- // and CipherAlg will be CIPHER_NONE by Windows ZeroConfig.14451445- // So we need to update CipherAlg after connect.14461446- //14471447- if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)14481448- {14491449- for (i = 0; i < SHARE_KEY_NUM; i++)14501450- {14511451- if (pAd->SharedKey[BSS0][i].KeyLen != 0)14521452- {14531453- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)14541454- {14551455- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_TKIP;14561456- }14571457- else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)14581458- {14591459- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_AES;14601460- }14611461- }14621462- else14631463- {14641464- pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;14651465- }14661466- }14671467-14681468- csr1.field.Bss0Key0CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;14691469- csr1.field.Bss0Key1CipherAlg = pAd->SharedKey[BSS0][1].CipherAlg;14701470- csr1.field.Bss0Key2CipherAlg = pAd->SharedKey[BSS0][2].CipherAlg;14711471- csr1.field.Bss0Key3CipherAlg = pAd->SharedKey[BSS0][3].CipherAlg;14721472- }14731473- RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE, csr1.word);14741474- DBGPRINT(RT_DEBUG_TRACE, ("SwitchBetweenWepAndCkip: modify BSS0 cipher to %s\n", CipherName[csr1.field.Bss0Key0CipherAlg]));14751475- }14761476-}14771477-14781478-int wext_notify_event_assoc(14791479- IN RTMP_ADAPTER *pAd)14801480-{14811481- union iwreq_data wrqu;14821482- char custom[IW_CUSTOM_MAX] = {0};14831483-14841484-#if WIRELESS_EXT > 1714851485- if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX)14861486- {14871487- wrqu.data.length = pAd->StaCfg.ReqVarIELen;14881488- memcpy(custom, pAd->StaCfg.ReqVarIEs, pAd->StaCfg.ReqVarIELen);14891489- wireless_send_event(pAd->net_dev, IWEVASSOCREQIE, &wrqu, custom);14901490- }14911491- else14921492- DBGPRINT(RT_DEBUG_TRACE, ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n"));14931493-#else14941494- if (((pAd->StaCfg.ReqVarIELen*2) + 17) <= IW_CUSTOM_MAX)14951495- {14961496- UCHAR idx;14971497- wrqu.data.length = (pAd->StaCfg.ReqVarIELen*2) + 17;14981498- sprintf(custom, "ASSOCINFO(ReqIEs=");14991499- for (idx=0; idx<pAd->StaCfg.ReqVarIELen; idx++)15001500- sprintf(custom, "%s%02x", custom, pAd->StaCfg.ReqVarIEs[idx]);15011501- wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);15021502- }15031503- else15041504- DBGPRINT(RT_DEBUG_TRACE, ("(pAd->StaCfg.ReqVarIELen*2) + 17 > MAX_CUSTOM_LEN\n"));15051505-#endif15061506-15071507- return 0;15081508-15091509-}15101510-15111511-BOOLEAN StaAddMacTableEntry(15121512- IN PRTMP_ADAPTER pAd,15131513- IN PMAC_TABLE_ENTRY pEntry,15141514- IN UCHAR MaxSupportedRateIn500Kbps,15151515- IN HT_CAPABILITY_IE *pHtCapability,15161516- IN UCHAR HtCapabilityLen,15171517- IN USHORT CapabilityInfo)15181518-{15191519- UCHAR MaxSupportedRate = RATE_11;15201520-15211521- if (ADHOC_ON(pAd))15221522- CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);15231523-15241524- switch (MaxSupportedRateIn500Kbps)15251525- {15261526- case 108: MaxSupportedRate = RATE_54; break;15271527- case 96: MaxSupportedRate = RATE_48; break;15281528- case 72: MaxSupportedRate = RATE_36; break;15291529- case 48: MaxSupportedRate = RATE_24; break;15301530- case 36: MaxSupportedRate = RATE_18; break;15311531- case 24: MaxSupportedRate = RATE_12; break;15321532- case 18: MaxSupportedRate = RATE_9; break;15331533- case 12: MaxSupportedRate = RATE_6; break;15341534- case 22: MaxSupportedRate = RATE_11; break;15351535- case 11: MaxSupportedRate = RATE_5_5; break;15361536- case 4: MaxSupportedRate = RATE_2; break;15371537- case 2: MaxSupportedRate = RATE_1; break;15381538- default: MaxSupportedRate = RATE_11; break;15391539- }15401540-15411541- if ((pAd->CommonCfg.PhyMode == PHY_11G) && (MaxSupportedRate < RATE_FIRST_OFDM_RATE))15421542- return FALSE;15431543-15441544- // 11n only15451545- if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))&& (HtCapabilityLen == 0))15461546- return FALSE;15471547-15481548- if (!pEntry)15491549- return FALSE;15501550-15511551- NdisAcquireSpinLock(&pAd->MacTabLock);15521552- if (pEntry)15531553- {15541554- pEntry->PortSecured = WPA_802_1X_PORT_SECURED;15551555- if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) ||15561556- (pAd->CommonCfg.PhyMode == PHY_11B))15571557- {15581558- pEntry->RateLen = 4;15591559- if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE)15601560- MaxSupportedRate = RATE_11;15611561- }15621562- else15631563- pEntry->RateLen = 12;15641564-15651565- pEntry->MaxHTPhyMode.word = 0;15661566- pEntry->MinHTPhyMode.word = 0;15671567- pEntry->HTPhyMode.word = 0;15681568- pEntry->MaxSupportedRate = MaxSupportedRate;15691569- if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE)15701570- {15711571- pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;15721572- pEntry->MaxHTPhyMode.field.MCS = pEntry->MaxSupportedRate;15731573- pEntry->MinHTPhyMode.field.MODE = MODE_CCK;15741574- pEntry->MinHTPhyMode.field.MCS = pEntry->MaxSupportedRate;15751575- pEntry->HTPhyMode.field.MODE = MODE_CCK;15761576- pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;15771577- }15781578- else15791579- {15801580- pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;15811581- pEntry->MaxHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];15821582- pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;15831583- pEntry->MinHTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];15841584- pEntry->HTPhyMode.field.MODE = MODE_OFDM;15851585- pEntry->HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];15861586- }15871587- pEntry->CapabilityInfo = CapabilityInfo;15881588- CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE);15891589- CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE);15901590- }15911591-15921592- // If this Entry supports 802.11n, upgrade to HT rate.15931593- if ((HtCapabilityLen != 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))15941594- {15951595- UCHAR j, bitmask; //k,bitmask;15961596- CHAR i;15971597-15981598- if (ADHOC_ON(pAd))15991599- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);16001600- if ((pHtCapability->HtCapInfo.GF) && (pAd->CommonCfg.DesiredHtPhy.GF))16011601- {16021602- pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;16031603- }16041604- else16051605- {16061606- pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;16071607- pAd->MacTab.fAnyStationNonGF = TRUE;16081608- pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;16091609- }16101610-16111611- if ((pHtCapability->HtCapInfo.ChannelWidth) && (pAd->CommonCfg.DesiredHtPhy.ChannelWidth))16121612- {16131613- pEntry->MaxHTPhyMode.field.BW= BW_40;16141614- pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor40)&(pHtCapability->HtCapInfo.ShortGIfor40));16151615- }16161616- else16171617- {16181618- pEntry->MaxHTPhyMode.field.BW = BW_20;16191619- pEntry->MaxHTPhyMode.field.ShortGI = ((pAd->CommonCfg.DesiredHtPhy.ShortGIfor20)&(pHtCapability->HtCapInfo.ShortGIfor20));16201620- pAd->MacTab.fAnyStation20Only = TRUE;16211621- }16221622-16231623- // 3*316241624- if (pAd->MACVersion >= RALINK_2883_VERSION && pAd->MACVersion < RALINK_3070_VERSION)16251625- pEntry->MaxHTPhyMode.field.TxBF = pAd->CommonCfg.RegTransmitSetting.field.TxBF;16261626-16271627- // find max fixed rate16281628- for (i=23; i>=0; i--) // 3*316291629- {16301630- j = i/8;16311631- bitmask = (1<<(i-(j*8)));16321632- if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask) && (pHtCapability->MCSSet[j] & bitmask))16331633- {16341634- pEntry->MaxHTPhyMode.field.MCS = i;16351635- break;16361636- }16371637- if (i==0)16381638- break;16391639- }16401640-16411641-16421642- if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO)16431643- {16441644- if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32)16451645- {16461646- // Fix MCS as HT Duplicated Mode16471647- pEntry->MaxHTPhyMode.field.BW = 1;16481648- pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;16491649- pEntry->MaxHTPhyMode.field.STBC = 0;16501650- pEntry->MaxHTPhyMode.field.ShortGI = 0;16511651- pEntry->MaxHTPhyMode.field.MCS = 32;16521652- }16531653- else if (pEntry->MaxHTPhyMode.field.MCS > pAd->StaCfg.HTPhyMode.field.MCS)16541654- {16551655- // STA supports fixed MCS16561656- pEntry->MaxHTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;16571657- }16581658- }16591659-16601660- pEntry->MaxHTPhyMode.field.STBC = (pHtCapability->HtCapInfo.RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));16611661- pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity;16621662- pEntry->MaxRAmpduFactor = pHtCapability->HtCapParm.MaxRAmpduFactor;16631663- pEntry->MmpsMode = (UCHAR)pHtCapability->HtCapInfo.MimoPs;16641664- pEntry->AMsduSize = (UCHAR)pHtCapability->HtCapInfo.AMsduSize;16651665- pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;16661666-16671667- if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE))16681668- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED);16691669- if (pHtCapability->HtCapInfo.ShortGIfor20)16701670- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE);16711671- if (pHtCapability->HtCapInfo.ShortGIfor40)16721672- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE);16731673- if (pHtCapability->HtCapInfo.TxSTBC)16741674- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_TxSTBC_CAPABLE);16751675- if (pHtCapability->HtCapInfo.RxSTBC)16761676- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RxSTBC_CAPABLE);16771677- if (pHtCapability->ExtHtCapInfo.PlusHTC)16781678- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_HTC_CAPABLE);16791679- if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport)16801680- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_RDG_CAPABLE);16811681- if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03)16821682- CLIENT_STATUS_SET_FLAG(pEntry, fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);16831683- }16841684- else16851685- {16861686- pAd->MacTab.fAnyStationIsLegacy = TRUE;16871687- }16881688-16891689- NdisMoveMemory(&pEntry->HTCapability, pHtCapability, sizeof(HT_CAPABILITY_IE));16901690-16911691- pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;16921692- pEntry->CurrTxRate = pEntry->MaxSupportedRate;16931693-16941694- // Set asic auto fall back16951695- if (pAd->StaCfg.bAutoTxRateSwitch == TRUE)16961696- {16971697- PUCHAR pTable;16981698- UCHAR TableSize = 0;16991699-17001700- MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &pEntry->CurrTxRateIndex);17011701- pEntry->bAutoTxRateSwitch = TRUE;17021702- }17031703- else17041704- {17051705- pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;17061706- pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;17071707- pEntry->bAutoTxRateSwitch = FALSE;17081708-17091709- // If the legacy mode is set, overwrite the transmit setting of this entry.17101710- RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);17111711- }17121712-17131713- pEntry->PortSecured = WPA_802_1X_PORT_SECURED;17141714- pEntry->Sst = SST_ASSOC;17151715- pEntry->AuthState = AS_AUTH_OPEN;17161716- pEntry->AuthMode = pAd->StaCfg.AuthMode;17171717- pEntry->WepStatus = pAd->StaCfg.WepStatus;17181718-17191719- NdisReleaseSpinLock(&pAd->MacTabLock);17201720-17211721- {17221722- union iwreq_data wrqu;17231723- wext_notify_event_assoc(pAd);17241724-17251725- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);17261726- memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);17271727- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);17281728-17291729- }17301730- return TRUE;17311731-}17321732-17331733-11+#include "../../rt2870/sta/assoc.c"
+1-461
drivers/staging/rt3070/sta/auth.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- auth.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John 2004-9-3 porting from RT25003636-*/3737-#include "../rt_config.h"3838-3939-/*4040- ==========================================================================4141- Description:4242- authenticate state machine init, including state transition and timer init4343- Parameters:4444- Sm - pointer to the auth state machine4545- Note:4646- The state machine looks like this4747-4848- AUTH_REQ_IDLE AUTH_WAIT_SEQ2 AUTH_WAIT_SEQ44949- MT2_MLME_AUTH_REQ mlme_auth_req_action invalid_state_when_auth invalid_state_when_auth5050- MT2_PEER_AUTH_EVEN drop peer_auth_even_at_seq2_action peer_auth_even_at_seq4_action5151- MT2_AUTH_TIMEOUT Drop auth_timeout_action auth_timeout_action5252-5353- IRQL = PASSIVE_LEVEL5454-5555- ==========================================================================5656- */5757-5858-void AuthStateMachineInit(5959- IN PRTMP_ADAPTER pAd,6060- IN STATE_MACHINE *Sm,6161- OUT STATE_MACHINE_FUNC Trans[])6262-{6363- StateMachineInit(Sm, Trans, MAX_AUTH_STATE, MAX_AUTH_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_REQ_IDLE, AUTH_MACHINE_BASE);6464-6565- // the first column6666- StateMachineSetAction(Sm, AUTH_REQ_IDLE, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)MlmeAuthReqAction);6767-6868- // the second column6969- StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);7070- StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq2Action);7171- StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);7272-7373- // the third column7474- StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_MLME_AUTH_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAuth);7575- StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_PEER_AUTH_EVEN, (STATE_MACHINE_FUNC)PeerAuthRspAtSeq4Action);7676- StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_AUTH_TIMEOUT, (STATE_MACHINE_FUNC)AuthTimeoutAction);7777-7878- RTMPInitTimer(pAd, &pAd->MlmeAux.AuthTimer, GET_TIMER_FUNCTION(AuthTimeout), pAd, FALSE);7979-}8080-8181-/*8282- ==========================================================================8383- Description:8484- function to be executed at timer thread when auth timer expires8585-8686- IRQL = DISPATCH_LEVEL8787-8888- ==========================================================================8989- */9090-VOID AuthTimeout(9191- IN PVOID SystemSpecific1,9292- IN PVOID FunctionContext,9393- IN PVOID SystemSpecific2,9494- IN PVOID SystemSpecific3)9595-{9696- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;9797-9898- DBGPRINT(RT_DEBUG_TRACE,("AUTH - AuthTimeout\n"));9999-100100- // Do nothing if the driver is starting halt state.101101- // This might happen when timer already been fired before cancel timer with mlmehalt102102- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))103103- return;104104-105105- // send a de-auth to reset AP's state machine (Patch AP-Dir635)106106- if (pAd->Mlme.AuthMachine.CurrState == AUTH_WAIT_SEQ2)107107- Cls2errAction(pAd, pAd->MlmeAux.Bssid);108108-109109-110110- MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_AUTH_TIMEOUT, 0, NULL);111111- RT28XX_MLME_HANDLER(pAd);112112-}113113-114114-115115-/*116116- ==========================================================================117117- Description:118118-119119- IRQL = DISPATCH_LEVEL120120-121121- ==========================================================================122122- */123123-VOID MlmeAuthReqAction(124124- IN PRTMP_ADAPTER pAd,125125- IN MLME_QUEUE_ELEM *Elem)126126-{127127- UCHAR Addr[6];128128- USHORT Alg, Seq, Status;129129- ULONG Timeout;130130- HEADER_802_11 AuthHdr;131131- BOOLEAN TimerCancelled;132132- NDIS_STATUS NStatus;133133- PUCHAR pOutBuffer = NULL;134134- ULONG FrameLen = 0;135135-136136- // Block all authentication request durning WPA block period137137- if (pAd->StaCfg.bBlockAssoc == TRUE)138138- {139139- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Block Auth request durning WPA block period!\n"));140140- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;141141- Status = MLME_STATE_MACHINE_REJECT;142142- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);143143- }144144- else if(MlmeAuthReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr, &Timeout, &Alg))145145- {146146- // reset timer147147- RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);148148- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, Addr);149149- pAd->MlmeAux.Alg = Alg;150150- Seq = 1;151151- Status = MLME_SUCCESS;152152-153153- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory154154- if(NStatus != NDIS_STATUS_SUCCESS)155155- {156156- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeAuthReqAction(Alg:%d) allocate memory failed\n", Alg));157157- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;158158- Status = MLME_FAIL_NO_RESOURCE;159159- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);160160- return;161161- }162162-163163- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#1 (Alg=%d)...\n", Alg));164164- MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr, pAd->MlmeAux.Bssid);165165- MakeOutgoingFrame(pOutBuffer, &FrameLen,166166- sizeof(HEADER_802_11),&AuthHdr,167167- 2, &Alg,168168- 2, &Seq,169169- 2, &Status,170170- END_OF_ARGS);171171- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);172172- MlmeFreeMemory(pAd, pOutBuffer);173173-174174- RTMPSetTimer(&pAd->MlmeAux.AuthTimer, Timeout);175175- pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ2;176176- }177177- else178178- {179179- DBGPRINT_ERR(("AUTH - MlmeAuthReqAction() sanity check failed\n"));180180- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;181181- Status = MLME_INVALID_FORMAT;182182- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);183183- }184184-}185185-186186-/*187187- ==========================================================================188188- Description:189189-190190- IRQL = DISPATCH_LEVEL191191-192192- ==========================================================================193193- */194194-VOID PeerAuthRspAtSeq2Action(195195- IN PRTMP_ADAPTER pAd,196196- IN MLME_QUEUE_ELEM *Elem)197197-{198198- UCHAR Addr2[MAC_ADDR_LEN];199199- USHORT Seq, Status, RemoteStatus, Alg;200200- UCHAR ChlgText[CIPHER_TEXT_LEN];201201- UCHAR CyperChlgText[CIPHER_TEXT_LEN + 8 + 8];202202- UCHAR Element[2];203203- HEADER_802_11 AuthHdr;204204- BOOLEAN TimerCancelled;205205- PUCHAR pOutBuffer = NULL;206206- NDIS_STATUS NStatus;207207- ULONG FrameLen = 0;208208- USHORT Status2;209209-210210- if (PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))211211- {212212- if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 2)213213- {214214- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#2 to me (Alg=%d, Status=%d)\n", Alg, Status));215215- RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);216216-217217- if (Status == MLME_SUCCESS)218218- {219219- // Authentication Mode "LEAP" has allow for CCX 1.X220220- if ((pAd->MlmeAux.Alg == Ndis802_11AuthModeOpen)221221- )222222- {223223- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;224224- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);225225- }226226- else227227- {228228- // 2. shared key, need to be challenged229229- Seq++;230230- RemoteStatus = MLME_SUCCESS;231231-232232- // Get an unused nonpaged memory233233- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);234234- if(NStatus != NDIS_STATUS_SUCCESS)235235- {236236- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq2Action() allocate memory fail\n"));237237- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;238238- Status2 = MLME_FAIL_NO_RESOURCE;239239- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status2);240240- return;241241- }242242-243243- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send AUTH request seq#3...\n"));244244- MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr2, pAd->MlmeAux.Bssid);245245- AuthHdr.FC.Wep = 1;246246- // Encrypt challenge text & auth information247247- RTMPInitWepEngine(248248- pAd,249249- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,250250- pAd->StaCfg.DefaultKeyId,251251- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen,252252- CyperChlgText);253253-254254- Alg = cpu2le16(*(USHORT *)&Alg);255255- Seq = cpu2le16(*(USHORT *)&Seq);256256- RemoteStatus= cpu2le16(*(USHORT *)&RemoteStatus);257257-258258- RTMPEncryptData(pAd, (PUCHAR) &Alg, CyperChlgText + 4, 2);259259- RTMPEncryptData(pAd, (PUCHAR) &Seq, CyperChlgText + 6, 2);260260- RTMPEncryptData(pAd, (PUCHAR) &RemoteStatus, CyperChlgText + 8, 2);261261- Element[0] = 16;262262- Element[1] = 128;263263- RTMPEncryptData(pAd, Element, CyperChlgText + 10, 2);264264- RTMPEncryptData(pAd, ChlgText, CyperChlgText + 12, 128);265265- RTMPSetICV(pAd, CyperChlgText + 140);266266- MakeOutgoingFrame(pOutBuffer, &FrameLen,267267- sizeof(HEADER_802_11), &AuthHdr,268268- CIPHER_TEXT_LEN + 16, CyperChlgText,269269- END_OF_ARGS);270270- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);271271- MlmeFreeMemory(pAd, pOutBuffer);272272-273273- RTMPSetTimer(&pAd->MlmeAux.AuthTimer, AUTH_TIMEOUT);274274- pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ4;275275- }276276- }277277- else278278- {279279- pAd->StaCfg.AuthFailReason = Status;280280- COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);281281- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;282282- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);283283- }284284- }285285- }286286- else287287- {288288- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthSanity() sanity check fail\n"));289289- }290290-}291291-292292-/*293293- ==========================================================================294294- Description:295295-296296- IRQL = DISPATCH_LEVEL297297-298298- ==========================================================================299299- */300300-VOID PeerAuthRspAtSeq4Action(301301- IN PRTMP_ADAPTER pAd,302302- IN MLME_QUEUE_ELEM *Elem)303303-{304304- UCHAR Addr2[MAC_ADDR_LEN];305305- USHORT Alg, Seq, Status;306306- CHAR ChlgText[CIPHER_TEXT_LEN];307307- BOOLEAN TimerCancelled;308308-309309- if(PeerAuthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, ChlgText))310310- {311311- if(MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 4)312312- {313313- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Receive AUTH_RSP seq#4 to me\n"));314314- RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &TimerCancelled);315315-316316- if (Status != MLME_SUCCESS)317317- {318318- pAd->StaCfg.AuthFailReason = Status;319319- COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);320320- }321321-322322- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;323323- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);324324- }325325- }326326- else327327- {328328- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - PeerAuthRspAtSeq4Action() sanity check fail\n"));329329- }330330-}331331-332332-/*333333- ==========================================================================334334- Description:335335-336336- IRQL = DISPATCH_LEVEL337337-338338- ==========================================================================339339- */340340-VOID MlmeDeauthReqAction(341341- IN PRTMP_ADAPTER pAd,342342- IN MLME_QUEUE_ELEM *Elem)343343-{344344- MLME_DEAUTH_REQ_STRUCT *pInfo;345345- HEADER_802_11 DeauthHdr;346346- PUCHAR pOutBuffer = NULL;347347- NDIS_STATUS NStatus;348348- ULONG FrameLen = 0;349349- USHORT Status;350350-351351- pInfo = (MLME_DEAUTH_REQ_STRUCT *)Elem->Msg;352352-353353- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory354354- if (NStatus != NDIS_STATUS_SUCCESS)355355- {356356- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - MlmeDeauthReqAction() allocate memory fail\n"));357357- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;358358- Status = MLME_FAIL_NO_RESOURCE;359359- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);360360- return;361361- }362362-363363-364364- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Send DE-AUTH request (Reason=%d)...\n", pInfo->Reason));365365- MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pInfo->Addr, pAd->MlmeAux.Bssid);366366- MakeOutgoingFrame(pOutBuffer, &FrameLen,367367- sizeof(HEADER_802_11),&DeauthHdr,368368- 2, &pInfo->Reason,369369- END_OF_ARGS);370370- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);371371- MlmeFreeMemory(pAd, pOutBuffer);372372-373373- pAd->StaCfg.DeauthReason = pInfo->Reason;374374- COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pInfo->Addr);375375- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;376376- Status = MLME_SUCCESS;377377- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);378378-379379- // send wireless event - for deauthentication380380- if (pAd->CommonCfg.bWirelessEvent)381381- RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);382382-}383383-384384-/*385385- ==========================================================================386386- Description:387387-388388- IRQL = DISPATCH_LEVEL389389-390390- ==========================================================================391391- */392392-VOID AuthTimeoutAction(393393- IN PRTMP_ADAPTER pAd,394394- IN MLME_QUEUE_ELEM *Elem)395395-{396396- USHORT Status;397397- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeoutAction\n"));398398- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;399399- Status = MLME_REJ_TIMEOUT;400400- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);401401-}402402-403403-/*404404- ==========================================================================405405- Description:406406-407407- IRQL = DISPATCH_LEVEL408408-409409- ==========================================================================410410- */411411-VOID InvalidStateWhenAuth(412412- IN PRTMP_ADAPTER pAd,413413- IN MLME_QUEUE_ELEM *Elem)414414-{415415- USHORT Status;416416- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - InvalidStateWhenAuth (state=%ld), reset AUTH state machine\n", pAd->Mlme.AuthMachine.CurrState));417417- pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;418418- Status = MLME_STATE_MACHINE_REJECT;419419- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);420420-}421421-422422-/*423423- ==========================================================================424424- Description:425425- Some STA/AP426426- Note:427427- This action should never trigger AUTH state transition, therefore we428428- separate it from AUTH state machine, and make it as a standalone service429429-430430- IRQL = DISPATCH_LEVEL431431-432432- ==========================================================================433433- */434434-VOID Cls2errAction(435435- IN PRTMP_ADAPTER pAd,436436- IN PUCHAR pAddr)437437-{438438- HEADER_802_11 DeauthHdr;439439- PUCHAR pOutBuffer = NULL;440440- NDIS_STATUS NStatus;441441- ULONG FrameLen = 0;442442- USHORT Reason = REASON_CLS2ERR;443443-444444- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory445445- if (NStatus != NDIS_STATUS_SUCCESS)446446- return;447447-448448- DBGPRINT(RT_DEBUG_TRACE, ("AUTH - Class 2 error, Send DEAUTH frame...\n"));449449- MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pAddr, pAd->MlmeAux.Bssid);450450- MakeOutgoingFrame(pOutBuffer, &FrameLen,451451- sizeof(HEADER_802_11),&DeauthHdr,452452- 2, &Reason,453453- END_OF_ARGS);454454- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);455455- MlmeFreeMemory(pAd, pOutBuffer);456456-457457- pAd->StaCfg.DeauthReason = Reason;458458- COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pAddr);459459-}460460-461461-11+#include "../../rt2870/sta/auth.c"
+1-149
drivers/staging/rt3070/sta/auth_rsp.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- auth_rsp.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John 2004-10-1 copy from RT25603636-*/3737-#include "../rt_config.h"3838-3939-/*4040- ==========================================================================4141- Description:4242- authentication state machine init procedure4343- Parameters:4444- Sm - the state machine4545-4646- IRQL = PASSIVE_LEVEL4747-4848- ==========================================================================4949- */5050-VOID AuthRspStateMachineInit(5151- IN PRTMP_ADAPTER pAd,5252- IN PSTATE_MACHINE Sm,5353- IN STATE_MACHINE_FUNC Trans[])5454-{5555- StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_RSP_IDLE, AUTH_RSP_MACHINE_BASE);5656-5757- // column 15858- StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);5959-6060- // column 26161- StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);6262-6363-}6464-6565-/*6666- ==========================================================================6767- Description:6868-6969- IRQL = DISPATCH_LEVEL7070-7171- ==========================================================================7272-*/7373-VOID PeerAuthSimpleRspGenAndSend(7474- IN PRTMP_ADAPTER pAd,7575- IN PHEADER_802_11 pHdr80211,7676- IN USHORT Alg,7777- IN USHORT Seq,7878- IN USHORT Reason,7979- IN USHORT Status)8080-{8181- HEADER_802_11 AuthHdr;8282- ULONG FrameLen = 0;8383- PUCHAR pOutBuffer = NULL;8484- NDIS_STATUS NStatus;8585-8686- if (Reason != MLME_SUCCESS)8787- {8888- DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n"));8989- return;9090- }9191-9292- //Get an unused nonpaged memory9393- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);9494- if (NStatus != NDIS_STATUS_SUCCESS)9595- return;9696-9797- DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n"));9898- MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2, pAd->MlmeAux.Bssid);9999- MakeOutgoingFrame(pOutBuffer, &FrameLen,100100- sizeof(HEADER_802_11), &AuthHdr,101101- 2, &Alg,102102- 2, &Seq,103103- 2, &Reason,104104- END_OF_ARGS);105105- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);106106- MlmeFreeMemory(pAd, pOutBuffer);107107-}108108-109109-/*110110- ==========================================================================111111- Description:112112-113113- IRQL = DISPATCH_LEVEL114114-115115- ==========================================================================116116-*/117117-VOID PeerDeauthAction(118118- IN PRTMP_ADAPTER pAd,119119- IN PMLME_QUEUE_ELEM Elem)120120-{121121- UCHAR Addr2[MAC_ADDR_LEN];122122- USHORT Reason;123123-124124- if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))125125- {126126- if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid))127127- {128128- DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n", Reason));129129-130130-131131- {132132- union iwreq_data wrqu;133133- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);134134- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);135135- }136136-137137- // send wireless event - for deauthentication138138- if (pAd->CommonCfg.bWirelessEvent)139139- RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);140140-141141- LinkDown(pAd, TRUE);142142- }143143- }144144- else145145- {146146- DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - PeerDeauthAction() sanity check fail\n"));147147- }148148-}149149-11+#include "../../rt2870/sta/auth_rsp.c"
+1-2461
drivers/staging/rt3070/sta/connect.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- connect.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John 2004-08-08 Major modification from RT25603636-*/3737-#include "../rt_config.h"3838-3939-UCHAR CipherSuiteWpaNoneTkip[] = {4040- 0x00, 0x50, 0xf2, 0x01, // oui4141- 0x01, 0x00, // Version4242- 0x00, 0x50, 0xf2, 0x02, // Multicast4343- 0x01, 0x00, // Number of unicast4444- 0x00, 0x50, 0xf2, 0x02, // unicast4545- 0x01, 0x00, // number of authentication method4646- 0x00, 0x50, 0xf2, 0x00 // authentication4747- };4848-UCHAR CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));4949-5050-UCHAR CipherSuiteWpaNoneAes[] = {5151- 0x00, 0x50, 0xf2, 0x01, // oui5252- 0x01, 0x00, // Version5353- 0x00, 0x50, 0xf2, 0x04, // Multicast5454- 0x01, 0x00, // Number of unicast5555- 0x00, 0x50, 0xf2, 0x04, // unicast5656- 0x01, 0x00, // number of authentication method5757- 0x00, 0x50, 0xf2, 0x00 // authentication5858- };5959-UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));6060-6161-// The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,6262-// or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS6363-// All settings successfuly negotiated furing MLME state machines become final settings6464-// and are copied to pAd->StaActive6565-#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \6666-{ \6767- (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \6868- NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \6969- COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \7070- (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \7171- (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \7272- (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \7373- (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \7474- (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \7575- (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \7676- (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \7777- (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \7878- (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \7979- NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\8080- (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \8181- NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\8282- NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\8383- NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\8484- NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\8585- COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \8686- (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \8787- (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\8888- COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\8989- (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\9090-}9191-9292-/*9393- ==========================================================================9494- Description:9595-9696- IRQL = PASSIVE_LEVEL9797-9898- ==========================================================================9999-*/100100-VOID MlmeCntlInit(101101- IN PRTMP_ADAPTER pAd,102102- IN STATE_MACHINE *S,103103- OUT STATE_MACHINE_FUNC Trans[])104104-{105105- // Control state machine differs from other state machines, the interface106106- // follows the standard interface107107- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;108108-}109109-110110-/*111111- ==========================================================================112112- Description:113113-114114- IRQL = DISPATCH_LEVEL115115-116116- ==========================================================================117117-*/118118-VOID MlmeCntlMachinePerformAction(119119- IN PRTMP_ADAPTER pAd,120120- IN STATE_MACHINE *S,121121- IN MLME_QUEUE_ELEM *Elem)122122-{123123- switch(pAd->Mlme.CntlMachine.CurrState)124124- {125125- case CNTL_IDLE:126126- {127127- CntlIdleProc(pAd, Elem);128128- }129129- break;130130- case CNTL_WAIT_DISASSOC:131131- CntlWaitDisassocProc(pAd, Elem);132132- break;133133- case CNTL_WAIT_JOIN:134134- CntlWaitJoinProc(pAd, Elem);135135- break;136136-137137- // CNTL_WAIT_REASSOC is the only state in CNTL machine that does138138- // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".139139- // Therefore not protected by NDIS's "only one outstanding OID request"140140- // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.141141- // Current approach is to block new SET request at RTMPSetInformation()142142- // when CntlMachine.CurrState is not CNTL_IDLE143143- case CNTL_WAIT_REASSOC:144144- CntlWaitReassocProc(pAd, Elem);145145- break;146146-147147- case CNTL_WAIT_START:148148- CntlWaitStartProc(pAd, Elem);149149- break;150150- case CNTL_WAIT_AUTH:151151- CntlWaitAuthProc(pAd, Elem);152152- break;153153- case CNTL_WAIT_AUTH2:154154- CntlWaitAuthProc2(pAd, Elem);155155- break;156156- case CNTL_WAIT_ASSOC:157157- CntlWaitAssocProc(pAd, Elem);158158- break;159159-160160- case CNTL_WAIT_OID_LIST_SCAN:161161- if(Elem->MsgType == MT2_SCAN_CONF)162162- {163163- // Resume TxRing after SCANING complete. We hope the out-of-service time164164- // won't be too long to let upper layer time-out the waiting frames165165- RTMPResumeMsduTransmission(pAd);166166- if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)167167- {168168- // Cisco scan request is finished, prepare beacon report169169- MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);170170- }171171- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;172172-173173- //174174- // Set LED status to previous status.175175- //176176- if (pAd->bLedOnScanning)177177- {178178- pAd->bLedOnScanning = FALSE;179179- RTMPSetLED(pAd, pAd->LedStatus);180180- }181181- }182182- break;183183-184184- case CNTL_WAIT_OID_DISASSOC:185185- if (Elem->MsgType == MT2_DISASSOC_CONF)186186- {187187- LinkDown(pAd, FALSE);188188- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;189189- }190190- break;191191-#ifdef RT2870192192- //193193- // This state is for that we want to connect to an AP but194194- // it didn't find on BSS List table. So we need to scan the air first,195195- // after that we can try to connect to the desired AP if available.196196- //197197- case CNTL_WAIT_SCAN_FOR_CONNECT:198198- if(Elem->MsgType == MT2_SCAN_CONF)199199- {200200- // Resume TxRing after SCANING complete. We hope the out-of-service time201201- // won't be too long to let upper layer time-out the waiting frames202202- RTMPResumeMsduTransmission(pAd);203203-#ifdef CCX_SUPPORT204204- if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)205205- {206206- // Cisco scan request is finished, prepare beacon report207207- MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);208208- }209209-#endif // CCX_SUPPORT //210210- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;211211-212212- //213213- // Check if we can connect to.214214- //215215- BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);216216- if (pAd->MlmeAux.SsidBssTab.BssNr > 0)217217- {218218- MlmeAutoReconnectLastSSID(pAd);219219- }220220- }221221- break;222222-#endif // RT2870 //223223- default:224224- DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));225225- break;226226- }227227-}228228-229229-230230-/*231231- ==========================================================================232232- Description:233233-234234- IRQL = DISPATCH_LEVEL235235-236236- ==========================================================================237237-*/238238-VOID CntlIdleProc(239239- IN PRTMP_ADAPTER pAd,240240- IN MLME_QUEUE_ELEM *Elem)241241-{242242- MLME_DISASSOC_REQ_STRUCT DisassocReq;243243-244244- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))245245- return;246246-247247- switch(Elem->MsgType)248248- {249249- case OID_802_11_SSID:250250- CntlOidSsidProc(pAd, Elem);251251- break;252252-253253- case OID_802_11_BSSID:254254- CntlOidRTBssidProc(pAd,Elem);255255- break;256256-257257- case OID_802_11_BSSID_LIST_SCAN:258258- CntlOidScanProc(pAd,Elem);259259- break;260260-261261- case OID_802_11_DISASSOCIATE:262262- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);263263- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);264264- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;265265-266266- if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)267267- {268268- // Set the AutoReconnectSsid to prevent it reconnect to old SSID269269- // Since calling this indicate user don't want to connect to that SSID anymore.270270- pAd->MlmeAux.AutoReconnectSsidLen= 32;271271- NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);272272- }273273- break;274274-275275- case MT2_MLME_ROAMING_REQ:276276- CntlMlmeRoamingProc(pAd, Elem);277277- break;278278-279279- case OID_802_11_MIC_FAILURE_REPORT_FRAME:280280- WpaMicFailureReportFrame(pAd, Elem);281281- break;282282-283283- default:284284- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));285285- break;286286- }287287-}288288-289289-VOID CntlOidScanProc(290290- IN PRTMP_ADAPTER pAd,291291- IN MLME_QUEUE_ELEM *Elem)292292-{293293- MLME_SCAN_REQ_STRUCT ScanReq;294294- ULONG BssIdx = BSS_NOT_FOUND;295295- BSS_ENTRY CurrBss;296296-297297- // record current BSS if network is connected.298298- // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.299299- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))300300- {301301- BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);302302- if (BssIdx != BSS_NOT_FOUND)303303- {304304- NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));305305- }306306- }307307-308308- // clean up previous SCAN result, add current BSS back to table if any309309- BssTableInit(&pAd->ScanTab);310310- if (BssIdx != BSS_NOT_FOUND)311311- {312312- // DDK Note: If the NIC is associated with a particular BSSID and SSID313313- // that are not contained in the list of BSSIDs generated by this scan, the314314- // BSSID description of the currently associated BSSID and SSID should be315315- // appended to the list of BSSIDs in the NIC's database.316316- // To ensure this, we append this BSS as the first entry in SCAN result317317- NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));318318- pAd->ScanTab.BssNr = 1;319319- }320320-321321- ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE);322322- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,323323- sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);324324- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;325325-}326326-327327-/*328328- ==========================================================================329329- Description:330330- Before calling this routine, user desired SSID should already been331331- recorded in CommonCfg.Ssid[]332332- IRQL = DISPATCH_LEVEL333333-334334- ==========================================================================335335-*/336336-VOID CntlOidSsidProc(337337- IN PRTMP_ADAPTER pAd,338338- IN MLME_QUEUE_ELEM * Elem)339339-{340340- PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;341341- MLME_DISASSOC_REQ_STRUCT DisassocReq;342342- ULONG Now;343343-344344- // Step 1. record the desired user settings to MlmeAux345345- NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);346346- NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);347347- pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength;348348- NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);349349- pAd->MlmeAux.BssType = pAd->StaCfg.BssType;350350-351351-352352- //353353- // Update Reconnect Ssid, that user desired to connect.354354- //355355- NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);356356- NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);357357- pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;358358-359359- // step 2. find all matching BSS in the lastest SCAN result (inBssTab)360360- // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order361361- BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);362362-363363- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",364364- pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));365365- NdisGetSystemUpTime(&Now);366366-367367- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&368368- (pAd->CommonCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) &&369369- NdisEqualMemory(pAd->CommonCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->CommonCfg.SsidLen) &&370370- MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid))371371- {372372- // Case 1. already connected with an AP who has the desired SSID373373- // with highest RSSI374374-375375- // Add checking Mode "LEAP" for CCX 1.0376376- if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||377377- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||378378- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||379379- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)380380- ) &&381381- (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))382382- {383383- // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo384384- // connection process385385- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));386386- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);387387- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,388388- sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);389389- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;390390- }391391- else if (pAd->bConfigChanged == TRUE)392392- {393393- // case 1.2 Important Config has changed, we have to reconnect to the same AP394394- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));395395- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);396396- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,397397- sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);398398- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;399399- }400400- else401401- {402402- // case 1.3. already connected to the SSID with highest RSSI.403403- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));404404- //405405- // (HCT 12.1) 1c_wlan_mediaevents required406406- // media connect events are indicated when associating with the same AP407407- //408408- if (INFRA_ON(pAd))409409- {410410- //411411- // Since MediaState already is NdisMediaStateConnected412412- // We just indicate the connect event again to meet the WHQL required.413413- //414414- pAd->IndicateMediaState = NdisMediaStateConnected;415415- RTMP_IndicateMediaState(pAd);416416- pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up417417- }418418-419419- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;420420-421421- {422422- union iwreq_data wrqu;423423-424424- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);425425- memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);426426- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);427427-428428- }429429- }430430- }431431- else if (INFRA_ON(pAd))432432- {433433- //434434- // For RT61435435- // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )436436- // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect437437- // But media status is connected, so the SSID not report correctly.438438- //439439- if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen))440440- {441441- //442442- // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.443443- //444444- pAd->MlmeAux.CurrReqIsFromNdis = TRUE;445445- }446446- // case 2. active INFRA association existent447447- // roaming is done within miniport driver, nothing to do with configuration448448- // utility. so upon a new SET(OID_802_11_SSID) is received, we just449449- // disassociate with the current associated AP,450450- // then perform a new association with this new SSID, no matter the451451- // new/old SSID are the same or not.452452- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));453453- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);454454- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,455455- sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);456456- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;457457- }458458- else459459- {460460- if (ADHOC_ON(pAd))461461- {462462- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));463463- LinkDown(pAd, FALSE);464464- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);465465- pAd->IndicateMediaState = NdisMediaStateDisconnected;466466- RTMP_IndicateMediaState(pAd);467467- pAd->ExtraInfo = GENERAL_LINK_DOWN;468468- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));469469- }470470-471471- if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&472472- (pAd->StaCfg.bAutoReconnect == TRUE) &&473473- (pAd->MlmeAux.BssType == BSS_INFRA) &&474474- (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)475475- )476476- {477477- MLME_SCAN_REQ_STRUCT ScanReq;478478-479479- DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));480480- ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);481481- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);482482- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;483483- // Reset Missed scan number484484- pAd->StaCfg.LastScanTime = Now;485485- }486486- else487487- {488488- pAd->MlmeAux.BssIdx = 0;489489- IterateOnBssTab(pAd);490490- }491491- }492492-}493493-494494-495495-/*496496- ==========================================================================497497- Description:498498-499499- IRQL = DISPATCH_LEVEL500500-501501- ==========================================================================502502-*/503503-VOID CntlOidRTBssidProc(504504- IN PRTMP_ADAPTER pAd,505505- IN MLME_QUEUE_ELEM * Elem)506506-{507507- ULONG BssIdx;508508- PUCHAR pOidBssid = (PUCHAR)Elem->Msg;509509- MLME_DISASSOC_REQ_STRUCT DisassocReq;510510- MLME_JOIN_REQ_STRUCT JoinReq;511511-512512- // record user desired settings513513- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);514514- pAd->MlmeAux.BssType = pAd->StaCfg.BssType;515515-516516- //517517- // Update Reconnect Ssid, that user desired to connect.518518- //519519- NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);520520- pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;521521- NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);522522-523523- // find the desired BSS in the latest SCAN result table524524- BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);525525- if (BssIdx == BSS_NOT_FOUND)526526- {527527- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));528528- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;529529- return;530530- }531531-532532- // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?533533- // Because we need this entry to become the JOIN target in later on SYNC state machine534534- pAd->MlmeAux.BssIdx = 0;535535- pAd->MlmeAux.SsidBssTab.BssNr = 1;536536- NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));537537-538538- // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP539539- // we just follow normal procedure. The reason of user doing this may because he/she changed540540- // AP to another channel, but we still received BEACON from it thus don't claim Link Down.541541- // Since user knows he's changed AP channel, he'll re-connect again. By skipping the following542542- // checking, we'll disassociate then re-do normal association with this AP at the new channel.543543- // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do544544- // connection when setting the same BSSID.545545- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&546546- MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid))547547- {548548- // already connected to the same BSSID, go back to idle state directly549549- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));550550- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;551551-552552- {553553- union iwreq_data wrqu;554554-555555- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);556556- memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);557557- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);558558-559559- }560560- }561561- else562562- {563563- if (INFRA_ON(pAd))564564- {565565- // disassoc from current AP first566566- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n"));567567- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);568568- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,569569- sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);570570-571571- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;572572- }573573- else574574- {575575- if (ADHOC_ON(pAd))576576- {577577- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - drop current ADHOC\n"));578578- LinkDown(pAd, FALSE);579579- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);580580- pAd->IndicateMediaState = NdisMediaStateDisconnected;581581- RTMP_IndicateMediaState(pAd);582582- pAd->ExtraInfo = GENERAL_LINK_DOWN;583583- DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));584584- }585585-586586- // Change the wepstatus to original wepstatus587587- pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;588588- pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;589589- pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;590590-591591- // Check cipher suite, AP must have more secured cipher than station setting592592- // Set the Pairwise and Group cipher to match the intended AP setting593593- // We can only connect to AP with less secured cipher setting594594- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))595595- {596596- pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;597597-598598- if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)599599- pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;600600- else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)601601- pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;602602- else // There is no PairCipher Aux, downgrade our capability to TKIP603603- pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;604604- }605605- else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))606606- {607607- pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;608608-609609- if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)610610- pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;611611- else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)612612- pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;613613- else // There is no PairCipher Aux, downgrade our capability to TKIP614614- pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;615615-616616- // RSN capability617617- pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;618618- }619619-620620- // Set Mix cipher flag621621- pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;622622- if (pAd->StaCfg.bMixCipher == TRUE)623623- {624624- // If mix cipher, re-build RSNIE625625- RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);626626- }627627- // No active association, join the BSS immediately628628- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",629629- pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]));630630-631631- JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);632632- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);633633-634634- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;635635- }636636- }637637-}638638-639639-// Roaming is the only external request triggering CNTL state machine640640-// despite of other "SET OID" operation. All "SET OID" related oerations641641-// happen in sequence, because no other SET OID will be sent to this device642642-// until the the previous SET operation is complete (successful o failed).643643-// So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?644644-// or been corrupted by other "SET OID"?645645-//646646-// IRQL = DISPATCH_LEVEL647647-VOID CntlMlmeRoamingProc(648648- IN PRTMP_ADAPTER pAd,649649- IN MLME_QUEUE_ELEM *Elem)650650-{651651- // TODO:652652- // AP in different channel may show lower RSSI than actual value??653653- // should we add a weighting factor to compensate it?654654- DBGPRINT(RT_DEBUG_TRACE,("CNTL - Roaming in MlmeAux.RoamTab...\n"));655655-656656- NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));657657- pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;658658-659659- BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);660660- pAd->MlmeAux.BssIdx = 0;661661- IterateOnBssTab(pAd);662662-}663663-664664-/*665665- ==========================================================================666666- Description:667667-668668- IRQL = DISPATCH_LEVEL669669-670670- ==========================================================================671671-*/672672-VOID CntlWaitDisassocProc(673673- IN PRTMP_ADAPTER pAd,674674- IN MLME_QUEUE_ELEM *Elem)675675-{676676- MLME_START_REQ_STRUCT StartReq;677677-678678- if (Elem->MsgType == MT2_DISASSOC_CONF)679679- {680680- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));681681-682682- if (pAd->CommonCfg.bWirelessEvent)683683- {684684- RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);685685- }686686-687687- LinkDown(pAd, FALSE);688688-689689- // case 1. no matching BSS, and user wants ADHOC, so we just start a new one690690- if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC))691691- {692692- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));693693- StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);694694- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);695695- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;696696- }697697- // case 2. try each matched BSS698698- else699699- {700700- pAd->MlmeAux.BssIdx = 0;701701-702702- IterateOnBssTab(pAd);703703- }704704- }705705-}706706-707707-/*708708- ==========================================================================709709- Description:710710-711711- IRQL = DISPATCH_LEVEL712712-713713- ==========================================================================714714-*/715715-VOID CntlWaitJoinProc(716716- IN PRTMP_ADAPTER pAd,717717- IN MLME_QUEUE_ELEM *Elem)718718-{719719- USHORT Reason;720720- MLME_AUTH_REQ_STRUCT AuthReq;721721-722722- if (Elem->MsgType == MT2_JOIN_CONF)723723- {724724- NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));725725- if (Reason == MLME_SUCCESS)726726- {727727- // 1. joined an IBSS, we are pretty much done here728728- if (pAd->MlmeAux.BssType == BSS_ADHOC)729729- {730730- //731731- // 5G bands rules of Japan:732732- // Ad hoc must be disabled in W53(ch52,56,60,64) channels.733733- //734734- if ( (pAd->CommonCfg.bIEEE80211H == 1) &&735735- RadarChannelCheck(pAd, pAd->CommonCfg.Channel)736736- )737737- {738738- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;739739- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));740740- return;741741- }742742-743743- LinkUp(pAd, BSS_ADHOC);744744- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;745745- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",746746- pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],747747- pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));748748-749749- pAd->IndicateMediaState = NdisMediaStateConnected;750750- pAd->ExtraInfo = GENERAL_LINK_UP;751751- }752752- // 2. joined a new INFRA network, start from authentication753753- else754754- {755755- {756756- // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first757757- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||758758- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))759759- {760760- AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);761761- }762762- else763763- {764764- AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);765765- }766766- }767767- MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,768768- sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);769769-770770- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;771771- }772772- }773773- else774774- {775775- // 3. failed, try next BSS776776- pAd->MlmeAux.BssIdx++;777777- IterateOnBssTab(pAd);778778- }779779- }780780-}781781-782782-783783-/*784784- ==========================================================================785785- Description:786786-787787- IRQL = DISPATCH_LEVEL788788-789789- ==========================================================================790790-*/791791-VOID CntlWaitStartProc(792792- IN PRTMP_ADAPTER pAd,793793- IN MLME_QUEUE_ELEM *Elem)794794-{795795- USHORT Result;796796-797797- if (Elem->MsgType == MT2_START_CONF)798798- {799799- NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));800800- if (Result == MLME_SUCCESS)801801- {802802- //803803- // 5G bands rules of Japan:804804- // Ad hoc must be disabled in W53(ch52,56,60,64) channels.805805- //806806- if ( (pAd->CommonCfg.bIEEE80211H == 1) &&807807- RadarChannelCheck(pAd, pAd->CommonCfg.Channel)808808- )809809- {810810- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;811811- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));812812- return;813813- }814814-815815- if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)816816- {817817- N_ChannelCheck(pAd);818818- SetCommonHT(pAd);819819- NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, &pAd->CommonCfg.AddHTInfo, sizeof(ADD_HT_INFO_IE));820820- RTMPCheckHt(pAd, BSSID_WCID, &pAd->CommonCfg.HtCapability, &pAd->CommonCfg.AddHTInfo);821821- pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;822822- NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], 16);823823- NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], &pAd->CommonCfg.HtCapability.MCSSet[0], 16);824824- COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);825825-826826- if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&827827- (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))828828- {829829- pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel + 2;830830- }831831- else if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&832832- (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))833833- {834834- pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel - 2;835835- }836836- }837837- else838838- {839839- pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;840840- }841841- LinkUp(pAd, BSS_ADHOC);842842- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;843843- // Before send beacon, driver need do radar detection844844- if ((pAd->CommonCfg.Channel > 14 )845845- && (pAd->CommonCfg.bIEEE80211H == 1)846846- && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))847847- {848848- pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;849849- pAd->CommonCfg.RadarDetect.RDCount = 0;850850- }851851-852852- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",853853- pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],854854- pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));855855- }856856- else857857- {858858- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Start IBSS fail. BUG!!!!!\n"));859859- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;860860- }861861- }862862-}863863-864864-/*865865- ==========================================================================866866- Description:867867-868868- IRQL = DISPATCH_LEVEL869869-870870- ==========================================================================871871-*/872872-VOID CntlWaitAuthProc(873873- IN PRTMP_ADAPTER pAd,874874- IN MLME_QUEUE_ELEM *Elem)875875-{876876- USHORT Reason;877877- MLME_ASSOC_REQ_STRUCT AssocReq;878878- MLME_AUTH_REQ_STRUCT AuthReq;879879-880880- if (Elem->MsgType == MT2_AUTH_CONF)881881- {882882- NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));883883- if (Reason == MLME_SUCCESS)884884- {885885- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));886886- AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,887887- ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);888888-889889- {890890- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,891891- sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);892892-893893- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;894894- }895895- }896896- else897897- {898898- // This fail may because of the AP already keep us in its MAC table without899899- // ageing-out. The previous authentication attempt must have let it remove us.900900- // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.901901- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));902902-903903- {904904- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||905905- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))906906- {907907- // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first908908- AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);909909- }910910- else911911- {912912- AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);913913- }914914- }915915- MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,916916- sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);917917-918918- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;919919- }920920- }921921-}922922-923923-/*924924- ==========================================================================925925- Description:926926-927927- IRQL = DISPATCH_LEVEL928928-929929- ==========================================================================930930-*/931931-VOID CntlWaitAuthProc2(932932- IN PRTMP_ADAPTER pAd,933933- IN MLME_QUEUE_ELEM *Elem)934934-{935935- USHORT Reason;936936- MLME_ASSOC_REQ_STRUCT AssocReq;937937- MLME_AUTH_REQ_STRUCT AuthReq;938938-939939- if (Elem->MsgType == MT2_AUTH_CONF)940940- {941941- NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));942942- if (Reason == MLME_SUCCESS)943943- {944944- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));945945- AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,946946- ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);947947- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,948948- sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);949949-950950- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;951951- }952952- else953953- {954954- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&955955- (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))956956- {957957- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try OPEN system...\n"));958958- AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);959959- MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,960960- sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);961961-962962- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;963963- }964964- else965965- {966966- // not success, try next BSS967967- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, give up; try next BSS\n"));968968- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????969969- pAd->MlmeAux.BssIdx++;970970- IterateOnBssTab(pAd);971971- }972972- }973973- }974974-}975975-976976-/*977977- ==========================================================================978978- Description:979979-980980- IRQL = DISPATCH_LEVEL981981-982982- ==========================================================================983983-*/984984-VOID CntlWaitAssocProc(985985- IN PRTMP_ADAPTER pAd,986986- IN MLME_QUEUE_ELEM *Elem)987987-{988988- USHORT Reason;989989-990990- if (Elem->MsgType == MT2_ASSOC_CONF)991991- {992992- NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));993993- if (Reason == MLME_SUCCESS)994994- {995995- LinkUp(pAd, BSS_INFRA);996996- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;997997- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association successful on BSS #%ld\n",pAd->MlmeAux.BssIdx));998998-999999- if (pAd->CommonCfg.bWirelessEvent)10001000- {10011001- RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);10021002- }10031003- }10041004- else10051005- {10061006- // not success, try next BSS10071007- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association fails on BSS #%ld\n",pAd->MlmeAux.BssIdx));10081008- pAd->MlmeAux.BssIdx++;10091009- IterateOnBssTab(pAd);10101010- }10111011- }10121012-}10131013-10141014-/*10151015- ==========================================================================10161016- Description:10171017-10181018- IRQL = DISPATCH_LEVEL10191019-10201020- ==========================================================================10211021-*/10221022-VOID CntlWaitReassocProc(10231023- IN PRTMP_ADAPTER pAd,10241024- IN MLME_QUEUE_ELEM *Elem)10251025-{10261026- USHORT Result;10271027-10281028- if (Elem->MsgType == MT2_REASSOC_CONF)10291029- {10301030- NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));10311031- if (Result == MLME_SUCCESS)10321032- {10331033- //10341034- // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC10351035- //10361036- LinkUp(pAd, BSS_INFRA);10371037-10381038- // send wireless event - for association10391039- if (pAd->CommonCfg.bWirelessEvent)10401040- RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);10411041-10421042- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;10431043- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));10441044- }10451045- else10461046- {10471047- // reassoc failed, try to pick next BSS in the BSS Table10481048- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd->MlmeAux.RoamIdx));10491049- pAd->MlmeAux.RoamIdx++;10501050- IterateOnBssTab2(pAd);10511051- }10521052- }10531053-}10541054-10551055-10561056-VOID AdhocTurnOnQos(10571057- IN PRTMP_ADAPTER pAd)10581058-{10591059-#define AC0_DEF_TXOP 010601060-#define AC1_DEF_TXOP 010611061-#define AC2_DEF_TXOP 9410621062-#define AC3_DEF_TXOP 4710631063-10641064- // Turn on QOs if use HT rate.10651065- if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)10661066- {10671067- pAd->CommonCfg.APEdcaParm.bValid = TRUE;10681068- pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;10691069- pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;10701070- pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;10711071- pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;10721072-10731073- pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;10741074- pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;10751075- pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;10761076- pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;10771077-10781078- pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;10791079- pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;10801080- pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;10811081- pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;10821082-10831083- pAd->CommonCfg.APEdcaParm.Txop[0] = 0;10841084- pAd->CommonCfg.APEdcaParm.Txop[1] = 0;10851085- pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;10861086- pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;10871087- }10881088- AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);10891089-}10901090-10911091-/*10921092- ==========================================================================10931093- Description:10941094-10951095- IRQL = DISPATCH_LEVEL10961096-10971097- ==========================================================================10981098-*/10991099-VOID LinkUp(11001100- IN PRTMP_ADAPTER pAd,11011101- IN UCHAR BssType)11021102-{11031103- ULONG Now;11041104- UINT32 Data;11051105- BOOLEAN Cancelled;11061106- UCHAR Value = 0, idx;11071107- MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;11081108-11091109- pEntry = &pAd->MacTab.Content[BSSID_WCID];11101110-11111111- //11121112- // ASSOC - DisassocTimeoutAction11131113- // CNTL - Dis-associate successful11141114- // !!! LINK DOWN !!!11151115- // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )11161116- //11171117- // To prevent DisassocTimeoutAction to call Link down after we link up,11181118- // cancel the DisassocTimer no matter what it start or not.11191119- //11201120- RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);11211121-11221122- COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);11231123-11241124- COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);11251125-11261126- // It's quite difficult to tell if a newly added KEY is WEP or CKIP until a new BSS11271127- // is formed (either ASSOC/RE-ASSOC done or IBSS started. LinkUP should be a safe place11281128- // to examine if cipher algorithm switching is required.11291129- //rt2860b. Don't know why need this11301130- SwitchBetweenWepAndCkip(pAd);11311131-11321132-11331133- if (BssType == BSS_ADHOC)11341134- {11351135- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);11361136- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);11371137-11381138- if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&11391139- (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))11401140- {11411141- pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;11421142- }11431143- else if ((pAd->CommonCfg.Channel > 2) &&11441144- (pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&11451145- (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))11461146- {11471147- pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;11481148- }11491149-11501150- if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)11511151- AdhocTurnOnQos(pAd);11521152-11531153- DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));11541154- }11551155- else11561156- {11571157- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);11581158- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);11591159-11601160- DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n" ));11611161- }11621162-11631163- // 3*311641164- // reset Tx beamforming bit11651165- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);11661166- Value &= (~0x01);11671167- Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;11681168- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);11691169-11701170- // Change to AP channel11711171- if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))11721172- {11731173- // Must using 40MHz.11741174- pAd->CommonCfg.BBPCurrentBW = BW_40;11751175- AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);11761176- AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);11771177-11781178- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);11791179- Value &= (~0x18);11801180- Value |= 0x10;11811181- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);11821182-11831183- // RX : control channel at lower11841184- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);11851185- Value &= (~0x20);11861186- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);11871187-11881188- RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);11891189- Data &= 0xfffffffe;11901190- RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);11911191-11921192- if (pAd->MACVersion == 0x28600100)11931193- {11941194- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);11951195- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);11961196- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);11971197- DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));11981198- }11991199-12001200- DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));12011201- }12021202- else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))12031203- {12041204- // Must using 40MHz.12051205- pAd->CommonCfg.BBPCurrentBW = BW_40;12061206- AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);12071207- AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);12081208-12091209- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);12101210- Value &= (~0x18);12111211- Value |= 0x10;12121212- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);12131213-12141214- RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);12151215- Data |= 0x1;12161216- RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);12171217-12181218- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);12191219- Value |= (0x20);12201220- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);12211221-12221222- if (pAd->MACVersion == 0x28600100)12231223- {12241224- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);12251225- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);12261226- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);12271227- DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));12281228- }12291229-12301230- DBGPRINT(RT_DEBUG_TRACE, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));12311231- }12321232- else12331233- {12341234- pAd->CommonCfg.BBPCurrentBW = BW_20;12351235- pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;12361236- AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);12371237- AsicLockChannel(pAd, pAd->CommonCfg.Channel);12381238-12391239- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);12401240- Value &= (~0x18);12411241- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);12421242-12431243- RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);12441244- Data &= 0xfffffffe;12451245- RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);12461246-12471247- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);12481248- Value &= (~0x20);12491249- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);12501250-12511251- if (pAd->MACVersion == 0x28600100)12521252- {12531253- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);12541254- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);12551255- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);12561256- DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));12571257- }12581258-12591259- DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n" ));12601260- }12611261-12621262- RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);12631263- //12641264- // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission12651265- //12661266- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);12671267-12681268- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",12691269- BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));12701270-12711271- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (Density =%d, )\n", pAd->MacTab.Content[BSSID_WCID].MpduDensity));12721272-12731273- AsicSetBssid(pAd, pAd->CommonCfg.Bssid);12741274-12751275- AsicSetSlotTime(pAd, TRUE);12761276- AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);12771277-12781278- // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit12791279- AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, FALSE);12801280-12811281- if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))12821282- {12831283- // Update HT protectionfor based on AP's operating mode.12841284- if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)12851285- {12861286- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);12871287- }12881288- else12891289- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);12901290- }12911291-12921292- NdisZeroMemory(&pAd->DrsCounters, sizeof(COUNTER_DRS));12931293-12941294- NdisGetSystemUpTime(&Now);12951295- pAd->StaCfg.LastBeaconRxTime = Now; // last RX timestamp12961296-12971297- if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&12981298- CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo))12991299- {13001300- MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);13011301- }13021302-13031303- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);13041304-13051305- if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)13061306- {13071307- }13081308- pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;13091309-13101310- if (BssType == BSS_ADHOC)13111311- {13121312- MakeIbssBeacon(pAd);13131313- if ((pAd->CommonCfg.Channel > 14)13141314- && (pAd->CommonCfg.bIEEE80211H == 1)13151315- && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))13161316- {13171317- ; //Do nothing13181318- }13191319- else13201320- {13211321- AsicEnableIbssSync(pAd);13221322- }13231323-13241324- // In ad hoc mode, use MAC table from index 1.13251325- // p.s ASIC use all 0xff as termination of WCID table search.To prevent it's 0xff-ff-ff-ff-ff-ff, Write 0 here.13261326- RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);13271327- RTMP_IO_WRITE32(pAd, 0x1808, 0x00);13281328-13291329- // If WEP is enabled, add key material and cipherAlg into Asic13301330- // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)13311331-13321332- if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)13331333- {13341334- PUCHAR Key;13351335- UCHAR CipherAlg;13361336-13371337- for (idx=0; idx < SHARE_KEY_NUM; idx++)13381338- {13391339- CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;13401340- Key = pAd->SharedKey[BSS0][idx].Key;13411341-13421342- if (pAd->SharedKey[BSS0][idx].KeyLen > 0)13431343- {13441344- // Set key material and cipherAlg to Asic13451345- AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);13461346-13471347- if (idx == pAd->StaCfg.DefaultKeyId)13481348- {13491349- // Update WCID attribute table and IVEIV table for this group key table13501350- RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);13511351- }13521352- }13531353-13541354-13551355- }13561356- }13571357- // If WPANone is enabled, add key material and cipherAlg into Asic13581358- // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)13591359- else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)13601360- {13611361- pAd->StaCfg.DefaultKeyId = 0; // always be zero13621362-13631363- NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));13641364- pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;13651365- NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);13661366-13671367- if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)13681368- {13691369- NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);13701370- NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);13711371- }13721372-13731373- // Decide its ChiperAlg13741374- if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)13751375- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;13761376- else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)13771377- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;13781378- else13791379- {13801380- DBGPRINT(RT_DEBUG_TRACE, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd->StaCfg.PairCipher));13811381- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;13821382- }13831383-13841384- // Set key material and cipherAlg to Asic13851385- AsicAddSharedKeyEntry(pAd,13861386- BSS0,13871387- 0,13881388- pAd->SharedKey[BSS0][0].CipherAlg,13891389- pAd->SharedKey[BSS0][0].Key,13901390- pAd->SharedKey[BSS0][0].TxMic,13911391- pAd->SharedKey[BSS0][0].RxMic);13921392-13931393- // Update WCID attribute table and IVEIV table for this group key table13941394- RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pAd->SharedKey[BSS0][0].CipherAlg, NULL);13951395-13961396- }13971397-13981398- }13991399- else // BSS_INFRA14001400- {14011401- // Check the new SSID with last SSID14021402- while (Cancelled == TRUE)14031403- {14041404- if (pAd->CommonCfg.LastSsidLen == pAd->CommonCfg.SsidLen)14051405- {14061406- if (RTMPCompareMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen) == 0)14071407- {14081408- // Link to the old one no linkdown is required.14091409- break;14101410- }14111411- }14121412- // Send link down event before set to link up14131413- pAd->IndicateMediaState = NdisMediaStateDisconnected;14141414- RTMP_IndicateMediaState(pAd);14151415- pAd->ExtraInfo = GENERAL_LINK_DOWN;14161416- DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));14171417- break;14181418- }14191419-14201420- //14211421- // On WPA mode, Remove All Keys if not connect to the last BSSID14221422- // Key will be set after 4-way handshake.14231423- //14241424- if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))14251425- {14261426- ULONG IV;14271427-14281428- // Remove all WPA keys14291429- RTMPWPARemoveAllKeys(pAd);14301430- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;14311431- pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;14321432-14331433- // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP14341434- // If IV related values are too large in GroupMsg2, AP would ignore this message.14351435- IV = 0;14361436- IV |= (pAd->StaCfg.DefaultKeyId << 30);14371437- AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);14381438- }14391439- // NOTE:14401440- // the decision of using "short slot time" or not may change dynamically due to14411441- // new STA association to the AP. so we have to decide that upon parsing BEACON, not here14421442-14431443- // NOTE:14441444- // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically14451445- // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here14461446-14471447- ComposePsPoll(pAd);14481448- ComposeNullFrame(pAd);14491449-14501450- AsicEnableBssSync(pAd);14511451-14521452- // Add BSSID to WCID search table14531453- AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);14541454-14551455- NdisAcquireSpinLock(&pAd->MacTabLock);14561456- // add this BSSID entry into HASH table14571457- {14581458- UCHAR HashIdx;14591459-14601460- //pEntry = &pAd->MacTab.Content[BSSID_WCID];14611461- HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);14621462- if (pAd->MacTab.Hash[HashIdx] == NULL)14631463- {14641464- pAd->MacTab.Hash[HashIdx] = pEntry;14651465- }14661466- else14671467- {14681468- pCurrEntry = pAd->MacTab.Hash[HashIdx];14691469- while (pCurrEntry->pNext != NULL)14701470- pCurrEntry = pCurrEntry->pNext;14711471- pCurrEntry->pNext = pEntry;14721472- }14731473- }14741474- NdisReleaseSpinLock(&pAd->MacTabLock);14751475-14761476-14771477- // If WEP is enabled, add paiewise and shared key14781478- if (((pAd->StaCfg.WpaSupplicantUP)&&14791479- (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&14801480- (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||14811481- ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&14821482- (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))14831483- {14841484- PUCHAR Key;14851485- UCHAR CipherAlg;14861486-14871487- for (idx=0; idx < SHARE_KEY_NUM; idx++)14881488- {14891489- CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;14901490- Key = pAd->SharedKey[BSS0][idx].Key;14911491-14921492- if (pAd->SharedKey[BSS0][idx].KeyLen > 0)14931493- {14941494- // Set key material and cipherAlg to Asic14951495- AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);14961496-14971497- if (idx == pAd->StaCfg.DefaultKeyId)14981498- {14991499- // Assign group key info15001500- RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);15011501-15021502- // Assign pairwise key info15031503- RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);15041504- }15051505- }15061506- }15071507- }15081508-15091509- // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode15101510- // should wait until at least 2 active nodes in this BSSID.15111511- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);15121512-15131513- // For GUI ++15141514- if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)15151515- {15161516- pAd->IndicateMediaState = NdisMediaStateConnected;15171517- pAd->ExtraInfo = GENERAL_LINK_UP;15181518- RTMP_IndicateMediaState(pAd);15191519- }15201520- // --15211521-15221522- // Add BSSID in my MAC Table.15231523- NdisAcquireSpinLock(&pAd->MacTabLock);15241524- RTMPMoveMemory(pAd->MacTab.Content[BSSID_WCID].Addr, pAd->CommonCfg.Bssid, MAC_ADDR_LEN);15251525- pAd->MacTab.Content[BSSID_WCID].Aid = BSSID_WCID;15261526- pAd->MacTab.Content[BSSID_WCID].pAd = pAd;15271527- pAd->MacTab.Content[BSSID_WCID].ValidAsCLI = TRUE; //Although this is bssid..still set ValidAsCl15281528- pAd->MacTab.Size = 1; // infra mode always set MACtab size =1.15291529- pAd->MacTab.Content[BSSID_WCID].Sst = SST_ASSOC;15301530- pAd->MacTab.Content[BSSID_WCID].AuthState = SST_ASSOC;15311531- pAd->MacTab.Content[BSSID_WCID].AuthMode = pAd->StaCfg.AuthMode;15321532- pAd->MacTab.Content[BSSID_WCID].WepStatus = pAd->StaCfg.WepStatus;15331533- NdisReleaseSpinLock(&pAd->MacTabLock);15341534-15351535- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",15361536- pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));15371537-15381538- MlmeUpdateTxRates(pAd, TRUE, BSS0);15391539- MlmeUpdateHtTxRates(pAd, BSS0);15401540- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));15411541-15421542- if (pAd->CommonCfg.bAggregationCapable)15431543- {15441544- if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)15451545- {15461546-15471547- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);15481548- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);15491549- RTMPSetPiggyBack(pAd, TRUE);15501550- DBGPRINT(RT_DEBUG_TRACE, ("Turn on Piggy-Back\n"));15511551- }15521552- else if (pAd->MlmeAux.APRalinkIe & 0x00000001)15531553- {15541554- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);15551555- }15561556- }15571557-15581558- if (pAd->MlmeAux.APRalinkIe != 0x0)15591559- {15601560- if (CLIENT_STATUS_TEST_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RDG_CAPABLE))15611561- {15621562- AsicEnableRDG(pAd);15631563- }15641564-15651565- OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);15661566- CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);15671567- }15681568- else15691569- {15701570- OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);15711571- CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);15721572- }15731573- }15741574-15751575- DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n", pAd->CommonCfg.BACapability.word, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));15761576-15771577- // Set LED15781578- RTMPSetLED(pAd, LED_LINK_UP);15791579-15801580- pAd->Mlme.PeriodicRound = 0;15811581- pAd->Mlme.OneSecPeriodicRound = 0;15821582- pAd->bConfigChanged = FALSE; // Reset config flag15831583- pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up15841584-15851585- // Set asic auto fall back15861586- {15871587- PUCHAR pTable;15881588- UCHAR TableSize = 0;15891589-15901590- MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], &pTable, &TableSize, &pAd->CommonCfg.TxRateIndex);15911591- AsicUpdateAutoFallBackTable(pAd, pTable);15921592- }15931593-15941594- NdisAcquireSpinLock(&pAd->MacTabLock);15951595- pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;15961596- pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;15971597- if (pAd->StaCfg.bAutoTxRateSwitch == FALSE)15981598- {15991599- pEntry->bAutoTxRateSwitch = FALSE;16001600-16011601- if (pEntry->HTPhyMode.field.MCS == 32)16021602- pEntry->HTPhyMode.field.ShortGI = GI_800;16031603-16041604- if ((pEntry->HTPhyMode.field.MCS > MCS_7) || (pEntry->HTPhyMode.field.MCS == 32))16051605- pEntry->HTPhyMode.field.STBC = STBC_NONE;16061606-16071607- // If the legacy mode is set, overwrite the transmit setting of this entry.16081608- if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)16091609- RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);16101610- }16111611- else16121612- pEntry->bAutoTxRateSwitch = TRUE;16131613- NdisReleaseSpinLock(&pAd->MacTabLock);16141614-16151615- // Let Link Status Page display first initial rate.16161616- pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);16171617- // Select DAC according to HT or Legacy16181618- if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00)16191619- {16201620- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);16211621- Value &= (~0x18);16221622- if (pAd->Antenna.field.TxPath == 2)16231623- {16241624- Value |= 0x10;16251625- }16261626- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);16271627- }16281628- else16291629- {16301630- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);16311631- Value &= (~0x18);16321632- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);16331633- }16341634-16351635- if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)16361636- {16371637- }16381638- else if (pEntry->MaxRAmpduFactor == 0)16391639- {16401640- // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.16411641- // Because our Init value is 1 at MACRegTable.16421642- RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);16431643- }16441644-16451645- // Patch for Marvel AP to gain high throughput16461646- // Need to set as following,16471647- // 1. Set txop in register-EDCA_AC0_CFG as 0x6016481648- // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero16491649- // 3. PBF_MAX_PCNT as 0x1F3FBF9F16501650- // 4. kick per two packets when dequeue16511651- //16521652- // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable16531653- //16541654- // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.16551655- if (!((pAd->CommonCfg.RxStream == 1)&&(pAd->CommonCfg.TxStream == 1)) &&16561656- (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))16571657- || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE))))16581658- {16591659- RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);16601660- Data &= 0xFFFFFF00;16611661- RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);16621662-16631663- RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);16641664- DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));16651665- }16661666- else16671667- if (pAd->CommonCfg.bEnableTxBurst)16681668- {16691669- RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);16701670- Data &= 0xFFFFFF00;16711671- Data |= 0x60;16721672- RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);16731673- pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;16741674-16751675- RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);16761676- DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));16771677- }16781678- else16791679- {16801680- RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);16811681- Data &= 0xFFFFFF00;16821682- RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);16831683-16841684- RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);16851685- DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));16861686- }16871687-16881688- // Re-check to turn on TX burst or not.16891689- if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) && ((STA_WEP_ON(pAd))||(STA_TKIP_ON(pAd))))16901690- {16911691- pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;16921692- if (pAd->CommonCfg.bEnableTxBurst)16931693- {16941694- UINT32 MACValue = 0;16951695- // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.16961696- // I didn't change PBF_MAX_PCNT setting.16971697- RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);16981698- MACValue &= 0xFFFFFF00;16991699- RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);17001700- pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;17011701- }17021702- }17031703- else17041704- {17051705- pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;17061706- }17071707-17081708- pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;17091709- COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);17101710- DBGPRINT(RT_DEBUG_TRACE, ("!!!pAd->bNextDisableRxBA= %d \n", pAd->CommonCfg.IOTestParm.bNextDisableRxBA));17111711- // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap17121712- // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.17131713- // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.17141714-17151715- if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled)17161716- {17171717- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;17181718- pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;17191719- }17201720-17211721- NdisAcquireSpinLock(&pAd->MacTabLock);17221722- pEntry->PortSecured = pAd->StaCfg.PortSecured;17231723- NdisReleaseSpinLock(&pAd->MacTabLock);17241724-17251725- //17261726- // Patch Atheros AP TX will breakdown issue.17271727- // AP Model: DLink DWL-8200AP17281728- //17291729- if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && STA_TKIP_ON(pAd))17301730- {17311731- RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);17321732- }17331733- else17341734- {17351735- RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);17361736- }17371737-17381738- RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);17391739-}17401740-17411741-/*17421742- ==========================================================================17431743-17441744- Routine Description:17451745- Disconnect current BSSID17461746-17471747- Arguments:17481748- pAd - Pointer to our adapter17491749- IsReqFromAP - Request from AP17501750-17511751- Return Value:17521752- None17531753-17541754- IRQL = DISPATCH_LEVEL17551755-17561756- Note:17571757- We need more information to know it's this requst from AP.17581758- If yes! we need to do extra handling, for example, remove the WPA key.17591759- Otherwise on 4-way handshaking will faied, since the WPA key didn't be17601760- remove while auto reconnect.17611761- Disconnect request from AP, it means we will start afresh 4-way handshaking17621762- on WPA mode.17631763-17641764- ==========================================================================17651765-*/17661766-VOID LinkDown(17671767- IN PRTMP_ADAPTER pAd,17681768- IN BOOLEAN IsReqFromAP)17691769-{17701770- UCHAR i, ByteValue = 0;17711771-17721772- // Do nothing if monitor mode is on17731773- if (MONITOR_ON(pAd))17741774- return;17751775-17761776- if (pAd->CommonCfg.bWirelessEvent)17771777- {17781778- RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);17791779- }17801780-17811781- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));17821782- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);17831783-17841784- if (ADHOC_ON(pAd)) // Adhoc mode link down17851785- {17861786- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));17871787-17881788- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);17891789- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);17901790- pAd->IndicateMediaState = NdisMediaStateDisconnected;17911791- RTMP_IndicateMediaState(pAd);17921792- pAd->ExtraInfo = GENERAL_LINK_DOWN;17931793- BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);17941794- DBGPRINT(RT_DEBUG_TRACE, ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));17951795- }17961796- else // Infra structure mode17971797- {17981798- DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));17991799-18001800- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);18011801- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);18021802-18031803- // Saved last SSID for linkup comparison18041804- pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;18051805- NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen);18061806- COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);18071807- if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)18081808- {18091809- pAd->IndicateMediaState = NdisMediaStateDisconnected;18101810- RTMP_IndicateMediaState(pAd);18111811- pAd->ExtraInfo = GENERAL_LINK_DOWN;18121812- DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));18131813- pAd->MlmeAux.CurrReqIsFromNdis = FALSE;18141814- }18151815- else18161816- {18171817- //18181818- // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.18191819- // Otherwise lost beacon or receive De-Authentication from AP,18201820- // then we should delete BSSID from BssTable.18211821- // If we don't delete from entry, roaming will fail.18221822- //18231823- BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);18241824- }18251825-18261826- // restore back to -18271827- // 1. long slot (20 us) or short slot (9 us) time18281828- // 2. turn on/off RTS/CTS and/or CTS-to-self protection18291829- // 3. short preamble18301830- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);18311831-18321832- if (pAd->StaCfg.CCXAdjacentAPReportFlag == TRUE)18331833- {18341834- //18351835- // Record current AP's information.18361836- // for later used reporting Adjacent AP report.18371837- //18381838- pAd->StaCfg.CCXAdjacentAPChannel = pAd->CommonCfg.Channel;18391839- pAd->StaCfg.CCXAdjacentAPSsidLen = pAd->CommonCfg.SsidLen;18401840- NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);18411841- COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);18421842- }18431843- }18441844-18451845- for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)18461846- {18471847- if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)18481848- MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, pAd->MacTab.Content[i].Addr);18491849- }18501850-18511851- pAd->StaCfg.CCXQosECWMin = 4;18521852- pAd->StaCfg.CCXQosECWMax = 10;18531853-18541854- AsicSetSlotTime(pAd, TRUE); //FALSE);18551855- AsicSetEdcaParm(pAd, NULL);18561856-18571857- // Set LED18581858- RTMPSetLED(pAd, LED_LINK_DOWN);18591859- pAd->LedIndicatorStregth = 0xF0;18601860- RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.18611861-18621862- AsicDisableSync(pAd);18631863-18641864- pAd->Mlme.PeriodicRound = 0;18651865- pAd->Mlme.OneSecPeriodicRound = 0;18661866-18671867- if (pAd->StaCfg.BssType == BSS_INFRA)18681868- {18691869- // Remove StaCfg Information after link down18701870- NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);18711871- NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);18721872- pAd->CommonCfg.SsidLen = 0;18731873- }18741874-18751875- NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(HT_CAPABILITY_IE));18761876- NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(ADD_HT_INFO_IE));18771877- pAd->MlmeAux.HtCapabilityLen = 0;18781878- pAd->MlmeAux.NewExtChannelOffset = 0xff;18791879-18801880- // Reset WPA-PSK state. Only reset when supplicant enabled18811881- if (pAd->StaCfg.WpaState != SS_NOTUSE)18821882- {18831883- pAd->StaCfg.WpaState = SS_START;18841884- // Clear Replay counter18851885- NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);18861886- }18871887-18881888-18891889- //18901890- // if link down come from AP, we need to remove all WPA keys on WPA mode.18911891- // otherwise will cause 4-way handshaking failed, since the WPA key not empty.18921892- //18931893- if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))18941894- {18951895- // Remove all WPA keys18961896- RTMPWPARemoveAllKeys(pAd);18971897- }18981898-18991899- // 802.1x port control19001900-19011901- // Prevent clear PortSecured here with static WEP19021902- // NetworkManger set security policy first then set SSID to connect AP.19031903- if (pAd->StaCfg.WpaSupplicantUP &&19041904- (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&19051905- (pAd->StaCfg.IEEE8021X == FALSE))19061906- {19071907- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;19081908- }19091909- else19101910- {19111911- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;19121912- pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;19131913- }19141914-19151915- NdisAcquireSpinLock(&pAd->MacTabLock);19161916- pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;19171917- NdisReleaseSpinLock(&pAd->MacTabLock);19181918-19191919- pAd->StaCfg.MicErrCnt = 0;19201920-19211921- // Turn off Ckip control flag19221922- pAd->StaCfg.bCkipOn = FALSE;19231923- pAd->StaCfg.CCXEnable = FALSE;19241924-19251925- pAd->IndicateMediaState = NdisMediaStateDisconnected;19261926- // Update extra information to link is up19271927- pAd->ExtraInfo = GENERAL_LINK_DOWN;19281928-19291929- pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;19301930-19311931- // Reset the Current AP's IP address19321932- NdisZeroMemory(pAd->StaCfg.AironetIPAddress, 4);19331933-#ifdef RT287019341934- pAd->bUsbTxBulkAggre = FALSE;19351935-#endif // RT2870 //19361936-19371937- // Clean association information19381938- NdisZeroMemory(&pAd->StaCfg.AssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));19391939- pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);19401940- pAd->StaCfg.ReqVarIELen = 0;19411941- pAd->StaCfg.ResVarIELen = 0;19421942-19431943- //19441944- // Reset RSSI value after link down19451945- //19461946- pAd->StaCfg.RssiSample.AvgRssi0 = 0;19471947- pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;19481948- pAd->StaCfg.RssiSample.AvgRssi1 = 0;19491949- pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;19501950- pAd->StaCfg.RssiSample.AvgRssi2 = 0;19511951- pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;19521952-19531953- // Restore MlmeRate19541954- pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;19551955- pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;19561956-19571957- //19581958- // After Link down, reset piggy-back setting in ASIC. Disable RDG.19591959- //19601960- if (pAd->CommonCfg.BBPCurrentBW == BW_40)19611961- {19621962- pAd->CommonCfg.BBPCurrentBW = BW_20;19631963- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);19641964- ByteValue &= (~0x18);19651965- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);19661966- }19671967-19681968- // Reset DAC19691969- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);19701970- ByteValue &= (~0x18);19711971- if (pAd->Antenna.field.TxPath == 2)19721972- {19731973- ByteValue |= 0x10;19741974- }19751975- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);19761976-19771977- RTMPSetPiggyBack(pAd,FALSE);19781978- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);19791979-19801980- pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;19811981-19821982- // Restore all settings in the following.19831983- AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);19841984- AsicDisableRDG(pAd);19851985- pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;19861986- pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;19871987-19881988- RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);19891989- RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);19901990-19911991- {19921992- union iwreq_data wrqu;19931993- memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);19941994- wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);19951995- }19961996-19971997-#ifdef RT30xx19981998- if (IS_RT3090(pAd))19991999- {20002000- UINT32 macdata;20012001- // disable MMPS BBP control register20022002- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &ByteValue);20032003- ByteValue &= ~(0x04); //bit 220042004- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, ByteValue);20052005-20062006- // disable MMPS MAC control register20072007- RTMP_IO_READ32(pAd, 0x1210, &macdata);20082008- macdata &= ~(0x09); //bit 0, 320092009- RTMP_IO_WRITE32(pAd, 0x1210, macdata);20102010- }20112011-#endif // RT30xx //20122012-20132013-}20142014-20152015-/*20162016- ==========================================================================20172017- Description:20182018-20192019- IRQL = DISPATCH_LEVEL20202020-20212021- ==========================================================================20222022-*/20232023-VOID IterateOnBssTab(20242024- IN PRTMP_ADAPTER pAd)20252025-{20262026- MLME_START_REQ_STRUCT StartReq;20272027- MLME_JOIN_REQ_STRUCT JoinReq;20282028- ULONG BssIdx;20292029-20302030- // Change the wepstatus to original wepstatus20312031- pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;20322032- pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;20332033- pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;20342034-20352035- BssIdx = pAd->MlmeAux.BssIdx;20362036- if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)20372037- {20382038- // Check cipher suite, AP must have more secured cipher than station setting20392039- // Set the Pairwise and Group cipher to match the intended AP setting20402040- // We can only connect to AP with less secured cipher setting20412041- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))20422042- {20432043- pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;20442044-20452045- if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)20462046- pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;20472047- else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)20482048- pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;20492049- else // There is no PairCipher Aux, downgrade our capability to TKIP20502050- pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;20512051- }20522052- else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))20532053- {20542054- pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;20552055-20562056- if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)20572057- pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;20582058- else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)20592059- pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;20602060- else // There is no PairCipher Aux, downgrade our capability to TKIP20612061- pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;20622062-20632063- // RSN capability20642064- pAd->StaCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;20652065- }20662066-20672067- // Set Mix cipher flag20682068- pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;20692069- if (pAd->StaCfg.bMixCipher == TRUE)20702070- {20712071- // If mix cipher, re-build RSNIE20722072- RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);20732073- }20742074-20752075- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr));20762076- JoinParmFill(pAd, &JoinReq, BssIdx);20772077- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT),20782078- &JoinReq);20792079- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;20802080- }20812081- else if (pAd->StaCfg.BssType == BSS_ADHOC)20822082- {20832083- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));20842084- StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);20852085- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);20862086- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;20872087- }20882088- else // no more BSS20892089- {20902090- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All roaming failed, stay @ ch #%d\n", pAd->CommonCfg.Channel));20912091- AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);20922092- AsicLockChannel(pAd, pAd->CommonCfg.Channel);20932093- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;20942094- }20952095-}20962096-20972097-// for re-association only20982098-// IRQL = DISPATCH_LEVEL20992099-VOID IterateOnBssTab2(21002100- IN PRTMP_ADAPTER pAd)21012101-{21022102- MLME_REASSOC_REQ_STRUCT ReassocReq;21032103- ULONG BssIdx;21042104- BSS_ENTRY *pBss;21052105-21062106- BssIdx = pAd->MlmeAux.RoamIdx;21072107- pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];21082108-21092109- if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)21102110- {21112111- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr));21122112-21132113- AsicSwitchChannel(pAd, pBss->Channel, FALSE);21142114- AsicLockChannel(pAd, pBss->Channel);21152115-21162116- // reassociate message has the same structure as associate message21172117- AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,21182118- ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);21192119- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,21202120- sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);21212121-21222122- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;21232123- }21242124- else // no more BSS21252125- {21262126- DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All fast roaming failed, back to ch #%d\n",pAd->CommonCfg.Channel));21272127- AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);21282128- AsicLockChannel(pAd, pAd->CommonCfg.Channel);21292129- pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;21302130- }21312131-}21322132-21332133-/*21342134- ==========================================================================21352135- Description:21362136-21372137- IRQL = DISPATCH_LEVEL21382138-21392139- ==========================================================================21402140-*/21412141-VOID JoinParmFill(21422142- IN PRTMP_ADAPTER pAd,21432143- IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,21442144- IN ULONG BssIdx)21452145-{21462146- JoinReq->BssIdx = BssIdx;21472147-}21482148-21492149-/*21502150- ==========================================================================21512151- Description:21522152-21532153- IRQL = DISPATCH_LEVEL21542154-21552155- ==========================================================================21562156-*/21572157-VOID ScanParmFill(21582158- IN PRTMP_ADAPTER pAd,21592159- IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,21602160- IN CHAR Ssid[],21612161- IN UCHAR SsidLen,21622162- IN UCHAR BssType,21632163- IN UCHAR ScanType)21642164-{21652165- NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);21662166- ScanReq->SsidLen = SsidLen;21672167- NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);21682168- ScanReq->BssType = BssType;21692169- ScanReq->ScanType = ScanType;21702170-}21712171-21722172-/*21732173- ==========================================================================21742174- Description:21752175-21762176- IRQL = DISPATCH_LEVEL21772177-21782178- ==========================================================================21792179-*/21802180-VOID StartParmFill(21812181- IN PRTMP_ADAPTER pAd,21822182- IN OUT MLME_START_REQ_STRUCT *StartReq,21832183- IN CHAR Ssid[],21842184- IN UCHAR SsidLen)21852185-{21862186- ASSERT(SsidLen <= MAX_LEN_OF_SSID);21872187- NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);21882188- StartReq->SsidLen = SsidLen;21892189-}21902190-21912191-/*21922192- ==========================================================================21932193- Description:21942194-21952195- IRQL = DISPATCH_LEVEL21962196-21972197- ==========================================================================21982198-*/21992199-VOID AuthParmFill(22002200- IN PRTMP_ADAPTER pAd,22012201- IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,22022202- IN PUCHAR pAddr,22032203- IN USHORT Alg)22042204-{22052205- COPY_MAC_ADDR(AuthReq->Addr, pAddr);22062206- AuthReq->Alg = Alg;22072207- AuthReq->Timeout = AUTH_TIMEOUT;22082208-}22092209-22102210-/*22112211- ==========================================================================22122212- Description:22132213-22142214- IRQL = DISPATCH_LEVEL22152215-22162216- ==========================================================================22172217- */22182218-22192219-22202220-#ifdef RT287022212221-22222222-VOID MlmeCntlConfirm(22232223- IN PRTMP_ADAPTER pAd,22242224- IN ULONG MsgType,22252225- IN USHORT Msg)22262226-{22272227- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(USHORT), &Msg);22282228-}22292229-22302230-VOID ComposePsPoll(22312231- IN PRTMP_ADAPTER pAd)22322232-{22332233- PTXINFO_STRUC pTxInfo;22342234- PTXWI_STRUC pTxWI;22352235-22362236- DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));22372237- NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));22382238-22392239- pAd->PsPollFrame.FC.PwrMgmt = 0;22402240- pAd->PsPollFrame.FC.Type = BTYPE_CNTL;22412241- pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;22422242- pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;22432243- COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);22442244- COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);22452245-22462246- RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0], 100);22472247- pTxInfo = (PTXINFO_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0];22482248- RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(PSPOLL_FRAME)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);22492249- pTxWI = (PTXWI_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];22502250- RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(PSPOLL_FRAME)),22512251- 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);22522252- RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->PsPollFrame, sizeof(PSPOLL_FRAME));22532253- // Append 4 extra zero bytes.22542254- pAd->PsPollContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(PSPOLL_FRAME) + 4;22552255-}22562256-22572257-// IRQL = DISPATCH_LEVEL22582258-VOID ComposeNullFrame(22592259- IN PRTMP_ADAPTER pAd)22602260-{22612261- PTXINFO_STRUC pTxInfo;22622262- PTXWI_STRUC pTxWI;22632263-22642264- NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));22652265- pAd->NullFrame.FC.Type = BTYPE_DATA;22662266- pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;22672267- pAd->NullFrame.FC.ToDs = 1;22682268- COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);22692269- COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);22702270- COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);22712271- RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], 100);22722272- pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];22732273- RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);22742274- pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];22752275- RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),22762276- 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);22772277- RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));22782278- pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;22792279-}22802280-#endif // RT2870 //22812281-22822282-22832283-/*22842284- ==========================================================================22852285- Description:22862286- Pre-build a BEACON frame in the shared memory22872287-22882288- IRQL = PASSIVE_LEVEL22892289- IRQL = DISPATCH_LEVEL22902290-22912291- ==========================================================================22922292-*/22932293-ULONG MakeIbssBeacon(22942294- IN PRTMP_ADAPTER pAd)22952295-{22962296- UCHAR DsLen = 1, IbssLen = 2;22972297- UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};22982298- HEADER_802_11 BcnHdr;22992299- USHORT CapabilityInfo;23002300- LARGE_INTEGER FakeTimestamp;23012301- ULONG FrameLen = 0;23022302- PTXWI_STRUC pTxWI = &pAd->BeaconTxWI;23032303- CHAR *pBeaconFrame = pAd->BeaconBuf;23042304- BOOLEAN Privacy;23052305- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];23062306- UCHAR SupRateLen = 0;23072307- UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];23082308- UCHAR ExtRateLen = 0;23092309- UCHAR RSNIe = IE_WPA;23102310-23112311- if ((pAd->CommonCfg.PhyMode == PHY_11B) && (pAd->CommonCfg.Channel <= 14))23122312- {23132313- SupRate[0] = 0x82; // 1 mbps23142314- SupRate[1] = 0x84; // 2 mbps23152315- SupRate[2] = 0x8b; // 5.5 mbps23162316- SupRate[3] = 0x96; // 11 mbps23172317- SupRateLen = 4;23182318- ExtRateLen = 0;23192319- }23202320- else if (pAd->CommonCfg.Channel > 14)23212321- {23222322- SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate23232323- SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps23242324- SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate23252325- SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps23262326- SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate23272327- SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps23282328- SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps23292329- SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps23302330- SupRateLen = 8;23312331- ExtRateLen = 0;23322332-23332333- //23342334- // Also Update MlmeRate & RtsRate for G only & A only23352335- //23362336- pAd->CommonCfg.MlmeRate = RATE_6;23372337- pAd->CommonCfg.RtsRate = RATE_6;23382338- pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;23392339- pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];23402340- pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;23412341- pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];23422342- }23432343- else23442344- {23452345- SupRate[0] = 0x82; // 1 mbps23462346- SupRate[1] = 0x84; // 2 mbps23472347- SupRate[2] = 0x8b; // 5.5 mbps23482348- SupRate[3] = 0x96; // 11 mbps23492349- SupRateLen = 4;23502350-23512351- ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,23522352- ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps23532353- ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,23542354- ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps23552355- ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,23562356- ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps23572357- ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps23582358- ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps23592359- ExtRateLen = 8;23602360- }23612361-23622362- pAd->StaActive.SupRateLen = SupRateLen;23632363- NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);23642364- pAd->StaActive.ExtRateLen = ExtRateLen;23652365- NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);23662366-23672367- // compose IBSS beacon frame23682368- MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->CommonCfg.Bssid);23692369- Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||23702370- (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||23712371- (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);23722372- CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);23732373-23742374- MakeOutgoingFrame(pBeaconFrame, &FrameLen,23752375- sizeof(HEADER_802_11), &BcnHdr,23762376- TIMESTAMP_LEN, &FakeTimestamp,23772377- 2, &pAd->CommonCfg.BeaconPeriod,23782378- 2, &CapabilityInfo,23792379- 1, &SsidIe,23802380- 1, &pAd->CommonCfg.SsidLen,23812381- pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,23822382- 1, &SupRateIe,23832383- 1, &SupRateLen,23842384- SupRateLen, SupRate,23852385- 1, &DsIe,23862386- 1, &DsLen,23872387- 1, &pAd->CommonCfg.Channel,23882388- 1, &IbssIe,23892389- 1, &IbssLen,23902390- 2, &pAd->StaActive.AtimWin,23912391- END_OF_ARGS);23922392-23932393- // add ERP_IE and EXT_RAE IE of in 802.11g23942394- if (ExtRateLen)23952395- {23962396- ULONG tmp;23972397-23982398- MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,23992399- 3, LocalErpIe,24002400- 1, &ExtRateIe,24012401- 1, &ExtRateLen,24022402- ExtRateLen, ExtRate,24032403- END_OF_ARGS);24042404- FrameLen += tmp;24052405- }24062406-24072407- // If adhoc secruity is set for WPA-None, append the cipher suite IE24082408- if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)24092409- {24102410- ULONG tmp;24112411- RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);24122412-24132413- MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,24142414- 1, &RSNIe,24152415- 1, &pAd->StaCfg.RSNIE_Len,24162416- pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,24172417- END_OF_ARGS);24182418- FrameLen += tmp;24192419- }24202420-24212421- if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))24222422- {24232423- ULONG TmpLen;24242424- UCHAR HtLen, HtLen1;24252425-24262426- // add HT Capability IE24272427- HtLen = sizeof(pAd->CommonCfg.HtCapability);24282428- HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);24292429-24302430- MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,24312431- 1, &HtCapIe,24322432- 1, &HtLen,24332433- HtLen, &pAd->CommonCfg.HtCapability,24342434- 1, &AddHtInfoIe,24352435- 1, &HtLen1,24362436- HtLen1, &pAd->CommonCfg.AddHTInfo,24372437- END_OF_ARGS);24382438-24392439- FrameLen += TmpLen;24402440- }24412441-24422442- //beacon use reserved WCID 0xff24432443- if (pAd->CommonCfg.Channel > 14)24442444- {24452445- RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,24462446- PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);24472447- }24482448- else24492449- {24502450- // Set to use 1Mbps for Adhoc beacon.24512451- HTTRANSMIT_SETTING Transmit;24522452- Transmit.word = 0;24532453- RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,24542454- PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);24552455- }24562456-24572457- DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",24582458- FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));24592459- return FrameLen;24602460-}24612461-11+#include "../../rt2870/sta/connect.c"24622
+1-2429
drivers/staging/rt3070/sta/rtmp_data.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- rtmp_data.c2929-3030- Abstract:3131- Data path subroutines3232-3333- Revision History:3434- Who When What3535- -------- ---------- ----------------------------------------------3636- John Aug/17/04 major modification for RT2561/26613737- Jan Lee Mar/17/06 major modification for RT2860 New Ring Design3838-*/3939-#include "../rt_config.h"4040-4141-4242-4343-VOID STARxEAPOLFrameIndicate(4444- IN PRTMP_ADAPTER pAd,4545- IN MAC_TABLE_ENTRY *pEntry,4646- IN RX_BLK *pRxBlk,4747- IN UCHAR FromWhichBSSID)4848-{4949- PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);5050- PRXWI_STRUC pRxWI = pRxBlk->pRxWI;5151- UCHAR *pTmpBuf;5252-5353-5454- if (pAd->StaCfg.WpaSupplicantUP)5555- {5656- // All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon)5757- // TBD : process fragmented EAPol frames5858- {5959- // In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable6060- if ( pAd->StaCfg.IEEE8021X == TRUE &&6161- (EAP_CODE_SUCCESS == WpaCheckEapCode(pAd, pRxBlk->pData, pRxBlk->DataSize, LENGTH_802_1_H)))6262- {6363- PUCHAR Key;6464- UCHAR CipherAlg;6565- int idx = 0;6666-6767- DBGPRINT_RAW(RT_DEBUG_TRACE, ("Receive EAP-SUCCESS Packet\n"));6868- STA_PORT_SECURED(pAd);6969-7070- if (pAd->StaCfg.IEEE8021x_required_keys == FALSE)7171- {7272- idx = pAd->StaCfg.DesireSharedKeyId;7373- CipherAlg = pAd->StaCfg.DesireSharedKey[idx].CipherAlg;7474- Key = pAd->StaCfg.DesireSharedKey[idx].Key;7575-7676- if (pAd->StaCfg.DesireSharedKey[idx].KeyLen > 0)7777- {7878-#ifdef RT28707979- union8080- {8181- char buf[sizeof(NDIS_802_11_WEP)+MAX_LEN_OF_KEY- 1];8282- NDIS_802_11_WEP keyinfo;8383- } WepKey;8484- int len;8585-8686-8787- NdisZeroMemory(&WepKey, sizeof(WepKey));8888- len =pAd->StaCfg.DesireSharedKey[idx].KeyLen;8989-9090- NdisMoveMemory(WepKey.keyinfo.KeyMaterial,9191- pAd->StaCfg.DesireSharedKey[idx].Key,9292- pAd->StaCfg.DesireSharedKey[idx].KeyLen);9393-9494- WepKey.keyinfo.KeyIndex = 0x80000000 + idx;9595- WepKey.keyinfo.KeyLength = len;9696- pAd->SharedKey[BSS0][idx].KeyLen =(UCHAR) (len <= 5 ? 5 : 13);9797-9898- pAd->IndicateMediaState = NdisMediaStateConnected;9999- pAd->ExtraInfo = GENERAL_LINK_UP;100100- // need to enqueue cmd to thread101101- RTUSBEnqueueCmdFromNdis(pAd, OID_802_11_ADD_WEP, TRUE, &WepKey, sizeof(WepKey.keyinfo) + len - 1);102102-#endif // RT2870 //103103- // For Preventing ShardKey Table is cleared by remove key procedure.104104- pAd->SharedKey[BSS0][idx].CipherAlg = CipherAlg;105105- pAd->SharedKey[BSS0][idx].KeyLen = pAd->StaCfg.DesireSharedKey[idx].KeyLen;106106- NdisMoveMemory(pAd->SharedKey[BSS0][idx].Key,107107- pAd->StaCfg.DesireSharedKey[idx].Key,108108- pAd->StaCfg.DesireSharedKey[idx].KeyLen);109109- }110110- }111111- }112112-113113- Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);114114- return;115115- }116116- }117117- else118118- {119119- // Special DATA frame that has to pass to MLME120120- // 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process121121- // 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process122122- {123123- pTmpBuf = pRxBlk->pData - LENGTH_802_11;124124- NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11);125125- REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pTmpBuf, pRxBlk->DataSize + LENGTH_802_11, pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);126126- DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! report EAPOL/AIRONET DATA to MLME (len=%d) !!!\n", pRxBlk->DataSize));127127- }128128- }129129-130130- RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);131131- return;132132-133133-}134134-135135-VOID STARxDataFrameAnnounce(136136- IN PRTMP_ADAPTER pAd,137137- IN MAC_TABLE_ENTRY *pEntry,138138- IN RX_BLK *pRxBlk,139139- IN UCHAR FromWhichBSSID)140140-{141141-142142- // non-EAP frame143143- if (!RTMPCheckWPAframe(pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID))144144- {145145-146146- {147147- // drop all non-EAP DATA frame before148148- // this client's Port-Access-Control is secured149149- if (pRxBlk->pHeader->FC.Wep)150150- {151151- // unsupported cipher suite152152- if (pAd->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)153153- {154154- // release packet155155- RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);156156- return;157157- }158158- }159159- else160160- {161161- // encryption in-use but receive a non-EAPOL clear text frame, drop it162162- if ((pAd->StaCfg.WepStatus != Ndis802_11EncryptionDisabled) &&163163- (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))164164- {165165- // release packet166166- RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);167167- return;168168- }169169- }170170- }171171- RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP);172172- if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK))173173- {174174- // Normal legacy, AMPDU or AMSDU175175- CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, FromWhichBSSID);176176-177177- }178178- else179179- {180180- // ARALINK181181- CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);182182- }183183- }184184- else185185- {186186- RX_BLK_SET_FLAG(pRxBlk, fRX_EAP);187187-188188- if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0))189189- {190190- Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);191191- }192192- else193193- {194194- // Determin the destination of the EAP frame195195- // to WPA state machine or upper layer196196- STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);197197- }198198- }199199-}200200-201201-202202-// For TKIP frame, calculate the MIC value203203-BOOLEAN STACheckTkipMICValue(204204- IN PRTMP_ADAPTER pAd,205205- IN MAC_TABLE_ENTRY *pEntry,206206- IN RX_BLK *pRxBlk)207207-{208208- PHEADER_802_11 pHeader = pRxBlk->pHeader;209209- UCHAR *pData = pRxBlk->pData;210210- USHORT DataSize = pRxBlk->DataSize;211211- UCHAR UserPriority = pRxBlk->UserPriority;212212- PCIPHER_KEY pWpaKey;213213- UCHAR *pDA, *pSA;214214-215215- pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex];216216-217217- pDA = pHeader->Addr1;218218- if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA))219219- {220220- pSA = pHeader->Addr3;221221- }222222- else223223- {224224- pSA = pHeader->Addr2;225225- }226226-227227- if (RTMPTkipCompareMICValue(pAd,228228- pData,229229- pDA,230230- pSA,231231- pWpaKey->RxMic,232232- UserPriority,233233- DataSize) == FALSE)234234- {235235- DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error 2\n"));236236-237237- if (pAd->StaCfg.WpaSupplicantUP)238238- {239239- WpaSendMicFailureToWpaSupplicant(pAd, (pWpaKey->Type == PAIRWISEKEY) ? TRUE : FALSE);240240- }241241- else242242- {243243- RTMPReportMicError(pAd, pWpaKey);244244- }245245-246246- // release packet247247- RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);248248- return FALSE;249249- }250250-251251- return TRUE;252252-}253253-254254-255255-//256256-// All Rx routines use RX_BLK structure to hande rx events257257-// It is very important to build pRxBlk attributes258258-// 1. pHeader pointer to 802.11 Header259259-// 2. pData pointer to payload including LLC (just skip Header)260260-// 3. set payload size including LLC to DataSize261261-// 4. set some flags with RX_BLK_SET_FLAG()262262-//263263-VOID STAHandleRxDataFrame(264264- IN PRTMP_ADAPTER pAd,265265- IN RX_BLK *pRxBlk)266266-{267267- PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);268268- PRXWI_STRUC pRxWI = pRxBlk->pRxWI;269269- PHEADER_802_11 pHeader = pRxBlk->pHeader;270270- PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;271271- BOOLEAN bFragment = FALSE;272272- MAC_TABLE_ENTRY *pEntry = NULL;273273- UCHAR FromWhichBSSID = BSS0;274274- UCHAR UserPriority = 0;275275-276276- {277277- // before LINK UP, all DATA frames are rejected278278- if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))279279- {280280- // release packet281281- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);282282- return;283283- }284284-285285- // Drop not my BSS frames286286- if (pRxD->MyBss == 0)287287- {288288- {289289- // release packet290290- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);291291- return;292292- }293293- }294294-295295- pAd->RalinkCounters.RxCountSinceLastNULL++;296296- if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable && (pHeader->FC.SubType & 0x08))297297- {298298- UCHAR *pData;299299- DBGPRINT(RT_DEBUG_TRACE,("bAPSDCapable\n"));300300-301301- // Qos bit 4302302- pData = (PUCHAR)pHeader + LENGTH_802_11;303303- if ((*pData >> 4) & 0x01)304304- {305305- DBGPRINT(RT_DEBUG_TRACE,("RxDone- Rcv EOSP frame, driver may fall into sleep\n"));306306- pAd->CommonCfg.bInServicePeriod = FALSE;307307-308308- // Force driver to fall into sleep mode when rcv EOSP frame309309- if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))310310- {311311- USHORT TbttNumToNextWakeUp;312312- USHORT NextDtim = pAd->StaCfg.DtimPeriod;313313- ULONG Now;314314-315315- NdisGetSystemUpTime(&Now);316316- NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod;317317-318318- TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;319319- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))320320- TbttNumToNextWakeUp = NextDtim;321321-322322- MlmeSetPsmBit(pAd, PWR_SAVE);323323- // if WMM-APSD is failed, try to disable following line324324- AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);325325- }326326- }327327-328328- if ((pHeader->FC.MoreData) && (pAd->CommonCfg.bInServicePeriod))329329- {330330- DBGPRINT(RT_DEBUG_TRACE,("Sending another trigger frame when More Data bit is set to 1\n"));331331- }332332- }333333-334334- // Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame335335- if ((pHeader->FC.SubType & 0x04)) // bit 2 : no DATA336336- {337337- // release packet338338- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);339339- return;340340- }341341-342342- // Drop not my BSS frame (we can not only check the MyBss bit in RxD)343343-344344- if (INFRA_ON(pAd))345345- {346346- // Infrastructure mode, check address 2 for BSSID347347- if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6))348348- {349349- // Receive frame not my BSSID350350- // release packet351351- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);352352- return;353353- }354354- }355355- else // Ad-Hoc mode or Not associated356356- {357357- // Ad-Hoc mode, check address 3 for BSSID358358- if (!RTMPEqualMemory(&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6))359359- {360360- // Receive frame not my BSSID361361- // release packet362362- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);363363- return;364364- }365365- }366366-367367- //368368- // find pEntry369369- //370370- if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE)371371- {372372- pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];373373- }374374- else375375- {376376- // 1. release packet if infra mode377377- // 2. new a pEntry if ad-hoc mode378378- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);379379- return;380380- }381381-382382- // infra or ad-hoc383383- if (INFRA_ON(pAd))384384- {385385- RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);386386- ASSERT(pRxWI->WirelessCliID == BSSID_WCID);387387- }388388-389389- // check Atheros Client390390- if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) && (pHeader->FC.Retry ))391391- {392392- pEntry->bIAmBadAtheros = TRUE;393393- pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE;394394- pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE;395395- if (!STA_AES_ON(pAd))396396- {397397- AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, FALSE);398398- }399399- }400400- }401401-402402- pRxBlk->pData = (UCHAR *)pHeader;403403-404404- //405405- // update RxBlk->pData, DataSize406406- // 802.11 Header, QOS, HTC, Hw Padding407407- //408408-409409- // 1. skip 802.11 HEADER410410- {411411- pRxBlk->pData += LENGTH_802_11;412412- pRxBlk->DataSize -= LENGTH_802_11;413413- }414414-415415- // 2. QOS416416- if (pHeader->FC.SubType & 0x08)417417- {418418- RX_BLK_SET_FLAG(pRxBlk, fRX_QOS);419419- UserPriority = *(pRxBlk->pData) & 0x0f;420420- // bit 7 in QoS Control field signals the HT A-MSDU format421421- if ((*pRxBlk->pData) & 0x80)422422- {423423- RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU);424424- }425425-426426- // skip QOS contorl field427427- pRxBlk->pData += 2;428428- pRxBlk->DataSize -=2;429429- }430430- pRxBlk->UserPriority = UserPriority;431431-432432- // 3. Order bit: A-Ralink or HTC+433433- if (pHeader->FC.Order)434434- {435435-#ifdef AGGREGATION_SUPPORT436436- if ((pRxWI->PHYMODE <= MODE_OFDM) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)))437437- {438438- RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK);439439- }440440- else441441-#endif442442- {443443- RX_BLK_SET_FLAG(pRxBlk, fRX_HTC);444444- // skip HTC contorl field445445- pRxBlk->pData += 4;446446- pRxBlk->DataSize -= 4;447447- }448448- }449449-450450- // 4. skip HW padding451451- if (pRxD->L2PAD)452452- {453453- // just move pData pointer454454- // because DataSize excluding HW padding455455- RX_BLK_SET_FLAG(pRxBlk, fRX_PAD);456456- pRxBlk->pData += 2;457457- }458458-459459- if (pRxD->BA)460460- {461461- RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU);462462- }463463-464464- //465465- // Case I Process Broadcast & Multicast data frame466466- //467467- if (pRxD->Bcast || pRxD->Mcast)468468- {469469- INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);470470-471471- // Drop Mcast/Bcast frame with fragment bit on472472- if (pHeader->FC.MoreFrag)473473- {474474- // release packet475475- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);476476- return;477477- }478478-479479- // Filter out Bcast frame which AP relayed for us480480- if (pHeader->FC.FrDs && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress))481481- {482482- // release packet483483- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);484484- return;485485- }486486-487487- Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);488488- return;489489- }490490- else if (pRxD->U2M)491491- {492492- pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ;493493-494494- if (ADHOC_ON(pAd))495495- {496496- pEntry = MacTableLookup(pAd, pHeader->Addr2);497497- if (pEntry)498498- Update_Rssi_Sample(pAd, &pEntry->RssiSample, pRxWI);499499- }500500-501501-502502- Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);503503-504504- pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);505505- pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);506506-507507- pAd->RalinkCounters.OneSecRxOkDataCnt++;508508-509509-510510- if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0)))511511- {512512- // re-assemble the fragmented packets513513- // return complete frame (pRxPacket) or NULL514514- bFragment = TRUE;515515- pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk);516516- }517517-518518- if (pRxPacket)519519- {520520- pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];521521-522522- // process complete frame523523- if (bFragment && (pRxD->Decrypted) && (pEntry->WepStatus == Ndis802_11Encryption2Enabled))524524- {525525- // Minus MIC length526526- pRxBlk->DataSize -= 8;527527-528528- // For TKIP frame, calculate the MIC value529529- if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == FALSE)530530- {531531- return;532532- }533533- }534534-535535- STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, FromWhichBSSID);536536- return;537537- }538538- else539539- {540540- // just return541541- // because RTMPDeFragmentDataFrame() will release rx packet,542542- // if packet is fragmented543543- return;544544- }545545- }546546-547547- ASSERT(0);548548- // release packet549549- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);550550-}551551-552552-VOID STAHandleRxMgmtFrame(553553- IN PRTMP_ADAPTER pAd,554554- IN RX_BLK *pRxBlk)555555-{556556- PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);557557- PRXWI_STRUC pRxWI = pRxBlk->pRxWI;558558- PHEADER_802_11 pHeader = pRxBlk->pHeader;559559- PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;560560-561561- do562562- {563563-564564- // We should collect RSSI not only U2M data but also my beacon565565- if ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2))566566- && (pAd->RxAnt.EvaluatePeriod == 0))567567- {568568- Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);569569-570570- pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0);571571- pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1);572572- }573573-574574-#ifdef RT30xx575575- // collect rssi information for antenna diversity576576- if (pAd->NicConfig2.field.AntDiversity)577577- {578578- if ((pRxD->U2M) || ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2))))579579- {580580- COLLECT_RX_ANTENNA_AVERAGE_RSSI(pAd, ConvertToRssi(pAd, (UCHAR)pRxWI->RSSI0, RSSI_0), 0); //Note: RSSI2 not used on RT73581581- pAd->StaCfg.NumOfAvgRssiSample ++;582582- }583583- }584584-#endif // RT30xx //585585-586586- // First check the size, it MUST not exceed the mlme queue size587587- if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE)588588- {589589- DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount));590590- break;591591- }592592-593593- REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, pRxWI->MPDUtotalByteCount,594594- pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal);595595- } while (FALSE);596596-597597- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);598598-}599599-600600-VOID STAHandleRxControlFrame(601601- IN PRTMP_ADAPTER pAd,602602- IN RX_BLK *pRxBlk)603603-{604604- PRXWI_STRUC pRxWI = pRxBlk->pRxWI;605605- PHEADER_802_11 pHeader = pRxBlk->pHeader;606606- PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket;607607-608608- switch (pHeader->FC.SubType)609609- {610610- case SUBTYPE_BLOCK_ACK_REQ:611611- {612612- CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, (pRxWI->MPDUtotalByteCount), (PFRAME_BA_REQ)pHeader);613613- }614614- break;615615- case SUBTYPE_BLOCK_ACK:616616- case SUBTYPE_ACK:617617- default:618618- break;619619- }620620-621621- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);622622-}623623-624624-625625-/*626626- ========================================================================627627-628628- Routine Description:629629- Process RxDone interrupt, running in DPC level630630-631631- Arguments:632632- pAd Pointer to our adapter633633-634634- Return Value:635635- None636636-637637- IRQL = DISPATCH_LEVEL638638-639639- Note:640640- This routine has to maintain Rx ring read pointer.641641- Need to consider QOS DATA format when converting to 802.3642642- ========================================================================643643-*/644644-BOOLEAN STARxDoneInterruptHandle(645645- IN PRTMP_ADAPTER pAd,646646- IN BOOLEAN argc)647647-{648648- NDIS_STATUS Status;649649- UINT32 RxProcessed, RxPending;650650- BOOLEAN bReschedule = FALSE;651651- RT28XX_RXD_STRUC *pRxD;652652- UCHAR *pData;653653- PRXWI_STRUC pRxWI;654654- PNDIS_PACKET pRxPacket;655655- PHEADER_802_11 pHeader;656656- RX_BLK RxCell;657657-658658- RxProcessed = RxPending = 0;659659-660660- // process whole rx ring661661- while (1)662662- {663663-664664- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF |665665- fRTMP_ADAPTER_RESET_IN_PROGRESS |666666- fRTMP_ADAPTER_HALT_IN_PROGRESS |667667- fRTMP_ADAPTER_NIC_NOT_EXIST) ||668668- !RTMP_TEST_FLAG(pAd,fRTMP_ADAPTER_START_UP))669669- {670670- break;671671- }672672-673673-674674- RxProcessed ++; // test675675-676676- // 1. allocate a new data packet into rx ring to replace received packet677677- // then processing the received packet678678- // 2. the callee must take charge of release of packet679679- // 3. As far as driver is concerned ,680680- // the rx packet must681681- // a. be indicated to upper layer or682682- // b. be released if it is discarded683683- pRxPacket = GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, &RxPending);684684- if (pRxPacket == NULL)685685- {686686- // no more packet to process687687- break;688688- }689689-690690- // get rx ring descriptor691691- pRxD = &(RxCell.RxD);692692- // get rx data buffer693693- pData = GET_OS_PKT_DATAPTR(pRxPacket);694694- pRxWI = (PRXWI_STRUC) pData;695695- pHeader = (PHEADER_802_11) (pData+RXWI_SIZE) ;696696-697697- // build RxCell698698- RxCell.pRxWI = pRxWI;699699- RxCell.pHeader = pHeader;700700- RxCell.pRxPacket = pRxPacket;701701- RxCell.pData = (UCHAR *) pHeader;702702- RxCell.DataSize = pRxWI->MPDUtotalByteCount;703703- RxCell.Flags = 0;704704-705705- // Increase Total receive byte counter after real data received no mater any error or not706706- pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount;707707- pAd->RalinkCounters.RxCount ++;708708-709709- INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);710710-711711- if (pRxWI->MPDUtotalByteCount < 14)712712- Status = NDIS_STATUS_FAILURE;713713-714714- if (MONITOR_ON(pAd))715715- {716716- send_monitor_packets(pAd, &RxCell);717717- break;718718- }719719- /* RT2870 invokes STARxDoneInterruptHandle() in rtusb_bulk.c */720720-721721- // Check for all RxD errors722722- Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);723723-724724- // Handle the received frame725725- if (Status == NDIS_STATUS_SUCCESS)726726- {727727- switch (pHeader->FC.Type)728728- {729729- // CASE I, receive a DATA frame730730- case BTYPE_DATA:731731- {732732- // process DATA frame733733- STAHandleRxDataFrame(pAd, &RxCell);734734- }735735- break;736736- // CASE II, receive a MGMT frame737737- case BTYPE_MGMT:738738- {739739- STAHandleRxMgmtFrame(pAd, &RxCell);740740- }741741- break;742742- // CASE III. receive a CNTL frame743743- case BTYPE_CNTL:744744- {745745- STAHandleRxControlFrame(pAd, &RxCell);746746- }747747- break;748748- // discard other type749749- default:750750- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);751751- break;752752- }753753- }754754- else755755- {756756- pAd->Counters8023.RxErrors++;757757- // discard this frame758758- RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);759759- }760760- }761761-762762- return bReschedule;763763-}764764-765765-/*766766- ========================================================================767767-768768- Routine Description:769769- Arguments:770770- pAd Pointer to our adapter771771-772772- IRQL = DISPATCH_LEVEL773773-774774- ========================================================================775775-*/776776-VOID RTMPHandleTwakeupInterrupt(777777- IN PRTMP_ADAPTER pAd)778778-{779779- AsicForceWakeup(pAd, FALSE);780780-}781781-782782-/*783783-========================================================================784784-Routine Description:785785- Early checking and OS-depened parsing for Tx packet send to our STA driver.786786-787787-Arguments:788788- NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd.789789- PPNDIS_PACKET ppPacketArray The packet array need to do transmission.790790- UINT NumberOfPackets Number of packet in packet array.791791-792792-Return Value:793793- NONE794794-795795-Note:796796- This function do early checking and classification for send-out packet.797797- You only can put OS-depened & STA related code in here.798798-========================================================================799799-*/800800-VOID STASendPackets(801801- IN NDIS_HANDLE MiniportAdapterContext,802802- IN PPNDIS_PACKET ppPacketArray,803803- IN UINT NumberOfPackets)804804-{805805- UINT Index;806806- PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) MiniportAdapterContext;807807- PNDIS_PACKET pPacket;808808- BOOLEAN allowToSend = FALSE;809809-810810-811811- for (Index = 0; Index < NumberOfPackets; Index++)812812- {813813- pPacket = ppPacketArray[Index];814814-815815- do816816- {817817-818818- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||819819- RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||820820- RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))821821- {822822- // Drop send request since hardware is in reset state823823- break;824824- }825825- else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd))826826- {827827- // Drop send request since there are no physical connection yet828828- break;829829- }830830- else831831- {832832- // Record that orignal packet source is from NDIS layer,so that833833- // later on driver knows how to release this NDIS PACKET834834- RTMP_SET_PACKET_WCID(pPacket, 0); // this field is useless when in STA mode835835- RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);836836- NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING);837837- pAd->RalinkCounters.PendingNdisPacketCount++;838838-839839- allowToSend = TRUE;840840- }841841- } while(FALSE);842842-843843- if (allowToSend == TRUE)844844- STASendPacket(pAd, pPacket);845845- else846846- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);847847- }848848-849849- // Dequeue outgoing frames from TxSwQueue[] and process it850850- RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);851851-852852-}853853-854854-855855-/*856856-========================================================================857857-Routine Description:858858- This routine is used to do packet parsing and classification for Tx packet859859- to STA device, and it will en-queue packets to our TxSwQueue depends on AC860860- class.861861-862862-Arguments:863863- pAd Pointer to our adapter864864- pPacket Pointer to send packet865865-866866-Return Value:867867- NDIS_STATUS_SUCCESS If succes to queue the packet into TxSwQueue.868868- NDIS_STATUS_FAILURE If failed to do en-queue.869869-870870-Note:871871- You only can put OS-indepened & STA related code in here.872872-========================================================================873873-*/874874-NDIS_STATUS STASendPacket(875875- IN PRTMP_ADAPTER pAd,876876- IN PNDIS_PACKET pPacket)877877-{878878- PACKET_INFO PacketInfo;879879- PUCHAR pSrcBufVA;880880- UINT SrcBufLen;881881- UINT AllowFragSize;882882- UCHAR NumberOfFrag;883883- UCHAR QueIdx, UserPriority;884884- MAC_TABLE_ENTRY *pEntry = NULL;885885- unsigned int IrqFlags;886886- UCHAR FlgIsIP = 0;887887- UCHAR Rate;888888-889889- // Prepare packet information structure for buffer descriptor890890- // chained within a single NDIS packet.891891- RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);892892-893893- if (pSrcBufVA == NULL)894894- {895895- DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> pSrcBufVA == NULL !!!SrcBufLen=%x\n",SrcBufLen));896896- // Resourece is low, system did not allocate virtual address897897- // return NDIS_STATUS_FAILURE directly to upper layer898898- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);899899- return NDIS_STATUS_FAILURE;900900- }901901-902902-903903- if (SrcBufLen < 14)904904- {905905- DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> Ndis Packet buffer error !!!\n"));906906- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);907907- return (NDIS_STATUS_FAILURE);908908- }909909-910910- // In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry.911911- // Note multicast packets in adhoc also use BSSID_WCID index.912912- {913913- if(INFRA_ON(pAd))914914- {915915- {916916- pEntry = &pAd->MacTab.Content[BSSID_WCID];917917- RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID);918918- Rate = pAd->CommonCfg.TxRate;919919- }920920- }921921- else if (ADHOC_ON(pAd))922922- {923923- if (*pSrcBufVA & 0x01)924924- {925925- RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID);926926- pEntry = &pAd->MacTab.Content[MCAST_WCID];927927- }928928- else929929- {930930- pEntry = MacTableLookup(pAd, pSrcBufVA);931931- }932932- Rate = pAd->CommonCfg.TxRate;933933- }934934- }935935-936936- if (!pEntry)937937- {938938- DBGPRINT(RT_DEBUG_ERROR,("STASendPacket->Cannot find pEntry(%2x:%2x:%2x:%2x:%2x:%2x) in MacTab!\n", PRINT_MAC(pSrcBufVA)));939939- // Resourece is low, system did not allocate virtual address940940- // return NDIS_STATUS_FAILURE directly to upper layer941941- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);942942- return NDIS_STATUS_FAILURE;943943- }944944-945945- if (ADHOC_ON(pAd)946946- )947947- {948948- RTMP_SET_PACKET_WCID(pPacket, (UCHAR)pEntry->Aid);949949- }950950-951951- //952952- // Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags.953953- // Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL).954954- RTMPCheckEtherType(pAd, pPacket);955955-956956-957957-958958- //959959- // WPA 802.1x secured port control - drop all non-802.1x frame before port secured960960- //961961- if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||962962- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||963963- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||964964- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)965965- || (pAd->StaCfg.IEEE8021X == TRUE)966966- )967967- && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) || (pAd->StaCfg.MicErrCnt >= 2))968968- && (RTMP_GET_PACKET_EAPOL(pPacket)== FALSE)969969- )970970- {971971- DBGPRINT(RT_DEBUG_TRACE,("STASendPacket --> Drop packet before port secured !!!\n"));972972- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);973973-974974- return (NDIS_STATUS_FAILURE);975975- }976976-977977-978978- // STEP 1. Decide number of fragments required to deliver this MSDU.979979- // The estimation here is not very accurate because difficult to980980- // take encryption overhead into consideration here. The result981981- // "NumberOfFrag" is then just used to pre-check if enough free982982- // TXD are available to hold this MSDU.983983-984984-985985- if (*pSrcBufVA & 0x01) // fragmentation not allowed on multicast & broadcast986986- NumberOfFrag = 1;987987- else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))988988- NumberOfFrag = 1; // Aggregation overwhelms fragmentation989989- else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED))990990- NumberOfFrag = 1; // Aggregation overwhelms fragmentation991991- else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD))992992- NumberOfFrag = 1; // MIMO RATE overwhelms fragmentation993993- else994994- {995995- // The calculated "NumberOfFrag" is a rough estimation because of various996996- // encryption/encapsulation overhead not taken into consideration. This number is just997997- // used to make sure enough free TXD are available before fragmentation takes place.998998- // In case the actual required number of fragments of an NDIS packet999999- // excceeds "NumberOfFrag"caculated here and not enough free TXD available, the10001000- // last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of10011001- // resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should10021002- // rarely happen and the penalty is just like a TX RETRY fail. Affordable.10031003-10041004- AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;10051005- NumberOfFrag = ((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) / AllowFragSize) + 1;10061006- // To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size10071007- if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) % AllowFragSize) == 0)10081008- {10091009- NumberOfFrag--;10101010- }10111011- }10121012-10131013- // Save fragment number to Ndis packet reserved field10141014- RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag);10151015-10161016-10171017- // STEP 2. Check the requirement of RTS:10181018- // If multiple fragment required, RTS is required only for the first fragment10191019- // if the fragment size large than RTS threshold10201020- // For RT28xx, Let ASIC send RTS/CTS10211021- RTMP_SET_PACKET_RTS(pPacket, 0);10221022- RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate);10231023-10241024- //10251025- // STEP 3. Traffic classification. outcome = <UserPriority, QueIdx>10261026- //10271027- UserPriority = 0;10281028- QueIdx = QID_AC_BE;10291029- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&10301030- CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE))10311031- {10321032- USHORT Protocol;10331033- UCHAR LlcSnapLen = 0, Byte0, Byte1;10341034- do10351035- {10361036- // get Ethernet protocol field10371037- Protocol = (USHORT)((pSrcBufVA[12] << 8) + pSrcBufVA[13]);10381038- if (Protocol <= 1500)10391039- {10401040- // get Ethernet protocol field from LLC/SNAP10411041- if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)10421042- break;10431043-10441044- Protocol = (USHORT)((Byte0 << 8) + Byte1);10451045- LlcSnapLen = 8;10461046- }10471047-10481048- // always AC_BE for non-IP packet10491049- if (Protocol != 0x0800)10501050- break;10511051-10521052- // get IP header10531053- if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)10541054- break;10551055-10561056- // return AC_BE if packet is not IPv410571057- if ((Byte0 & 0xf0) != 0x40)10581058- break;10591059-10601060- FlgIsIP = 1;10611061- UserPriority = (Byte1 & 0xe0) >> 5;10621062- QueIdx = MapUserPriorityToAccessCategory[UserPriority];10631063-10641064- // TODO: have to check ACM bit. apply TSPEC if ACM is ON10651065- // TODO: downgrade UP & QueIdx before passing ACM10661066- if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx])10671067- {10681068- UserPriority = 0;10691069- QueIdx = QID_AC_BE;10701070- }10711071- } while (FALSE);10721072- }10731073-10741074- RTMP_SET_PACKET_UP(pPacket, UserPriority);10751075-10761076-10771077-10781078- // Make sure SendTxWait queue resource won't be used by other threads10791079- RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);10801080- if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE)10811081- {10821082- RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);10831083- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);10841084-10851085- return NDIS_STATUS_FAILURE;10861086- }10871087- else10881088- {10891089- InsertTailQueue(&pAd->TxSwQueue[QueIdx], PACKET_TO_QUEUE_ENTRY(pPacket));10901090- }10911091- RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);10921092-10931093- if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE)&&10941094- IS_HT_STA(pEntry))10951095- {10961096- if (((pEntry->TXBAbitmap & (1<<UserPriority)) == 0) &&10971097- ((pEntry->BADeclineBitmap & (1<<UserPriority)) == 0) &&10981098- (pEntry->PortSecured == WPA_802_1X_PORT_SECURED)10991099- // For IOT compatibility, if11001100- // 1. It is Ralink chip or11011101- // 2. It is OPEN or AES mode,11021102- // then BA session can be bulit.11031103- && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) ||11041104- (pEntry->WepStatus == Ndis802_11WEPDisabled || pEntry->WepStatus == Ndis802_11Encryption3Enabled))11051105- )11061106- {11071107- BAOriSessionSetUp(pAd, pEntry, 0, 0, 10, FALSE);11081108- }11091109- }11101110-11111111- pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; // TODO: for debug only. to be removed11121112- return NDIS_STATUS_SUCCESS;11131113-}11141114-11151115-11161116-/*11171117- ========================================================================11181118-11191119- Routine Description:11201120- This subroutine will scan through releative ring descriptor to find11211121- out avaliable free ring descriptor and compare with request size.11221122-11231123- Arguments:11241124- pAd Pointer to our adapter11251125- QueIdx Selected TX Ring11261126-11271127- Return Value:11281128- NDIS_STATUS_FAILURE Not enough free descriptor11291129- NDIS_STATUS_SUCCESS Enough free descriptor11301130-11311131- IRQL = PASSIVE_LEVEL11321132- IRQL = DISPATCH_LEVEL11331133-11341134- Note:11351135-11361136- ========================================================================11371137-*/11381138-11391139-#ifdef RT287011401140-/*11411141- Actually, this function used to check if the TxHardware Queue still has frame need to send.11421142- If no frame need to send, go to sleep, else, still wake up.11431143-*/11441144-NDIS_STATUS RTMPFreeTXDRequest(11451145- IN PRTMP_ADAPTER pAd,11461146- IN UCHAR QueIdx,11471147- IN UCHAR NumberRequired,11481148- IN PUCHAR FreeNumberIs)11491149-{11501150- NDIS_STATUS Status = NDIS_STATUS_FAILURE;11511151- unsigned long IrqFlags;11521152- HT_TX_CONTEXT *pHTTXContext;11531153-11541154- switch (QueIdx)11551155- {11561156- case QID_AC_BK:11571157- case QID_AC_BE:11581158- case QID_AC_VI:11591159- case QID_AC_VO:11601160- case QID_HCCA:11611161- {11621162- pHTTXContext = &pAd->TxContext[QueIdx];11631163- RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);11641164- if ((pHTTXContext->CurWritePosition != pHTTXContext->ENextBulkOutPosition) ||11651165- (pHTTXContext->IRPPending == TRUE))11661166- {11671167- Status = NDIS_STATUS_FAILURE;11681168- }11691169- else11701170- {11711171- Status = NDIS_STATUS_SUCCESS;11721172- }11731173- RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);11741174- }11751175- break;11761176-11771177- case QID_MGMT:11781178- if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE)11791179- Status = NDIS_STATUS_FAILURE;11801180- else11811181- Status = NDIS_STATUS_SUCCESS;11821182- break;11831183-11841184- default:11851185- DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));11861186- break;11871187- }11881188-11891189- return (Status);11901190-11911191-}11921192-#endif // RT2870 //11931193-11941194-11951195-VOID RTMPSendDisassociationFrame(11961196- IN PRTMP_ADAPTER pAd)11971197-{11981198-}11991199-12001200-VOID RTMPSendNullFrame(12011201- IN PRTMP_ADAPTER pAd,12021202- IN UCHAR TxRate,12031203- IN BOOLEAN bQosNull)12041204-{12051205- UCHAR NullFrame[48];12061206- ULONG Length;12071207- PHEADER_802_11 pHeader_802_11;12081208-12091209- // WPA 802.1x secured port control12101210- if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||12111211- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||12121212- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||12131213- (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)12141214- || (pAd->StaCfg.IEEE8021X == TRUE)12151215- ) &&12161216- (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))12171217- {12181218- return;12191219- }12201220-12211221- NdisZeroMemory(NullFrame, 48);12221222- Length = sizeof(HEADER_802_11);12231223-12241224- pHeader_802_11 = (PHEADER_802_11) NullFrame;12251225-12261226- pHeader_802_11->FC.Type = BTYPE_DATA;12271227- pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC;12281228- pHeader_802_11->FC.ToDs = 1;12291229- COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);12301230- COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);12311231- COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);12321232-12331233- if (pAd->CommonCfg.bAPSDForcePowerSave)12341234- {12351235- pHeader_802_11->FC.PwrMgmt = PWR_SAVE;12361236- }12371237- else12381238- {12391239- pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE) ? 1: 0;12401240- }12411241- pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14);12421242-12431243- pAd->Sequence++;12441244- pHeader_802_11->Sequence = pAd->Sequence;12451245-12461246- // Prepare QosNull function frame12471247- if (bQosNull)12481248- {12491249- pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL;12501250-12511251- // copy QOS control bytes12521252- NullFrame[Length] = 0;12531253- NullFrame[Length+1] = 0;12541254- Length += 2;// if pad with 2 bytes for alignment, APSD will fail12551255- }12561256-12571257- HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length);12581258-12591259-}12601260-12611261-// IRQL = DISPATCH_LEVEL12621262-VOID RTMPSendRTSFrame(12631263- IN PRTMP_ADAPTER pAd,12641264- IN PUCHAR pDA,12651265- IN unsigned int NextMpduSize,12661266- IN UCHAR TxRate,12671267- IN UCHAR RTSRate,12681268- IN USHORT AckDuration,12691269- IN UCHAR QueIdx,12701270- IN UCHAR FrameGap)12711271-{12721272-}12731273-12741274-12751275-12761276-// --------------------------------------------------------12771277-// FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM12781278-// Find the WPA key, either Group or Pairwise Key12791279-// LEAP + TKIP also use WPA key.12801280-// --------------------------------------------------------12811281-// Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst12821282-// In Cisco CCX 2.0 Leap Authentication12831283-// WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey12841284-// Instead of the SharedKey, SharedKey Length may be Zero.12851285-VOID STAFindCipherAlgorithm(12861286- IN PRTMP_ADAPTER pAd,12871287- IN TX_BLK *pTxBlk)12881288-{12891289- NDIS_802_11_ENCRYPTION_STATUS Cipher; // To indicate cipher used for this packet12901290- UCHAR CipherAlg = CIPHER_NONE; // cipher alogrithm12911291- UCHAR KeyIdx = 0xff;12921292- PUCHAR pSrcBufVA;12931293- PCIPHER_KEY pKey = NULL;12941294-12951295- pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket);12961296-12971297- {12981298- // Select Cipher12991299- if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))13001300- Cipher = pAd->StaCfg.GroupCipher; // Cipher for Multicast or Broadcast13011301- else13021302- Cipher = pAd->StaCfg.PairCipher; // Cipher for Unicast13031303-13041304- if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))13051305- {13061306- ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= CIPHER_CKIP128);13071307-13081308- // 4-way handshaking frame must be clear13091309- if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) && (pAd->SharedKey[BSS0][0].CipherAlg) &&13101310- (pAd->SharedKey[BSS0][0].KeyLen))13111311- {13121312- CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;13131313- KeyIdx = 0;13141314- }13151315- }13161316- else if (Cipher == Ndis802_11Encryption1Enabled)13171317- {13181318- KeyIdx = pAd->StaCfg.DefaultKeyId;13191319- }13201320- else if ((Cipher == Ndis802_11Encryption2Enabled) ||13211321- (Cipher == Ndis802_11Encryption3Enabled))13221322- {13231323- if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) // multicast13241324- KeyIdx = pAd->StaCfg.DefaultKeyId;13251325- else if (pAd->SharedKey[BSS0][0].KeyLen)13261326- KeyIdx = 0;13271327- else13281328- KeyIdx = pAd->StaCfg.DefaultKeyId;13291329- }13301330-13311331- if (KeyIdx == 0xff)13321332- CipherAlg = CIPHER_NONE;13331333- else if ((Cipher == Ndis802_11EncryptionDisabled) || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0))13341334- CipherAlg = CIPHER_NONE;13351335- else if ( pAd->StaCfg.WpaSupplicantUP &&13361336- (Cipher == Ndis802_11Encryption1Enabled) &&13371337- (pAd->StaCfg.IEEE8021X == TRUE) &&13381338- (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))13391339- CipherAlg = CIPHER_NONE;13401340- else13411341- {13421342- //Header_802_11.FC.Wep = 1;13431343- CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;13441344- pKey = &pAd->SharedKey[BSS0][KeyIdx];13451345- }13461346- }13471347-13481348- pTxBlk->CipherAlg = CipherAlg;13491349- pTxBlk->pKey = pKey;13501350-}13511351-13521352-13531353-VOID STABuildCommon802_11Header(13541354- IN PRTMP_ADAPTER pAd,13551355- IN TX_BLK *pTxBlk)13561356-{13571357- HEADER_802_11 *pHeader_802_11;13581358-13591359- //13601360- // MAKE A COMMON 802.11 HEADER13611361- //13621362-13631363- // normal wlan header size : 24 octets13641364- pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);13651365-13661366- pHeader_802_11 = (HEADER_802_11 *) &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];13671367-13681368- NdisZeroMemory(pHeader_802_11, sizeof(HEADER_802_11));13691369-13701370- pHeader_802_11->FC.FrDs = 0;13711371- pHeader_802_11->FC.Type = BTYPE_DATA;13721372- pHeader_802_11->FC.SubType = ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : SUBTYPE_DATA);13731373-13741374- if (pTxBlk->pMacEntry)13751375- {13761376- if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS))13771377- {13781378- pHeader_802_11->Sequence = pTxBlk->pMacEntry->NonQosDataSeq;13791379- pTxBlk->pMacEntry->NonQosDataSeq = (pTxBlk->pMacEntry->NonQosDataSeq+1) & MAXSEQ;13801380- }13811381- else13821382- {13831383- {13841384- pHeader_802_11->Sequence = pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority];13851385- pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = (pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;13861386- }13871387- }13881388- }13891389- else13901390- {13911391- pHeader_802_11->Sequence = pAd->Sequence;13921392- pAd->Sequence = (pAd->Sequence+1) & MAXSEQ; // next sequence13931393- }13941394-13951395- pHeader_802_11->Frag = 0;13961396-13971397- pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);13981398-13991399- {14001400- if (INFRA_ON(pAd))14011401- {14021402- {14031403- COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);14041404- COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);14051405- COPY_MAC_ADDR(pHeader_802_11->Addr3, pTxBlk->pSrcBufHeader);14061406- pHeader_802_11->FC.ToDs = 1;14071407- }14081408- }14091409- else if (ADHOC_ON(pAd))14101410- {14111411- COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader);14121412- COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);14131413- COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);14141414- pHeader_802_11->FC.ToDs = 0;14151415- }14161416- }14171417-14181418- if (pTxBlk->CipherAlg != CIPHER_NONE)14191419- pHeader_802_11->FC.Wep = 1;14201420-14211421- // -----------------------------------------------------------------14221422- // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.14231423- // -----------------------------------------------------------------14241424- if (pAd->CommonCfg.bAPSDForcePowerSave)14251425- pHeader_802_11->FC.PwrMgmt = PWR_SAVE;14261426- else14271427- pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);14281428-}14291429-14301430-VOID STABuildCache802_11Header(14311431- IN RTMP_ADAPTER *pAd,14321432- IN TX_BLK *pTxBlk,14331433- IN UCHAR *pHeader)14341434-{14351435- MAC_TABLE_ENTRY *pMacEntry;14361436- PHEADER_802_11 pHeader80211;14371437-14381438- pHeader80211 = (PHEADER_802_11)pHeader;14391439- pMacEntry = pTxBlk->pMacEntry;14401440-14411441- //14421442- // Update the cached 802.11 HEADER14431443- //14441444-14451445- // normal wlan header size : 24 octets14461446- pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11);14471447-14481448- // More Bit14491449- pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);14501450-14511451- // Sequence14521452- pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority];14531453- pMacEntry->TxSeq[pTxBlk->UserPriority] = (pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ;14541454-14551455- {14561456- // The addr3 of normal packet send from DS is Dest Mac address.14571457- if (ADHOC_ON(pAd))14581458- COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid);14591459- else14601460- COPY_MAC_ADDR(pHeader80211->Addr3, pTxBlk->pSrcBufHeader);14611461- }14621462-14631463- // -----------------------------------------------------------------14641464- // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later.14651465- // -----------------------------------------------------------------14661466- if (pAd->CommonCfg.bAPSDForcePowerSave)14671467- pHeader80211->FC.PwrMgmt = PWR_SAVE;14681468- else14691469- pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);14701470-}14711471-14721472-static inline PUCHAR STA_Build_ARalink_Frame_Header(14731473- IN RTMP_ADAPTER *pAd,14741474- IN TX_BLK *pTxBlk)14751475-{14761476- PUCHAR pHeaderBufPtr;14771477- HEADER_802_11 *pHeader_802_11;14781478- PNDIS_PACKET pNextPacket;14791479- UINT32 nextBufLen;14801480- PQUEUE_ENTRY pQEntry;14811481-14821482- STAFindCipherAlgorithm(pAd, pTxBlk);14831483- STABuildCommon802_11Header(pAd, pTxBlk);14841484-14851485-14861486- pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];14871487- pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;14881488-14891489- // steal "order" bit to mark "aggregation"14901490- pHeader_802_11->FC.Order = 1;14911491-14921492- // skip common header14931493- pHeaderBufPtr += pTxBlk->MpduHeaderLen;14941494-14951495- if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))14961496- {14971497- //14981498- // build QOS Control bytes14991499- //15001500- *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);15011501-15021502- *(pHeaderBufPtr+1) = 0;15031503- pHeaderBufPtr +=2;15041504- pTxBlk->MpduHeaderLen += 2;15051505- }15061506-15071507- // padding at front of LLC header. LLC header should at 4-bytes aligment.15081508- pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;15091509- pHeaderBufPtr = (PCHAR)ROUND_UP(pHeaderBufPtr, 4);15101510- pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);15111511-15121512- // For RA Aggregation,15131513- // put the 2nd MSDU length(extra 2-byte field) after QOS_CONTROL in little endian format15141514- pQEntry = pTxBlk->TxPacketList.Head;15151515- pNextPacket = QUEUE_ENTRY_TO_PKT(pQEntry);15161516- nextBufLen = GET_OS_PKT_LEN(pNextPacket);15171517- if (RTMP_GET_PACKET_VLAN(pNextPacket))15181518- nextBufLen -= LENGTH_802_1Q;15191519-15201520- *pHeaderBufPtr = (UCHAR)nextBufLen & 0xff;15211521- *(pHeaderBufPtr+1) = (UCHAR)(nextBufLen >> 8);15221522-15231523- pHeaderBufPtr += 2;15241524- pTxBlk->MpduHeaderLen += 2;15251525-15261526- return pHeaderBufPtr;15271527-15281528-}15291529-15301530-static inline PUCHAR STA_Build_AMSDU_Frame_Header(15311531- IN RTMP_ADAPTER *pAd,15321532- IN TX_BLK *pTxBlk)15331533-{15341534- PUCHAR pHeaderBufPtr;//, pSaveBufPtr;15351535- HEADER_802_11 *pHeader_802_11;15361536-15371537-15381538- STAFindCipherAlgorithm(pAd, pTxBlk);15391539- STABuildCommon802_11Header(pAd, pTxBlk);15401540-15411541- pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];15421542- pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;15431543-15441544- // skip common header15451545- pHeaderBufPtr += pTxBlk->MpduHeaderLen;15461546-15471547- //15481548- // build QOS Control bytes15491549- //15501550- *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);15511551-15521552- //15531553- // A-MSDU packet15541554- //15551555- *pHeaderBufPtr |= 0x80;15561556-15571557- *(pHeaderBufPtr+1) = 0;15581558- pHeaderBufPtr +=2;15591559- pTxBlk->MpduHeaderLen += 2;15601560-15611561- //pSaveBufPtr = pHeaderBufPtr;15621562-15631563- //15641564- // padding at front of LLC header15651565- // LLC header should locate at 4-octets aligment15661566- //15671567- // @@@ MpduHeaderLen excluding padding @@@15681568- //15691569- pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;15701570- pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);15711571- pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);15721572-15731573- return pHeaderBufPtr;15741574-15751575-}15761576-15771577-15781578-VOID STA_AMPDU_Frame_Tx(15791579- IN PRTMP_ADAPTER pAd,15801580- IN TX_BLK *pTxBlk)15811581-{15821582- HEADER_802_11 *pHeader_802_11;15831583- PUCHAR pHeaderBufPtr;15841584- USHORT FreeNumber;15851585- MAC_TABLE_ENTRY *pMacEntry;15861586- BOOLEAN bVLANPkt;15871587- PQUEUE_ENTRY pQEntry;15881588-15891589- ASSERT(pTxBlk);15901590-15911591- while(pTxBlk->TxPacketList.Head)15921592- {15931593- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);15941594- pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);15951595- if ( RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)15961596- {15971597- RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);15981598- continue;15991599- }16001600-16011601- bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);16021602-16031603- pMacEntry = pTxBlk->pMacEntry;16041604- if (pMacEntry->isCached)16051605- {16061606- // NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]!!!!16071607- NdisMoveMemory((PUCHAR)&pTxBlk->HeaderBuf[TXINFO_SIZE], (PUCHAR)&pMacEntry->CachedBuf[0], TXWI_SIZE + sizeof(HEADER_802_11));16081608- pHeaderBufPtr = (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]);16091609- STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr);16101610- }16111611- else16121612- {16131613- STAFindCipherAlgorithm(pAd, pTxBlk);16141614- STABuildCommon802_11Header(pAd, pTxBlk);16151615-16161616- pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];16171617- }16181618-16191619-16201620- pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;16211621-16221622- // skip common header16231623- pHeaderBufPtr += pTxBlk->MpduHeaderLen;16241624-16251625- //16261626- // build QOS Control bytes16271627- //16281628- *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);16291629- *(pHeaderBufPtr+1) = 0;16301630- pHeaderBufPtr +=2;16311631- pTxBlk->MpduHeaderLen += 2;16321632-16331633- //16341634- // build HTC+16351635- // HTC control filed following QoS field16361636- //16371637- if ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, fCLIENT_STATUS_RDG_CAPABLE))16381638- {16391639- if (pMacEntry->isCached == FALSE)16401640- {16411641- // mark HTC bit16421642- pHeader_802_11->FC.Order = 1;16431643-16441644- NdisZeroMemory(pHeaderBufPtr, 4);16451645- *(pHeaderBufPtr+3) |= 0x80;16461646- }16471647- pHeaderBufPtr += 4;16481648- pTxBlk->MpduHeaderLen += 4;16491649- }16501650-16511651- //pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE;16521652- ASSERT(pTxBlk->MpduHeaderLen >= 24);16531653-16541654- // skip 802.3 header16551655- pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;16561656- pTxBlk->SrcBufLen -= LENGTH_802_3;16571657-16581658- // skip vlan tag16591659- if (bVLANPkt)16601660- {16611661- pTxBlk->pSrcBufData += LENGTH_802_1Q;16621662- pTxBlk->SrcBufLen -= LENGTH_802_1Q;16631663- }16641664-16651665- //16661666- // padding at front of LLC header16671667- // LLC header should locate at 4-octets aligment16681668- //16691669- // @@@ MpduHeaderLen excluding padding @@@16701670- //16711671- pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;16721672- pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);16731673- pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);16741674-16751675- {16761676-16771677- //16781678- // Insert LLC-SNAP encapsulation - 8 octets16791679- //16801680- EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);16811681- if (pTxBlk->pExtraLlcSnapEncap)16821682- {16831683- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);16841684- pHeaderBufPtr += 6;16851685- // get 2 octets (TypeofLen)16861686- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);16871687- pHeaderBufPtr += 2;16881688- pTxBlk->MpduHeaderLen += LENGTH_802_1_H;16891689- }16901690-16911691- }16921692-16931693- if (pMacEntry->isCached)16941694- {16951695- RTMPWriteTxWI_Cache(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);16961696- }16971697- else16981698- {16991699- RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);17001700-17011701- NdisZeroMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), sizeof(pMacEntry->CachedBuf));17021702- NdisMoveMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), (pHeaderBufPtr - (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE])));17031703- pMacEntry->isCached = TRUE;17041704- }17051705-17061706- // calculate Transmitted AMPDU count and ByteCount17071707- {17081708- pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.LowPart ++;17091709- pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.QuadPart += pTxBlk->SrcBufLen;17101710- }17111711-17121712- //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);17131713-17141714- HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);17151715-17161716- //17171717- // Kick out Tx17181718- //17191719- HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);17201720-17211721- pAd->RalinkCounters.KickTxCount++;17221722- pAd->RalinkCounters.OneSecTxDoneCount++;17231723- }17241724-17251725-}17261726-17271727-17281728-VOID STA_AMSDU_Frame_Tx(17291729- IN PRTMP_ADAPTER pAd,17301730- IN TX_BLK *pTxBlk)17311731-{17321732- PUCHAR pHeaderBufPtr;17331733- USHORT FreeNumber;17341734- USHORT subFramePayloadLen = 0; // AMSDU Subframe length without AMSDU-Header / Padding.17351735- USHORT totalMPDUSize=0;17361736- UCHAR *subFrameHeader;17371737- UCHAR padding = 0;17381738- USHORT FirstTx = 0, LastTxIdx = 0;17391739- BOOLEAN bVLANPkt;17401740- int frameNum = 0;17411741- PQUEUE_ENTRY pQEntry;17421742-17431743-17441744- ASSERT(pTxBlk);17451745-17461746- ASSERT((pTxBlk->TxPacketList.Number > 1));17471747-17481748- while(pTxBlk->TxPacketList.Head)17491749- {17501750- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);17511751- pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);17521752- if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)17531753- {17541754- RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);17551755- continue;17561756- }17571757-17581758- bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);17591759-17601760- // skip 802.3 header17611761- pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;17621762- pTxBlk->SrcBufLen -= LENGTH_802_3;17631763-17641764- // skip vlan tag17651765- if (bVLANPkt)17661766- {17671767- pTxBlk->pSrcBufData += LENGTH_802_1Q;17681768- pTxBlk->SrcBufLen -= LENGTH_802_1Q;17691769- }17701770-17711771- if (frameNum == 0)17721772- {17731773- pHeaderBufPtr = STA_Build_AMSDU_Frame_Header(pAd, pTxBlk);17741774-17751775- // NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled.17761776- RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);17771777- }17781778- else17791779- {17801780- pHeaderBufPtr = &pTxBlk->HeaderBuf[0];17811781- padding = ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen, 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen);17821782- NdisZeroMemory(pHeaderBufPtr, padding + LENGTH_AMSDU_SUBFRAMEHEAD);17831783- pHeaderBufPtr += padding;17841784- pTxBlk->MpduHeaderLen = padding;17851785- }17861786-17871787- //17881788- // A-MSDU subframe17891789- // DA(6)+SA(6)+Length(2) + LLC/SNAP Encap17901790- //17911791- subFrameHeader = pHeaderBufPtr;17921792- subFramePayloadLen = pTxBlk->SrcBufLen;17931793-17941794- NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12);17951795-17961796-17971797- pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD;17981798- pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD;17991799-18001800-18011801- //18021802- // Insert LLC-SNAP encapsulation - 8 octets18031803- //18041804- EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);18051805-18061806- subFramePayloadLen = pTxBlk->SrcBufLen;18071807-18081808- if (pTxBlk->pExtraLlcSnapEncap)18091809- {18101810- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);18111811- pHeaderBufPtr += 6;18121812- // get 2 octets (TypeofLen)18131813- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);18141814- pHeaderBufPtr += 2;18151815- pTxBlk->MpduHeaderLen += LENGTH_802_1_H;18161816- subFramePayloadLen += LENGTH_802_1_H;18171817- }18181818-18191819- // update subFrame Length field18201820- subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8;18211821- subFrameHeader[13] = subFramePayloadLen & 0xFF;18221822-18231823- totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;18241824-18251825- if (frameNum ==0)18261826- FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);18271827- else18281828- LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);18291829-18301830- frameNum++;18311831-18321832- pAd->RalinkCounters.KickTxCount++;18331833- pAd->RalinkCounters.OneSecTxDoneCount++;18341834-18351835- // calculate Transmitted AMSDU Count and ByteCount18361836- {18371837- pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart ++;18381838- pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += totalMPDUSize;18391839- }18401840-18411841- }18421842-18431843- HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);18441844- HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);18451845-18461846- //18471847- // Kick out Tx18481848- //18491849- HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);18501850-}18511851-18521852-VOID STA_Legacy_Frame_Tx(18531853- IN PRTMP_ADAPTER pAd,18541854- IN TX_BLK *pTxBlk)18551855-{18561856- HEADER_802_11 *pHeader_802_11;18571857- PUCHAR pHeaderBufPtr;18581858- USHORT FreeNumber;18591859- BOOLEAN bVLANPkt;18601860- PQUEUE_ENTRY pQEntry;18611861-18621862- ASSERT(pTxBlk);18631863-18641864-18651865- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);18661866- pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);18671867- if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)18681868- {18691869- RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);18701870- return;18711871- }18721872-18731873- if (pTxBlk->TxFrameType == TX_MCAST_FRAME)18741874- {18751875- INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount);18761876- }18771877-18781878- if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket))18791879- TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired);18801880- else18811881- TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired);18821882-18831883- bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);18841884-18851885- if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate)18861886- pTxBlk->TxRate = pAd->CommonCfg.MinTxRate;18871887-18881888- STAFindCipherAlgorithm(pAd, pTxBlk);18891889- STABuildCommon802_11Header(pAd, pTxBlk);18901890-18911891-18921892- // skip 802.3 header18931893- pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;18941894- pTxBlk->SrcBufLen -= LENGTH_802_3;18951895-18961896- // skip vlan tag18971897- if (bVLANPkt)18981898- {18991899- pTxBlk->pSrcBufData += LENGTH_802_1Q;19001900- pTxBlk->SrcBufLen -= LENGTH_802_1Q;19011901- }19021902-19031903- pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];19041904- pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr;19051905-19061906- // skip common header19071907- pHeaderBufPtr += pTxBlk->MpduHeaderLen;19081908-19091909- if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))19101910- {19111911- //19121912- // build QOS Control bytes19131913- //19141914- *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);19151915- *(pHeaderBufPtr+1) = 0;19161916- pHeaderBufPtr +=2;19171917- pTxBlk->MpduHeaderLen += 2;19181918- }19191919-19201920- // The remaining content of MPDU header should locate at 4-octets aligment19211921- pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;19221922- pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);19231923- pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);19241924-19251925- {19261926-19271927- //19281928- // Insert LLC-SNAP encapsulation - 8 octets19291929- //19301930- //19311931- // if original Ethernet frame contains no LLC/SNAP,19321932- // then an extra LLC/SNAP encap is required19331933- //19341934- EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);19351935- if (pTxBlk->pExtraLlcSnapEncap)19361936- {19371937- UCHAR vlan_size;19381938-19391939- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);19401940- pHeaderBufPtr += 6;19411941- // skip vlan tag19421942- vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;19431943- // get 2 octets (TypeofLen)19441944- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);19451945- pHeaderBufPtr += 2;19461946- pTxBlk->MpduHeaderLen += LENGTH_802_1_H;19471947- }19481948-19491949- }19501950-19511951- //19521952- // prepare for TXWI19531953- // use Wcid as Key Index19541954- //19551955-19561956- RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);19571957-19581958- //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);19591959-19601960- HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);19611961-19621962- pAd->RalinkCounters.KickTxCount++;19631963- pAd->RalinkCounters.OneSecTxDoneCount++;19641964-19651965- //19661966- // Kick out Tx19671967- //19681968- HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);19691969-}19701970-19711971-19721972-VOID STA_ARalink_Frame_Tx(19731973- IN PRTMP_ADAPTER pAd,19741974- IN TX_BLK *pTxBlk)19751975-{19761976- PUCHAR pHeaderBufPtr;19771977- USHORT FreeNumber;19781978- USHORT totalMPDUSize=0;19791979- USHORT FirstTx, LastTxIdx;19801980- int frameNum = 0;19811981- BOOLEAN bVLANPkt;19821982- PQUEUE_ENTRY pQEntry;19831983-19841984-19851985- ASSERT(pTxBlk);19861986-19871987- ASSERT((pTxBlk->TxPacketList.Number== 2));19881988-19891989-19901990- FirstTx = LastTxIdx = 0; // Is it ok init they as 0?19911991- while(pTxBlk->TxPacketList.Head)19921992- {19931993- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);19941994- pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);19951995-19961996- if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)19971997- {19981998- RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);19991999- continue;20002000- }20012001-20022002- bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);20032003-20042004- // skip 802.3 header20052005- pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;20062006- pTxBlk->SrcBufLen -= LENGTH_802_3;20072007-20082008- // skip vlan tag20092009- if (bVLANPkt)20102010- {20112011- pTxBlk->pSrcBufData += LENGTH_802_1Q;20122012- pTxBlk->SrcBufLen -= LENGTH_802_1Q;20132013- }20142014-20152015- if (frameNum == 0)20162016- { // For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header20172017-20182018- pHeaderBufPtr = STA_Build_ARalink_Frame_Header(pAd, pTxBlk);20192019-20202020- // It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount20212021- // will be updated after final frame was handled.20222022- RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);20232023-20242024-20252025- //20262026- // Insert LLC-SNAP encapsulation - 8 octets20272027- //20282028- EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap);20292029-20302030- if (pTxBlk->pExtraLlcSnapEncap)20312031- {20322032- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);20332033- pHeaderBufPtr += 6;20342034- // get 2 octets (TypeofLen)20352035- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);20362036- pHeaderBufPtr += 2;20372037- pTxBlk->MpduHeaderLen += LENGTH_802_1_H;20382038- }20392039- }20402040- else20412041- { // For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0.20422042-20432043- pHeaderBufPtr = &pTxBlk->HeaderBuf[0];20442044- pTxBlk->MpduHeaderLen = 0;20452045-20462046- // A-Ralink sub-sequent frame header is the same as 802.3 header.20472047- // DA(6)+SA(6)+FrameType(2)20482048- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, 12);20492049- pHeaderBufPtr += 12;20502050- // get 2 octets (TypeofLen)20512051- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2);20522052- pHeaderBufPtr += 2;20532053- pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD;20542054- }20552055-20562056- totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;20572057-20582058- //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx);20592059- if (frameNum ==0)20602060- FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);20612061- else20622062- LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber);20632063-20642064- frameNum++;20652065-20662066- pAd->RalinkCounters.OneSecTxAggregationCount++;20672067- pAd->RalinkCounters.KickTxCount++;20682068- pAd->RalinkCounters.OneSecTxDoneCount++;20692069-20702070- }20712071-20722072- HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);20732073- HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);20742074-20752075- //20762076- // Kick out Tx20772077- //20782078- HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);20792079-20802080-}20812081-20822082-20832083-VOID STA_Fragment_Frame_Tx(20842084- IN RTMP_ADAPTER *pAd,20852085- IN TX_BLK *pTxBlk)20862086-{20872087- HEADER_802_11 *pHeader_802_11;20882088- PUCHAR pHeaderBufPtr;20892089- USHORT FreeNumber;20902090- UCHAR fragNum = 0;20912091- PACKET_INFO PacketInfo;20922092- USHORT EncryptionOverhead = 0;20932093- UINT32 FreeMpduSize, SrcRemainingBytes;20942094- USHORT AckDuration;20952095- UINT NextMpduSize;20962096- BOOLEAN bVLANPkt;20972097- PQUEUE_ENTRY pQEntry;20982098-20992099-21002100- ASSERT(pTxBlk);21012101-21022102- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);21032103- pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);21042104- if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE)21052105- {21062106- RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);21072107- return;21082108- }21092109-21102110- ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag));21112111- bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);21122112-21132113- STAFindCipherAlgorithm(pAd, pTxBlk);21142114- STABuildCommon802_11Header(pAd, pTxBlk);21152115-21162116- if (pTxBlk->CipherAlg == CIPHER_TKIP)21172117- {21182118- pTxBlk->pPacket = duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket);21192119- if (pTxBlk->pPacket == NULL)21202120- return;21212121- RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen);21222122- }21232123-21242124- // skip 802.3 header21252125- pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;21262126- pTxBlk->SrcBufLen -= LENGTH_802_3;21272127-21282128-21292129- // skip vlan tag21302130- if (bVLANPkt)21312131- {21322132- pTxBlk->pSrcBufData += LENGTH_802_1Q;21332133- pTxBlk->SrcBufLen -= LENGTH_802_1Q;21342134- }21352135-21362136- pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];21372137- pHeader_802_11 = (HEADER_802_11 *)pHeaderBufPtr;21382138-21392139-21402140- // skip common header21412141- pHeaderBufPtr += pTxBlk->MpduHeaderLen;21422142-21432143- if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM))21442144- {21452145- //21462146- // build QOS Control bytes21472147- //21482148- *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);21492149-21502150- *(pHeaderBufPtr+1) = 0;21512151- pHeaderBufPtr +=2;21522152- pTxBlk->MpduHeaderLen += 2;21532153- }21542154-21552155- //21562156- // padding at front of LLC header21572157- // LLC header should locate at 4-octets aligment21582158- //21592159- pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr;21602160- pHeaderBufPtr = (PCHAR) ROUND_UP(pHeaderBufPtr, 4);21612161- pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen);21622162-21632163-21642164-21652165- //21662166- // Insert LLC-SNAP encapsulation - 8 octets21672167- //21682168- //21692169- // if original Ethernet frame contains no LLC/SNAP,21702170- // then an extra LLC/SNAP encap is required21712171- //21722172- EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap);21732173- if (pTxBlk->pExtraLlcSnapEncap)21742174- {21752175- UCHAR vlan_size;21762176-21772177- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);21782178- pHeaderBufPtr += 6;21792179- // skip vlan tag21802180- vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;21812181- // get 2 octets (TypeofLen)21822182- NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2);21832183- pHeaderBufPtr += 2;21842184- pTxBlk->MpduHeaderLen += LENGTH_802_1_H;21852185- }21862186-21872187-21882188- // If TKIP is used and fragmentation is required. Driver has to21892189- // append TKIP MIC at tail of the scatter buffer21902190- // MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC21912191- if (pTxBlk->CipherAlg == CIPHER_TKIP)21922192- {21932193-21942194- // NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust21952195- // to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress.21962196- NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, &pAd->PrivateInfo.Tx.MIC[0], 8);21972197- //skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8);21982198- pTxBlk->SrcBufLen += 8;21992199- pTxBlk->TotalFrameLen += 8;22002200- pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;22012201- }22022202-22032203- //22042204- // calcuate the overhead bytes that encryption algorithm may add. This22052205- // affects the calculate of "duration" field22062206- //22072207- if ((pTxBlk->CipherAlg == CIPHER_WEP64) || (pTxBlk->CipherAlg == CIPHER_WEP128))22082208- EncryptionOverhead = 8; //WEP: IV[4] + ICV[4];22092209- else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC)22102210- EncryptionOverhead = 12;//TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength22112211- else if (pTxBlk->CipherAlg == CIPHER_TKIP)22122212- EncryptionOverhead = 20;//TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8]22132213- else if (pTxBlk->CipherAlg == CIPHER_AES)22142214- EncryptionOverhead = 16; // AES: IV[4] + EIV[4] + MIC[8]22152215- else22162216- EncryptionOverhead = 0;22172217-22182218- // decide how much time an ACK/CTS frame will consume in the air22192219- AckDuration = RTMPCalcDuration(pAd, pAd->CommonCfg.ExpectedACKRate[pTxBlk->TxRate], 14);22202220-22212221- // Init the total payload length of this frame.22222222- SrcRemainingBytes = pTxBlk->SrcBufLen;22232223-22242224- pTxBlk->TotalFragNum = 0xff;22252225-22262226- do {22272227-22282228- FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC;22292229-22302230- FreeMpduSize -= pTxBlk->MpduHeaderLen;22312231-22322232- if (SrcRemainingBytes <= FreeMpduSize)22332233- { // this is the last or only fragment22342234-22352235- pTxBlk->SrcBufLen = SrcRemainingBytes;22362236-22372237- pHeader_802_11->FC.MoreFrag = 0;22382238- pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + AckDuration;22392239-22402240- // Indicate the lower layer that this's the last fragment.22412241- pTxBlk->TotalFragNum = fragNum;22422242- }22432243- else22442244- { // more fragment is required22452245-22462246- pTxBlk->SrcBufLen = FreeMpduSize;22472247-22482248- NextMpduSize = min(((UINT)SrcRemainingBytes - pTxBlk->SrcBufLen), ((UINT)pAd->CommonCfg.FragmentThreshold));22492249- pHeader_802_11->FC.MoreFrag = 1;22502250- pHeader_802_11->Duration = (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + RTMPCalcDuration(pAd, pTxBlk->TxRate, NextMpduSize + EncryptionOverhead);22512251- }22522252-22532253- if (fragNum == 0)22542254- pTxBlk->FrameGap = IFS_HTTXOP;22552255- else22562256- pTxBlk->FrameGap = IFS_SIFS;22572257-22582258- RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk);22592259-22602260- HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber);22612261-22622262- pAd->RalinkCounters.KickTxCount++;22632263- pAd->RalinkCounters.OneSecTxDoneCount++;22642264-22652265- // Update the frame number, remaining size of the NDIS packet payload.22662266-22672267- // space for 802.11 header.22682268- if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap)22692269- pTxBlk->MpduHeaderLen -= LENGTH_802_1_H;22702270-22712271- fragNum++;22722272- SrcRemainingBytes -= pTxBlk->SrcBufLen;22732273- pTxBlk->pSrcBufData += pTxBlk->SrcBufLen;22742274-22752275- pHeader_802_11->Frag++; // increase Frag #22762276-22772277- }while(SrcRemainingBytes > 0);22782278-22792279- //22802280- // Kick out Tx22812281- //22822282- HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);22832283-}22842284-22852285-22862286-#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \22872287- while(_pTxBlk->TxPacketList.Head) \22882288- { \22892289- _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \22902290- RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \22912291- }22922292-22932293-22942294-/*22952295- ========================================================================22962296-22972297- Routine Description:22982298- Copy frame from waiting queue into relative ring buffer and set22992299- appropriate ASIC register to kick hardware encryption before really23002300- sent out to air.23012301-23022302- Arguments:23032303- pAd Pointer to our adapter23042304- PNDIS_PACKET Pointer to outgoing Ndis frame23052305- NumberOfFrag Number of fragment required23062306-23072307- Return Value:23082308- None23092309-23102310- IRQL = DISPATCH_LEVEL23112311-23122312- Note:23132313-23142314- ========================================================================23152315-*/23162316-NDIS_STATUS STAHardTransmit(23172317- IN PRTMP_ADAPTER pAd,23182318- IN TX_BLK *pTxBlk,23192319- IN UCHAR QueIdx)23202320-{23212321- NDIS_PACKET *pPacket;23222322- PQUEUE_ENTRY pQEntry;23232323-23242324- // ---------------------------------------------23252325- // STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION.23262326- // ---------------------------------------------23272327- //23282328- ASSERT(pTxBlk->TxPacketList.Number);23292329- if (pTxBlk->TxPacketList.Head == NULL)23302330- {23312331- DBGPRINT(RT_DEBUG_ERROR, ("pTxBlk->TotalFrameNum == %ld!\n", pTxBlk->TxPacketList.Number));23322332- return NDIS_STATUS_FAILURE;23332333- }23342334-23352335- pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head);23362336-23372337- // ------------------------------------------------------------------23382338- // STEP 1. WAKE UP PHY23392339- // outgoing frame always wakeup PHY to prevent frame lost and23402340- // turn off PSM bit to improve performance23412341- // ------------------------------------------------------------------23422342- // not to change PSM bit, just send this frame out?23432343- if ((pAd->StaCfg.Psm == PWR_SAVE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))23442344- {23452345- DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicForceWakeup At HardTx\n"));23462346- AsicForceWakeup(pAd, TRUE);23472347- }23482348-23492349- // It should not change PSM bit, when APSD turn on.23502350- if ((!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE))23512351- || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))23522352- || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket)))23532353- {23542354- if ((pAd->StaCfg.Psm == PWR_SAVE) &&23552355- (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP))23562356- MlmeSetPsmBit(pAd, PWR_ACTIVE);23572357- }23582358-23592359- switch (pTxBlk->TxFrameType)23602360- {23612361- case TX_AMPDU_FRAME:23622362- STA_AMPDU_Frame_Tx(pAd, pTxBlk);23632363- break;23642364- case TX_AMSDU_FRAME:23652365- STA_AMSDU_Frame_Tx(pAd, pTxBlk);23662366- break;23672367- case TX_LEGACY_FRAME:23682368- STA_Legacy_Frame_Tx(pAd, pTxBlk);23692369- break;23702370- case TX_MCAST_FRAME:23712371- STA_Legacy_Frame_Tx(pAd, pTxBlk);23722372- break;23732373- case TX_RALINK_FRAME:23742374- STA_ARalink_Frame_Tx(pAd, pTxBlk);23752375- break;23762376- case TX_FRAG_FRAME:23772377- STA_Fragment_Frame_Tx(pAd, pTxBlk);23782378- break;23792379- default:23802380- {23812381- // It should not happened!23822382- DBGPRINT(RT_DEBUG_ERROR, ("Send a pacekt was not classified!! It should not happen!\n"));23832383- while(pTxBlk->TxPacketList.Number)23842384- {23852385- pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);23862386- pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);23872387- if (pPacket)23882388- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);23892389- }23902390- }23912391- break;23922392- }23932393-23942394- return (NDIS_STATUS_SUCCESS);23952395-23962396-}23972397-23982398-ULONG HashBytesPolynomial(UCHAR *value, unsigned int len)23992399-{24002400- unsigned char *word = value;24012401- unsigned int ret = 0;24022402- unsigned int i;24032403-24042404- for(i=0; i < len; i++)24052405- {24062406- int mod = i % 32;24072407- ret ^=(unsigned int) (word[i]) << mod;24082408- ret ^=(unsigned int) (word[i]) >> (32 - mod);24092409- }24102410- return ret;24112411-}24122412-24132413-VOID Sta_Announce_or_Forward_802_3_Packet(24142414- IN PRTMP_ADAPTER pAd,24152415- IN PNDIS_PACKET pPacket,24162416- IN UCHAR FromWhichBSSID)24172417-{24182418- if (TRUE24192419- )24202420- {24212421- announce_802_3_packet(pAd, pPacket);24222422- }24232423- else24242424- {24252425- // release packet24262426- RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);24272427- }24282428-}24292429-11+#include "../../rt2870/sta/rtmp_data.c"
+1-418
drivers/staging/rt3070/sta/sanity.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- sanity.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John Chang 2004-09-01 add WMM support3636-*/3737-#include "../rt_config.h"3838-3939-extern UCHAR CISCO_OUI[];4040-4141-extern UCHAR WPA_OUI[];4242-extern UCHAR RSN_OUI[];4343-extern UCHAR WME_INFO_ELEM[];4444-extern UCHAR WME_PARM_ELEM[];4545-extern UCHAR Ccx2QosInfo[];4646-extern UCHAR RALINK_OUI[];4747-extern UCHAR BROADCOM_OUI[];4848-4949-/*5050- ==========================================================================5151- Description:5252- MLME message sanity check5353- Return:5454- TRUE if all parameters are OK, FALSE otherwise5555- ==========================================================================5656- */5757-BOOLEAN MlmeStartReqSanity(5858- IN PRTMP_ADAPTER pAd,5959- IN VOID *Msg,6060- IN ULONG MsgLen,6161- OUT CHAR Ssid[],6262- OUT UCHAR *pSsidLen)6363-{6464- MLME_START_REQ_STRUCT *Info;6565-6666- Info = (MLME_START_REQ_STRUCT *)(Msg);6767-6868- if (Info->SsidLen > MAX_LEN_OF_SSID)6969- {7070- DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqSanity fail - wrong SSID length\n"));7171- return FALSE;7272- }7373-7474- *pSsidLen = Info->SsidLen;7575- NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);7676-7777- return TRUE;7878-}7979-8080-/*8181- ==========================================================================8282- Description:8383- MLME message sanity check8484- Return:8585- TRUE if all parameters are OK, FALSE otherwise8686-8787- IRQL = DISPATCH_LEVEL8888-8989- ==========================================================================9090- */9191-BOOLEAN PeerAssocRspSanity(9292- IN PRTMP_ADAPTER pAd,9393- IN VOID *pMsg,9494- IN ULONG MsgLen,9595- OUT PUCHAR pAddr2,9696- OUT USHORT *pCapabilityInfo,9797- OUT USHORT *pStatus,9898- OUT USHORT *pAid,9999- OUT UCHAR SupRate[],100100- OUT UCHAR *pSupRateLen,101101- OUT UCHAR ExtRate[],102102- OUT UCHAR *pExtRateLen,103103- OUT HT_CAPABILITY_IE *pHtCapability,104104- OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE105105- OUT UCHAR *pHtCapabilityLen,106106- OUT UCHAR *pAddHtInfoLen,107107- OUT UCHAR *pNewExtChannelOffset,108108- OUT PEDCA_PARM pEdcaParm,109109- OUT UCHAR *pCkipFlag)110110-{111111- CHAR IeType, *Ptr;112112- PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;113113- PEID_STRUCT pEid;114114- ULONG Length = 0;115115-116116- *pNewExtChannelOffset = 0xff;117117- *pHtCapabilityLen = 0;118118- *pAddHtInfoLen = 0;119119- COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);120120- Ptr = pFrame->Octet;121121- Length += LENGTH_802_11;122122-123123- NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);124124- Length += 2;125125- NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);126126- Length += 2;127127- *pCkipFlag = 0;128128- *pExtRateLen = 0;129129- pEdcaParm->bValid = FALSE;130130-131131- if (*pStatus != MLME_SUCCESS)132132- return TRUE;133133-134134- NdisMoveMemory(pAid, &pFrame->Octet[4], 2);135135- Length += 2;136136-137137- // Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform138138- *pAid = (*pAid) & 0x3fff; // AID is low 14-bit139139-140140- // -- get supported rates from payload and advance the pointer141141- IeType = pFrame->Octet[6];142142- *pSupRateLen = pFrame->Octet[7];143143- if ((IeType != IE_SUPP_RATES) || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES))144144- {145145- DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));146146- return FALSE;147147- }148148- else149149- NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);150150-151151- Length = Length + 2 + *pSupRateLen;152152-153153- // many AP implement proprietary IEs in non-standard order, we'd better154154- // tolerate mis-ordered IEs to get best compatibility155155- pEid = (PEID_STRUCT) &pFrame->Octet[8 + (*pSupRateLen)];156156-157157- // get variable fields from payload and advance the pointer158158- while ((Length + 2 + pEid->Len) <= MsgLen)159159- {160160- switch (pEid->Eid)161161- {162162- case IE_EXT_SUPP_RATES:163163- if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)164164- {165165- NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);166166- *pExtRateLen = pEid->Len;167167- }168168- break;169169-170170- case IE_HT_CAP:171171- case IE_HT_CAP2:172172- if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!173173- {174174- NdisMoveMemory(pHtCapability, pEid->Octet, SIZE_HT_CAP_IE);175175-176176- *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));177177- *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));178178-179179- *pHtCapabilityLen = SIZE_HT_CAP_IE;180180- }181181- else182182- {183183- DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));184184- }185185-186186- break;187187- case IE_ADD_HT:188188- case IE_ADD_HT2:189189- if (pEid->Len >= sizeof(ADD_HT_INFO_IE))190190- {191191- // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only192192- // copy first sizeof(ADD_HT_INFO_IE)193193- NdisMoveMemory(pAddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));194194-195195- *(USHORT *)(&pAddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo2));196196- *(USHORT *)(&pAddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo3));197197-198198- *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;199199- }200200- else201201- {202202- DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));203203- }204204-205205- break;206206- case IE_SECONDARY_CH_OFFSET:207207- if (pEid->Len == 1)208208- {209209- *pNewExtChannelOffset = pEid->Octet[0];210210- }211211- else212212- {213213- DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));214214- }215215- break;216216- case IE_AIRONET_CKIP:217217- // 0. Check Aironet IE length, it must be larger or equal to 28218218- // Cisco's AP VxWork version(will not be supported) used this IE length as 28219219- // Cisco's AP IOS version used this IE length as 30220220- if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))221221- break;222222-223223- // 1. Copy CKIP flag byte to buffer for process224224- *pCkipFlag = *(pEid->Octet + 8);225225- break;226226-227227- case IE_AIRONET_IPADDRESS:228228- if (pEid->Len != 0x0A)229229- break;230230-231231- // Get Cisco Aironet IP information232232- if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)233233- NdisMoveMemory(pAd->StaCfg.AironetIPAddress, pEid->Octet + 4, 4);234234- break;235235-236236- // CCX2, WMM use the same IE value237237- // case IE_CCX_V2:238238- case IE_VENDOR_SPECIFIC:239239- // handle WME PARAMTER ELEMENT240240- if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))241241- {242242- PUCHAR ptr;243243- int i;244244-245245- // parsing EDCA parameters246246- pEdcaParm->bValid = TRUE;247247- pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;248248- pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;249249- pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;250250- //pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80;251251- pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;252252- pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;253253- ptr = &pEid->Octet[8];254254- for (i=0; i<4; i++)255255- {256256- UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX257257- pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM258258- pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN259259- pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin260260- pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax261261- pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us262262- ptr += 4; // point to next AC263263- }264264- }265265-266266- // handle CCX IE267267- else268268- {269269- // 0. Check the size and CCX admin control270270- if (pAd->StaCfg.CCXControl.field.Enable == 0)271271- break;272272- if (pEid->Len != 5)273273- break;274274-275275- // Turn CCX2 if matched276276- if (NdisEqualMemory(pEid->Octet, Ccx2IeInfo, 5) == 1)277277- pAd->StaCfg.CCXEnable = TRUE;278278- break;279279- }280280- break;281281-282282- default:283283- DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity - ignore unrecognized EID = %d\n", pEid->Eid));284284- break;285285- }286286-287287- Length = Length + 2 + pEid->Len;288288- pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);289289- }290290-291291- // Force CCX2 enable to TRUE for those AP didn't replay CCX v2 IE, we still force it to be on292292- if (pAd->StaCfg.CCXControl.field.Enable == 1)293293- pAd->StaCfg.CCXEnable = TRUE;294294-295295- return TRUE;296296-}297297-298298-/*299299- ==========================================================================300300- Description:301301- MLME message sanity check302302- Return:303303- TRUE if all parameters are OK, FALSE otherwise304304-305305- IRQL = DISPATCH_LEVEL306306-307307- ==========================================================================308308- */309309-BOOLEAN PeerProbeReqSanity(310310- IN PRTMP_ADAPTER pAd,311311- IN VOID *Msg,312312- IN ULONG MsgLen,313313- OUT PUCHAR pAddr2,314314- OUT CHAR Ssid[],315315- OUT UCHAR *pSsidLen)316316-{317317- UCHAR Idx;318318- UCHAR RateLen;319319- CHAR IeType;320320- PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;321321-322322- COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);323323-324324- if ((pFrame->Octet[0] != IE_SSID) || (pFrame->Octet[1] > MAX_LEN_OF_SSID))325325- {326326- DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",pFrame->Octet[0],pFrame->Octet[1]));327327- return FALSE;328328- }329329-330330- *pSsidLen = pFrame->Octet[1];331331- NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);332332-333333- Idx = *pSsidLen + 2;334334-335335- // -- get supported rates from payload and advance the pointer336336- IeType = pFrame->Octet[Idx];337337- RateLen = pFrame->Octet[Idx + 1];338338- if (IeType != IE_SUPP_RATES)339339- {340340- DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",pFrame->Octet[Idx],pFrame->Octet[Idx+1]));341341- return FALSE;342342- }343343- else344344- {345345- if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))346346- return (FALSE);347347- }348348-349349- return TRUE;350350-}351351-352352-/*353353- ==========================================================================354354- Description:355355-356356- IRQL = DISPATCH_LEVEL357357-358358- ==========================================================================359359- */360360-BOOLEAN GetTimBit(361361- IN CHAR *Ptr,362362- IN USHORT Aid,363363- OUT UCHAR *TimLen,364364- OUT UCHAR *BcastFlag,365365- OUT UCHAR *DtimCount,366366- OUT UCHAR *DtimPeriod,367367- OUT UCHAR *MessageToMe)368368-{369369- UCHAR BitCntl, N1, N2, MyByte, MyBit;370370- CHAR *IdxPtr;371371-372372- IdxPtr = Ptr;373373-374374- IdxPtr ++;375375- *TimLen = *IdxPtr;376376-377377- // get DTIM Count from TIM element378378- IdxPtr ++;379379- *DtimCount = *IdxPtr;380380-381381- // get DTIM Period from TIM element382382- IdxPtr++;383383- *DtimPeriod = *IdxPtr;384384-385385- // get Bitmap Control from TIM element386386- IdxPtr++;387387- BitCntl = *IdxPtr;388388-389389- if ((*DtimCount == 0) && (BitCntl & 0x01))390390- *BcastFlag = TRUE;391391- else392392- *BcastFlag = FALSE;393393-394394- // Parse Partial Virtual Bitmap from TIM element395395- N1 = BitCntl & 0xfe; // N1 is the first bitmap byte#396396- N2 = *TimLen - 4 + N1; // N2 is the last bitmap byte#397397-398398- if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))399399- *MessageToMe = FALSE;400400- else401401- {402402- MyByte = (Aid >> 3) - N1; // my byte position in the bitmap byte-stream403403- MyBit = Aid % 16 - ((MyByte & 0x01)? 8:0);404404-405405- IdxPtr += (MyByte + 1);406406-407407- //if (*IdxPtr)408408- // DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr));409409-410410- if (*IdxPtr & (0x01 << MyBit))411411- *MessageToMe = TRUE;412412- else413413- *MessageToMe = FALSE;414414- }415415-416416- return TRUE;417417-}418418-11+#include "../../rt2870/sta/sanity.c"
+1-1601
drivers/staging/rt3070/sta/sync.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- sync.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- John Chang 2004-09-01 modified for rt2561/26613636- Jan Lee 2006-08-01 modified for rt2860 for 802.11n3737-*/3838-#include "../rt_config.h"3939-4040-#define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) // 2 sec4141-4242-/*4343- ==========================================================================4444- Description:4545- The sync state machine,4646- Parameters:4747- Sm - pointer to the state machine4848- Note:4949- the state machine looks like the following5050-5151- ==========================================================================5252- */5353-VOID SyncStateMachineInit(5454- IN PRTMP_ADAPTER pAd,5555- IN STATE_MACHINE *Sm,5656- OUT STATE_MACHINE_FUNC Trans[])5757-{5858- StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG, (STATE_MACHINE_FUNC)Drop, SYNC_IDLE, SYNC_MACHINE_BASE);5959-6060- // column 16161- StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)MlmeScanReqAction);6262- StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)MlmeJoinReqAction);6363- StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)MlmeStartReqAction);6464- StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeacon);6565- StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ, (STATE_MACHINE_FUNC)PeerProbeReqAction);6666-6767- //column 26868- StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);6969- StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);7070- StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);7171- StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtJoinAction);7272- StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT, (STATE_MACHINE_FUNC)BeaconTimeoutAtJoinAction);7373-7474- // column 37575- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);7676- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);7777- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);7878- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);7979- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);8080- StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT, (STATE_MACHINE_FUNC)ScanTimeoutAction);8181-8282- // timer init8383- RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer, GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE);8484- RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer, GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE);8585-}8686-8787-/*8888- ==========================================================================8989- Description:9090- Beacon timeout handler, executed in timer thread9191-9292- IRQL = DISPATCH_LEVEL9393-9494- ==========================================================================9595- */9696-VOID BeaconTimeout(9797- IN PVOID SystemSpecific1,9898- IN PVOID FunctionContext,9999- IN PVOID SystemSpecific2,100100- IN PVOID SystemSpecific3)101101-{102102- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;103103-104104- DBGPRINT(RT_DEBUG_TRACE,("SYNC - BeaconTimeout\n"));105105-106106- // Do nothing if the driver is starting halt state.107107- // This might happen when timer already been fired before cancel timer with mlmehalt108108- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))109109- return;110110-111111- if ((pAd->CommonCfg.BBPCurrentBW == BW_40)112112- )113113- {114114- UCHAR BBPValue = 0;115115- AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);116116- AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);117117- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);118118- BBPValue &= (~0x18);119119- BBPValue |= 0x10;120120- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);121121- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));122122- }123123-124124- MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL);125125- RT28XX_MLME_HANDLER(pAd);126126-}127127-128128-/*129129- ==========================================================================130130- Description:131131- Scan timeout handler, executed in timer thread132132-133133- IRQL = DISPATCH_LEVEL134134-135135- ==========================================================================136136- */137137-VOID ScanTimeout(138138- IN PVOID SystemSpecific1,139139- IN PVOID FunctionContext,140140- IN PVOID SystemSpecific2,141141- IN PVOID SystemSpecific3)142142-{143143- RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;144144-145145-146146- // Do nothing if the driver is starting halt state.147147- // This might happen when timer already been fired before cancel timer with mlmehalt148148- if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))149149- return;150150-151151- if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL))152152- {153153- RT28XX_MLME_HANDLER(pAd);154154- }155155- else156156- {157157- // To prevent SyncMachine.CurrState is SCAN_LISTEN forever.158158- pAd->MlmeAux.Channel = 0;159159- ScanNextChannel(pAd);160160- if (pAd->CommonCfg.bWirelessEvent)161161- {162162- RTMPSendWirelessEvent(pAd, IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);163163- }164164- }165165-}166166-167167-/*168168- ==========================================================================169169- Description:170170- MLME SCAN req state machine procedure171171- ==========================================================================172172- */173173-VOID MlmeScanReqAction(174174- IN PRTMP_ADAPTER pAd,175175- IN MLME_QUEUE_ELEM *Elem)176176-{177177- UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0;178178- BOOLEAN TimerCancelled;179179- ULONG Now;180180- USHORT Status;181181- PHEADER_802_11 pHdr80211;182182- PUCHAR pOutBuffer = NULL;183183- NDIS_STATUS NStatus;184184-185185- // Check the total scan tries for one single OID command186186- // If this is the CCX 2.0 Case, skip that!187187- if ( !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))188188- {189189- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeScanReqAction before Startup\n"));190190- return;191191- }192192-193193- // Increase the scan retry counters.194194- pAd->StaCfg.ScanCnt++;195195-196196-197197- // first check the parameter sanity198198- if (MlmeScanReqSanity(pAd,199199- Elem->Msg,200200- Elem->MsgLen,201201- &BssType,202202- Ssid,203203- &SsidLen,204204- &ScanType))205205- {206206-207207- // Check for channel load and noise hist request208208- // Suspend MSDU only at scan request, not the last two mentioned209209- if ((ScanType == SCAN_CISCO_NOISE) || (ScanType == SCAN_CISCO_CHANNEL_LOAD))210210- {211211- if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)212212- RTMPSuspendMsduTransmission(pAd); // Suspend MSDU transmission here213213- }214214- else215215- {216216- // Suspend MSDU transmission here217217- RTMPSuspendMsduTransmission(pAd);218218- }219219-220220- //221221- // To prevent data lost.222222- // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.223223- // And should send an NULL data with turned PSM bit off to AP, when scan progress done224224- //225225- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))226226- {227227- NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);228228- if (NStatus == NDIS_STATUS_SUCCESS)229229- {230230- pHdr80211 = (PHEADER_802_11) pOutBuffer;231231- MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);232232- pHdr80211->Duration = 0;233233- pHdr80211->FC.Type = BTYPE_DATA;234234- pHdr80211->FC.PwrMgmt = PWR_SAVE;235235-236236- // Send using priority queue237237- MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));238238- DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n"));239239- MlmeFreeMemory(pAd, pOutBuffer);240240- RTMPusecDelay(5000);241241- }242242- }243243-244244- NdisGetSystemUpTime(&Now);245245- pAd->StaCfg.LastScanTime = Now;246246- // reset all the timers247247- RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);248248- RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);249249-250250- // record desired BSS parameters251251- pAd->MlmeAux.BssType = BssType;252252- pAd->MlmeAux.ScanType = ScanType;253253- pAd->MlmeAux.SsidLen = SsidLen;254254- NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);255255- NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);256256-257257- // start from the first channel258258- pAd->MlmeAux.Channel = FirstChannel(pAd);259259-260260- // Change the scan channel when dealing with CCX beacon report261261- if ((ScanType == SCAN_CISCO_PASSIVE) || (ScanType == SCAN_CISCO_ACTIVE) ||262262- (ScanType == SCAN_CISCO_CHANNEL_LOAD) || (ScanType == SCAN_CISCO_NOISE))263263- pAd->MlmeAux.Channel = pAd->StaCfg.CCXScanChannel;264264-265265- // Let BBP register at 20MHz to do scan266266- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);267267- BBPValue &= (~0x18);268268- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);269269- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));270270- ScanNextChannel(pAd);271271- }272272- else273273- {274274- DBGPRINT_ERR(("SYNC - MlmeScanReqAction() sanity check fail\n"));275275- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;276276- Status = MLME_INVALID_FORMAT;277277- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);278278- }279279-}280280-281281-/*282282- ==========================================================================283283- Description:284284- MLME JOIN req state machine procedure285285- ==========================================================================286286- */287287-VOID MlmeJoinReqAction(288288- IN PRTMP_ADAPTER pAd,289289- IN MLME_QUEUE_ELEM *Elem)290290-{291291- UCHAR BBPValue = 0;292292- BSS_ENTRY *pBss;293293- BOOLEAN TimerCancelled;294294- HEADER_802_11 Hdr80211;295295- NDIS_STATUS NStatus;296296- ULONG FrameLen = 0;297297- PUCHAR pOutBuffer = NULL;298298- PUCHAR pSupRate = NULL;299299- UCHAR SupRateLen;300300- PUCHAR pExtRate = NULL;301301- UCHAR ExtRateLen;302302- UCHAR ASupRate[] = {0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C};303303- UCHAR ASupRateLen = sizeof(ASupRate)/sizeof(UCHAR);304304- MLME_JOIN_REQ_STRUCT *pInfo = (MLME_JOIN_REQ_STRUCT *)(Elem->Msg);305305-306306- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx));307307-308308-309309- // reset all the timers310310- RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);311311- RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);312312-313313- pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx];314314-315315- // record the desired SSID & BSSID we're waiting for316316- COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid);317317-318318- // If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again.319319- if (pBss->Hidden == 0)320320- {321321- NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen);322322- pAd->MlmeAux.SsidLen = pBss->SsidLen;323323- }324324-325325- pAd->MlmeAux.BssType = pBss->BssType;326326- pAd->MlmeAux.Channel = pBss->Channel;327327- pAd->MlmeAux.CentralChannel = pBss->CentralChannel;328328-329329- // Let BBP register at 20MHz to do scan330330- RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);331331- BBPValue &= (~0x18);332332- RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);333333- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));334334-335335- // switch channel and waiting for beacon timer336336- AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);337337- AsicLockChannel(pAd, pAd->MlmeAux.Channel);338338- RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT);339339-340340- do341341- {342342- if (((pAd->CommonCfg.bIEEE80211H == 1) &&343343- (pAd->MlmeAux.Channel > 14) &&344344- RadarChannelCheck(pAd, pAd->MlmeAux.Channel))345345- )346346- {347347- //348348- // We can't send any Probe request frame to meet 802.11h.349349- //350350- if (pBss->Hidden == 0)351351- break;352352- }353353-354354- //355355- // send probe request356356- //357357- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);358358- if (NStatus == NDIS_STATUS_SUCCESS)359359- {360360- if (pAd->MlmeAux.Channel <= 14)361361- {362362- pSupRate = pAd->CommonCfg.SupRate;363363- SupRateLen = pAd->CommonCfg.SupRateLen;364364- pExtRate = pAd->CommonCfg.ExtRate;365365- ExtRateLen = pAd->CommonCfg.ExtRateLen;366366- }367367- else368368- {369369- //370370- // Overwrite Support Rate, CCK rate are not allowed371371- //372372- pSupRate = ASupRate;373373- SupRateLen = ASupRateLen;374374- ExtRateLen = 0;375375- }376376-377377- if (pAd->MlmeAux.BssType == BSS_INFRA)378378- MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, pAd->MlmeAux.Bssid, pAd->MlmeAux.Bssid);379379- else380380- MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);381381-382382- MakeOutgoingFrame(pOutBuffer, &FrameLen,383383- sizeof(HEADER_802_11), &Hdr80211,384384- 1, &SsidIe,385385- 1, &pAd->MlmeAux.SsidLen,386386- pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,387387- 1, &SupRateIe,388388- 1, &SupRateLen,389389- SupRateLen, pSupRate,390390- END_OF_ARGS);391391-392392- if (ExtRateLen)393393- {394394- ULONG Tmp;395395- MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,396396- 1, &ExtRateIe,397397- 1, &ExtRateLen,398398- ExtRateLen, pExtRate,399399- END_OF_ARGS);400400- FrameLen += Tmp;401401- }402402-403403-404404- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);405405- MlmeFreeMemory(pAd, pOutBuffer);406406- }407407- } while (FALSE);408408-409409- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Switch to ch %d, Wait BEACON from %02x:%02x:%02x:%02x:%02x:%02x\n",410410- pBss->Channel, pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2], pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));411411-412412- pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON;413413-}414414-415415-/*416416- ==========================================================================417417- Description:418418- MLME START Request state machine procedure, starting an IBSS419419- ==========================================================================420420- */421421-VOID MlmeStartReqAction(422422- IN PRTMP_ADAPTER pAd,423423- IN MLME_QUEUE_ELEM *Elem)424424-{425425- UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen;426426- BOOLEAN TimerCancelled;427427-428428- // New for WPA security suites429429- UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5430430- NDIS_802_11_VARIABLE_IEs *pVIE = NULL;431431- LARGE_INTEGER TimeStamp;432432- BOOLEAN Privacy;433433- USHORT Status;434434-435435- // Init Variable IE structure436436- pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;437437- pVIE->Length = 0;438438- TimeStamp.u.LowPart = 0;439439- TimeStamp.u.HighPart = 0;440440-441441- if (MlmeStartReqSanity(pAd, Elem->Msg, Elem->MsgLen, Ssid, &SsidLen))442442- {443443- // reset all the timers444444- RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);445445- RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);446446-447447- //448448- // Start a new IBSS. All IBSS parameters are decided now....449449- //450450- DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n"));451451- pAd->MlmeAux.BssType = BSS_ADHOC;452452- NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);453453- pAd->MlmeAux.SsidLen = SsidLen;454454-455455- // generate a radom number as BSSID456456- MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid);457457- DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - generate a radom number as BSSID \n"));458458-459459- Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||460460- (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||461461- (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);462462- pAd->MlmeAux.CapabilityInfo = CAP_GENERATE(0,1,Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 1, 0);463463- pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod;464464- pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin;465465- pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;466466-467467- pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;468468- pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel;469469-470470- pAd->MlmeAux.SupRateLen= pAd->CommonCfg.SupRateLen;471471- NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);472472- RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);473473- pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen;474474- NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);475475- RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);476476-477477- if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)478478- {479479- RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy, &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0], &pAd->MlmeAux.HtCapability, &pAd->MlmeAux.AddHtInfo);480480- pAd->MlmeAux.HtCapabilityLen = sizeof(HT_CAPABILITY_IE);481481- // Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here.482482- DBGPRINT(RT_DEBUG_TRACE, ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n"));483483- }484484- else485485- {486486- pAd->MlmeAux.HtCapabilityLen = 0;487487- pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;488488- }489489- // temporarily not support QOS in IBSS490490- NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));491491- NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));492492- NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));493493-494494- AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);495495- AsicLockChannel(pAd, pAd->MlmeAux.Channel);496496-497497- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n",498498- pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));499499-500500- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;501501- Status = MLME_SUCCESS;502502- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);503503- }504504- else505505- {506506- DBGPRINT_ERR(("SYNC - MlmeStartReqAction() sanity check fail.\n"));507507- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;508508- Status = MLME_INVALID_FORMAT;509509- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);510510- }511511-}512512-513513-/*514514- ==========================================================================515515- Description:516516- peer sends beacon back when scanning517517- ==========================================================================518518- */519519-VOID PeerBeaconAtScanAction(520520- IN PRTMP_ADAPTER pAd,521521- IN MLME_QUEUE_ELEM *Elem)522522-{523523- UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];524524- UCHAR Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel,525525- SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe;526526- CF_PARM CfParm;527527- USHORT BeaconPeriod, AtimWin, CapabilityInfo;528528- PFRAME_802_11 pFrame;529529- LARGE_INTEGER TimeStamp;530530- UCHAR Erp;531531- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];532532- UCHAR SupRateLen, ExtRateLen;533533- USHORT LenVIE;534534- UCHAR CkipFlag;535535- UCHAR AironetCellPowerLimit;536536- EDCA_PARM EdcaParm;537537- QBSS_LOAD_PARM QbssLoad;538538- QOS_CAPABILITY_PARM QosCapability;539539- ULONG RalinkIe;540540- UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5541541- NDIS_802_11_VARIABLE_IEs *pVIE = NULL;542542- HT_CAPABILITY_IE HtCapability;543543- ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE544544- UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;545545- UCHAR AddHtInfoLen;546546- UCHAR NewExtChannelOffset = 0xff;547547-548548- pFrame = (PFRAME_802_11) Elem->Msg;549549- // Init Variable IE structure550550- pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;551551- pVIE->Length = 0;552552-553553- RTMPZeroMemory(&HtCapability, sizeof(HtCapability));554554- RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));555555-556556- if (PeerBeaconAndProbeRspSanity(pAd,557557- Elem->Msg,558558- Elem->MsgLen,559559- Elem->Channel,560560- Addr2,561561- Bssid,562562- Ssid,563563- &SsidLen,564564- &BssType,565565- &BeaconPeriod,566566- &Channel,567567- &NewChannel,568568- &TimeStamp,569569- &CfParm,570570- &AtimWin,571571- &CapabilityInfo,572572- &Erp,573573- &DtimCount,574574- &DtimPeriod,575575- &BcastFlag,576576- &MessageToMe,577577- SupRate,578578- &SupRateLen,579579- ExtRate,580580- &ExtRateLen,581581- &CkipFlag,582582- &AironetCellPowerLimit,583583- &EdcaParm,584584- &QbssLoad,585585- &QosCapability,586586- &RalinkIe,587587- &HtCapabilityLen,588588- &PreNHtCapabilityLen,589589- &HtCapability,590590- &AddHtInfoLen,591591- &AddHtInfo,592592- &NewExtChannelOffset,593593- &LenVIE,594594- pVIE))595595- {596596- ULONG Idx;597597- CHAR Rssi = 0;598598-599599- Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);600600- if (Idx != BSS_NOT_FOUND)601601- Rssi = pAd->ScanTab.BssEntry[Idx].Rssi;602602-603603- Rssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));604604-605605- if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))606606- HtCapabilityLen = SIZE_HT_CAP_IE;607607-608608- if ((pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) && (Channel == pAd->StaCfg.CCXScanChannel))609609- {610610- Idx = BssTableSetEntry(pAd, &pAd->StaCfg.CCXBssTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,611611- &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen,ExtRate, ExtRateLen, &HtCapability,612612- &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,613613- &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);614614- if (Idx != BSS_NOT_FOUND)615615- {616616- NdisMoveMemory(pAd->StaCfg.CCXBssTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);617617- NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);618618- NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);619619- if (pAd->StaCfg.CCXReqType == MSRN_TYPE_BEACON_REQ)620620- AironetAddBeaconReport(pAd, Idx, Elem);621621- }622622- }623623- else624624- {625625- Idx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,626626- &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,627627- &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,628628- &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);629629-630630- if (Idx != BSS_NOT_FOUND)631631- {632632- NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);633633- NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);634634- NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);635635- }636636- }637637- }638638- // sanity check fail, ignored639639-}640640-641641-/*642642- ==========================================================================643643- Description:644644- When waiting joining the (I)BSS, beacon received from external645645- ==========================================================================646646- */647647-VOID PeerBeaconAtJoinAction(648648- IN PRTMP_ADAPTER pAd,649649- IN MLME_QUEUE_ELEM *Elem)650650-{651651- UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];652652- UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe,653653- DtimCount, DtimPeriod, BcastFlag, NewChannel;654654- LARGE_INTEGER TimeStamp;655655- USHORT BeaconPeriod, AtimWin, CapabilityInfo;656656- CF_PARM Cf;657657- BOOLEAN TimerCancelled;658658- UCHAR Erp;659659- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];660660- UCHAR SupRateLen, ExtRateLen;661661- UCHAR CkipFlag;662662- USHORT LenVIE;663663- UCHAR AironetCellPowerLimit;664664- EDCA_PARM EdcaParm;665665- QBSS_LOAD_PARM QbssLoad;666666- QOS_CAPABILITY_PARM QosCapability;667667- USHORT Status;668668- UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5669669- NDIS_802_11_VARIABLE_IEs *pVIE = NULL;670670- ULONG RalinkIe;671671- ULONG Idx;672672- HT_CAPABILITY_IE HtCapability;673673- ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE674674- UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;675675- UCHAR AddHtInfoLen;676676- UCHAR NewExtChannelOffset = 0xff;677677- UCHAR CentralChannel;678678-679679- // Init Variable IE structure680680- pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;681681- pVIE->Length = 0;682682- RTMPZeroMemory(&HtCapability, sizeof(HtCapability));683683- RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));684684-685685-686686- if (PeerBeaconAndProbeRspSanity(pAd,687687- Elem->Msg,688688- Elem->MsgLen,689689- Elem->Channel,690690- Addr2,691691- Bssid,692692- Ssid,693693- &SsidLen,694694- &BssType,695695- &BeaconPeriod,696696- &Channel,697697- &NewChannel,698698- &TimeStamp,699699- &Cf,700700- &AtimWin,701701- &CapabilityInfo,702702- &Erp,703703- &DtimCount,704704- &DtimPeriod,705705- &BcastFlag,706706- &MessageToMe,707707- SupRate,708708- &SupRateLen,709709- ExtRate,710710- &ExtRateLen,711711- &CkipFlag,712712- &AironetCellPowerLimit,713713- &EdcaParm,714714- &QbssLoad,715715- &QosCapability,716716- &RalinkIe,717717- &HtCapabilityLen,718718- &PreNHtCapabilityLen,719719- &HtCapability,720720- &AddHtInfoLen,721721- &AddHtInfo,722722- &NewExtChannelOffset,723723- &LenVIE,724724- pVIE))725725- {726726- // Disqualify 11b only adhoc when we are in 11g only adhoc mode727727- if ((BssType == BSS_ADHOC) && (pAd->CommonCfg.PhyMode == PHY_11G) && ((SupRateLen+ExtRateLen)< 12))728728- return;729729-730730- // BEACON from desired BSS/IBSS found. We should be able to decide most731731- // BSS parameters here.732732- // Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATEION?733733- // Do we need to receover back all parameters belonging to previous BSS?734734- // A. Should be not. There's no back-door recover to previous AP. It still need735735- // a new JOIN-AUTH-ASSOC sequence.736736- if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid))737737- {738738- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n", Channel));739739- RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);740740-741741- // Update RSSI to prevent No signal display when cards first initialized742742- pAd->StaCfg.RssiSample.LastRssi0 = ConvertToRssi(pAd, Elem->Rssi0, RSSI_0);743743- pAd->StaCfg.RssiSample.LastRssi1 = ConvertToRssi(pAd, Elem->Rssi1, RSSI_1);744744- pAd->StaCfg.RssiSample.LastRssi2 = ConvertToRssi(pAd, Elem->Rssi2, RSSI_2);745745- pAd->StaCfg.RssiSample.AvgRssi0 = pAd->StaCfg.RssiSample.LastRssi0;746746- pAd->StaCfg.RssiSample.AvgRssi0X8 = pAd->StaCfg.RssiSample.AvgRssi0 << 3;747747- pAd->StaCfg.RssiSample.AvgRssi1 = pAd->StaCfg.RssiSample.LastRssi1;748748- pAd->StaCfg.RssiSample.AvgRssi1X8 = pAd->StaCfg.RssiSample.AvgRssi1 << 3;749749- pAd->StaCfg.RssiSample.AvgRssi2 = pAd->StaCfg.RssiSample.LastRssi2;750750- pAd->StaCfg.RssiSample.AvgRssi2X8 = pAd->StaCfg.RssiSample.AvgRssi2 << 3;751751-752752- //753753- // We need to check if SSID only set to any, then we can record the current SSID.754754- // Otherwise will cause hidden SSID association failed.755755- //756756- if (pAd->MlmeAux.SsidLen == 0)757757- {758758- NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);759759- pAd->MlmeAux.SsidLen = SsidLen;760760- }761761- else762762- {763763- Idx = BssSsidTableSearch(&pAd->ScanTab, Bssid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Channel);764764-765765- if (Idx != BSS_NOT_FOUND)766766- {767767- //768768- // Multiple SSID case, used correct CapabilityInfo769769- //770770- CapabilityInfo = pAd->ScanTab.BssEntry[Idx].CapabilityInfo;771771- }772772- }773773- NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN);774774- pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;775775- pAd->MlmeAux.BssType = BssType;776776- pAd->MlmeAux.BeaconPeriod = BeaconPeriod;777777- pAd->MlmeAux.Channel = Channel;778778- pAd->MlmeAux.AtimWin = AtimWin;779779- pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod;780780- pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;781781- pAd->MlmeAux.APRalinkIe = RalinkIe;782782-783783- // Copy AP's supported rate to MlmeAux for creating assoication request784784- // Also filter out not supported rate785785- pAd->MlmeAux.SupRateLen = SupRateLen;786786- NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);787787- RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);788788- pAd->MlmeAux.ExtRateLen = ExtRateLen;789789- NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);790790- RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);791791-792792- NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, 16);793793-794794- pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;795795- pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen;796796-797797- // filter out un-supported ht rates798798- if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))799799- {800800- RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);801801- RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo, &AddHtInfo, SIZE_ADD_HT_INFO_IE);802802-803803- // StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability804804- NdisMoveMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, HtCapability.MCSSet, 16);805805- pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;806806- pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE;807807- pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;808808- if (PreNHtCapabilityLen > 0)809809- pAd->StaActive.SupportedPhyInfo.bPreNHt = TRUE;810810- RTMPCheckHt(pAd, BSSID_WCID, &HtCapability, &AddHtInfo);811811- // Copy AP Parameter to StaActive. This is also in LinkUp.812812- DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n",813813- pAd->StaActive.SupportedHtPhy.MpduDensity, pAd->StaActive.SupportedHtPhy.MaxRAmpduFactor, HtCapability.HtCapInfo.ChannelWidth));814814-815815- if (AddHtInfoLen > 0)816816- {817817- CentralChannel = AddHtInfo.ControlChan;818818- // Check again the Bandwidth capability of this AP.819819- if ((AddHtInfo.ControlChan > 2)&& (AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))820820- {821821- CentralChannel = AddHtInfo.ControlChan - 2;822822- }823823- else if ((AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))824824- {825825- CentralChannel = AddHtInfo.ControlChan + 2;826826- }827827-828828- // Check Error .829829- if (pAd->MlmeAux.CentralChannel != CentralChannel)830830- DBGPRINT(RT_DEBUG_ERROR, ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n", CentralChannel, AddHtInfo.ControlChan, pAd->MlmeAux.CentralChannel));831831-832832- DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n", CentralChannel, AddHtInfo.ControlChan));833833-834834- }835835-836836- }837837- else838838- {839839- // To prevent error, let legacy AP must have same CentralChannel and Channel.840840- if ((HtCapabilityLen == 0) && (PreNHtCapabilityLen == 0))841841- pAd->MlmeAux.CentralChannel = pAd->MlmeAux.Channel;842842-843843- pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;844844- RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);845845- RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo, SIZE_ADD_HT_INFO_IE);846846- }847847-848848- RTMPUpdateMlmeRate(pAd);849849-850850- // copy QOS related information851851- if ((pAd->CommonCfg.bWmmCapable)852852- || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)853853- )854854- {855855- NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, &EdcaParm, sizeof(EDCA_PARM));856856- NdisMoveMemory(&pAd->MlmeAux.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));857857- NdisMoveMemory(&pAd->MlmeAux.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));858858- }859859- else860860- {861861- NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));862862- NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));863863- NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));864864- }865865-866866- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n",867867- pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));868868-869869- if (AironetCellPowerLimit != 0xFF)870870- {871871- //We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power872872- ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);873873- }874874- else //Used the default TX Power Percentage.875875- pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;876876-877877- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;878878- Status = MLME_SUCCESS;879879- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);880880- }881881- // not to me BEACON, ignored882882- }883883- // sanity check fail, ignore this frame884884-}885885-886886-/*887887- ==========================================================================888888- Description:889889- receive BEACON from peer890890-891891- IRQL = DISPATCH_LEVEL892892-893893- ==========================================================================894894- */895895-VOID PeerBeacon(896896- IN PRTMP_ADAPTER pAd,897897- IN MLME_QUEUE_ELEM *Elem)898898-{899899- UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];900900- CHAR Ssid[MAX_LEN_OF_SSID];901901- CF_PARM CfParm;902902- UCHAR SsidLen, MessageToMe=0, BssType, Channel, NewChannel, index=0;903903- UCHAR DtimCount=0, DtimPeriod=0, BcastFlag=0;904904- USHORT CapabilityInfo, AtimWin, BeaconPeriod;905905- LARGE_INTEGER TimeStamp;906906- USHORT TbttNumToNextWakeUp;907907- UCHAR Erp;908908- UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];909909- UCHAR SupRateLen, ExtRateLen;910910- UCHAR CkipFlag;911911- USHORT LenVIE;912912- UCHAR AironetCellPowerLimit;913913- EDCA_PARM EdcaParm;914914- QBSS_LOAD_PARM QbssLoad;915915- QOS_CAPABILITY_PARM QosCapability;916916- ULONG RalinkIe;917917- // New for WPA security suites918918- UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5919919- NDIS_802_11_VARIABLE_IEs *pVIE = NULL;920920- HT_CAPABILITY_IE HtCapability;921921- ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE922922- UCHAR HtCapabilityLen, PreNHtCapabilityLen;923923- UCHAR AddHtInfoLen;924924- UCHAR NewExtChannelOffset = 0xff;925925-926926- if (!(INFRA_ON(pAd) || ADHOC_ON(pAd)927927- ))928928- return;929929-930930- // Init Variable IE structure931931- pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;932932- pVIE->Length = 0;933933- RTMPZeroMemory(&HtCapability, sizeof(HtCapability));934934- RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));935935-936936- if (PeerBeaconAndProbeRspSanity(pAd,937937- Elem->Msg,938938- Elem->MsgLen,939939- Elem->Channel,940940- Addr2,941941- Bssid,942942- Ssid,943943- &SsidLen,944944- &BssType,945945- &BeaconPeriod,946946- &Channel,947947- &NewChannel,948948- &TimeStamp,949949- &CfParm,950950- &AtimWin,951951- &CapabilityInfo,952952- &Erp,953953- &DtimCount,954954- &DtimPeriod,955955- &BcastFlag,956956- &MessageToMe,957957- SupRate,958958- &SupRateLen,959959- ExtRate,960960- &ExtRateLen,961961- &CkipFlag,962962- &AironetCellPowerLimit,963963- &EdcaParm,964964- &QbssLoad,965965- &QosCapability,966966- &RalinkIe,967967- &HtCapabilityLen,968968- &PreNHtCapabilityLen,969969- &HtCapability,970970- &AddHtInfoLen,971971- &AddHtInfo,972972- &NewExtChannelOffset,973973- &LenVIE,974974- pVIE))975975- {976976- BOOLEAN is_my_bssid, is_my_ssid;977977- ULONG Bssidx, Now;978978- BSS_ENTRY *pBss;979979- CHAR RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));980980-981981- is_my_bssid = MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid)? TRUE : FALSE;982982- is_my_ssid = SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen)? TRUE:FALSE;983983-984984-985985- // ignore BEACON not for my SSID986986- if ((! is_my_ssid) && (! is_my_bssid))987987- return;988988-989989- // It means STA waits disassoc completely from this AP, ignores this beacon.990990- if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC)991991- return;992992-993993- // Copy Control channel for this BSSID.994994- if (AddHtInfoLen != 0)995995- Channel = AddHtInfo.ControlChan;996996-997997- if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))998998- HtCapabilityLen = SIZE_HT_CAP_IE;999999-10001000- //10011001- // Housekeeping "SsidBssTab" table for later-on ROAMing usage.10021002- //10031003- Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);10041004- if (Bssidx == BSS_NOT_FOUND)10051005- {10061006- // discover new AP of this network, create BSS entry10071007- Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,10081008- &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,10091009- &HtCapability, &AddHtInfo,HtCapabilityLen,AddHtInfoLen,NewExtChannelOffset, Channel,10101010- RealRssi, TimeStamp, CkipFlag, &EdcaParm, &QosCapability,10111011- &QbssLoad, LenVIE, pVIE);10121012- if (Bssidx == BSS_NOT_FOUND) // return if BSS table full10131013- return;10141014-10151015- NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF, &Elem->Msg[24], 4);10161016- NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);10171017- NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);10181018-10191019-10201020-10211021- }10221022-10231023- if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))10241024- {10251025- // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).10261026- // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.10271027- AsicSwitchChannel(pAd, 1, FALSE);10281028- AsicLockChannel(pAd, 1);10291029- LinkDown(pAd, FALSE);10301030- MlmeQueueInit(&pAd->Mlme.Queue);10311031- BssTableInit(&pAd->ScanTab);10321032- RTMPusecDelay(1000000); // use delay to prevent STA do reassoc10331033-10341034- // channel sanity check10351035- for (index = 0 ; index < pAd->ChannelListNum; index++)10361036- {10371037- if (pAd->ChannelList[index].Channel == NewChannel)10381038- {10391039- pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;10401040- pAd->CommonCfg.Channel = NewChannel;10411041- AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);10421042- AsicLockChannel(pAd, pAd->CommonCfg.Channel);10431043- DBGPRINT(RT_DEBUG_TRACE, ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));10441044- break;10451045- }10461046- }10471047-10481048- if (index >= pAd->ChannelListNum)10491049- {10501050- DBGPRINT_ERR(("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));10511051- }10521052- }10531053-10541054- // if the ssid matched & bssid unmatched, we should select the bssid with large value.10551055- // This might happened when two STA start at the same time10561056- if ((! is_my_bssid) && ADHOC_ON(pAd))10571057- {10581058- INT i;10591059-10601060- // Add the safeguard against the mismatch of adhoc wep status10611061- if (pAd->StaCfg.WepStatus != pAd->ScanTab.BssEntry[Bssidx].WepStatus)10621062- {10631063- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Not matched wep status %d %d\n", pAd->StaCfg.WepStatus, pAd->ScanTab.BssEntry[Bssidx].WepStatus));10641064- DBGPRINT(RT_DEBUG_TRACE, ("bssid=%s\n", pAd->ScanTab.BssEntry[Bssidx].Bssid));10651065- return;10661066- }10671067-10681068- // collapse into the ADHOC network which has bigger BSSID value.10691069- for (i = 0; i < 6; i++)10701070- {10711071- if (Bssid[i] > pAd->CommonCfg.Bssid[i])10721072- {10731073- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - merge to the IBSS with bigger BSSID=%02x:%02x:%02x:%02x:%02x:%02x\n",10741074- Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));10751075- AsicDisableSync(pAd);10761076- COPY_MAC_ADDR(pAd->CommonCfg.Bssid, Bssid);10771077- AsicSetBssid(pAd, pAd->CommonCfg.Bssid);10781078- MakeIbssBeacon(pAd); // re-build BEACON frame10791079- AsicEnableIbssSync(pAd); // copy BEACON frame to on-chip memory10801080- is_my_bssid = TRUE;10811081- break;10821082- }10831083- else if (Bssid[i] < pAd->CommonCfg.Bssid[i])10841084- break;10851085- }10861086- }10871087-10881088-10891089- NdisGetSystemUpTime(&Now);10901090- pBss = &pAd->ScanTab.BssEntry[Bssidx];10911091- pBss->Rssi = RealRssi; // lastest RSSI10921092- pBss->LastBeaconRxTime = Now; // last RX timestamp10931093-10941094- //10951095- // BEACON from my BSSID - either IBSS or INFRA network10961096- //10971097- if (is_my_bssid)10981098- {10991099- RXWI_STRUC RxWI;11001100-11011101- pAd->StaCfg.DtimCount = DtimCount;11021102- pAd->StaCfg.DtimPeriod = DtimPeriod;11031103- pAd->StaCfg.LastBeaconRxTime = Now;11041104-11051105-11061106- RxWI.RSSI0 = Elem->Rssi0;11071107- RxWI.RSSI1 = Elem->Rssi1;11081108- RxWI.RSSI2 = Elem->Rssi2;11091109-11101110- Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI);11111111- if (AironetCellPowerLimit != 0xFF)11121112- {11131113- //11141114- // We get the Cisco (ccx) "TxPower Limit" required11151115- // Changed to appropriate TxPower Limit for Ciso Compatible Extensions11161116- //11171117- ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);11181118- }11191119- else11201120- {11211121- //11221122- // AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist.11231123- // Used the default TX Power Percentage, that set from UI.11241124- //11251125- pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;11261126- }11271127-11281128- if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo)))11291129- {11301130- UCHAR MaxSupportedRateIn500Kbps = 0;11311131- UCHAR idx;11321132- MAC_TABLE_ENTRY *pEntry;11331133-11341134- // supported rates array may not be sorted. sort it and find the maximum rate11351135- for (idx=0; idx<SupRateLen; idx++)11361136- {11371137- if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))11381138- MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;11391139- }11401140-11411141- for (idx=0; idx<ExtRateLen; idx++)11421142- {11431143- if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))11441144- MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;11451145- }11461146-11471147- // look up the existing table11481148- pEntry = MacTableLookup(pAd, Addr2);11491149-11501150- // Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon.11511151- // To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station.11521152- if ((ADHOC_ON(pAd) && (Elem->Wcid == RESERVED_WCID)) ||11531153- (pEntry && ((pEntry->LastBeaconRxTime + ADHOC_ENTRY_BEACON_LOST_TIME) < Now)))11541154- {11551155- if (pEntry == NULL)11561156- // Another adhoc joining, add to our MAC table.11571157- pEntry = MacTableInsertEntry(pAd, Addr2, BSS0, FALSE);11581158-11591159- if (StaAddMacTableEntry(pAd, pEntry, MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo) == FALSE)11601160- {11611161- DBGPRINT(RT_DEBUG_TRACE, ("ADHOC - Add Entry failed.\n"));11621162- return;11631163- }11641164-11651165- if (pEntry &&11661166- (Elem->Wcid == RESERVED_WCID))11671167- {11681168- idx = pAd->StaCfg.DefaultKeyId;11691169- RT28XX_STA_SECURITY_INFO_ADD(pAd, BSS0, idx, pEntry);11701170- }11711171- }11721172-11731173- if (pEntry && pEntry->ValidAsCLI)11741174- pEntry->LastBeaconRxTime = Now;11751175-11761176- // At least another peer in this IBSS, declare MediaState as CONNECTED11771177- if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))11781178- {11791179- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);11801180-11811181- pAd->IndicateMediaState = NdisMediaStateConnected;11821182- RTMP_IndicateMediaState(pAd);11831183- pAd->ExtraInfo = GENERAL_LINK_UP;11841184- AsicSetBssid(pAd, pAd->CommonCfg.Bssid);11851185-11861186- // 2003/03/12 - john11871187- // Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that11881188- // "site survey" result should always include the current connected network.11891189- //11901190- Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);11911191- if (Bssidx == BSS_NOT_FOUND)11921192- {11931193- Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,11941194- &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,11951195- &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, RealRssi, TimeStamp, 0,11961196- &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);11971197- }11981198- DBGPRINT(RT_DEBUG_TRACE, ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n"));11991199- }12001200- }12011201-12021202- if (INFRA_ON(pAd))12031203- {12041204- BOOLEAN bUseShortSlot, bUseBGProtection;12051205-12061206- // decide to use/change to -12071207- // 1. long slot (20 us) or short slot (9 us) time12081208- // 2. turn on/off RTS/CTS and/or CTS-to-self protection12091209- // 3. short preamble12101210-12111211- //bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo);12121212- bUseShortSlot = CAP_IS_SHORT_SLOT(CapabilityInfo);12131213- if (bUseShortSlot != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))12141214- AsicSetSlotTime(pAd, bUseShortSlot);12151215-12161216- bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || // always use12171217- ((pAd->CommonCfg.UseBGProtection == 0) && ERP_IS_USE_PROTECTION(Erp));12181218-12191219- if (pAd->CommonCfg.Channel > 14) // always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP12201220- bUseBGProtection = FALSE;12211221-12221222- if (bUseBGProtection != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))12231223- {12241224- if (bUseBGProtection)12251225- {12261226- OPSTATUS_SET_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);12271227- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),FALSE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));12281228- }12291229- else12301230- {12311231- OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);12321232- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),TRUE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));12331233- }12341234-12351235- DBGPRINT(RT_DEBUG_WARN, ("SYNC - AP changed B/G protection to %d\n", bUseBGProtection));12361236- }12371237-12381238- // check Ht protection mode. and adhere to the Non-GF device indication by AP.12391239- if ((AddHtInfoLen != 0) &&12401240- ((AddHtInfo.AddHtInfo2.OperaionMode != pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode) ||12411241- (AddHtInfo.AddHtInfo2.NonGfPresent != pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent)))12421242- {12431243- pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent = AddHtInfo.AddHtInfo2.NonGfPresent;12441244- pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode = AddHtInfo.AddHtInfo2.OperaionMode;12451245- if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)12461246- {12471247- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);12481248- }12491249- else12501250- AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);12511251-12521252- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP changed N OperaionMode to %d\n", pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode));12531253- }12541254-12551255- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED) &&12561256- ERP_IS_USE_BARKER_PREAMBLE(Erp))12571257- {12581258- MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);12591259- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP forced to use LONG preamble\n"));12601260- }12611261-12621262- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&12631263- (EdcaParm.bValid == TRUE) &&12641264- (EdcaParm.EdcaUpdateCount != pAd->CommonCfg.APEdcaParm.EdcaUpdateCount))12651265- {12661266- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP change EDCA parameters(from %d to %d)\n",12671267- pAd->CommonCfg.APEdcaParm.EdcaUpdateCount,12681268- EdcaParm.EdcaUpdateCount));12691269- AsicSetEdcaParm(pAd, &EdcaParm);12701270- }12711271-12721272- // copy QOS related information12731273- NdisMoveMemory(&pAd->CommonCfg.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));12741274- NdisMoveMemory(&pAd->CommonCfg.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));12751275- }12761276-12771277- // only INFRASTRUCTURE mode support power-saving feature12781278- if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE)) || (pAd->CommonCfg.bAPSDForcePowerSave))12791279- {12801280- UCHAR FreeNumber;12811281- // 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL12821282- // 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE12831283- // 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE12841284- // 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE12851285- // 5. otherwise, put PHY back to sleep to save battery.12861286- if (MessageToMe)12871287- {12881288- if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable &&12891289- pAd->CommonCfg.bAPSDAC_BE && pAd->CommonCfg.bAPSDAC_BK && pAd->CommonCfg.bAPSDAC_VI && pAd->CommonCfg.bAPSDAC_VO)12901290- {12911291- pAd->CommonCfg.bNeedSendTriggerFrame = TRUE;12921292- }12931293- else12941294- RT28XX_PS_POLL_ENQUEUE(pAd);12951295- }12961296- else if (BcastFlag && (DtimCount == 0) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM))12971297- {12981298- }12991299- else if ((pAd->TxSwQueue[QID_AC_BK].Number != 0) ||13001300- (pAd->TxSwQueue[QID_AC_BE].Number != 0) ||13011301- (pAd->TxSwQueue[QID_AC_VI].Number != 0) ||13021302- (pAd->TxSwQueue[QID_AC_VO].Number != 0) ||13031303- (RTMPFreeTXDRequest(pAd, QID_AC_BK, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||13041304- (RTMPFreeTXDRequest(pAd, QID_AC_BE, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||13051305- (RTMPFreeTXDRequest(pAd, QID_AC_VI, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||13061306- (RTMPFreeTXDRequest(pAd, QID_AC_VO, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||13071307- (RTMPFreeTXDRequest(pAd, QID_MGMT, MGMT_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS))13081308- {13091309- // TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme13101310- // can we cheat here (i.e. just check MGMT & AC_BE) for better performance?13111311- }13121312- else13131313- {13141314- USHORT NextDtim = DtimCount;13151315-13161316- if (NextDtim == 0)13171317- NextDtim = DtimPeriod;13181318-13191319- TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;13201320- if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))13211321- TbttNumToNextWakeUp = NextDtim;13221322-13231323- if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))13241324- {13251325- AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);13261326- }13271327- }13281328- }13291329- }13301330- // not my BSSID, ignore it13311331- }13321332- // sanity check fail, ignore this frame13331333-}13341334-13351335-/*13361336- ==========================================================================13371337- Description:13381338- Receive PROBE REQ from remote peer when operating in IBSS mode13391339- ==========================================================================13401340- */13411341-VOID PeerProbeReqAction(13421342- IN PRTMP_ADAPTER pAd,13431343- IN MLME_QUEUE_ELEM *Elem)13441344-{13451345- UCHAR Addr2[MAC_ADDR_LEN];13461346- CHAR Ssid[MAX_LEN_OF_SSID];13471347- UCHAR SsidLen;13481348- UCHAR HtLen, AddHtLen, NewExtLen;13491349- HEADER_802_11 ProbeRspHdr;13501350- NDIS_STATUS NStatus;13511351- PUCHAR pOutBuffer = NULL;13521352- ULONG FrameLen = 0;13531353- LARGE_INTEGER FakeTimestamp;13541354- UCHAR DsLen = 1, IbssLen = 2;13551355- UCHAR LocalErpIe[3] = {IE_ERP, 1, 0};13561356- BOOLEAN Privacy;13571357- USHORT CapabilityInfo;13581358- UCHAR RSNIe = IE_WPA;13591359-13601360- if (! ADHOC_ON(pAd))13611361- return;13621362-13631363- if (PeerProbeReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen))13641364- {13651365- if ((SsidLen == 0) || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))13661366- {13671367- // allocate and send out ProbeRsp frame13681368- NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory13691369- if (NStatus != NDIS_STATUS_SUCCESS)13701370- return;13711371-13721372- //pAd->StaCfg.AtimWin = 0; // ??????13731373-13741374- Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||13751375- (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||13761376- (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);13771377- CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);13781378-13791379- MakeOutgoingFrame(pOutBuffer, &FrameLen,13801380- sizeof(HEADER_802_11), &ProbeRspHdr,13811381- TIMESTAMP_LEN, &FakeTimestamp,13821382- 2, &pAd->CommonCfg.BeaconPeriod,13831383- 2, &CapabilityInfo,13841384- 1, &SsidIe,13851385- 1, &pAd->CommonCfg.SsidLen,13861386- pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,13871387- 1, &SupRateIe,13881388- 1, &pAd->StaActive.SupRateLen,13891389- pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,13901390- 1, &DsIe,13911391- 1, &DsLen,13921392- 1, &pAd->CommonCfg.Channel,13931393- 1, &IbssIe,13941394- 1, &IbssLen,13951395- 2, &pAd->StaActive.AtimWin,13961396- END_OF_ARGS);13971397-13981398- if (pAd->StaActive.ExtRateLen)13991399- {14001400- ULONG tmp;14011401- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,14021402- 3, LocalErpIe,14031403- 1, &ExtRateIe,14041404- 1, &pAd->StaActive.ExtRateLen,14051405- pAd->StaActive.ExtRateLen, &pAd->StaActive.ExtRate,14061406- END_OF_ARGS);14071407- FrameLen += tmp;14081408- }14091409-14101410- // If adhoc secruity is set for WPA-None, append the cipher suite IE14111411- if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)14121412- {14131413- ULONG tmp;14141414- MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,14151415- 1, &RSNIe,14161416- 1, &pAd->StaCfg.RSNIE_Len,14171417- pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,14181418- END_OF_ARGS);14191419- FrameLen += tmp;14201420- }14211421-14221422- if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)14231423- {14241424- ULONG TmpLen;14251425- UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};14261426- HtLen = sizeof(pAd->CommonCfg.HtCapability);14271427- AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo);14281428- NewExtLen = 1;14291429- //New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame14301430- if (pAd->bBroadComHT == TRUE)14311431- {14321432- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,14331433- 1, &WpaIe,14341434- 4, &BROADCOM[0],14351435- pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,14361436- END_OF_ARGS);14371437- }14381438- else14391439- {14401440- MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,14411441- 1, &HtCapIe,14421442- 1, &HtLen,14431443- sizeof(HT_CAPABILITY_IE), &pAd->CommonCfg.HtCapability,14441444- 1, &AddHtInfoIe,14451445- 1, &AddHtLen,14461446- sizeof(ADD_HT_INFO_IE), &pAd->CommonCfg.AddHTInfo,14471447- 1, &NewExtChanIe,14481448- 1, &NewExtLen,14491449- sizeof(NEW_EXT_CHAN_IE), &pAd->CommonCfg.NewExtChanOffset,14501450- END_OF_ARGS);14511451- }14521452- FrameLen += TmpLen;14531453- }14541454-14551455- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);14561456- MlmeFreeMemory(pAd, pOutBuffer);14571457- }14581458- }14591459-}14601460-14611461-VOID BeaconTimeoutAtJoinAction(14621462- IN PRTMP_ADAPTER pAd,14631463- IN MLME_QUEUE_ELEM *Elem)14641464-{14651465- USHORT Status;14661466- DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n"));14671467- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;14681468- Status = MLME_REJ_TIMEOUT;14691469- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);14701470-}14711471-14721472-/*14731473- ==========================================================================14741474- Description:14751475- Scan timeout procedure. basically add channel index by 1 and rescan14761476- ==========================================================================14771477- */14781478-VOID ScanTimeoutAction(14791479- IN PRTMP_ADAPTER pAd,14801480- IN MLME_QUEUE_ELEM *Elem)14811481-{14821482- pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel);14831483-14841484- // Only one channel scanned for CISCO beacon request14851485- if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) ||14861486- (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) ||14871487- (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) ||14881488- (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD))14891489- pAd->MlmeAux.Channel = 0;14901490-14911491- // this routine will stop if pAd->MlmeAux.Channel == 014921492- ScanNextChannel(pAd);14931493-}14941494-14951495-/*14961496- ==========================================================================14971497- Description:14981498- ==========================================================================14991499- */15001500-VOID InvalidStateWhenScan(15011501- IN PRTMP_ADAPTER pAd,15021502- IN MLME_QUEUE_ELEM *Elem)15031503-{15041504- USHORT Status;15051505- DBGPRINT(RT_DEBUG_TRACE, ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));15061506- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;15071507- Status = MLME_STATE_MACHINE_REJECT;15081508- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);15091509-}15101510-15111511-/*15121512- ==========================================================================15131513- Description:15141514- ==========================================================================15151515- */15161516-VOID InvalidStateWhenJoin(15171517- IN PRTMP_ADAPTER pAd,15181518- IN MLME_QUEUE_ELEM *Elem)15191519-{15201520- USHORT Status;15211521- DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));15221522- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;15231523- Status = MLME_STATE_MACHINE_REJECT;15241524- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);15251525-}15261526-15271527-/*15281528- ==========================================================================15291529- Description:15301530- ==========================================================================15311531- */15321532-VOID InvalidStateWhenStart(15331533- IN PRTMP_ADAPTER pAd,15341534- IN MLME_QUEUE_ELEM *Elem)15351535-{15361536- USHORT Status;15371537- DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));15381538- pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;15391539- Status = MLME_STATE_MACHINE_REJECT;15401540- MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);15411541-}15421542-15431543-/*15441544- ==========================================================================15451545- Description:15461546-15471547- IRQL = DISPATCH_LEVEL15481548-15491549- ==========================================================================15501550- */15511551-VOID EnqueuePsPoll(15521552- IN PRTMP_ADAPTER pAd)15531553-{15541554- if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP)15551555- pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE;15561556- MiniportMMRequest(pAd, 0, (PUCHAR)&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));15571557-}15581558-15591559-15601560-/*15611561- ==========================================================================15621562- Description:15631563- ==========================================================================15641564- */15651565-VOID EnqueueProbeRequest(15661566- IN PRTMP_ADAPTER pAd)15671567-{15681568- NDIS_STATUS NState;15691569- PUCHAR pOutBuffer;15701570- ULONG FrameLen = 0;15711571- HEADER_802_11 Hdr80211;15721572-15731573- DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n"));15741574-15751575- NState = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory15761576- if (NState == NDIS_STATUS_SUCCESS)15771577- {15781578- MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);15791579-15801580- // this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse15811581- MakeOutgoingFrame(pOutBuffer, &FrameLen,15821582- sizeof(HEADER_802_11), &Hdr80211,15831583- 1, &SsidIe,15841584- 1, &pAd->CommonCfg.SsidLen,15851585- pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,15861586- 1, &SupRateIe,15871587- 1, &pAd->StaActive.SupRateLen,15881588- pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,15891589- END_OF_ARGS);15901590- MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);15911591- MlmeFreeMemory(pAd, pOutBuffer);15921592- }15931593-15941594-}15951595-15961596-BOOLEAN ScanRunning(15971597- IN PRTMP_ADAPTER pAd)15981598-{15991599- return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE;16001600-}16011601-11+#include "../../rt2870/sta/sync.c"
+1-2083
drivers/staging/rt3070/sta/wpa.c
···11-/*22- *************************************************************************33- * Ralink Tech Inc.44- * 5F., No.36, Taiyuan St., Jhubei City,55- * Hsinchu County 302,66- * Taiwan, R.O.C.77- *88- * (c) Copyright 2002-2007, Ralink Technology, Inc.99- *1010- * This program is free software; you can redistribute it and/or modify *1111- * it under the terms of the GNU General Public License as published by *1212- * the Free Software Foundation; either version 2 of the License, or *1313- * (at your option) any later version. *1414- * *1515- * This program is distributed in the hope that it will be useful, *1616- * but WITHOUT ANY WARRANTY; without even the implied warranty of *1717- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *1818- * GNU General Public License for more details. *1919- * *2020- * You should have received a copy of the GNU General Public License *2121- * along with this program; if not, write to the *2222- * Free Software Foundation, Inc., *2323- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *2424- * *2525- *************************************************************************2626-2727- Module Name:2828- wpa.c2929-3030- Abstract:3131-3232- Revision History:3333- Who When What3434- -------- ---------- ----------------------------------------------3535- Jan Lee 03-07-22 Initial3636- Paul Lin 03-11-28 Modify for supplicant3737-*/3838-#include "../rt_config.h"3939-4040-#define WPARSNIE 0xdd4141-#define WPA2RSNIE 0x304242-4343-//extern UCHAR BIT8[];4444-UCHAR CipherWpaPskTkip[] = {4545- 0xDD, 0x16, // RSN IE4646- 0x00, 0x50, 0xf2, 0x01, // oui4747- 0x01, 0x00, // Version4848- 0x00, 0x50, 0xf2, 0x02, // Multicast4949- 0x01, 0x00, // Number of unicast5050- 0x00, 0x50, 0xf2, 0x02, // unicast5151- 0x01, 0x00, // number of authentication method5252- 0x00, 0x50, 0xf2, 0x02 // authentication5353- };5454-UCHAR CipherWpaPskTkipLen = (sizeof(CipherWpaPskTkip) / sizeof(UCHAR));5555-5656-UCHAR CipherWpaPskAes[] = {5757- 0xDD, 0x16, // RSN IE5858- 0x00, 0x50, 0xf2, 0x01, // oui5959- 0x01, 0x00, // Version6060- 0x00, 0x50, 0xf2, 0x04, // Multicast6161- 0x01, 0x00, // Number of unicast6262- 0x00, 0x50, 0xf2, 0x04, // unicast6363- 0x01, 0x00, // number of authentication method6464- 0x00, 0x50, 0xf2, 0x02 // authentication6565- };6666-UCHAR CipherWpaPskAesLen = (sizeof(CipherWpaPskAes) / sizeof(UCHAR));6767-6868-UCHAR CipherSuiteCiscoCCKM[] = {6969- 0xDD, 0x16, // RSN IE7070- 0x00, 0x50, 0xf2, 0x01, // oui7171- 0x01, 0x00, // Version7272- 0x00, 0x40, 0x96, 0x01, // Multicast7373- 0x01, 0x00, // Number of uicast7474- 0x00, 0x40, 0x96, 0x01, // unicast7575- 0x01, 0x00, // number of authentication method7676- 0x00, 0x40, 0x96, 0x00 // Authentication7777- };7878-UCHAR CipherSuiteCiscoCCKMLen = (sizeof(CipherSuiteCiscoCCKM) / sizeof(UCHAR));7979-8080-UCHAR CipherSuiteCiscoCCKM24[] = {8181- 0xDD, 0x18, // RSN IE8282- 0x00, 0x50, 0xf2, 0x01, // oui8383- 0x01, 0x00, // Version8484- 0x00, 0x40, 0x96, 0x01, // Multicast8585- 0x01, 0x00, // Number of uicast8686- 0x00, 0x40, 0x96, 0x01, // unicast8787- 0x01, 0x00, // number of authentication method8888- 0x00, 0x40, 0x96, 0x00,8989- 0x28, 0x00// Authentication9090- };9191-9292-UCHAR CipherSuiteCiscoCCKM24Len = (sizeof(CipherSuiteCiscoCCKM24) / sizeof(UCHAR));9393-9494-UCHAR CipherSuiteCCXTkip[] = {9595- 0xDD, 0x16, // RSN IE9696- 0x00, 0x50, 0xf2, 0x01, // oui9797- 0x01, 0x00, // Version9898- 0x00, 0x50, 0xf2, 0x02, // Multicast9999- 0x01, 0x00, // Number of unicast100100- 0x00, 0x50, 0xf2, 0x02, // unicast101101- 0x01, 0x00, // number of authentication method102102- 0x00, 0x50, 0xf2, 0x01 // authentication103103- };104104-UCHAR CipherSuiteCCXTkipLen = (sizeof(CipherSuiteCCXTkip) / sizeof(UCHAR));105105-106106-UCHAR CCX_LLC_HDR[] = {0xAA, 0xAA, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02};107107-UCHAR LLC_NORMAL[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};108108-109109-UCHAR EAPOL_FRAME[] = {0x88, 0x8E};110110-111111-BOOLEAN CheckRSNIE(112112- IN PRTMP_ADAPTER pAd,113113- IN PUCHAR pData,114114- IN UCHAR DataLen,115115- OUT UCHAR *Offset);116116-117117-void inc_byte_array(UCHAR *counter, int len);118118-119119-/*120120- ========================================================================121121-122122- Routine Description:123123- Classify WPA EAP message type124124-125125- Arguments:126126- EAPType Value of EAP message type127127- MsgType Internal Message definition for MLME state machine128128-129129- Return Value:130130- TRUE Found appropriate message type131131- FALSE No appropriate message type132132-133133- IRQL = DISPATCH_LEVEL134134-135135- Note:136136- All these constants are defined in wpa.h137137- For supplicant, there is only EAPOL Key message avaliable138138-139139- ========================================================================140140-*/141141-BOOLEAN WpaMsgTypeSubst(142142- IN UCHAR EAPType,143143- OUT INT *MsgType)144144-{145145- switch (EAPType)146146- {147147- case EAPPacket:148148- *MsgType = MT2_EAPPacket;149149- break;150150- case EAPOLStart:151151- *MsgType = MT2_EAPOLStart;152152- break;153153- case EAPOLLogoff:154154- *MsgType = MT2_EAPOLLogoff;155155- break;156156- case EAPOLKey:157157- *MsgType = MT2_EAPOLKey;158158- break;159159- case EAPOLASFAlert:160160- *MsgType = MT2_EAPOLASFAlert;161161- break;162162- default:163163- return FALSE;164164- }165165- return TRUE;166166-}167167-168168-/*169169- ==========================================================================170170- Description:171171- association state machine init, including state transition and timer init172172- Parameters:173173- S - pointer to the association state machine174174- ==========================================================================175175- */176176-VOID WpaPskStateMachineInit(177177- IN PRTMP_ADAPTER pAd,178178- IN STATE_MACHINE *S,179179- OUT STATE_MACHINE_FUNC Trans[])180180-{181181- StateMachineInit(S, Trans, MAX_WPA_PSK_STATE, MAX_WPA_PSK_MSG, (STATE_MACHINE_FUNC)Drop, WPA_PSK_IDLE, WPA_MACHINE_BASE);182182- StateMachineSetAction(S, WPA_PSK_IDLE, MT2_EAPOLKey, (STATE_MACHINE_FUNC)WpaEAPOLKeyAction);183183-}184184-185185-/*186186- ==========================================================================187187- Description:188188- This is state machine function.189189- When receiving EAPOL packets which is for 802.1x key management.190190- Use both in WPA, and WPAPSK case.191191- In this function, further dispatch to different functions according to the received packet. 3 categories are :192192- 1. normal 4-way pairwisekey and 2-way groupkey handshake193193- 2. MIC error (Countermeasures attack) report packet from STA.194194- 3. Request for pairwise/group key update from STA195195- Return:196196- ==========================================================================197197-*/198198-VOID WpaEAPOLKeyAction(199199- IN PRTMP_ADAPTER pAd,200200- IN MLME_QUEUE_ELEM *Elem)201201-202202-{203203- INT MsgType = EAPOL_MSG_INVALID;204204- PKEY_DESCRIPTER pKeyDesc;205205- PHEADER_802_11 pHeader; //red206206- UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY];207207- UCHAR EapolVr;208208- KEY_INFO peerKeyInfo;209209-210210- DBGPRINT(RT_DEBUG_TRACE, ("-----> WpaEAPOLKeyAction\n"));211211-212212- // Get 802.11 header first213213- pHeader = (PHEADER_802_11) Elem->Msg;214214-215215- // Get EAPoL-Key Descriptor216216- pKeyDesc = (PKEY_DESCRIPTER) &Elem->Msg[(LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H)];217217-218218- NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));219219- NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pKeyDesc->KeyInfo, sizeof(KEY_INFO));220220-221221- *((USHORT *)&peerKeyInfo) = cpu2le16(*((USHORT *)&peerKeyInfo));222222-223223-224224- // 1. Check EAPOL frame version and type225225- EapolVr = (UCHAR) Elem->Msg[LENGTH_802_11+LENGTH_802_1_H];226226-227227- if (((EapolVr != EAPOL_VER) && (EapolVr != EAPOL_VER2)) || ((pKeyDesc->Type != WPA1_KEY_DESC) && (pKeyDesc->Type != WPA2_KEY_DESC)))228228- {229229- DBGPRINT(RT_DEBUG_ERROR, ("Key descripter does not match with WPA rule\n"));230230- return;231231- }232232-233233- // First validate replay counter, only accept message with larger replay counter234234- // Let equal pass, some AP start with all zero replay counter235235- NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);236236-237237- if((RTMPCompareMemory(pKeyDesc->ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1) &&238238- (RTMPCompareMemory(pKeyDesc->ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0))239239- {240240- DBGPRINT(RT_DEBUG_ERROR, (" ReplayCounter not match \n"));241241- return;242242- }243243-244244- // Process WPA2PSK frame245245- if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)246246- {247247- if((peerKeyInfo.KeyType == PAIRWISEKEY) &&248248- (peerKeyInfo.EKD_DL == 0) &&249249- (peerKeyInfo.KeyAck == 1) &&250250- (peerKeyInfo.KeyMic == 0) &&251251- (peerKeyInfo.Secure == 0) &&252252- (peerKeyInfo.Error == 0) &&253253- (peerKeyInfo.Request == 0))254254- {255255- MsgType = EAPOL_PAIR_MSG_1;256256- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));257257- } else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&258258- (peerKeyInfo.EKD_DL == 1) &&259259- (peerKeyInfo.KeyAck == 1) &&260260- (peerKeyInfo.KeyMic == 1) &&261261- (peerKeyInfo.Secure == 1) &&262262- (peerKeyInfo.Error == 0) &&263263- (peerKeyInfo.Request == 0))264264- {265265- MsgType = EAPOL_PAIR_MSG_3;266266- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));267267- } else if((peerKeyInfo.KeyType == GROUPKEY) &&268268- (peerKeyInfo.EKD_DL == 1) &&269269- (peerKeyInfo.KeyAck == 1) &&270270- (peerKeyInfo.KeyMic == 1) &&271271- (peerKeyInfo.Secure == 1) &&272272- (peerKeyInfo.Error == 0) &&273273- (peerKeyInfo.Request == 0))274274- {275275- MsgType = EAPOL_GROUP_MSG_1;276276- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));277277- }278278-279279- // We will assume link is up (assoc suceess and port not secured).280280- // All state has to be able to process message from previous state281281- switch(pAd->StaCfg.WpaState)282282- {283283- case SS_START:284284- if(MsgType == EAPOL_PAIR_MSG_1)285285- {286286- Wpa2PairMsg1Action(pAd, Elem);287287- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;288288- }289289- break;290290-291291- case SS_WAIT_MSG_3:292292- if(MsgType == EAPOL_PAIR_MSG_1)293293- {294294- Wpa2PairMsg1Action(pAd, Elem);295295- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;296296- }297297- else if(MsgType == EAPOL_PAIR_MSG_3)298298- {299299- Wpa2PairMsg3Action(pAd, Elem);300300- pAd->StaCfg.WpaState = SS_WAIT_GROUP;301301- }302302- break;303303-304304- case SS_WAIT_GROUP: // When doing group key exchange305305- case SS_FINISH: // This happened when update group key306306- if(MsgType == EAPOL_PAIR_MSG_1)307307- {308308- // Reset port secured variable309309- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;310310- Wpa2PairMsg1Action(pAd, Elem);311311- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;312312- }313313- else if(MsgType == EAPOL_PAIR_MSG_3)314314- {315315- // Reset port secured variable316316- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;317317- Wpa2PairMsg3Action(pAd, Elem);318318- pAd->StaCfg.WpaState = SS_WAIT_GROUP;319319- }320320- else if(MsgType == EAPOL_GROUP_MSG_1)321321- {322322- WpaGroupMsg1Action(pAd, Elem);323323- pAd->StaCfg.WpaState = SS_FINISH;324324- }325325- break;326326-327327- default:328328- break;329329- }330330- }331331- // Process WPAPSK Frame332332- // Classify message Type, either pairwise message 1, 3, or group message 1 for supplicant333333- else if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)334334- {335335- if((peerKeyInfo.KeyType == PAIRWISEKEY) &&336336- (peerKeyInfo.KeyIndex == 0) &&337337- (peerKeyInfo.KeyAck == 1) &&338338- (peerKeyInfo.KeyMic == 0) &&339339- (peerKeyInfo.Secure == 0) &&340340- (peerKeyInfo.Error == 0) &&341341- (peerKeyInfo.Request == 0))342342- {343343- MsgType = EAPOL_PAIR_MSG_1;344344- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 1\n"));345345- }346346- else if((peerKeyInfo.KeyType == PAIRWISEKEY) &&347347- (peerKeyInfo.KeyIndex == 0) &&348348- (peerKeyInfo.KeyAck == 1) &&349349- (peerKeyInfo.KeyMic == 1) &&350350- (peerKeyInfo.Secure == 0) &&351351- (peerKeyInfo.Error == 0) &&352352- (peerKeyInfo.Request == 0))353353- {354354- MsgType = EAPOL_PAIR_MSG_3;355355- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Pairwise Message 3\n"));356356- }357357- else if((peerKeyInfo.KeyType == GROUPKEY) &&358358- (peerKeyInfo.KeyIndex != 0) &&359359- (peerKeyInfo.KeyAck == 1) &&360360- (peerKeyInfo.KeyMic == 1) &&361361- (peerKeyInfo.Secure == 1) &&362362- (peerKeyInfo.Error == 0) &&363363- (peerKeyInfo.Request == 0))364364- {365365- MsgType = EAPOL_GROUP_MSG_1;366366- DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL Key Group Message 1\n"));367367- }368368-369369- // We will assume link is up (assoc suceess and port not secured).370370- // All state has to be able to process message from previous state371371- switch(pAd->StaCfg.WpaState)372372- {373373- case SS_START:374374- if(MsgType == EAPOL_PAIR_MSG_1)375375- {376376- WpaPairMsg1Action(pAd, Elem);377377- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;378378- }379379- break;380380-381381- case SS_WAIT_MSG_3:382382- if(MsgType == EAPOL_PAIR_MSG_1)383383- {384384- WpaPairMsg1Action(pAd, Elem);385385- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;386386- }387387- else if(MsgType == EAPOL_PAIR_MSG_3)388388- {389389- WpaPairMsg3Action(pAd, Elem);390390- pAd->StaCfg.WpaState = SS_WAIT_GROUP;391391- }392392- break;393393-394394- case SS_WAIT_GROUP: // When doing group key exchange395395- case SS_FINISH: // This happened when update group key396396- if(MsgType == EAPOL_PAIR_MSG_1)397397- {398398- WpaPairMsg1Action(pAd, Elem);399399- pAd->StaCfg.WpaState = SS_WAIT_MSG_3;400400- // Reset port secured variable401401- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;402402- }403403- else if(MsgType == EAPOL_PAIR_MSG_3)404404- {405405- WpaPairMsg3Action(pAd, Elem);406406- pAd->StaCfg.WpaState = SS_WAIT_GROUP;407407- // Reset port secured variable408408- pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;409409- }410410- else if(MsgType == EAPOL_GROUP_MSG_1)411411- {412412- WpaGroupMsg1Action(pAd, Elem);413413- pAd->StaCfg.WpaState = SS_FINISH;414414- }415415- break;416416-417417- default:418418- break;419419- }420420- }421421-422422- DBGPRINT(RT_DEBUG_TRACE, ("<----- WpaEAPOLKeyAction\n"));423423-}424424-425425-/*426426- ========================================================================427427-428428- Routine Description:429429- Process Pairwise key 4-way handshaking430430-431431- Arguments:432432- pAd Pointer to our adapter433433- Elem Message body434434-435435- Return Value:436436- None437437-438438- Note:439439-440440- ========================================================================441441-*/442442-VOID WpaPairMsg1Action(443443- IN PRTMP_ADAPTER pAd,444444- IN MLME_QUEUE_ELEM *Elem)445445-{446446- PHEADER_802_11 pHeader;447447- UCHAR *mpool, *PTK, *digest;448448- PUCHAR pOutBuffer = NULL;449449- UCHAR Header802_3[14];450450- ULONG FrameLen = 0;451451- PEAPOL_PACKET pMsg1;452452- EAPOL_PACKET Packet;453453- UCHAR Mic[16];454454-455455- DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action ----->\n"));456456-457457- // allocate memory pool458458- os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);459459-460460- if (mpool == NULL)461461- return;462462-463463- // PTK Len = 80.464464- PTK = (UCHAR *) ROUND_UP(mpool, 4);465465- // digest Len = 80.466466- digest = (UCHAR *) ROUND_UP(PTK + 80, 4);467467-468468- pHeader = (PHEADER_802_11) Elem->Msg;469469-470470- // Process message 1 from authenticator471471- pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];472472-473473- // 1. Save Replay counter, it will use to verify message 3 and construct message 2474474- NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);475475-476476- // 2. Save ANonce477477- NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);478478-479479- // Generate random SNonce480480- GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);481481-482482- // Calc PTK(ANonce, SNonce)483483- WpaCountPTK(pAd,484484- pAd->StaCfg.PMK,485485- pAd->StaCfg.ANonce,486486- pAd->CommonCfg.Bssid,487487- pAd->StaCfg.SNonce,488488- pAd->CurrentAddress,489489- PTK,490490- LEN_PTK);491491-492492- // Save key to PTK entry493493- NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);494494-495495- // init 802.3 header and Fill Packet496496- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);497497-498498- // Zero Message 2 body499499- NdisZeroMemory(&Packet, sizeof(Packet));500500- Packet.ProVer = EAPOL_VER;501501- Packet.ProType = EAPOLKey;502502- //503503- // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)504504- //505505- Packet.KeyDesc.Type = WPA1_KEY_DESC;506506- // 1. Key descriptor version and appropriate RSN IE507507- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)508508- {509509- Packet.KeyDesc.KeyInfo.KeyDescVer = 2;510510- }511511- else // TKIP512512- {513513- Packet.KeyDesc.KeyInfo.KeyDescVer = 1;514514- }515515-516516- // fill in Data Material and its length517517- Packet.KeyDesc.KeyData[0] = IE_WPA;518518- Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;519519- Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;520520- NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);521521-522522- // Update packet length after decide Key data payload523523- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];524524-525525- // Update Key length526526- Packet.KeyDesc.KeyLength[0] = pMsg1->KeyDesc.KeyLength[0];527527- Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];528528- // 2. Key Type PeerKey529529- Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;530530-531531- // 3. KeyMic field presented532532- Packet.KeyDesc.KeyInfo.KeyMic = 1;533533-534534- //Convert to little-endian format.535535- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));536536-537537-538538- // 4. Fill SNonce539539- NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);540540-541541- // 5. Key Replay Count542542- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);543543-544544- // Send EAPOL(0, 1, 0, 0, 0, P, 0, SNonce, MIC, RSN_IE)545545- // Out buffer for transmitting message 2546546- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory547547- if(pOutBuffer == NULL)548548- {549549- os_free_mem(pAd, mpool);550550- return;551551- }552552- // Prepare EAPOL frame for MIC calculation553553- // Be careful, only EAPOL frame is counted for MIC calculation554554- MakeOutgoingFrame(pOutBuffer, &FrameLen,555555- Packet.Body_Len[1] + 4, &Packet,556556- END_OF_ARGS);557557-558558- // 6. Prepare and Fill MIC value559559- NdisZeroMemory(Mic, sizeof(Mic));560560- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)561561- { // AES562562-563563- HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);564564- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);565565- }566566- else567567- { // TKIP568568- hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);569569- }570570- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);571571-572572- //hex_dump("MIC", Mic, LEN_KEY_DESC_MIC);573573-574574- MakeOutgoingFrame(pOutBuffer, &FrameLen,575575- LENGTH_802_3, &Header802_3,576576- Packet.Body_Len[1] + 4, &Packet,577577- END_OF_ARGS);578578-579579-580580- // 5. Copy frame to Tx ring and send Msg 2 to authenticator581581- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);582582-583583- MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);584584- os_free_mem(pAd, (PUCHAR)mpool);585585-586586- DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg1Action <-----\n"));587587-}588588-589589-VOID Wpa2PairMsg1Action(590590- IN PRTMP_ADAPTER pAd,591591- IN MLME_QUEUE_ELEM *Elem)592592-{593593- PHEADER_802_11 pHeader;594594- UCHAR *mpool, *PTK, *digest;595595- PUCHAR pOutBuffer = NULL;596596- UCHAR Header802_3[14];597597- ULONG FrameLen = 0;598598- PEAPOL_PACKET pMsg1;599599- EAPOL_PACKET Packet;600600- UCHAR Mic[16];601601-602602- DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action ----->\n"));603603-604604- // allocate memory pool605605- os_alloc_mem(pAd, (PUCHAR *)&mpool, 256);606606-607607- if (mpool == NULL)608608- return;609609-610610- // PTK Len = 80.611611- PTK = (UCHAR *) ROUND_UP(mpool, 4);612612- // digest Len = 80.613613- digest = (UCHAR *) ROUND_UP(PTK + 80, 4);614614-615615- pHeader = (PHEADER_802_11) Elem->Msg;616616-617617- // Process message 1 from authenticator618618- pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];619619-620620- // 1. Save Replay counter, it will use to verify message 3 and construct message 2621621- NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);622622-623623- // 2. Save ANonce624624- NdisMoveMemory(pAd->StaCfg.ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);625625-626626- // Generate random SNonce627627- GenRandom(pAd, pAd->CurrentAddress, pAd->StaCfg.SNonce);628628-629629- if(pMsg1->KeyDesc.KeyDataLen[1] > 0 )630630- {631631- // cached PMKID632632- }633633-634634- // Calc PTK(ANonce, SNonce)635635- WpaCountPTK(pAd,636636- pAd->StaCfg.PMK,637637- pAd->StaCfg.ANonce,638638- pAd->CommonCfg.Bssid,639639- pAd->StaCfg.SNonce,640640- pAd->CurrentAddress,641641- PTK,642642- LEN_PTK);643643-644644- // Save key to PTK entry645645- NdisMoveMemory(pAd->StaCfg.PTK, PTK, LEN_PTK);646646-647647- // init 802.3 header and Fill Packet648648- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);649649-650650- // Zero message 2 body651651- NdisZeroMemory(&Packet, sizeof(Packet));652652- Packet.ProVer = EAPOL_VER;653653- Packet.ProType = EAPOLKey;654654- //655655- // Message 2 as EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)656656- //657657- Packet.KeyDesc.Type = WPA2_KEY_DESC;658658-659659- // 1. Key descriptor version and appropriate RSN IE660660- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)661661- {662662- Packet.KeyDesc.KeyInfo.KeyDescVer = 2;663663- }664664- else // TKIP665665- {666666- Packet.KeyDesc.KeyInfo.KeyDescVer = 1;667667- }668668-669669- // fill in Data Material and its length670670- Packet.KeyDesc.KeyData[0] = IE_WPA2;671671- Packet.KeyDesc.KeyData[1] = pAd->StaCfg.RSNIE_Len;672672- Packet.KeyDesc.KeyDataLen[1] = pAd->StaCfg.RSNIE_Len + 2;673673- NdisMoveMemory(&Packet.KeyDesc.KeyData[2], pAd->StaCfg.RSN_IE, pAd->StaCfg.RSNIE_Len);674674-675675- // Update packet length after decide Key data payload676676- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE + Packet.KeyDesc.KeyDataLen[1];677677-678678- // 2. Key Type PeerKey679679- Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;680680-681681- // 3. KeyMic field presented682682- Packet.KeyDesc.KeyInfo.KeyMic = 1;683683-684684- // Update Key Length685685- Packet.KeyDesc.KeyLength[0] = 0;686686- Packet.KeyDesc.KeyLength[1] = pMsg1->KeyDesc.KeyLength[1];687687-688688- // 4. Fill SNonce689689- NdisMoveMemory(Packet.KeyDesc.KeyNonce, pAd->StaCfg.SNonce, LEN_KEY_DESC_NONCE);690690-691691- // 5. Key Replay Count692692- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);693693-694694- // Convert to little-endian format.695695- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));696696-697697- // Send EAPOL-Key(0,1,0,0,0,P,0,SNonce,MIC,RSN IE)698698- // Out buffer for transmitting message 2699699- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory700700- if(pOutBuffer == NULL)701701- {702702- os_free_mem(pAd, mpool);703703- return;704704- }705705-706706- // Prepare EAPOL frame for MIC calculation707707- // Be careful, only EAPOL frame is counted for MIC calculation708708- MakeOutgoingFrame(pOutBuffer, &FrameLen,709709- Packet.Body_Len[1] + 4, &Packet,710710- END_OF_ARGS);711711-712712- // 6. Prepare and Fill MIC value713713- NdisZeroMemory(Mic, sizeof(Mic));714714- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)715715- {716716- // AES717717- HMAC_SHA1(pOutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);718718- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);719719- }720720- else721721- {722722- hmac_md5(PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);723723- }724724- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);725725-726726-727727- // Make Transmitting frame728728- MakeOutgoingFrame(pOutBuffer, &FrameLen,729729- LENGTH_802_3, &Header802_3,730730- Packet.Body_Len[1] + 4, &Packet,731731- END_OF_ARGS);732732-733733-734734- // 5. Copy frame to Tx ring735735- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);736736-737737- MlmeFreeMemory(pAd, pOutBuffer);738738- os_free_mem(pAd, mpool);739739-740740- DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg1Action <-----\n"));741741-742742-}743743-744744-/*745745- ========================================================================746746-747747- Routine Description:748748- Process Pairwise key 4-way handshaking749749-750750- Arguments:751751- pAd Pointer to our adapter752752- Elem Message body753753-754754- Return Value:755755- None756756-757757- Note:758758-759759- ========================================================================760760-*/761761-VOID WpaPairMsg3Action(762762- IN PRTMP_ADAPTER pAd,763763- IN MLME_QUEUE_ELEM *Elem)764764-765765-{766766- PHEADER_802_11 pHeader;767767- PUCHAR pOutBuffer = NULL;768768- UCHAR Header802_3[14];769769- ULONG FrameLen = 0;770770- EAPOL_PACKET Packet;771771- PEAPOL_PACKET pMsg3;772772- UCHAR Mic[16], OldMic[16];773773- MAC_TABLE_ENTRY *pEntry = NULL;774774- UCHAR skip_offset;775775- KEY_INFO peerKeyInfo;776776-777777- DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action ----->\n"));778778-779779- // Record 802.11 header & the received EAPOL packet Msg3780780- pHeader = (PHEADER_802_11) Elem->Msg;781781- pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];782782-783783- NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));784784- NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));785785-786786- *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));787787-788788-789789- // 1. Verify cipher type match790790- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))791791- {792792- return;793793- }794794- else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))795795- {796796- return;797797- }798798-799799- // Verify RSN IE800800- //if (!RTMPEqualMemory(pMsg3->KeyDesc.KeyData, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len))801801- if (!CheckRSNIE(pAd, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1], &skip_offset))802802- {803803- DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in Msg 3 of WPA1 4-way handshake!! \n"));804804- hex_dump("The original RSN_IE", pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);805805- hex_dump("The received RSN_IE", pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);806806- return;807807- }808808- else809809- DBGPRINT(RT_DEBUG_TRACE, ("RSN_IE VALID in Msg 3 of WPA1 4-way handshake!! \n"));810810-811811-812812- // 2. Check MIC value813813- // Save the MIC and replace with zero814814- NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);815815- NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);816816- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)817817- {818818- // AES819819- UCHAR digest[80];820820-821821- HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);822822- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);823823- }824824- else // TKIP825825- {826826- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);827827- }828828-829829- if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))830830- {831831- DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));832832- return;833833- }834834- else835835- DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));836836-837837- // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger838838- if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)839839- return;840840-841841- // Update new replay counter842842- NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);843843-844844- // 4. Double check ANonce845845- if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))846846- return;847847-848848- // init 802.3 header and Fill Packet849849- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);850850-851851- // Zero Message 4 body852852- NdisZeroMemory(&Packet, sizeof(Packet));853853- Packet.ProVer = EAPOL_VER;854854- Packet.ProType = EAPOLKey;855855- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field856856-857857- //858858- // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)859859- //860860- Packet.KeyDesc.Type = WPA1_KEY_DESC;861861-862862- // Key descriptor version and appropriate RSN IE863863- Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;864864-865865- // Update Key Length866866- Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];867867- Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];868868-869869- // Key Type PeerKey870870- Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;871871-872872- // KeyMic field presented873873- Packet.KeyDesc.KeyInfo.KeyMic = 1;874874-875875- // In Msg3, KeyInfo.secure =0 if Group Key HS to come. 1 if no group key HS876876- // Station sends Msg4 KeyInfo.secure should be the same as that in Msg.3877877- Packet.KeyDesc.KeyInfo.Secure= peerKeyInfo.Secure;878878-879879- // Convert to little-endian format.880880- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));881881-882882- // Key Replay count883883- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);884884-885885- // Out buffer for transmitting message 4886886- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory887887- if(pOutBuffer == NULL)888888- return;889889-890890- // Prepare EAPOL frame for MIC calculation891891- // Be careful, only EAPOL frame is counted for MIC calculation892892- MakeOutgoingFrame(pOutBuffer, &FrameLen,893893- Packet.Body_Len[1] + 4, &Packet,894894- END_OF_ARGS);895895-896896- // Prepare and Fill MIC value897897- NdisZeroMemory(Mic, sizeof(Mic));898898- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)899899- {900900- // AES901901- UCHAR digest[80];902902-903903- HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);904904- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);905905- }906906- else907907- {908908- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);909909- }910910- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);911911-912912- // Update PTK913913- // Prepare pair-wise key information into shared key table914914- NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));915915- pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;916916- NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);917917- NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);918918- NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);919919-920920- // Decide its ChiperAlg921921- if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)922922- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;923923- else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)924924- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;925925- else926926- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;927927-928928- // Update these related information to MAC_TABLE_ENTRY929929- pEntry = &pAd->MacTab.Content[BSSID_WCID];930930- NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);931931- NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);932932- NdisMoveMemory(pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);933933- pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;934934-935935- // Update pairwise key information to ASIC Shared Key Table936936- AsicAddSharedKeyEntry(pAd,937937- BSS0,938938- 0,939939- pAd->SharedKey[BSS0][0].CipherAlg,940940- pAd->SharedKey[BSS0][0].Key,941941- pAd->SharedKey[BSS0][0].TxMic,942942- pAd->SharedKey[BSS0][0].RxMic);943943-944944- // Update ASIC WCID attribute table and IVEIV table945945- RTMPAddWcidAttributeEntry(pAd,946946- BSS0,947947- 0,948948- pAd->SharedKey[BSS0][0].CipherAlg,949949- pEntry);950950-951951- // Make transmitting frame952952- MakeOutgoingFrame(pOutBuffer, &FrameLen,953953- LENGTH_802_3, &Header802_3,954954- Packet.Body_Len[1] + 4, &Packet,955955- END_OF_ARGS);956956-957957-958958- // Copy frame to Tx ring and Send Message 4 to authenticator959959- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);960960-961961- MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);962962-963963- DBGPRINT(RT_DEBUG_TRACE, ("WpaPairMsg3Action <-----\n"));964964-}965965-966966-VOID Wpa2PairMsg3Action(967967- IN PRTMP_ADAPTER pAd,968968- IN MLME_QUEUE_ELEM *Elem)969969-970970-{971971- PHEADER_802_11 pHeader;972972- PUCHAR pOutBuffer = NULL;973973- UCHAR Header802_3[14];974974- ULONG FrameLen = 0;975975- EAPOL_PACKET Packet;976976- PEAPOL_PACKET pMsg3;977977- UCHAR Mic[16], OldMic[16];978978- UCHAR *mpool, *KEYDATA, *digest;979979- UCHAR Key[32];980980- MAC_TABLE_ENTRY *pEntry = NULL;981981- KEY_INFO peerKeyInfo;982982-983983- // allocate memory984984- os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);985985-986986- if(mpool == NULL)987987- return;988988-989989- // KEYDATA Len = 512.990990- KEYDATA = (UCHAR *) ROUND_UP(mpool, 4);991991- // digest Len = 80.992992- digest = (UCHAR *) ROUND_UP(KEYDATA + 512, 4);993993-994994- DBGPRINT(RT_DEBUG_TRACE, ("Wpa2PairMsg3Action ----->\n"));995995-996996- pHeader = (PHEADER_802_11) Elem->Msg;997997-998998- // Process message 3 frame.999999- pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];10001000-10011001- NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));10021002- NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pMsg3->KeyDesc.KeyInfo, sizeof(KEY_INFO));10031003-10041004- *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));10051005-10061006- // 1. Verify cipher type match10071007- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer!= 2))10081008- {10091009- os_free_mem(pAd, (PUCHAR)mpool);10101010- return;10111011- }10121012- else if(pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))10131013- {10141014- os_free_mem(pAd, (PUCHAR)mpool);10151015- return;10161016- }10171017-10181018- // 2. Check MIC value10191019- // Save the MIC and replace with zero10201020- NdisMoveMemory(OldMic, pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);10211021- NdisZeroMemory(pMsg3->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);10221022- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)10231023- {10241024- // AES10251025- HMAC_SHA1((PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);10261026- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);10271027- }10281028- else10291029- {10301030- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pMsg3, pMsg3->Body_Len[1] + 4, Mic);10311031- }10321032-10331033- if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))10341034- {10351035- DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in msg 3 of 4-way handshake!!!!!!!!!! \n"));10361036- os_free_mem(pAd, (PUCHAR)mpool);10371037- return;10381038- }10391039- else10401040- DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in msg 3 of 4-way handshake!!!!!!!!!! \n"));10411041-10421042- // 3. Check Replay Counter, it has to be larger than last one. No need to be exact one larger10431043- if(RTMPCompareMemory(pMsg3->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)10441044- {10451045- os_free_mem(pAd, (PUCHAR)mpool);10461046- return;10471047- }10481048-10491049- // Update new replay counter10501050- NdisMoveMemory(pAd->StaCfg.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);10511051-10521052- // 4. Double check ANonce10531053- if(!NdisEqualMemory(pAd->StaCfg.ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))10541054- {10551055- os_free_mem(pAd, (PUCHAR)mpool);10561056- return;10571057- }10581058-10591059- // Obtain GTK10601060- // 5. Decrypt GTK from Key Data10611061- DBGPRINT_RAW(RT_DEBUG_TRACE, ("EKD = %d\n", peerKeyInfo.EKD_DL));10621062- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)10631063- {10641064- // Decrypt AES GTK10651065- AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pMsg3->KeyDesc.KeyDataLen[1],pMsg3->KeyDesc.KeyData);10661066- }10671067- else // TKIP10681068- {10691069- INT i;10701070- // Decrypt TKIP GTK10711071- // Construct 32 bytes RC4 Key10721072- NdisMoveMemory(Key, pMsg3->KeyDesc.KeyIv, 16);10731073- NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);10741074- ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);10751075- //discard first 256 bytes10761076- for(i = 0; i < 256; i++)10771077- ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);10781078- // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not10791079- ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg3->KeyDesc.KeyData, pMsg3->KeyDesc.KeyDataLen[1]);10801080- }10811081-10821082- if (!ParseKeyData(pAd, KEYDATA, pMsg3->KeyDesc.KeyDataLen[1], 1))10831083- {10841084- os_free_mem(pAd, (PUCHAR)mpool);10851085- return;10861086- }10871087-10881088- // Update GTK to ASIC10891089- // Update group key information to ASIC Shared Key Table10901090- AsicAddSharedKeyEntry(pAd,10911091- BSS0,10921092- pAd->StaCfg.DefaultKeyId,10931093- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,10941094- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,10951095- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,10961096- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);10971097-10981098- // Update ASIC WCID attribute table and IVEIV table10991099- RTMPAddWcidAttributeEntry(pAd,11001100- BSS0,11011101- pAd->StaCfg.DefaultKeyId,11021102- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,11031103- NULL);11041104-11051105- // init 802.3 header and Fill Packet11061106- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);11071107-11081108- // Zero message 4 body11091109- NdisZeroMemory(&Packet, sizeof(Packet));11101110- Packet.ProVer = EAPOL_VER;11111111- Packet.ProType = EAPOLKey;11121112- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field11131113-11141114- //11151115- // Message 4 as EAPOL-Key(0,1,0,0,0,P,0,0,MIC,0)11161116- //11171117- Packet.KeyDesc.Type = WPA2_KEY_DESC;11181118-11191119- // Key descriptor version and appropriate RSN IE11201120- Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;11211121-11221122- // Update Key Length11231123- Packet.KeyDesc.KeyLength[0] = pMsg3->KeyDesc.KeyLength[0];11241124- Packet.KeyDesc.KeyLength[1] = pMsg3->KeyDesc.KeyLength[1];11251125-11261126- // Key Type PeerKey11271127- Packet.KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;11281128-11291129- // KeyMic field presented11301130- Packet.KeyDesc.KeyInfo.KeyMic = 1;11311131- Packet.KeyDesc.KeyInfo.Secure = 1;11321132-11331133- // Convert to little-endian format.11341134- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));11351135-11361136- // Key Replay count11371137- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);11381138-11391139- // Out buffer for transmitting message 411401140- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory11411141- if(pOutBuffer == NULL)11421142- {11431143- os_free_mem(pAd, (PUCHAR)mpool);11441144- return;11451145- }11461146-11471147- // Prepare EAPOL frame for MIC calculation11481148- // Be careful, only EAPOL frame is counted for MIC calculation11491149- MakeOutgoingFrame(pOutBuffer, &FrameLen,11501150- Packet.Body_Len[1] + 4, &Packet,11511151- END_OF_ARGS);11521152-11531153- // Prepare and Fill MIC value11541154- NdisZeroMemory(Mic, sizeof(Mic));11551155- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)11561156- {11571157- // AES11581158- HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);11591159- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);11601160- }11611161- else11621162- {11631163- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);11641164- }11651165- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);11661166-11671167- // Update PTK11681168- // Prepare pair-wise key information into shared key table11691169- NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));11701170- pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;11711171- NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);11721172- NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);11731173- NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);11741174-11751175- // Decide its ChiperAlg11761176- if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)11771177- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;11781178- else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)11791179- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;11801180- else11811181- pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;11821182-11831183- // Update these related information to MAC_TABLE_ENTRY11841184- pEntry = &pAd->MacTab.Content[BSSID_WCID];11851185- NdisMoveMemory(&pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);11861186- NdisMoveMemory(&pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);11871187- NdisMoveMemory(&pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);11881188- pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;11891189-11901190- // Update pairwise key information to ASIC Shared Key Table11911191- AsicAddSharedKeyEntry(pAd,11921192- BSS0,11931193- 0,11941194- pAd->SharedKey[BSS0][0].CipherAlg,11951195- pAd->SharedKey[BSS0][0].Key,11961196- pAd->SharedKey[BSS0][0].TxMic,11971197- pAd->SharedKey[BSS0][0].RxMic);11981198-11991199- // Update ASIC WCID attribute table and IVEIV table12001200- RTMPAddWcidAttributeEntry(pAd,12011201- BSS0,12021202- 0,12031203- pAd->SharedKey[BSS0][0].CipherAlg,12041204- pEntry);12051205-12061206- // Make Transmitting frame12071207- MakeOutgoingFrame(pOutBuffer, &FrameLen,12081208- LENGTH_802_3, &Header802_3,12091209- Packet.Body_Len[1] + 4, &Packet,12101210- END_OF_ARGS);12111211-12121212-12131213- // Copy frame to Tx ring and Send Message 4 to authenticator12141214- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, TRUE);12151215-12161216- // set 802.1x port control12171217- STA_PORT_SECURED(pAd);12181218-12191219- // Indicate Connected for GUI12201220- pAd->IndicateMediaState = NdisMediaStateConnected;12211221-12221222- MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);12231223- os_free_mem(pAd, (PUCHAR)mpool);12241224-12251225-12261226- // send wireless event - for set key done WPA212271227- if (pAd->CommonCfg.bWirelessEvent)12281228- RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pEntry->Addr, BSS0, 0);12291229-12301230- DBGPRINT(RT_DEBUG_ERROR, ("Wpa2PairMsg3Action <-----\n"));12311231-12321232-}12331233-12341234-/*12351235- ========================================================================12361236-12371237- Routine Description:12381238- Process Group key 2-way handshaking12391239-12401240- Arguments:12411241- pAd Pointer to our adapter12421242- Elem Message body12431243-12441244- Return Value:12451245- None12461246-12471247- Note:12481248-12491249- ========================================================================12501250-*/12511251-VOID WpaGroupMsg1Action(12521252- IN PRTMP_ADAPTER pAd,12531253- IN MLME_QUEUE_ELEM *Elem)12541254-12551255-{12561256- PUCHAR pOutBuffer = NULL;12571257- UCHAR Header802_3[14];12581258- ULONG FrameLen = 0;12591259- EAPOL_PACKET Packet;12601260- PEAPOL_PACKET pGroup;12611261- UCHAR *mpool, *digest, *KEYDATA;12621262- UCHAR Mic[16], OldMic[16];12631263- UCHAR GTK[32], Key[32];12641264- KEY_INFO peerKeyInfo;12651265-12661266- // allocate memory12671267- os_alloc_mem(pAd, (PUCHAR *)&mpool, 1024);12681268-12691269- if(mpool == NULL)12701270- return;12711271-12721272- // digest Len = 80.12731273- digest = (UCHAR *) ROUND_UP(mpool, 4);12741274- // KEYDATA Len = 512.12751275- KEYDATA = (UCHAR *) ROUND_UP(digest + 80, 4);12761276-12771277- DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action ----->\n"));12781278-12791279- // Process Group Message 1 frame. skip 802.11 header(24) & LLC_SNAP header(8)12801280- pGroup = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];12811281-12821282- NdisZeroMemory((PUCHAR)&peerKeyInfo, sizeof(peerKeyInfo));12831283- NdisMoveMemory((PUCHAR)&peerKeyInfo, (PUCHAR)&pGroup->KeyDesc.KeyInfo, sizeof(KEY_INFO));12841284-12851285- *((USHORT*)&peerKeyInfo) = cpu2le16(*((USHORT*)&peerKeyInfo));12861286-12871287- // 0. Check cipher type match12881288- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled && (peerKeyInfo.KeyDescVer != 2))12891289- {12901290- os_free_mem(pAd, (PUCHAR)mpool);12911291- return;12921292- }12931293- else if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled && (peerKeyInfo.KeyDescVer != 1))12941294- {12951295- os_free_mem(pAd, (PUCHAR)mpool);12961296- return;12971297- }12981298-12991299- // 1. Verify Replay counter13001300- // Check Replay Counter, it has to be larger than last one. No need to be exact one larger13011301- if(RTMPCompareMemory(pGroup->KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY) != 1)13021302- {13031303- os_free_mem(pAd, (PUCHAR)mpool);13041304- return;13051305- }13061306-13071307- // Update new replay counter13081308- NdisMoveMemory(pAd->StaCfg.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);13091309-13101310- // 2. Verify MIC is valid13111311- // Save the MIC and replace with zero13121312- NdisMoveMemory(OldMic, pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);13131313- NdisZeroMemory(pGroup->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);13141314-13151315- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)13161316- { // AES13171317- HMAC_SHA1((PUCHAR) pGroup, pGroup->Body_Len[1] + 4, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);13181318- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);13191319- }13201320- else13211321- { // TKIP13221322- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, (PUCHAR) pGroup, pGroup->Body_Len[1] + 4, Mic);13231323- }13241324-13251325- if(!NdisEqualMemory(OldMic, Mic, LEN_KEY_DESC_MIC))13261326- {13271327- DBGPRINT(RT_DEBUG_ERROR, (" MIC Different in group msg 1 of 2-way handshake!!!!!!!!!! \n"));13281328- MlmeFreeMemory(pAd, (PUCHAR)mpool);13291329- return;13301330- }13311331- else13321332- DBGPRINT(RT_DEBUG_TRACE, (" MIC VALID in group msg 1 of 2-way handshake!!!!!!!!!! \n"));13331333-13341334-13351335- // 3. Decrypt GTK from Key Data13361336- if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)13371337- {13381338- // Decrypt AES GTK13391339- AES_GTK_KEY_UNWRAP(&pAd->StaCfg.PTK[16], KEYDATA, pGroup->KeyDesc.KeyDataLen[1], pGroup->KeyDesc.KeyData);13401340- }13411341- else // TKIP13421342- {13431343- INT i;13441344-13451345- // Decrypt TKIP GTK13461346- // Construct 32 bytes RC4 Key13471347- NdisMoveMemory(Key, pGroup->KeyDesc.KeyIv, 16);13481348- NdisMoveMemory(&Key[16], &pAd->StaCfg.PTK[16], 16);13491349- ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32);13501350- //discard first 256 bytes13511351- for(i = 0; i < 256; i++)13521352- ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT);13531353- // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not13541354- ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pGroup->KeyDesc.KeyData, pGroup->KeyDesc.KeyDataLen[1]);13551355- }13561356-13571357- // Process decrypted key data material13581358- // Parse keyData to handle KDE format for WPA2PSK13591359- if (peerKeyInfo.EKD_DL)13601360- {13611361- if (!ParseKeyData(pAd, KEYDATA, pGroup->KeyDesc.KeyDataLen[1], 0))13621362- {13631363- os_free_mem(pAd, (PUCHAR)mpool);13641364- return;13651365- }13661366- }13671367- else // WPAPSK13681368- {13691369- // set key material, TxMic and RxMic for WPAPSK13701370- NdisMoveMemory(GTK, KEYDATA, 32);13711371- NdisMoveMemory(pAd->StaCfg.GTK, GTK, 32);13721372- pAd->StaCfg.DefaultKeyId = peerKeyInfo.KeyIndex;13731373-13741374- // Prepare pair-wise key information into shared key table13751375- NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));13761376- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;13771377- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, GTK, LEN_TKIP_EK);13781378- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, >K[16], LEN_TKIP_RXMICK);13791379- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, >K[24], LEN_TKIP_TXMICK);13801380-13811381- // Update Shared Key CipherAlg13821382- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;13831383- if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)13841384- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;13851385- else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)13861386- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;13871387-13881388- //hex_dump("Group Key :", pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, LEN_TKIP_EK);13891389- }13901390-13911391- // Update group key information to ASIC Shared Key Table13921392- AsicAddSharedKeyEntry(pAd,13931393- BSS0,13941394- pAd->StaCfg.DefaultKeyId,13951395- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,13961396- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,13971397- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,13981398- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);13991399-14001400- // Update ASIC WCID attribute table and IVEIV table14011401- RTMPAddWcidAttributeEntry(pAd,14021402- BSS0,14031403- pAd->StaCfg.DefaultKeyId,14041404- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,14051405- NULL);14061406-14071407- // set 802.1x port control14081408- STA_PORT_SECURED(pAd);14091409-14101410- // Indicate Connected for GUI14111411- pAd->IndicateMediaState = NdisMediaStateConnected;14121412-14131413- // init header and Fill Packet14141414- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);14151415-14161416- // Zero Group message 1 body14171417- NdisZeroMemory(&Packet, sizeof(Packet));14181418- Packet.ProVer = EAPOL_VER;14191419- Packet.ProType = EAPOLKey;14201420- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE; // No data field14211421-14221422- //14231423- // Group Message 2 as EAPOL-Key(1,0,0,0,G,0,0,MIC,0)14241424- //14251425- if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)14261426- {14271427- Packet.KeyDesc.Type = WPA2_KEY_DESC;14281428- }14291429- else14301430- {14311431- Packet.KeyDesc.Type = WPA1_KEY_DESC;14321432- }14331433-14341434- // Key descriptor version and appropriate RSN IE14351435- Packet.KeyDesc.KeyInfo.KeyDescVer = peerKeyInfo.KeyDescVer;14361436-14371437- // Update Key Length14381438- Packet.KeyDesc.KeyLength[0] = pGroup->KeyDesc.KeyLength[0];14391439- Packet.KeyDesc.KeyLength[1] = pGroup->KeyDesc.KeyLength[1];14401440-14411441- // Key Index as G-Msg 114421442- if(pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)14431443- Packet.KeyDesc.KeyInfo.KeyIndex = peerKeyInfo.KeyIndex;14441444-14451445- // Key Type Group key14461446- Packet.KeyDesc.KeyInfo.KeyType = GROUPKEY;14471447-14481448- // KeyMic field presented14491449- Packet.KeyDesc.KeyInfo.KeyMic = 1;14501450-14511451- // Secure bit14521452- Packet.KeyDesc.KeyInfo.Secure = 1;14531453-14541454- // Convert to little-endian format.14551455- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));14561456-14571457- // Key Replay count14581458- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pGroup->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);14591459-14601460- // Out buffer for transmitting group message 214611461- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory14621462- if(pOutBuffer == NULL)14631463- {14641464- MlmeFreeMemory(pAd, (PUCHAR)mpool);14651465- return;14661466- }14671467-14681468- // Prepare EAPOL frame for MIC calculation14691469- // Be careful, only EAPOL frame is counted for MIC calculation14701470- MakeOutgoingFrame(pOutBuffer, &FrameLen,14711471- Packet.Body_Len[1] + 4, &Packet,14721472- END_OF_ARGS);14731473-14741474- // Prepare and Fill MIC value14751475- NdisZeroMemory(Mic, sizeof(Mic));14761476- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)14771477- {14781478- // AES14791479- HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);14801480- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);14811481- }14821482- else14831483- {14841484- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);14851485- }14861486- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);14871487-14881488-14891489- MakeOutgoingFrame(pOutBuffer, &FrameLen,14901490- LENGTH_802_3, &Header802_3,14911491- Packet.Body_Len[1] + 4, &Packet,14921492- END_OF_ARGS);14931493-14941494-14951495- // 5. Copy frame to Tx ring and prepare for encryption14961496- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);14971497-14981498- // 6 Free allocated memory14991499- MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);15001500- os_free_mem(pAd, (PUCHAR)mpool);15011501-15021502- // send wireless event - for set key done WPA215031503- if (pAd->CommonCfg.bWirelessEvent)15041504- RTMPSendWirelessEvent(pAd, IW_SET_KEY_DONE_WPA2_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);15051505-15061506- DBGPRINT(RT_DEBUG_TRACE, ("WpaGroupMsg1Action <-----\n"));15071507-}15081508-15091509-/*15101510- ========================================================================15111511-15121512- Routine Description:15131513- Init WPA MAC header15141514-15151515- Arguments:15161516- pAd Pointer to our adapter15171517-15181518- Return Value:15191519- None15201520-15211521- Note:15221522-15231523- ========================================================================15241524-*/15251525-VOID WpaMacHeaderInit(15261526- IN PRTMP_ADAPTER pAd,15271527- IN OUT PHEADER_802_11 pHdr80211,15281528- IN UCHAR wep,15291529- IN PUCHAR pAddr1)15301530-{15311531- NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11));15321532- pHdr80211->FC.Type = BTYPE_DATA;15331533- pHdr80211->FC.ToDs = 1;15341534- if (wep == 1)15351535- pHdr80211->FC.Wep = 1;15361536-15371537- // Addr1: BSSID, Addr2: SA, Addr3: DA15381538- COPY_MAC_ADDR(pHdr80211->Addr1, pAddr1);15391539- COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);15401540- COPY_MAC_ADDR(pHdr80211->Addr3, pAd->CommonCfg.Bssid);15411541- pHdr80211->Sequence = pAd->Sequence;15421542-}15431543-15441544-/*15451545- ========================================================================15461546-15471547- Routine Description:15481548- Copy frame from waiting queue into relative ring buffer and set15491549- appropriate ASIC register to kick hardware encryption before really15501550- sent out to air.15511551-15521552- Arguments:15531553- pAd Pointer to our adapter15541554- PNDIS_PACKET Pointer to outgoing Ndis frame15551555- NumberOfFrag Number of fragment required15561556-15571557- Return Value:15581558- None15591559-15601560- Note:15611561-15621562- ========================================================================15631563-*/15641564-VOID RTMPToWirelessSta(15651565- IN PRTMP_ADAPTER pAd,15661566- IN PUCHAR pHeader802_3,15671567- IN UINT HdrLen,15681568- IN PUCHAR pData,15691569- IN UINT DataLen,15701570- IN BOOLEAN is4wayFrame)15711571-15721572-{15731573- NDIS_STATUS Status;15741574- PNDIS_PACKET pPacket;15751575- UCHAR Index;15761576-15771577- do15781578- {15791579- // 1. build a NDIS packet and call RTMPSendPacket();15801580- // be careful about how/when to release this internal allocated NDIS PACKET buffer15811581- Status = RTMPAllocateNdisPacket(pAd, &pPacket, pHeader802_3, HdrLen, pData, DataLen);15821582- if (Status != NDIS_STATUS_SUCCESS)15831583- break;15841584-15851585- if (is4wayFrame)15861586- RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 1);15871587- else15881588- RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 0);15891589-15901590- // 2. send out the packet15911591- Status = STASendPacket(pAd, pPacket);15921592- if(Status == NDIS_STATUS_SUCCESS)15931593- {15941594- // Dequeue one frame from TxSwQueue0..3 queue and process it15951595- // There are three place calling dequeue for TX ring.15961596- // 1. Here, right after queueing the frame.15971597- // 2. At the end of TxRingTxDone service routine.15981598- // 3. Upon NDIS call RTMPSendPackets15991599- if((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&16001600- (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)))16011601- {16021602- for(Index = 0; Index < 5; Index ++)16031603- if(pAd->TxSwQueue[Index].Number > 0)16041604- RTMPDeQueuePacket(pAd, FALSE, Index, MAX_TX_PROCESS);16051605- }16061606- }16071607- } while(FALSE);16081608-16091609-}16101610-16111611-/*16121612- ========================================================================16131613-16141614- Routine Description:16151615- Check Sanity RSN IE form AP16161616-16171617- Arguments:16181618-16191619- Return Value:16201620-16211621-16221622- ========================================================================16231623-*/16241624-BOOLEAN CheckRSNIE(16251625- IN PRTMP_ADAPTER pAd,16261626- IN PUCHAR pData,16271627- IN UCHAR DataLen,16281628- OUT UCHAR *Offset)16291629-{16301630- PUCHAR pVIE;16311631- UCHAR len;16321632- PEID_STRUCT pEid;16331633- BOOLEAN result = FALSE;16341634-16351635- pVIE = pData;16361636- len = DataLen;16371637- *Offset = 0;16381638-16391639- while (len > sizeof(RSNIE2))16401640- {16411641- pEid = (PEID_STRUCT) pVIE;16421642- // WPA RSN IE16431643- if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))16441644- {16451645- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) &&16461646- (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&16471647- (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))16481648- {16491649- DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA/WPAPSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));16501650- result = TRUE;16511651- }16521652-16531653- *Offset += (pEid->Len + 2);16541654- }16551655- // WPA2 RSN IE16561656- else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))16571657- {16581658- if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2 || pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) &&16591659- (NdisEqualMemory(pVIE, pAd->MacTab.Content[BSSID_WCID].RSN_IE, pAd->MacTab.Content[BSSID_WCID].RSNIE_Len)) &&16601660- (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == (pEid->Len + 2)))16611661- {16621662- DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", (pEid->Len + 2)));16631663- result = TRUE;16641664- }16651665-16661666- *Offset += (pEid->Len + 2);16671667- }16681668- else16691669- {16701670- break;16711671- }16721672-16731673- pVIE += (pEid->Len + 2);16741674- len -= (pEid->Len + 2);16751675- }16761676-16771677- DBGPRINT(RT_DEBUG_TRACE, ("CheckRSNIE ==> skip_offset(%d) \n", *Offset));16781678-16791679- return result;16801680-16811681-}16821682-16831683-16841684-/*16851685- ========================================================================16861686-16871687- Routine Description:16881688- Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.16891689- GTK is encaptulated in KDE format at p.83 802.11i D1016901690-16911691- Arguments:16921692-16931693- Return Value:16941694-16951695- Note:16961696- 802.11i D1016971697-16981698- ========================================================================16991699-*/17001700-BOOLEAN ParseKeyData(17011701- IN PRTMP_ADAPTER pAd,17021702- IN PUCHAR pKeyData,17031703- IN UCHAR KeyDataLen,17041704- IN UCHAR bPairewise)17051705-{17061706- PKDE_ENCAP pKDE = NULL;17071707- PUCHAR pMyKeyData = pKeyData;17081708- UCHAR KeyDataLength = KeyDataLen;17091709- UCHAR GTKLEN;17101710- UCHAR skip_offset;17111711-17121712- // Verify The RSN IE contained in Pairewise-Msg 3 and skip it17131713- if (bPairewise)17141714- {17151715- // Check RSN IE whether it is WPA2/WPA2PSK17161716- if (!CheckRSNIE(pAd, pKeyData, KeyDataLen, &skip_offset))17171717- {17181718- DBGPRINT(RT_DEBUG_ERROR, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE mismatched \n"));17191719- hex_dump("Get KEYDATA :", pKeyData, KeyDataLen);17201720- return FALSE;17211721- }17221722- else17231723- {17241724- // skip RSN IE17251725- pMyKeyData += skip_offset;17261726- KeyDataLength -= skip_offset;17271727-17281728- //DBGPRINT(RT_DEBUG_TRACE, ("ParseKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));17291729- }17301730- }17311731-17321732- DBGPRINT(RT_DEBUG_TRACE,("ParseKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));17331733-17341734- // Parse EKD format17351735- if (KeyDataLength >= 8)17361736- {17371737- pKDE = (PKDE_ENCAP) pMyKeyData;17381738- }17391739- else17401740- {17411741- DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KeyDataLength is too short \n"));17421742- return FALSE;17431743- }17441744-17451745-17461746- // Sanity check - shared key index should not be 017471747- if (pKDE->GTKEncap.Kid == 0)17481748- {17491749- DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index zero \n"));17501750- return FALSE;17511751- }17521752-17531753- // Sanity check - KED length17541754- if (KeyDataLength < (pKDE->Len + 2))17551755- {17561756- DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));17571757- return FALSE;17581758- }17591759-17601760- // Get GTK length - refer to IEEE 802.11i-2004 p.8217611761- GTKLEN = pKDE->Len -6;17621762-17631763- if (GTKLEN < LEN_AES_KEY)17641764- {17651765- DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));17661766- return FALSE;17671767- }17681768- else17691769- DBGPRINT(RT_DEBUG_TRACE, ("GTK Key with KDE formet got index=%d, len=%d \n", pKDE->GTKEncap.Kid, GTKLEN));17701770-17711771- // Update GTK17721772- // set key material, TxMic and RxMic for WPAPSK17731773- NdisMoveMemory(pAd->StaCfg.GTK, pKDE->GTKEncap.GTK, 32);17741774- pAd->StaCfg.DefaultKeyId = pKDE->GTKEncap.Kid;17751775-17761776- // Update shared key table17771777- NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));17781778- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;17791779- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKDE->GTKEncap.GTK, LEN_TKIP_EK);17801780- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, &pKDE->GTKEncap.GTK[16], LEN_TKIP_RXMICK);17811781- NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, &pKDE->GTKEncap.GTK[24], LEN_TKIP_TXMICK);17821782-17831783- // Update Shared Key CipherAlg17841784- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;17851785- if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)17861786- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;17871787- else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)17881788- pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;17891789-17901790- return TRUE;17911791-17921792-}17931793-17941794-/*17951795- ========================================================================17961796-17971797- Routine Description:17981798- Cisco CCKM PRF function17991799-18001800- Arguments:18011801- key Cisco Base Transient Key (BTK)18021802- key_len The key length of the BTK18031803- data Ruquest Number(RN) + BSSID18041804- data_len The length of the data18051805- output Store for PTK(Pairwise transient keys)18061806- len The length of the output18071807- Return Value:18081808- None18091809-18101810- Note:18111811- 802.1i Annex F.918121812-18131813- ========================================================================18141814-*/18151815-VOID CCKMPRF(18161816- IN UCHAR *key,18171817- IN INT key_len,18181818- IN UCHAR *data,18191819- IN INT data_len,18201820- OUT UCHAR *output,18211821- IN INT len)18221822-{18231823- INT i;18241824- UCHAR input[1024];18251825- INT currentindex = 0;18261826- INT total_len;18271827-18281828- NdisMoveMemory(input, data, data_len);18291829- total_len = data_len;18301830- input[total_len] = 0;18311831- total_len++;18321832- for (i = 0; i < (len + 19) / 20; i++)18331833- {18341834- HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);18351835- currentindex += 20;18361836- input[total_len - 1]++;18371837- }18381838-}18391839-18401840-/*18411841- ========================================================================18421842-18431843- Routine Description:18441844- Process MIC error indication and record MIC error timer.18451845-18461846- Arguments:18471847- pAd Pointer to our adapter18481848- pWpaKey Pointer to the WPA key structure18491849-18501850- Return Value:18511851- None18521852-18531853- IRQL = DISPATCH_LEVEL18541854-18551855- Note:18561856-18571857- ========================================================================18581858-*/18591859-VOID RTMPReportMicError(18601860- IN PRTMP_ADAPTER pAd,18611861- IN PCIPHER_KEY pWpaKey)18621862-{18631863- ULONG Now;18641864- UCHAR unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1:0);18651865-18661866- // Record Last MIC error time and count18671867- Now = jiffies;18681868- if (pAd->StaCfg.MicErrCnt == 0)18691869- {18701870- pAd->StaCfg.MicErrCnt++;18711871- pAd->StaCfg.LastMicErrorTime = Now;18721872- NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);18731873- }18741874- else if (pAd->StaCfg.MicErrCnt == 1)18751875- {18761876- if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now)18771877- {18781878- // Update Last MIC error time, this did not violate two MIC errors within 60 seconds18791879- pAd->StaCfg.LastMicErrorTime = Now;18801880- }18811881- else18821882- {18831883-18841884- if (pAd->CommonCfg.bWirelessEvent)18851885- RTMPSendWirelessEvent(pAd, IW_COUNTER_MEASURES_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);18861886-18871887- pAd->StaCfg.LastMicErrorTime = Now;18881888- // Violate MIC error counts, MIC countermeasures kicks in18891889- pAd->StaCfg.MicErrCnt++;18901890- }18911891- }18921892- else18931893- {18941894- // MIC error count >= 218951895- // This should not happen18961896- ;18971897- }18981898- MlmeEnqueue(pAd,18991899- MLME_CNTL_STATE_MACHINE,19001900- OID_802_11_MIC_FAILURE_REPORT_FRAME,19011901- 1,19021902- &unicastKey);19031903-19041904- if (pAd->StaCfg.MicErrCnt == 2)19051905- {19061906- RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100);19071907- }19081908-}19091909-19101910-#define LENGTH_EAP_H 419111911-// If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)).19121912-INT WpaCheckEapCode(19131913- IN PRTMP_ADAPTER pAd,19141914- IN PUCHAR pFrame,19151915- IN USHORT FrameLen,19161916- IN USHORT OffSet)19171917-{19181918-19191919- PUCHAR pData;19201920- INT result = 0;19211921-19221922- if( FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H )19231923- return result;19241924-19251925- pData = pFrame + OffSet; // skip offset bytes19261926-19271927- if(*(pData+1) == EAPPacket) // 802.1x header - Packet Type19281928- {19291929- result = *(pData+4); // EAP header - Code19301930- }19311931-19321932- return result;19331933-}19341934-19351935-VOID WpaSendMicFailureToWpaSupplicant(19361936- IN PRTMP_ADAPTER pAd,19371937- IN BOOLEAN bUnicast)19381938-{19391939- union iwreq_data wrqu;19401940- char custom[IW_CUSTOM_MAX] = {0};19411941-19421942- sprintf(custom, "MLME-MICHAELMICFAILURE.indication");19431943- if (bUnicast)19441944- sprintf(custom, "%s unicast", custom);19451945- wrqu.data.length = strlen(custom);19461946- wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, custom);19471947-19481948- return;19491949-}19501950-19511951-VOID WpaMicFailureReportFrame(19521952- IN PRTMP_ADAPTER pAd,19531953- IN MLME_QUEUE_ELEM *Elem)19541954-{19551955- PUCHAR pOutBuffer = NULL;19561956- UCHAR Header802_3[14];19571957- ULONG FrameLen = 0;19581958- EAPOL_PACKET Packet;19591959- UCHAR Mic[16];19601960- BOOLEAN bUnicast;19611961-19621962- DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n"));19631963-19641964- bUnicast = (Elem->Msg[0] == 1 ? TRUE:FALSE);19651965- pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER);19661966-19671967- // init 802.3 header and Fill Packet19681968- MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL);19691969-19701970- NdisZeroMemory(&Packet, sizeof(Packet));19711971- Packet.ProVer = EAPOL_VER;19721972- Packet.ProType = EAPOLKey;19731973-19741974- Packet.KeyDesc.Type = WPA1_KEY_DESC;19751975-19761976- // Request field presented19771977- Packet.KeyDesc.KeyInfo.Request = 1;19781978-19791979- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)19801980- {19811981- Packet.KeyDesc.KeyInfo.KeyDescVer = 2;19821982- }19831983- else // TKIP19841984- {19851985- Packet.KeyDesc.KeyInfo.KeyDescVer = 1;19861986- }19871987-19881988- Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY);19891989-19901990- // KeyMic field presented19911991- Packet.KeyDesc.KeyInfo.KeyMic = 1;19921992-19931993- // Error field presented19941994- Packet.KeyDesc.KeyInfo.Error = 1;19951995-19961996- // Update packet length after decide Key data payload19971997- Packet.Body_Len[1] = sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE;19981998-19991999- // Key Replay Count20002000- NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);20012001- inc_byte_array(pAd->StaCfg.ReplayCounter, 8);20022002-20032003- // Convert to little-endian format.20042004- *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo));20052005-20062006-20072007- MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory20082008- if(pOutBuffer == NULL)20092009- {20102010- return;20112011- }20122012-20132013- // Prepare EAPOL frame for MIC calculation20142014- // Be careful, only EAPOL frame is counted for MIC calculation20152015- MakeOutgoingFrame(pOutBuffer, &FrameLen,20162016- Packet.Body_Len[1] + 4, &Packet,20172017- END_OF_ARGS);20182018-20192019- // Prepare and Fill MIC value20202020- NdisZeroMemory(Mic, sizeof(Mic));20212021- if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)20222022- { // AES20232023- UCHAR digest[20] = {0};20242024- HMAC_SHA1(pOutBuffer, FrameLen, pAd->StaCfg.PTK, LEN_EAP_MICK, digest);20252025- NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);20262026- }20272027- else20282028- { // TKIP20292029- hmac_md5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic);20302030- }20312031- NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);20322032-20332033- MakeOutgoingFrame(pOutBuffer, &FrameLen,20342034- LENGTH_802_3, &Header802_3,20352035- Packet.Body_Len[1] + 4, &Packet,20362036- END_OF_ARGS);20372037-20382038- // opy frame to Tx ring and send MIC failure report frame to authenticator20392039- RTMPToWirelessSta(pAd, Header802_3, LENGTH_802_3, (PUCHAR)&Packet, Packet.Body_Len[1] + 4, FALSE);20402040-20412041- MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer);20422042-20432043- DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n"));20442044-}20452045-20462046-/** from wpa_supplicant20472047- * inc_byte_array - Increment arbitrary length byte array by one20482048- * @counter: Pointer to byte array20492049- * @len: Length of the counter in bytes20502050- *20512051- * This function increments the last byte of the counter by one and continues20522052- * rolling over to more significant bytes if the byte was incremented from20532053- * 0xff to 0x00.20542054- */20552055-void inc_byte_array(UCHAR *counter, int len)20562056-{20572057- int pos = len - 1;20582058- while (pos >= 0) {20592059- counter[pos]++;20602060- if (counter[pos] != 0)20612061- break;20622062- pos--;20632063- }20642064-}20652065-20662066-VOID WpaDisassocApAndBlockAssoc(20672067- IN PVOID SystemSpecific1,20682068- IN PVOID FunctionContext,20692069- IN PVOID SystemSpecific2,20702070- IN PVOID SystemSpecific3)20712071-{20722072- RTMP_ADAPTER *pAd = (PRTMP_ADAPTER)FunctionContext;20732073- MLME_DISASSOC_REQ_STRUCT DisassocReq;20742074-20752075- // disassoc from current AP first20762076- DBGPRINT(RT_DEBUG_TRACE, ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n"));20772077- DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_MIC_FAILURE);20782078- MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);20792079-20802080- pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;20812081- pAd->StaCfg.bBlockAssoc = TRUE;20822082-}20832083-11+#include "../../rt2870/sta/wpa.c"