Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: rt28[67]0: merge rt28[67]0/common/*.[ch]

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Bartlomiej Zolnierkiewicz and committed by
Greg Kroah-Hartman
371abf6d 59fe2d89

+16 -31753
+1 -616
drivers/staging/rt2870/common/action.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - action.c 29 - 30 - Abstract: 31 - Handle association related requests either from WSTA or from local MLME 32 - 33 - Revision History: 34 - Who When What 35 - -------- ---------- ---------------------------------------------- 36 - Jan Lee 2006 created for rt2860 37 - */ 38 - 39 - #include "../rt_config.h" 40 - #include "action.h" 41 - 42 - 43 - static VOID ReservedAction( 44 - IN PRTMP_ADAPTER pAd, 45 - IN MLME_QUEUE_ELEM *Elem); 46 - 47 - /* 48 - ========================================================================== 49 - Description: 50 - association state machine init, including state transition and timer init 51 - Parameters: 52 - S - pointer to the association state machine 53 - Note: 54 - The state machine looks like the following 55 - 56 - ASSOC_IDLE 57 - MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action 58 - MT2_PEER_DISASSOC_REQ peer_disassoc_action 59 - MT2_PEER_ASSOC_REQ drop 60 - MT2_PEER_REASSOC_REQ drop 61 - MT2_CLS3ERR cls3err_action 62 - ========================================================================== 63 - */ 64 - VOID ActionStateMachineInit( 65 - IN PRTMP_ADAPTER pAd, 66 - IN STATE_MACHINE *S, 67 - OUT STATE_MACHINE_FUNC Trans[]) 68 - { 69 - StateMachineInit(S, (STATE_MACHINE_FUNC *)Trans, MAX_ACT_STATE, MAX_ACT_MSG, (STATE_MACHINE_FUNC)Drop, ACT_IDLE, ACT_MACHINE_BASE); 70 - 71 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_SPECTRUM_CATE, (STATE_MACHINE_FUNC)PeerSpectrumAction); 72 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_QOS_CATE, (STATE_MACHINE_FUNC)PeerQOSAction); 73 - 74 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, (STATE_MACHINE_FUNC)ReservedAction); 75 - 76 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_BA_CATE, (STATE_MACHINE_FUNC)PeerBAAction); 77 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_HT_CATE, (STATE_MACHINE_FUNC)PeerHTAction); 78 - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ADD_BA_CATE, (STATE_MACHINE_FUNC)MlmeADDBAAction); 79 - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ORI_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction); 80 - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_REC_DELBA_CATE, (STATE_MACHINE_FUNC)MlmeDELBAAction); 81 - 82 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_PUBLIC_CATE, (STATE_MACHINE_FUNC)PeerPublicAction); 83 - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_RM_CATE, (STATE_MACHINE_FUNC)PeerRMAction); 84 - 85 - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_QOS_CATE, (STATE_MACHINE_FUNC)MlmeQOSAction); 86 - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_DLS_CATE, (STATE_MACHINE_FUNC)MlmeDLSAction); 87 - StateMachineSetAction(S, ACT_IDLE, MT2_ACT_INVALID, (STATE_MACHINE_FUNC)MlmeInvalidAction); 88 - } 89 - 90 - VOID MlmeADDBAAction( 91 - IN PRTMP_ADAPTER pAd, 92 - IN MLME_QUEUE_ELEM *Elem) 93 - 94 - { 95 - MLME_ADDBA_REQ_STRUCT *pInfo; 96 - UCHAR Addr[6]; 97 - PUCHAR pOutBuffer = NULL; 98 - NDIS_STATUS NStatus; 99 - ULONG Idx; 100 - FRAME_ADDBA_REQ Frame; 101 - ULONG FrameLen; 102 - BA_ORI_ENTRY *pBAEntry = NULL; 103 - 104 - pInfo = (MLME_ADDBA_REQ_STRUCT *)Elem->Msg; 105 - NdisZeroMemory(&Frame, sizeof(FRAME_ADDBA_REQ)); 106 - 107 - if(MlmeAddBAReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr)) 108 - { 109 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 110 - if(NStatus != NDIS_STATUS_SUCCESS) 111 - { 112 - DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeADDBAAction() allocate memory failed \n")); 113 - return; 114 - } 115 - // 1. find entry 116 - Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID]; 117 - if (Idx == 0) 118 - { 119 - MlmeFreeMemory(pAd, pOutBuffer); 120 - DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() can't find BAOriEntry \n")); 121 - return; 122 - } 123 - else 124 - { 125 - pBAEntry =&pAd->BATable.BAOriEntry[Idx]; 126 - } 127 - 128 - { 129 - if (ADHOC_ON(pAd)) 130 - ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid); 131 - else 132 - ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pInfo->pAddr); 133 - } 134 - 135 - Frame.Category = CATEGORY_BA; 136 - Frame.Action = ADDBA_REQ; 137 - Frame.BaParm.AMSDUSupported = 0; 138 - Frame.BaParm.BAPolicy = IMMED_BA; 139 - Frame.BaParm.TID = pInfo->TID; 140 - Frame.BaParm.BufSize = pInfo->BaBufSize; 141 - Frame.Token = pInfo->Token; 142 - Frame.TimeOutValue = pInfo->TimeOutValue; 143 - Frame.BaStartSeq.field.FragNum = 0; 144 - Frame.BaStartSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; 145 - 146 - *(USHORT *)(&Frame.BaParm) = cpu2le16(*(USHORT *)(&Frame.BaParm)); 147 - Frame.TimeOutValue = cpu2le16(Frame.TimeOutValue); 148 - Frame.BaStartSeq.word = cpu2le16(Frame.BaStartSeq.word); 149 - 150 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 151 - sizeof(FRAME_ADDBA_REQ), &Frame, 152 - END_OF_ARGS); 153 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 154 - MlmeFreeMemory(pAd, pOutBuffer); 155 - 156 - DBGPRINT(RT_DEBUG_TRACE, ("BA - Send ADDBA request. StartSeq = %x, FrameLen = %ld. BufSize = %d\n", Frame.BaStartSeq.field.StartSeq, FrameLen, Frame.BaParm.BufSize)); 157 - } 158 - } 159 - 160 - /* 161 - ========================================================================== 162 - Description: 163 - send DELBA and delete BaEntry if any 164 - Parametrs: 165 - Elem - MLME message MLME_DELBA_REQ_STRUCT 166 - 167 - IRQL = DISPATCH_LEVEL 168 - 169 - ========================================================================== 170 - */ 171 - VOID MlmeDELBAAction( 172 - IN PRTMP_ADAPTER pAd, 173 - IN MLME_QUEUE_ELEM *Elem) 174 - { 175 - MLME_DELBA_REQ_STRUCT *pInfo; 176 - PUCHAR pOutBuffer = NULL; 177 - PUCHAR pOutBuffer2 = NULL; 178 - NDIS_STATUS NStatus; 179 - ULONG Idx; 180 - FRAME_DELBA_REQ Frame; 181 - ULONG FrameLen; 182 - FRAME_BAR FrameBar; 183 - 184 - pInfo = (MLME_DELBA_REQ_STRUCT *)Elem->Msg; 185 - // must send back DELBA 186 - NdisZeroMemory(&Frame, sizeof(FRAME_DELBA_REQ)); 187 - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeDELBAAction(), Initiator(%d) \n", pInfo->Initiator)); 188 - 189 - if(MlmeDelBAReqSanity(pAd, Elem->Msg, Elem->MsgLen)) 190 - { 191 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 192 - if(NStatus != NDIS_STATUS_SUCCESS) 193 - { 194 - DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeDELBAAction() allocate memory failed 1. \n")); 195 - return; 196 - } 197 - 198 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory 199 - if(NStatus != NDIS_STATUS_SUCCESS) 200 - { 201 - MlmeFreeMemory(pAd, pOutBuffer); 202 - DBGPRINT(RT_DEBUG_ERROR, ("BA - MlmeDELBAAction() allocate memory failed 2. \n")); 203 - return; 204 - } 205 - 206 - // SEND BAR (Send BAR to refresh peer reordering buffer.) 207 - Idx = pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID]; 208 - 209 - BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress); 210 - 211 - FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL funciton. 212 - FrameBar.StartingSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; // make sure sequence not clear in DEL funciton. 213 - FrameBar.BarControl.TID = pInfo->TID; // make sure sequence not clear in DEL funciton. 214 - FrameBar.BarControl.ACKPolicy = IMMED_BA; // make sure sequence not clear in DEL funciton. 215 - FrameBar.BarControl.Compressed = 1; // make sure sequence not clear in DEL funciton. 216 - FrameBar.BarControl.MTID = 0; // make sure sequence not clear in DEL funciton. 217 - 218 - MakeOutgoingFrame(pOutBuffer2, &FrameLen, 219 - sizeof(FRAME_BAR), &FrameBar, 220 - END_OF_ARGS); 221 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen); 222 - MlmeFreeMemory(pAd, pOutBuffer2); 223 - DBGPRINT(RT_DEBUG_TRACE,("BA - MlmeDELBAAction() . Send BAR to refresh peer reordering buffer \n")); 224 - 225 - // SEND DELBA FRAME 226 - FrameLen = 0; 227 - 228 - { 229 - if (ADHOC_ON(pAd)) 230 - ActHeaderInit(pAd, &Frame.Hdr, pAd->MacTab.Content[pInfo->Wcid].Addr, pAd->CurrentAddress, pAd->CommonCfg.Bssid); 231 - else 232 - ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[pInfo->Wcid].Addr); 233 - } 234 - 235 - Frame.Category = CATEGORY_BA; 236 - Frame.Action = DELBA; 237 - Frame.DelbaParm.Initiator = pInfo->Initiator; 238 - Frame.DelbaParm.TID = pInfo->TID; 239 - Frame.ReasonCode = 39; // Time Out 240 - *(USHORT *)(&Frame.DelbaParm) = cpu2le16(*(USHORT *)(&Frame.DelbaParm)); 241 - Frame.ReasonCode = cpu2le16(Frame.ReasonCode); 242 - 243 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 244 - sizeof(FRAME_DELBA_REQ), &Frame, 245 - END_OF_ARGS); 246 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 247 - MlmeFreeMemory(pAd, pOutBuffer); 248 - DBGPRINT(RT_DEBUG_TRACE, ("BA - MlmeDELBAAction() . 3 DELBA sent. Initiator(%d)\n", pInfo->Initiator)); 249 - } 250 - } 251 - 252 - VOID MlmeQOSAction( 253 - IN PRTMP_ADAPTER pAd, 254 - IN MLME_QUEUE_ELEM *Elem) 255 - { 256 - } 257 - 258 - VOID MlmeDLSAction( 259 - IN PRTMP_ADAPTER pAd, 260 - IN MLME_QUEUE_ELEM *Elem) 261 - { 262 - } 263 - 264 - VOID MlmeInvalidAction( 265 - IN PRTMP_ADAPTER pAd, 266 - IN MLME_QUEUE_ELEM *Elem) 267 - { 268 - //PUCHAR pOutBuffer = NULL; 269 - //Return the receiving frame except the MSB of category filed set to 1. 7.3.1.11 270 - } 271 - 272 - VOID PeerQOSAction( 273 - IN PRTMP_ADAPTER pAd, 274 - IN MLME_QUEUE_ELEM *Elem) 275 - { 276 - } 277 - 278 - VOID PeerBAAction( 279 - IN PRTMP_ADAPTER pAd, 280 - IN MLME_QUEUE_ELEM *Elem) 281 - { 282 - UCHAR Action = Elem->Msg[LENGTH_802_11+1]; 283 - 284 - switch(Action) 285 - { 286 - case ADDBA_REQ: 287 - PeerAddBAReqAction(pAd,Elem); 288 - break; 289 - case ADDBA_RESP: 290 - PeerAddBARspAction(pAd,Elem); 291 - break; 292 - case DELBA: 293 - PeerDelBAAction(pAd,Elem); 294 - break; 295 - } 296 - } 297 - 298 - VOID PeerPublicAction( 299 - IN PRTMP_ADAPTER pAd, 300 - IN MLME_QUEUE_ELEM *Elem) 301 - { 302 - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) 303 - return; 304 - } 305 - 306 - 307 - static VOID ReservedAction( 308 - IN PRTMP_ADAPTER pAd, 309 - IN MLME_QUEUE_ELEM *Elem) 310 - { 311 - UCHAR Category; 312 - 313 - if (Elem->MsgLen <= LENGTH_802_11) 314 - { 315 - return; 316 - } 317 - 318 - Category = Elem->Msg[LENGTH_802_11]; 319 - DBGPRINT(RT_DEBUG_TRACE,("Rcv reserved category(%d) Action Frame\n", Category)); 320 - hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen); 321 - } 322 - 323 - VOID PeerRMAction( 324 - IN PRTMP_ADAPTER pAd, 325 - IN MLME_QUEUE_ELEM *Elem) 326 - 327 - { 328 - return; 329 - } 330 - 331 - static VOID respond_ht_information_exchange_action( 332 - IN PRTMP_ADAPTER pAd, 333 - IN MLME_QUEUE_ELEM *Elem) 334 - { 335 - PUCHAR pOutBuffer = NULL; 336 - NDIS_STATUS NStatus; 337 - ULONG FrameLen; 338 - FRAME_HT_INFO HTINFOframe, *pFrame; 339 - UCHAR *pAddr; 340 - 341 - 342 - // 2. Always send back ADDBA Response 343 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 344 - 345 - if (NStatus != NDIS_STATUS_SUCCESS) 346 - { 347 - DBGPRINT(RT_DEBUG_TRACE,("ACTION - respond_ht_information_exchange_action() allocate memory failed \n")); 348 - return; 349 - } 350 - 351 - // get RA 352 - pFrame = (FRAME_HT_INFO *) &Elem->Msg[0]; 353 - pAddr = pFrame->Hdr.Addr2; 354 - 355 - NdisZeroMemory(&HTINFOframe, sizeof(FRAME_HT_INFO)); 356 - // 2-1. Prepare ADDBA Response frame. 357 - { 358 - if (ADHOC_ON(pAd)) 359 - ActHeaderInit(pAd, &HTINFOframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid); 360 - else 361 - ActHeaderInit(pAd, &HTINFOframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr); 362 - } 363 - 364 - HTINFOframe.Category = CATEGORY_HT; 365 - HTINFOframe.Action = HT_INFO_EXCHANGE; 366 - HTINFOframe.HT_Info.Request = 0; 367 - HTINFOframe.HT_Info.Forty_MHz_Intolerant = pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant; 368 - HTINFOframe.HT_Info.STA_Channel_Width = pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth; 369 - 370 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 371 - sizeof(FRAME_HT_INFO), &HTINFOframe, 372 - END_OF_ARGS); 373 - 374 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 375 - MlmeFreeMemory(pAd, pOutBuffer); 376 - } 377 - 378 - VOID PeerHTAction( 379 - IN PRTMP_ADAPTER pAd, 380 - IN MLME_QUEUE_ELEM *Elem) 381 - { 382 - UCHAR Action = Elem->Msg[LENGTH_802_11+1]; 383 - 384 - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) 385 - return; 386 - 387 - switch(Action) 388 - { 389 - case NOTIFY_BW_ACTION: 390 - DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Notify Channel bandwidth action----> \n")); 391 - 392 - if(pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) 393 - { 394 - // Note, this is to patch DIR-1353 AP. When the AP set to Wep, it will use legacy mode. But AP still keeps 395 - // sending BW_Notify Action frame, and cause us to linkup and linkdown. 396 - // In legacy mode, don't need to parse HT action frame. 397 - DBGPRINT(RT_DEBUG_TRACE,("ACTION -Ignore HT Notify Channel BW when link as legacy mode. BW = %d---> \n", 398 - Elem->Msg[LENGTH_802_11+2] )); 399 - break; 400 - } 401 - 402 - if (Elem->Msg[LENGTH_802_11+2] == 0) // 7.4.8.2. if value is 1, keep the same as supported channel bandwidth. 403 - pAd->MacTab.Content[Elem->Wcid].HTPhyMode.field.BW = 0; 404 - 405 - break; 406 - 407 - case SMPS_ACTION: 408 - // 7.3.1.25 409 - DBGPRINT(RT_DEBUG_TRACE,("ACTION - SMPS action----> \n")); 410 - if (((Elem->Msg[LENGTH_802_11+2]&0x1) == 0)) 411 - { 412 - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_ENABLE; 413 - } 414 - else if (((Elem->Msg[LENGTH_802_11+2]&0x2) == 0)) 415 - { 416 - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_STATIC; 417 - } 418 - else 419 - { 420 - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_DYNAMIC; 421 - } 422 - 423 - DBGPRINT(RT_DEBUG_TRACE,("Aid(%d) MIMO PS = %d\n", Elem->Wcid, pAd->MacTab.Content[Elem->Wcid].MmpsMode)); 424 - // rt2860c : add something for smps change. 425 - break; 426 - 427 - case SETPCO_ACTION: 428 - break; 429 - 430 - case MIMO_CHA_MEASURE_ACTION: 431 - break; 432 - 433 - case HT_INFO_EXCHANGE: 434 - { 435 - HT_INFORMATION_OCTET *pHT_info; 436 - 437 - pHT_info = (HT_INFORMATION_OCTET *) &Elem->Msg[LENGTH_802_11+2]; 438 - // 7.4.8.10 439 - DBGPRINT(RT_DEBUG_TRACE,("ACTION - HT Information Exchange action----> \n")); 440 - if (pHT_info->Request) 441 - { 442 - respond_ht_information_exchange_action(pAd, Elem); 443 - } 444 - } 445 - break; 446 - } 447 - } 448 - 449 - 450 - /* 451 - ========================================================================== 452 - Description: 453 - Retry sending ADDBA Reqest. 454 - 455 - IRQL = DISPATCH_LEVEL 456 - 457 - Parametrs: 458 - p8023Header: if this is already 802.3 format, p8023Header is NULL 459 - 460 - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. 461 - FALSE , then continue indicaterx at this moment. 462 - ========================================================================== 463 - */ 464 - VOID ORIBATimerTimeout( 465 - IN PRTMP_ADAPTER pAd) 466 - { 467 - MAC_TABLE_ENTRY *pEntry; 468 - INT i, total; 469 - UCHAR TID; 470 - 471 - total = pAd->MacTab.Size * NUM_OF_TID; 472 - 473 - for (i = 1; ((i <MAX_LEN_OF_BA_ORI_TABLE) && (total > 0)) ; i++) 474 - { 475 - if (pAd->BATable.BAOriEntry[i].ORI_BA_Status == Originator_Done) 476 - { 477 - pEntry = &pAd->MacTab.Content[pAd->BATable.BAOriEntry[i].Wcid]; 478 - TID = pAd->BATable.BAOriEntry[i].TID; 479 - 480 - ASSERT(pAd->BATable.BAOriEntry[i].Wcid < MAX_LEN_OF_MAC_TABLE); 481 - } 482 - total --; 483 - } 484 - } 485 - 486 - 487 - VOID SendRefreshBAR( 488 - IN PRTMP_ADAPTER pAd, 489 - IN MAC_TABLE_ENTRY *pEntry) 490 - { 491 - FRAME_BAR FrameBar; 492 - ULONG FrameLen; 493 - NDIS_STATUS NStatus; 494 - PUCHAR pOutBuffer = NULL; 495 - USHORT Sequence; 496 - UCHAR i, TID; 497 - USHORT idx; 498 - BA_ORI_ENTRY *pBAEntry; 499 - 500 - for (i = 0; i <NUM_OF_TID; i++) 501 - { 502 - idx = pEntry->BAOriWcidArray[i]; 503 - if (idx == 0) 504 - { 505 - continue; 506 - } 507 - pBAEntry = &pAd->BATable.BAOriEntry[idx]; 508 - 509 - if (pBAEntry->ORI_BA_Status == Originator_Done) 510 - { 511 - TID = pBAEntry->TID; 512 - 513 - ASSERT(pBAEntry->Wcid < MAX_LEN_OF_MAC_TABLE); 514 - 515 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 516 - if(NStatus != NDIS_STATUS_SUCCESS) 517 - { 518 - DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n")); 519 - return; 520 - } 521 - 522 - Sequence = pEntry->TxSeq[TID]; 523 - 524 - BarHeaderInit(pAd, &FrameBar, pEntry->Addr, pAd->CurrentAddress); 525 - 526 - FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function. 527 - FrameBar.StartingSeq.field.StartSeq = Sequence; // make sure sequence not clear in DEL funciton. 528 - FrameBar.BarControl.TID = TID; // make sure sequence not clear in DEL funciton. 529 - 530 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 531 - sizeof(FRAME_BAR), &FrameBar, 532 - END_OF_ARGS); 533 - 534 - if (1) // Now we always send BAR. 535 - { 536 - #ifndef RT30xx 537 - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); 538 - #endif 539 - #ifdef RT30xx 540 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 541 - #endif 542 - } 543 - MlmeFreeMemory(pAd, pOutBuffer); 544 - } 545 - } 546 - } 547 - 548 - VOID ActHeaderInit( 549 - IN PRTMP_ADAPTER pAd, 550 - IN OUT PHEADER_802_11 pHdr80211, 551 - IN PUCHAR Addr1, 552 - IN PUCHAR Addr2, 553 - IN PUCHAR Addr3) 554 - { 555 - NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11)); 556 - pHdr80211->FC.Type = BTYPE_MGMT; 557 - pHdr80211->FC.SubType = SUBTYPE_ACTION; 558 - 559 - COPY_MAC_ADDR(pHdr80211->Addr1, Addr1); 560 - COPY_MAC_ADDR(pHdr80211->Addr2, Addr2); 561 - COPY_MAC_ADDR(pHdr80211->Addr3, Addr3); 562 - } 563 - 564 - VOID BarHeaderInit( 565 - IN PRTMP_ADAPTER pAd, 566 - IN OUT PFRAME_BAR pCntlBar, 567 - IN PUCHAR pDA, 568 - IN PUCHAR pSA) 569 - { 570 - NdisZeroMemory(pCntlBar, sizeof(FRAME_BAR)); 571 - pCntlBar->FC.Type = BTYPE_CNTL; 572 - pCntlBar->FC.SubType = SUBTYPE_BLOCK_ACK_REQ; 573 - pCntlBar->BarControl.MTID = 0; 574 - pCntlBar->BarControl.Compressed = 1; 575 - pCntlBar->BarControl.ACKPolicy = 0; 576 - 577 - 578 - pCntlBar->Duration = 16 + RTMPCalcDuration(pAd, RATE_1, sizeof(FRAME_BA)); 579 - 580 - COPY_MAC_ADDR(pCntlBar->Addr1, pDA); 581 - COPY_MAC_ADDR(pCntlBar->Addr2, pSA); 582 - } 583 - 584 - 585 - /* 586 - ========================================================================== 587 - Description: 588 - Insert Category and action code into the action frame. 589 - 590 - Parametrs: 591 - 1. frame buffer pointer. 592 - 2. frame length. 593 - 3. category code of the frame. 594 - 4. action code of the frame. 595 - 596 - Return : None. 597 - ========================================================================== 598 - */ 599 - VOID InsertActField( 600 - IN PRTMP_ADAPTER pAd, 601 - OUT PUCHAR pFrameBuf, 602 - OUT PULONG pFrameLen, 603 - IN UINT8 Category, 604 - IN UINT8 ActCode) 605 - { 606 - ULONG TempLen; 607 - 608 - MakeOutgoingFrame( pFrameBuf, &TempLen, 609 - 1, &Category, 610 - 1, &ActCode, 611 - END_OF_ARGS); 612 - 613 - *pFrameLen = *pFrameLen + TempLen; 614 - 615 - return; 616 - } 1 + #include "../../rt2860/common/action.c"
+1 -61
drivers/staging/rt2870/common/action.h
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - aironet.h 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Name Date Modification logs 36 - Paul Lin 04-06-15 Initial 37 - */ 38 - 39 - #ifndef __ACTION_H__ 40 - #define __ACTION_H__ 41 - 42 - typedef struct PACKED __HT_INFO_OCTET 43 - { 44 - UCHAR Request:1; 45 - UCHAR Forty_MHz_Intolerant:1; 46 - UCHAR STA_Channel_Width:1; 47 - UCHAR Reserved:5; 48 - } HT_INFORMATION_OCTET; 49 - 50 - 51 - typedef struct PACKED __FRAME_HT_INFO 52 - { 53 - HEADER_802_11 Hdr; 54 - UCHAR Category; 55 - UCHAR Action; 56 - HT_INFORMATION_OCTET HT_Info; 57 - } FRAME_HT_INFO, *PFRAME_HT_INFO; 58 - 59 - #endif /* __ACTION_H__ */ 60 - 61 - 1 + #include "../../rt2860/common/action.h"
+1 -1770
drivers/staging/rt2870/common/ba_action.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - */ 27 - 28 - 29 - #include "../rt_config.h" 30 - 31 - 32 - 33 - #define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) //1 // inital sequence number of BA session 34 - 35 - #define ORI_SESSION_MAX_RETRY 8 36 - #define ORI_BA_SESSION_TIMEOUT (2000) // ms 37 - #define REC_BA_SESSION_IDLE_TIMEOUT (1000) // ms 38 - 39 - #define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms 40 - #define MAX_REORDERING_PACKET_TIMEOUT ((3000 * HZ)/1000) // system ticks -- 100 ms 41 - 42 - #define RESET_RCV_SEQ (0xFFFF) 43 - 44 - static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk); 45 - 46 - 47 - BA_ORI_ENTRY *BATableAllocOriEntry( 48 - IN PRTMP_ADAPTER pAd, 49 - OUT USHORT *Idx); 50 - 51 - BA_REC_ENTRY *BATableAllocRecEntry( 52 - IN PRTMP_ADAPTER pAd, 53 - OUT USHORT *Idx); 54 - 55 - VOID BAOriSessionSetupTimeout( 56 - IN PVOID SystemSpecific1, 57 - IN PVOID FunctionContext, 58 - IN PVOID SystemSpecific2, 59 - IN PVOID SystemSpecific3); 60 - 61 - VOID BARecSessionIdleTimeout( 62 - IN PVOID SystemSpecific1, 63 - IN PVOID FunctionContext, 64 - IN PVOID SystemSpecific2, 65 - IN PVOID SystemSpecific3); 66 - 67 - 68 - BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout); 69 - BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout); 70 - 71 - #define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \ 72 - Announce_Reordering_Packet(_pAd, _mpdu_blk); 73 - 74 - VOID BA_MaxWinSizeReasign( 75 - IN PRTMP_ADAPTER pAd, 76 - IN MAC_TABLE_ENTRY *pEntryPeer, 77 - OUT UCHAR *pWinSize) 78 - { 79 - UCHAR MaxSize; 80 - 81 - 82 - if (pAd->MACVersion >= RALINK_2883_VERSION) // 3*3 83 - { 84 - if (pAd->MACVersion >= RALINK_3070_VERSION) 85 - { 86 - if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled) 87 - MaxSize = 7; // for non-open mode 88 - else 89 - MaxSize = 13; 90 - } 91 - else 92 - MaxSize = 31; 93 - } 94 - else if (pAd->MACVersion >= RALINK_2880E_VERSION) // 2880 e 95 - { 96 - if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled) 97 - MaxSize = 7; // for non-open mode 98 - else 99 - MaxSize = 13; 100 - } 101 - else 102 - MaxSize = 7; 103 - 104 - DBGPRINT(RT_DEBUG_TRACE, ("ba> Win Size = %d, Max Size = %d\n", 105 - *pWinSize, MaxSize)); 106 - 107 - if ((*pWinSize) > MaxSize) 108 - { 109 - DBGPRINT(RT_DEBUG_TRACE, ("ba> reassign max win size from %d to %d\n", 110 - *pWinSize, MaxSize)); 111 - 112 - *pWinSize = MaxSize; 113 - } 114 - } 115 - 116 - void Announce_Reordering_Packet(IN PRTMP_ADAPTER pAd, 117 - IN struct reordering_mpdu *mpdu) 118 - { 119 - PNDIS_PACKET pPacket; 120 - 121 - pPacket = mpdu->pPacket; 122 - 123 - if (mpdu->bAMSDU) 124 - { 125 - ASSERT(0); 126 - BA_Reorder_AMSDU_Annnounce(pAd, pPacket); 127 - } 128 - else 129 - { 130 - // 131 - // pass this 802.3 packet to upper layer or forward this packet to WM directly 132 - // 133 - 134 - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket, RTMP_GET_PACKET_IF(pPacket)); 135 - } 136 - } 137 - 138 - /* 139 - * Insert a reordering mpdu into sorted linked list by sequence no. 140 - */ 141 - BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list, struct reordering_mpdu *mpdu) 142 - { 143 - 144 - struct reordering_mpdu **ppScan = &list->next; 145 - 146 - while (*ppScan != NULL) 147 - { 148 - if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ)) 149 - { 150 - ppScan = &(*ppScan)->next; 151 - } 152 - else if ((*ppScan)->Sequence == mpdu->Sequence) 153 - { 154 - /* give up this duplicated frame */ 155 - return(FALSE); 156 - } 157 - else 158 - { 159 - /* find position */ 160 - break; 161 - } 162 - } 163 - 164 - mpdu->next = *ppScan; 165 - *ppScan = mpdu; 166 - list->qlen++; 167 - return TRUE; 168 - } 169 - 170 - 171 - /* 172 - * caller lock critical section if necessary 173 - */ 174 - static inline void ba_enqueue(struct reordering_list *list, struct reordering_mpdu *mpdu_blk) 175 - { 176 - list->qlen++; 177 - mpdu_blk->next = list->next; 178 - list->next = mpdu_blk; 179 - } 180 - 181 - /* 182 - * caller lock critical section if necessary 183 - */ 184 - static inline struct reordering_mpdu * ba_dequeue(struct reordering_list *list) 185 - { 186 - struct reordering_mpdu *mpdu_blk = NULL; 187 - 188 - ASSERT(list); 189 - 190 - if (list->qlen) 191 - { 192 - list->qlen--; 193 - mpdu_blk = list->next; 194 - if (mpdu_blk) 195 - { 196 - list->next = mpdu_blk->next; 197 - mpdu_blk->next = NULL; 198 - } 199 - } 200 - return mpdu_blk; 201 - } 202 - 203 - 204 - static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct reordering_list *list) 205 - { 206 - return(ba_dequeue(list)); 207 - } 208 - 209 - 210 - static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct reordering_list *list) 211 - { 212 - ASSERT(list); 213 - 214 - return(list->next); 215 - } 216 - 217 - 218 - /* 219 - * free all resource for reordering mechanism 220 - */ 221 - void ba_reordering_resource_release(PRTMP_ADAPTER pAd) 222 - { 223 - BA_TABLE *Tab; 224 - PBA_REC_ENTRY pBAEntry; 225 - struct reordering_mpdu *mpdu_blk; 226 - int i; 227 - 228 - Tab = &pAd->BATable; 229 - 230 - /* I. release all pending reordering packet */ 231 - NdisAcquireSpinLock(&pAd->BATabLock); 232 - for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) 233 - { 234 - pBAEntry = &Tab->BARecEntry[i]; 235 - if (pBAEntry->REC_BA_Status != Recipient_NONE) 236 - { 237 - while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) 238 - { 239 - ASSERT(mpdu_blk->pPacket); 240 - RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket, NDIS_STATUS_FAILURE); 241 - ba_mpdu_blk_free(pAd, mpdu_blk); 242 - } 243 - } 244 - } 245 - NdisReleaseSpinLock(&pAd->BATabLock); 246 - 247 - ASSERT(pBAEntry->list.qlen == 0); 248 - /* II. free memory of reordering mpdu table */ 249 - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); 250 - os_free_mem(pAd, pAd->mpdu_blk_pool.mem); 251 - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); 252 - } 253 - 254 - 255 - 256 - /* 257 - * Allocate all resource for reordering mechanism 258 - */ 259 - BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num) 260 - { 261 - int i; 262 - PUCHAR mem; 263 - struct reordering_mpdu *mpdu_blk; 264 - struct reordering_list *freelist; 265 - 266 - /* allocate spinlock */ 267 - NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock); 268 - 269 - /* initialize freelist */ 270 - freelist = &pAd->mpdu_blk_pool.freelist; 271 - freelist->next = NULL; 272 - freelist->qlen = 0; 273 - 274 - DBGPRINT(RT_DEBUG_TRACE, ("Allocate %d memory for BA reordering\n", (UINT32)(num*sizeof(struct reordering_mpdu)))); 275 - 276 - /* allocate number of mpdu_blk memory */ 277 - os_alloc_mem(pAd, (PUCHAR *)&mem, (num*sizeof(struct reordering_mpdu))); 278 - 279 - pAd->mpdu_blk_pool.mem = mem; 280 - 281 - if (mem == NULL) 282 - { 283 - DBGPRINT(RT_DEBUG_ERROR, ("Can't Allocate Memory for BA Reordering\n")); 284 - return(FALSE); 285 - } 286 - 287 - /* build mpdu_blk free list */ 288 - for (i=0; i<num; i++) 289 - { 290 - /* get mpdu_blk */ 291 - mpdu_blk = (struct reordering_mpdu *) mem; 292 - /* initial mpdu_blk */ 293 - NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); 294 - /* next mpdu_blk */ 295 - mem += sizeof(struct reordering_mpdu); 296 - /* insert mpdu_blk into freelist */ 297 - ba_enqueue(freelist, mpdu_blk); 298 - } 299 - 300 - return(TRUE); 301 - } 302 - 303 - //static int blk_count=0; // sample take off, no use 304 - 305 - static struct reordering_mpdu *ba_mpdu_blk_alloc(PRTMP_ADAPTER pAd) 306 - { 307 - struct reordering_mpdu *mpdu_blk; 308 - 309 - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); 310 - mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist); 311 - if (mpdu_blk) 312 - { 313 - // blk_count++; 314 - /* reset mpdu_blk */ 315 - NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); 316 - } 317 - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); 318 - return mpdu_blk; 319 - } 320 - 321 - static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk) 322 - { 323 - ASSERT(mpdu_blk); 324 - 325 - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); 326 - // blk_count--; 327 - ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk); 328 - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); 329 - } 330 - 331 - 332 - static USHORT ba_indicate_reordering_mpdus_in_order( 333 - IN PRTMP_ADAPTER pAd, 334 - IN PBA_REC_ENTRY pBAEntry, 335 - IN USHORT StartSeq) 336 - { 337 - struct reordering_mpdu *mpdu_blk; 338 - USHORT LastIndSeq = RESET_RCV_SEQ; 339 - 340 - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); 341 - 342 - while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) 343 - { 344 - /* find in-order frame */ 345 - if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ)) 346 - { 347 - break; 348 - } 349 - /* dequeue in-order frame from reodering list */ 350 - mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); 351 - /* pass this frame up */ 352 - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); 353 - /* move to next sequence */ 354 - StartSeq = mpdu_blk->Sequence; 355 - LastIndSeq = StartSeq; 356 - /* free mpdu_blk */ 357 - ba_mpdu_blk_free(pAd, mpdu_blk); 358 - } 359 - 360 - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); 361 - 362 - /* update last indicated sequence */ 363 - return LastIndSeq; 364 - } 365 - 366 - static void ba_indicate_reordering_mpdus_le_seq( 367 - IN PRTMP_ADAPTER pAd, 368 - IN PBA_REC_ENTRY pBAEntry, 369 - IN USHORT Sequence) 370 - { 371 - struct reordering_mpdu *mpdu_blk; 372 - 373 - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); 374 - while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) 375 - { 376 - /* find in-order frame */ 377 - if ((mpdu_blk->Sequence == Sequence) || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ)) 378 - { 379 - /* dequeue in-order frame from reodering list */ 380 - mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); 381 - /* pass this frame up */ 382 - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); 383 - /* free mpdu_blk */ 384 - ba_mpdu_blk_free(pAd, mpdu_blk); 385 - } 386 - else 387 - { 388 - break; 389 - } 390 - } 391 - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); 392 - } 393 - 394 - 395 - static void ba_refresh_reordering_mpdus( 396 - IN PRTMP_ADAPTER pAd, 397 - PBA_REC_ENTRY pBAEntry) 398 - { 399 - struct reordering_mpdu *mpdu_blk; 400 - 401 - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); 402 - 403 - /* dequeue in-order frame from reodering list */ 404 - while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) 405 - { 406 - /* pass this frame up */ 407 - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); 408 - 409 - pBAEntry->LastIndSeq = mpdu_blk->Sequence; 410 - ba_mpdu_blk_free(pAd, mpdu_blk); 411 - 412 - /* update last indicated sequence */ 413 - } 414 - ASSERT(pBAEntry->list.qlen == 0); 415 - pBAEntry->LastIndSeq = RESET_RCV_SEQ; 416 - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); 417 - } 418 - 419 - 420 - //static 421 - void ba_flush_reordering_timeout_mpdus( 422 - IN PRTMP_ADAPTER pAd, 423 - IN PBA_REC_ENTRY pBAEntry, 424 - IN ULONG Now32) 425 - 426 - { 427 - USHORT Sequence; 428 - 429 - // if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) && 430 - // (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //|| 431 - // (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) && 432 - // (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8))) 433 - if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(MAX_REORDERING_PACKET_TIMEOUT/6))) 434 - &&(pBAEntry->list.qlen > 1) 435 - ) 436 - { 437 - DBGPRINT(RT_DEBUG_TRACE,("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer), 438 - (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), MAX_REORDERING_PACKET_TIMEOUT, 439 - pBAEntry->LastIndSeq)); 440 - ba_refresh_reordering_mpdus(pAd, pBAEntry); 441 - pBAEntry->LastIndSeqAtTimer = Now32; 442 - } 443 - else 444 - if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT))) 445 - && (pBAEntry->list.qlen > 0) 446 - ) 447 - { 448 - // 449 - // force LastIndSeq to shift to LastIndSeq+1 450 - // 451 - Sequence = (pBAEntry->LastIndSeq+1) & MAXSEQ; 452 - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); 453 - pBAEntry->LastIndSeqAtTimer = Now32; 454 - pBAEntry->LastIndSeq = Sequence; 455 - // 456 - // indicate in-order mpdus 457 - // 458 - Sequence = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, Sequence); 459 - if (Sequence != RESET_RCV_SEQ) 460 - { 461 - pBAEntry->LastIndSeq = Sequence; 462 - } 463 - 464 - } 465 - } 466 - 467 - 468 - /* 469 - * generate ADDBA request to 470 - * set up BA agreement 471 - */ 472 - VOID BAOriSessionSetUp( 473 - IN PRTMP_ADAPTER pAd, 474 - IN MAC_TABLE_ENTRY *pEntry, 475 - IN UCHAR TID, 476 - IN USHORT TimeOut, 477 - IN ULONG DelayTime, 478 - IN BOOLEAN isForced) 479 - 480 - { 481 - //MLME_ADDBA_REQ_STRUCT AddbaReq; 482 - BA_ORI_ENTRY *pBAEntry = NULL; 483 - USHORT Idx; 484 - BOOLEAN Cancelled; 485 - 486 - if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE) && (isForced == FALSE)) 487 - return; 488 - 489 - // if this entry is limited to use legacy tx mode, it doesn't generate BA. 490 - if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT) 491 - return; 492 - 493 - if ((pEntry->BADeclineBitmap & (1<<TID)) && (isForced == FALSE)) 494 - { 495 - // try again after 3 secs 496 - DelayTime = 3000; 497 - // printk("DeCline BA from Peer\n"); 498 - // return; 499 - } 500 - 501 - 502 - Idx = pEntry->BAOriWcidArray[TID]; 503 - if (Idx == 0) 504 - { 505 - // allocate a BA session 506 - pBAEntry = BATableAllocOriEntry(pAd, &Idx); 507 - if (pBAEntry == NULL) 508 - { 509 - DBGPRINT(RT_DEBUG_TRACE,("ADDBA - MlmeADDBAAction() allocate BA session failed \n")); 510 - return; 511 - } 512 - } 513 - else 514 - { 515 - pBAEntry =&pAd->BATable.BAOriEntry[Idx]; 516 - } 517 - 518 - if (pBAEntry->ORI_BA_Status >= Originator_WaitRes) 519 - { 520 - return; 521 - } 522 - 523 - pEntry->BAOriWcidArray[TID] = Idx; 524 - 525 - // Initialize BA session 526 - pBAEntry->ORI_BA_Status = Originator_WaitRes; 527 - pBAEntry->Wcid = pEntry->Aid; 528 - pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit; 529 - pBAEntry->Sequence = BA_ORI_INIT_SEQ; 530 - pBAEntry->Token = 1; // (2008-01-21) Jan Lee recommends it - this token can't be 0 531 - pBAEntry->TID = TID; 532 - pBAEntry->TimeOutValue = TimeOut; 533 - pBAEntry->pAdapter = pAd; 534 - 535 - #ifdef RT30xx 536 - DBGPRINT(RT_DEBUG_TRACE,("Send AddBA to %02x:%02x:%02x:%02x:%02x:%02x Tid:%d isForced:%d Wcid:%d\n" 537 - ,pEntry->Addr[0],pEntry->Addr[1],pEntry->Addr[2] 538 - ,pEntry->Addr[3],pEntry->Addr[4],pEntry->Addr[5] 539 - ,TID,isForced,pEntry->Aid)); 540 - #endif 541 - 542 - if (!(pEntry->TXBAbitmap & (1<<TID))) 543 - { 544 - RTMPInitTimer(pAd, &pBAEntry->ORIBATimer, GET_TIMER_FUNCTION(BAOriSessionSetupTimeout), pBAEntry, FALSE); 545 - } 546 - else 547 - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); 548 - 549 - // set timer to send ADDBA request 550 - RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime); 551 - } 552 - 553 - VOID BAOriSessionAdd( 554 - IN PRTMP_ADAPTER pAd, 555 - IN MAC_TABLE_ENTRY *pEntry, 556 - IN PFRAME_ADDBA_RSP pFrame) 557 - { 558 - BA_ORI_ENTRY *pBAEntry = NULL; 559 - BOOLEAN Cancelled; 560 - UCHAR TID; 561 - USHORT Idx; 562 - PUCHAR pOutBuffer2 = NULL; 563 - NDIS_STATUS NStatus; 564 - ULONG FrameLen; 565 - FRAME_BAR FrameBar; 566 - 567 - TID = pFrame->BaParm.TID; 568 - Idx = pEntry->BAOriWcidArray[TID]; 569 - pBAEntry =&pAd->BATable.BAOriEntry[Idx]; 570 - 571 - // Start fill in parameters. 572 - if ((Idx !=0) && (pBAEntry->TID == TID) && (pBAEntry->ORI_BA_Status == Originator_WaitRes)) 573 - { 574 - pBAEntry->BAWinSize = min(pBAEntry->BAWinSize, ((UCHAR)pFrame->BaParm.BufSize)); 575 - BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize); 576 - 577 - pBAEntry->TimeOutValue = pFrame->TimeOutValue; 578 - pBAEntry->ORI_BA_Status = Originator_Done; 579 - // reset sequence number 580 - pBAEntry->Sequence = BA_ORI_INIT_SEQ; 581 - // Set Bitmap flag. 582 - pEntry->TXBAbitmap |= (1<<TID); 583 - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); 584 - 585 - pBAEntry->ORIBATimer.TimerValue = 0; //pFrame->TimeOutValue; 586 - 587 - DBGPRINT(RT_DEBUG_TRACE,("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n", __func__, pEntry->TXBAbitmap, 588 - pBAEntry->BAWinSize, pBAEntry->ORIBATimer.TimerValue)); 589 - 590 - // SEND BAR ; 591 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory 592 - if (NStatus != NDIS_STATUS_SUCCESS) 593 - { 594 - DBGPRINT(RT_DEBUG_TRACE,("BA - BAOriSessionAdd() allocate memory failed \n")); 595 - return; 596 - } 597 - 598 - BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pBAEntry->Wcid].Addr, pAd->CurrentAddress); 599 - 600 - FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function. 601 - FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; // make sure sequence not clear in DEL funciton. 602 - FrameBar.BarControl.TID = pBAEntry->TID; // make sure sequence not clear in DEL funciton. 603 - MakeOutgoingFrame(pOutBuffer2, &FrameLen, 604 - sizeof(FRAME_BAR), &FrameBar, 605 - END_OF_ARGS); 606 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen); 607 - MlmeFreeMemory(pAd, pOutBuffer2); 608 - 609 - 610 - if (pBAEntry->ORIBATimer.TimerValue) 611 - RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); // in mSec 612 - } 613 - } 614 - 615 - BOOLEAN BARecSessionAdd( 616 - IN PRTMP_ADAPTER pAd, 617 - IN MAC_TABLE_ENTRY *pEntry, 618 - IN PFRAME_ADDBA_REQ pFrame) 619 - { 620 - BA_REC_ENTRY *pBAEntry = NULL; 621 - BOOLEAN Status = TRUE; 622 - BOOLEAN Cancelled; 623 - USHORT Idx; 624 - UCHAR TID; 625 - UCHAR BAWinSize; 626 - //UINT32 Value; 627 - //UINT offset; 628 - 629 - 630 - ASSERT(pEntry); 631 - 632 - // find TID 633 - TID = pFrame->BaParm.TID; 634 - 635 - BAWinSize = min(((UCHAR)pFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit); 636 - 637 - // Intel patch 638 - if (BAWinSize == 0) 639 - { 640 - BAWinSize = 64; 641 - } 642 - 643 - Idx = pEntry->BARecWcidArray[TID]; 644 - 645 - 646 - if (Idx == 0) 647 - { 648 - pBAEntry = BATableAllocRecEntry(pAd, &Idx); 649 - } 650 - else 651 - { 652 - pBAEntry = &pAd->BATable.BARecEntry[Idx]; 653 - // flush all pending reordering mpdus 654 - ba_refresh_reordering_mpdus(pAd, pBAEntry); 655 - } 656 - 657 - DBGPRINT(RT_DEBUG_TRACE,("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __func__, pAd->BATable.numAsRecipient, Idx, 658 - pFrame->BaParm.BufSize, BAWinSize)); 659 - 660 - // Start fill in parameters. 661 - if (pBAEntry != NULL) 662 - { 663 - ASSERT(pBAEntry->list.qlen == 0); 664 - 665 - pBAEntry->REC_BA_Status = Recipient_HandleRes; 666 - pBAEntry->BAWinSize = BAWinSize; 667 - pBAEntry->Wcid = pEntry->Aid; 668 - pBAEntry->TID = TID; 669 - pBAEntry->TimeOutValue = pFrame->TimeOutValue; 670 - pBAEntry->REC_BA_Status = Recipient_Accept; 671 - // initial sequence number 672 - pBAEntry->LastIndSeq = RESET_RCV_SEQ; //pFrame->BaStartSeq.field.StartSeq; 673 - 674 - printk("Start Seq = %08x\n", pFrame->BaStartSeq.field.StartSeq); 675 - 676 - if (pEntry->RXBAbitmap & (1<<TID)) 677 - { 678 - RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); 679 - } 680 - else 681 - { 682 - RTMPInitTimer(pAd, &pBAEntry->RECBATimer, GET_TIMER_FUNCTION(BARecSessionIdleTimeout), pBAEntry, TRUE); 683 - } 684 - 685 - // Set Bitmap flag. 686 - pEntry->RXBAbitmap |= (1<<TID); 687 - pEntry->BARecWcidArray[TID] = Idx; 688 - 689 - pEntry->BADeclineBitmap &= ~(1<<TID); 690 - 691 - // Set BA session mask in WCID table. 692 - RT28XX_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID); 693 - 694 - DBGPRINT(RT_DEBUG_TRACE,("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n", 695 - pEntry->Aid, pEntry->RXBAbitmap, pEntry->BARecWcidArray[TID])); 696 - } 697 - else 698 - { 699 - Status = FALSE; 700 - DBGPRINT(RT_DEBUG_TRACE,("Can't Accept ADDBA for %02x:%02x:%02x:%02x:%02x:%02x TID = %d\n", 701 - PRINT_MAC(pEntry->Addr), TID)); 702 - } 703 - return(Status); 704 - } 705 - 706 - 707 - BA_REC_ENTRY *BATableAllocRecEntry( 708 - IN PRTMP_ADAPTER pAd, 709 - OUT USHORT *Idx) 710 - { 711 - int i; 712 - BA_REC_ENTRY *pBAEntry = NULL; 713 - 714 - 715 - NdisAcquireSpinLock(&pAd->BATabLock); 716 - 717 - if (pAd->BATable.numAsRecipient >= MAX_BARECI_SESSION) 718 - { 719 - printk("BA Recipeint Session (%ld) > %d\n", pAd->BATable.numAsRecipient, 720 - MAX_BARECI_SESSION); 721 - goto done; 722 - } 723 - 724 - // reserve idx 0 to identify BAWcidArray[TID] as empty 725 - for (i=1; i < MAX_LEN_OF_BA_REC_TABLE; i++) 726 - { 727 - pBAEntry =&pAd->BATable.BARecEntry[i]; 728 - if ((pBAEntry->REC_BA_Status == Recipient_NONE)) 729 - { 730 - // get one 731 - pAd->BATable.numAsRecipient++; 732 - pBAEntry->REC_BA_Status = Recipient_USED; 733 - *Idx = i; 734 - break; 735 - } 736 - } 737 - 738 - done: 739 - NdisReleaseSpinLock(&pAd->BATabLock); 740 - return pBAEntry; 741 - } 742 - 743 - BA_ORI_ENTRY *BATableAllocOriEntry( 744 - IN PRTMP_ADAPTER pAd, 745 - OUT USHORT *Idx) 746 - { 747 - int i; 748 - BA_ORI_ENTRY *pBAEntry = NULL; 749 - 750 - NdisAcquireSpinLock(&pAd->BATabLock); 751 - 752 - if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE)) 753 - { 754 - goto done; 755 - } 756 - 757 - // reserve idx 0 to identify BAWcidArray[TID] as empty 758 - for (i=1; i<MAX_LEN_OF_BA_ORI_TABLE; i++) 759 - { 760 - pBAEntry =&pAd->BATable.BAOriEntry[i]; 761 - if ((pBAEntry->ORI_BA_Status == Originator_NONE)) 762 - { 763 - // get one 764 - pAd->BATable.numAsOriginator++; 765 - pBAEntry->ORI_BA_Status = Originator_USED; 766 - pBAEntry->pAdapter = pAd; 767 - *Idx = i; 768 - break; 769 - } 770 - } 771 - 772 - done: 773 - NdisReleaseSpinLock(&pAd->BATabLock); 774 - return pBAEntry; 775 - } 776 - 777 - 778 - VOID BATableFreeOriEntry( 779 - IN PRTMP_ADAPTER pAd, 780 - IN ULONG Idx) 781 - { 782 - BA_ORI_ENTRY *pBAEntry = NULL; 783 - MAC_TABLE_ENTRY *pEntry; 784 - 785 - 786 - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) 787 - return; 788 - 789 - pBAEntry =&pAd->BATable.BAOriEntry[Idx]; 790 - 791 - if (pBAEntry->ORI_BA_Status != Originator_NONE) 792 - { 793 - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; 794 - pEntry->BAOriWcidArray[pBAEntry->TID] = 0; 795 - 796 - 797 - NdisAcquireSpinLock(&pAd->BATabLock); 798 - if (pBAEntry->ORI_BA_Status == Originator_Done) 799 - { 800 - pEntry->TXBAbitmap &= (~(1<<(pBAEntry->TID) )); 801 - DBGPRINT(RT_DEBUG_TRACE, ("BATableFreeOriEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient)); 802 - // Erase Bitmap flag. 803 - } 804 - 805 - ASSERT(pAd->BATable.numAsOriginator != 0); 806 - 807 - pAd->BATable.numAsOriginator -= 1; 808 - 809 - pBAEntry->ORI_BA_Status = Originator_NONE; 810 - pBAEntry->Token = 0; 811 - NdisReleaseSpinLock(&pAd->BATabLock); 812 - } 813 - } 814 - 815 - 816 - VOID BATableFreeRecEntry( 817 - IN PRTMP_ADAPTER pAd, 818 - IN ULONG Idx) 819 - { 820 - BA_REC_ENTRY *pBAEntry = NULL; 821 - MAC_TABLE_ENTRY *pEntry; 822 - 823 - 824 - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE)) 825 - return; 826 - 827 - pBAEntry =&pAd->BATable.BARecEntry[Idx]; 828 - 829 - if (pBAEntry->REC_BA_Status != Recipient_NONE) 830 - { 831 - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; 832 - pEntry->BARecWcidArray[pBAEntry->TID] = 0; 833 - 834 - NdisAcquireSpinLock(&pAd->BATabLock); 835 - 836 - ASSERT(pAd->BATable.numAsRecipient != 0); 837 - 838 - pAd->BATable.numAsRecipient -= 1; 839 - 840 - pBAEntry->REC_BA_Status = Recipient_NONE; 841 - NdisReleaseSpinLock(&pAd->BATabLock); 842 - } 843 - } 844 - 845 - 846 - VOID BAOriSessionTearDown( 847 - IN OUT PRTMP_ADAPTER pAd, 848 - IN UCHAR Wcid, 849 - IN UCHAR TID, 850 - IN BOOLEAN bPassive, 851 - IN BOOLEAN bForceSend) 852 - { 853 - ULONG Idx = 0; 854 - BA_ORI_ENTRY *pBAEntry; 855 - BOOLEAN Cancelled; 856 - 857 - if (Wcid >= MAX_LEN_OF_MAC_TABLE) 858 - { 859 - return; 860 - } 861 - 862 - // 863 - // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). 864 - // 865 - Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID]; 866 - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) 867 - { 868 - if (bForceSend == TRUE) 869 - { 870 - // force send specified TID DelBA 871 - MLME_DELBA_REQ_STRUCT DelbaReq; 872 - MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); 873 - 874 - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 875 - NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); 876 - 877 - COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); 878 - DelbaReq.Wcid = Wcid; 879 - DelbaReq.TID = TID; 880 - DelbaReq.Initiator = ORIGINATOR; 881 - #if 1 882 - Elem->MsgLen = sizeof(DelbaReq); 883 - NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); 884 - MlmeDELBAAction(pAd, Elem); 885 - kfree(Elem); 886 - #else 887 - MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq); 888 - RT28XX_MLME_HANDLER(pAd); 889 - #endif 890 - } 891 - 892 - return; 893 - } 894 - 895 - DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID)); 896 - 897 - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; 898 - DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->ORI_BA_Status)); 899 - // 900 - // Prepare DelBA action frame and send to the peer. 901 - // 902 - if ((bPassive == FALSE) && (TID == pBAEntry->TID) && (pBAEntry->ORI_BA_Status == Originator_Done)) 903 - { 904 - MLME_DELBA_REQ_STRUCT DelbaReq; 905 - MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); 906 - 907 - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 908 - NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); 909 - 910 - COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); 911 - DelbaReq.Wcid = Wcid; 912 - DelbaReq.TID = pBAEntry->TID; 913 - DelbaReq.Initiator = ORIGINATOR; 914 - #if 1 915 - Elem->MsgLen = sizeof(DelbaReq); 916 - NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); 917 - MlmeDELBAAction(pAd, Elem); 918 - kfree(Elem); 919 - #else 920 - MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq); 921 - RT28XX_MLME_HANDLER(pAd); 922 - #endif 923 - } 924 - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); 925 - BATableFreeOriEntry(pAd, Idx); 926 - 927 - if (bPassive) 928 - { 929 - //BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE); 930 - } 931 - } 932 - 933 - VOID BARecSessionTearDown( 934 - IN OUT PRTMP_ADAPTER pAd, 935 - IN UCHAR Wcid, 936 - IN UCHAR TID, 937 - IN BOOLEAN bPassive) 938 - { 939 - ULONG Idx = 0; 940 - BA_REC_ENTRY *pBAEntry; 941 - 942 - if (Wcid >= MAX_LEN_OF_MAC_TABLE) 943 - { 944 - return; 945 - } 946 - 947 - // 948 - // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). 949 - // 950 - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; 951 - if (Idx == 0) 952 - return; 953 - 954 - DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID)); 955 - 956 - 957 - pBAEntry = &pAd->BATable.BARecEntry[Idx]; 958 - DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->REC_BA_Status)); 959 - // 960 - // Prepare DelBA action frame and send to the peer. 961 - // 962 - if ((TID == pBAEntry->TID) && (pBAEntry->REC_BA_Status == Recipient_Accept)) 963 - { 964 - MLME_DELBA_REQ_STRUCT DelbaReq; 965 - BOOLEAN Cancelled; 966 - MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); 967 - //ULONG offset; 968 - //UINT32 VALUE; 969 - 970 - RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); 971 - 972 - // 973 - // 1. Send DELBA Action Frame 974 - // 975 - if (bPassive == FALSE) 976 - { 977 - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 978 - NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); 979 - 980 - COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); 981 - DelbaReq.Wcid = Wcid; 982 - DelbaReq.TID = TID; 983 - DelbaReq.Initiator = RECIPIENT; 984 - #if 1 985 - Elem->MsgLen = sizeof(DelbaReq); 986 - NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); 987 - MlmeDELBAAction(pAd, Elem); 988 - kfree(Elem); 989 - #else 990 - MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ORI_DELBA_CATE, sizeof(MLME_DELBA_REQ_STRUCT), (PVOID)&DelbaReq); 991 - RT28XX_MLME_HANDLER(pAd); 992 - #endif 993 - } 994 - 995 - 996 - // 997 - // 2. Free resource of BA session 998 - // 999 - // flush all pending reordering mpdus 1000 - ba_refresh_reordering_mpdus(pAd, pBAEntry); 1001 - 1002 - NdisAcquireSpinLock(&pAd->BATabLock); 1003 - 1004 - // Erase Bitmap flag. 1005 - pBAEntry->LastIndSeq = RESET_RCV_SEQ; 1006 - pBAEntry->BAWinSize = 0; 1007 - // Erase Bitmap flag at software mactable 1008 - pAd->MacTab.Content[Wcid].RXBAbitmap &= (~(1<<(pBAEntry->TID))); 1009 - pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0; 1010 - 1011 - RT28XX_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID); 1012 - 1013 - NdisReleaseSpinLock(&pAd->BATabLock); 1014 - 1015 - } 1016 - 1017 - BATableFreeRecEntry(pAd, Idx); 1018 - } 1019 - 1020 - VOID BASessionTearDownALL( 1021 - IN OUT PRTMP_ADAPTER pAd, 1022 - IN UCHAR Wcid) 1023 - { 1024 - int i; 1025 - 1026 - for (i=0; i<NUM_OF_TID; i++) 1027 - { 1028 - BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE); 1029 - BARecSessionTearDown(pAd, Wcid, i, FALSE); 1030 - } 1031 - } 1032 - 1033 - 1034 - /* 1035 - ========================================================================== 1036 - Description: 1037 - Retry sending ADDBA Reqest. 1038 - 1039 - IRQL = DISPATCH_LEVEL 1040 - 1041 - Parametrs: 1042 - p8023Header: if this is already 802.3 format, p8023Header is NULL 1043 - 1044 - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. 1045 - FALSE , then continue indicaterx at this moment. 1046 - ========================================================================== 1047 - */ 1048 - VOID BAOriSessionSetupTimeout( 1049 - IN PVOID SystemSpecific1, 1050 - IN PVOID FunctionContext, 1051 - IN PVOID SystemSpecific2, 1052 - IN PVOID SystemSpecific3) 1053 - { 1054 - BA_ORI_ENTRY *pBAEntry = (BA_ORI_ENTRY *)FunctionContext; 1055 - MAC_TABLE_ENTRY *pEntry; 1056 - PRTMP_ADAPTER pAd; 1057 - 1058 - if (pBAEntry == NULL) 1059 - return; 1060 - 1061 - pAd = pBAEntry->pAdapter; 1062 - 1063 - // Do nothing if monitor mode is on 1064 - if (MONITOR_ON(pAd)) 1065 - return; 1066 - 1067 - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; 1068 - 1069 - if ((pBAEntry->ORI_BA_Status == Originator_WaitRes) && (pBAEntry->Token < ORI_SESSION_MAX_RETRY)) 1070 - { 1071 - MLME_ADDBA_REQ_STRUCT AddbaReq; 1072 - 1073 - NdisZeroMemory(&AddbaReq, sizeof(AddbaReq)); 1074 - COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr); 1075 - AddbaReq.Wcid = (UCHAR)(pEntry->Aid); 1076 - AddbaReq.TID = pBAEntry->TID; 1077 - AddbaReq.BaBufSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit; 1078 - AddbaReq.TimeOutValue = 0; 1079 - AddbaReq.Token = pBAEntry->Token; 1080 - MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE, sizeof(MLME_ADDBA_REQ_STRUCT), (PVOID)&AddbaReq); 1081 - RT28XX_MLME_HANDLER(pAd); 1082 - #ifndef RT30xx 1083 - DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) : Send ADD BA again\n", pBAEntry->Token)); 1084 - #endif 1085 - #ifdef RT30xx 1086 - DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) to %02x:%02x:%02x:%02x:%02x:%02x Tid:%d Wcid:%d\n" 1087 - ,pBAEntry->Token 1088 - ,pEntry->Addr[0],pEntry->Addr[1],pEntry->Addr[2] 1089 - ,pEntry->Addr[3],pEntry->Addr[4],pEntry->Addr[5] 1090 - ,pBAEntry->TID,pEntry->Aid)); 1091 - #endif 1092 - pBAEntry->Token++; 1093 - RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT); 1094 - } 1095 - else 1096 - { 1097 - BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]); 1098 - } 1099 - } 1100 - 1101 - /* 1102 - ========================================================================== 1103 - Description: 1104 - Retry sending ADDBA Reqest. 1105 - 1106 - IRQL = DISPATCH_LEVEL 1107 - 1108 - Parametrs: 1109 - p8023Header: if this is already 802.3 format, p8023Header is NULL 1110 - 1111 - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. 1112 - FALSE , then continue indicaterx at this moment. 1113 - ========================================================================== 1114 - */ 1115 - VOID BARecSessionIdleTimeout( 1116 - IN PVOID SystemSpecific1, 1117 - IN PVOID FunctionContext, 1118 - IN PVOID SystemSpecific2, 1119 - IN PVOID SystemSpecific3) 1120 - { 1121 - 1122 - BA_REC_ENTRY *pBAEntry = (BA_REC_ENTRY *)FunctionContext; 1123 - PRTMP_ADAPTER pAd; 1124 - ULONG Now32; 1125 - 1126 - if (pBAEntry == NULL) 1127 - return; 1128 - 1129 - if ((pBAEntry->REC_BA_Status == Recipient_Accept)) 1130 - { 1131 - NdisGetSystemUpTime(&Now32); 1132 - 1133 - if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer + REC_BA_SESSION_IDLE_TIMEOUT))) 1134 - { 1135 - pAd = pBAEntry->pAdapter; 1136 - // flush all pending reordering mpdus 1137 - ba_refresh_reordering_mpdus(pAd, pBAEntry); 1138 - printk("%ld: REC BA session Timeout\n", Now32); 1139 - } 1140 - } 1141 - } 1142 - 1143 - 1144 - VOID PeerAddBAReqAction( 1145 - IN PRTMP_ADAPTER pAd, 1146 - IN MLME_QUEUE_ELEM *Elem) 1147 - 1148 - { 1149 - // 7.4.4.1 1150 - //ULONG Idx; 1151 - UCHAR Status = 1; 1152 - UCHAR pAddr[6]; 1153 - FRAME_ADDBA_RSP ADDframe; 1154 - PUCHAR pOutBuffer = NULL; 1155 - NDIS_STATUS NStatus; 1156 - PFRAME_ADDBA_REQ pAddreqFrame = NULL; 1157 - //UCHAR BufSize; 1158 - ULONG FrameLen; 1159 - PULONG ptemp; 1160 - PMAC_TABLE_ENTRY pMacEntry; 1161 - 1162 - DBGPRINT(RT_DEBUG_TRACE, ("%s ==> (Wcid = %d)\n", __func__, Elem->Wcid)); 1163 - 1164 - //hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen); 1165 - 1166 - //ADDBA Request from unknown peer, ignore this. 1167 - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) 1168 - return; 1169 - 1170 - pMacEntry = &pAd->MacTab.Content[Elem->Wcid]; 1171 - DBGPRINT(RT_DEBUG_TRACE,("BA - PeerAddBAReqAction----> \n")); 1172 - ptemp = (PULONG)Elem->Msg; 1173 - //DBGPRINT_RAW(RT_DEBUG_EMU, ("%08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x\n", *(ptemp), *(ptemp+1), *(ptemp+2), *(ptemp+3), *(ptemp+4), *(ptemp+5), *(ptemp+6), *(ptemp+7), *(ptemp+8))); 1174 - 1175 - if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr)) 1176 - { 1177 - 1178 - if ((pAd->CommonCfg.bBADecline == FALSE) && IS_HT_STA(pMacEntry)) 1179 - { 1180 - pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]); 1181 - printk("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid); 1182 - if (BARecSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pAddreqFrame)) 1183 - Status = 0; 1184 - else 1185 - Status = 38; // more parameters have invalid values 1186 - } 1187 - else 1188 - { 1189 - Status = 37; // the request has been declined. 1190 - } 1191 - } 1192 - 1193 - if (pAd->MacTab.Content[Elem->Wcid].ValidAsCLI) 1194 - ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC); 1195 - 1196 - pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]); 1197 - // 2. Always send back ADDBA Response 1198 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 1199 - if (NStatus != NDIS_STATUS_SUCCESS) 1200 - { 1201 - DBGPRINT(RT_DEBUG_TRACE,("ACTION - PeerBAAction() allocate memory failed \n")); 1202 - return; 1203 - } 1204 - 1205 - NdisZeroMemory(&ADDframe, sizeof(FRAME_ADDBA_RSP)); 1206 - 1207 - // 2-1. Prepare ADDBA Response frame. 1208 - { 1209 - if (ADHOC_ON(pAd)) 1210 - ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid); 1211 - else 1212 - ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr); 1213 - } 1214 - 1215 - ADDframe.Category = CATEGORY_BA; 1216 - ADDframe.Action = ADDBA_RESP; 1217 - ADDframe.Token = pAddreqFrame->Token; 1218 - // What is the Status code?? need to check. 1219 - ADDframe.StatusCode = Status; 1220 - ADDframe.BaParm.BAPolicy = IMMED_BA; 1221 - ADDframe.BaParm.AMSDUSupported = 0; 1222 - ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID; 1223 - ADDframe.BaParm.BufSize = min(((UCHAR)pAddreqFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit); 1224 - if (ADDframe.BaParm.BufSize == 0) 1225 - { 1226 - ADDframe.BaParm.BufSize = 64; 1227 - } 1228 - ADDframe.TimeOutValue = 0; //pAddreqFrame->TimeOutValue; 1229 - 1230 - *(USHORT *)(&ADDframe.BaParm) = cpu2le16(*(USHORT *)(&ADDframe.BaParm)); 1231 - ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode); 1232 - ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue); 1233 - 1234 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 1235 - sizeof(FRAME_ADDBA_RSP), &ADDframe, 1236 - END_OF_ARGS); 1237 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 1238 - MlmeFreeMemory(pAd, pOutBuffer); 1239 - 1240 - DBGPRINT(RT_DEBUG_TRACE, ("%s(%d): TID(%d), BufSize(%d) <== \n", __func__, Elem->Wcid, ADDframe.BaParm.TID, 1241 - ADDframe.BaParm.BufSize)); 1242 - } 1243 - 1244 - 1245 - VOID PeerAddBARspAction( 1246 - IN PRTMP_ADAPTER pAd, 1247 - IN MLME_QUEUE_ELEM *Elem) 1248 - 1249 - { 1250 - //UCHAR Idx, i; 1251 - //PUCHAR pOutBuffer = NULL; 1252 - PFRAME_ADDBA_RSP pFrame = NULL; 1253 - //PBA_ORI_ENTRY pBAEntry; 1254 - 1255 - //ADDBA Response from unknown peer, ignore this. 1256 - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) 1257 - return; 1258 - 1259 - DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __func__, Elem->Wcid)); 1260 - 1261 - //hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen); 1262 - 1263 - if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen)) 1264 - { 1265 - pFrame = (PFRAME_ADDBA_RSP)(&Elem->Msg[0]); 1266 - 1267 - DBGPRINT(RT_DEBUG_TRACE, ("\t\t StatusCode = %d\n", pFrame->StatusCode)); 1268 - switch (pFrame->StatusCode) 1269 - { 1270 - case 0: 1271 - // I want a BAsession with this peer as an originator. 1272 - BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pFrame); 1273 - break; 1274 - default: 1275 - // check status == USED ??? 1276 - BAOriSessionTearDown(pAd, Elem->Wcid, pFrame->BaParm.TID, TRUE, FALSE); 1277 - break; 1278 - } 1279 - // Rcv Decline StatusCode 1280 - if ((pFrame->StatusCode == 37) 1281 - || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd) && (pFrame->StatusCode != 0)) 1282 - ) 1283 - { 1284 - pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |= 1<<pFrame->BaParm.TID; 1285 - } 1286 - } 1287 - } 1288 - 1289 - VOID PeerDelBAAction( 1290 - IN PRTMP_ADAPTER pAd, 1291 - IN MLME_QUEUE_ELEM *Elem) 1292 - 1293 - { 1294 - //UCHAR Idx; 1295 - //PUCHAR pOutBuffer = NULL; 1296 - PFRAME_DELBA_REQ pDelFrame = NULL; 1297 - 1298 - DBGPRINT(RT_DEBUG_TRACE,("%s ==>\n", __func__)); 1299 - //DELBA Request from unknown peer, ignore this. 1300 - if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen)) 1301 - { 1302 - pDelFrame = (PFRAME_DELBA_REQ)(&Elem->Msg[0]); 1303 - if (pDelFrame->DelbaParm.Initiator == ORIGINATOR) 1304 - { 1305 - DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> ORIGINATOR\n")); 1306 - BARecSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE); 1307 - } 1308 - else 1309 - { 1310 - DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n", pDelFrame->ReasonCode)); 1311 - //hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen); 1312 - BAOriSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE, FALSE); 1313 - } 1314 - } 1315 - } 1316 - 1317 - 1318 - BOOLEAN CntlEnqueueForRecv( 1319 - IN PRTMP_ADAPTER pAd, 1320 - IN ULONG Wcid, 1321 - IN ULONG MsgLen, 1322 - IN PFRAME_BA_REQ pMsg) 1323 - { 1324 - PFRAME_BA_REQ pFrame = pMsg; 1325 - //PRTMP_REORDERBUF pBuffer; 1326 - //PRTMP_REORDERBUF pDmaBuf; 1327 - PBA_REC_ENTRY pBAEntry; 1328 - //BOOLEAN Result; 1329 - ULONG Idx; 1330 - //UCHAR NumRxPkt; 1331 - UCHAR TID;//, i; 1332 - 1333 - TID = (UCHAR)pFrame->BARControl.TID; 1334 - 1335 - DBGPRINT(RT_DEBUG_TRACE, ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __func__, Wcid, TID)); 1336 - //hex_dump("BAR", (PCHAR) pFrame, MsgLen); 1337 - // Do nothing if the driver is starting halt state. 1338 - // This might happen when timer already been fired before cancel timer with mlmehalt 1339 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) 1340 - return FALSE; 1341 - 1342 - // First check the size, it MUST not exceed the mlme queue size 1343 - if (MsgLen > MGMT_DMA_BUFFER_SIZE) 1344 - { 1345 - DBGPRINT_ERR(("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen)); 1346 - return FALSE; 1347 - } 1348 - else if (MsgLen != sizeof(FRAME_BA_REQ)) 1349 - { 1350 - DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); 1351 - return FALSE; 1352 - } 1353 - else if (MsgLen != sizeof(FRAME_BA_REQ)) 1354 - { 1355 - DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); 1356 - return FALSE; 1357 - } 1358 - 1359 - if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8)) 1360 - { 1361 - // if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search. 1362 - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; 1363 - pBAEntry = &pAd->BATable.BARecEntry[Idx]; 1364 - } 1365 - else 1366 - { 1367 - return FALSE; 1368 - } 1369 - 1370 - DBGPRINT(RT_DEBUG_TRACE, ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID, pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq )); 1371 - 1372 - if (SEQ_SMALLER(pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq, MAXSEQ)) 1373 - { 1374 - //printk("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq); 1375 - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, pFrame->BAStartingSeq.field.StartSeq); 1376 - pBAEntry->LastIndSeq = (pFrame->BAStartingSeq.field.StartSeq == 0) ? MAXSEQ :(pFrame->BAStartingSeq.field.StartSeq -1); 1377 - } 1378 - //ba_refresh_reordering_mpdus(pAd, pBAEntry); 1379 - return TRUE; 1380 - } 1381 - 1382 - /* 1383 - Description : Send PSMP Action frame If PSMP mode switches. 1384 - */ 1385 - VOID SendPSMPAction( 1386 - IN PRTMP_ADAPTER pAd, 1387 - IN UCHAR Wcid, 1388 - IN UCHAR Psmp) 1389 - { 1390 - PUCHAR pOutBuffer = NULL; 1391 - NDIS_STATUS NStatus; 1392 - //ULONG Idx; 1393 - FRAME_PSMP_ACTION Frame; 1394 - ULONG FrameLen; 1395 - #ifdef RT30xx 1396 - UCHAR bbpdata=0; 1397 - UINT32 macdata; 1398 - #endif // RT30xx // 1399 - 1400 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 1401 - if (NStatus != NDIS_STATUS_SUCCESS) 1402 - { 1403 - DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n")); 1404 - return; 1405 - } 1406 - 1407 - ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr); 1408 - 1409 - Frame.Category = CATEGORY_HT; 1410 - Frame.Action = SMPS_ACTION; 1411 - switch (Psmp) 1412 - { 1413 - case MMPS_ENABLE: 1414 - #ifdef RT30xx 1415 - if (IS_RT3090(pAd)) 1416 - { 1417 - // disable MMPS BBP control register 1418 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata); 1419 - bbpdata &= ~(0x04); //bit 2 1420 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata); 1421 - 1422 - // disable MMPS MAC control register 1423 - RTMP_IO_READ32(pAd, 0x1210, &macdata); 1424 - macdata &= ~(0x09); //bit 0, 3 1425 - RTMP_IO_WRITE32(pAd, 0x1210, macdata); 1426 - } 1427 - #endif // RT30xx // 1428 - Frame.Psmp = 0; 1429 - break; 1430 - case MMPS_DYNAMIC: 1431 - #ifdef RT30xx 1432 - if (IS_RT3090(pAd)) 1433 - { 1434 - // enable MMPS BBP control register 1435 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata); 1436 - bbpdata |= 0x04; //bit 2 1437 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata); 1438 - 1439 - // enable MMPS MAC control register 1440 - RTMP_IO_READ32(pAd, 0x1210, &macdata); 1441 - macdata |= 0x09; //bit 0, 3 1442 - RTMP_IO_WRITE32(pAd, 0x1210, macdata); 1443 - } 1444 - #endif // RT30xx // 1445 - Frame.Psmp = 3; 1446 - break; 1447 - case MMPS_STATIC: 1448 - #ifdef RT30xx 1449 - if (IS_RT3090(pAd)) 1450 - { 1451 - // enable MMPS BBP control register 1452 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &bbpdata); 1453 - bbpdata |= 0x04; //bit 2 1454 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, bbpdata); 1455 - 1456 - // enable MMPS MAC control register 1457 - RTMP_IO_READ32(pAd, 0x1210, &macdata); 1458 - macdata |= 0x09; //bit 0, 3 1459 - RTMP_IO_WRITE32(pAd, 0x1210, macdata); 1460 - } 1461 - #endif // RT30xx // 1462 - Frame.Psmp = 1; 1463 - break; 1464 - } 1465 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 1466 - sizeof(FRAME_PSMP_ACTION), &Frame, 1467 - END_OF_ARGS); 1468 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 1469 - MlmeFreeMemory(pAd, pOutBuffer); 1470 - DBGPRINT(RT_DEBUG_ERROR,("HT - SendPSMPAction( %d ) \n", Frame.Psmp)); 1471 - } 1472 - 1473 - 1474 - #define RADIO_MEASUREMENT_REQUEST_ACTION 0 1475 - 1476 - typedef struct PACKED 1477 - { 1478 - UCHAR RegulatoryClass; 1479 - UCHAR ChannelNumber; 1480 - USHORT RandomInterval; 1481 - USHORT MeasurementDuration; 1482 - UCHAR MeasurementMode; 1483 - UCHAR BSSID[MAC_ADDR_LEN]; 1484 - UCHAR ReportingCondition; 1485 - UCHAR Threshold; 1486 - UCHAR SSIDIE[2]; // 2 byte 1487 - } BEACON_REQUEST; 1488 - 1489 - typedef struct PACKED 1490 - { 1491 - UCHAR ID; 1492 - UCHAR Length; 1493 - UCHAR Token; 1494 - UCHAR RequestMode; 1495 - UCHAR Type; 1496 - } MEASUREMENT_REQ; 1497 - 1498 - 1499 - 1500 - 1501 - void convert_reordering_packet_to_preAMSDU_or_802_3_packet( 1502 - IN PRTMP_ADAPTER pAd, 1503 - IN RX_BLK *pRxBlk, 1504 - IN UCHAR FromWhichBSSID) 1505 - { 1506 - PNDIS_PACKET pRxPkt; 1507 - UCHAR Header802_3[LENGTH_802_3]; 1508 - 1509 - // 1. get 802.3 Header 1510 - // 2. remove LLC 1511 - // a. pointer pRxBlk->pData to payload 1512 - // b. modify pRxBlk->DataSize 1513 - 1514 - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); 1515 - 1516 - ASSERT(pRxBlk->pRxPacket); 1517 - pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); 1518 - 1519 - RTPKT_TO_OSPKT(pRxPkt)->dev = get_netdev_from_bssid(pAd, FromWhichBSSID); 1520 - RTPKT_TO_OSPKT(pRxPkt)->data = pRxBlk->pData; 1521 - RTPKT_TO_OSPKT(pRxPkt)->len = pRxBlk->DataSize; 1522 - RTPKT_TO_OSPKT(pRxPkt)->tail = RTPKT_TO_OSPKT(pRxPkt)->data + RTPKT_TO_OSPKT(pRxPkt)->len; 1523 - 1524 - // 1525 - // copy 802.3 header, if necessary 1526 - // 1527 - if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) 1528 - { 1529 - #ifdef LINUX 1530 - NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3); 1531 - #endif 1532 - } 1533 - } 1534 - 1535 - 1536 - #define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \ 1537 - do \ 1538 - { \ 1539 - if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \ 1540 - { \ 1541 - Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ 1542 - } \ 1543 - else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \ 1544 - { \ 1545 - Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ 1546 - } \ 1547 - else \ 1548 - { \ 1549 - Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ 1550 - } \ 1551 - } while (0); 1552 - 1553 - 1554 - 1555 - static VOID ba_enqueue_reordering_packet( 1556 - IN PRTMP_ADAPTER pAd, 1557 - IN PBA_REC_ENTRY pBAEntry, 1558 - IN RX_BLK *pRxBlk, 1559 - IN UCHAR FromWhichBSSID) 1560 - { 1561 - struct reordering_mpdu *mpdu_blk; 1562 - UINT16 Sequence = (UINT16) pRxBlk->pHeader->Sequence; 1563 - 1564 - mpdu_blk = ba_mpdu_blk_alloc(pAd); 1565 - if (mpdu_blk != NULL) 1566 - { 1567 - // Write RxD buffer address & allocated buffer length 1568 - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); 1569 - 1570 - mpdu_blk->Sequence = Sequence; 1571 - 1572 - mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU); 1573 - 1574 - convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd, pRxBlk, FromWhichBSSID); 1575 - 1576 - STATS_INC_RX_PACKETS(pAd, FromWhichBSSID); 1577 - 1578 - // 1579 - // it is necessary for reordering packet to record 1580 - // which BSS it come from 1581 - // 1582 - RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID); 1583 - 1584 - mpdu_blk->pPacket = pRxBlk->pRxPacket; 1585 - 1586 - if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk) == FALSE) 1587 - { 1588 - // had been already within reordering list 1589 - // don't indicate 1590 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_SUCCESS); 1591 - ba_mpdu_blk_free(pAd, mpdu_blk); 1592 - } 1593 - 1594 - ASSERT((0<= pBAEntry->list.qlen) && (pBAEntry->list.qlen <= pBAEntry->BAWinSize)); 1595 - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); 1596 - } 1597 - else 1598 - { 1599 - DBGPRINT(RT_DEBUG_ERROR, ("!!! (%d) Can't allocate reordering mpdu blk\n", 1600 - pBAEntry->list.qlen)); 1601 - 1602 - /* 1603 - * flush all pending reordering mpdus 1604 - * and receving mpdu to upper layer 1605 - * make tcp/ip to take care reordering mechanism 1606 - */ 1607 - //ba_refresh_reordering_mpdus(pAd, pBAEntry); 1608 - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); 1609 - 1610 - pBAEntry->LastIndSeq = Sequence; 1611 - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); 1612 - } 1613 - } 1614 - 1615 - 1616 - /* 1617 - ========================================================================== 1618 - Description: 1619 - Indicate this packet to upper layer or put it into reordering buffer 1620 - 1621 - Parametrs: 1622 - pRxBlk : carry necessary packet info 802.11 format 1623 - FromWhichBSSID : the packet received from which BSS 1624 - 1625 - Return : 1626 - none 1627 - 1628 - Note : 1629 - the packet queued into reordering buffer need to cover to 802.3 format 1630 - or pre_AMSDU format 1631 - ========================================================================== 1632 - */ 1633 - 1634 - VOID Indicate_AMPDU_Packet( 1635 - IN PRTMP_ADAPTER pAd, 1636 - IN RX_BLK *pRxBlk, 1637 - IN UCHAR FromWhichBSSID) 1638 - { 1639 - USHORT Idx; 1640 - PBA_REC_ENTRY pBAEntry = NULL; 1641 - UINT16 Sequence = pRxBlk->pHeader->Sequence; 1642 - ULONG Now32; 1643 - UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID; 1644 - UCHAR TID = pRxBlk->pRxWI->TID; 1645 - 1646 - 1647 - if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU) && (pRxBlk->DataSize > MAX_RX_PKT_LEN)) 1648 - { 1649 - // release packet 1650 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 1651 - return; 1652 - } 1653 - 1654 - if (Wcid < MAX_LEN_OF_MAC_TABLE) 1655 - { 1656 - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; 1657 - if (Idx == 0) 1658 - { 1659 - /* Rec BA Session had been torn down */ 1660 - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); 1661 - return; 1662 - } 1663 - pBAEntry = &pAd->BATable.BARecEntry[Idx]; 1664 - } 1665 - else 1666 - { 1667 - // impossible !!! 1668 - ASSERT(0); 1669 - // release packet 1670 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 1671 - return; 1672 - } 1673 - 1674 - ASSERT(pBAEntry); 1675 - 1676 - // update last rx time 1677 - NdisGetSystemUpTime(&Now32); 1678 - 1679 - pBAEntry->rcvSeq = Sequence; 1680 - 1681 - 1682 - ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32); 1683 - pBAEntry->LastIndSeqAtTimer = Now32; 1684 - 1685 - // 1686 - // Reset Last Indicate Sequence 1687 - // 1688 - if (pBAEntry->LastIndSeq == RESET_RCV_SEQ) 1689 - { 1690 - ASSERT((pBAEntry->list.qlen == 0) && (pBAEntry->list.next == NULL)); 1691 - 1692 - // reset rcv sequence of BA session 1693 - pBAEntry->LastIndSeq = Sequence; 1694 - pBAEntry->LastIndSeqAtTimer = Now32; 1695 - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); 1696 - return; 1697 - } 1698 - 1699 - 1700 - // 1701 - // I. Check if in order. 1702 - // 1703 - if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) 1704 - { 1705 - USHORT LastIndSeq; 1706 - 1707 - pBAEntry->LastIndSeq = Sequence; 1708 - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); 1709 - LastIndSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq); 1710 - if (LastIndSeq != RESET_RCV_SEQ) 1711 - { 1712 - pBAEntry->LastIndSeq = LastIndSeq; 1713 - } 1714 - pBAEntry->LastIndSeqAtTimer = Now32; 1715 - } 1716 - // 1717 - // II. Drop Duplicated Packet 1718 - // 1719 - else if (Sequence == pBAEntry->LastIndSeq) 1720 - { 1721 - 1722 - // drop and release packet 1723 - pBAEntry->nDropPacket++; 1724 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 1725 - } 1726 - // 1727 - // III. Drop Old Received Packet 1728 - // 1729 - else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) 1730 - { 1731 - 1732 - // drop and release packet 1733 - pBAEntry->nDropPacket++; 1734 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 1735 - } 1736 - // 1737 - // IV. Receive Sequence within Window Size 1738 - // 1739 - else if (SEQ_SMALLER(Sequence, (((pBAEntry->LastIndSeq+pBAEntry->BAWinSize+1)) & MAXSEQ), MAXSEQ)) 1740 - { 1741 - ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID); 1742 - } 1743 - // 1744 - // V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer 1745 - // 1746 - else 1747 - { 1748 - LONG WinStartSeq, TmpSeq; 1749 - 1750 - 1751 - TmpSeq = Sequence - (pBAEntry->BAWinSize) -1; 1752 - if (TmpSeq < 0) 1753 - { 1754 - TmpSeq = (MAXSEQ+1) + TmpSeq; 1755 - } 1756 - WinStartSeq = (TmpSeq+1) & MAXSEQ; 1757 - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq); 1758 - pBAEntry->LastIndSeq = WinStartSeq; //TmpSeq; 1759 - 1760 - pBAEntry->LastIndSeqAtTimer = Now32; 1761 - 1762 - ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID); 1763 - 1764 - TmpSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq); 1765 - if (TmpSeq != RESET_RCV_SEQ) 1766 - { 1767 - pBAEntry->LastIndSeq = TmpSeq; 1768 - } 1769 - } 1770 - } 1 + #include "../../rt2860/common/ba_action.c"
+1 -2585
drivers/staging/rt2870/common/cmm_data.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - */ 27 - 28 - #include "../rt_config.h" 29 - 30 - #define MAX_TX_IN_TBTT (16) 31 - 32 - 33 - UCHAR SNAP_802_1H[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; 34 - UCHAR SNAP_BRIDGE_TUNNEL[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8}; 35 - // Add Cisco Aironet SNAP heade for CCX2 support 36 - UCHAR SNAP_AIRONET[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00}; 37 - UCHAR CKIP_LLC_SNAP[] = {0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02}; 38 - UCHAR EAPOL_LLC_SNAP[]= {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e}; 39 - UCHAR EAPOL[] = {0x88, 0x8e}; 40 - UCHAR TPID[] = {0x81, 0x00}; /* VLAN related */ 41 - 42 - UCHAR IPX[] = {0x81, 0x37}; 43 - UCHAR APPLE_TALK[] = {0x80, 0xf3}; 44 - UCHAR RateIdToPlcpSignal[12] = { 45 - 0, /* RATE_1 */ 1, /* RATE_2 */ 2, /* RATE_5_5 */ 3, /* RATE_11 */ // see BBP spec 46 - 11, /* RATE_6 */ 15, /* RATE_9 */ 10, /* RATE_12 */ 14, /* RATE_18 */ // see IEEE802.11a-1999 p.14 47 - 9, /* RATE_24 */ 13, /* RATE_36 */ 8, /* RATE_48 */ 12 /* RATE_54 */ }; // see IEEE802.11a-1999 p.14 48 - 49 - UCHAR OfdmSignalToRateId[16] = { 50 - RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 0, 1, 2, 3 respectively 51 - RATE_54, RATE_54, RATE_54, RATE_54, // OFDM PLCP Signal = 4, 5, 6, 7 respectively 52 - RATE_48, RATE_24, RATE_12, RATE_6, // OFDM PLCP Signal = 8, 9, 10, 11 respectively 53 - RATE_54, RATE_36, RATE_18, RATE_9, // OFDM PLCP Signal = 12, 13, 14, 15 respectively 54 - }; 55 - 56 - UCHAR OfdmRateToRxwiMCS[12] = { 57 - 0, 0, 0, 0, 58 - 0, 1, 2, 3, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 59 - 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 60 - }; 61 - UCHAR RxwiMCSToOfdmRate[12] = { 62 - RATE_6, RATE_9, RATE_12, RATE_18, 63 - RATE_24, RATE_36, RATE_48, RATE_54, // OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 64 - 4, 5, 6, 7, // OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 65 - }; 66 - 67 - char* MCSToMbps[] = {"1Mbps","2Mbps","5.5Mbps","11Mbps","06Mbps","09Mbps","12Mbps","18Mbps","24Mbps","36Mbps","48Mbps","54Mbps","MM-0","MM-1","MM-2","MM-3","MM-4","MM-5","MM-6","MM-7","MM-8","MM-9","MM-10","MM-11","MM-12","MM-13","MM-14","MM-15","MM-32","ee1","ee2","ee3"}; 68 - 69 - UCHAR default_cwmin[]={CW_MIN_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1, CW_MIN_IN_BITS-2}; 70 - UCHAR default_sta_aifsn[]={3,7,2,2}; 71 - 72 - UCHAR MapUserPriorityToAccessCategory[8] = {QID_AC_BE, QID_AC_BK, QID_AC_BK, QID_AC_BE, QID_AC_VI, QID_AC_VI, QID_AC_VO, QID_AC_VO}; 73 - 74 - 75 - /* 76 - ======================================================================== 77 - 78 - Routine Description: 79 - API for MLME to transmit management frame to AP (BSS Mode) 80 - or station (IBSS Mode) 81 - 82 - Arguments: 83 - pAd Pointer to our adapter 84 - pData Pointer to the outgoing 802.11 frame 85 - Length Size of outgoing management frame 86 - 87 - Return Value: 88 - NDIS_STATUS_FAILURE 89 - NDIS_STATUS_PENDING 90 - NDIS_STATUS_SUCCESS 91 - 92 - IRQL = PASSIVE_LEVEL 93 - IRQL = DISPATCH_LEVEL 94 - 95 - Note: 96 - 97 - ======================================================================== 98 - */ 99 - NDIS_STATUS MiniportMMRequest( 100 - IN PRTMP_ADAPTER pAd, 101 - IN UCHAR QueIdx, 102 - IN PUCHAR pData, 103 - IN UINT Length) 104 - { 105 - PNDIS_PACKET pPacket; 106 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 107 - ULONG FreeNum; 108 - UCHAR IrqState; 109 - UCHAR rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; //RTMP_HW_HDR_LEN]; 110 - 111 - ASSERT(Length <= MGMT_DMA_BUFFER_SIZE); 112 - 113 - QueIdx=3; 114 - 115 - // 2860C use Tx Ring 116 - 117 - IrqState = pAd->irq_disabled; 118 - 119 - do 120 - { 121 - // Reset is in progress, stop immediately 122 - if ( RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || 123 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)|| 124 - !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) 125 - { 126 - Status = NDIS_STATUS_FAILURE; 127 - break; 128 - } 129 - 130 - // Check Free priority queue 131 - // Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing. 132 - 133 - // 2860C use Tx Ring 134 - if (pAd->MACVersion == 0x28600100) 135 - { 136 - FreeNum = GET_TXRING_FREENO(pAd, QueIdx); 137 - } 138 - else 139 - { 140 - FreeNum = GET_MGMTRING_FREENO(pAd); 141 - } 142 - 143 - if ((FreeNum > 0)) 144 - { 145 - // We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870 146 - NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE)); 147 - Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE), pData, Length); 148 - if (Status != NDIS_STATUS_SUCCESS) 149 - { 150 - DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n")); 151 - break; 152 - } 153 - 154 - //pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; 155 - //pAd->CommonCfg.MlmeRate = RATE_2; 156 - 157 - 158 - Status = MlmeHardTransmit(pAd, QueIdx, pPacket); 159 - if (Status != NDIS_STATUS_SUCCESS) 160 - RTMPFreeNdisPacket(pAd, pPacket); 161 - } 162 - else 163 - { 164 - pAd->RalinkCounters.MgmtRingFullCount++; 165 - DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n", 166 - QueIdx, pAd->RalinkCounters.MgmtRingFullCount)); 167 - } 168 - 169 - } while (FALSE); 170 - 171 - 172 - return Status; 173 - } 174 - 175 - #ifdef RT30xx 176 - NDIS_STATUS MlmeDataHardTransmit( 177 - IN PRTMP_ADAPTER pAd, 178 - IN UCHAR QueIdx, 179 - IN PNDIS_PACKET pPacket); 180 - 181 - #define MAX_DATAMM_RETRY 3 182 - /* 183 - ======================================================================== 184 - 185 - Routine Description: 186 - API for MLME to transmit management frame to AP (BSS Mode) 187 - or station (IBSS Mode) 188 - 189 - Arguments: 190 - pAd Pointer to our adapter 191 - pData Pointer to the outgoing 802.11 frame 192 - Length Size of outgoing management frame 193 - 194 - Return Value: 195 - NDIS_STATUS_FAILURE 196 - NDIS_STATUS_PENDING 197 - NDIS_STATUS_SUCCESS 198 - 199 - IRQL = PASSIVE_LEVEL 200 - IRQL = DISPATCH_LEVEL 201 - 202 - Note: 203 - 204 - ======================================================================== 205 - */ 206 - NDIS_STATUS MiniportDataMMRequest( 207 - IN PRTMP_ADAPTER pAd, 208 - IN UCHAR QueIdx, 209 - IN PUCHAR pData, 210 - IN UINT Length) 211 - { 212 - PNDIS_PACKET pPacket; 213 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 214 - ULONG FreeNum; 215 - int retry = 0; 216 - UCHAR IrqState; 217 - UCHAR rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; //RTMP_HW_HDR_LEN]; 218 - 219 - ASSERT(Length <= MGMT_DMA_BUFFER_SIZE); 220 - 221 - // 2860C use Tx Ring 222 - IrqState = pAd->irq_disabled; 223 - 224 - do 225 - { 226 - // Reset is in progress, stop immediately 227 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || 228 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)|| 229 - !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) 230 - { 231 - Status = NDIS_STATUS_FAILURE; 232 - break; 233 - } 234 - 235 - // Check Free priority queue 236 - // Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing. 237 - 238 - // 2860C use Tx Ring 239 - 240 - // free Tx(QueIdx) resources 241 - FreeNum = GET_TXRING_FREENO(pAd, QueIdx); 242 - 243 - if ((FreeNum > 0)) 244 - { 245 - // We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870 246 - NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE)); 247 - Status = RTMPAllocateNdisPacket(pAd, &pPacket, (PUCHAR)&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE), pData, Length); 248 - if (Status != NDIS_STATUS_SUCCESS) 249 - { 250 - DBGPRINT(RT_DEBUG_WARN, ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n")); 251 - break; 252 - } 253 - 254 - //pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; 255 - //pAd->CommonCfg.MlmeRate = RATE_2; 256 - 257 - 258 - Status = MlmeDataHardTransmit(pAd, QueIdx, pPacket); 259 - if (Status != NDIS_STATUS_SUCCESS) 260 - RTMPFreeNdisPacket(pAd, pPacket); 261 - retry = MAX_DATAMM_RETRY; 262 - } 263 - else 264 - { 265 - retry ++; 266 - 267 - printk("retry %d\n", retry); 268 - pAd->RalinkCounters.MgmtRingFullCount++; 269 - 270 - if (retry >= MAX_DATAMM_RETRY) 271 - { 272 - DBGPRINT(RT_DEBUG_ERROR, ("Qidx(%d), not enough space in DataRing, MgmtRingFullCount=%ld!\n", 273 - QueIdx, pAd->RalinkCounters.MgmtRingFullCount)); 274 - } 275 - } 276 - 277 - } while (retry < MAX_DATAMM_RETRY); 278 - 279 - 280 - return Status; 281 - } 282 - #endif /* RT30xx */ 283 - 284 - 285 - /* 286 - ======================================================================== 287 - 288 - Routine Description: 289 - Copy frame from waiting queue into relative ring buffer and set 290 - appropriate ASIC register to kick hardware transmit function 291 - 292 - Arguments: 293 - pAd Pointer to our adapter 294 - pBuffer Pointer to memory of outgoing frame 295 - Length Size of outgoing management frame 296 - 297 - Return Value: 298 - NDIS_STATUS_FAILURE 299 - NDIS_STATUS_PENDING 300 - NDIS_STATUS_SUCCESS 301 - 302 - IRQL = PASSIVE_LEVEL 303 - IRQL = DISPATCH_LEVEL 304 - 305 - Note: 306 - 307 - ======================================================================== 308 - */ 309 - NDIS_STATUS MlmeHardTransmit( 310 - IN PRTMP_ADAPTER pAd, 311 - IN UCHAR QueIdx, 312 - IN PNDIS_PACKET pPacket) 313 - { 314 - if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) 315 - ) 316 - { 317 - return NDIS_STATUS_FAILURE; 318 - } 319 - 320 - return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket); 321 - 322 - } 323 - 324 - #ifdef RT30xx 325 - NDIS_STATUS MlmeDataHardTransmit( 326 - IN PRTMP_ADAPTER pAd, 327 - IN UCHAR QueIdx, 328 - IN PNDIS_PACKET pPacket) 329 - { 330 - if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) 331 - ) 332 - { 333 - return NDIS_STATUS_FAILURE; 334 - } 335 - 336 - #ifdef RT2870 337 - return MlmeHardTransmitMgmtRing(pAd,QueIdx,pPacket); 338 - #endif // RT2870 // 339 - } 340 - #endif /* RT30xx */ 341 - 342 - NDIS_STATUS MlmeHardTransmitMgmtRing( 343 - IN PRTMP_ADAPTER pAd, 344 - IN UCHAR QueIdx, 345 - IN PNDIS_PACKET pPacket) 346 - { 347 - PACKET_INFO PacketInfo; 348 - PUCHAR pSrcBufVA; 349 - UINT SrcBufLen; 350 - PHEADER_802_11 pHeader_802_11; 351 - BOOLEAN bAckRequired, bInsertTimestamp; 352 - UCHAR MlmeRate; 353 - PTXWI_STRUC pFirstTxWI; 354 - MAC_TABLE_ENTRY *pMacEntry = NULL; 355 - 356 - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); 357 - 358 - RTMP_SEM_LOCK(&pAd->MgmtRingLock); 359 - 360 - 361 - if (pSrcBufVA == NULL) 362 - { 363 - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); 364 - return NDIS_STATUS_FAILURE; 365 - } 366 - 367 - // outgoing frame always wakeup PHY to prevent frame lost 368 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) 369 - AsicForceWakeup(pAd, TRUE); 370 - 371 - pFirstTxWI = (PTXWI_STRUC)(pSrcBufVA + TXINFO_SIZE); 372 - pHeader_802_11 = (PHEADER_802_11) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); //TXWI_SIZE); 373 - 374 - if (pHeader_802_11->Addr1[0] & 0x01) 375 - { 376 - MlmeRate = pAd->CommonCfg.BasicMlmeRate; 377 - } 378 - else 379 - { 380 - MlmeRate = pAd->CommonCfg.MlmeRate; 381 - } 382 - 383 - // Verify Mlme rate for a / g bands. 384 - if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) // 11A band 385 - MlmeRate = RATE_6; 386 - 387 - if ((pHeader_802_11->FC.Type == BTYPE_DATA) && 388 - (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL)) 389 - { 390 - pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1); 391 - } 392 - 393 - { 394 - // Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode. 395 - if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED 396 - || pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED 397 - ) 398 - { 399 - if (pAd->LatchRfRegs.Channel > 14) 400 - pAd->CommonCfg.MlmeTransmit.field.MODE = 1; 401 - else 402 - pAd->CommonCfg.MlmeTransmit.field.MODE = 0; 403 - } 404 - } 405 - 406 - // 407 - // Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE) 408 - // Snice it's been set to 0 while on MgtMacHeaderInit 409 - // By the way this will cause frame to be send on PWR_SAVE failed. 410 - // 411 - // pHeader_802_11->FC.PwrMgmt = 0; // (pAd->StaCfg.Psm == PWR_SAVE); 412 - // 413 - // In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame 414 - 415 - // Data-Null packets alse pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD 416 - if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL)) 417 - { 418 - if ((pAd->StaCfg.Psm == PWR_SAVE) && 419 - (pHeader_802_11->FC.SubType == SUBTYPE_ACTION)) 420 - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; 421 - else 422 - pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE; 423 - } 424 - 425 - bInsertTimestamp = FALSE; 426 - if (pHeader_802_11->FC.Type == BTYPE_CNTL) // must be PS-POLL 427 - { 428 - //Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue. 429 - if ((pAd->OpMode == OPMODE_STA) && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL)) 430 - { 431 - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; 432 - } 433 - bAckRequired = FALSE; 434 - } 435 - else // BTYPE_MGMT or BTYPE_DATA(must be NULL frame) 436 - { 437 - if (pHeader_802_11->Addr1[0] & 0x01) // MULTICAST, BROADCAST 438 - { 439 - bAckRequired = FALSE; 440 - pHeader_802_11->Duration = 0; 441 - } 442 - else 443 - { 444 - bAckRequired = TRUE; 445 - pHeader_802_11->Duration = RTMPCalcDuration(pAd, MlmeRate, 14); 446 - if (pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP) 447 - { 448 - bInsertTimestamp = TRUE; 449 - } 450 - } 451 - } 452 - 453 - pHeader_802_11->Sequence = pAd->Sequence++; 454 - if (pAd->Sequence >0xfff) 455 - pAd->Sequence = 0; 456 - 457 - // Before radar detection done, mgmt frame can not be sent but probe req 458 - // Because we need to use probe req to trigger driver to send probe req in passive scan 459 - if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ) 460 - && (pAd->CommonCfg.bIEEE80211H == 1) 461 - && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)) 462 - { 463 - DBGPRINT(RT_DEBUG_ERROR,("MlmeHardTransmit --> radar detect not in normal mode !!!\n")); 464 - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); 465 - return (NDIS_STATUS_FAILURE); 466 - } 467 - 468 - // 469 - // fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET 470 - // should always has only one ohysical buffer, and the whole frame size equals 471 - // to the first scatter buffer size 472 - // 473 - 474 - // Initialize TX Descriptor 475 - // For inter-frame gap, the number is for this frame and next frame 476 - // For MLME rate, we will fix as 2Mb to match other vendor's implement 477 - 478 - // management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not. 479 - if (pMacEntry == NULL) 480 - { 481 - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, FALSE, bAckRequired, FALSE, 482 - 0, RESERVED_WCID, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), PID_MGMT, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit); 483 - } 484 - else 485 - { 486 - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, 487 - bInsertTimestamp, FALSE, bAckRequired, FALSE, 488 - 0, pMacEntry->Aid, (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), 489 - pMacEntry->MaxHTPhyMode.field.MCS, 0, 490 - (UCHAR)pMacEntry->MaxHTPhyMode.field.MCS, 491 - IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode); 492 - } 493 - 494 - // Now do hardware-depened kick out. 495 - HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen); 496 - 497 - // Make sure to release MGMT ring resource 498 - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); 499 - return NDIS_STATUS_SUCCESS; 500 - } 501 - 502 - 503 - /******************************************************************************** 504 - 505 - New DeQueue Procedures. 506 - 507 - ********************************************************************************/ 508 - 509 - #define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \ 510 - do{ \ 511 - if (bIntContext == FALSE) \ 512 - RTMP_IRQ_LOCK((lock), IrqFlags); \ 513 - }while(0) 514 - 515 - #define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \ 516 - do{ \ 517 - if (bIntContext == FALSE) \ 518 - RTMP_IRQ_UNLOCK((lock), IrqFlags); \ 519 - }while(0) 520 - 521 - /* 522 - ======================================================================== 523 - Tx Path design algorithm: 524 - Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal), 525 - Specific Packet Type. Following show the classification rule and policy for each kinds of packets. 526 - Classification Rule=> 527 - Multicast: (*addr1 & 0x01) == 0x01 528 - Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc. 529 - 11N Rate : If peer support HT 530 - (1).AMPDU -- If TXBA is negotiated. 531 - (2).AMSDU -- If AMSDU is capable for both peer and ourself. 532 - *). AMSDU can embedded in a AMPDU, but now we didn't support it. 533 - (3).Normal -- Other packets which send as 11n rate. 534 - 535 - B/G Rate : If peer is b/g only. 536 - (1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6 537 - (2).Normal -- Other packets which send as b/g rate. 538 - Fragment: 539 - The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment. 540 - 541 - Classified Packet Handle Rule=> 542 - Multicast: 543 - No ACK, //pTxBlk->bAckRequired = FALSE; 544 - No WMM, //pTxBlk->bWMM = FALSE; 545 - No piggyback, //pTxBlk->bPiggyBack = FALSE; 546 - Force LowRate, //pTxBlk->bForceLowRate = TRUE; 547 - Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use 548 - the same policy to handle it. 549 - Force LowRate, //pTxBlk->bForceLowRate = TRUE; 550 - 551 - 11N Rate : 552 - No piggyback, //pTxBlk->bPiggyBack = FALSE; 553 - 554 - (1).AMSDU 555 - pTxBlk->bWMM = TRUE; 556 - (2).AMPDU 557 - pTxBlk->bWMM = TRUE; 558 - (3).Normal 559 - 560 - B/G Rate : 561 - (1).ARALINK 562 - 563 - (2).Normal 564 - ======================================================================== 565 - */ 566 - static UCHAR TxPktClassification( 567 - IN RTMP_ADAPTER *pAd, 568 - IN PNDIS_PACKET pPacket) 569 - { 570 - UCHAR TxFrameType = TX_UNKOWN_FRAME; 571 - UCHAR Wcid; 572 - MAC_TABLE_ENTRY *pMacEntry = NULL; 573 - BOOLEAN bHTRate = FALSE; 574 - 575 - Wcid = RTMP_GET_PACKET_WCID(pPacket); 576 - if (Wcid == MCAST_WCID) 577 - { // Handle for RA is Broadcast/Multicast Address. 578 - return TX_MCAST_FRAME; 579 - } 580 - 581 - // Handle for unicast packets 582 - pMacEntry = &pAd->MacTab.Content[Wcid]; 583 - if (RTMP_GET_PACKET_LOWRATE(pPacket)) 584 - { // It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame 585 - TxFrameType = TX_LEGACY_FRAME; 586 - } 587 - else if (IS_HT_RATE(pMacEntry)) 588 - { // it's a 11n capable packet 589 - 590 - // Depends on HTPhyMode to check if the peer support the HTRate transmission. 591 - // Currently didn't support A-MSDU embedded in A-MPDU 592 - bHTRate = TRUE; 593 - if (RTMP_GET_PACKET_MOREDATA(pPacket) || (pMacEntry->PsMode == PWR_SAVE)) 594 - TxFrameType = TX_LEGACY_FRAME; 595 - #ifdef UAPSD_AP_SUPPORT 596 - else if (RTMP_GET_PACKET_EOSP(pPacket)) 597 - TxFrameType = TX_LEGACY_FRAME; 598 - #endif // UAPSD_AP_SUPPORT // 599 - else if((pMacEntry->TXBAbitmap & (1<<(RTMP_GET_PACKET_UP(pPacket)))) != 0) 600 - return TX_AMPDU_FRAME; 601 - else if(CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AMSDU_INUSED)) 602 - return TX_AMSDU_FRAME; 603 - else 604 - TxFrameType = TX_LEGACY_FRAME; 605 - } 606 - else 607 - { // it's a legacy b/g packet. 608 - if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) && 609 - (RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) && 610 - (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) 611 - { // if peer support Ralink Aggregation, we use it. 612 - TxFrameType = TX_RALINK_FRAME; 613 - } 614 - else 615 - { 616 - TxFrameType = TX_LEGACY_FRAME; 617 - } 618 - } 619 - 620 - // Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU. 621 - if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1) && (TxFrameType == TX_LEGACY_FRAME)) 622 - TxFrameType = TX_FRAG_FRAME; 623 - 624 - return TxFrameType; 625 - } 626 - 627 - 628 - BOOLEAN RTMP_FillTxBlkInfo( 629 - IN RTMP_ADAPTER *pAd, 630 - IN TX_BLK *pTxBlk) 631 - { 632 - PACKET_INFO PacketInfo; 633 - PNDIS_PACKET pPacket; 634 - PMAC_TABLE_ENTRY pMacEntry = NULL; 635 - 636 - pPacket = pTxBlk->pPacket; 637 - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen); 638 - 639 - pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket); 640 - pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket); 641 - pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket); 642 - pTxBlk->FrameGap = IFS_HTTXOP; // ASIC determine Frame Gap 643 - 644 - if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket)) 645 - TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame); 646 - else 647 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame); 648 - 649 - // Default to clear this flag 650 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS); 651 - 652 - 653 - if (pTxBlk->Wcid == MCAST_WCID) 654 - { 655 - pTxBlk->pMacEntry = NULL; 656 - { 657 - #ifdef MCAST_RATE_SPECIFIC 658 - PUCHAR pDA = GET_OS_PKT_DATAPTR(pPacket); 659 - if (((*pDA & 0x01) == 0x01) && (*pDA != 0xff)) 660 - pTxBlk->pTransmit = &pAd->CommonCfg.MCastPhyMode; 661 - else 662 - #endif // MCAST_RATE_SPECIFIC // 663 - pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode; 664 - } 665 - 666 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); // AckRequired = FALSE, when broadcast packet in Adhoc mode. 667 - //TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate); 668 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag); 669 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM); 670 - if (RTMP_GET_PACKET_MOREDATA(pPacket)) 671 - { 672 - TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData); 673 - } 674 - 675 - } 676 - else 677 - { 678 - pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid]; 679 - pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode; 680 - 681 - pMacEntry = pTxBlk->pMacEntry; 682 - 683 - 684 - // For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK. 685 - if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK) 686 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); 687 - else 688 - TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired); 689 - 690 - { 691 - // If support WMM, enable it. 692 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && 693 - CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)) 694 - TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM); 695 - } 696 - 697 - if (pTxBlk->TxFrameType == TX_LEGACY_FRAME) 698 - { 699 - if ( (RTMP_GET_PACKET_LOWRATE(pPacket)) || 700 - ((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1))) 701 - { // Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate. 702 - pTxBlk->pTransmit = &pAd->MacTab.Content[MCAST_WCID].HTPhyMode; 703 - 704 - // Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it??? 705 - if (IS_HT_STA(pTxBlk->pMacEntry) && 706 - (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET)) && 707 - ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_RDG_CAPABLE))) 708 - { 709 - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM); 710 - TX_BLK_SET_FLAG(pTxBlk, fTX_bForceNonQoS); 711 - } 712 - } 713 - 714 - if ( (IS_HT_RATE(pMacEntry) == FALSE) && 715 - (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE))) 716 - { // Currently piggy-back only support when peer is operate in b/g mode. 717 - TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack); 718 - } 719 - 720 - if (RTMP_GET_PACKET_MOREDATA(pPacket)) 721 - { 722 - TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData); 723 - } 724 - #ifdef UAPSD_AP_SUPPORT 725 - if (RTMP_GET_PACKET_EOSP(pPacket)) 726 - { 727 - TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM_UAPSD_EOSP); 728 - } 729 - #endif // UAPSD_AP_SUPPORT // 730 - } 731 - else if (pTxBlk->TxFrameType == TX_FRAG_FRAME) 732 - { 733 - TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag); 734 - } 735 - 736 - pMacEntry->DebugTxCount++; 737 - } 738 - 739 - return TRUE; 740 - 741 - #ifdef RT30xx 742 - FillTxBlkErr: 743 - return FALSE; 744 - #endif 745 - } 746 - 747 - 748 - BOOLEAN CanDoAggregateTransmit( 749 - IN RTMP_ADAPTER *pAd, 750 - IN NDIS_PACKET *pPacket, 751 - IN TX_BLK *pTxBlk) 752 - { 753 - 754 - //printk("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType); 755 - 756 - if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID) 757 - return FALSE; 758 - 759 - if (RTMP_GET_PACKET_DHCP(pPacket) || 760 - RTMP_GET_PACKET_EAPOL(pPacket) || 761 - RTMP_GET_PACKET_WAI(pPacket)) 762 - return FALSE; 763 - 764 - if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) && 765 - ((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))> (RX_BUFFER_AGGRESIZE - 100))) 766 - { // For AMSDU, allow the packets with total length < max-amsdu size 767 - return FALSE; 768 - } 769 - 770 - if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) && 771 - (pTxBlk->TxPacketList.Number == 2)) 772 - { // For RALINK-Aggregation, allow two frames in one batch. 773 - return FALSE; 774 - } 775 - 776 - if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) // must be unicast to AP 777 - return TRUE; 778 - else 779 - return FALSE; 780 - } 781 - 782 - 783 - /* 784 - ======================================================================== 785 - 786 - Routine Description: 787 - To do the enqueue operation and extract the first item of waiting 788 - list. If a number of available shared memory segments could meet 789 - the request of extracted item, the extracted item will be fragmented 790 - into shared memory segments. 791 - 792 - Arguments: 793 - pAd Pointer to our adapter 794 - pQueue Pointer to Waiting Queue 795 - 796 - Return Value: 797 - None 798 - 799 - IRQL = DISPATCH_LEVEL 800 - 801 - Note: 802 - 803 - ======================================================================== 804 - */ 805 - VOID RTMPDeQueuePacket( 806 - IN PRTMP_ADAPTER pAd, 807 - IN BOOLEAN bIntContext, 808 - IN UCHAR QIdx, /* BulkOutPipeId */ 809 - IN UCHAR Max_Tx_Packets) 810 - { 811 - PQUEUE_ENTRY pEntry = NULL; 812 - PNDIS_PACKET pPacket; 813 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 814 - UCHAR Count=0; 815 - PQUEUE_HEADER pQueue; 816 - ULONG FreeNumber[NUM_OF_TX_RING]; 817 - UCHAR QueIdx, sQIdx, eQIdx; 818 - unsigned long IrqFlags = 0; 819 - BOOLEAN hasTxDesc = FALSE; 820 - TX_BLK TxBlk; 821 - TX_BLK *pTxBlk; 822 - 823 - #ifdef DBG_DIAGNOSE 824 - BOOLEAN firstRound; 825 - RtmpDiagStruct *pDiagStruct = &pAd->DiagStruct; 826 - #endif 827 - 828 - 829 - if (QIdx == NUM_OF_TX_RING) 830 - { 831 - sQIdx = 0; 832 - //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA) 833 - eQIdx = 3; // 4 ACs, start from 0. 834 - } 835 - else 836 - { 837 - sQIdx = eQIdx = QIdx; 838 - } 839 - 840 - for (QueIdx=sQIdx; QueIdx <= eQIdx; QueIdx++) 841 - { 842 - Count=0; 843 - 844 - RT28XX_START_DEQUEUE(pAd, QueIdx, IrqFlags); 845 - 846 - #ifdef DBG_DIAGNOSE 847 - firstRound = ((QueIdx == 0) ? TRUE : FALSE); 848 - #endif // DBG_DIAGNOSE // 849 - 850 - while (1) 851 - { 852 - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS | 853 - fRTMP_ADAPTER_RADIO_OFF | 854 - fRTMP_ADAPTER_RESET_IN_PROGRESS | 855 - fRTMP_ADAPTER_HALT_IN_PROGRESS | 856 - fRTMP_ADAPTER_NIC_NOT_EXIST)))) 857 - { 858 - RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags); 859 - return; 860 - } 861 - 862 - if (Count >= Max_Tx_Packets) 863 - break; 864 - 865 - DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags); 866 - if (&pAd->TxSwQueue[QueIdx] == NULL) 867 - { 868 - #ifdef DBG_DIAGNOSE 869 - if (firstRound == TRUE) 870 - pDiagStruct->TxSWQueCnt[pDiagStruct->ArrayCurIdx][0]++; 871 - #endif // DBG_DIAGNOSE // 872 - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); 873 - break; 874 - } 875 - 876 - 877 - // probe the Queue Head 878 - pQueue = &pAd->TxSwQueue[QueIdx]; 879 - if ((pEntry = pQueue->Head) == NULL) 880 - { 881 - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); 882 - break; 883 - } 884 - 885 - pTxBlk = &TxBlk; 886 - NdisZeroMemory((PUCHAR)pTxBlk, sizeof(TX_BLK)); 887 - pTxBlk->QueIdx = QueIdx; 888 - 889 - pPacket = QUEUE_ENTRY_TO_PKT(pEntry); 890 - 891 - // Early check to make sure we have enoguh Tx Resource. 892 - hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket); 893 - if (!hasTxDesc) 894 - { 895 - pAd->PrivateInfo.TxRingFullCnt++; 896 - 897 - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); 898 - 899 - break; 900 - } 901 - 902 - pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket); 903 - pEntry = RemoveHeadQueue(pQueue); 904 - pTxBlk->TotalFrameNum++; 905 - pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary 906 - pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket); 907 - pTxBlk->pPacket = pPacket; 908 - InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket)); 909 - 910 - if (pTxBlk->TxFrameType == TX_RALINK_FRAME || pTxBlk->TxFrameType == TX_AMSDU_FRAME) 911 - { 912 - // Enhance SW Aggregation Mechanism 913 - if (NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, FreeNumber[QueIdx], pTxBlk->TxFrameType)) 914 - { 915 - InsertHeadQueue(pQueue, PACKET_TO_QUEUE_ENTRY(pPacket)); 916 - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); 917 - break; 918 - } 919 - 920 - do{ 921 - if((pEntry = pQueue->Head) == NULL) 922 - break; 923 - 924 - // For TX_AMSDU_FRAME/TX_RALINK_FRAME, Need to check if next pakcet can do aggregation. 925 - pPacket = QUEUE_ENTRY_TO_PKT(pEntry); 926 - FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx); 927 - hasTxDesc = RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, FreeNumber[QueIdx], pPacket); 928 - if ((hasTxDesc == FALSE) || (CanDoAggregateTransmit(pAd, pPacket, pTxBlk) == FALSE)) 929 - break; 930 - 931 - //Remove the packet from the TxSwQueue and insert into pTxBlk 932 - pEntry = RemoveHeadQueue(pQueue); 933 - ASSERT(pEntry); 934 - pPacket = QUEUE_ENTRY_TO_PKT(pEntry); 935 - pTxBlk->TotalFrameNum++; 936 - pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); // The real fragment number maybe vary 937 - pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket); 938 - InsertTailQueue(&pTxBlk->TxPacketList, PACKET_TO_QUEUE_ENTRY(pPacket)); 939 - }while(1); 940 - 941 - if (pTxBlk->TxPacketList.Number == 1) 942 - pTxBlk->TxFrameType = TX_LEGACY_FRAME; 943 - } 944 - 945 - #ifdef RT2870 946 - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); 947 - #endif // RT2870 // 948 - 949 - Count += pTxBlk->TxPacketList.Number; 950 - 951 - // Do HardTransmit now. 952 - Status = STAHardTransmit(pAd, pTxBlk, QueIdx); 953 - } 954 - 955 - RT28XX_STOP_DEQUEUE(pAd, QueIdx, IrqFlags); 956 - 957 - #ifdef RT2870 958 - if (!hasTxDesc) 959 - RTUSBKickBulkOut(pAd); 960 - #endif // RT2870 // 961 - } 962 - 963 - } 964 - 965 - 966 - /* 967 - ======================================================================== 968 - 969 - Routine Description: 970 - Calculates the duration which is required to transmit out frames 971 - with given size and specified rate. 972 - 973 - Arguments: 974 - pAd Pointer to our adapter 975 - Rate Transmit rate 976 - Size Frame size in units of byte 977 - 978 - Return Value: 979 - Duration number in units of usec 980 - 981 - IRQL = PASSIVE_LEVEL 982 - IRQL = DISPATCH_LEVEL 983 - 984 - Note: 985 - 986 - ======================================================================== 987 - */ 988 - USHORT RTMPCalcDuration( 989 - IN PRTMP_ADAPTER pAd, 990 - IN UCHAR Rate, 991 - IN ULONG Size) 992 - { 993 - ULONG Duration = 0; 994 - 995 - if (Rate < RATE_FIRST_OFDM_RATE) // CCK 996 - { 997 - if ((Rate > RATE_1) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED)) 998 - Duration = 96; // 72+24 preamble+plcp 999 - else 1000 - Duration = 192; // 144+48 preamble+plcp 1001 - 1002 - Duration += (USHORT)((Size << 4) / RateIdTo500Kbps[Rate]); 1003 - if ((Size << 4) % RateIdTo500Kbps[Rate]) 1004 - Duration ++; 1005 - } 1006 - else if (Rate <= RATE_LAST_OFDM_RATE)// OFDM rates 1007 - { 1008 - Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension 1009 - Duration += 4 * (USHORT)((11 + Size * 4) / RateIdTo500Kbps[Rate]); 1010 - if ((11 + Size * 4) % RateIdTo500Kbps[Rate]) 1011 - Duration += 4; 1012 - } 1013 - else //mimo rate 1014 - { 1015 - Duration = 20 + 6; // 16+4 preamble+plcp + Signal Extension 1016 - } 1017 - 1018 - return (USHORT)Duration; 1019 - } 1020 - 1021 - 1022 - /* 1023 - ======================================================================== 1024 - 1025 - Routine Description: 1026 - Calculates the duration which is required to transmit out frames 1027 - with given size and specified rate. 1028 - 1029 - Arguments: 1030 - pTxWI Pointer to head of each MPDU to HW. 1031 - Ack Setting for Ack requirement bit 1032 - Fragment Setting for Fragment bit 1033 - RetryMode Setting for retry mode 1034 - Ifs Setting for IFS gap 1035 - Rate Setting for transmit rate 1036 - Service Setting for service 1037 - Length Frame length 1038 - TxPreamble Short or Long preamble when using CCK rates 1039 - QueIdx - 0-3, according to 802.11e/d4.4 June/2003 1040 - 1041 - Return Value: 1042 - None 1043 - 1044 - IRQL = PASSIVE_LEVEL 1045 - IRQL = DISPATCH_LEVEL 1046 - 1047 - See also : BASmartHardTransmit() !!! 1048 - 1049 - ======================================================================== 1050 - */ 1051 - VOID RTMPWriteTxWI( 1052 - IN PRTMP_ADAPTER pAd, 1053 - IN PTXWI_STRUC pOutTxWI, 1054 - IN BOOLEAN FRAG, 1055 - IN BOOLEAN CFACK, 1056 - IN BOOLEAN InsTimestamp, 1057 - IN BOOLEAN AMPDU, 1058 - IN BOOLEAN Ack, 1059 - IN BOOLEAN NSeq, // HW new a sequence. 1060 - IN UCHAR BASize, 1061 - IN UCHAR WCID, 1062 - IN ULONG Length, 1063 - IN UCHAR PID, 1064 - IN UCHAR TID, 1065 - IN UCHAR TxRate, 1066 - IN UCHAR Txopmode, 1067 - IN BOOLEAN CfAck, 1068 - IN HTTRANSMIT_SETTING *pTransmit) 1069 - { 1070 - PMAC_TABLE_ENTRY pMac = NULL; 1071 - TXWI_STRUC TxWI; 1072 - PTXWI_STRUC pTxWI; 1073 - 1074 - if (WCID < MAX_LEN_OF_MAC_TABLE) 1075 - pMac = &pAd->MacTab.Content[WCID]; 1076 - 1077 - // 1078 - // Always use Long preamble before verifiation short preamble functionality works well. 1079 - // Todo: remove the following line if short preamble functionality works 1080 - // 1081 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); 1082 - NdisZeroMemory(&TxWI, TXWI_SIZE); 1083 - pTxWI = &TxWI; 1084 - 1085 - pTxWI->FRAG= FRAG; 1086 - 1087 - pTxWI->CFACK = CFACK; 1088 - pTxWI->TS= InsTimestamp; 1089 - pTxWI->AMPDU = AMPDU; 1090 - pTxWI->ACK = Ack; 1091 - pTxWI->txop= Txopmode; 1092 - 1093 - pTxWI->NSEQ = NSeq; 1094 - // John tune the performace with Intel Client in 20 MHz performance 1095 - BASize = pAd->CommonCfg.TxBASize; 1096 - 1097 - if( BASize >7 ) 1098 - BASize =7; 1099 - pTxWI->BAWinSize = BASize; 1100 - pTxWI->ShortGI = pTransmit->field.ShortGI; 1101 - pTxWI->STBC = pTransmit->field.STBC; 1102 - 1103 - pTxWI->WirelessCliID = WCID; 1104 - pTxWI->MPDUtotalByteCount = Length; 1105 - pTxWI->PacketId = PID; 1106 - 1107 - // If CCK or OFDM, BW must be 20 1108 - pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); 1109 - 1110 - pTxWI->MCS = pTransmit->field.MCS; 1111 - pTxWI->PHYMODE = pTransmit->field.MODE; 1112 - pTxWI->CFACK = CfAck; 1113 - 1114 - if (pMac) 1115 - { 1116 - if (pAd->CommonCfg.bMIMOPSEnable) 1117 - { 1118 - if ((pMac->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7)) 1119 - { 1120 - // Dynamic MIMO Power Save Mode 1121 - pTxWI->MIMOps = 1; 1122 - } 1123 - else if (pMac->MmpsMode == MMPS_STATIC) 1124 - { 1125 - // Static MIMO Power Save Mode 1126 - if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7) 1127 - { 1128 - pTxWI->MCS = 7; 1129 - pTxWI->MIMOps = 0; 1130 - } 1131 - } 1132 - } 1133 - //pTxWI->MIMOps = (pMac->PsMode == PWR_MMPS)? 1:0; 1134 - if (pMac->bIAmBadAtheros && (pMac->WepStatus != Ndis802_11WEPDisabled)) 1135 - { 1136 - pTxWI->MpduDensity = 7; 1137 - } 1138 - else 1139 - { 1140 - pTxWI->MpduDensity = pMac->MpduDensity; 1141 - } 1142 - } 1143 - 1144 - pTxWI->PacketId = pTxWI->MCS; 1145 - NdisMoveMemory(pOutTxWI, &TxWI, sizeof(TXWI_STRUC)); 1146 - } 1147 - 1148 - 1149 - VOID RTMPWriteTxWI_Data( 1150 - IN PRTMP_ADAPTER pAd, 1151 - IN OUT PTXWI_STRUC pTxWI, 1152 - IN TX_BLK *pTxBlk) 1153 - { 1154 - HTTRANSMIT_SETTING *pTransmit; 1155 - PMAC_TABLE_ENTRY pMacEntry; 1156 - UCHAR BASize; 1157 - 1158 - ASSERT(pTxWI); 1159 - 1160 - pTransmit = pTxBlk->pTransmit; 1161 - pMacEntry = pTxBlk->pMacEntry; 1162 - 1163 - 1164 - // 1165 - // Always use Long preamble before verifiation short preamble functionality works well. 1166 - // Todo: remove the following line if short preamble functionality works 1167 - // 1168 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); 1169 - NdisZeroMemory(pTxWI, TXWI_SIZE); 1170 - 1171 - pTxWI->FRAG = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag); 1172 - pTxWI->ACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAckRequired); 1173 - pTxWI->txop = pTxBlk->FrameGap; 1174 - 1175 - pTxWI->WirelessCliID = pTxBlk->Wcid; 1176 - 1177 - pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; 1178 - pTxWI->CFACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bPiggyBack); 1179 - 1180 - // If CCK or OFDM, BW must be 20 1181 - pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); 1182 - pTxWI->AMPDU = ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) ? TRUE : FALSE); 1183 - 1184 - // John tune the performace with Intel Client in 20 MHz performance 1185 - BASize = pAd->CommonCfg.TxBASize; 1186 - if((pTxBlk->TxFrameType == TX_AMPDU_FRAME) && (pMacEntry)) 1187 - { 1188 - UCHAR RABAOriIdx = 0; //The RA's BA Originator table index. 1189 - 1190 - RABAOriIdx = pTxBlk->pMacEntry->BAOriWcidArray[pTxBlk->UserPriority]; 1191 - BASize = pAd->BATable.BAOriEntry[RABAOriIdx].BAWinSize; 1192 - } 1193 - 1194 - pTxWI->TxBF = pTransmit->field.TxBF; 1195 - pTxWI->BAWinSize = BASize; 1196 - pTxWI->ShortGI = pTransmit->field.ShortGI; 1197 - pTxWI->STBC = pTransmit->field.STBC; 1198 - 1199 - pTxWI->MCS = pTransmit->field.MCS; 1200 - pTxWI->PHYMODE = pTransmit->field.MODE; 1201 - 1202 - if (pMacEntry) 1203 - { 1204 - if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7)) 1205 - { 1206 - // Dynamic MIMO Power Save Mode 1207 - pTxWI->MIMOps = 1; 1208 - } 1209 - else if (pMacEntry->MmpsMode == MMPS_STATIC) 1210 - { 1211 - // Static MIMO Power Save Mode 1212 - if (pTransmit->field.MODE >= MODE_HTMIX && pTransmit->field.MCS > 7) 1213 - { 1214 - pTxWI->MCS = 7; 1215 - pTxWI->MIMOps = 0; 1216 - } 1217 - } 1218 - 1219 - if (pMacEntry->bIAmBadAtheros && (pMacEntry->WepStatus != Ndis802_11WEPDisabled)) 1220 - { 1221 - pTxWI->MpduDensity = 7; 1222 - } 1223 - else 1224 - { 1225 - pTxWI->MpduDensity = pMacEntry->MpduDensity; 1226 - } 1227 - } 1228 - 1229 - #ifdef DBG_DIAGNOSE 1230 - if (pTxBlk->QueIdx== 0) 1231 - { 1232 - pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++; 1233 - pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++; 1234 - } 1235 - #endif // DBG_DIAGNOSE // 1236 - 1237 - // for rate adapation 1238 - pTxWI->PacketId = pTxWI->MCS; 1239 - } 1240 - 1241 - 1242 - VOID RTMPWriteTxWI_Cache( 1243 - IN PRTMP_ADAPTER pAd, 1244 - IN OUT PTXWI_STRUC pTxWI, 1245 - IN TX_BLK *pTxBlk) 1246 - { 1247 - PHTTRANSMIT_SETTING pTransmit; 1248 - PMAC_TABLE_ENTRY pMacEntry; 1249 - 1250 - // 1251 - // update TXWI 1252 - // 1253 - pMacEntry = pTxBlk->pMacEntry; 1254 - pTransmit = pTxBlk->pTransmit; 1255 - 1256 - if (pMacEntry->bAutoTxRateSwitch) 1257 - { 1258 - pTxWI->txop = IFS_HTTXOP; 1259 - 1260 - // If CCK or OFDM, BW must be 20 1261 - pTxWI->BW = (pTransmit->field.MODE <= MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); 1262 - pTxWI->ShortGI = pTransmit->field.ShortGI; 1263 - pTxWI->STBC = pTransmit->field.STBC; 1264 - 1265 - pTxWI->MCS = pTransmit->field.MCS; 1266 - pTxWI->PHYMODE = pTransmit->field.MODE; 1267 - 1268 - // set PID for TxRateSwitching 1269 - pTxWI->PacketId = pTransmit->field.MCS; 1270 - } 1271 - 1272 - pTxWI->AMPDU = ((pMacEntry->NoBADataCountDown == 0) ? TRUE: FALSE); 1273 - pTxWI->MIMOps = 0; 1274 - 1275 - if (pAd->CommonCfg.bMIMOPSEnable) 1276 - { 1277 - // MIMO Power Save Mode 1278 - if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) && (pTransmit->field.MCS > 7)) 1279 - { 1280 - // Dynamic MIMO Power Save Mode 1281 - pTxWI->MIMOps = 1; 1282 - } 1283 - else if (pMacEntry->MmpsMode == MMPS_STATIC) 1284 - { 1285 - // Static MIMO Power Save Mode 1286 - if ((pTransmit->field.MODE >= MODE_HTMIX) && (pTransmit->field.MCS > 7)) 1287 - { 1288 - pTxWI->MCS = 7; 1289 - pTxWI->MIMOps = 0; 1290 - } 1291 - } 1292 - } 1293 - 1294 - #ifdef DBG_DIAGNOSE 1295 - if (pTxBlk->QueIdx== 0) 1296 - { 1297 - pAd->DiagStruct.TxDataCnt[pAd->DiagStruct.ArrayCurIdx]++; 1298 - pAd->DiagStruct.TxMcsCnt[pAd->DiagStruct.ArrayCurIdx][pTxWI->MCS]++; 1299 - } 1300 - #endif // DBG_DIAGNOSE // 1301 - 1302 - pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; 1303 - 1304 - } 1305 - 1306 - 1307 - /* 1308 - ======================================================================== 1309 - 1310 - Routine Description: 1311 - Calculates the duration which is required to transmit out frames 1312 - with given size and specified rate. 1313 - 1314 - Arguments: 1315 - pTxD Pointer to transmit descriptor 1316 - Ack Setting for Ack requirement bit 1317 - Fragment Setting for Fragment bit 1318 - RetryMode Setting for retry mode 1319 - Ifs Setting for IFS gap 1320 - Rate Setting for transmit rate 1321 - Service Setting for service 1322 - Length Frame length 1323 - TxPreamble Short or Long preamble when using CCK rates 1324 - QueIdx - 0-3, according to 802.11e/d4.4 June/2003 1325 - 1326 - Return Value: 1327 - None 1328 - 1329 - IRQL = PASSIVE_LEVEL 1330 - IRQL = DISPATCH_LEVEL 1331 - 1332 - ======================================================================== 1333 - */ 1334 - VOID RTMPWriteTxDescriptor( 1335 - IN PRTMP_ADAPTER pAd, 1336 - IN PTXD_STRUC pTxD, 1337 - IN BOOLEAN bWIV, 1338 - IN UCHAR QueueSEL) 1339 - { 1340 - // 1341 - // Always use Long preamble before verifiation short preamble functionality works well. 1342 - // Todo: remove the following line if short preamble functionality works 1343 - // 1344 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); 1345 - 1346 - pTxD->WIV = (bWIV) ? 1: 0; 1347 - pTxD->QSEL= (QueueSEL); 1348 - if (pAd->bGenOneHCCA == TRUE) 1349 - pTxD->QSEL= FIFO_HCCA; 1350 - pTxD->DMADONE = 0; 1351 - } 1352 - 1353 - 1354 - // should be called only when - 1355 - // 1. MEADIA_CONNECTED 1356 - // 2. AGGREGATION_IN_USED 1357 - // 3. Fragmentation not in used 1358 - // 4. either no previous frame (pPrevAddr1=NULL) .OR. previoud frame is aggregatible 1359 - BOOLEAN TxFrameIsAggregatible( 1360 - IN PRTMP_ADAPTER pAd, 1361 - IN PUCHAR pPrevAddr1, 1362 - IN PUCHAR p8023hdr) 1363 - { 1364 - 1365 - // can't aggregate EAPOL (802.1x) frame 1366 - if ((p8023hdr[12] == 0x88) && (p8023hdr[13] == 0x8e)) 1367 - return FALSE; 1368 - 1369 - // can't aggregate multicast/broadcast frame 1370 - if (p8023hdr[0] & 0x01) 1371 - return FALSE; 1372 - 1373 - if (INFRA_ON(pAd)) // must be unicast to AP 1374 - return TRUE; 1375 - else if ((pPrevAddr1 == NULL) || MAC_ADDR_EQUAL(pPrevAddr1, p8023hdr)) // unicast to same STA 1376 - return TRUE; 1377 - else 1378 - return FALSE; 1379 - } 1380 - 1381 - 1382 - /* 1383 - ======================================================================== 1384 - 1385 - Routine Description: 1386 - Check the MSDU Aggregation policy 1387 - 1.HT aggregation is A-MSDU 1388 - 2.legaacy rate aggregation is software aggregation by Ralink. 1389 - 1390 - Arguments: 1391 - 1392 - Return Value: 1393 - 1394 - Note: 1395 - 1396 - ======================================================================== 1397 - */ 1398 - BOOLEAN PeerIsAggreOn( 1399 - IN PRTMP_ADAPTER pAd, 1400 - IN ULONG TxRate, 1401 - IN PMAC_TABLE_ENTRY pMacEntry) 1402 - { 1403 - ULONG AFlags = (fCLIENT_STATUS_AMSDU_INUSED | fCLIENT_STATUS_AGGREGATION_CAPABLE); 1404 - 1405 - if (pMacEntry != NULL && CLIENT_STATUS_TEST_FLAG(pMacEntry, AFlags)) 1406 - { 1407 - if (pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX) 1408 - { 1409 - return TRUE; 1410 - } 1411 - 1412 - #ifdef AGGREGATION_SUPPORT 1413 - if (TxRate >= RATE_6 && pAd->CommonCfg.bAggregationCapable && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) 1414 - { // legacy Ralink Aggregation support 1415 - return TRUE; 1416 - } 1417 - #endif // AGGREGATION_SUPPORT // 1418 - } 1419 - 1420 - return FALSE; 1421 - 1422 - } 1423 - 1424 - /* 1425 - ======================================================================== 1426 - 1427 - Routine Description: 1428 - Check and fine the packet waiting in SW queue with highest priority 1429 - 1430 - Arguments: 1431 - pAd Pointer to our adapter 1432 - 1433 - Return Value: 1434 - pQueue Pointer to Waiting Queue 1435 - 1436 - IRQL = DISPATCH_LEVEL 1437 - 1438 - Note: 1439 - 1440 - ======================================================================== 1441 - */ 1442 - PQUEUE_HEADER RTMPCheckTxSwQueue( 1443 - IN PRTMP_ADAPTER pAd, 1444 - OUT PUCHAR pQueIdx) 1445 - { 1446 - ULONG Number; 1447 - 1448 - Number = pAd->TxSwQueue[QID_AC_BK].Number 1449 - + pAd->TxSwQueue[QID_AC_BE].Number 1450 - + pAd->TxSwQueue[QID_AC_VI].Number 1451 - + pAd->TxSwQueue[QID_AC_VO].Number 1452 - + pAd->TxSwQueue[QID_HCCA].Number; 1453 - 1454 - if (pAd->TxSwQueue[QID_AC_VO].Head != NULL) 1455 - { 1456 - *pQueIdx = QID_AC_VO; 1457 - return (&pAd->TxSwQueue[QID_AC_VO]); 1458 - } 1459 - else if (pAd->TxSwQueue[QID_AC_VI].Head != NULL) 1460 - { 1461 - *pQueIdx = QID_AC_VI; 1462 - return (&pAd->TxSwQueue[QID_AC_VI]); 1463 - } 1464 - else if (pAd->TxSwQueue[QID_AC_BE].Head != NULL) 1465 - { 1466 - *pQueIdx = QID_AC_BE; 1467 - return (&pAd->TxSwQueue[QID_AC_BE]); 1468 - } 1469 - else if (pAd->TxSwQueue[QID_AC_BK].Head != NULL) 1470 - { 1471 - *pQueIdx = QID_AC_BK; 1472 - return (&pAd->TxSwQueue[QID_AC_BK]); 1473 - } 1474 - else if (pAd->TxSwQueue[QID_HCCA].Head != NULL) 1475 - { 1476 - *pQueIdx = QID_HCCA; 1477 - return (&pAd->TxSwQueue[QID_HCCA]); 1478 - } 1479 - 1480 - // No packet pending in Tx Sw queue 1481 - *pQueIdx = QID_AC_BK; 1482 - 1483 - return (NULL); 1484 - } 1485 - 1486 - 1487 - 1488 - /* 1489 - ======================================================================== 1490 - 1491 - Routine Description: 1492 - Suspend MSDU transmission 1493 - 1494 - Arguments: 1495 - pAd Pointer to our adapter 1496 - 1497 - Return Value: 1498 - None 1499 - 1500 - Note: 1501 - 1502 - ======================================================================== 1503 - */ 1504 - VOID RTMPSuspendMsduTransmission( 1505 - IN PRTMP_ADAPTER pAd) 1506 - { 1507 - DBGPRINT(RT_DEBUG_TRACE,("SCANNING, suspend MSDU transmission ...\n")); 1508 - 1509 - 1510 - // 1511 - // Before BSS_SCAN_IN_PROGRESS, we need to keep Current R66 value and 1512 - // use Lowbound as R66 value on ScanNextChannel(...) 1513 - // 1514 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue); 1515 - 1516 - // set BBP_R66 to 0x30/0x40 when scanning (AsicSwitchChannel will set R66 according to channel when scanning) 1517 - RTMPSetAGCInitValue(pAd, BW_20); 1518 - 1519 - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); 1520 - } 1521 - 1522 - /* 1523 - ======================================================================== 1524 - 1525 - Routine Description: 1526 - Resume MSDU transmission 1527 - 1528 - Arguments: 1529 - pAd Pointer to our adapter 1530 - 1531 - Return Value: 1532 - None 1533 - 1534 - IRQL = DISPATCH_LEVEL 1535 - 1536 - Note: 1537 - 1538 - ======================================================================== 1539 - */ 1540 - VOID RTMPResumeMsduTransmission( 1541 - IN PRTMP_ADAPTER pAd) 1542 - { 1543 - DBGPRINT(RT_DEBUG_TRACE,("SCAN done, resume MSDU transmission ...\n")); 1544 - 1545 - #ifdef RT30xx 1546 - // After finish BSS_SCAN_IN_PROGRESS, we need to restore Current R66 value 1547 - // R66 should not be 0 1548 - if (pAd->BbpTuning.R66CurrentValue == 0) 1549 - { 1550 - pAd->BbpTuning.R66CurrentValue = 0x38; 1551 - DBGPRINT_ERR(("RTMPResumeMsduTransmission, R66CurrentValue=0...\n")); 1552 - } 1553 - #endif 1554 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, pAd->BbpTuning.R66CurrentValue); 1555 - 1556 - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); 1557 - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); 1558 - } 1559 - 1560 - 1561 - UINT deaggregate_AMSDU_announce( 1562 - IN PRTMP_ADAPTER pAd, 1563 - PNDIS_PACKET pPacket, 1564 - IN PUCHAR pData, 1565 - IN ULONG DataSize) 1566 - { 1567 - USHORT PayloadSize; 1568 - USHORT SubFrameSize; 1569 - PHEADER_802_3 pAMSDUsubheader; 1570 - UINT nMSDU; 1571 - UCHAR Header802_3[14]; 1572 - 1573 - PUCHAR pPayload, pDA, pSA, pRemovedLLCSNAP; 1574 - PNDIS_PACKET pClonePacket; 1575 - 1576 - 1577 - 1578 - nMSDU = 0; 1579 - 1580 - while (DataSize > LENGTH_802_3) 1581 - { 1582 - 1583 - nMSDU++; 1584 - 1585 - pAMSDUsubheader = (PHEADER_802_3)pData; 1586 - PayloadSize = pAMSDUsubheader->Octet[1] + (pAMSDUsubheader->Octet[0]<<8); 1587 - SubFrameSize = PayloadSize + LENGTH_802_3; 1588 - 1589 - 1590 - if ((DataSize < SubFrameSize) || (PayloadSize > 1518 )) 1591 - { 1592 - break; 1593 - } 1594 - 1595 - pPayload = pData + LENGTH_802_3; 1596 - pDA = pData; 1597 - pSA = pData + MAC_ADDR_LEN; 1598 - 1599 - // convert to 802.3 header 1600 - CONVERT_TO_802_3(Header802_3, pDA, pSA, pPayload, PayloadSize, pRemovedLLCSNAP); 1601 - 1602 - if ((Header802_3[12] == 0x88) && (Header802_3[13] == 0x8E) ) 1603 - { 1604 - // avoid local heap overflow, use dyanamic allocation 1605 - MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); 1606 - memmove(Elem->Msg+(LENGTH_802_11 + LENGTH_802_1_H), pPayload, PayloadSize); 1607 - Elem->MsgLen = LENGTH_802_11 + LENGTH_802_1_H + PayloadSize; 1608 - WpaEAPOLKeyAction(pAd, Elem); 1609 - kfree(Elem); 1610 - } 1611 - 1612 - { 1613 - if (pRemovedLLCSNAP) 1614 - { 1615 - pPayload -= LENGTH_802_3; 1616 - PayloadSize += LENGTH_802_3; 1617 - NdisMoveMemory(pPayload, &Header802_3[0], LENGTH_802_3); 1618 - } 1619 - } 1620 - 1621 - pClonePacket = ClonePacket(pAd, pPacket, pPayload, PayloadSize); 1622 - if (pClonePacket) 1623 - { 1624 - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pClonePacket, RTMP_GET_PACKET_IF(pPacket)); 1625 - } 1626 - 1627 - 1628 - // A-MSDU has padding to multiple of 4 including subframe header. 1629 - // align SubFrameSize up to multiple of 4 1630 - SubFrameSize = (SubFrameSize+3)&(~0x3); 1631 - 1632 - 1633 - if (SubFrameSize > 1528 || SubFrameSize < 32) 1634 - { 1635 - break; 1636 - } 1637 - 1638 - if (DataSize > SubFrameSize) 1639 - { 1640 - pData += SubFrameSize; 1641 - DataSize -= SubFrameSize; 1642 - } 1643 - else 1644 - { 1645 - // end of A-MSDU 1646 - DataSize = 0; 1647 - } 1648 - } 1649 - 1650 - // finally release original rx packet 1651 - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); 1652 - 1653 - return nMSDU; 1654 - } 1655 - 1656 - 1657 - UINT BA_Reorder_AMSDU_Annnounce( 1658 - IN PRTMP_ADAPTER pAd, 1659 - IN PNDIS_PACKET pPacket) 1660 - { 1661 - PUCHAR pData; 1662 - USHORT DataSize; 1663 - UINT nMSDU = 0; 1664 - 1665 - pData = (PUCHAR) GET_OS_PKT_DATAPTR(pPacket); 1666 - DataSize = (USHORT) GET_OS_PKT_LEN(pPacket); 1667 - 1668 - nMSDU = deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize); 1669 - 1670 - return nMSDU; 1671 - } 1672 - 1673 - 1674 - /* 1675 - ========================================================================== 1676 - Description: 1677 - Look up the MAC address in the MAC table. Return NULL if not found. 1678 - Return: 1679 - pEntry - pointer to the MAC entry; NULL is not found 1680 - ========================================================================== 1681 - */ 1682 - MAC_TABLE_ENTRY *MacTableLookup( 1683 - IN PRTMP_ADAPTER pAd, 1684 - PUCHAR pAddr) 1685 - { 1686 - ULONG HashIdx; 1687 - MAC_TABLE_ENTRY *pEntry = NULL; 1688 - 1689 - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); 1690 - pEntry = pAd->MacTab.Hash[HashIdx]; 1691 - 1692 - while (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsWDS || pEntry->ValidAsApCli || pEntry->ValidAsMesh)) 1693 - { 1694 - if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) 1695 - { 1696 - break; 1697 - } 1698 - else 1699 - pEntry = pEntry->pNext; 1700 - } 1701 - 1702 - return pEntry; 1703 - } 1704 - 1705 - MAC_TABLE_ENTRY *MacTableInsertEntry( 1706 - IN PRTMP_ADAPTER pAd, 1707 - IN PUCHAR pAddr, 1708 - IN UCHAR apidx, 1709 - IN BOOLEAN CleanAll) 1710 - { 1711 - UCHAR HashIdx; 1712 - int i, FirstWcid; 1713 - MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry; 1714 - 1715 - // if FULL, return 1716 - if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE) 1717 - return NULL; 1718 - 1719 - FirstWcid = 1; 1720 - 1721 - if (pAd->StaCfg.BssType == BSS_INFRA) 1722 - FirstWcid = 2; 1723 - 1724 - // allocate one MAC entry 1725 - NdisAcquireSpinLock(&pAd->MacTabLock); 1726 - for (i = FirstWcid; i< MAX_LEN_OF_MAC_TABLE; i++) // skip entry#0 so that "entry index == AID" for fast lookup 1727 - { 1728 - // pick up the first available vacancy 1729 - if ((pAd->MacTab.Content[i].ValidAsCLI == FALSE) && 1730 - (pAd->MacTab.Content[i].ValidAsWDS == FALSE) && 1731 - (pAd->MacTab.Content[i].ValidAsApCli== FALSE) && 1732 - (pAd->MacTab.Content[i].ValidAsMesh == FALSE) 1733 - ) 1734 - { 1735 - pEntry = &pAd->MacTab.Content[i]; 1736 - if (CleanAll == TRUE) 1737 - { 1738 - pEntry->MaxSupportedRate = RATE_11; 1739 - pEntry->CurrTxRate = RATE_11; 1740 - NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY)); 1741 - pEntry->PairwiseKey.KeyLen = 0; 1742 - pEntry->PairwiseKey.CipherAlg = CIPHER_NONE; 1743 - } 1744 - { 1745 - { 1746 - pEntry->ValidAsCLI = TRUE; 1747 - pEntry->ValidAsWDS = FALSE; 1748 - pEntry->ValidAsApCli = FALSE; 1749 - pEntry->ValidAsMesh = FALSE; 1750 - pEntry->ValidAsDls = FALSE; 1751 - } 1752 - } 1753 - 1754 - pEntry->bIAmBadAtheros = FALSE; 1755 - pEntry->pAd = pAd; 1756 - pEntry->CMTimerRunning = FALSE; 1757 - pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE; 1758 - pEntry->RSNIE_Len = 0; 1759 - NdisZeroMemory(pEntry->R_Counter, sizeof(pEntry->R_Counter)); 1760 - pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR; 1761 - 1762 - if (pEntry->ValidAsMesh) 1763 - pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_MESH); 1764 - else if (pEntry->ValidAsApCli) 1765 - pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_APCLI); 1766 - else if (pEntry->ValidAsWDS) 1767 - pEntry->apidx = (apidx - MIN_NET_DEVICE_FOR_WDS); 1768 - else 1769 - pEntry->apidx = apidx; 1770 - 1771 - { 1772 - { 1773 - pEntry->AuthMode = pAd->StaCfg.AuthMode; 1774 - pEntry->WepStatus = pAd->StaCfg.WepStatus; 1775 - pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll; 1776 - } 1777 - } 1778 - 1779 - pEntry->GTKState = REKEY_NEGOTIATING; 1780 - pEntry->PairwiseKey.KeyLen = 0; 1781 - pEntry->PairwiseKey.CipherAlg = CIPHER_NONE; 1782 - pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED; 1783 - pEntry->PMKID_CacheIdx = ENTRY_NOT_FOUND; 1784 - COPY_MAC_ADDR(pEntry->Addr, pAddr); 1785 - pEntry->Sst = SST_NOT_AUTH; 1786 - pEntry->AuthState = AS_NOT_AUTH; 1787 - pEntry->Aid = (USHORT)i; //0; 1788 - pEntry->CapabilityInfo = 0; 1789 - pEntry->PsMode = PWR_ACTIVE; 1790 - pEntry->PsQIdleCount = 0; 1791 - pEntry->NoDataIdleCount = 0; 1792 - pEntry->ContinueTxFailCnt = 0; 1793 - InitializeQueueHeader(&pEntry->PsQueue); 1794 - 1795 - 1796 - pAd->MacTab.Size ++; 1797 - // Add this entry into ASIC RX WCID search table 1798 - RT28XX_STA_ENTRY_ADD(pAd, pEntry); 1799 - 1800 - DBGPRINT(RT_DEBUG_TRACE, ("MacTableInsertEntry - allocate entry #%d, Total= %d\n",i, pAd->MacTab.Size)); 1801 - break; 1802 - } 1803 - } 1804 - 1805 - // add this MAC entry into HASH table 1806 - if (pEntry) 1807 - { 1808 - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); 1809 - if (pAd->MacTab.Hash[HashIdx] == NULL) 1810 - { 1811 - pAd->MacTab.Hash[HashIdx] = pEntry; 1812 - } 1813 - else 1814 - { 1815 - pCurrEntry = pAd->MacTab.Hash[HashIdx]; 1816 - while (pCurrEntry->pNext != NULL) 1817 - pCurrEntry = pCurrEntry->pNext; 1818 - pCurrEntry->pNext = pEntry; 1819 - } 1820 - } 1821 - 1822 - NdisReleaseSpinLock(&pAd->MacTabLock); 1823 - return pEntry; 1824 - } 1825 - 1826 - /* 1827 - ========================================================================== 1828 - Description: 1829 - Delete a specified client from MAC table 1830 - ========================================================================== 1831 - */ 1832 - BOOLEAN MacTableDeleteEntry( 1833 - IN PRTMP_ADAPTER pAd, 1834 - IN USHORT wcid, 1835 - IN PUCHAR pAddr) 1836 - { 1837 - USHORT HashIdx; 1838 - MAC_TABLE_ENTRY *pEntry, *pPrevEntry, *pProbeEntry; 1839 - BOOLEAN Cancelled; 1840 - 1841 - if (wcid >= MAX_LEN_OF_MAC_TABLE) 1842 - return FALSE; 1843 - 1844 - NdisAcquireSpinLock(&pAd->MacTabLock); 1845 - 1846 - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); 1847 - pEntry = &pAd->MacTab.Content[wcid]; 1848 - 1849 - if (pEntry && (pEntry->ValidAsCLI || pEntry->ValidAsApCli || pEntry->ValidAsWDS || pEntry->ValidAsMesh 1850 - )) 1851 - { 1852 - if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) 1853 - { 1854 - 1855 - // Delete this entry from ASIC on-chip WCID Table 1856 - RT28XX_STA_ENTRY_MAC_RESET(pAd, wcid); 1857 - 1858 - // free resources of BA 1859 - BASessionTearDownALL(pAd, pEntry->Aid); 1860 - 1861 - pPrevEntry = NULL; 1862 - pProbeEntry = pAd->MacTab.Hash[HashIdx]; 1863 - ASSERT(pProbeEntry); 1864 - 1865 - // update Hash list 1866 - do 1867 - { 1868 - if (pProbeEntry == pEntry) 1869 - { 1870 - if (pPrevEntry == NULL) 1871 - { 1872 - pAd->MacTab.Hash[HashIdx] = pEntry->pNext; 1873 - } 1874 - else 1875 - { 1876 - pPrevEntry->pNext = pEntry->pNext; 1877 - } 1878 - break; 1879 - } 1880 - 1881 - pPrevEntry = pProbeEntry; 1882 - pProbeEntry = pProbeEntry->pNext; 1883 - } while (pProbeEntry); 1884 - 1885 - // not found !!! 1886 - ASSERT(pProbeEntry != NULL); 1887 - 1888 - RT28XX_STA_ENTRY_KEY_DEL(pAd, BSS0, wcid); 1889 - 1890 - 1891 - if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE) 1892 - { 1893 - RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled); 1894 - pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE; 1895 - } 1896 - 1897 - 1898 - NdisZeroMemory(pEntry, sizeof(MAC_TABLE_ENTRY)); 1899 - pAd->MacTab.Size --; 1900 - DBGPRINT(RT_DEBUG_TRACE, ("MacTableDeleteEntry1 - Total= %d\n", pAd->MacTab.Size)); 1901 - } 1902 - else 1903 - { 1904 - printk("\n%s: Impossible Wcid = %d !!!!!\n", __func__, wcid); 1905 - } 1906 - } 1907 - 1908 - NdisReleaseSpinLock(&pAd->MacTabLock); 1909 - 1910 - //Reset operating mode when no Sta. 1911 - if (pAd->MacTab.Size == 0) 1912 - { 1913 - pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode = 0; 1914 - #ifndef RT30xx 1915 - AsicUpdateProtect(pAd, 0 /*pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode*/, (ALLN_SETPROTECT), TRUE, 0 /*pAd->MacTab.fAnyStationNonGF*/); 1916 - #endif 1917 - #ifdef RT30xx 1918 - RT28XX_UPDATE_PROTECT(pAd); // edit by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet 1919 - #endif 1920 - } 1921 - 1922 - return TRUE; 1923 - } 1924 - 1925 - 1926 - /* 1927 - ========================================================================== 1928 - Description: 1929 - This routine reset the entire MAC table. All packets pending in 1930 - the power-saving queues are freed here. 1931 - ========================================================================== 1932 - */ 1933 - VOID MacTableReset( 1934 - IN PRTMP_ADAPTER pAd) 1935 - { 1936 - int i; 1937 - 1938 - DBGPRINT(RT_DEBUG_TRACE, ("MacTableReset\n")); 1939 - //NdisAcquireSpinLock(&pAd->MacTabLock); 1940 - 1941 - for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++) 1942 - { 1943 - if (pAd->MacTab.Content[i].ValidAsCLI == TRUE) 1944 - { 1945 - // free resources of BA 1946 - BASessionTearDownALL(pAd, i); 1947 - 1948 - pAd->MacTab.Content[i].ValidAsCLI = FALSE; 1949 - 1950 - 1951 - 1952 - #ifdef RT2870 1953 - NdisZeroMemory(pAd->MacTab.Content[i].Addr, 6); 1954 - RT28XX_STA_ENTRY_MAC_RESET(pAd, i); 1955 - #endif // RT2870 // 1956 - 1957 - //AsicDelWcidTab(pAd, i); 1958 - } 1959 - } 1960 - 1961 - return; 1962 - } 1963 - 1964 - /* 1965 - ========================================================================== 1966 - Description: 1967 - 1968 - IRQL = DISPATCH_LEVEL 1969 - 1970 - ========================================================================== 1971 - */ 1972 - VOID AssocParmFill( 1973 - IN PRTMP_ADAPTER pAd, 1974 - IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq, 1975 - IN PUCHAR pAddr, 1976 - IN USHORT CapabilityInfo, 1977 - IN ULONG Timeout, 1978 - IN USHORT ListenIntv) 1979 - { 1980 - COPY_MAC_ADDR(AssocReq->Addr, pAddr); 1981 - // Add mask to support 802.11b mode only 1982 - AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; // not cf-pollable, not cf-poll-request 1983 - AssocReq->Timeout = Timeout; 1984 - AssocReq->ListenIntv = ListenIntv; 1985 - } 1986 - 1987 - 1988 - /* 1989 - ========================================================================== 1990 - Description: 1991 - 1992 - IRQL = DISPATCH_LEVEL 1993 - 1994 - ========================================================================== 1995 - */ 1996 - VOID DisassocParmFill( 1997 - IN PRTMP_ADAPTER pAd, 1998 - IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq, 1999 - IN PUCHAR pAddr, 2000 - IN USHORT Reason) 2001 - { 2002 - COPY_MAC_ADDR(DisassocReq->Addr, pAddr); 2003 - DisassocReq->Reason = Reason; 2004 - } 2005 - 2006 - 2007 - /* 2008 - ======================================================================== 2009 - 2010 - Routine Description: 2011 - Check the out going frame, if this is an DHCP or ARP datagram 2012 - will be duplicate another frame at low data rate transmit. 2013 - 2014 - Arguments: 2015 - pAd Pointer to our adapter 2016 - pPacket Pointer to outgoing Ndis frame 2017 - 2018 - Return Value: 2019 - TRUE To be duplicate at Low data rate transmit. (1mb) 2020 - FALSE Do nothing. 2021 - 2022 - IRQL = DISPATCH_LEVEL 2023 - 2024 - Note: 2025 - 2026 - MAC header + IP Header + UDP Header 2027 - 14 Bytes 20 Bytes 2028 - 2029 - UDP Header 2030 - 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| 2031 - Source Port 2032 - 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31| 2033 - Destination Port 2034 - 2035 - port 0x43 means Bootstrap Protocol, server. 2036 - Port 0x44 means Bootstrap Protocol, client. 2037 - 2038 - ======================================================================== 2039 - */ 2040 - 2041 - BOOLEAN RTMPCheckDHCPFrame( 2042 - IN PRTMP_ADAPTER pAd, 2043 - IN PNDIS_PACKET pPacket) 2044 - { 2045 - PACKET_INFO PacketInfo; 2046 - ULONG NumberOfBytesRead = 0; 2047 - ULONG CurrentOffset = 0; 2048 - PVOID pVirtualAddress = NULL; 2049 - UINT NdisBufferLength; 2050 - PUCHAR pSrc; 2051 - USHORT Protocol; 2052 - UCHAR ByteOffset36 = 0; 2053 - UCHAR ByteOffset38 = 0; 2054 - BOOLEAN ReadFirstParm = TRUE; 2055 - 2056 - RTMP_QueryPacketInfo(pPacket, &PacketInfo, (PUCHAR *)&pVirtualAddress, &NdisBufferLength); 2057 - 2058 - NumberOfBytesRead += NdisBufferLength; 2059 - pSrc = (PUCHAR) pVirtualAddress; 2060 - Protocol = *(pSrc + 12) * 256 + *(pSrc + 13); 2061 - 2062 - // 2063 - // Check DHCP & BOOTP protocol 2064 - // 2065 - while (NumberOfBytesRead <= PacketInfo.TotalPacketLength) 2066 - { 2067 - if ((NumberOfBytesRead >= 35) && (ReadFirstParm == TRUE)) 2068 - { 2069 - CurrentOffset = 35 - (NumberOfBytesRead - NdisBufferLength); 2070 - ByteOffset36 = *(pSrc + CurrentOffset); 2071 - ReadFirstParm = FALSE; 2072 - } 2073 - 2074 - if (NumberOfBytesRead >= 37) 2075 - { 2076 - CurrentOffset = 37 - (NumberOfBytesRead - NdisBufferLength); 2077 - ByteOffset38 = *(pSrc + CurrentOffset); 2078 - //End of Read 2079 - break; 2080 - } 2081 - return FALSE; 2082 - } 2083 - 2084 - // Check for DHCP & BOOTP protocol 2085 - if ((ByteOffset36 != 0x44) || (ByteOffset38 != 0x43)) 2086 - { 2087 - // 2088 - // 2054 (hex 0806) for ARP datagrams 2089 - // if this packet is not ARP datagrams, then do nothing 2090 - // ARP datagrams will also be duplicate at 1mb broadcast frames 2091 - // 2092 - if (Protocol != 0x0806 ) 2093 - return FALSE; 2094 - } 2095 - 2096 - return TRUE; 2097 - } 2098 - 2099 - 2100 - BOOLEAN RTMPCheckEtherType( 2101 - IN PRTMP_ADAPTER pAd, 2102 - IN PNDIS_PACKET pPacket) 2103 - { 2104 - USHORT TypeLen; 2105 - UCHAR Byte0, Byte1; 2106 - PUCHAR pSrcBuf; 2107 - UINT32 pktLen; 2108 - UINT16 srcPort, dstPort; 2109 - BOOLEAN status = TRUE; 2110 - 2111 - 2112 - pSrcBuf = GET_OS_PKT_DATAPTR(pPacket); 2113 - pktLen = GET_OS_PKT_LEN(pPacket); 2114 - 2115 - ASSERT(pSrcBuf); 2116 - 2117 - RTMP_SET_PACKET_SPECIFIC(pPacket, 0); 2118 - 2119 - // get Ethernet protocol field 2120 - TypeLen = (pSrcBuf[12] << 8) + pSrcBuf[13]; 2121 - 2122 - pSrcBuf += LENGTH_802_3; // Skip the Ethernet Header. 2123 - 2124 - if (TypeLen <= 1500) 2125 - { // 802.3, 802.3 LLC 2126 - /* 2127 - DestMAC(6) + SrcMAC(6) + Lenght(2) + 2128 - DSAP(1) + SSAP(1) + Control(1) + 2129 - if the DSAP = 0xAA, SSAP=0xAA, Contorl = 0x03, it has a 5-bytes SNAP header. 2130 - => + SNAP (5, OriginationID(3) + etherType(2)) 2131 - */ 2132 - if (pSrcBuf[0] == 0xAA && pSrcBuf[1] == 0xAA && pSrcBuf[2] == 0x03) 2133 - { 2134 - Sniff2BytesFromNdisBuffer(pSrcBuf, 6, &Byte0, &Byte1); 2135 - RTMP_SET_PACKET_LLCSNAP(pPacket, 1); 2136 - TypeLen = (USHORT)((Byte0 << 8) + Byte1); 2137 - pSrcBuf += 8; // Skip this LLC/SNAP header 2138 - } 2139 - else 2140 - { 2141 - //It just has 3-byte LLC header, maybe a legacy ether type frame. we didn't handle it. 2142 - } 2143 - } 2144 - 2145 - // If it's a VLAN packet, get the real Type/Length field. 2146 - if (TypeLen == 0x8100) 2147 - { 2148 - /* 0x8100 means VLAN packets */ 2149 - 2150 - /* Dest. MAC Address (6-bytes) + 2151 - Source MAC Address (6-bytes) + 2152 - Length/Type = 802.1Q Tag Type (2-byte) + 2153 - Tag Control Information (2-bytes) + 2154 - Length / Type (2-bytes) + 2155 - data payload (0-n bytes) + 2156 - Pad (0-p bytes) + 2157 - Frame Check Sequence (4-bytes) */ 2158 - 2159 - RTMP_SET_PACKET_VLAN(pPacket, 1); 2160 - Sniff2BytesFromNdisBuffer(pSrcBuf, 2, &Byte0, &Byte1); 2161 - TypeLen = (USHORT)((Byte0 << 8) + Byte1); 2162 - 2163 - pSrcBuf += 4; // Skip the VLAN Header. 2164 - } 2165 - 2166 - switch (TypeLen) 2167 - { 2168 - case 0x0800: 2169 - { 2170 - ASSERT((pktLen > 34)); 2171 - if (*(pSrcBuf + 9) == 0x11) 2172 - { // udp packet 2173 - ASSERT((pktLen > 34)); // 14 for ethernet header, 20 for IP header 2174 - 2175 - pSrcBuf += 20; // Skip the IP header 2176 - srcPort = OS_NTOHS(*((UINT16 *)pSrcBuf)); 2177 - dstPort = OS_NTOHS(*((UINT16 *)(pSrcBuf +2))); 2178 - 2179 - if ((srcPort==0x44 && dstPort==0x43) || (srcPort==0x43 && dstPort==0x44)) 2180 - { //It's a BOOTP/DHCP packet 2181 - RTMP_SET_PACKET_DHCP(pPacket, 1); 2182 - } 2183 - } 2184 - } 2185 - break; 2186 - case 0x0806: 2187 - { 2188 - //ARP Packet. 2189 - RTMP_SET_PACKET_DHCP(pPacket, 1); 2190 - } 2191 - break; 2192 - case 0x888e: 2193 - { 2194 - // EAPOL Packet. 2195 - RTMP_SET_PACKET_EAPOL(pPacket, 1); 2196 - } 2197 - break; 2198 - default: 2199 - status = FALSE; 2200 - break; 2201 - } 2202 - 2203 - return status; 2204 - 2205 - } 2206 - 2207 - 2208 - 2209 - VOID Update_Rssi_Sample( 2210 - IN PRTMP_ADAPTER pAd, 2211 - IN RSSI_SAMPLE *pRssi, 2212 - IN PRXWI_STRUC pRxWI) 2213 - { 2214 - CHAR rssi0 = pRxWI->RSSI0; 2215 - CHAR rssi1 = pRxWI->RSSI1; 2216 - CHAR rssi2 = pRxWI->RSSI2; 2217 - 2218 - if (rssi0 != 0) 2219 - { 2220 - pRssi->LastRssi0 = ConvertToRssi(pAd, (CHAR)rssi0, RSSI_0); 2221 - pRssi->AvgRssi0X8 = (pRssi->AvgRssi0X8 - pRssi->AvgRssi0) + pRssi->LastRssi0; 2222 - pRssi->AvgRssi0 = pRssi->AvgRssi0X8 >> 3; 2223 - } 2224 - 2225 - if (rssi1 != 0) 2226 - { 2227 - pRssi->LastRssi1 = ConvertToRssi(pAd, (CHAR)rssi1, RSSI_1); 2228 - pRssi->AvgRssi1X8 = (pRssi->AvgRssi1X8 - pRssi->AvgRssi1) + pRssi->LastRssi1; 2229 - pRssi->AvgRssi1 = pRssi->AvgRssi1X8 >> 3; 2230 - } 2231 - 2232 - if (rssi2 != 0) 2233 - { 2234 - pRssi->LastRssi2 = ConvertToRssi(pAd, (CHAR)rssi2, RSSI_2); 2235 - pRssi->AvgRssi2X8 = (pRssi->AvgRssi2X8 - pRssi->AvgRssi2) + pRssi->LastRssi2; 2236 - pRssi->AvgRssi2 = pRssi->AvgRssi2X8 >> 3; 2237 - } 2238 - } 2239 - 2240 - 2241 - 2242 - // Normal legacy Rx packet indication 2243 - VOID Indicate_Legacy_Packet( 2244 - IN PRTMP_ADAPTER pAd, 2245 - IN RX_BLK *pRxBlk, 2246 - IN UCHAR FromWhichBSSID) 2247 - { 2248 - PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket; 2249 - UCHAR Header802_3[LENGTH_802_3]; 2250 - 2251 - // 1. get 802.3 Header 2252 - // 2. remove LLC 2253 - // a. pointer pRxBlk->pData to payload 2254 - // b. modify pRxBlk->DataSize 2255 - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); 2256 - 2257 - if (pRxBlk->DataSize > MAX_RX_PKT_LEN) 2258 - { 2259 - 2260 - // release packet 2261 - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); 2262 - return; 2263 - } 2264 - 2265 - 2266 - STATS_INC_RX_PACKETS(pAd, FromWhichBSSID); 2267 - 2268 - #ifdef RT2870 2269 - if (pAd->CommonCfg.bDisableReordering == 0) 2270 - { 2271 - PBA_REC_ENTRY pBAEntry; 2272 - ULONG Now32; 2273 - UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID; 2274 - UCHAR TID = pRxBlk->pRxWI->TID; 2275 - USHORT Idx; 2276 - 2277 - #define REORDERING_PACKET_TIMEOUT ((100 * HZ)/1000) // system ticks -- 100 ms 2278 - 2279 - if (Wcid < MAX_LEN_OF_MAC_TABLE) 2280 - { 2281 - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; 2282 - if (Idx != 0) 2283 - { 2284 - pBAEntry = &pAd->BATable.BARecEntry[Idx]; 2285 - // update last rx time 2286 - NdisGetSystemUpTime(&Now32); 2287 - if ((pBAEntry->list.qlen > 0) && 2288 - RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT))) 2289 - ) 2290 - { 2291 - printk("Indicate_Legacy_Packet():flush reordering_timeout_mpdus! RxWI->Flags=%d, pRxWI.TID=%d, RxD->AMPDU=%d!\n", pRxBlk->Flags, pRxBlk->pRxWI->TID, pRxBlk->RxD.AMPDU); 2292 - hex_dump("Dump the legacy Packet:", GET_OS_PKT_DATAPTR(pRxBlk->pRxPacket), 64); 2293 - ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32); 2294 - } 2295 - } 2296 - } 2297 - } 2298 - #endif // RT2870 // 2299 - 2300 - wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID); 2301 - 2302 - // 2303 - // pass this 802.3 packet to upper layer or forward this packet to WM directly 2304 - // 2305 - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxPacket, FromWhichBSSID); 2306 - } 2307 - 2308 - 2309 - // Normal, AMPDU or AMSDU 2310 - VOID CmmRxnonRalinkFrameIndicate( 2311 - IN PRTMP_ADAPTER pAd, 2312 - IN RX_BLK *pRxBlk, 2313 - IN UCHAR FromWhichBSSID) 2314 - { 2315 - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0)) 2316 - { 2317 - Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID); 2318 - } 2319 - else 2320 - { 2321 - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) 2322 - { 2323 - // handle A-MSDU 2324 - Indicate_AMSDU_Packet(pAd, pRxBlk, FromWhichBSSID); 2325 - } 2326 - else 2327 - { 2328 - Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); 2329 - } 2330 - } 2331 - } 2332 - 2333 - 2334 - VOID CmmRxRalinkFrameIndicate( 2335 - IN PRTMP_ADAPTER pAd, 2336 - IN MAC_TABLE_ENTRY *pEntry, 2337 - IN RX_BLK *pRxBlk, 2338 - IN UCHAR FromWhichBSSID) 2339 - { 2340 - UCHAR Header802_3[LENGTH_802_3]; 2341 - UINT16 Msdu2Size; 2342 - UINT16 Payload1Size, Payload2Size; 2343 - PUCHAR pData2; 2344 - PNDIS_PACKET pPacket2 = NULL; 2345 - 2346 - 2347 - 2348 - Msdu2Size = *(pRxBlk->pData) + (*(pRxBlk->pData+1) << 8); 2349 - 2350 - if ((Msdu2Size <= 1536) && (Msdu2Size < pRxBlk->DataSize)) 2351 - { 2352 - /* skip two byte MSDU2 len */ 2353 - pRxBlk->pData += 2; 2354 - pRxBlk->DataSize -= 2; 2355 - } 2356 - else 2357 - { 2358 - // release packet 2359 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 2360 - return; 2361 - } 2362 - 2363 - // get 802.3 Header and remove LLC 2364 - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); 2365 - 2366 - ASSERT(pRxBlk->pRxPacket); 2367 - 2368 - // Ralink Aggregation frame 2369 - pAd->RalinkCounters.OneSecRxAggregationCount ++; 2370 - Payload1Size = pRxBlk->DataSize - Msdu2Size; 2371 - Payload2Size = Msdu2Size - LENGTH_802_3; 2372 - 2373 - pData2 = pRxBlk->pData + Payload1Size + LENGTH_802_3; 2374 - 2375 - pPacket2 = duplicate_pkt(pAd, (pData2-LENGTH_802_3), LENGTH_802_3, pData2, Payload2Size, FromWhichBSSID); 2376 - 2377 - if (!pPacket2) 2378 - { 2379 - // release packet 2380 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 2381 - return; 2382 - } 2383 - 2384 - // update payload size of 1st packet 2385 - pRxBlk->DataSize = Payload1Size; 2386 - wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID); 2387 - 2388 - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxBlk->pRxPacket, FromWhichBSSID); 2389 - 2390 - if (pPacket2) 2391 - { 2392 - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket2, FromWhichBSSID); 2393 - } 2394 - } 2395 - 2396 - 2397 - #define RESET_FRAGFRAME(_fragFrame) \ 2398 - { \ 2399 - _fragFrame.RxSize = 0; \ 2400 - _fragFrame.Sequence = 0; \ 2401 - _fragFrame.LastFrag = 0; \ 2402 - _fragFrame.Flags = 0; \ 2403 - } 2404 - 2405 - 2406 - PNDIS_PACKET RTMPDeFragmentDataFrame( 2407 - IN PRTMP_ADAPTER pAd, 2408 - IN RX_BLK *pRxBlk) 2409 - { 2410 - PHEADER_802_11 pHeader = pRxBlk->pHeader; 2411 - PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket; 2412 - UCHAR *pData = pRxBlk->pData; 2413 - USHORT DataSize = pRxBlk->DataSize; 2414 - PNDIS_PACKET pRetPacket = NULL; 2415 - UCHAR *pFragBuffer = NULL; 2416 - BOOLEAN bReassDone = FALSE; 2417 - UCHAR HeaderRoom = 0; 2418 - 2419 - 2420 - ASSERT(pHeader); 2421 - 2422 - HeaderRoom = pData - (UCHAR *)pHeader; 2423 - 2424 - // Re-assemble the fragmented packets 2425 - if (pHeader->Frag == 0) // Frag. Number is 0 : First frag or only one pkt 2426 - { 2427 - // the first pkt of fragment, record it. 2428 - if (pHeader->FC.MoreFrag) 2429 - { 2430 - ASSERT(pAd->FragFrame.pFragPacket); 2431 - pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket); 2432 - pAd->FragFrame.RxSize = DataSize + HeaderRoom; 2433 - NdisMoveMemory(pFragBuffer, pHeader, pAd->FragFrame.RxSize); 2434 - pAd->FragFrame.Sequence = pHeader->Sequence; 2435 - pAd->FragFrame.LastFrag = pHeader->Frag; // Should be 0 2436 - ASSERT(pAd->FragFrame.LastFrag == 0); 2437 - goto done; // end of processing this frame 2438 - } 2439 - } 2440 - else //Middle & End of fragment 2441 - { 2442 - if ((pHeader->Sequence != pAd->FragFrame.Sequence) || 2443 - (pHeader->Frag != (pAd->FragFrame.LastFrag + 1))) 2444 - { 2445 - // Fragment is not the same sequence or out of fragment number order 2446 - // Reset Fragment control blk 2447 - RESET_FRAGFRAME(pAd->FragFrame); 2448 - DBGPRINT(RT_DEBUG_ERROR, ("Fragment is not the same sequence or out of fragment number order.\n")); 2449 - goto done; // give up this frame 2450 - } 2451 - else if ((pAd->FragFrame.RxSize + DataSize) > MAX_FRAME_SIZE) 2452 - { 2453 - // Fragment frame is too large, it exeeds the maximum frame size. 2454 - // Reset Fragment control blk 2455 - RESET_FRAGFRAME(pAd->FragFrame); 2456 - DBGPRINT(RT_DEBUG_ERROR, ("Fragment frame is too large, it exeeds the maximum frame size.\n")); 2457 - goto done; // give up this frame 2458 - } 2459 - 2460 - // 2461 - // Broadcom AP(BCM94704AGR) will send out LLC in fragment's packet, LLC only can accpet at first fragment. 2462 - // In this case, we will dropt it. 2463 - // 2464 - if (NdisEqualMemory(pData, SNAP_802_1H, sizeof(SNAP_802_1H))) 2465 - { 2466 - DBGPRINT(RT_DEBUG_ERROR, ("Find another LLC at Middle or End fragment(SN=%d, Frag=%d)\n", pHeader->Sequence, pHeader->Frag)); 2467 - goto done; // give up this frame 2468 - } 2469 - 2470 - pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket); 2471 - 2472 - // concatenate this fragment into the re-assembly buffer 2473 - NdisMoveMemory((pFragBuffer + pAd->FragFrame.RxSize), pData, DataSize); 2474 - pAd->FragFrame.RxSize += DataSize; 2475 - pAd->FragFrame.LastFrag = pHeader->Frag; // Update fragment number 2476 - 2477 - // Last fragment 2478 - if (pHeader->FC.MoreFrag == FALSE) 2479 - { 2480 - bReassDone = TRUE; 2481 - } 2482 - } 2483 - 2484 - done: 2485 - // always release rx fragmented packet 2486 - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); 2487 - 2488 - // return defragmented packet if packet is reassembled completely 2489 - // otherwise return NULL 2490 - if (bReassDone) 2491 - { 2492 - PNDIS_PACKET pNewFragPacket; 2493 - 2494 - // allocate a new packet buffer for fragment 2495 - pNewFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); 2496 - if (pNewFragPacket) 2497 - { 2498 - // update RxBlk 2499 - pRetPacket = pAd->FragFrame.pFragPacket; 2500 - pAd->FragFrame.pFragPacket = pNewFragPacket; 2501 - pRxBlk->pHeader = (PHEADER_802_11) GET_OS_PKT_DATAPTR(pRetPacket); 2502 - pRxBlk->pData = (UCHAR *)pRxBlk->pHeader + HeaderRoom; 2503 - pRxBlk->DataSize = pAd->FragFrame.RxSize - HeaderRoom; 2504 - pRxBlk->pRxPacket = pRetPacket; 2505 - } 2506 - else 2507 - { 2508 - RESET_FRAGFRAME(pAd->FragFrame); 2509 - } 2510 - } 2511 - 2512 - return pRetPacket; 2513 - } 2514 - 2515 - 2516 - VOID Indicate_AMSDU_Packet( 2517 - IN PRTMP_ADAPTER pAd, 2518 - IN RX_BLK *pRxBlk, 2519 - IN UCHAR FromWhichBSSID) 2520 - { 2521 - UINT nMSDU; 2522 - 2523 - update_os_packet_info(pAd, pRxBlk, FromWhichBSSID); 2524 - RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID); 2525 - nMSDU = deaggregate_AMSDU_announce(pAd, pRxBlk->pRxPacket, pRxBlk->pData, pRxBlk->DataSize); 2526 - } 2527 - 2528 - VOID Indicate_EAPOL_Packet( 2529 - IN PRTMP_ADAPTER pAd, 2530 - IN RX_BLK *pRxBlk, 2531 - IN UCHAR FromWhichBSSID) 2532 - { 2533 - MAC_TABLE_ENTRY *pEntry = NULL; 2534 - 2535 - { 2536 - pEntry = &pAd->MacTab.Content[BSSID_WCID]; 2537 - STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID); 2538 - return; 2539 - } 2540 - 2541 - if (pEntry == NULL) 2542 - { 2543 - DBGPRINT(RT_DEBUG_WARN, ("Indicate_EAPOL_Packet: drop and release the invalid packet.\n")); 2544 - // release packet 2545 - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); 2546 - return; 2547 - } 2548 - } 2549 - 2550 - #define BCN_TBTT_OFFSET 64 //defer 64 us 2551 - VOID ReSyncBeaconTime( 2552 - IN PRTMP_ADAPTER pAd) 2553 - { 2554 - 2555 - UINT32 Offset; 2556 - 2557 - 2558 - Offset = (pAd->TbttTickCount) % (BCN_TBTT_OFFSET); 2559 - 2560 - pAd->TbttTickCount++; 2561 - 2562 - // 2563 - // The updated BeaconInterval Value will affect Beacon Interval after two TBTT 2564 - // beacasue the original BeaconInterval had been loaded into next TBTT_TIMER 2565 - // 2566 - if (Offset == (BCN_TBTT_OFFSET-2)) 2567 - { 2568 - BCN_TIME_CFG_STRUC csr; 2569 - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); 2570 - csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod << 4) - 1 ; // ASIC register in units of 1/16 TU = 64us 2571 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); 2572 - } 2573 - else 2574 - { 2575 - if (Offset == (BCN_TBTT_OFFSET-1)) 2576 - { 2577 - BCN_TIME_CFG_STRUC csr; 2578 - 2579 - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); 2580 - csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod) << 4; // ASIC register in units of 1/16 TU 2581 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); 2582 - } 2583 - } 2584 - } 2585 - 1 + #include "../../rt2860/common/cmm_data.c"
+1 -3238
drivers/staging/rt2870/common/cmm_info.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - */ 27 - 28 - #include "../rt_config.h" 29 - 30 - INT Show_SSID_Proc( 31 - IN PRTMP_ADAPTER pAd, 32 - OUT PUCHAR pBuf); 33 - 34 - INT Show_WirelessMode_Proc( 35 - IN PRTMP_ADAPTER pAd, 36 - OUT PUCHAR pBuf); 37 - 38 - INT Show_TxBurst_Proc( 39 - IN PRTMP_ADAPTER pAd, 40 - OUT PUCHAR pBuf); 41 - 42 - INT Show_TxPreamble_Proc( 43 - IN PRTMP_ADAPTER pAd, 44 - OUT PUCHAR pBuf); 45 - 46 - INT Show_TxPower_Proc( 47 - IN PRTMP_ADAPTER pAd, 48 - OUT PUCHAR pBuf); 49 - 50 - INT Show_Channel_Proc( 51 - IN PRTMP_ADAPTER pAd, 52 - OUT PUCHAR pBuf); 53 - 54 - INT Show_BGProtection_Proc( 55 - IN PRTMP_ADAPTER pAd, 56 - OUT PUCHAR pBuf); 57 - 58 - INT Show_RTSThreshold_Proc( 59 - IN PRTMP_ADAPTER pAd, 60 - OUT PUCHAR pBuf); 61 - 62 - INT Show_FragThreshold_Proc( 63 - IN PRTMP_ADAPTER pAd, 64 - OUT PUCHAR pBuf); 65 - 66 - INT Show_HtBw_Proc( 67 - IN PRTMP_ADAPTER pAd, 68 - OUT PUCHAR pBuf); 69 - 70 - INT Show_HtMcs_Proc( 71 - IN PRTMP_ADAPTER pAd, 72 - OUT PUCHAR pBuf); 73 - 74 - INT Show_HtGi_Proc( 75 - IN PRTMP_ADAPTER pAd, 76 - OUT PUCHAR pBuf); 77 - 78 - INT Show_HtOpMode_Proc( 79 - IN PRTMP_ADAPTER pAd, 80 - OUT PUCHAR pBuf); 81 - 82 - INT Show_HtExtcha_Proc( 83 - IN PRTMP_ADAPTER pAd, 84 - OUT PUCHAR pBuf); 85 - 86 - INT Show_HtMpduDensity_Proc( 87 - IN PRTMP_ADAPTER pAd, 88 - OUT PUCHAR pBuf); 89 - 90 - INT Show_HtBaWinSize_Proc( 91 - IN PRTMP_ADAPTER pAd, 92 - OUT PUCHAR pBuf); 93 - 94 - INT Show_HtRdg_Proc( 95 - IN PRTMP_ADAPTER pAd, 96 - OUT PUCHAR pBuf); 97 - 98 - INT Show_HtAmsdu_Proc( 99 - IN PRTMP_ADAPTER pAd, 100 - OUT PUCHAR pBuf); 101 - 102 - INT Show_HtAutoBa_Proc( 103 - IN PRTMP_ADAPTER pAd, 104 - OUT PUCHAR pBuf); 105 - 106 - INT Show_CountryRegion_Proc( 107 - IN PRTMP_ADAPTER pAd, 108 - OUT PUCHAR pBuf); 109 - 110 - INT Show_CountryRegionABand_Proc( 111 - IN PRTMP_ADAPTER pAd, 112 - OUT PUCHAR pBuf); 113 - 114 - INT Show_CountryCode_Proc( 115 - IN PRTMP_ADAPTER pAd, 116 - OUT PUCHAR pBuf); 117 - 118 - #ifdef AGGREGATION_SUPPORT 119 - INT Show_PktAggregate_Proc( 120 - IN PRTMP_ADAPTER pAd, 121 - OUT PUCHAR pBuf); 122 - #endif // AGGREGATION_SUPPORT // 123 - 124 - #ifdef WMM_SUPPORT 125 - INT Show_WmmCapable_Proc( 126 - IN PRTMP_ADAPTER pAd, 127 - OUT PUCHAR pBuf); 128 - #endif // WMM_SUPPORT // 129 - 130 - INT Show_IEEE80211H_Proc( 131 - IN PRTMP_ADAPTER pAd, 132 - OUT PUCHAR pBuf); 133 - 134 - INT Show_NetworkType_Proc( 135 - IN PRTMP_ADAPTER pAd, 136 - OUT PUCHAR pBuf); 137 - 138 - INT Show_AuthMode_Proc( 139 - IN PRTMP_ADAPTER pAd, 140 - OUT PUCHAR pBuf); 141 - 142 - INT Show_EncrypType_Proc( 143 - IN PRTMP_ADAPTER pAd, 144 - OUT PUCHAR pBuf); 145 - 146 - INT Show_DefaultKeyID_Proc( 147 - IN PRTMP_ADAPTER pAd, 148 - OUT PUCHAR pBuf); 149 - 150 - INT Show_Key1_Proc( 151 - IN PRTMP_ADAPTER pAd, 152 - OUT PUCHAR pBuf); 153 - 154 - INT Show_Key2_Proc( 155 - IN PRTMP_ADAPTER pAd, 156 - OUT PUCHAR pBuf); 157 - 158 - INT Show_Key3_Proc( 159 - IN PRTMP_ADAPTER pAd, 160 - OUT PUCHAR pBuf); 161 - 162 - INT Show_Key4_Proc( 163 - IN PRTMP_ADAPTER pAd, 164 - OUT PUCHAR pBuf); 165 - 166 - INT Show_WPAPSK_Proc( 167 - IN PRTMP_ADAPTER pAd, 168 - OUT PUCHAR pBuf); 169 - 170 - static struct { 171 - CHAR *name; 172 - INT (*show_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg); 173 - } *PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC, RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC[] = { 174 - {"SSID", Show_SSID_Proc}, 175 - {"WirelessMode", Show_WirelessMode_Proc}, 176 - {"TxBurst", Show_TxBurst_Proc}, 177 - {"TxPreamble", Show_TxPreamble_Proc}, 178 - {"TxPower", Show_TxPower_Proc}, 179 - {"Channel", Show_Channel_Proc}, 180 - {"BGProtection", Show_BGProtection_Proc}, 181 - {"RTSThreshold", Show_RTSThreshold_Proc}, 182 - {"FragThreshold", Show_FragThreshold_Proc}, 183 - {"HtBw", Show_HtBw_Proc}, 184 - {"HtMcs", Show_HtMcs_Proc}, 185 - {"HtGi", Show_HtGi_Proc}, 186 - {"HtOpMode", Show_HtOpMode_Proc}, 187 - {"HtExtcha", Show_HtExtcha_Proc}, 188 - {"HtMpduDensity", Show_HtMpduDensity_Proc}, 189 - {"HtBaWinSize", Show_HtBaWinSize_Proc}, 190 - {"HtRdg", Show_HtRdg_Proc}, 191 - {"HtAmsdu", Show_HtAmsdu_Proc}, 192 - {"HtAutoBa", Show_HtAutoBa_Proc}, 193 - {"CountryRegion", Show_CountryRegion_Proc}, 194 - {"CountryRegionABand", Show_CountryRegionABand_Proc}, 195 - {"CountryCode", Show_CountryCode_Proc}, 196 - #ifdef AGGREGATION_SUPPORT 197 - {"PktAggregate", Show_PktAggregate_Proc}, 198 - #endif 199 - 200 - #ifdef WMM_SUPPORT 201 - {"WmmCapable", Show_WmmCapable_Proc}, 202 - #endif 203 - {"IEEE80211H", Show_IEEE80211H_Proc}, 204 - {"NetworkType", Show_NetworkType_Proc}, 205 - {"AuthMode", Show_AuthMode_Proc}, 206 - {"EncrypType", Show_EncrypType_Proc}, 207 - {"DefaultKeyID", Show_DefaultKeyID_Proc}, 208 - {"Key1", Show_Key1_Proc}, 209 - {"Key2", Show_Key2_Proc}, 210 - {"Key3", Show_Key3_Proc}, 211 - {"Key4", Show_Key4_Proc}, 212 - {"WPAPSK", Show_WPAPSK_Proc}, 213 - {NULL, NULL} 214 - }; 215 - 216 - /* 217 - ========================================================================== 218 - Description: 219 - Get Driver version. 220 - 221 - Return: 222 - ========================================================================== 223 - */ 224 - INT Set_DriverVersion_Proc( 225 - IN PRTMP_ADAPTER pAd, 226 - IN PUCHAR arg) 227 - { 228 - DBGPRINT(RT_DEBUG_TRACE, ("Driver version-%s\n", STA_DRIVER_VERSION)); 229 - 230 - return TRUE; 231 - } 232 - 233 - /* 234 - ========================================================================== 235 - Description: 236 - Set Country Region. 237 - This command will not work, if the field of CountryRegion in eeprom is programmed. 238 - Return: 239 - TRUE if all parameters are OK, FALSE otherwise 240 - ========================================================================== 241 - */ 242 - INT Set_CountryRegion_Proc( 243 - IN PRTMP_ADAPTER pAd, 244 - IN PUCHAR arg) 245 - { 246 - ULONG region; 247 - 248 - region = simple_strtol(arg, 0, 10); 249 - 250 - // Country can be set only when EEPROM not programmed 251 - if (pAd->CommonCfg.CountryRegion & 0x80) 252 - { 253 - DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n")); 254 - return FALSE; 255 - } 256 - 257 - if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND)) 258 - { 259 - pAd->CommonCfg.CountryRegion = (UCHAR) region; 260 - } 261 - else if (region == REGION_31_BG_BAND) 262 - { 263 - pAd->CommonCfg.CountryRegion = (UCHAR) region; 264 - } 265 - else 266 - { 267 - DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n")); 268 - return FALSE; 269 - } 270 - 271 - // if set country region, driver needs to be reset 272 - BuildChannelList(pAd); 273 - 274 - DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegion)); 275 - 276 - return TRUE; 277 - } 278 - 279 - /* 280 - ========================================================================== 281 - Description: 282 - Set Country Region for A band. 283 - This command will not work, if the field of CountryRegion in eeprom is programmed. 284 - Return: 285 - TRUE if all parameters are OK, FALSE otherwise 286 - ========================================================================== 287 - */ 288 - INT Set_CountryRegionABand_Proc( 289 - IN PRTMP_ADAPTER pAd, 290 - IN PUCHAR arg) 291 - { 292 - ULONG region; 293 - 294 - region = simple_strtol(arg, 0, 10); 295 - 296 - // Country can be set only when EEPROM not programmed 297 - if (pAd->CommonCfg.CountryRegionForABand & 0x80) 298 - { 299 - DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n")); 300 - return FALSE; 301 - } 302 - 303 - if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND)) 304 - { 305 - pAd->CommonCfg.CountryRegionForABand = (UCHAR) region; 306 - } 307 - else 308 - { 309 - DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n")); 310 - return FALSE; 311 - } 312 - 313 - // if set country region, driver needs to be reset 314 - BuildChannelList(pAd); 315 - 316 - DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegionABand_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegionForABand)); 317 - 318 - return TRUE; 319 - } 320 - 321 - /* 322 - ========================================================================== 323 - Description: 324 - Set Wireless Mode 325 - Return: 326 - TRUE if all parameters are OK, FALSE otherwise 327 - ========================================================================== 328 - */ 329 - INT Set_WirelessMode_Proc( 330 - IN PRTMP_ADAPTER pAd, 331 - IN PUCHAR arg) 332 - { 333 - ULONG WirelessMode; 334 - INT success = TRUE; 335 - 336 - WirelessMode = simple_strtol(arg, 0, 10); 337 - 338 - { 339 - INT MaxPhyMode = PHY_11G; 340 - 341 - MaxPhyMode = PHY_11N_5G; 342 - 343 - if (WirelessMode <= MaxPhyMode) 344 - { 345 - RTMPSetPhyMode(pAd, WirelessMode); 346 - 347 - if (WirelessMode >= PHY_11ABGN_MIXED) 348 - { 349 - pAd->CommonCfg.BACapability.field.AutoBA = TRUE; 350 - pAd->CommonCfg.REGBACapability.field.AutoBA = TRUE; 351 - } 352 - else 353 - { 354 - pAd->CommonCfg.BACapability.field.AutoBA = FALSE; 355 - pAd->CommonCfg.REGBACapability.field.AutoBA = FALSE; 356 - } 357 - 358 - // Set AdhocMode rates 359 - if (pAd->StaCfg.BssType == BSS_ADHOC) 360 - { 361 - MlmeUpdateTxRates(pAd, FALSE, 0); 362 - MakeIbssBeacon(pAd); // re-build BEACON frame 363 - AsicEnableIbssSync(pAd); // copy to on-chip memory 364 - } 365 - } 366 - else 367 - { 368 - success = FALSE; 369 - } 370 - } 371 - 372 - // it is needed to set SSID to take effect 373 - if (success == TRUE) 374 - { 375 - SetCommonHT(pAd); 376 - DBGPRINT(RT_DEBUG_TRACE, ("Set_WirelessMode_Proc::(=%ld)\n", WirelessMode)); 377 - } 378 - else 379 - { 380 - DBGPRINT(RT_DEBUG_ERROR, ("Set_WirelessMode_Proc::parameters out of range\n")); 381 - } 382 - 383 - return success; 384 - } 385 - 386 - /* 387 - ========================================================================== 388 - Description: 389 - Set Channel 390 - Return: 391 - TRUE if all parameters are OK, FALSE otherwise 392 - ========================================================================== 393 - */ 394 - INT Set_Channel_Proc( 395 - IN PRTMP_ADAPTER pAd, 396 - IN PUCHAR arg) 397 - { 398 - INT success = TRUE; 399 - UCHAR Channel; 400 - 401 - Channel = (UCHAR) simple_strtol(arg, 0, 10); 402 - 403 - // check if this channel is valid 404 - if (ChannelSanity(pAd, Channel) == TRUE) 405 - { 406 - { 407 - pAd->CommonCfg.Channel = Channel; 408 - 409 - if (MONITOR_ON(pAd)) 410 - { 411 - N_ChannelCheck(pAd); 412 - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED && 413 - pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40) 414 - { 415 - N_SetCenCh(pAd); 416 - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); 417 - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); 418 - DBGPRINT(RT_DEBUG_TRACE, ("BW_40, control_channel(%d), CentralChannel(%d) \n", 419 - pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel)); 420 - } 421 - else 422 - { 423 - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); 424 - AsicLockChannel(pAd, pAd->CommonCfg.Channel); 425 - DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAd->CommonCfg.Channel)); 426 - } 427 - } 428 - } 429 - success = TRUE; 430 - } 431 - else 432 - { 433 - success = FALSE; 434 - } 435 - 436 - 437 - if (success == TRUE) 438 - DBGPRINT(RT_DEBUG_TRACE, ("Set_Channel_Proc::(Channel=%d)\n", pAd->CommonCfg.Channel)); 439 - 440 - return success; 441 - } 442 - 443 - /* 444 - ========================================================================== 445 - Description: 446 - Set Short Slot Time Enable or Disable 447 - Return: 448 - TRUE if all parameters are OK, FALSE otherwise 449 - ========================================================================== 450 - */ 451 - INT Set_ShortSlot_Proc( 452 - IN PRTMP_ADAPTER pAd, 453 - IN PUCHAR arg) 454 - { 455 - ULONG ShortSlot; 456 - 457 - ShortSlot = simple_strtol(arg, 0, 10); 458 - 459 - if (ShortSlot == 1) 460 - pAd->CommonCfg.bUseShortSlotTime = TRUE; 461 - else if (ShortSlot == 0) 462 - pAd->CommonCfg.bUseShortSlotTime = FALSE; 463 - else 464 - return FALSE; //Invalid argument 465 - 466 - DBGPRINT(RT_DEBUG_TRACE, ("Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAd->CommonCfg.bUseShortSlotTime)); 467 - 468 - return TRUE; 469 - } 470 - 471 - /* 472 - ========================================================================== 473 - Description: 474 - Set Tx power 475 - Return: 476 - TRUE if all parameters are OK, FALSE otherwise 477 - ========================================================================== 478 - */ 479 - INT Set_TxPower_Proc( 480 - IN PRTMP_ADAPTER pAd, 481 - IN PUCHAR arg) 482 - { 483 - ULONG TxPower; 484 - INT success = FALSE; 485 - 486 - TxPower = (ULONG) simple_strtol(arg, 0, 10); 487 - if (TxPower <= 100) 488 - { 489 - { 490 - pAd->CommonCfg.TxPowerDefault = TxPower; 491 - pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault; 492 - } 493 - success = TRUE; 494 - } 495 - else 496 - success = FALSE; 497 - 498 - DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPower_Proc::(TxPowerPercentage=%ld)\n", pAd->CommonCfg.TxPowerPercentage)); 499 - 500 - return success; 501 - } 502 - 503 - /* 504 - ========================================================================== 505 - Description: 506 - Set 11B/11G Protection 507 - Return: 508 - TRUE if all parameters are OK, FALSE otherwise 509 - ========================================================================== 510 - */ 511 - INT Set_BGProtection_Proc( 512 - IN PRTMP_ADAPTER pAd, 513 - IN PUCHAR arg) 514 - { 515 - switch (simple_strtol(arg, 0, 10)) 516 - { 517 - case 0: //AUTO 518 - pAd->CommonCfg.UseBGProtection = 0; 519 - break; 520 - case 1: //Always On 521 - pAd->CommonCfg.UseBGProtection = 1; 522 - break; 523 - case 2: //Always OFF 524 - pAd->CommonCfg.UseBGProtection = 2; 525 - break; 526 - default: //Invalid argument 527 - return FALSE; 528 - } 529 - 530 - 531 - DBGPRINT(RT_DEBUG_TRACE, ("Set_BGProtection_Proc::(BGProtection=%ld)\n", pAd->CommonCfg.UseBGProtection)); 532 - 533 - return TRUE; 534 - } 535 - 536 - /* 537 - ========================================================================== 538 - Description: 539 - Set TxPreamble 540 - Return: 541 - TRUE if all parameters are OK, FALSE otherwise 542 - ========================================================================== 543 - */ 544 - INT Set_TxPreamble_Proc( 545 - IN PRTMP_ADAPTER pAd, 546 - IN PUCHAR arg) 547 - { 548 - RT_802_11_PREAMBLE Preamble; 549 - 550 - Preamble = simple_strtol(arg, 0, 10); 551 - 552 - 553 - switch (Preamble) 554 - { 555 - case Rt802_11PreambleShort: 556 - pAd->CommonCfg.TxPreamble = Preamble; 557 - 558 - MlmeSetTxPreamble(pAd, Rt802_11PreambleShort); 559 - break; 560 - case Rt802_11PreambleLong: 561 - case Rt802_11PreambleAuto: 562 - // if user wants AUTO, initialize to LONG here, then change according to AP's 563 - // capability upon association. 564 - pAd->CommonCfg.TxPreamble = Preamble; 565 - 566 - MlmeSetTxPreamble(pAd, Rt802_11PreambleLong); 567 - break; 568 - default: //Invalid argument 569 - return FALSE; 570 - } 571 - 572 - DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPreamble_Proc::(TxPreamble=%ld)\n", pAd->CommonCfg.TxPreamble)); 573 - 574 - return TRUE; 575 - } 576 - 577 - /* 578 - ========================================================================== 579 - Description: 580 - Set RTS Threshold 581 - Return: 582 - TRUE if all parameters are OK, FALSE otherwise 583 - ========================================================================== 584 - */ 585 - INT Set_RTSThreshold_Proc( 586 - IN PRTMP_ADAPTER pAd, 587 - IN PUCHAR arg) 588 - { 589 - NDIS_802_11_RTS_THRESHOLD RtsThresh; 590 - 591 - RtsThresh = simple_strtol(arg, 0, 10); 592 - 593 - if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD)) 594 - pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh; 595 - else if (RtsThresh == 0) 596 - pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD; 597 - else 598 - return FALSE; //Invalid argument 599 - 600 - DBGPRINT(RT_DEBUG_TRACE, ("Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAd->CommonCfg.RtsThreshold)); 601 - 602 - return TRUE; 603 - } 604 - 605 - /* 606 - ========================================================================== 607 - Description: 608 - Set Fragment Threshold 609 - Return: 610 - TRUE if all parameters are OK, FALSE otherwise 611 - ========================================================================== 612 - */ 613 - INT Set_FragThreshold_Proc( 614 - IN PRTMP_ADAPTER pAd, 615 - IN PUCHAR arg) 616 - { 617 - NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh; 618 - 619 - FragThresh = simple_strtol(arg, 0, 10); 620 - 621 - if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD) 622 - { 623 - //Illegal FragThresh so we set it to default 624 - pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD; 625 - } 626 - else if (FragThresh % 2 == 1) 627 - { 628 - // The length of each fragment shall always be an even number of octets, except for the last fragment 629 - // of an MSDU or MMPDU, which may be either an even or an odd number of octets. 630 - pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1); 631 - } 632 - else 633 - { 634 - pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh; 635 - } 636 - 637 - { 638 - if (pAd->CommonCfg.FragmentThreshold == MAX_FRAG_THRESHOLD) 639 - pAd->CommonCfg.bUseZeroToDisableFragment = TRUE; 640 - else 641 - pAd->CommonCfg.bUseZeroToDisableFragment = FALSE; 642 - } 643 - 644 - DBGPRINT(RT_DEBUG_TRACE, ("Set_FragThreshold_Proc::(FragThreshold=%d)\n", pAd->CommonCfg.FragmentThreshold)); 645 - 646 - return TRUE; 647 - } 648 - 649 - /* 650 - ========================================================================== 651 - Description: 652 - Set TxBurst 653 - Return: 654 - TRUE if all parameters are OK, FALSE otherwise 655 - ========================================================================== 656 - */ 657 - INT Set_TxBurst_Proc( 658 - IN PRTMP_ADAPTER pAd, 659 - IN PUCHAR arg) 660 - { 661 - ULONG TxBurst; 662 - 663 - TxBurst = simple_strtol(arg, 0, 10); 664 - if (TxBurst == 1) 665 - pAd->CommonCfg.bEnableTxBurst = TRUE; 666 - else if (TxBurst == 0) 667 - pAd->CommonCfg.bEnableTxBurst = FALSE; 668 - else 669 - return FALSE; //Invalid argument 670 - 671 - DBGPRINT(RT_DEBUG_TRACE, ("Set_TxBurst_Proc::(TxBurst=%d)\n", pAd->CommonCfg.bEnableTxBurst)); 672 - 673 - return TRUE; 674 - } 675 - 676 - #ifdef AGGREGATION_SUPPORT 677 - /* 678 - ========================================================================== 679 - Description: 680 - Set TxBurst 681 - Return: 682 - TRUE if all parameters are OK, FALSE otherwise 683 - ========================================================================== 684 - */ 685 - INT Set_PktAggregate_Proc( 686 - IN PRTMP_ADAPTER pAd, 687 - IN PUCHAR arg) 688 - { 689 - ULONG aggre; 690 - 691 - aggre = simple_strtol(arg, 0, 10); 692 - 693 - if (aggre == 1) 694 - pAd->CommonCfg.bAggregationCapable = TRUE; 695 - else if (aggre == 0) 696 - pAd->CommonCfg.bAggregationCapable = FALSE; 697 - else 698 - return FALSE; //Invalid argument 699 - 700 - 701 - DBGPRINT(RT_DEBUG_TRACE, ("Set_PktAggregate_Proc::(AGGRE=%d)\n", pAd->CommonCfg.bAggregationCapable)); 702 - 703 - return TRUE; 704 - } 705 - #endif 706 - 707 - /* 708 - ========================================================================== 709 - Description: 710 - Set IEEE80211H. 711 - This parameter is 1 when needs radar detection, otherwise 0 712 - Return: 713 - TRUE if all parameters are OK, FALSE otherwise 714 - ========================================================================== 715 - */ 716 - INT Set_IEEE80211H_Proc( 717 - IN PRTMP_ADAPTER pAd, 718 - IN PUCHAR arg) 719 - { 720 - ULONG ieee80211h; 721 - 722 - ieee80211h = simple_strtol(arg, 0, 10); 723 - 724 - if (ieee80211h == 1) 725 - pAd->CommonCfg.bIEEE80211H = TRUE; 726 - else if (ieee80211h == 0) 727 - pAd->CommonCfg.bIEEE80211H = FALSE; 728 - else 729 - return FALSE; //Invalid argument 730 - 731 - DBGPRINT(RT_DEBUG_TRACE, ("Set_IEEE80211H_Proc::(IEEE80211H=%d)\n", pAd->CommonCfg.bIEEE80211H)); 732 - 733 - return TRUE; 734 - } 735 - 736 - 737 - #ifdef DBG 738 - /* 739 - ========================================================================== 740 - Description: 741 - For Debug information 742 - Return: 743 - TRUE if all parameters are OK, FALSE otherwise 744 - ========================================================================== 745 - */ 746 - INT Set_Debug_Proc( 747 - IN PRTMP_ADAPTER pAd, 748 - IN PUCHAR arg) 749 - { 750 - DBGPRINT(RT_DEBUG_TRACE, ("==> Set_Debug_Proc *******************\n")); 751 - 752 - if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD) 753 - RTDebugLevel = simple_strtol(arg, 0, 10); 754 - 755 - DBGPRINT(RT_DEBUG_TRACE, ("<== Set_Debug_Proc(RTDebugLevel = %ld)\n", RTDebugLevel)); 756 - 757 - return TRUE; 758 - } 759 - #endif 760 - 761 - INT Show_DescInfo_Proc( 762 - IN PRTMP_ADAPTER pAd, 763 - IN PUCHAR arg) 764 - { 765 - 766 - return TRUE; 767 - } 768 - 769 - /* 770 - ========================================================================== 771 - Description: 772 - Reset statistics counter 773 - 774 - Arguments: 775 - pAdapter Pointer to our adapter 776 - arg 777 - 778 - Return: 779 - TRUE if all parameters are OK, FALSE otherwise 780 - ========================================================================== 781 - */ 782 - INT Set_ResetStatCounter_Proc( 783 - IN PRTMP_ADAPTER pAd, 784 - IN PUCHAR arg) 785 - { 786 - DBGPRINT(RT_DEBUG_TRACE, ("==>Set_ResetStatCounter_Proc\n")); 787 - 788 - // add the most up-to-date h/w raw counters into software counters 789 - NICUpdateRawCounters(pAd); 790 - 791 - NdisZeroMemory(&pAd->WlanCounters, sizeof(COUNTER_802_11)); 792 - NdisZeroMemory(&pAd->Counters8023, sizeof(COUNTER_802_3)); 793 - NdisZeroMemory(&pAd->RalinkCounters, sizeof(COUNTER_RALINK)); 794 - 795 - return TRUE; 796 - } 797 - 798 - BOOLEAN RTMPCheckStrPrintAble( 799 - IN CHAR *pInPutStr, 800 - IN UCHAR strLen) 801 - { 802 - UCHAR i=0; 803 - 804 - for (i=0; i<strLen; i++) 805 - { 806 - if ((pInPutStr[i] < 0x21) || 807 - (pInPutStr[i] > 0x7E)) 808 - return FALSE; 809 - } 810 - 811 - return TRUE; 812 - } 813 - 814 - /* 815 - ======================================================================== 816 - 817 - Routine Description: 818 - Remove WPA Key process 819 - 820 - Arguments: 821 - pAd Pointer to our adapter 822 - pBuf Pointer to the where the key stored 823 - 824 - Return Value: 825 - NDIS_SUCCESS Add key successfully 826 - 827 - IRQL = DISPATCH_LEVEL 828 - 829 - Note: 830 - 831 - ======================================================================== 832 - */ 833 - VOID RTMPSetDesiredRates( 834 - IN PRTMP_ADAPTER pAdapter, 835 - IN LONG Rates) 836 - { 837 - NDIS_802_11_RATES aryRates; 838 - 839 - memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES)); 840 - switch (pAdapter->CommonCfg.PhyMode) 841 - { 842 - case PHY_11A: // A only 843 - switch (Rates) 844 - { 845 - case 6000000: //6M 846 - aryRates[0] = 0x0c; // 6M 847 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0; 848 - break; 849 - case 9000000: //9M 850 - aryRates[0] = 0x12; // 9M 851 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1; 852 - break; 853 - case 12000000: //12M 854 - aryRates[0] = 0x18; // 12M 855 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2; 856 - break; 857 - case 18000000: //18M 858 - aryRates[0] = 0x24; // 18M 859 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3; 860 - break; 861 - case 24000000: //24M 862 - aryRates[0] = 0x30; // 24M 863 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4; 864 - break; 865 - case 36000000: //36M 866 - aryRates[0] = 0x48; // 36M 867 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5; 868 - break; 869 - case 48000000: //48M 870 - aryRates[0] = 0x60; // 48M 871 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6; 872 - break; 873 - case 54000000: //54M 874 - aryRates[0] = 0x6c; // 54M 875 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7; 876 - break; 877 - case -1: //Auto 878 - default: 879 - aryRates[0] = 0x6c; // 54Mbps 880 - aryRates[1] = 0x60; // 48Mbps 881 - aryRates[2] = 0x48; // 36Mbps 882 - aryRates[3] = 0x30; // 24Mbps 883 - aryRates[4] = 0x24; // 18M 884 - aryRates[5] = 0x18; // 12M 885 - aryRates[6] = 0x12; // 9M 886 - aryRates[7] = 0x0c; // 6M 887 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; 888 - break; 889 - } 890 - break; 891 - case PHY_11BG_MIXED: // B/G Mixed 892 - case PHY_11B: // B only 893 - case PHY_11ABG_MIXED: // A/B/G Mixed 894 - default: 895 - switch (Rates) 896 - { 897 - case 1000000: //1M 898 - aryRates[0] = 0x02; 899 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0; 900 - break; 901 - case 2000000: //2M 902 - aryRates[0] = 0x04; 903 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1; 904 - break; 905 - case 5000000: //5.5M 906 - aryRates[0] = 0x0b; // 5.5M 907 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2; 908 - break; 909 - case 11000000: //11M 910 - aryRates[0] = 0x16; // 11M 911 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3; 912 - break; 913 - case 6000000: //6M 914 - aryRates[0] = 0x0c; // 6M 915 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0; 916 - break; 917 - case 9000000: //9M 918 - aryRates[0] = 0x12; // 9M 919 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1; 920 - break; 921 - case 12000000: //12M 922 - aryRates[0] = 0x18; // 12M 923 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2; 924 - break; 925 - case 18000000: //18M 926 - aryRates[0] = 0x24; // 18M 927 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3; 928 - break; 929 - case 24000000: //24M 930 - aryRates[0] = 0x30; // 24M 931 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4; 932 - break; 933 - case 36000000: //36M 934 - aryRates[0] = 0x48; // 36M 935 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5; 936 - break; 937 - case 48000000: //48M 938 - aryRates[0] = 0x60; // 48M 939 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6; 940 - break; 941 - case 54000000: //54M 942 - aryRates[0] = 0x6c; // 54M 943 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7; 944 - break; 945 - case -1: //Auto 946 - default: 947 - if (pAdapter->CommonCfg.PhyMode == PHY_11B) 948 - { //B Only 949 - aryRates[0] = 0x16; // 11Mbps 950 - aryRates[1] = 0x0b; // 5.5Mbps 951 - aryRates[2] = 0x04; // 2Mbps 952 - aryRates[3] = 0x02; // 1Mbps 953 - } 954 - else 955 - { //(B/G) Mixed or (A/B/G) Mixed 956 - aryRates[0] = 0x6c; // 54Mbps 957 - aryRates[1] = 0x60; // 48Mbps 958 - aryRates[2] = 0x48; // 36Mbps 959 - aryRates[3] = 0x30; // 24Mbps 960 - aryRates[4] = 0x16; // 11Mbps 961 - aryRates[5] = 0x0b; // 5.5Mbps 962 - aryRates[6] = 0x04; // 2Mbps 963 - aryRates[7] = 0x02; // 1Mbps 964 - } 965 - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; 966 - break; 967 - } 968 - break; 969 - } 970 - 971 - NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES); 972 - NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES)); 973 - DBGPRINT(RT_DEBUG_TRACE, (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n", 974 - pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1], 975 - pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3], 976 - pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5], 977 - pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] )); 978 - // Changing DesiredRate may affect the MAX TX rate we used to TX frames out 979 - MlmeUpdateTxRates(pAdapter, FALSE, 0); 980 - } 981 - 982 - NDIS_STATUS RTMPWPARemoveKeyProc( 983 - IN PRTMP_ADAPTER pAd, 984 - IN PVOID pBuf) 985 - { 986 - PNDIS_802_11_REMOVE_KEY pKey; 987 - ULONG KeyIdx; 988 - NDIS_STATUS Status = NDIS_STATUS_FAILURE; 989 - BOOLEAN bTxKey; // Set the key as transmit key 990 - BOOLEAN bPairwise; // Indicate the key is pairwise key 991 - BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value. 992 - // Otherwise, it will set by the NIC. 993 - BOOLEAN bAuthenticator; // indicate key is set by authenticator. 994 - INT i; 995 - 996 - DBGPRINT(RT_DEBUG_TRACE,("---> RTMPWPARemoveKeyProc\n")); 997 - 998 - pKey = (PNDIS_802_11_REMOVE_KEY) pBuf; 999 - KeyIdx = pKey->KeyIndex & 0xff; 1000 - // Bit 31 of Add-key, Tx Key 1001 - bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE; 1002 - // Bit 30 of Add-key PairwiseKey 1003 - bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE; 1004 - // Bit 29 of Add-key KeyRSC 1005 - bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE; 1006 - // Bit 28 of Add-key Authenticator 1007 - bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE; 1008 - 1009 - // 1. If bTx is TRUE, return failure information 1010 - if (bTxKey == TRUE) 1011 - return(NDIS_STATUS_INVALID_DATA); 1012 - 1013 - // 2. Check Pairwise Key 1014 - if (bPairwise) 1015 - { 1016 - // a. If BSSID is broadcast, remove all pairwise keys. 1017 - // b. If not broadcast, remove the pairwise specified by BSSID 1018 - for (i = 0; i < SHARE_KEY_NUM; i++) 1019 - { 1020 - if (MAC_ADDR_EQUAL(pAd->SharedKey[BSS0][i].BssId, pKey->BSSID)) 1021 - { 1022 - DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%d)\n", i)); 1023 - pAd->SharedKey[BSS0][i].KeyLen = 0; 1024 - pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE; 1025 - AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)i); 1026 - Status = NDIS_STATUS_SUCCESS; 1027 - break; 1028 - } 1029 - } 1030 - } 1031 - // 3. Group Key 1032 - else 1033 - { 1034 - // a. If BSSID is broadcast, remove all group keys indexed 1035 - // b. If BSSID matched, delete the group key indexed. 1036 - DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%ld)\n", KeyIdx)); 1037 - pAd->SharedKey[BSS0][KeyIdx].KeyLen = 0; 1038 - pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE; 1039 - AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx); 1040 - Status = NDIS_STATUS_SUCCESS; 1041 - } 1042 - 1043 - return (Status); 1044 - } 1045 - 1046 - /* 1047 - ======================================================================== 1048 - 1049 - Routine Description: 1050 - Remove All WPA Keys 1051 - 1052 - Arguments: 1053 - pAd Pointer to our adapter 1054 - 1055 - Return Value: 1056 - None 1057 - 1058 - IRQL = DISPATCH_LEVEL 1059 - 1060 - Note: 1061 - 1062 - ======================================================================== 1063 - */ 1064 - VOID RTMPWPARemoveAllKeys( 1065 - IN PRTMP_ADAPTER pAd) 1066 - { 1067 - 1068 - UCHAR i; 1069 - 1070 - DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus)); 1071 - 1072 - // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after 1073 - // Link up. And it will be replaced if user changed it. 1074 - if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA) 1075 - return; 1076 - 1077 - // For WPA-None, there is no need to remove it, since WinXP won't set it again after 1078 - // Link up. And it will be replaced if user changed it. 1079 - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) 1080 - return; 1081 - 1082 - // set BSSID wcid entry of the Pair-wise Key table as no-security mode 1083 - AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID); 1084 - 1085 - // set all shared key mode as no-security. 1086 - for (i = 0; i < SHARE_KEY_NUM; i++) 1087 - { 1088 - DBGPRINT(RT_DEBUG_TRACE,("remove %s key #%d\n", CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i)); 1089 - NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY)); 1090 - 1091 - AsicRemoveSharedKeyEntry(pAd, BSS0, i); 1092 - } 1093 - 1094 - } 1095 - 1096 - /* 1097 - ======================================================================== 1098 - Routine Description: 1099 - Change NIC PHY mode. Re-association may be necessary. possible settings 1100 - include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED 1101 - 1102 - Arguments: 1103 - pAd - Pointer to our adapter 1104 - phymode - 1105 - 1106 - IRQL = PASSIVE_LEVEL 1107 - IRQL = DISPATCH_LEVEL 1108 - 1109 - ======================================================================== 1110 - */ 1111 - VOID RTMPSetPhyMode( 1112 - IN PRTMP_ADAPTER pAd, 1113 - IN ULONG phymode) 1114 - { 1115 - INT i; 1116 - // the selected phymode must be supported by the RF IC encoded in E2PROM 1117 - 1118 - pAd->CommonCfg.PhyMode = (UCHAR)phymode; 1119 - 1120 - DBGPRINT(RT_DEBUG_TRACE,("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel)); 1121 - 1122 - BuildChannelList(pAd); 1123 - 1124 - // sanity check user setting 1125 - for (i = 0; i < pAd->ChannelListNum; i++) 1126 - { 1127 - if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel) 1128 - break; 1129 - } 1130 - 1131 - if (i == pAd->ChannelListNum) 1132 - { 1133 - pAd->CommonCfg.Channel = FirstChannel(pAd); 1134 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", pAd->CommonCfg.Channel)); 1135 - } 1136 - 1137 - NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES); 1138 - NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES); 1139 - NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES); 1140 - switch (phymode) { 1141 - case PHY_11B: 1142 - pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate 1143 - pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate 1144 - pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate 1145 - pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate 1146 - pAd->CommonCfg.SupRateLen = 4; 1147 - pAd->CommonCfg.ExtRateLen = 0; 1148 - pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps 1149 - pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps 1150 - pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps 1151 - pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps 1152 - //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use 1153 - break; 1154 - 1155 - case PHY_11G: 1156 - case PHY_11BG_MIXED: 1157 - case PHY_11ABG_MIXED: 1158 - case PHY_11N_2_4G: 1159 - case PHY_11ABGN_MIXED: 1160 - case PHY_11BGN_MIXED: 1161 - case PHY_11GN_MIXED: 1162 - pAd->CommonCfg.SupRate[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate 1163 - pAd->CommonCfg.SupRate[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate 1164 - pAd->CommonCfg.SupRate[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate 1165 - pAd->CommonCfg.SupRate[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate 1166 - pAd->CommonCfg.SupRate[4] = 0x12; // 9 mbps, in units of 0.5 Mbps 1167 - pAd->CommonCfg.SupRate[5] = 0x24; // 18 mbps, in units of 0.5 Mbps 1168 - pAd->CommonCfg.SupRate[6] = 0x48; // 36 mbps, in units of 0.5 Mbps 1169 - pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps 1170 - pAd->CommonCfg.SupRateLen = 8; 1171 - pAd->CommonCfg.ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps 1172 - pAd->CommonCfg.ExtRate[1] = 0x18; // 12 mbps, in units of 0.5 Mbps 1173 - pAd->CommonCfg.ExtRate[2] = 0x30; // 24 mbps, in units of 0.5 Mbps 1174 - pAd->CommonCfg.ExtRate[3] = 0x60; // 48 mbps, in units of 0.5 Mbps 1175 - pAd->CommonCfg.ExtRateLen = 4; 1176 - pAd->CommonCfg.DesireRate[0] = 2; // 1 mbps, in units of 0.5 Mbps 1177 - pAd->CommonCfg.DesireRate[1] = 4; // 2 mbps, in units of 0.5 Mbps 1178 - pAd->CommonCfg.DesireRate[2] = 11; // 5.5 mbps, in units of 0.5 Mbps 1179 - pAd->CommonCfg.DesireRate[3] = 22; // 11 mbps, in units of 0.5 Mbps 1180 - pAd->CommonCfg.DesireRate[4] = 12; // 6 mbps, in units of 0.5 Mbps 1181 - pAd->CommonCfg.DesireRate[5] = 18; // 9 mbps, in units of 0.5 Mbps 1182 - pAd->CommonCfg.DesireRate[6] = 24; // 12 mbps, in units of 0.5 Mbps 1183 - pAd->CommonCfg.DesireRate[7] = 36; // 18 mbps, in units of 0.5 Mbps 1184 - pAd->CommonCfg.DesireRate[8] = 48; // 24 mbps, in units of 0.5 Mbps 1185 - pAd->CommonCfg.DesireRate[9] = 72; // 36 mbps, in units of 0.5 Mbps 1186 - pAd->CommonCfg.DesireRate[10] = 96; // 48 mbps, in units of 0.5 Mbps 1187 - pAd->CommonCfg.DesireRate[11] = 108; // 54 mbps, in units of 0.5 Mbps 1188 - break; 1189 - 1190 - case PHY_11A: 1191 - case PHY_11AN_MIXED: 1192 - case PHY_11AGN_MIXED: 1193 - case PHY_11N_5G: 1194 - pAd->CommonCfg.SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate 1195 - pAd->CommonCfg.SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps 1196 - pAd->CommonCfg.SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate 1197 - pAd->CommonCfg.SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps 1198 - pAd->CommonCfg.SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate 1199 - pAd->CommonCfg.SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps 1200 - pAd->CommonCfg.SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps 1201 - pAd->CommonCfg.SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps 1202 - pAd->CommonCfg.SupRateLen = 8; 1203 - pAd->CommonCfg.ExtRateLen = 0; 1204 - pAd->CommonCfg.DesireRate[0] = 12; // 6 mbps, in units of 0.5 Mbps 1205 - pAd->CommonCfg.DesireRate[1] = 18; // 9 mbps, in units of 0.5 Mbps 1206 - pAd->CommonCfg.DesireRate[2] = 24; // 12 mbps, in units of 0.5 Mbps 1207 - pAd->CommonCfg.DesireRate[3] = 36; // 18 mbps, in units of 0.5 Mbps 1208 - pAd->CommonCfg.DesireRate[4] = 48; // 24 mbps, in units of 0.5 Mbps 1209 - pAd->CommonCfg.DesireRate[5] = 72; // 36 mbps, in units of 0.5 Mbps 1210 - pAd->CommonCfg.DesireRate[6] = 96; // 48 mbps, in units of 0.5 Mbps 1211 - pAd->CommonCfg.DesireRate[7] = 108; // 54 mbps, in units of 0.5 Mbps 1212 - //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use 1213 - break; 1214 - 1215 - default: 1216 - break; 1217 - } 1218 - 1219 - 1220 - pAd->CommonCfg.BandState = UNKNOWN_BAND; 1221 - } 1222 - 1223 - /* 1224 - ======================================================================== 1225 - Routine Description: 1226 - Caller ensures we has 802.11n support. 1227 - Calls at setting HT from AP/STASetinformation 1228 - 1229 - Arguments: 1230 - pAd - Pointer to our adapter 1231 - phymode - 1232 - 1233 - ======================================================================== 1234 - */ 1235 - VOID RTMPSetHT( 1236 - IN PRTMP_ADAPTER pAd, 1237 - IN OID_SET_HT_PHYMODE *pHTPhyMode) 1238 - { 1239 - //ULONG *pmcs; 1240 - UINT32 Value = 0; 1241 - UCHAR BBPValue = 0; 1242 - UCHAR BBP3Value = 0; 1243 - UCHAR RxStream = pAd->CommonCfg.RxStream; 1244 - 1245 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n", 1246 - pHTPhyMode->HtMode, pHTPhyMode->ExtOffset, 1247 - pHTPhyMode->MCS, pHTPhyMode->BW, 1248 - pHTPhyMode->STBC, pHTPhyMode->SHORTGI)); 1249 - 1250 - // Don't zero supportedHyPhy structure. 1251 - RTMPZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability)); 1252 - RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo)); 1253 - RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, sizeof(pAd->CommonCfg.NewExtChanOffset)); 1254 - RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, sizeof(pAd->CommonCfg.DesiredHtPhy)); 1255 - 1256 - if (pAd->CommonCfg.bRdg) 1257 - { 1258 - pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1; 1259 - pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1; 1260 - } 1261 - else 1262 - { 1263 - pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0; 1264 - pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0; 1265 - } 1266 - 1267 - pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3; 1268 - pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3; 1269 - 1270 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : RxBAWinLimit = %d\n", pAd->CommonCfg.BACapability.field.RxBAWinLimit)); 1271 - 1272 - // Mimo power save, A-MSDU size, 1273 - pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable; 1274 - pAd->CommonCfg.DesiredHtPhy.AmsduSize = (UCHAR)pAd->CommonCfg.BACapability.field.AmsduSize; 1275 - pAd->CommonCfg.DesiredHtPhy.MimoPs = (UCHAR)pAd->CommonCfg.BACapability.field.MMPSmode; 1276 - pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity; 1277 - 1278 - pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize; 1279 - pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode; 1280 - pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity; 1281 - 1282 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n", 1283 - pAd->CommonCfg.DesiredHtPhy.AmsduSize, 1284 - pAd->CommonCfg.DesiredHtPhy.MimoPs, 1285 - pAd->CommonCfg.DesiredHtPhy.MpduDensity, 1286 - pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor)); 1287 - 1288 - if(pHTPhyMode->HtMode == HTMODE_GF) 1289 - { 1290 - pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1; 1291 - pAd->CommonCfg.DesiredHtPhy.GF = 1; 1292 - } 1293 - else 1294 - pAd->CommonCfg.DesiredHtPhy.GF = 0; 1295 - 1296 - // Decide Rx MCSSet 1297 - switch (RxStream) 1298 - { 1299 - case 1: 1300 - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; 1301 - pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00; 1302 - break; 1303 - 1304 - case 2: 1305 - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; 1306 - pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff; 1307 - break; 1308 - 1309 - case 3: // 3*3 1310 - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; 1311 - pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff; 1312 - pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff; 1313 - break; 1314 - } 1315 - 1316 - if (pAd->CommonCfg.bForty_Mhz_Intolerant && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40) ) 1317 - { 1318 - pHTPhyMode->BW = BW_20; 1319 - pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1; 1320 - } 1321 - 1322 - if(pHTPhyMode->BW == BW_40) 1323 - { 1324 - pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32 1325 - pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1; 1326 - if (pAd->CommonCfg.Channel <= 14) 1327 - pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1; 1328 - 1329 - pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1; 1330 - pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1; 1331 - pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = (pHTPhyMode->ExtOffset == EXTCHA_BELOW)? (EXTCHA_BELOW): EXTCHA_ABOVE; 1332 - // Set Regsiter for extension channel position. 1333 - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); 1334 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value); 1335 - if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW)) 1336 - { 1337 - Value |= 0x1; 1338 - BBP3Value |= (0x20); 1339 - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); 1340 - } 1341 - else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE)) 1342 - { 1343 - Value &= 0xfe; 1344 - BBP3Value &= (~0x20); 1345 - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); 1346 - } 1347 - 1348 - // Turn on BBP 40MHz mode now only as AP . 1349 - // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection. 1350 - if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd) 1351 - ) 1352 - { 1353 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); 1354 - BBPValue &= (~0x18); 1355 - BBPValue |= 0x10; 1356 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); 1357 - 1358 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value); 1359 - pAd->CommonCfg.BBPCurrentBW = BW_40; 1360 - } 1361 - } 1362 - else 1363 - { 1364 - pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0; 1365 - pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0; 1366 - pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0; 1367 - pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE; 1368 - pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel; 1369 - // Turn on BBP 20MHz mode by request here. 1370 - { 1371 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); 1372 - BBPValue &= (~0x18); 1373 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); 1374 - pAd->CommonCfg.BBPCurrentBW = BW_20; 1375 - } 1376 - } 1377 - 1378 - if(pHTPhyMode->STBC == STBC_USE) 1379 - { 1380 - pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1; 1381 - pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1; 1382 - pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1; 1383 - pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1; 1384 - } 1385 - else 1386 - { 1387 - pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0; 1388 - pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0; 1389 - } 1390 - 1391 - #ifndef RT30xx 1392 - #ifdef RT2870 1393 - /* Frank recommend ,If not, Tx maybe block in high power. Rx has no problem*/ 1394 - if(IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020))) 1395 - { 1396 - pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 0; 1397 - pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0; 1398 - } 1399 - #endif // RT2870 // 1400 - #endif 1401 - 1402 - if(pHTPhyMode->SHORTGI == GI_400) 1403 - { 1404 - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1; 1405 - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1; 1406 - pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1; 1407 - pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1; 1408 - } 1409 - else 1410 - { 1411 - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0; 1412 - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0; 1413 - pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0; 1414 - pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0; 1415 - } 1416 - 1417 - // We support link adaptation for unsolicit MCS feedback, set to 2. 1418 - pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT; 1419 - pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel; 1420 - // 1, the extension channel above the control channel. 1421 - 1422 - // EDCA parameters used for AP's own transmission 1423 - if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) 1424 - { 1425 - pAd->CommonCfg.APEdcaParm.bValid = TRUE; 1426 - pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3; 1427 - pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7; 1428 - pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1; 1429 - pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1; 1430 - 1431 - pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4; 1432 - pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4; 1433 - pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3; 1434 - pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2; 1435 - 1436 - pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6; 1437 - pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10; 1438 - pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4; 1439 - pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3; 1440 - 1441 - pAd->CommonCfg.APEdcaParm.Txop[0] = 0; 1442 - pAd->CommonCfg.APEdcaParm.Txop[1] = 0; 1443 - pAd->CommonCfg.APEdcaParm.Txop[2] = 94; 1444 - pAd->CommonCfg.APEdcaParm.Txop[3] = 47; 1445 - } 1446 - AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm); 1447 - 1448 - RTMPSetIndividualHT(pAd, 0); 1449 - } 1450 - 1451 - /* 1452 - ======================================================================== 1453 - Routine Description: 1454 - Caller ensures we has 802.11n support. 1455 - Calls at setting HT from AP/STASetinformation 1456 - 1457 - Arguments: 1458 - pAd - Pointer to our adapter 1459 - phymode - 1460 - 1461 - ======================================================================== 1462 - */ 1463 - VOID RTMPSetIndividualHT( 1464 - IN PRTMP_ADAPTER pAd, 1465 - IN UCHAR apidx) 1466 - { 1467 - PRT_HT_PHY_INFO pDesired_ht_phy = NULL; 1468 - UCHAR TxStream = pAd->CommonCfg.TxStream; 1469 - UCHAR DesiredMcs = MCS_AUTO; 1470 - 1471 - do 1472 - { 1473 - { 1474 - pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo; 1475 - DesiredMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS; 1476 - //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE; 1477 - break; 1478 - } 1479 - } while (FALSE); 1480 - 1481 - if (pDesired_ht_phy == NULL) 1482 - { 1483 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx)); 1484 - return; 1485 - } 1486 - RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO)); 1487 - 1488 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs)); 1489 - // Check the validity of MCS 1490 - if ((TxStream == 1) && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15))) 1491 - { 1492 - DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", DesiredMcs)); 1493 - DesiredMcs = MCS_7; 1494 - } 1495 - 1496 - if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) && (DesiredMcs == MCS_32)) 1497 - { 1498 - DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n")); 1499 - DesiredMcs = MCS_0; 1500 - } 1501 - 1502 - pDesired_ht_phy->bHtEnable = TRUE; 1503 - 1504 - // Decide desired Tx MCS 1505 - switch (TxStream) 1506 - { 1507 - case 1: 1508 - if (DesiredMcs == MCS_AUTO) 1509 - { 1510 - pDesired_ht_phy->MCSSet[0]= 0xff; 1511 - pDesired_ht_phy->MCSSet[1]= 0x00; 1512 - } 1513 - else if (DesiredMcs <= MCS_7) 1514 - { 1515 - pDesired_ht_phy->MCSSet[0]= 1<<DesiredMcs; 1516 - pDesired_ht_phy->MCSSet[1]= 0x00; 1517 - } 1518 - break; 1519 - 1520 - case 2: 1521 - if (DesiredMcs == MCS_AUTO) 1522 - { 1523 - pDesired_ht_phy->MCSSet[0]= 0xff; 1524 - pDesired_ht_phy->MCSSet[1]= 0xff; 1525 - } 1526 - else if (DesiredMcs <= MCS_15) 1527 - { 1528 - ULONG mode; 1529 - 1530 - mode = DesiredMcs / 8; 1531 - if (mode < 2) 1532 - pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8)); 1533 - } 1534 - break; 1535 - 1536 - case 3: // 3*3 1537 - if (DesiredMcs == MCS_AUTO) 1538 - { 1539 - /* MCS0 ~ MCS23, 3 bytes */ 1540 - pDesired_ht_phy->MCSSet[0]= 0xff; 1541 - pDesired_ht_phy->MCSSet[1]= 0xff; 1542 - pDesired_ht_phy->MCSSet[2]= 0xff; 1543 - } 1544 - else if (DesiredMcs <= MCS_23) 1545 - { 1546 - ULONG mode; 1547 - 1548 - mode = DesiredMcs / 8; 1549 - if (mode < 3) 1550 - pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8)); 1551 - } 1552 - break; 1553 - } 1554 - 1555 - if(pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40) 1556 - { 1557 - if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32) 1558 - pDesired_ht_phy->MCSSet[4] = 0x1; 1559 - } 1560 - 1561 - // update HT Rate setting 1562 - if (pAd->OpMode == OPMODE_STA) 1563 - MlmeUpdateHtTxRates(pAd, BSS0); 1564 - else 1565 - MlmeUpdateHtTxRates(pAd, apidx); 1566 - } 1567 - 1568 - 1569 - /* 1570 - ======================================================================== 1571 - Routine Description: 1572 - Update HT IE from our capability. 1573 - 1574 - Arguments: 1575 - Send all HT IE in beacon/probe rsp/assoc rsp/action frame. 1576 - 1577 - 1578 - ======================================================================== 1579 - */ 1580 - VOID RTMPUpdateHTIE( 1581 - IN RT_HT_CAPABILITY *pRtHt, 1582 - IN UCHAR *pMcsSet, 1583 - OUT HT_CAPABILITY_IE *pHtCapability, 1584 - OUT ADD_HT_INFO_IE *pAddHtInfo) 1585 - { 1586 - RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE)); 1587 - RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE)); 1588 - 1589 - pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth; 1590 - pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs; 1591 - pHtCapability->HtCapInfo.GF = pRtHt->GF; 1592 - pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20; 1593 - pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40; 1594 - pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC; 1595 - pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC; 1596 - pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize; 1597 - pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor; 1598 - pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity; 1599 - 1600 - pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset ; 1601 - pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth; 1602 - pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode; 1603 - pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent; 1604 - RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet*/pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar. 1605 - 1606 - DBGPRINT(RT_DEBUG_TRACE,("RTMPUpdateHTIE <== \n")); 1607 - } 1608 - 1609 - /* 1610 - ======================================================================== 1611 - Description: 1612 - Add Client security information into ASIC WCID table and IVEIV table. 1613 - Return: 1614 - ======================================================================== 1615 - */ 1616 - VOID RTMPAddWcidAttributeEntry( 1617 - IN PRTMP_ADAPTER pAd, 1618 - IN UCHAR BssIdx, 1619 - IN UCHAR KeyIdx, 1620 - IN UCHAR CipherAlg, 1621 - IN MAC_TABLE_ENTRY *pEntry) 1622 - { 1623 - UINT32 WCIDAttri = 0; 1624 - USHORT offset; 1625 - UCHAR IVEIV = 0; 1626 - USHORT Wcid = 0; 1627 - 1628 - { 1629 - { 1630 - if (BssIdx > BSS0) 1631 - { 1632 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", BssIdx)); 1633 - return; 1634 - } 1635 - 1636 - // 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists. 1637 - // 2. In Infra mode, the AID:1 MUST be wcid of infra STA. 1638 - // the AID:2~ assign to mesh link entry. 1639 - if (pEntry && ADHOC_ON(pAd)) 1640 - Wcid = pEntry->Aid; 1641 - else if (pEntry && INFRA_ON(pAd)) 1642 - { 1643 - Wcid = BSSID_WCID; 1644 - } 1645 - else 1646 - Wcid = MCAST_WCID; 1647 - } 1648 - } 1649 - 1650 - // Update WCID attribute table 1651 - offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE); 1652 - 1653 - { 1654 - if (pEntry && pEntry->ValidAsMesh) 1655 - WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE; 1656 - else 1657 - WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE; 1658 - } 1659 - 1660 - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); 1661 - 1662 - 1663 - // Update IV/EIV table 1664 - offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE); 1665 - 1666 - // WPA mode 1667 - if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES)) 1668 - { 1669 - // Eiv bit on. keyid always is 0 for pairwise key 1670 - IVEIV = (KeyIdx <<6) | 0x20; 1671 - } 1672 - else 1673 - { 1674 - // WEP KeyIdx is default tx key. 1675 - IVEIV = (KeyIdx << 6); 1676 - } 1677 - 1678 - // For key index and ext IV bit, so only need to update the position(offset+3). 1679 - #ifdef RT2870 1680 - RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV); 1681 - #endif // RT2870 // 1682 - 1683 - DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg])); 1684 - DBGPRINT(RT_DEBUG_TRACE,(" WCIDAttri = 0x%x \n", WCIDAttri)); 1685 - 1686 - } 1687 - 1688 - /* 1689 - ========================================================================== 1690 - Description: 1691 - Parse encryption type 1692 - Arguments: 1693 - pAdapter Pointer to our adapter 1694 - wrq Pointer to the ioctl argument 1695 - 1696 - Return Value: 1697 - None 1698 - 1699 - Note: 1700 - ========================================================================== 1701 - */ 1702 - CHAR *GetEncryptType(CHAR enc) 1703 - { 1704 - if(enc == Ndis802_11WEPDisabled) 1705 - return "NONE"; 1706 - if(enc == Ndis802_11WEPEnabled) 1707 - return "WEP"; 1708 - if(enc == Ndis802_11Encryption2Enabled) 1709 - return "TKIP"; 1710 - if(enc == Ndis802_11Encryption3Enabled) 1711 - return "AES"; 1712 - if(enc == Ndis802_11Encryption4Enabled) 1713 - return "TKIPAES"; 1714 - else 1715 - return "UNKNOW"; 1716 - } 1717 - 1718 - CHAR *GetAuthMode(CHAR auth) 1719 - { 1720 - if(auth == Ndis802_11AuthModeOpen) 1721 - return "OPEN"; 1722 - if(auth == Ndis802_11AuthModeShared) 1723 - return "SHARED"; 1724 - if(auth == Ndis802_11AuthModeAutoSwitch) 1725 - return "AUTOWEP"; 1726 - if(auth == Ndis802_11AuthModeWPA) 1727 - return "WPA"; 1728 - if(auth == Ndis802_11AuthModeWPAPSK) 1729 - return "WPAPSK"; 1730 - if(auth == Ndis802_11AuthModeWPANone) 1731 - return "WPANONE"; 1732 - if(auth == Ndis802_11AuthModeWPA2) 1733 - return "WPA2"; 1734 - if(auth == Ndis802_11AuthModeWPA2PSK) 1735 - return "WPA2PSK"; 1736 - if(auth == Ndis802_11AuthModeWPA1WPA2) 1737 - return "WPA1WPA2"; 1738 - if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK) 1739 - return "WPA1PSKWPA2PSK"; 1740 - 1741 - return "UNKNOW"; 1742 - } 1743 - 1744 - /* 1745 - ========================================================================== 1746 - Description: 1747 - Get site survey results 1748 - Arguments: 1749 - pAdapter Pointer to our adapter 1750 - wrq Pointer to the ioctl argument 1751 - 1752 - Return Value: 1753 - None 1754 - 1755 - Note: 1756 - Usage: 1757 - 1.) UI needs to wait 4 seconds after issue a site survey command 1758 - 2.) iwpriv ra0 get_site_survey 1759 - 3.) UI needs to prepare at least 4096bytes to get the results 1760 - ========================================================================== 1761 - */ 1762 - #define LINE_LEN (4+33+20+8+10+9+7+3) // Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType 1763 - VOID RTMPIoctlGetSiteSurvey( 1764 - IN PRTMP_ADAPTER pAdapter, 1765 - IN struct iwreq *wrq) 1766 - { 1767 - CHAR *msg; 1768 - INT i=0; 1769 - INT WaitCnt; 1770 - INT Status=0; 1771 - CHAR Ssid[MAX_LEN_OF_SSID +1]; 1772 - INT Rssi = 0, max_len = LINE_LEN; 1773 - UINT Rssi_Quality = 0; 1774 - NDIS_802_11_NETWORK_TYPE wireless_mode; 1775 - 1776 - os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len)); 1777 - 1778 - if (msg == NULL) 1779 - { 1780 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n")); 1781 - return; 1782 - } 1783 - 1784 - memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len ); 1785 - memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1)); 1786 - sprintf(msg,"%s","\n"); 1787 - sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n", 1788 - "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT"); 1789 - 1790 - 1791 - WaitCnt = 0; 1792 - pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE; 1793 - 1794 - while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200)) 1795 - OS_WAIT(500); 1796 - 1797 - for(i=0; i<pAdapter->ScanTab.BssNr ;i++) 1798 - { 1799 - if( pAdapter->ScanTab.BssEntry[i].Channel==0) 1800 - break; 1801 - 1802 - if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA) 1803 - break; 1804 - 1805 - //Channel 1806 - sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel); 1807 - //SSID 1808 - memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen); 1809 - Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0'; 1810 - sprintf(msg+strlen(msg),"%-33s", Ssid); 1811 - //BSSID 1812 - sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x ", 1813 - pAdapter->ScanTab.BssEntry[i].Bssid[0], 1814 - pAdapter->ScanTab.BssEntry[i].Bssid[1], 1815 - pAdapter->ScanTab.BssEntry[i].Bssid[2], 1816 - pAdapter->ScanTab.BssEntry[i].Bssid[3], 1817 - pAdapter->ScanTab.BssEntry[i].Bssid[4], 1818 - pAdapter->ScanTab.BssEntry[i].Bssid[5]); 1819 - //Encryption Type 1820 - sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus)); 1821 - //Authentication Mode 1822 - if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled) 1823 - sprintf(msg+strlen(msg),"%-10s", "UNKNOW"); 1824 - else 1825 - sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode)); 1826 - // Rssi 1827 - Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi; 1828 - if (Rssi >= -50) 1829 - Rssi_Quality = 100; 1830 - else if (Rssi >= -80) // between -50 ~ -80dbm 1831 - Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10); 1832 - else if (Rssi >= -90) // between -80 ~ -90dbm 1833 - Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10); 1834 - else // < -84 dbm 1835 - Rssi_Quality = 0; 1836 - sprintf(msg+strlen(msg),"%-9d", Rssi_Quality); 1837 - // Wireless Mode 1838 - wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]); 1839 - if (wireless_mode == Ndis802_11FH || 1840 - wireless_mode == Ndis802_11DS) 1841 - sprintf(msg+strlen(msg),"%-7s", "11b"); 1842 - else if (wireless_mode == Ndis802_11OFDM5) 1843 - sprintf(msg+strlen(msg),"%-7s", "11a"); 1844 - else if (wireless_mode == Ndis802_11OFDM5_N) 1845 - sprintf(msg+strlen(msg),"%-7s", "11a/n"); 1846 - else if (wireless_mode == Ndis802_11OFDM24) 1847 - sprintf(msg+strlen(msg),"%-7s", "11b/g"); 1848 - else if (wireless_mode == Ndis802_11OFDM24_N) 1849 - sprintf(msg+strlen(msg),"%-7s", "11b/g/n"); 1850 - else 1851 - sprintf(msg+strlen(msg),"%-7s", "unknow"); 1852 - //Network Type 1853 - if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC) 1854 - sprintf(msg+strlen(msg),"%-3s", " Ad"); 1855 - else 1856 - sprintf(msg+strlen(msg),"%-3s", " In"); 1857 - 1858 - sprintf(msg+strlen(msg),"\n"); 1859 - } 1860 - 1861 - pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE; 1862 - wrq->u.data.length = strlen(msg); 1863 - Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length); 1864 - 1865 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length)); 1866 - os_free_mem(NULL, (PUCHAR)msg); 1867 - } 1868 - 1869 - 1870 - #define MAC_LINE_LEN (14+4+4+10+10+10+6+6) // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate 1871 - VOID RTMPIoctlGetMacTable( 1872 - IN PRTMP_ADAPTER pAd, 1873 - IN struct iwreq *wrq) 1874 - { 1875 - INT i; 1876 - RT_802_11_MAC_TABLE MacTab; 1877 - char *msg; 1878 - 1879 - MacTab.Num = 0; 1880 - for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++) 1881 - { 1882 - if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC)) 1883 - { 1884 - COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr); 1885 - MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid; 1886 - MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode; 1887 - MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode; 1888 - 1889 - // Fill in RSSI per entry 1890 - MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0; 1891 - MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1; 1892 - MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2; 1893 - 1894 - // the connected time per entry 1895 - MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime; 1896 - MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS; 1897 - MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW; 1898 - MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI; 1899 - MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC; 1900 - MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv; 1901 - MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE; 1902 - MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word; 1903 - 1904 - MacTab.Num += 1; 1905 - } 1906 - } 1907 - wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE); 1908 - if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length)) 1909 - { 1910 - DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__)); 1911 - } 1912 - 1913 - msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG); 1914 - memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN ); 1915 - sprintf(msg,"%s","\n"); 1916 - sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n", 1917 - "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR"); 1918 - 1919 - for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++) 1920 - { 1921 - PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i]; 1922 - if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC)) 1923 - { 1924 - if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) ) 1925 - break; 1926 - sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x ", 1927 - pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2], 1928 - pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]); 1929 - sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid); 1930 - sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode); 1931 - sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo 1932 - sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo 1933 - sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo 1934 - sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]); 1935 - sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo 1936 - } 1937 - } 1938 - // for compatible with old API just do the printk to console 1939 - //wrq->u.data.length = strlen(msg); 1940 - //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length)) 1941 - { 1942 - DBGPRINT(RT_DEBUG_TRACE, ("%s", msg)); 1943 - } 1944 - 1945 - kfree(msg); 1946 - } 1947 - 1948 - INT Set_BASetup_Proc( 1949 - IN PRTMP_ADAPTER pAd, 1950 - IN PUCHAR arg) 1951 - { 1952 - UCHAR mac[6], tid; 1953 - char *token, sepValue[] = ":", DASH = '-'; 1954 - INT i; 1955 - MAC_TABLE_ENTRY *pEntry; 1956 - 1957 - /* 1958 - The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d, 1959 - =>The six 2 digit hex-decimal number previous are the Mac address, 1960 - =>The seventh decimal number is the tid value. 1961 - */ 1962 - 1963 - if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format. 1964 - return FALSE; 1965 - 1966 - token = strchr(arg, DASH); 1967 - if ((token != NULL) && (strlen(token)>1)) 1968 - { 1969 - tid = simple_strtol((token+1), 0, 10); 1970 - if (tid > 15) 1971 - return FALSE; 1972 - 1973 - *token = '\0'; 1974 - for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++) 1975 - { 1976 - if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1)))) 1977 - return FALSE; 1978 - AtoH(token, (PUCHAR)(&mac[i]), 1); 1979 - } 1980 - if(i != 6) 1981 - return FALSE; 1982 - 1983 - printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1], 1984 - mac[2], mac[3], mac[4], mac[5], tid); 1985 - 1986 - pEntry = MacTableLookup(pAd, mac); 1987 - 1988 - if (pEntry) { 1989 - printk("\nSetup BA Session: Tid = %d\n", tid); 1990 - BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE); 1991 - } 1992 - 1993 - return TRUE; 1994 - } 1995 - 1996 - return FALSE; 1997 - 1998 - } 1999 - 2000 - INT Set_BADecline_Proc( 2001 - IN PRTMP_ADAPTER pAd, 2002 - IN PUCHAR arg) 2003 - { 2004 - ULONG bBADecline; 2005 - 2006 - bBADecline = simple_strtol(arg, 0, 10); 2007 - 2008 - if (bBADecline == 0) 2009 - { 2010 - pAd->CommonCfg.bBADecline = FALSE; 2011 - } 2012 - else if (bBADecline == 1) 2013 - { 2014 - pAd->CommonCfg.bBADecline = TRUE; 2015 - } 2016 - else 2017 - { 2018 - return FALSE; //Invalid argument 2019 - } 2020 - 2021 - DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline)); 2022 - 2023 - return TRUE; 2024 - } 2025 - 2026 - INT Set_BAOriTearDown_Proc( 2027 - IN PRTMP_ADAPTER pAd, 2028 - IN PUCHAR arg) 2029 - { 2030 - UCHAR mac[6], tid; 2031 - char *token, sepValue[] = ":", DASH = '-'; 2032 - INT i; 2033 - MAC_TABLE_ENTRY *pEntry; 2034 - 2035 - /* 2036 - The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d, 2037 - =>The six 2 digit hex-decimal number previous are the Mac address, 2038 - =>The seventh decimal number is the tid value. 2039 - */ 2040 - if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format. 2041 - return FALSE; 2042 - 2043 - token = strchr(arg, DASH); 2044 - if ((token != NULL) && (strlen(token)>1)) 2045 - { 2046 - tid = simple_strtol((token+1), 0, 10); 2047 - if (tid > NUM_OF_TID) 2048 - return FALSE; 2049 - 2050 - *token = '\0'; 2051 - for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++) 2052 - { 2053 - if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1)))) 2054 - return FALSE; 2055 - AtoH(token, (PUCHAR)(&mac[i]), 1); 2056 - } 2057 - if(i != 6) 2058 - return FALSE; 2059 - 2060 - printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1], 2061 - mac[2], mac[3], mac[4], mac[5], tid); 2062 - 2063 - pEntry = MacTableLookup(pAd, mac); 2064 - 2065 - if (pEntry) { 2066 - printk("\nTear down Ori BA Session: Tid = %d\n", tid); 2067 - BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE); 2068 - } 2069 - 2070 - return TRUE; 2071 - } 2072 - 2073 - return FALSE; 2074 - 2075 - } 2076 - 2077 - INT Set_BARecTearDown_Proc( 2078 - IN PRTMP_ADAPTER pAd, 2079 - IN PUCHAR arg) 2080 - { 2081 - UCHAR mac[6], tid; 2082 - char *token, sepValue[] = ":", DASH = '-'; 2083 - INT i; 2084 - MAC_TABLE_ENTRY *pEntry; 2085 - 2086 - //printk("\n%s\n", arg); 2087 - /* 2088 - The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d, 2089 - =>The six 2 digit hex-decimal number previous are the Mac address, 2090 - =>The seventh decimal number is the tid value. 2091 - */ 2092 - if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format. 2093 - return FALSE; 2094 - 2095 - token = strchr(arg, DASH); 2096 - if ((token != NULL) && (strlen(token)>1)) 2097 - { 2098 - tid = simple_strtol((token+1), 0, 10); 2099 - if (tid > NUM_OF_TID) 2100 - return FALSE; 2101 - 2102 - *token = '\0'; 2103 - for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++) 2104 - { 2105 - if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1)))) 2106 - return FALSE; 2107 - AtoH(token, (PUCHAR)(&mac[i]), 1); 2108 - } 2109 - if(i != 6) 2110 - return FALSE; 2111 - 2112 - printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1], 2113 - mac[2], mac[3], mac[4], mac[5], tid); 2114 - 2115 - pEntry = MacTableLookup(pAd, mac); 2116 - 2117 - if (pEntry) { 2118 - printk("\nTear down Rec BA Session: Tid = %d\n", tid); 2119 - BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE); 2120 - } 2121 - 2122 - return TRUE; 2123 - } 2124 - 2125 - return FALSE; 2126 - 2127 - } 2128 - 2129 - INT Set_HtBw_Proc( 2130 - IN PRTMP_ADAPTER pAd, 2131 - IN PUCHAR arg) 2132 - { 2133 - ULONG HtBw; 2134 - 2135 - HtBw = simple_strtol(arg, 0, 10); 2136 - if (HtBw == BW_40) 2137 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40; 2138 - else if (HtBw == BW_20) 2139 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20; 2140 - else 2141 - return FALSE; //Invalid argument 2142 - 2143 - SetCommonHT(pAd); 2144 - 2145 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW)); 2146 - 2147 - return TRUE; 2148 - } 2149 - 2150 - INT Set_HtMcs_Proc( 2151 - IN PRTMP_ADAPTER pAd, 2152 - IN PUCHAR arg) 2153 - { 2154 - ULONG HtMcs, Mcs_tmp; 2155 - BOOLEAN bAutoRate = FALSE; 2156 - 2157 - Mcs_tmp = simple_strtol(arg, 0, 10); 2158 - 2159 - if (Mcs_tmp <= 15 || Mcs_tmp == 32) 2160 - HtMcs = Mcs_tmp; 2161 - else 2162 - HtMcs = MCS_AUTO; 2163 - 2164 - { 2165 - pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs; 2166 - pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE; 2167 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n", 2168 - pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch)); 2169 - 2170 - if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) || 2171 - (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX)) 2172 - { 2173 - if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) && 2174 - (HtMcs >= 0 && HtMcs <= 3) && 2175 - (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK)) 2176 - { 2177 - RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000)); 2178 - } 2179 - else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) && 2180 - (HtMcs >= 0 && HtMcs <= 7) && 2181 - (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM)) 2182 - { 2183 - RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000)); 2184 - } 2185 - else 2186 - bAutoRate = TRUE; 2187 - 2188 - if (bAutoRate) 2189 - { 2190 - pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; 2191 - RTMPSetDesiredRates(pAd, -1); 2192 - } 2193 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode)); 2194 - } 2195 - if (ADHOC_ON(pAd)) 2196 - return TRUE; 2197 - } 2198 - 2199 - SetCommonHT(pAd); 2200 - 2201 - return TRUE; 2202 - } 2203 - 2204 - INT Set_HtGi_Proc( 2205 - IN PRTMP_ADAPTER pAd, 2206 - IN PUCHAR arg) 2207 - { 2208 - ULONG HtGi; 2209 - 2210 - HtGi = simple_strtol(arg, 0, 10); 2211 - 2212 - if ( HtGi == GI_400) 2213 - pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400; 2214 - else if ( HtGi == GI_800 ) 2215 - pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800; 2216 - else 2217 - return FALSE; //Invalid argument 2218 - 2219 - SetCommonHT(pAd); 2220 - 2221 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI)); 2222 - 2223 - return TRUE; 2224 - } 2225 - 2226 - 2227 - INT Set_HtTxBASize_Proc( 2228 - IN PRTMP_ADAPTER pAd, 2229 - IN PUCHAR arg) 2230 - { 2231 - UCHAR Size; 2232 - 2233 - Size = simple_strtol(arg, 0, 10); 2234 - 2235 - if (Size <=0 || Size >=64) 2236 - { 2237 - Size = 8; 2238 - } 2239 - pAd->CommonCfg.TxBASize = Size-1; 2240 - DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size)); 2241 - 2242 - return TRUE; 2243 - } 2244 - 2245 - 2246 - INT Set_HtOpMode_Proc( 2247 - IN PRTMP_ADAPTER pAd, 2248 - IN PUCHAR arg) 2249 - { 2250 - 2251 - ULONG Value; 2252 - 2253 - Value = simple_strtol(arg, 0, 10); 2254 - 2255 - if (Value == HTMODE_GF) 2256 - pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF; 2257 - else if ( Value == HTMODE_MM ) 2258 - pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM; 2259 - else 2260 - return FALSE; //Invalid argument 2261 - 2262 - SetCommonHT(pAd); 2263 - 2264 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE)); 2265 - 2266 - return TRUE; 2267 - 2268 - } 2269 - 2270 - INT Set_HtStbc_Proc( 2271 - IN PRTMP_ADAPTER pAd, 2272 - IN PUCHAR arg) 2273 - { 2274 - 2275 - ULONG Value; 2276 - 2277 - Value = simple_strtol(arg, 0, 10); 2278 - 2279 - if (Value == STBC_USE) 2280 - pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE; 2281 - else if ( Value == STBC_NONE ) 2282 - pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE; 2283 - else 2284 - return FALSE; //Invalid argument 2285 - 2286 - SetCommonHT(pAd); 2287 - 2288 - DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC)); 2289 - 2290 - return TRUE; 2291 - } 2292 - 2293 - INT Set_HtHtc_Proc( 2294 - IN PRTMP_ADAPTER pAd, 2295 - IN PUCHAR arg) 2296 - { 2297 - 2298 - ULONG Value; 2299 - 2300 - Value = simple_strtol(arg, 0, 10); 2301 - if (Value == 0) 2302 - pAd->HTCEnable = FALSE; 2303 - else if ( Value ==1 ) 2304 - pAd->HTCEnable = TRUE; 2305 - else 2306 - return FALSE; //Invalid argument 2307 - 2308 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable)); 2309 - 2310 - return TRUE; 2311 - } 2312 - 2313 - INT Set_HtExtcha_Proc( 2314 - IN PRTMP_ADAPTER pAd, 2315 - IN PUCHAR arg) 2316 - { 2317 - 2318 - ULONG Value; 2319 - 2320 - Value = simple_strtol(arg, 0, 10); 2321 - 2322 - if (Value == 0) 2323 - pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW; 2324 - else if ( Value ==1 ) 2325 - pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE; 2326 - else 2327 - return FALSE; //Invalid argument 2328 - 2329 - SetCommonHT(pAd); 2330 - 2331 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)); 2332 - 2333 - return TRUE; 2334 - } 2335 - 2336 - INT Set_HtMpduDensity_Proc( 2337 - IN PRTMP_ADAPTER pAd, 2338 - IN PUCHAR arg) 2339 - { 2340 - ULONG Value; 2341 - 2342 - Value = simple_strtol(arg, 0, 10); 2343 - 2344 - if (Value <=7 && Value >= 0) 2345 - pAd->CommonCfg.BACapability.field.MpduDensity = Value; 2346 - else 2347 - pAd->CommonCfg.BACapability.field.MpduDensity = 4; 2348 - 2349 - SetCommonHT(pAd); 2350 - 2351 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity)); 2352 - 2353 - return TRUE; 2354 - } 2355 - 2356 - INT Set_HtBaWinSize_Proc( 2357 - IN PRTMP_ADAPTER pAd, 2358 - IN PUCHAR arg) 2359 - { 2360 - ULONG Value; 2361 - 2362 - Value = simple_strtol(arg, 0, 10); 2363 - 2364 - 2365 - if (Value >=1 && Value <= 64) 2366 - { 2367 - pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value; 2368 - pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value; 2369 - } 2370 - else 2371 - { 2372 - pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64; 2373 - pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; 2374 - } 2375 - 2376 - SetCommonHT(pAd); 2377 - 2378 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit)); 2379 - 2380 - return TRUE; 2381 - } 2382 - 2383 - INT Set_HtRdg_Proc( 2384 - IN PRTMP_ADAPTER pAd, 2385 - IN PUCHAR arg) 2386 - { 2387 - ULONG Value; 2388 - 2389 - Value = simple_strtol(arg, 0, 10); 2390 - 2391 - if (Value == 0) 2392 - pAd->CommonCfg.bRdg = FALSE; 2393 - else if ( Value ==1 ) 2394 - { 2395 - pAd->HTCEnable = TRUE; 2396 - pAd->CommonCfg.bRdg = TRUE; 2397 - } 2398 - else 2399 - return FALSE; //Invalid argument 2400 - 2401 - SetCommonHT(pAd); 2402 - 2403 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg)); 2404 - 2405 - return TRUE; 2406 - } 2407 - 2408 - INT Set_HtLinkAdapt_Proc( 2409 - IN PRTMP_ADAPTER pAd, 2410 - IN PUCHAR arg) 2411 - { 2412 - ULONG Value; 2413 - 2414 - Value = simple_strtol(arg, 0, 10); 2415 - if (Value == 0) 2416 - pAd->bLinkAdapt = FALSE; 2417 - else if ( Value ==1 ) 2418 - { 2419 - pAd->HTCEnable = TRUE; 2420 - pAd->bLinkAdapt = TRUE; 2421 - } 2422 - else 2423 - return FALSE; //Invalid argument 2424 - 2425 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt)); 2426 - 2427 - return TRUE; 2428 - } 2429 - 2430 - INT Set_HtAmsdu_Proc( 2431 - IN PRTMP_ADAPTER pAd, 2432 - IN PUCHAR arg) 2433 - { 2434 - ULONG Value; 2435 - 2436 - Value = simple_strtol(arg, 0, 10); 2437 - if (Value == 0) 2438 - pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE; 2439 - else if ( Value == 1 ) 2440 - pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE; 2441 - else 2442 - return FALSE; //Invalid argument 2443 - 2444 - SetCommonHT(pAd); 2445 - 2446 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable)); 2447 - 2448 - return TRUE; 2449 - } 2450 - 2451 - INT Set_HtAutoBa_Proc( 2452 - IN PRTMP_ADAPTER pAd, 2453 - IN PUCHAR arg) 2454 - { 2455 - ULONG Value; 2456 - 2457 - Value = simple_strtol(arg, 0, 10); 2458 - if (Value == 0) 2459 - { 2460 - pAd->CommonCfg.BACapability.field.AutoBA = FALSE; 2461 - #ifdef RT30xx 2462 - pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE; 2463 - #endif 2464 - } 2465 - else if (Value == 1) 2466 - { 2467 - pAd->CommonCfg.BACapability.field.AutoBA = TRUE; 2468 - #ifdef RT30xx 2469 - pAd->CommonCfg.BACapability.field.Policy = IMMED_BA; 2470 - #endif 2471 - } 2472 - else 2473 - return FALSE; //Invalid argument 2474 - 2475 - pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA; 2476 - #ifdef RT30xx 2477 - pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy; 2478 - #endif 2479 - SetCommonHT(pAd); 2480 - 2481 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA)); 2482 - 2483 - return TRUE; 2484 - 2485 - } 2486 - 2487 - INT Set_HtProtect_Proc( 2488 - IN PRTMP_ADAPTER pAd, 2489 - IN PUCHAR arg) 2490 - { 2491 - ULONG Value; 2492 - 2493 - Value = simple_strtol(arg, 0, 10); 2494 - if (Value == 0) 2495 - pAd->CommonCfg.bHTProtect = FALSE; 2496 - else if (Value == 1) 2497 - pAd->CommonCfg.bHTProtect = TRUE; 2498 - else 2499 - return FALSE; //Invalid argument 2500 - 2501 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect)); 2502 - 2503 - return TRUE; 2504 - } 2505 - 2506 - INT Set_SendPSMPAction_Proc( 2507 - IN PRTMP_ADAPTER pAd, 2508 - IN PUCHAR arg) 2509 - { 2510 - UCHAR mac[6], mode; 2511 - char *token, sepValue[] = ":", DASH = '-'; 2512 - INT i; 2513 - MAC_TABLE_ENTRY *pEntry; 2514 - 2515 - //printk("\n%s\n", arg); 2516 - /* 2517 - The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d, 2518 - =>The six 2 digit hex-decimal number previous are the Mac address, 2519 - =>The seventh decimal number is the mode value. 2520 - */ 2521 - if(strlen(arg) < 19) //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format. 2522 - return FALSE; 2523 - 2524 - token = strchr(arg, DASH); 2525 - if ((token != NULL) && (strlen(token)>1)) 2526 - { 2527 - mode = simple_strtol((token+1), 0, 10); 2528 - if (mode > MMPS_ENABLE) 2529 - return FALSE; 2530 - 2531 - *token = '\0'; 2532 - for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++) 2533 - { 2534 - if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1)))) 2535 - return FALSE; 2536 - AtoH(token, (PUCHAR)(&mac[i]), 1); 2537 - } 2538 - if(i != 6) 2539 - return FALSE; 2540 - 2541 - printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1], 2542 - mac[2], mac[3], mac[4], mac[5], mode); 2543 - 2544 - pEntry = MacTableLookup(pAd, mac); 2545 - 2546 - if (pEntry) { 2547 - printk("\nSendPSMPAction MIPS mode = %d\n", mode); 2548 - SendPSMPAction(pAd, pEntry->Aid, mode); 2549 - } 2550 - 2551 - return TRUE; 2552 - } 2553 - 2554 - return FALSE; 2555 - 2556 - 2557 - } 2558 - 2559 - INT Set_HtMIMOPSmode_Proc( 2560 - IN PRTMP_ADAPTER pAd, 2561 - IN PUCHAR arg) 2562 - { 2563 - ULONG Value; 2564 - 2565 - Value = simple_strtol(arg, 0, 10); 2566 - 2567 - if (Value <=3 && Value >= 0) 2568 - pAd->CommonCfg.BACapability.field.MMPSmode = Value; 2569 - else 2570 - pAd->CommonCfg.BACapability.field.MMPSmode = 3; 2571 - 2572 - SetCommonHT(pAd); 2573 - 2574 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode)); 2575 - 2576 - return TRUE; 2577 - } 2578 - 2579 - 2580 - INT Set_ForceShortGI_Proc( 2581 - IN PRTMP_ADAPTER pAd, 2582 - IN PUCHAR arg) 2583 - { 2584 - ULONG Value; 2585 - 2586 - Value = simple_strtol(arg, 0, 10); 2587 - if (Value == 0) 2588 - pAd->WIFItestbed.bShortGI = FALSE; 2589 - else if (Value == 1) 2590 - pAd->WIFItestbed.bShortGI = TRUE; 2591 - else 2592 - return FALSE; //Invalid argument 2593 - 2594 - SetCommonHT(pAd); 2595 - 2596 - DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI)); 2597 - 2598 - return TRUE; 2599 - } 2600 - 2601 - 2602 - 2603 - INT Set_ForceGF_Proc( 2604 - IN PRTMP_ADAPTER pAd, 2605 - IN PUCHAR arg) 2606 - { 2607 - ULONG Value; 2608 - 2609 - Value = simple_strtol(arg, 0, 10); 2610 - if (Value == 0) 2611 - pAd->WIFItestbed.bGreenField = FALSE; 2612 - else if (Value == 1) 2613 - pAd->WIFItestbed.bGreenField = TRUE; 2614 - else 2615 - return FALSE; //Invalid argument 2616 - 2617 - SetCommonHT(pAd); 2618 - 2619 - DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField)); 2620 - 2621 - return TRUE; 2622 - } 2623 - 2624 - INT Set_HtMimoPs_Proc( 2625 - IN PRTMP_ADAPTER pAd, 2626 - IN PUCHAR arg) 2627 - { 2628 - ULONG Value; 2629 - 2630 - Value = simple_strtol(arg, 0, 10); 2631 - if (Value == 0) 2632 - pAd->CommonCfg.bMIMOPSEnable = FALSE; 2633 - else if (Value == 1) 2634 - pAd->CommonCfg.bMIMOPSEnable = TRUE; 2635 - else 2636 - return FALSE; //Invalid argument 2637 - 2638 - DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable)); 2639 - 2640 - return TRUE; 2641 - } 2642 - 2643 - INT SetCommonHT( 2644 - IN PRTMP_ADAPTER pAd) 2645 - { 2646 - OID_SET_HT_PHYMODE SetHT; 2647 - 2648 - if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) 2649 - return FALSE; 2650 - 2651 - SetHT.PhyMode = pAd->CommonCfg.PhyMode; 2652 - SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath); 2653 - SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE; 2654 - SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA; 2655 - SetHT.MCS = MCS_AUTO; 2656 - SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW; 2657 - SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC; 2658 - SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI; 2659 - 2660 - RTMPSetHT(pAd, &SetHT); 2661 - 2662 - return TRUE; 2663 - } 2664 - 2665 - INT Set_FixedTxMode_Proc( 2666 - IN PRTMP_ADAPTER pAd, 2667 - IN PUCHAR arg) 2668 - { 2669 - UCHAR fix_tx_mode = FIXED_TXMODE_HT; 2670 - 2671 - if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0) 2672 - { 2673 - fix_tx_mode = FIXED_TXMODE_OFDM; 2674 - } 2675 - else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0) 2676 - { 2677 - fix_tx_mode = FIXED_TXMODE_CCK; 2678 - } 2679 - 2680 - pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode; 2681 - 2682 - DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode)); 2683 - 2684 - return TRUE; 2685 - } 2686 - 2687 - ///////////////////////////////////////////////////////////////////////// 2688 - PCHAR RTMPGetRalinkAuthModeStr( 2689 - IN NDIS_802_11_AUTHENTICATION_MODE authMode) 2690 - { 2691 - switch(authMode) 2692 - { 2693 - case Ndis802_11AuthModeOpen: 2694 - return "OPEN"; 2695 - #ifdef RT30xx 2696 - default: 2697 - #endif 2698 - case Ndis802_11AuthModeWPAPSK: 2699 - return "WPAPSK"; 2700 - case Ndis802_11AuthModeShared: 2701 - return "SHARED"; 2702 - case Ndis802_11AuthModeWPA: 2703 - return "WPA"; 2704 - case Ndis802_11AuthModeWPA2: 2705 - return "WPA2"; 2706 - case Ndis802_11AuthModeWPA2PSK: 2707 - return "WPA2PSK"; 2708 - case Ndis802_11AuthModeWPA1PSKWPA2PSK: 2709 - return "WPAPSKWPA2PSK"; 2710 - case Ndis802_11AuthModeWPA1WPA2: 2711 - return "WPA1WPA2"; 2712 - #ifndef RT30xx 2713 - case Ndis802_11AuthModeWPANone: 2714 - return "WPANONE"; 2715 - default: 2716 - return "UNKNOW"; 2717 - #endif 2718 - } 2719 - } 2720 - 2721 - PCHAR RTMPGetRalinkEncryModeStr( 2722 - IN USHORT encryMode) 2723 - { 2724 - switch(encryMode) 2725 - { 2726 - #ifdef RT30xx 2727 - default: 2728 - #endif 2729 - case Ndis802_11WEPDisabled: 2730 - return "NONE"; 2731 - case Ndis802_11WEPEnabled: 2732 - return "WEP"; 2733 - case Ndis802_11Encryption2Enabled: 2734 - return "TKIP"; 2735 - case Ndis802_11Encryption3Enabled: 2736 - return "AES"; 2737 - case Ndis802_11Encryption4Enabled: 2738 - return "TKIPAES"; 2739 - #ifndef RT30xx 2740 - default: 2741 - return "UNKNOW"; 2742 - #endif 2743 - } 2744 - } 2745 - 2746 - INT RTMPShowCfgValue( 2747 - IN PRTMP_ADAPTER pAd, 2748 - IN PUCHAR pName, 2749 - IN PUCHAR pBuf) 2750 - { 2751 - INT Status = 0; 2752 - 2753 - for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++) 2754 - { 2755 - if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name)) 2756 - { 2757 - if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf)) 2758 - Status = -EINVAL; 2759 - break; //Exit for loop. 2760 - } 2761 - } 2762 - 2763 - if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL) 2764 - { 2765 - sprintf(pBuf, "\n"); 2766 - for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++) 2767 - #ifndef RT30xx 2768 - sprintf(pBuf + strlen(pBuf), "%s\n", PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name); 2769 - #endif 2770 - #ifdef RT30xx 2771 - sprintf(pBuf, "%s%s\n", pBuf, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name); 2772 - #endif 2773 - } 2774 - 2775 - return Status; 2776 - } 2777 - 2778 - INT Show_SSID_Proc( 2779 - IN PRTMP_ADAPTER pAd, 2780 - OUT PUCHAR pBuf) 2781 - { 2782 - sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid); 2783 - return 0; 2784 - } 2785 - 2786 - INT Show_WirelessMode_Proc( 2787 - IN PRTMP_ADAPTER pAd, 2788 - OUT PUCHAR pBuf) 2789 - { 2790 - switch(pAd->CommonCfg.PhyMode) 2791 - { 2792 - case PHY_11BG_MIXED: 2793 - sprintf(pBuf, "\t11B/G"); 2794 - break; 2795 - case PHY_11B: 2796 - sprintf(pBuf, "\t11B"); 2797 - break; 2798 - case PHY_11A: 2799 - sprintf(pBuf, "\t11A"); 2800 - break; 2801 - case PHY_11ABG_MIXED: 2802 - sprintf(pBuf, "\t11A/B/G"); 2803 - break; 2804 - case PHY_11G: 2805 - sprintf(pBuf, "\t11G"); 2806 - break; 2807 - case PHY_11ABGN_MIXED: 2808 - sprintf(pBuf, "\t11A/B/G/N"); 2809 - break; 2810 - case PHY_11N_2_4G: 2811 - sprintf(pBuf, "\t11N only with 2.4G"); 2812 - break; 2813 - case PHY_11GN_MIXED: 2814 - sprintf(pBuf, "\t11G/N"); 2815 - break; 2816 - case PHY_11AN_MIXED: 2817 - sprintf(pBuf, "\t11A/N"); 2818 - break; 2819 - case PHY_11BGN_MIXED: 2820 - sprintf(pBuf, "\t11B/G/N"); 2821 - break; 2822 - case PHY_11AGN_MIXED: 2823 - sprintf(pBuf, "\t11A/G/N"); 2824 - break; 2825 - case PHY_11N_5G: 2826 - sprintf(pBuf, "\t11N only with 5G"); 2827 - break; 2828 - default: 2829 - sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode); 2830 - break; 2831 - } 2832 - return 0; 2833 - } 2834 - 2835 - 2836 - INT Show_TxBurst_Proc( 2837 - IN PRTMP_ADAPTER pAd, 2838 - OUT PUCHAR pBuf) 2839 - { 2840 - sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE"); 2841 - return 0; 2842 - } 2843 - 2844 - INT Show_TxPreamble_Proc( 2845 - IN PRTMP_ADAPTER pAd, 2846 - OUT PUCHAR pBuf) 2847 - { 2848 - switch(pAd->CommonCfg.TxPreamble) 2849 - { 2850 - case Rt802_11PreambleShort: 2851 - sprintf(pBuf, "\tShort"); 2852 - break; 2853 - case Rt802_11PreambleLong: 2854 - sprintf(pBuf, "\tLong"); 2855 - break; 2856 - case Rt802_11PreambleAuto: 2857 - sprintf(pBuf, "\tAuto"); 2858 - break; 2859 - default: 2860 - sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble); 2861 - break; 2862 - } 2863 - 2864 - return 0; 2865 - } 2866 - 2867 - INT Show_TxPower_Proc( 2868 - IN PRTMP_ADAPTER pAd, 2869 - OUT PUCHAR pBuf) 2870 - { 2871 - sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage); 2872 - return 0; 2873 - } 2874 - 2875 - INT Show_Channel_Proc( 2876 - IN PRTMP_ADAPTER pAd, 2877 - OUT PUCHAR pBuf) 2878 - { 2879 - sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel); 2880 - return 0; 2881 - } 2882 - 2883 - INT Show_BGProtection_Proc( 2884 - IN PRTMP_ADAPTER pAd, 2885 - OUT PUCHAR pBuf) 2886 - { 2887 - switch(pAd->CommonCfg.UseBGProtection) 2888 - { 2889 - case 1: //Always On 2890 - sprintf(pBuf, "\tON"); 2891 - break; 2892 - case 2: //Always OFF 2893 - sprintf(pBuf, "\tOFF"); 2894 - break; 2895 - case 0: //AUTO 2896 - sprintf(pBuf, "\tAuto"); 2897 - break; 2898 - default: 2899 - sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection); 2900 - break; 2901 - } 2902 - return 0; 2903 - } 2904 - 2905 - INT Show_RTSThreshold_Proc( 2906 - IN PRTMP_ADAPTER pAd, 2907 - OUT PUCHAR pBuf) 2908 - { 2909 - sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold); 2910 - return 0; 2911 - } 2912 - 2913 - INT Show_FragThreshold_Proc( 2914 - IN PRTMP_ADAPTER pAd, 2915 - OUT PUCHAR pBuf) 2916 - { 2917 - sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold); 2918 - return 0; 2919 - } 2920 - 2921 - INT Show_HtBw_Proc( 2922 - IN PRTMP_ADAPTER pAd, 2923 - OUT PUCHAR pBuf) 2924 - { 2925 - if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40) 2926 - { 2927 - sprintf(pBuf, "\t40 MHz"); 2928 - } 2929 - else 2930 - { 2931 - sprintf(pBuf, "\t20 MHz"); 2932 - } 2933 - return 0; 2934 - } 2935 - 2936 - INT Show_HtMcs_Proc( 2937 - IN PRTMP_ADAPTER pAd, 2938 - OUT PUCHAR pBuf) 2939 - { 2940 - sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS); 2941 - return 0; 2942 - } 2943 - 2944 - INT Show_HtGi_Proc( 2945 - IN PRTMP_ADAPTER pAd, 2946 - OUT PUCHAR pBuf) 2947 - { 2948 - switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI) 2949 - { 2950 - case GI_400: 2951 - sprintf(pBuf, "\tGI_400"); 2952 - break; 2953 - case GI_800: 2954 - sprintf(pBuf, "\tGI_800"); 2955 - break; 2956 - default: 2957 - sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI); 2958 - break; 2959 - } 2960 - return 0; 2961 - } 2962 - 2963 - INT Show_HtOpMode_Proc( 2964 - IN PRTMP_ADAPTER pAd, 2965 - OUT PUCHAR pBuf) 2966 - { 2967 - switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE) 2968 - { 2969 - case HTMODE_GF: 2970 - sprintf(pBuf, "\tGF"); 2971 - break; 2972 - case HTMODE_MM: 2973 - sprintf(pBuf, "\tMM"); 2974 - break; 2975 - default: 2976 - sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE); 2977 - break; 2978 - } 2979 - return 0; 2980 - } 2981 - 2982 - INT Show_HtExtcha_Proc( 2983 - IN PRTMP_ADAPTER pAd, 2984 - OUT PUCHAR pBuf) 2985 - { 2986 - switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA) 2987 - { 2988 - case EXTCHA_BELOW: 2989 - sprintf(pBuf, "\tBelow"); 2990 - break; 2991 - case EXTCHA_ABOVE: 2992 - sprintf(pBuf, "\tAbove"); 2993 - break; 2994 - default: 2995 - sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA); 2996 - break; 2997 - } 2998 - return 0; 2999 - } 3000 - 3001 - 3002 - INT Show_HtMpduDensity_Proc( 3003 - IN PRTMP_ADAPTER pAd, 3004 - OUT PUCHAR pBuf) 3005 - { 3006 - sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity); 3007 - return 0; 3008 - } 3009 - 3010 - INT Show_HtBaWinSize_Proc( 3011 - IN PRTMP_ADAPTER pAd, 3012 - OUT PUCHAR pBuf) 3013 - { 3014 - sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit); 3015 - return 0; 3016 - } 3017 - 3018 - INT Show_HtRdg_Proc( 3019 - IN PRTMP_ADAPTER pAd, 3020 - OUT PUCHAR pBuf) 3021 - { 3022 - sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE"); 3023 - return 0; 3024 - } 3025 - 3026 - INT Show_HtAmsdu_Proc( 3027 - IN PRTMP_ADAPTER pAd, 3028 - OUT PUCHAR pBuf) 3029 - { 3030 - sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE"); 3031 - return 0; 3032 - } 3033 - 3034 - INT Show_HtAutoBa_Proc( 3035 - IN PRTMP_ADAPTER pAd, 3036 - OUT PUCHAR pBuf) 3037 - { 3038 - sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE"); 3039 - return 0; 3040 - } 3041 - 3042 - INT Show_CountryRegion_Proc( 3043 - IN PRTMP_ADAPTER pAd, 3044 - OUT PUCHAR pBuf) 3045 - { 3046 - sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion); 3047 - return 0; 3048 - } 3049 - 3050 - INT Show_CountryRegionABand_Proc( 3051 - IN PRTMP_ADAPTER pAd, 3052 - OUT PUCHAR pBuf) 3053 - { 3054 - sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand); 3055 - return 0; 3056 - } 3057 - 3058 - INT Show_CountryCode_Proc( 3059 - IN PRTMP_ADAPTER pAd, 3060 - OUT PUCHAR pBuf) 3061 - { 3062 - sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode); 3063 - return 0; 3064 - } 3065 - 3066 - #ifdef AGGREGATION_SUPPORT 3067 - INT Show_PktAggregate_Proc( 3068 - IN PRTMP_ADAPTER pAd, 3069 - OUT PUCHAR pBuf) 3070 - { 3071 - sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE"); 3072 - return 0; 3073 - } 3074 - #endif // AGGREGATION_SUPPORT // 3075 - 3076 - #ifdef WMM_SUPPORT 3077 - INT Show_WmmCapable_Proc( 3078 - IN PRTMP_ADAPTER pAd, 3079 - OUT PUCHAR pBuf) 3080 - { 3081 - sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE"); 3082 - 3083 - return 0; 3084 - } 3085 - #endif // WMM_SUPPORT // 3086 - 3087 - INT Show_IEEE80211H_Proc( 3088 - IN PRTMP_ADAPTER pAd, 3089 - OUT PUCHAR pBuf) 3090 - { 3091 - sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE"); 3092 - return 0; 3093 - } 3094 - 3095 - INT Show_NetworkType_Proc( 3096 - IN PRTMP_ADAPTER pAd, 3097 - OUT PUCHAR pBuf) 3098 - { 3099 - switch(pAd->StaCfg.BssType) 3100 - { 3101 - case BSS_ADHOC: 3102 - sprintf(pBuf, "\tAdhoc"); 3103 - break; 3104 - case BSS_INFRA: 3105 - sprintf(pBuf, "\tInfra"); 3106 - break; 3107 - case BSS_ANY: 3108 - sprintf(pBuf, "\tAny"); 3109 - break; 3110 - case BSS_MONITOR: 3111 - sprintf(pBuf, "\tMonitor"); 3112 - break; 3113 - default: 3114 - sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType); 3115 - break; 3116 - } 3117 - return 0; 3118 - } 3119 - 3120 - INT Show_AuthMode_Proc( 3121 - IN PRTMP_ADAPTER pAd, 3122 - OUT PUCHAR pBuf) 3123 - { 3124 - NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen; 3125 - 3126 - AuthMode = pAd->StaCfg.AuthMode; 3127 - 3128 - if ((AuthMode >= Ndis802_11AuthModeOpen) && 3129 - (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK)) 3130 - sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode)); 3131 - else 3132 - sprintf(pBuf, "\tUnknow Value(%d)", AuthMode); 3133 - 3134 - return 0; 3135 - } 3136 - 3137 - INT Show_EncrypType_Proc( 3138 - IN PRTMP_ADAPTER pAd, 3139 - OUT PUCHAR pBuf) 3140 - { 3141 - NDIS_802_11_WEP_STATUS WepStatus = Ndis802_11WEPDisabled; 3142 - 3143 - WepStatus = pAd->StaCfg.WepStatus; 3144 - 3145 - if ((WepStatus >= Ndis802_11WEPEnabled) && 3146 - (WepStatus <= Ndis802_11Encryption4KeyAbsent)) 3147 - sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus)); 3148 - else 3149 - sprintf(pBuf, "\tUnknow Value(%d)", WepStatus); 3150 - 3151 - return 0; 3152 - } 3153 - 3154 - INT Show_DefaultKeyID_Proc( 3155 - IN PRTMP_ADAPTER pAd, 3156 - OUT PUCHAR pBuf) 3157 - { 3158 - UCHAR DefaultKeyId = 0; 3159 - 3160 - DefaultKeyId = pAd->StaCfg.DefaultKeyId; 3161 - 3162 - sprintf(pBuf, "\t%d", DefaultKeyId); 3163 - 3164 - return 0; 3165 - } 3166 - 3167 - INT Show_WepKey_Proc( 3168 - IN PRTMP_ADAPTER pAd, 3169 - IN INT KeyIdx, 3170 - OUT PUCHAR pBuf) 3171 - { 3172 - UCHAR Key[16] = {0}, KeyLength = 0; 3173 - INT index = BSS0; 3174 - 3175 - KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen; 3176 - NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength); 3177 - 3178 - //check key string is ASCII or not 3179 - if (RTMPCheckStrPrintAble(Key, KeyLength)) 3180 - sprintf(pBuf, "\t%s", Key); 3181 - else 3182 - { 3183 - int idx; 3184 - sprintf(pBuf, "\t"); 3185 - for (idx = 0; idx < KeyLength; idx++) 3186 - sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]); 3187 - } 3188 - return 0; 3189 - } 3190 - 3191 - INT Show_Key1_Proc( 3192 - IN PRTMP_ADAPTER pAd, 3193 - OUT PUCHAR pBuf) 3194 - { 3195 - Show_WepKey_Proc(pAd, 0, pBuf); 3196 - return 0; 3197 - } 3198 - 3199 - INT Show_Key2_Proc( 3200 - IN PRTMP_ADAPTER pAd, 3201 - OUT PUCHAR pBuf) 3202 - { 3203 - Show_WepKey_Proc(pAd, 1, pBuf); 3204 - return 0; 3205 - } 3206 - 3207 - INT Show_Key3_Proc( 3208 - IN PRTMP_ADAPTER pAd, 3209 - OUT PUCHAR pBuf) 3210 - { 3211 - Show_WepKey_Proc(pAd, 2, pBuf); 3212 - return 0; 3213 - } 3214 - 3215 - INT Show_Key4_Proc( 3216 - IN PRTMP_ADAPTER pAd, 3217 - OUT PUCHAR pBuf) 3218 - { 3219 - Show_WepKey_Proc(pAd, 3, pBuf); 3220 - return 0; 3221 - } 3222 - 3223 - INT Show_WPAPSK_Proc( 3224 - IN PRTMP_ADAPTER pAd, 3225 - OUT PUCHAR pBuf) 3226 - { 3227 - INT idx; 3228 - UCHAR PMK[32] = {0}; 3229 - 3230 - NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32); 3231 - 3232 - sprintf(pBuf, "\tPMK = "); 3233 - for (idx = 0; idx < 32; idx++) 3234 - sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]); 3235 - 3236 - return 0; 3237 - } 3238 - 1 + #include "../../rt2860/common/cmm_info.c"
+1 -1238
drivers/staging/rt2870/common/cmm_sanity.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - sanity.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - John Chang 2004-09-01 add WMM support 36 - */ 37 - #include "../rt_config.h" 38 - 39 - 40 - extern UCHAR CISCO_OUI[]; 41 - 42 - extern UCHAR WPA_OUI[]; 43 - extern UCHAR RSN_OUI[]; 44 - extern UCHAR WME_INFO_ELEM[]; 45 - extern UCHAR WME_PARM_ELEM[]; 46 - extern UCHAR Ccx2QosInfo[]; 47 - extern UCHAR RALINK_OUI[]; 48 - extern UCHAR BROADCOM_OUI[]; 49 - extern UCHAR WPS_OUI[]; 50 - 51 - /* 52 - ========================================================================== 53 - Description: 54 - MLME message sanity check 55 - Return: 56 - TRUE if all parameters are OK, FALSE otherwise 57 - 58 - IRQL = DISPATCH_LEVEL 59 - 60 - ========================================================================== 61 - */ 62 - BOOLEAN MlmeAddBAReqSanity( 63 - IN PRTMP_ADAPTER pAd, 64 - IN VOID *Msg, 65 - IN ULONG MsgLen, 66 - OUT PUCHAR pAddr2) 67 - { 68 - PMLME_ADDBA_REQ_STRUCT pInfo; 69 - 70 - pInfo = (MLME_ADDBA_REQ_STRUCT *)Msg; 71 - 72 - if ((MsgLen != sizeof(MLME_ADDBA_REQ_STRUCT))) 73 - { 74 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - message lenght not correct.\n")); 75 - return FALSE; 76 - } 77 - 78 - if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) 79 - { 80 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n")); 81 - return FALSE; 82 - } 83 - 84 - if ((pInfo->pAddr[0]&0x01) == 0x01) 85 - { 86 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - broadcast address not support BA\n")); 87 - return FALSE; 88 - } 89 - 90 - return TRUE; 91 - } 92 - 93 - /* 94 - ========================================================================== 95 - Description: 96 - MLME message sanity check 97 - Return: 98 - TRUE if all parameters are OK, FALSE otherwise 99 - 100 - IRQL = DISPATCH_LEVEL 101 - 102 - ========================================================================== 103 - */ 104 - BOOLEAN MlmeDelBAReqSanity( 105 - IN PRTMP_ADAPTER pAd, 106 - IN VOID *Msg, 107 - IN ULONG MsgLen) 108 - { 109 - MLME_DELBA_REQ_STRUCT *pInfo; 110 - pInfo = (MLME_DELBA_REQ_STRUCT *)Msg; 111 - 112 - if ((MsgLen != sizeof(MLME_DELBA_REQ_STRUCT))) 113 - { 114 - DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - message lenght not correct.\n")); 115 - return FALSE; 116 - } 117 - 118 - if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) 119 - { 120 - DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n")); 121 - return FALSE; 122 - } 123 - 124 - if ((pInfo->TID & 0xf0)) 125 - { 126 - DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n")); 127 - return FALSE; 128 - } 129 - 130 - if (NdisEqualMemory(pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr, MAC_ADDR_LEN) == 0) 131 - { 132 - DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n")); 133 - return FALSE; 134 - } 135 - 136 - return TRUE; 137 - } 138 - 139 - BOOLEAN PeerAddBAReqActionSanity( 140 - IN PRTMP_ADAPTER pAd, 141 - IN VOID *pMsg, 142 - IN ULONG MsgLen, 143 - OUT PUCHAR pAddr2) 144 - { 145 - PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg; 146 - PFRAME_ADDBA_REQ pAddFrame; 147 - pAddFrame = (PFRAME_ADDBA_REQ)(pMsg); 148 - if (MsgLen < (sizeof(FRAME_ADDBA_REQ))) 149 - { 150 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", MsgLen)); 151 - return FALSE; 152 - } 153 - // we support immediate BA. 154 - *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm)); 155 - pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); 156 - pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word); 157 - 158 - if (pAddFrame->BaParm.BAPolicy != IMMED_BA) 159 - { 160 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy)); 161 - DBGPRINT(RT_DEBUG_ERROR,("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, pAddFrame->BaParm.AMSDUSupported)); 162 - return FALSE; 163 - } 164 - 165 - // we support immediate BA. 166 - if (pAddFrame->BaParm.TID &0xfff0) 167 - { 168 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", pAddFrame->BaParm.TID)); 169 - return FALSE; 170 - } 171 - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); 172 - return TRUE; 173 - } 174 - 175 - BOOLEAN PeerAddBARspActionSanity( 176 - IN PRTMP_ADAPTER pAd, 177 - IN VOID *pMsg, 178 - IN ULONG MsgLen) 179 - { 180 - PFRAME_ADDBA_RSP pAddFrame; 181 - 182 - pAddFrame = (PFRAME_ADDBA_RSP)(pMsg); 183 - if (MsgLen < (sizeof(FRAME_ADDBA_RSP))) 184 - { 185 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", MsgLen)); 186 - return FALSE; 187 - } 188 - // we support immediate BA. 189 - *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm)); 190 - pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode); 191 - pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); 192 - 193 - if (pAddFrame->BaParm.BAPolicy != IMMED_BA) 194 - { 195 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy)); 196 - return FALSE; 197 - } 198 - 199 - // we support immediate BA. 200 - if (pAddFrame->BaParm.TID &0xfff0) 201 - { 202 - DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", pAddFrame->BaParm.TID)); 203 - return FALSE; 204 - } 205 - return TRUE; 206 - 207 - } 208 - 209 - BOOLEAN PeerDelBAActionSanity( 210 - IN PRTMP_ADAPTER pAd, 211 - IN UCHAR Wcid, 212 - IN VOID *pMsg, 213 - IN ULONG MsgLen ) 214 - { 215 - //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg; 216 - PFRAME_DELBA_REQ pDelFrame; 217 - if (MsgLen != (sizeof(FRAME_DELBA_REQ))) 218 - return FALSE; 219 - 220 - if (Wcid >= MAX_LEN_OF_MAC_TABLE) 221 - return FALSE; 222 - 223 - pDelFrame = (PFRAME_DELBA_REQ)(pMsg); 224 - 225 - *(USHORT *)(&pDelFrame->DelbaParm) = cpu2le16(*(USHORT *)(&pDelFrame->DelbaParm)); 226 - pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode); 227 - 228 - if (pDelFrame->DelbaParm.TID &0xfff0) 229 - return FALSE; 230 - 231 - return TRUE; 232 - } 233 - 234 - /* 235 - ========================================================================== 236 - Description: 237 - MLME message sanity check 238 - Return: 239 - TRUE if all parameters are OK, FALSE otherwise 240 - 241 - IRQL = DISPATCH_LEVEL 242 - 243 - ========================================================================== 244 - */ 245 - BOOLEAN PeerBeaconAndProbeRspSanity( 246 - IN PRTMP_ADAPTER pAd, 247 - IN VOID *Msg, 248 - IN ULONG MsgLen, 249 - IN UCHAR MsgChannel, 250 - OUT PUCHAR pAddr2, 251 - OUT PUCHAR pBssid, 252 - OUT CHAR Ssid[], 253 - OUT UCHAR *pSsidLen, 254 - OUT UCHAR *pBssType, 255 - OUT USHORT *pBeaconPeriod, 256 - OUT UCHAR *pChannel, 257 - OUT UCHAR *pNewChannel, 258 - OUT LARGE_INTEGER *pTimestamp, 259 - OUT CF_PARM *pCfParm, 260 - OUT USHORT *pAtimWin, 261 - OUT USHORT *pCapabilityInfo, 262 - OUT UCHAR *pErp, 263 - OUT UCHAR *pDtimCount, 264 - OUT UCHAR *pDtimPeriod, 265 - OUT UCHAR *pBcastFlag, 266 - OUT UCHAR *pMessageToMe, 267 - OUT UCHAR SupRate[], 268 - OUT UCHAR *pSupRateLen, 269 - OUT UCHAR ExtRate[], 270 - OUT UCHAR *pExtRateLen, 271 - OUT UCHAR *pCkipFlag, 272 - OUT UCHAR *pAironetCellPowerLimit, 273 - OUT PEDCA_PARM pEdcaParm, 274 - OUT PQBSS_LOAD_PARM pQbssLoad, 275 - OUT PQOS_CAPABILITY_PARM pQosCapability, 276 - OUT ULONG *pRalinkIe, 277 - OUT UCHAR *pHtCapabilityLen, 278 - OUT UCHAR *pPreNHtCapabilityLen, 279 - OUT HT_CAPABILITY_IE *pHtCapability, 280 - OUT UCHAR *AddHtInfoLen, 281 - OUT ADD_HT_INFO_IE *AddHtInfo, 282 - OUT UCHAR *NewExtChannelOffset, // Ht extension channel offset(above or below) 283 - OUT USHORT *LengthVIE, 284 - OUT PNDIS_802_11_VARIABLE_IEs pVIE) 285 - { 286 - CHAR *Ptr; 287 - CHAR TimLen; 288 - PFRAME_802_11 pFrame; 289 - PEID_STRUCT pEid; 290 - UCHAR SubType; 291 - UCHAR Sanity; 292 - //UCHAR ECWMin, ECWMax; 293 - //MAC_CSR9_STRUC Csr9; 294 - ULONG Length = 0; 295 - 296 - // For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel 297 - // 1. If the AP is 11n enabled, then check the control channel. 298 - // 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!!) 299 - UCHAR CtrlChannel = 0; 300 - 301 - // Add for 3 necessary EID field check 302 - Sanity = 0; 303 - 304 - *pAtimWin = 0; 305 - *pErp = 0; 306 - *pDtimCount = 0; 307 - *pDtimPeriod = 0; 308 - *pBcastFlag = 0; 309 - *pMessageToMe = 0; 310 - *pExtRateLen = 0; 311 - *pCkipFlag = 0; // Default of CkipFlag is 0 312 - *pAironetCellPowerLimit = 0xFF; // Default of AironetCellPowerLimit is 0xFF 313 - *LengthVIE = 0; // Set the length of VIE to init value 0 314 - *pHtCapabilityLen = 0; // Set the length of VIE to init value 0 315 - if (pAd->OpMode == OPMODE_STA) 316 - *pPreNHtCapabilityLen = 0; // Set the length of VIE to init value 0 317 - *AddHtInfoLen = 0; // Set the length of VIE to init value 0 318 - *pRalinkIe = 0; 319 - *pNewChannel = 0; 320 - *NewExtChannelOffset = 0xff; //Default 0xff means no such IE 321 - pCfParm->bValid = FALSE; // default: no IE_CF found 322 - pQbssLoad->bValid = FALSE; // default: no IE_QBSS_LOAD found 323 - pEdcaParm->bValid = FALSE; // default: no IE_EDCA_PARAMETER found 324 - pQosCapability->bValid = FALSE; // default: no IE_QOS_CAPABILITY found 325 - 326 - pFrame = (PFRAME_802_11)Msg; 327 - 328 - // get subtype from header 329 - SubType = (UCHAR)pFrame->Hdr.FC.SubType; 330 - 331 - // get Addr2 and BSSID from header 332 - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); 333 - COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3); 334 - 335 - Ptr = pFrame->Octet; 336 - Length += LENGTH_802_11; 337 - 338 - // get timestamp from payload and advance the pointer 339 - NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN); 340 - 341 - pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart); 342 - pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart); 343 - 344 - Ptr += TIMESTAMP_LEN; 345 - Length += TIMESTAMP_LEN; 346 - 347 - // get beacon interval from payload and advance the pointer 348 - NdisMoveMemory(pBeaconPeriod, Ptr, 2); 349 - Ptr += 2; 350 - Length += 2; 351 - 352 - // get capability info from payload and advance the pointer 353 - NdisMoveMemory(pCapabilityInfo, Ptr, 2); 354 - Ptr += 2; 355 - Length += 2; 356 - 357 - if (CAP_IS_ESS_ON(*pCapabilityInfo)) 358 - *pBssType = BSS_INFRA; 359 - else 360 - *pBssType = BSS_ADHOC; 361 - 362 - pEid = (PEID_STRUCT) Ptr; 363 - 364 - // get variable fields from payload and advance the pointer 365 - while ((Length + 2 + pEid->Len) <= MsgLen) 366 - { 367 - // 368 - // Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow. 369 - // 370 - if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN) 371 - { 372 - DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n", 373 - (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN)); 374 - break; 375 - } 376 - 377 - switch(pEid->Eid) 378 - { 379 - case IE_SSID: 380 - // Already has one SSID EID in this beacon, ignore the second one 381 - if (Sanity & 0x1) 382 - break; 383 - if(pEid->Len <= MAX_LEN_OF_SSID) 384 - { 385 - NdisMoveMemory(Ssid, pEid->Octet, pEid->Len); 386 - *pSsidLen = pEid->Len; 387 - Sanity |= 0x1; 388 - } 389 - else 390 - { 391 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len)); 392 - return FALSE; 393 - } 394 - break; 395 - 396 - case IE_SUPP_RATES: 397 - if(pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) 398 - { 399 - Sanity |= 0x2; 400 - NdisMoveMemory(SupRate, pEid->Octet, pEid->Len); 401 - *pSupRateLen = pEid->Len; 402 - 403 - // TODO: 2004-09-14 not a good design here, cause it exclude extra rates 404 - // from ScanTab. We should report as is. And filter out unsupported 405 - // rates in MlmeAux. 406 - // Check against the supported rates 407 - // RTMPCheckRates(pAd, SupRate, pSupRateLen); 408 - } 409 - else 410 - { 411 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",pEid->Len)); 412 - return FALSE; 413 - } 414 - break; 415 - 416 - case IE_HT_CAP: 417 - if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!! 418 - { 419 - NdisMoveMemory(pHtCapability, pEid->Octet, sizeof(HT_CAPABILITY_IE)); 420 - *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes. 421 - 422 - *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo)); 423 - *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo)); 424 - 425 - { 426 - *pPreNHtCapabilityLen = 0; // Nnow we only support 26 bytes. 427 - 428 - Ptr = (PUCHAR) pVIE; 429 - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); 430 - *LengthVIE += (pEid->Len + 2); 431 - } 432 - } 433 - else 434 - { 435 - DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n", pEid->Len)); 436 - } 437 - 438 - break; 439 - case IE_ADD_HT: 440 - if (pEid->Len >= sizeof(ADD_HT_INFO_IE)) 441 - { 442 - // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only 443 - // copy first sizeof(ADD_HT_INFO_IE) 444 - NdisMoveMemory(AddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE)); 445 - *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; 446 - 447 - CtrlChannel = AddHtInfo->ControlChan; 448 - 449 - *(USHORT *)(&AddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo2)); 450 - *(USHORT *)(&AddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo3)); 451 - 452 - { 453 - Ptr = (PUCHAR) pVIE; 454 - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); 455 - *LengthVIE += (pEid->Len + 2); 456 - } 457 - } 458 - else 459 - { 460 - DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n")); 461 - } 462 - 463 - break; 464 - case IE_SECONDARY_CH_OFFSET: 465 - if (pEid->Len == 1) 466 - { 467 - *NewExtChannelOffset = pEid->Octet[0]; 468 - } 469 - else 470 - { 471 - DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n")); 472 - } 473 - 474 - break; 475 - case IE_FH_PARM: 476 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n")); 477 - break; 478 - 479 - case IE_DS_PARM: 480 - if(pEid->Len == 1) 481 - { 482 - *pChannel = *pEid->Octet; 483 - 484 - { 485 - if (ChannelSanity(pAd, *pChannel) == 0) 486 - { 487 - 488 - return FALSE; 489 - } 490 - } 491 - 492 - Sanity |= 0x4; 493 - } 494 - else 495 - { 496 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n",pEid->Len)); 497 - return FALSE; 498 - } 499 - break; 500 - 501 - case IE_CF_PARM: 502 - if(pEid->Len == 6) 503 - { 504 - pCfParm->bValid = TRUE; 505 - pCfParm->CfpCount = pEid->Octet[0]; 506 - pCfParm->CfpPeriod = pEid->Octet[1]; 507 - pCfParm->CfpMaxDuration = pEid->Octet[2] + 256 * pEid->Octet[3]; 508 - pCfParm->CfpDurRemaining = pEid->Octet[4] + 256 * pEid->Octet[5]; 509 - } 510 - else 511 - { 512 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n")); 513 - return FALSE; 514 - } 515 - break; 516 - 517 - case IE_IBSS_PARM: 518 - if(pEid->Len == 2) 519 - { 520 - NdisMoveMemory(pAtimWin, pEid->Octet, pEid->Len); 521 - } 522 - else 523 - { 524 - DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n")); 525 - return FALSE; 526 - } 527 - break; 528 - 529 - case IE_TIM: 530 - if(INFRA_ON(pAd) && SubType == SUBTYPE_BEACON) 531 - { 532 - GetTimBit((PUCHAR)pEid, pAd->StaActive.Aid, &TimLen, pBcastFlag, pDtimCount, pDtimPeriod, pMessageToMe); 533 - } 534 - break; 535 - 536 - case IE_CHANNEL_SWITCH_ANNOUNCEMENT: 537 - if(pEid->Len == 3) 538 - { 539 - *pNewChannel = pEid->Octet[1]; //extract new channel number 540 - } 541 - break; 542 - 543 - // New for WPA 544 - // CCX v2 has the same IE, we need to parse that too 545 - // Wifi WMM use the same IE vale, need to parse that too 546 - // case IE_WPA: 547 - case IE_VENDOR_SPECIFIC: 548 - // Check the OUI version, filter out non-standard usage 549 - if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3) && (pEid->Len == 7)) 550 - { 551 - //*pRalinkIe = pEid->Octet[3]; 552 - if (pEid->Octet[3] != 0) 553 - *pRalinkIe = pEid->Octet[3]; 554 - else 555 - *pRalinkIe = 0xf0000000; // Set to non-zero value (can't set bit0-2) to represent this is Ralink Chip. So at linkup, we will set ralinkchip flag. 556 - } 557 - // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. 558 - 559 - // Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP, 560 - // Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE 561 - else if ((*pHtCapabilityLen == 0) && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI, 3) && (pEid->Len >= 4) && (pAd->OpMode == OPMODE_STA)) 562 - { 563 - if ((pEid->Octet[3] == OUI_PREN_HT_CAP) && (pEid->Len >= 30) && (*pHtCapabilityLen == 0)) 564 - { 565 - NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE)); 566 - *pPreNHtCapabilityLen = SIZE_HT_CAP_IE; 567 - } 568 - 569 - if ((pEid->Octet[3] == OUI_PREN_ADD_HT) && (pEid->Len >= 26)) 570 - { 571 - NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE)); 572 - *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; 573 - } 574 - } 575 - else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) 576 - { 577 - // Copy to pVIE which will report to microsoft bssid list. 578 - Ptr = (PUCHAR) pVIE; 579 - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); 580 - *LengthVIE += (pEid->Len + 2); 581 - } 582 - else if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24)) 583 - { 584 - PUCHAR ptr; 585 - int i; 586 - 587 - // parsing EDCA parameters 588 - pEdcaParm->bValid = TRUE; 589 - pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10; 590 - pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20; 591 - pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40; 592 - pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f; 593 - pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0; 594 - ptr = &pEid->Octet[8]; 595 - for (i=0; i<4; i++) 596 - { 597 - UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX 598 - pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM 599 - pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN 600 - pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin 601 - pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax 602 - pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us 603 - ptr += 4; // point to next AC 604 - } 605 - } 606 - else if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6) && (pEid->Len == 7)) 607 - { 608 - // parsing EDCA parameters 609 - pEdcaParm->bValid = TRUE; 610 - pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10; 611 - pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20; 612 - pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40; 613 - pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f; 614 - pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0; 615 - 616 - // use default EDCA parameter 617 - pEdcaParm->bACM[QID_AC_BE] = 0; 618 - pEdcaParm->Aifsn[QID_AC_BE] = 3; 619 - pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS; 620 - pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS; 621 - pEdcaParm->Txop[QID_AC_BE] = 0; 622 - 623 - pEdcaParm->bACM[QID_AC_BK] = 0; 624 - pEdcaParm->Aifsn[QID_AC_BK] = 7; 625 - pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS; 626 - pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS; 627 - pEdcaParm->Txop[QID_AC_BK] = 0; 628 - 629 - pEdcaParm->bACM[QID_AC_VI] = 0; 630 - pEdcaParm->Aifsn[QID_AC_VI] = 2; 631 - pEdcaParm->Cwmin[QID_AC_VI] = CW_MIN_IN_BITS-1; 632 - pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS; 633 - pEdcaParm->Txop[QID_AC_VI] = 96; // AC_VI: 96*32us ~= 3ms 634 - 635 - pEdcaParm->bACM[QID_AC_VO] = 0; 636 - pEdcaParm->Aifsn[QID_AC_VO] = 2; 637 - pEdcaParm->Cwmin[QID_AC_VO] = CW_MIN_IN_BITS-2; 638 - pEdcaParm->Cwmax[QID_AC_VO] = CW_MAX_IN_BITS-1; 639 - pEdcaParm->Txop[QID_AC_VO] = 48; // AC_VO: 48*32us ~= 1.5ms 640 - } 641 - break; 642 - 643 - case IE_EXT_SUPP_RATES: 644 - if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) 645 - { 646 - NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len); 647 - *pExtRateLen = pEid->Len; 648 - 649 - // TODO: 2004-09-14 not a good design here, cause it exclude extra rates 650 - // from ScanTab. We should report as is. And filter out unsupported 651 - // rates in MlmeAux. 652 - // Check against the supported rates 653 - // RTMPCheckRates(pAd, ExtRate, pExtRateLen); 654 - } 655 - break; 656 - 657 - case IE_ERP: 658 - if (pEid->Len == 1) 659 - { 660 - *pErp = (UCHAR)pEid->Octet[0]; 661 - } 662 - break; 663 - 664 - case IE_AIRONET_CKIP: 665 - // 0. Check Aironet IE length, it must be larger or equal to 28 666 - // Cisco AP350 used length as 28 667 - // Cisco AP12XX used length as 30 668 - if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2)) 669 - break; 670 - 671 - // 1. Copy CKIP flag byte to buffer for process 672 - *pCkipFlag = *(pEid->Octet + 8); 673 - break; 674 - 675 - case IE_AP_TX_POWER: 676 - // AP Control of Client Transmit Power 677 - //0. Check Aironet IE length, it must be 6 678 - if (pEid->Len != 0x06) 679 - break; 680 - 681 - // Get cell power limit in dBm 682 - if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1) 683 - *pAironetCellPowerLimit = *(pEid->Octet + 4); 684 - break; 685 - 686 - // WPA2 & 802.11i RSN 687 - case IE_RSN: 688 - // There is no OUI for version anymore, check the group cipher OUI before copying 689 - if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3)) 690 - { 691 - // Copy to pVIE which will report to microsoft bssid list. 692 - Ptr = (PUCHAR) pVIE; 693 - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); 694 - *LengthVIE += (pEid->Len + 2); 695 - } 696 - break; 697 - 698 - default: 699 - break; 700 - } 701 - 702 - Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len] 703 - pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len); 704 - } 705 - 706 - // For some 11a AP. it did not have the channel EID, patch here 707 - { 708 - UCHAR LatchRfChannel = MsgChannel; 709 - if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0)) 710 - { 711 - if (CtrlChannel != 0) 712 - *pChannel = CtrlChannel; 713 - else 714 - *pChannel = LatchRfChannel; 715 - Sanity |= 0x4; 716 - } 717 - } 718 - 719 - if (Sanity != 0x7) 720 - { 721 - DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n", Sanity)); 722 - return FALSE; 723 - } 724 - else 725 - { 726 - return TRUE; 727 - } 728 - 729 - } 730 - 731 - /* 732 - ========================================================================== 733 - Description: 734 - MLME message sanity check 735 - Return: 736 - TRUE if all parameters are OK, FALSE otherwise 737 - ========================================================================== 738 - */ 739 - BOOLEAN MlmeScanReqSanity( 740 - IN PRTMP_ADAPTER pAd, 741 - IN VOID *Msg, 742 - IN ULONG MsgLen, 743 - OUT UCHAR *pBssType, 744 - OUT CHAR Ssid[], 745 - OUT UCHAR *pSsidLen, 746 - OUT UCHAR *pScanType) 747 - { 748 - MLME_SCAN_REQ_STRUCT *Info; 749 - 750 - Info = (MLME_SCAN_REQ_STRUCT *)(Msg); 751 - *pBssType = Info->BssType; 752 - *pSsidLen = Info->SsidLen; 753 - NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen); 754 - *pScanType = Info->ScanType; 755 - 756 - if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC || *pBssType == BSS_ANY) 757 - && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE 758 - || *pScanType == SCAN_CISCO_PASSIVE || *pScanType == SCAN_CISCO_ACTIVE 759 - || *pScanType == SCAN_CISCO_CHANNEL_LOAD || *pScanType == SCAN_CISCO_NOISE 760 - )) 761 - { 762 - return TRUE; 763 - } 764 - else 765 - { 766 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqSanity fail - wrong BssType or ScanType\n")); 767 - return FALSE; 768 - } 769 - } 770 - 771 - // IRQL = DISPATCH_LEVEL 772 - UCHAR ChannelSanity( 773 - IN PRTMP_ADAPTER pAd, 774 - IN UCHAR channel) 775 - { 776 - int i; 777 - 778 - for (i = 0; i < pAd->ChannelListNum; i ++) 779 - { 780 - if (channel == pAd->ChannelList[i].Channel) 781 - return 1; 782 - } 783 - return 0; 784 - } 785 - 786 - /* 787 - ========================================================================== 788 - Description: 789 - MLME message sanity check 790 - Return: 791 - TRUE if all parameters are OK, FALSE otherwise 792 - 793 - IRQL = DISPATCH_LEVEL 794 - 795 - ========================================================================== 796 - */ 797 - BOOLEAN PeerDeauthSanity( 798 - IN PRTMP_ADAPTER pAd, 799 - IN VOID *Msg, 800 - IN ULONG MsgLen, 801 - OUT PUCHAR pAddr2, 802 - OUT USHORT *pReason) 803 - { 804 - PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; 805 - 806 - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); 807 - NdisMoveMemory(pReason, &pFrame->Octet[0], 2); 808 - 809 - return TRUE; 810 - } 811 - 812 - /* 813 - ========================================================================== 814 - Description: 815 - MLME message sanity check 816 - Return: 817 - TRUE if all parameters are OK, FALSE otherwise 818 - 819 - IRQL = DISPATCH_LEVEL 820 - 821 - ========================================================================== 822 - */ 823 - BOOLEAN PeerAuthSanity( 824 - IN PRTMP_ADAPTER pAd, 825 - IN VOID *Msg, 826 - IN ULONG MsgLen, 827 - OUT PUCHAR pAddr, 828 - OUT USHORT *pAlg, 829 - OUT USHORT *pSeq, 830 - OUT USHORT *pStatus, 831 - CHAR *pChlgText) 832 - { 833 - PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; 834 - 835 - COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2); 836 - NdisMoveMemory(pAlg, &pFrame->Octet[0], 2); 837 - NdisMoveMemory(pSeq, &pFrame->Octet[2], 2); 838 - NdisMoveMemory(pStatus, &pFrame->Octet[4], 2); 839 - 840 - if ((*pAlg == Ndis802_11AuthModeOpen) 841 - ) 842 - { 843 - if (*pSeq == 1 || *pSeq == 2) 844 - { 845 - return TRUE; 846 - } 847 - else 848 - { 849 - DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n")); 850 - return FALSE; 851 - } 852 - } 853 - else if (*pAlg == Ndis802_11AuthModeShared) 854 - { 855 - if (*pSeq == 1 || *pSeq == 4) 856 - { 857 - return TRUE; 858 - } 859 - else if (*pSeq == 2 || *pSeq == 3) 860 - { 861 - NdisMoveMemory(pChlgText, &pFrame->Octet[8], CIPHER_TEXT_LEN); 862 - return TRUE; 863 - } 864 - else 865 - { 866 - DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n")); 867 - return FALSE; 868 - } 869 - } 870 - else 871 - { 872 - DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong algorithm\n")); 873 - return FALSE; 874 - } 875 - } 876 - 877 - /* 878 - ========================================================================== 879 - Description: 880 - MLME message sanity check 881 - Return: 882 - TRUE if all parameters are OK, FALSE otherwise 883 - ========================================================================== 884 - */ 885 - BOOLEAN MlmeAuthReqSanity( 886 - IN PRTMP_ADAPTER pAd, 887 - IN VOID *Msg, 888 - IN ULONG MsgLen, 889 - OUT PUCHAR pAddr, 890 - OUT ULONG *pTimeout, 891 - OUT USHORT *pAlg) 892 - { 893 - MLME_AUTH_REQ_STRUCT *pInfo; 894 - 895 - pInfo = (MLME_AUTH_REQ_STRUCT *)Msg; 896 - COPY_MAC_ADDR(pAddr, pInfo->Addr); 897 - *pTimeout = pInfo->Timeout; 898 - *pAlg = pInfo->Alg; 899 - 900 - if (((*pAlg == Ndis802_11AuthModeShared) ||(*pAlg == Ndis802_11AuthModeOpen) 901 - ) && 902 - ((*pAddr & 0x01) == 0)) 903 - { 904 - return TRUE; 905 - } 906 - else 907 - { 908 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeAuthReqSanity fail - wrong algorithm\n")); 909 - return FALSE; 910 - } 911 - } 912 - 913 - /* 914 - ========================================================================== 915 - Description: 916 - MLME message sanity check 917 - Return: 918 - TRUE if all parameters are OK, FALSE otherwise 919 - 920 - IRQL = DISPATCH_LEVEL 921 - 922 - ========================================================================== 923 - */ 924 - BOOLEAN MlmeAssocReqSanity( 925 - IN PRTMP_ADAPTER pAd, 926 - IN VOID *Msg, 927 - IN ULONG MsgLen, 928 - OUT PUCHAR pApAddr, 929 - OUT USHORT *pCapabilityInfo, 930 - OUT ULONG *pTimeout, 931 - OUT USHORT *pListenIntv) 932 - { 933 - MLME_ASSOC_REQ_STRUCT *pInfo; 934 - 935 - pInfo = (MLME_ASSOC_REQ_STRUCT *)Msg; 936 - *pTimeout = pInfo->Timeout; // timeout 937 - COPY_MAC_ADDR(pApAddr, pInfo->Addr); // AP address 938 - *pCapabilityInfo = pInfo->CapabilityInfo; // capability info 939 - *pListenIntv = pInfo->ListenIntv; 940 - 941 - return TRUE; 942 - } 943 - 944 - /* 945 - ========================================================================== 946 - Description: 947 - MLME message sanity check 948 - Return: 949 - TRUE if all parameters are OK, FALSE otherwise 950 - 951 - IRQL = DISPATCH_LEVEL 952 - 953 - ========================================================================== 954 - */ 955 - BOOLEAN PeerDisassocSanity( 956 - IN PRTMP_ADAPTER pAd, 957 - IN VOID *Msg, 958 - IN ULONG MsgLen, 959 - OUT PUCHAR pAddr2, 960 - OUT USHORT *pReason) 961 - { 962 - PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; 963 - 964 - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); 965 - NdisMoveMemory(pReason, &pFrame->Octet[0], 2); 966 - 967 - return TRUE; 968 - } 969 - 970 - /* 971 - ======================================================================== 972 - Routine Description: 973 - Sanity check NetworkType (11b, 11g or 11a) 974 - 975 - Arguments: 976 - pBss - Pointer to BSS table. 977 - 978 - Return Value: 979 - Ndis802_11DS .......(11b) 980 - Ndis802_11OFDM24....(11g) 981 - Ndis802_11OFDM5.....(11a) 982 - 983 - IRQL = DISPATCH_LEVEL 984 - 985 - ======================================================================== 986 - */ 987 - NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity( 988 - IN PBSS_ENTRY pBss) 989 - { 990 - NDIS_802_11_NETWORK_TYPE NetWorkType; 991 - UCHAR rate, i; 992 - 993 - NetWorkType = Ndis802_11DS; 994 - 995 - if (pBss->Channel <= 14) 996 - { 997 - // 998 - // First check support Rate. 999 - // 1000 - for (i = 0; i < pBss->SupRateLen; i++) 1001 - { 1002 - rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit 1003 - if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22)) 1004 - { 1005 - continue; 1006 - } 1007 - else 1008 - { 1009 - // 1010 - // Otherwise (even rate > 108) means Ndis802_11OFDM24 1011 - // 1012 - NetWorkType = Ndis802_11OFDM24; 1013 - break; 1014 - } 1015 - } 1016 - 1017 - // 1018 - // Second check Extend Rate. 1019 - // 1020 - if (NetWorkType != Ndis802_11OFDM24) 1021 - { 1022 - for (i = 0; i < pBss->ExtRateLen; i++) 1023 - { 1024 - rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit 1025 - if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22)) 1026 - { 1027 - continue; 1028 - } 1029 - else 1030 - { 1031 - // 1032 - // Otherwise (even rate > 108) means Ndis802_11OFDM24 1033 - // 1034 - NetWorkType = Ndis802_11OFDM24; 1035 - break; 1036 - } 1037 - } 1038 - } 1039 - } 1040 - else 1041 - { 1042 - NetWorkType = Ndis802_11OFDM5; 1043 - } 1044 - 1045 - if (pBss->HtCapabilityLen != 0) 1046 - { 1047 - if (NetWorkType == Ndis802_11OFDM5) 1048 - NetWorkType = Ndis802_11OFDM5_N; 1049 - else 1050 - NetWorkType = Ndis802_11OFDM24_N; 1051 - } 1052 - 1053 - return NetWorkType; 1054 - } 1055 - 1056 - /* 1057 - ========================================================================== 1058 - Description: 1059 - WPA message sanity check 1060 - Return: 1061 - TRUE if all parameters are OK, FALSE otherwise 1062 - ========================================================================== 1063 - */ 1064 - BOOLEAN PeerWpaMessageSanity( 1065 - IN PRTMP_ADAPTER pAd, 1066 - IN PEAPOL_PACKET pMsg, 1067 - IN ULONG MsgLen, 1068 - IN UCHAR MsgType, 1069 - IN MAC_TABLE_ENTRY *pEntry) 1070 - { 1071 - UCHAR mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE]; 1072 - BOOLEAN bReplayDiff = FALSE; 1073 - BOOLEAN bWPA2 = FALSE; 1074 - KEY_INFO EapolKeyInfo; 1075 - UCHAR GroupKeyIndex = 0; 1076 - 1077 - 1078 - NdisZeroMemory(mic, sizeof(mic)); 1079 - NdisZeroMemory(digest, sizeof(digest)); 1080 - NdisZeroMemory(KEYDATA, sizeof(KEYDATA)); 1081 - NdisZeroMemory((PUCHAR)&EapolKeyInfo, sizeof(EapolKeyInfo)); 1082 - 1083 - NdisMoveMemory((PUCHAR)&EapolKeyInfo, (PUCHAR)&pMsg->KeyDesc.KeyInfo, sizeof(KEY_INFO)); 1084 - 1085 - *((USHORT *)&EapolKeyInfo) = cpu2le16(*((USHORT *)&EapolKeyInfo)); 1086 - 1087 - // Choose WPA2 or not 1088 - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) 1089 - bWPA2 = TRUE; 1090 - 1091 - // 0. Check MsgType 1092 - if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1)) 1093 - { 1094 - DBGPRINT(RT_DEBUG_ERROR, ("The message type is invalid(%d)! \n", MsgType)); 1095 - return FALSE; 1096 - } 1097 - 1098 - // 1. Replay counter check 1099 - if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) // For supplicant 1100 - { 1101 - // First validate replay counter, only accept message with larger replay counter. 1102 - // Let equal pass, some AP start with all zero replay counter 1103 - UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY]; 1104 - 1105 - NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY); 1106 - if ((RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY) != 1) && 1107 - (RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0)) 1108 - { 1109 - bReplayDiff = TRUE; 1110 - } 1111 - } 1112 - else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) // For authenticator 1113 - { 1114 - // check Replay Counter coresponds to MSG from authenticator, otherwise discard 1115 - if (!NdisEqualMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY)) 1116 - { 1117 - bReplayDiff = TRUE; 1118 - } 1119 - } 1120 - 1121 - // Replay Counter different condition 1122 - if (bReplayDiff) 1123 - { 1124 - // send wireless event - for replay counter different 1125 - if (pAd->CommonCfg.bWirelessEvent) 1126 - RTMPSendWirelessEvent(pAd, IW_REPLAY_COUNTER_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0); 1127 - 1128 - if (MsgType < EAPOL_GROUP_MSG_1) 1129 - { 1130 - DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n", MsgType)); 1131 - } 1132 - else 1133 - { 1134 - DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4))); 1135 - } 1136 - 1137 - hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY); 1138 - hex_dump("Current replay counter ", pEntry->R_Counter, LEN_KEY_DESC_REPLAY); 1139 - return FALSE; 1140 - } 1141 - 1142 - // 2. Verify MIC except Pairwise Msg1 1143 - if (MsgType != EAPOL_PAIR_MSG_1) 1144 - { 1145 - UCHAR rcvd_mic[LEN_KEY_DESC_MIC]; 1146 - 1147 - // Record the received MIC for check later 1148 - NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); 1149 - NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); 1150 - 1151 - if (pEntry->WepStatus == Ndis802_11Encryption2Enabled) // TKIP 1152 - { 1153 - hmac_md5(pEntry->PTK, LEN_EAP_MICK, (PUCHAR)pMsg, MsgLen, mic); 1154 - } 1155 - else if (pEntry->WepStatus == Ndis802_11Encryption3Enabled) // AES 1156 - { 1157 - HMAC_SHA1((PUCHAR)pMsg, MsgLen, pEntry->PTK, LEN_EAP_MICK, digest); 1158 - NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC); 1159 - } 1160 - 1161 - if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC)) 1162 - { 1163 - // send wireless event - for MIC different 1164 - if (pAd->CommonCfg.bWirelessEvent) 1165 - RTMPSendWirelessEvent(pAd, IW_MIC_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0); 1166 - 1167 - if (MsgType < EAPOL_GROUP_MSG_1) 1168 - { 1169 - DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in pairwise msg %d of 4-way handshake!\n", MsgType)); 1170 - } 1171 - else 1172 - { 1173 - DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4))); 1174 - } 1175 - 1176 - hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC); 1177 - hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC); 1178 - 1179 - return FALSE; 1180 - } 1181 - } 1182 - 1183 - // Extract the context of the Key Data field if it exist 1184 - // The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is un-encrypted. 1185 - // The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted. 1186 - if (pMsg->KeyDesc.KeyDataLen[1] > 0) 1187 - { 1188 - // Decrypt this field 1189 - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1)) 1190 - { 1191 - if(pEntry->WepStatus == Ndis802_11Encryption3Enabled) 1192 - { 1193 - // AES 1194 - AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA, pMsg->KeyDesc.KeyDataLen[1],pMsg->KeyDesc.KeyData); 1195 - } 1196 - else 1197 - { 1198 - INT i; 1199 - UCHAR Key[32]; 1200 - // Decrypt TKIP GTK 1201 - // Construct 32 bytes RC4 Key 1202 - NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16); 1203 - NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16); 1204 - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32); 1205 - //discard first 256 bytes 1206 - for(i = 0; i < 256; i++) 1207 - ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT); 1208 - // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not 1209 - ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]); 1210 - } 1211 - 1212 - if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) 1213 - GroupKeyIndex = EapolKeyInfo.KeyIndex; 1214 - 1215 - } 1216 - else if ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2)) 1217 - { 1218 - NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]); 1219 - } 1220 - else 1221 - { 1222 - 1223 - return TRUE; 1224 - } 1225 - 1226 - // Parse Key Data field to 1227 - // 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2) 1228 - // 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2 1229 - // 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2) 1230 - if (!RTMPParseEapolKeyData(pAd, KEYDATA, pMsg->KeyDesc.KeyDataLen[1], GroupKeyIndex, MsgType, bWPA2, pEntry)) 1231 - { 1232 - return FALSE; 1233 - } 1234 - } 1235 - 1236 - return TRUE; 1237 - 1238 - } 1 + #include "../../rt2860/common/cmm_sanity.c"
+1 -617
drivers/staging/rt2870/common/cmm_sync.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - sync.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - John Chang 2004-09-01 modified for rt2561/2661 36 - */ 37 - #include "../rt_config.h" 38 - 39 - // 2.4 Ghz channel plan index in the TxPower arrays. 40 - #define BG_BAND_REGION_0_START 0 // 1,2,3,4,5,6,7,8,9,10,11 41 - #define BG_BAND_REGION_0_SIZE 11 42 - #define BG_BAND_REGION_1_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13 43 - #define BG_BAND_REGION_1_SIZE 13 44 - #define BG_BAND_REGION_2_START 9 // 10,11 45 - #define BG_BAND_REGION_2_SIZE 2 46 - #define BG_BAND_REGION_3_START 9 // 10,11,12,13 47 - #define BG_BAND_REGION_3_SIZE 4 48 - #define BG_BAND_REGION_4_START 13 // 14 49 - #define BG_BAND_REGION_4_SIZE 1 50 - #define BG_BAND_REGION_5_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14 51 - #define BG_BAND_REGION_5_SIZE 14 52 - #define BG_BAND_REGION_6_START 2 // 3,4,5,6,7,8,9 53 - #define BG_BAND_REGION_6_SIZE 7 54 - #define BG_BAND_REGION_7_START 4 // 5,6,7,8,9,10,11,12,13 55 - #define BG_BAND_REGION_7_SIZE 9 56 - #define BG_BAND_REGION_31_START 0 // 1,2,3,4,5,6,7,8,9,10,11,12,13,14 57 - #define BG_BAND_REGION_31_SIZE 14 58 - 59 - // 5 Ghz channel plan index in the TxPower arrays. 60 - UCHAR A_BAND_REGION_0_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165}; 61 - UCHAR A_BAND_REGION_1_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}; 62 - UCHAR A_BAND_REGION_2_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64}; 63 - UCHAR A_BAND_REGION_3_CHANNEL_LIST[]={52, 56, 60, 64, 149, 153, 157, 161}; 64 - UCHAR A_BAND_REGION_4_CHANNEL_LIST[]={149, 153, 157, 161, 165}; 65 - UCHAR A_BAND_REGION_5_CHANNEL_LIST[]={149, 153, 157, 161}; 66 - UCHAR A_BAND_REGION_6_CHANNEL_LIST[]={36, 40, 44, 48}; 67 - UCHAR A_BAND_REGION_7_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165}; 68 - UCHAR A_BAND_REGION_8_CHANNEL_LIST[]={52, 56, 60, 64}; 69 - UCHAR A_BAND_REGION_9_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165}; 70 - UCHAR A_BAND_REGION_10_CHANNEL_LIST[]={36, 40, 44, 48, 149, 153, 157, 161, 165}; 71 - UCHAR A_BAND_REGION_11_CHANNEL_LIST[]={36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161}; 72 - 73 - //BaSizeArray follows the 802.11n definition as MaxRxFactor. 2^(13+factor) bytes. When factor =0, it's about Ba buffer size =8. 74 - UCHAR BaSizeArray[4] = {8,16,32,64}; 75 - 76 - /* 77 - ========================================================================== 78 - Description: 79 - Update StaCfg->ChannelList[] according to 1) Country Region 2) RF IC type, 80 - and 3) PHY-mode user selected. 81 - The outcome is used by driver when doing site survey. 82 - 83 - IRQL = PASSIVE_LEVEL 84 - IRQL = DISPATCH_LEVEL 85 - 86 - ========================================================================== 87 - */ 88 - VOID BuildChannelList( 89 - IN PRTMP_ADAPTER pAd) 90 - { 91 - UCHAR i, j, index=0, num=0; 92 - PUCHAR pChannelList = NULL; 93 - 94 - NdisZeroMemory(pAd->ChannelList, MAX_NUM_OF_CHANNELS * sizeof(CHANNEL_TX_POWER)); 95 - 96 - // if not 11a-only mode, channel list starts from 2.4Ghz band 97 - if ((pAd->CommonCfg.PhyMode != PHY_11A) 98 - && (pAd->CommonCfg.PhyMode != PHY_11AN_MIXED) && (pAd->CommonCfg.PhyMode != PHY_11N_5G) 99 - ) 100 - { 101 - switch (pAd->CommonCfg.CountryRegion & 0x7f) 102 - { 103 - case REGION_0_BG_BAND: // 1 -11 104 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_0_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_0_SIZE); 105 - index += BG_BAND_REGION_0_SIZE; 106 - break; 107 - case REGION_1_BG_BAND: // 1 - 13 108 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_1_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_1_SIZE); 109 - index += BG_BAND_REGION_1_SIZE; 110 - break; 111 - case REGION_2_BG_BAND: // 10 - 11 112 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_2_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_2_SIZE); 113 - index += BG_BAND_REGION_2_SIZE; 114 - break; 115 - case REGION_3_BG_BAND: // 10 - 13 116 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_3_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_3_SIZE); 117 - index += BG_BAND_REGION_3_SIZE; 118 - break; 119 - case REGION_4_BG_BAND: // 14 120 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_4_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_4_SIZE); 121 - index += BG_BAND_REGION_4_SIZE; 122 - break; 123 - case REGION_5_BG_BAND: // 1 - 14 124 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_5_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_5_SIZE); 125 - index += BG_BAND_REGION_5_SIZE; 126 - break; 127 - case REGION_6_BG_BAND: // 3 - 9 128 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_6_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_6_SIZE); 129 - index += BG_BAND_REGION_6_SIZE; 130 - break; 131 - case REGION_7_BG_BAND: // 5 - 13 132 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_7_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_7_SIZE); 133 - index += BG_BAND_REGION_7_SIZE; 134 - break; 135 - case REGION_31_BG_BAND: // 1 - 14 136 - NdisMoveMemory(&pAd->ChannelList[index], &pAd->TxPower[BG_BAND_REGION_31_START], sizeof(CHANNEL_TX_POWER) * BG_BAND_REGION_31_SIZE); 137 - index += BG_BAND_REGION_31_SIZE; 138 - break; 139 - default: // Error. should never happen 140 - break; 141 - } 142 - for (i=0; i<index; i++) 143 - pAd->ChannelList[i].MaxTxPwr = 20; 144 - } 145 - 146 - if ((pAd->CommonCfg.PhyMode == PHY_11A) || (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) 147 - || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) 148 - || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11N_5G) 149 - ) 150 - { 151 - switch (pAd->CommonCfg.CountryRegionForABand & 0x7f) 152 - { 153 - case REGION_0_A_BAND: 154 - num = sizeof(A_BAND_REGION_0_CHANNEL_LIST)/sizeof(UCHAR); 155 - pChannelList = A_BAND_REGION_0_CHANNEL_LIST; 156 - break; 157 - case REGION_1_A_BAND: 158 - num = sizeof(A_BAND_REGION_1_CHANNEL_LIST)/sizeof(UCHAR); 159 - pChannelList = A_BAND_REGION_1_CHANNEL_LIST; 160 - break; 161 - case REGION_2_A_BAND: 162 - num = sizeof(A_BAND_REGION_2_CHANNEL_LIST)/sizeof(UCHAR); 163 - pChannelList = A_BAND_REGION_2_CHANNEL_LIST; 164 - break; 165 - case REGION_3_A_BAND: 166 - num = sizeof(A_BAND_REGION_3_CHANNEL_LIST)/sizeof(UCHAR); 167 - pChannelList = A_BAND_REGION_3_CHANNEL_LIST; 168 - break; 169 - case REGION_4_A_BAND: 170 - num = sizeof(A_BAND_REGION_4_CHANNEL_LIST)/sizeof(UCHAR); 171 - pChannelList = A_BAND_REGION_4_CHANNEL_LIST; 172 - break; 173 - case REGION_5_A_BAND: 174 - num = sizeof(A_BAND_REGION_5_CHANNEL_LIST)/sizeof(UCHAR); 175 - pChannelList = A_BAND_REGION_5_CHANNEL_LIST; 176 - break; 177 - case REGION_6_A_BAND: 178 - num = sizeof(A_BAND_REGION_6_CHANNEL_LIST)/sizeof(UCHAR); 179 - pChannelList = A_BAND_REGION_6_CHANNEL_LIST; 180 - break; 181 - case REGION_7_A_BAND: 182 - num = sizeof(A_BAND_REGION_7_CHANNEL_LIST)/sizeof(UCHAR); 183 - pChannelList = A_BAND_REGION_7_CHANNEL_LIST; 184 - break; 185 - case REGION_8_A_BAND: 186 - num = sizeof(A_BAND_REGION_8_CHANNEL_LIST)/sizeof(UCHAR); 187 - pChannelList = A_BAND_REGION_8_CHANNEL_LIST; 188 - break; 189 - case REGION_9_A_BAND: 190 - num = sizeof(A_BAND_REGION_9_CHANNEL_LIST)/sizeof(UCHAR); 191 - pChannelList = A_BAND_REGION_9_CHANNEL_LIST; 192 - break; 193 - 194 - case REGION_10_A_BAND: 195 - num = sizeof(A_BAND_REGION_10_CHANNEL_LIST)/sizeof(UCHAR); 196 - pChannelList = A_BAND_REGION_10_CHANNEL_LIST; 197 - break; 198 - 199 - case REGION_11_A_BAND: 200 - num = sizeof(A_BAND_REGION_11_CHANNEL_LIST)/sizeof(UCHAR); 201 - pChannelList = A_BAND_REGION_11_CHANNEL_LIST; 202 - break; 203 - 204 - default: // Error. should never happen 205 - DBGPRINT(RT_DEBUG_WARN,("countryregion=%d not support", pAd->CommonCfg.CountryRegionForABand)); 206 - break; 207 - } 208 - 209 - if (num != 0) 210 - { 211 - UCHAR RadarCh[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}; 212 - for (i=0; i<num; i++) 213 - { 214 - for (j=0; j<MAX_NUM_OF_CHANNELS; j++) 215 - { 216 - if (pChannelList[i] == pAd->TxPower[j].Channel) 217 - NdisMoveMemory(&pAd->ChannelList[index+i], &pAd->TxPower[j], sizeof(CHANNEL_TX_POWER)); 218 - } 219 - for (j=0; j<15; j++) 220 - { 221 - if (pChannelList[i] == RadarCh[j]) 222 - pAd->ChannelList[index+i].DfsReq = TRUE; 223 - } 224 - pAd->ChannelList[index+i].MaxTxPwr = 20; 225 - } 226 - index += num; 227 - } 228 - } 229 - 230 - pAd->ChannelListNum = index; 231 - DBGPRINT(RT_DEBUG_TRACE,("country code=%d/%d, RFIC=%d, PHY mode=%d, support %d channels\n", 232 - pAd->CommonCfg.CountryRegion, pAd->CommonCfg.CountryRegionForABand, pAd->RfIcType, pAd->CommonCfg.PhyMode, pAd->ChannelListNum)); 233 - #ifdef DBG 234 - for (i=0;i<pAd->ChannelListNum;i++) 235 - { 236 - DBGPRINT_RAW(RT_DEBUG_TRACE,("BuildChannel # %d :: Pwr0 = %d, Pwr1 =%d, \n ", pAd->ChannelList[i].Channel, pAd->ChannelList[i].Power, pAd->ChannelList[i].Power2)); 237 - } 238 - #endif 239 - } 240 - 241 - /* 242 - ========================================================================== 243 - Description: 244 - This routine return the first channel number according to the country 245 - code selection and RF IC selection (signal band or dual band). It is called 246 - whenever driver need to start a site survey of all supported channels. 247 - Return: 248 - ch - the first channel number of current country code setting 249 - 250 - IRQL = PASSIVE_LEVEL 251 - 252 - ========================================================================== 253 - */ 254 - UCHAR FirstChannel( 255 - IN PRTMP_ADAPTER pAd) 256 - { 257 - return pAd->ChannelList[0].Channel; 258 - } 259 - 260 - /* 261 - ========================================================================== 262 - Description: 263 - This routine returns the next channel number. This routine is called 264 - during driver need to start a site survey of all supported channels. 265 - Return: 266 - next_channel - the next channel number valid in current country code setting. 267 - Note: 268 - return 0 if no more next channel 269 - ========================================================================== 270 - */ 271 - UCHAR NextChannel( 272 - IN PRTMP_ADAPTER pAd, 273 - IN UCHAR channel) 274 - { 275 - int i; 276 - UCHAR next_channel = 0; 277 - 278 - for (i = 0; i < (pAd->ChannelListNum - 1); i++) 279 - if (channel == pAd->ChannelList[i].Channel) 280 - { 281 - next_channel = pAd->ChannelList[i+1].Channel; 282 - break; 283 - } 284 - return next_channel; 285 - } 286 - 287 - /* 288 - ========================================================================== 289 - Description: 290 - This routine is for Cisco Compatible Extensions 2.X 291 - Spec31. AP Control of Client Transmit Power 292 - Return: 293 - None 294 - Note: 295 - Required by Aironet dBm(mW) 296 - 0dBm(1mW), 1dBm(5mW), 13dBm(20mW), 15dBm(30mW), 297 - 17dBm(50mw), 20dBm(100mW) 298 - 299 - We supported 300 - 3dBm(Lowest), 6dBm(10%), 9dBm(25%), 12dBm(50%), 301 - 14dBm(75%), 15dBm(100%) 302 - 303 - The client station's actual transmit power shall be within +/- 5dB of 304 - the minimum value or next lower value. 305 - ========================================================================== 306 - */ 307 - VOID ChangeToCellPowerLimit( 308 - IN PRTMP_ADAPTER pAd, 309 - IN UCHAR AironetCellPowerLimit) 310 - { 311 - //valud 0xFF means that hasn't found power limit information 312 - //from the AP's Beacon/Probe response. 313 - if (AironetCellPowerLimit == 0xFF) 314 - return; 315 - 316 - if (AironetCellPowerLimit < 6) //Used Lowest Power Percentage. 317 - pAd->CommonCfg.TxPowerPercentage = 6; 318 - else if (AironetCellPowerLimit < 9) 319 - pAd->CommonCfg.TxPowerPercentage = 10; 320 - else if (AironetCellPowerLimit < 12) 321 - pAd->CommonCfg.TxPowerPercentage = 25; 322 - else if (AironetCellPowerLimit < 14) 323 - pAd->CommonCfg.TxPowerPercentage = 50; 324 - else if (AironetCellPowerLimit < 15) 325 - pAd->CommonCfg.TxPowerPercentage = 75; 326 - else 327 - pAd->CommonCfg.TxPowerPercentage = 100; //else used maximum 328 - 329 - if (pAd->CommonCfg.TxPowerPercentage > pAd->CommonCfg.TxPowerDefault) 330 - pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault; 331 - 332 - } 333 - 334 - CHAR ConvertToRssi( 335 - IN PRTMP_ADAPTER pAd, 336 - IN CHAR Rssi, 337 - IN UCHAR RssiNumber) 338 - { 339 - UCHAR RssiOffset, LNAGain; 340 - 341 - // Rssi equals to zero should be an invalid value 342 - if (Rssi == 0) 343 - return -99; 344 - 345 - LNAGain = GET_LNA_GAIN(pAd); 346 - if (pAd->LatchRfRegs.Channel > 14) 347 - { 348 - if (RssiNumber == 0) 349 - RssiOffset = pAd->ARssiOffset0; 350 - else if (RssiNumber == 1) 351 - RssiOffset = pAd->ARssiOffset1; 352 - else 353 - RssiOffset = pAd->ARssiOffset2; 354 - } 355 - else 356 - { 357 - if (RssiNumber == 0) 358 - RssiOffset = pAd->BGRssiOffset0; 359 - else if (RssiNumber == 1) 360 - RssiOffset = pAd->BGRssiOffset1; 361 - else 362 - RssiOffset = pAd->BGRssiOffset2; 363 - } 364 - 365 - return (-12 - RssiOffset - LNAGain - Rssi); 366 - } 367 - 368 - /* 369 - ========================================================================== 370 - Description: 371 - Scan next channel 372 - ========================================================================== 373 - */ 374 - VOID ScanNextChannel( 375 - IN PRTMP_ADAPTER pAd) 376 - { 377 - HEADER_802_11 Hdr80211; 378 - PUCHAR pOutBuffer = NULL; 379 - NDIS_STATUS NStatus; 380 - ULONG FrameLen = 0; 381 - UCHAR SsidLen = 0, ScanType = pAd->MlmeAux.ScanType, BBPValue = 0; 382 - USHORT Status; 383 - PHEADER_802_11 pHdr80211; 384 - UINT ScanTimeIn5gChannel = SHORT_CHANNEL_TIME; 385 - 386 - if (MONITOR_ON(pAd)) 387 - return; 388 - 389 - if (pAd->MlmeAux.Channel == 0) 390 - { 391 - if ((pAd->CommonCfg.BBPCurrentBW == BW_40) 392 - && (INFRA_ON(pAd) 393 - || (pAd->OpMode == OPMODE_AP)) 394 - ) 395 - { 396 - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); 397 - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); 398 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); 399 - BBPValue &= (~0x18); 400 - BBPValue |= 0x10; 401 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); 402 - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr)); 403 - } 404 - else 405 - { 406 - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); 407 - AsicLockChannel(pAd, pAd->CommonCfg.Channel); 408 - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to channel %d, Total BSS[%02d]\n",pAd->CommonCfg.Channel, pAd->ScanTab.BssNr)); 409 - } 410 - 411 - { 412 - // 413 - // To prevent data lost. 414 - // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress. 415 - // Now, we need to send an NULL data with turned PSM bit off to AP, when scan progress done 416 - // 417 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd))) 418 - { 419 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); 420 - if (NStatus == NDIS_STATUS_SUCCESS) 421 - { 422 - pHdr80211 = (PHEADER_802_11) pOutBuffer; 423 - MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid); 424 - pHdr80211->Duration = 0; 425 - pHdr80211->FC.Type = BTYPE_DATA; 426 - pHdr80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE); 427 - 428 - // Send using priority queue 429 - MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11)); 430 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame\n")); 431 - MlmeFreeMemory(pAd, pOutBuffer); 432 - RTMPusecDelay(5000); 433 - } 434 - } 435 - 436 - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 437 - Status = MLME_SUCCESS; 438 - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status); 439 - } 440 - 441 - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); 442 - } 443 - #ifdef RT2870 444 - else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) && (pAd->OpMode == OPMODE_STA)) 445 - { 446 - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 447 - MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE); 448 - } 449 - #endif // RT2870 // 450 - else 451 - { 452 - { 453 - // BBP and RF are not accessible in PS mode, we has to wake them up first 454 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) 455 - AsicForceWakeup(pAd, TRUE); 456 - 457 - // leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON 458 - if (pAd->StaCfg.Psm == PWR_SAVE) 459 - MlmeSetPsmBit(pAd, PWR_ACTIVE); 460 - } 461 - 462 - AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, TRUE); 463 - AsicLockChannel(pAd, pAd->MlmeAux.Channel); 464 - 465 - { 466 - if (pAd->MlmeAux.Channel > 14) 467 - { 468 - if ((pAd->CommonCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->MlmeAux.Channel)) 469 - { 470 - ScanType = SCAN_PASSIVE; 471 - ScanTimeIn5gChannel = MIN_CHANNEL_TIME; 472 - } 473 - } 474 - } 475 - 476 - //Global country domain(ch1-11:active scan, ch12-14 passive scan) 477 - if ((pAd->MlmeAux.Channel <= 14) && (pAd->MlmeAux.Channel >= 12) && ((pAd->CommonCfg.CountryRegion & 0x7f) == REGION_31_BG_BAND)) 478 - { 479 - ScanType = SCAN_PASSIVE; 480 - } 481 - 482 - // We need to shorten active scan time in order for WZC connect issue 483 - // Chnage the channel scan time for CISCO stuff based on its IAPP announcement 484 - if (ScanType == FAST_SCAN_ACTIVE) 485 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, FAST_ACTIVE_SCAN_TIME); 486 - else if (((ScanType == SCAN_CISCO_ACTIVE) || 487 - (ScanType == SCAN_CISCO_PASSIVE) || 488 - (ScanType == SCAN_CISCO_CHANNEL_LOAD) || 489 - (ScanType == SCAN_CISCO_NOISE)) && (pAd->OpMode == OPMODE_STA)) 490 - { 491 - if (pAd->StaCfg.CCXScanTime < 25) 492 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime * 2); 493 - else 494 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, pAd->StaCfg.CCXScanTime); 495 - } 496 - else // must be SCAN_PASSIVE or SCAN_ACTIVE 497 - { 498 - if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) 499 - || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) 500 - ) 501 - { 502 - if (pAd->MlmeAux.Channel > 14) 503 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, ScanTimeIn5gChannel); 504 - else 505 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MIN_CHANNEL_TIME); 506 - } 507 - else 508 - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, MAX_CHANNEL_TIME); 509 - } 510 - 511 - if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE) || 512 - (ScanType == SCAN_CISCO_ACTIVE)) 513 - { 514 - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory 515 - if (NStatus != NDIS_STATUS_SUCCESS) 516 - { 517 - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - ScanNextChannel() allocate memory fail\n")); 518 - 519 - { 520 - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 521 - Status = MLME_FAIL_NO_RESOURCE; 522 - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status); 523 - } 524 - 525 - return; 526 - } 527 - 528 - // There is no need to send broadcast probe request if active scan is in effect. 529 - if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE) 530 - ) 531 - SsidLen = pAd->MlmeAux.SsidLen; 532 - else 533 - SsidLen = 0; 534 - 535 - MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR); 536 - MakeOutgoingFrame(pOutBuffer, &FrameLen, 537 - sizeof(HEADER_802_11), &Hdr80211, 538 - 1, &SsidIe, 539 - 1, &SsidLen, 540 - SsidLen, pAd->MlmeAux.Ssid, 541 - 1, &SupRateIe, 542 - 1, &pAd->CommonCfg.SupRateLen, 543 - pAd->CommonCfg.SupRateLen, pAd->CommonCfg.SupRate, 544 - END_OF_ARGS); 545 - 546 - if (pAd->CommonCfg.ExtRateLen) 547 - { 548 - ULONG Tmp; 549 - MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp, 550 - 1, &ExtRateIe, 551 - 1, &pAd->CommonCfg.ExtRateLen, 552 - pAd->CommonCfg.ExtRateLen, pAd->CommonCfg.ExtRate, 553 - END_OF_ARGS); 554 - FrameLen += Tmp; 555 - } 556 - 557 - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) 558 - { 559 - ULONG Tmp; 560 - UCHAR HtLen; 561 - UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33}; 562 - 563 - if (pAd->bBroadComHT == TRUE) 564 - { 565 - HtLen = pAd->MlmeAux.HtCapabilityLen + 4; 566 - 567 - MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp, 568 - 1, &WpaIe, 569 - 1, &HtLen, 570 - 4, &BROADCOM[0], 571 - pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability, 572 - END_OF_ARGS); 573 - } 574 - else 575 - { 576 - HtLen = pAd->MlmeAux.HtCapabilityLen; 577 - 578 - MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp, 579 - 1, &HtCapIe, 580 - 1, &HtLen, 581 - HtLen, &pAd->CommonCfg.HtCapability, 582 - END_OF_ARGS); 583 - } 584 - FrameLen += Tmp; 585 - } 586 - 587 - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); 588 - MlmeFreeMemory(pAd, pOutBuffer); 589 - } 590 - 591 - // For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe reponse 592 - 593 - pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN; 594 - } 595 - } 596 - 597 - VOID MgtProbReqMacHeaderInit( 598 - IN PRTMP_ADAPTER pAd, 599 - IN OUT PHEADER_802_11 pHdr80211, 600 - IN UCHAR SubType, 601 - IN UCHAR ToDs, 602 - IN PUCHAR pDA, 603 - IN PUCHAR pBssid) 604 - { 605 - NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11)); 606 - 607 - pHdr80211->FC.Type = BTYPE_MGMT; 608 - pHdr80211->FC.SubType = SubType; 609 - if (SubType == SUBTYPE_ACK) 610 - pHdr80211->FC.Type = BTYPE_CNTL; 611 - pHdr80211->FC.ToDs = ToDs; 612 - COPY_MAC_ADDR(pHdr80211->Addr1, pDA); 613 - COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); 614 - COPY_MAC_ADDR(pHdr80211->Addr3, pBssid); 615 - } 616 - 617 - 1 + #include "../../rt2860/common/cmm_sync.c"
+1 -1638
drivers/staging/rt2870/common/cmm_wpa.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - wpa.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Jan Lee 03-07-22 Initial 36 - Paul Lin 03-11-28 Modify for supplicant 37 - */ 38 - #include "../rt_config.h" 39 - // WPA OUI 40 - UCHAR OUI_WPA_NONE_AKM[4] = {0x00, 0x50, 0xF2, 0x00}; 41 - UCHAR OUI_WPA_VERSION[4] = {0x00, 0x50, 0xF2, 0x01}; 42 - #ifndef RT30xx 43 - UCHAR OUI_WPA_WEP40[4] = {0x00, 0x50, 0xF2, 0x01}; 44 - #endif 45 - UCHAR OUI_WPA_TKIP[4] = {0x00, 0x50, 0xF2, 0x02}; 46 - UCHAR OUI_WPA_CCMP[4] = {0x00, 0x50, 0xF2, 0x04}; 47 - #ifndef RT30xx 48 - UCHAR OUI_WPA_WEP104[4] = {0x00, 0x50, 0xF2, 0x05}; 49 - #endif 50 - UCHAR OUI_WPA_8021X_AKM[4] = {0x00, 0x50, 0xF2, 0x01}; 51 - UCHAR OUI_WPA_PSK_AKM[4] = {0x00, 0x50, 0xF2, 0x02}; 52 - // WPA2 OUI 53 - UCHAR OUI_WPA2_WEP40[4] = {0x00, 0x0F, 0xAC, 0x01}; 54 - UCHAR OUI_WPA2_TKIP[4] = {0x00, 0x0F, 0xAC, 0x02}; 55 - UCHAR OUI_WPA2_CCMP[4] = {0x00, 0x0F, 0xAC, 0x04}; 56 - UCHAR OUI_WPA2_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x01}; 57 - UCHAR OUI_WPA2_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x02}; 58 - #ifndef RT30xx 59 - UCHAR OUI_WPA2_WEP104[4] = {0x00, 0x0F, 0xAC, 0x05}; 60 - #endif 61 - // MSA OUI 62 - UCHAR OUI_MSA_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x05}; // Not yet final - IEEE 802.11s-D1.06 63 - UCHAR OUI_MSA_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x06}; // Not yet final - IEEE 802.11s-D1.06 64 - 65 - /* 66 - ======================================================================== 67 - 68 - Routine Description: 69 - The pseudo-random function(PRF) that hashes various inputs to 70 - derive a pseudo-random value. To add liveness to the pseudo-random 71 - value, a nonce should be one of the inputs. 72 - 73 - It is used to generate PTK, GTK or some specific random value. 74 - 75 - Arguments: 76 - UCHAR *key, - the key material for HMAC_SHA1 use 77 - INT key_len - the length of key 78 - UCHAR *prefix - a prefix label 79 - INT prefix_len - the length of the label 80 - UCHAR *data - a specific data with variable length 81 - INT data_len - the length of a specific data 82 - INT len - the output lenght 83 - 84 - Return Value: 85 - UCHAR *output - the calculated result 86 - 87 - Note: 88 - 802.11i-2004 Annex H.3 89 - 90 - ======================================================================== 91 - */ 92 - VOID PRF( 93 - IN UCHAR *key, 94 - IN INT key_len, 95 - IN UCHAR *prefix, 96 - IN INT prefix_len, 97 - IN UCHAR *data, 98 - IN INT data_len, 99 - OUT UCHAR *output, 100 - IN INT len) 101 - { 102 - INT i; 103 - UCHAR *input; 104 - INT currentindex = 0; 105 - INT total_len; 106 - 107 - // Allocate memory for input 108 - os_alloc_mem(NULL, (PUCHAR *)&input, 1024); 109 - 110 - if (input == NULL) 111 - { 112 - DBGPRINT(RT_DEBUG_ERROR, ("!!!PRF: no memory!!!\n")); 113 - return; 114 - } 115 - 116 - // Generate concatenation input 117 - NdisMoveMemory(input, prefix, prefix_len); 118 - 119 - // Concatenate a single octet containing 0 120 - input[prefix_len] = 0; 121 - 122 - // Concatenate specific data 123 - NdisMoveMemory(&input[prefix_len + 1], data, data_len); 124 - total_len = prefix_len + 1 + data_len; 125 - 126 - // Concatenate a single octet containing 0 127 - // This octet shall be update later 128 - input[total_len] = 0; 129 - total_len++; 130 - 131 - // Iterate to calculate the result by hmac-sha-1 132 - // Then concatenate to last result 133 - for (i = 0; i < (len + 19) / 20; i++) 134 - { 135 - HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]); 136 - currentindex += 20; 137 - 138 - // update the last octet 139 - input[total_len - 1]++; 140 - } 141 - os_free_mem(NULL, input); 142 - } 143 - 144 - /* 145 - ======================================================================== 146 - 147 - Routine Description: 148 - It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK. 149 - It shall be called by 4-way handshake processing. 150 - 151 - Arguments: 152 - pAd - pointer to our pAdapter context 153 - PMK - pointer to PMK 154 - ANonce - pointer to ANonce 155 - AA - pointer to Authenticator Address 156 - SNonce - pointer to SNonce 157 - SA - pointer to Supplicant Address 158 - len - indicate the length of PTK (octet) 159 - 160 - Return Value: 161 - Output pointer to the PTK 162 - 163 - Note: 164 - Refer to IEEE 802.11i-2004 8.5.1.2 165 - 166 - ======================================================================== 167 - */ 168 - VOID WpaCountPTK( 169 - IN PRTMP_ADAPTER pAd, 170 - IN UCHAR *PMK, 171 - IN UCHAR *ANonce, 172 - IN UCHAR *AA, 173 - IN UCHAR *SNonce, 174 - IN UCHAR *SA, 175 - OUT UCHAR *output, 176 - IN UINT len) 177 - { 178 - UCHAR concatenation[76]; 179 - UINT CurrPos = 0; 180 - UCHAR temp[32]; 181 - UCHAR Prefix[] = {'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ', 182 - 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'}; 183 - 184 - // initiate the concatenation input 185 - NdisZeroMemory(temp, sizeof(temp)); 186 - NdisZeroMemory(concatenation, 76); 187 - 188 - // Get smaller address 189 - if (RTMPCompareMemory(SA, AA, 6) == 1) 190 - NdisMoveMemory(concatenation, AA, 6); 191 - else 192 - NdisMoveMemory(concatenation, SA, 6); 193 - CurrPos += 6; 194 - 195 - // Get larger address 196 - if (RTMPCompareMemory(SA, AA, 6) == 1) 197 - NdisMoveMemory(&concatenation[CurrPos], SA, 6); 198 - else 199 - NdisMoveMemory(&concatenation[CurrPos], AA, 6); 200 - 201 - // store the larger mac address for backward compatible of 202 - // ralink proprietary STA-key issue 203 - NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN); 204 - CurrPos += 6; 205 - 206 - // Get smaller Nonce 207 - if (RTMPCompareMemory(ANonce, SNonce, 32) == 0) 208 - NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue 209 - else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1) 210 - NdisMoveMemory(&concatenation[CurrPos], SNonce, 32); 211 - else 212 - NdisMoveMemory(&concatenation[CurrPos], ANonce, 32); 213 - CurrPos += 32; 214 - 215 - // Get larger Nonce 216 - if (RTMPCompareMemory(ANonce, SNonce, 32) == 0) 217 - NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue 218 - else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1) 219 - NdisMoveMemory(&concatenation[CurrPos], ANonce, 32); 220 - else 221 - NdisMoveMemory(&concatenation[CurrPos], SNonce, 32); 222 - CurrPos += 32; 223 - 224 - hex_dump("concatenation=", concatenation, 76); 225 - 226 - // Use PRF to generate PTK 227 - PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len); 228 - 229 - } 230 - 231 - /* 232 - ======================================================================== 233 - 234 - Routine Description: 235 - Generate random number by software. 236 - 237 - Arguments: 238 - pAd - pointer to our pAdapter context 239 - macAddr - pointer to local MAC address 240 - 241 - Return Value: 242 - 243 - Note: 244 - 802.1ii-2004 Annex H.5 245 - 246 - ======================================================================== 247 - */ 248 - VOID GenRandom( 249 - IN PRTMP_ADAPTER pAd, 250 - IN UCHAR *macAddr, 251 - OUT UCHAR *random) 252 - { 253 - INT i, curr; 254 - UCHAR local[80], KeyCounter[32]; 255 - UCHAR result[80]; 256 - ULONG CurrentTime; 257 - UCHAR prefix[] = {'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r'}; 258 - 259 - // Zero the related information 260 - NdisZeroMemory(result, 80); 261 - NdisZeroMemory(local, 80); 262 - NdisZeroMemory(KeyCounter, 32); 263 - 264 - for (i = 0; i < 32; i++) 265 - { 266 - // copy the local MAC address 267 - COPY_MAC_ADDR(local, macAddr); 268 - curr = MAC_ADDR_LEN; 269 - 270 - // concatenate the current time 271 - NdisGetSystemUpTime(&CurrentTime); 272 - NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime)); 273 - curr += sizeof(CurrentTime); 274 - 275 - // concatenate the last result 276 - NdisMoveMemory(&local[curr], result, 32); 277 - curr += 32; 278 - 279 - // concatenate a variable 280 - NdisMoveMemory(&local[curr], &i, 2); 281 - curr += 2; 282 - 283 - // calculate the result 284 - PRF(KeyCounter, 32, prefix,12, local, curr, result, 32); 285 - } 286 - 287 - NdisMoveMemory(random, result, 32); 288 - } 289 - 290 - /* 291 - ======================================================================== 292 - 293 - Routine Description: 294 - Build cipher suite in RSN-IE. 295 - It only shall be called by RTMPMakeRSNIE. 296 - 297 - Arguments: 298 - pAd - pointer to our pAdapter context 299 - ElementID - indicate the WPA1 or WPA2 300 - WepStatus - indicate the encryption type 301 - bMixCipher - a boolean to indicate the pairwise cipher and group 302 - cipher are the same or not 303 - 304 - Return Value: 305 - 306 - Note: 307 - 308 - ======================================================================== 309 - */ 310 - static VOID RTMPInsertRsnIeCipher( 311 - IN PRTMP_ADAPTER pAd, 312 - IN UCHAR ElementID, 313 - IN UINT WepStatus, 314 - IN BOOLEAN bMixCipher, 315 - IN UCHAR FlexibleCipher, 316 - OUT PUCHAR pRsnIe, 317 - OUT UCHAR *rsn_len) 318 - { 319 - UCHAR PairwiseCnt; 320 - 321 - *rsn_len = 0; 322 - 323 - // decide WPA2 or WPA1 324 - if (ElementID == Wpa2Ie) 325 - { 326 - RSNIE2 *pRsnie_cipher = (RSNIE2*)pRsnIe; 327 - 328 - // Assign the verson as 1 329 - pRsnie_cipher->version = 1; 330 - 331 - switch (WepStatus) 332 - { 333 - // TKIP mode 334 - case Ndis802_11Encryption2Enabled: 335 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4); 336 - pRsnie_cipher->ucount = 1; 337 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4); 338 - *rsn_len = sizeof(RSNIE2); 339 - break; 340 - 341 - // AES mode 342 - case Ndis802_11Encryption3Enabled: 343 - if (bMixCipher) 344 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4); 345 - else 346 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_CCMP, 4); 347 - pRsnie_cipher->ucount = 1; 348 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4); 349 - *rsn_len = sizeof(RSNIE2); 350 - break; 351 - 352 - // TKIP-AES mix mode 353 - case Ndis802_11Encryption4Enabled: 354 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4); 355 - 356 - PairwiseCnt = 1; 357 - // Insert WPA2 TKIP as the first pairwise cipher 358 - if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher)) 359 - { 360 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4); 361 - // Insert WPA2 AES as the secondary pairwise cipher 362 - if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher)) 363 - { 364 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA2_CCMP, 4); 365 - PairwiseCnt = 2; 366 - } 367 - } 368 - else 369 - { 370 - // Insert WPA2 AES as the first pairwise cipher 371 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4); 372 - } 373 - 374 - pRsnie_cipher->ucount = PairwiseCnt; 375 - *rsn_len = sizeof(RSNIE2) + (4 * (PairwiseCnt - 1)); 376 - break; 377 - } 378 - 379 - #ifndef RT30xx 380 - if ((pAd->OpMode == OPMODE_STA) && 381 - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) && 382 - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) 383 - { 384 - UINT GroupCipher = pAd->StaCfg.GroupCipher; 385 - switch(GroupCipher) 386 - { 387 - case Ndis802_11GroupWEP40Enabled: 388 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP40, 4); 389 - break; 390 - case Ndis802_11GroupWEP104Enabled: 391 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP104, 4); 392 - break; 393 - } 394 - } 395 - #endif 396 - // swap for big-endian platform 397 - pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version); 398 - pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount); 399 - } 400 - else 401 - { 402 - RSNIE *pRsnie_cipher = (RSNIE*)pRsnIe; 403 - 404 - // Assign OUI and version 405 - NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4); 406 - pRsnie_cipher->version = 1; 407 - 408 - switch (WepStatus) 409 - { 410 - // TKIP mode 411 - case Ndis802_11Encryption2Enabled: 412 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4); 413 - pRsnie_cipher->ucount = 1; 414 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4); 415 - *rsn_len = sizeof(RSNIE); 416 - break; 417 - 418 - // AES mode 419 - case Ndis802_11Encryption3Enabled: 420 - if (bMixCipher) 421 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4); 422 - else 423 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_CCMP, 4); 424 - pRsnie_cipher->ucount = 1; 425 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4); 426 - *rsn_len = sizeof(RSNIE); 427 - break; 428 - 429 - // TKIP-AES mix mode 430 - case Ndis802_11Encryption4Enabled: 431 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4); 432 - 433 - PairwiseCnt = 1; 434 - // Insert WPA TKIP as the first pairwise cipher 435 - if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher)) 436 - { 437 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4); 438 - // Insert WPA AES as the secondary pairwise cipher 439 - if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher)) 440 - { 441 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA_CCMP, 4); 442 - PairwiseCnt = 2; 443 - } 444 - } 445 - else 446 - { 447 - // Insert WPA AES as the first pairwise cipher 448 - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4); 449 - } 450 - 451 - pRsnie_cipher->ucount = PairwiseCnt; 452 - *rsn_len = sizeof(RSNIE) + (4 * (PairwiseCnt - 1)); 453 - break; 454 - } 455 - 456 - #ifndef RT30xx 457 - if ((pAd->OpMode == OPMODE_STA) && 458 - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) && 459 - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) 460 - { 461 - UINT GroupCipher = pAd->StaCfg.GroupCipher; 462 - switch(GroupCipher) 463 - { 464 - case Ndis802_11GroupWEP40Enabled: 465 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP40, 4); 466 - break; 467 - case Ndis802_11GroupWEP104Enabled: 468 - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP104, 4); 469 - break; 470 - } 471 - } 472 - #endif 473 - // swap for big-endian platform 474 - pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version); 475 - pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount); 476 - } 477 - } 478 - 479 - /* 480 - ======================================================================== 481 - 482 - Routine Description: 483 - Build AKM suite in RSN-IE. 484 - It only shall be called by RTMPMakeRSNIE. 485 - 486 - Arguments: 487 - pAd - pointer to our pAdapter context 488 - ElementID - indicate the WPA1 or WPA2 489 - AuthMode - indicate the authentication mode 490 - apidx - indicate the interface index 491 - 492 - Return Value: 493 - 494 - Note: 495 - 496 - ======================================================================== 497 - */ 498 - static VOID RTMPInsertRsnIeAKM( 499 - IN PRTMP_ADAPTER pAd, 500 - IN UCHAR ElementID, 501 - IN UINT AuthMode, 502 - IN UCHAR apidx, 503 - OUT PUCHAR pRsnIe, 504 - OUT UCHAR *rsn_len) 505 - { 506 - RSNIE_AUTH *pRsnie_auth; 507 - 508 - pRsnie_auth = (RSNIE_AUTH*)(pRsnIe + (*rsn_len)); 509 - 510 - // decide WPA2 or WPA1 511 - if (ElementID == Wpa2Ie) 512 - { 513 - switch (AuthMode) 514 - { 515 - case Ndis802_11AuthModeWPA2: 516 - case Ndis802_11AuthModeWPA1WPA2: 517 - pRsnie_auth->acount = 1; 518 - NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_8021X_AKM, 4); 519 - break; 520 - 521 - case Ndis802_11AuthModeWPA2PSK: 522 - case Ndis802_11AuthModeWPA1PSKWPA2PSK: 523 - pRsnie_auth->acount = 1; 524 - NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_PSK_AKM, 4); 525 - break; 526 - } 527 - } 528 - else 529 - { 530 - switch (AuthMode) 531 - { 532 - case Ndis802_11AuthModeWPA: 533 - case Ndis802_11AuthModeWPA1WPA2: 534 - pRsnie_auth->acount = 1; 535 - NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_8021X_AKM, 4); 536 - break; 537 - 538 - case Ndis802_11AuthModeWPAPSK: 539 - case Ndis802_11AuthModeWPA1PSKWPA2PSK: 540 - pRsnie_auth->acount = 1; 541 - NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_PSK_AKM, 4); 542 - break; 543 - 544 - case Ndis802_11AuthModeWPANone: 545 - pRsnie_auth->acount = 1; 546 - NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_NONE_AKM, 4); 547 - break; 548 - } 549 - } 550 - 551 - pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount); 552 - 553 - (*rsn_len) += sizeof(RSNIE_AUTH); // update current RSNIE length 554 - 555 - } 556 - 557 - /* 558 - ======================================================================== 559 - 560 - Routine Description: 561 - Build capability in RSN-IE. 562 - It only shall be called by RTMPMakeRSNIE. 563 - 564 - Arguments: 565 - pAd - pointer to our pAdapter context 566 - ElementID - indicate the WPA1 or WPA2 567 - apidx - indicate the interface index 568 - 569 - Return Value: 570 - 571 - Note: 572 - 573 - ======================================================================== 574 - */ 575 - static VOID RTMPInsertRsnIeCap( 576 - IN PRTMP_ADAPTER pAd, 577 - IN UCHAR ElementID, 578 - IN UCHAR apidx, 579 - OUT PUCHAR pRsnIe, 580 - OUT UCHAR *rsn_len) 581 - { 582 - RSN_CAPABILITIES *pRSN_Cap; 583 - 584 - // it could be ignored in WPA1 mode 585 - if (ElementID == WpaIe) 586 - return; 587 - 588 - pRSN_Cap = (RSN_CAPABILITIES*)(pRsnIe + (*rsn_len)); 589 - 590 - 591 - pRSN_Cap->word = cpu2le16(pRSN_Cap->word); 592 - 593 - (*rsn_len) += sizeof(RSN_CAPABILITIES); // update current RSNIE length 594 - 595 - } 596 - 597 - 598 - /* 599 - ======================================================================== 600 - 601 - Routine Description: 602 - Build RSN IE context. It is not included element-ID and length. 603 - 604 - Arguments: 605 - pAd - pointer to our pAdapter context 606 - AuthMode - indicate the authentication mode 607 - WepStatus - indicate the encryption type 608 - apidx - indicate the interface index 609 - 610 - Return Value: 611 - 612 - Note: 613 - 614 - ======================================================================== 615 - */ 616 - VOID RTMPMakeRSNIE( 617 - IN PRTMP_ADAPTER pAd, 618 - IN UINT AuthMode, 619 - IN UINT WepStatus, 620 - IN UCHAR apidx) 621 - { 622 - PUCHAR pRsnIe = NULL; // primary RSNIE 623 - UCHAR *rsnielen_cur_p = 0; // the length of the primary RSNIE 624 - UCHAR *rsnielen_ex_cur_p = 0; // the length of the secondary RSNIE 625 - UCHAR PrimaryRsnie; 626 - BOOLEAN bMixCipher = FALSE; // indicate the pairwise and group cipher are different 627 - UCHAR p_offset; 628 - WPA_MIX_PAIR_CIPHER FlexibleCipher = MIX_CIPHER_NOTUSE; // it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode 629 - 630 - rsnielen_cur_p = NULL; 631 - rsnielen_ex_cur_p = NULL; 632 - 633 - { 634 - { 635 - if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) 636 - { 637 - if (AuthMode < Ndis802_11AuthModeWPA) 638 - return; 639 - } 640 - else 641 - { 642 - // Support WPAPSK or WPA2PSK in STA-Infra mode 643 - // Support WPANone in STA-Adhoc mode 644 - if ((AuthMode != Ndis802_11AuthModeWPAPSK) && 645 - (AuthMode != Ndis802_11AuthModeWPA2PSK) && 646 - (AuthMode != Ndis802_11AuthModeWPANone) 647 - ) 648 - return; 649 - } 650 - 651 - DBGPRINT(RT_DEBUG_TRACE,("==> RTMPMakeRSNIE(STA)\n")); 652 - 653 - // Zero RSNIE context 654 - pAd->StaCfg.RSNIE_Len = 0; 655 - NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE); 656 - 657 - // Pointer to RSNIE 658 - rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len; 659 - pRsnIe = pAd->StaCfg.RSN_IE; 660 - 661 - bMixCipher = pAd->StaCfg.bMixCipher; 662 - } 663 - } 664 - 665 - // indicate primary RSNIE as WPA or WPA2 666 - if ((AuthMode == Ndis802_11AuthModeWPA) || 667 - (AuthMode == Ndis802_11AuthModeWPAPSK) || 668 - (AuthMode == Ndis802_11AuthModeWPANone) || 669 - (AuthMode == Ndis802_11AuthModeWPA1WPA2) || 670 - (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK)) 671 - PrimaryRsnie = WpaIe; 672 - else 673 - PrimaryRsnie = Wpa2Ie; 674 - 675 - { 676 - // Build the primary RSNIE 677 - // 1. insert cipher suite 678 - RTMPInsertRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, FlexibleCipher, pRsnIe, &p_offset); 679 - 680 - // 2. insert AKM 681 - RTMPInsertRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, &p_offset); 682 - 683 - // 3. insert capability 684 - RTMPInsertRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset); 685 - } 686 - 687 - // 4. update the RSNIE length 688 - *rsnielen_cur_p = p_offset; 689 - 690 - hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p)); 691 - 692 - 693 - } 694 - 695 - /* 696 - ========================================================================== 697 - Description: 698 - Check whether the received frame is EAP frame. 699 - 700 - Arguments: 701 - pAd - pointer to our pAdapter context 702 - pEntry - pointer to active entry 703 - pData - the received frame 704 - DataByteCount - the received frame's length 705 - FromWhichBSSID - indicate the interface index 706 - 707 - Return: 708 - TRUE - This frame is EAP frame 709 - FALSE - otherwise 710 - ========================================================================== 711 - */ 712 - BOOLEAN RTMPCheckWPAframe( 713 - IN PRTMP_ADAPTER pAd, 714 - IN PMAC_TABLE_ENTRY pEntry, 715 - IN PUCHAR pData, 716 - IN ULONG DataByteCount, 717 - IN UCHAR FromWhichBSSID) 718 - { 719 - ULONG Body_len; 720 - BOOLEAN Cancelled; 721 - 722 - 723 - if(DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H)) 724 - return FALSE; 725 - 726 - 727 - // Skip LLC header 728 - if (NdisEqualMemory(SNAP_802_1H, pData, 6) || 729 - // Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL 730 - NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6)) 731 - { 732 - pData += 6; 733 - } 734 - // Skip 2-bytes EAPoL type 735 - if (NdisEqualMemory(EAPOL, pData, 2)) 736 - { 737 - pData += 2; 738 - } 739 - else 740 - return FALSE; 741 - 742 - switch (*(pData+1)) 743 - { 744 - case EAPPacket: 745 - Body_len = (*(pData+2)<<8) | (*(pData+3)); 746 - DBGPRINT(RT_DEBUG_TRACE, ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", Body_len)); 747 - break; 748 - case EAPOLStart: 749 - DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Start frame, TYPE = 1 \n")); 750 - if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE) 751 - { 752 - DBGPRINT(RT_DEBUG_TRACE, ("Cancel the EnqueueEapolStartTimerRunning \n")); 753 - RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled); 754 - pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE; 755 - } 756 - break; 757 - case EAPOLLogoff: 758 - DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLLogoff frame, TYPE = 2 \n")); 759 - break; 760 - case EAPOLKey: 761 - Body_len = (*(pData+2)<<8) | (*(pData+3)); 762 - DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", Body_len)); 763 - break; 764 - case EAPOLASFAlert: 765 - DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLASFAlert frame, TYPE = 4 \n")); 766 - break; 767 - default: 768 - return FALSE; 769 - 770 - } 771 - return TRUE; 772 - } 773 - 774 - 775 - /* 776 - ========================================================================== 777 - Description: 778 - ENCRYPT AES GTK before sending in EAPOL frame. 779 - AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function. 780 - This function references to RFC 3394 for aes key wrap algorithm. 781 - Return: 782 - ========================================================================== 783 - */ 784 - VOID AES_GTK_KEY_WRAP( 785 - IN UCHAR *key, 786 - IN UCHAR *plaintext, 787 - IN UCHAR p_len, 788 - OUT UCHAR *ciphertext) 789 - { 790 - UCHAR A[8], BIN[16], BOUT[16]; 791 - UCHAR R[512]; 792 - INT num_blocks = p_len/8; // unit:64bits 793 - INT i, j; 794 - aes_context aesctx; 795 - UCHAR xor; 796 - 797 - rtmp_aes_set_key(&aesctx, key, 128); 798 - 799 - // Init IA 800 - for (i = 0; i < 8; i++) 801 - A[i] = 0xa6; 802 - 803 - //Input plaintext 804 - for (i = 0; i < num_blocks; i++) 805 - { 806 - for (j = 0 ; j < 8; j++) 807 - R[8 * (i + 1) + j] = plaintext[8 * i + j]; 808 - } 809 - 810 - // Key Mix 811 - for (j = 0; j < 6; j++) 812 - { 813 - for(i = 1; i <= num_blocks; i++) 814 - { 815 - //phase 1 816 - NdisMoveMemory(BIN, A, 8); 817 - NdisMoveMemory(&BIN[8], &R[8 * i], 8); 818 - rtmp_aes_encrypt(&aesctx, BIN, BOUT); 819 - 820 - NdisMoveMemory(A, &BOUT[0], 8); 821 - xor = num_blocks * j + i; 822 - A[7] = BOUT[7] ^ xor; 823 - NdisMoveMemory(&R[8 * i], &BOUT[8], 8); 824 - } 825 - } 826 - 827 - // Output ciphertext 828 - NdisMoveMemory(ciphertext, A, 8); 829 - 830 - for (i = 1; i <= num_blocks; i++) 831 - { 832 - for (j = 0 ; j < 8; j++) 833 - ciphertext[8 * i + j] = R[8 * i + j]; 834 - } 835 - } 836 - 837 - 838 - /* 839 - ======================================================================== 840 - 841 - Routine Description: 842 - Misc function to decrypt AES body 843 - 844 - Arguments: 845 - 846 - Return Value: 847 - 848 - Note: 849 - This function references to RFC 3394 for aes key unwrap algorithm. 850 - 851 - ======================================================================== 852 - */ 853 - VOID AES_GTK_KEY_UNWRAP( 854 - IN UCHAR *key, 855 - OUT UCHAR *plaintext, 856 - IN UCHAR c_len, 857 - IN UCHAR *ciphertext) 858 - 859 - { 860 - UCHAR A[8], BIN[16], BOUT[16]; 861 - UCHAR xor; 862 - INT i, j; 863 - aes_context aesctx; 864 - UCHAR *R; 865 - INT num_blocks = c_len/8; // unit:64bits 866 - 867 - 868 - os_alloc_mem(NULL, (PUCHAR *)&R, 512); 869 - 870 - if (R == NULL) 871 - { 872 - DBGPRINT(RT_DEBUG_ERROR, ("!!!AES_GTK_KEY_UNWRAP: no memory!!!\n")); 873 - return; 874 - } /* End of if */ 875 - 876 - // Initialize 877 - NdisMoveMemory(A, ciphertext, 8); 878 - //Input plaintext 879 - for(i = 0; i < (c_len-8); i++) 880 - { 881 - R[ i] = ciphertext[i + 8]; 882 - } 883 - 884 - rtmp_aes_set_key(&aesctx, key, 128); 885 - 886 - for(j = 5; j >= 0; j--) 887 - { 888 - for(i = (num_blocks-1); i > 0; i--) 889 - { 890 - xor = (num_blocks -1 )* j + i; 891 - NdisMoveMemory(BIN, A, 8); 892 - BIN[7] = A[7] ^ xor; 893 - NdisMoveMemory(&BIN[8], &R[(i-1)*8], 8); 894 - rtmp_aes_decrypt(&aesctx, BIN, BOUT); 895 - NdisMoveMemory(A, &BOUT[0], 8); 896 - NdisMoveMemory(&R[(i-1)*8], &BOUT[8], 8); 897 - } 898 - } 899 - 900 - // OUTPUT 901 - for(i = 0; i < c_len; i++) 902 - { 903 - plaintext[i] = R[i]; 904 - } 905 - 906 - 907 - os_free_mem(NULL, R); 908 - } 909 - 910 - /* 911 - ========================================================================== 912 - Description: 913 - Report the EAP message type 914 - 915 - Arguments: 916 - msg - EAPOL_PAIR_MSG_1 917 - EAPOL_PAIR_MSG_2 918 - EAPOL_PAIR_MSG_3 919 - EAPOL_PAIR_MSG_4 920 - EAPOL_GROUP_MSG_1 921 - EAPOL_GROUP_MSG_2 922 - 923 - Return: 924 - message type string 925 - 926 - ========================================================================== 927 - */ 928 - CHAR *GetEapolMsgType(CHAR msg) 929 - { 930 - if(msg == EAPOL_PAIR_MSG_1) 931 - return "Pairwise Message 1"; 932 - else if(msg == EAPOL_PAIR_MSG_2) 933 - return "Pairwise Message 2"; 934 - else if(msg == EAPOL_PAIR_MSG_3) 935 - return "Pairwise Message 3"; 936 - else if(msg == EAPOL_PAIR_MSG_4) 937 - return "Pairwise Message 4"; 938 - else if(msg == EAPOL_GROUP_MSG_1) 939 - return "Group Message 1"; 940 - else if(msg == EAPOL_GROUP_MSG_2) 941 - return "Group Message 2"; 942 - else 943 - return "Invalid Message"; 944 - } 945 - 946 - 947 - /* 948 - ======================================================================== 949 - 950 - Routine Description: 951 - Check Sanity RSN IE of EAPoL message 952 - 953 - Arguments: 954 - 955 - Return Value: 956 - 957 - 958 - ======================================================================== 959 - */ 960 - BOOLEAN RTMPCheckRSNIE( 961 - IN PRTMP_ADAPTER pAd, 962 - IN PUCHAR pData, 963 - IN UCHAR DataLen, 964 - IN MAC_TABLE_ENTRY *pEntry, 965 - OUT UCHAR *Offset) 966 - { 967 - PUCHAR pVIE; 968 - UCHAR len; 969 - PEID_STRUCT pEid; 970 - BOOLEAN result = FALSE; 971 - 972 - pVIE = pData; 973 - len = DataLen; 974 - *Offset = 0; 975 - 976 - while (len > sizeof(RSNIE2)) 977 - { 978 - pEid = (PEID_STRUCT) pVIE; 979 - // WPA RSN IE 980 - if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))) 981 - { 982 - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) && 983 - (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) && 984 - (pEntry->RSNIE_Len == (pEid->Len + 2))) 985 - { 986 - result = TRUE; 987 - } 988 - 989 - *Offset += (pEid->Len + 2); 990 - } 991 - // WPA2 RSN IE 992 - else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))) 993 - { 994 - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) && 995 - (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) && 996 - (pEntry->RSNIE_Len == (pEid->Len + 2))/* ToDo-AlbertY for mesh*/) 997 - { 998 - result = TRUE; 999 - } 1000 - 1001 - *Offset += (pEid->Len + 2); 1002 - } 1003 - else 1004 - { 1005 - break; 1006 - } 1007 - 1008 - pVIE += (pEid->Len + 2); 1009 - len -= (pEid->Len + 2); 1010 - } 1011 - 1012 - 1013 - return result; 1014 - 1015 - } 1016 - 1017 - 1018 - /* 1019 - ======================================================================== 1020 - 1021 - Routine Description: 1022 - Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK. 1023 - GTK is encaptulated in KDE format at p.83 802.11i D10 1024 - 1025 - Arguments: 1026 - 1027 - Return Value: 1028 - 1029 - Note: 1030 - 802.11i D10 1031 - 1032 - ======================================================================== 1033 - */ 1034 - BOOLEAN RTMPParseEapolKeyData( 1035 - IN PRTMP_ADAPTER pAd, 1036 - IN PUCHAR pKeyData, 1037 - IN UCHAR KeyDataLen, 1038 - IN UCHAR GroupKeyIndex, 1039 - IN UCHAR MsgType, 1040 - IN BOOLEAN bWPA2, 1041 - IN MAC_TABLE_ENTRY *pEntry) 1042 - { 1043 - PKDE_ENCAP pKDE = NULL; 1044 - PUCHAR pMyKeyData = pKeyData; 1045 - UCHAR KeyDataLength = KeyDataLen; 1046 - UCHAR GTKLEN = 0; 1047 - UCHAR DefaultIdx = 0; 1048 - UCHAR skip_offset; 1049 - 1050 - // Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it 1051 - if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3) 1052 - { 1053 - // Check RSN IE whether it is WPA2/WPA2PSK 1054 - if (!RTMPCheckRSNIE(pAd, pKeyData, KeyDataLen, pEntry, &skip_offset)) 1055 - { 1056 - // send wireless event - for RSN IE different 1057 - if (pAd->CommonCfg.bWirelessEvent) 1058 - RTMPSendWirelessEvent(pAd, IW_RSNIE_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0); 1059 - 1060 - DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in msg %d of 4-way handshake!\n", MsgType)); 1061 - hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen); 1062 - hex_dump("Desired RSN_IE ", pEntry->RSN_IE, pEntry->RSNIE_Len); 1063 - 1064 - return FALSE; 1065 - } 1066 - else 1067 - { 1068 - if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3) 1069 - { 1070 - // skip RSN IE 1071 - pMyKeyData += skip_offset; 1072 - KeyDataLength -= skip_offset; 1073 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset)); 1074 - } 1075 - else 1076 - return TRUE; 1077 - } 1078 - } 1079 - 1080 - DBGPRINT(RT_DEBUG_TRACE,("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength)); 1081 - 1082 - // Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2 1083 - if (bWPA2 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1)) 1084 - { 1085 - if (KeyDataLength >= 8) // KDE format exclude GTK length 1086 - { 1087 - pKDE = (PKDE_ENCAP) pMyKeyData; 1088 - 1089 - 1090 - DefaultIdx = pKDE->GTKEncap.Kid; 1091 - 1092 - // Sanity check - KED length 1093 - if (KeyDataLength < (pKDE->Len + 2)) 1094 - { 1095 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n")); 1096 - return FALSE; 1097 - } 1098 - 1099 - // Get GTK length - refer to IEEE 802.11i-2004 p.82 1100 - GTKLEN = pKDE->Len -6; 1101 - if (GTKLEN < LEN_AES_KEY) 1102 - { 1103 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN)); 1104 - return FALSE; 1105 - } 1106 - 1107 - } 1108 - else 1109 - { 1110 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KDE format length is too short \n")); 1111 - return FALSE; 1112 - } 1113 - 1114 - DBGPRINT(RT_DEBUG_TRACE, ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", DefaultIdx, GTKLEN)); 1115 - // skip it 1116 - pMyKeyData += 8; 1117 - KeyDataLength -= 8; 1118 - 1119 - } 1120 - else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1) 1121 - { 1122 - DefaultIdx = GroupKeyIndex; 1123 - DBGPRINT(RT_DEBUG_TRACE, ("GTK DefaultKeyID=%d \n", DefaultIdx)); 1124 - } 1125 - 1126 - // Sanity check - shared key index must be 1 ~ 3 1127 - if (DefaultIdx < 1 || DefaultIdx > 3) 1128 - { 1129 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index(%d) is invalid in %s %s \n", DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType))); 1130 - return FALSE; 1131 - } 1132 - 1133 - return TRUE; 1134 - 1135 - } 1136 - 1137 - 1138 - /* 1139 - ======================================================================== 1140 - 1141 - Routine Description: 1142 - Construct EAPoL message for WPA handshaking 1143 - Its format is below, 1144 - 1145 - +--------------------+ 1146 - | Protocol Version | 1 octet 1147 - +--------------------+ 1148 - | Protocol Type | 1 octet 1149 - +--------------------+ 1150 - | Body Length | 2 octets 1151 - +--------------------+ 1152 - | Descriptor Type | 1 octet 1153 - +--------------------+ 1154 - | Key Information | 2 octets 1155 - +--------------------+ 1156 - | Key Length | 1 octet 1157 - +--------------------+ 1158 - | Key Repaly Counter | 8 octets 1159 - +--------------------+ 1160 - | Key Nonce | 32 octets 1161 - +--------------------+ 1162 - | Key IV | 16 octets 1163 - +--------------------+ 1164 - | Key RSC | 8 octets 1165 - +--------------------+ 1166 - | Key ID or Reserved | 8 octets 1167 - +--------------------+ 1168 - | Key MIC | 16 octets 1169 - +--------------------+ 1170 - | Key Data Length | 2 octets 1171 - +--------------------+ 1172 - | Key Data | n octets 1173 - +--------------------+ 1174 - 1175 - 1176 - Arguments: 1177 - pAd Pointer to our adapter 1178 - 1179 - Return Value: 1180 - None 1181 - 1182 - Note: 1183 - 1184 - ======================================================================== 1185 - */ 1186 - VOID ConstructEapolMsg( 1187 - IN PRTMP_ADAPTER pAd, 1188 - IN UCHAR AuthMode, 1189 - IN UCHAR WepStatus, 1190 - IN UCHAR GroupKeyWepStatus, 1191 - IN UCHAR MsgType, 1192 - IN UCHAR DefaultKeyIdx, 1193 - IN UCHAR *ReplayCounter, 1194 - IN UCHAR *KeyNonce, 1195 - IN UCHAR *TxRSC, 1196 - IN UCHAR *PTK, 1197 - IN UCHAR *GTK, 1198 - IN UCHAR *RSNIE, 1199 - IN UCHAR RSNIE_Len, 1200 - OUT PEAPOL_PACKET pMsg) 1201 - { 1202 - BOOLEAN bWPA2 = FALSE; 1203 - 1204 - // Choose WPA2 or not 1205 - if ((AuthMode == Ndis802_11AuthModeWPA2) || (AuthMode == Ndis802_11AuthModeWPA2PSK)) 1206 - bWPA2 = TRUE; 1207 - 1208 - // Init Packet and Fill header 1209 - pMsg->ProVer = EAPOL_VER; 1210 - pMsg->ProType = EAPOLKey; 1211 - 1212 - // Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field 1213 - pMsg->Body_Len[1] = LEN_EAPOL_KEY_MSG; 1214 - 1215 - // Fill in EAPoL descriptor 1216 - if (bWPA2) 1217 - pMsg->KeyDesc.Type = WPA2_KEY_DESC; 1218 - else 1219 - pMsg->KeyDesc.Type = WPA1_KEY_DESC; 1220 - 1221 - // Fill in Key information, refer to IEEE Std 802.11i-2004 page 78 1222 - // When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used. 1223 - pMsg->KeyDesc.KeyInfo.KeyDescVer = 1224 - (((WepStatus == Ndis802_11Encryption3Enabled) || (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP)); 1225 - 1226 - // Specify Key Type as Group(0) or Pairwise(1) 1227 - if (MsgType >= EAPOL_GROUP_MSG_1) 1228 - pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY; 1229 - else 1230 - pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY; 1231 - 1232 - // Specify Key Index, only group_msg1_WPA1 1233 - if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)) 1234 - pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx; 1235 - 1236 - if (MsgType == EAPOL_PAIR_MSG_3) 1237 - pMsg->KeyDesc.KeyInfo.Install = 1; 1238 - 1239 - if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)) 1240 - pMsg->KeyDesc.KeyInfo.KeyAck = 1; 1241 - 1242 - if (MsgType != EAPOL_PAIR_MSG_1) 1243 - pMsg->KeyDesc.KeyInfo.KeyMic = 1; 1244 - 1245 - if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))) 1246 - { 1247 - pMsg->KeyDesc.KeyInfo.Secure = 1; 1248 - } 1249 - 1250 - if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))) 1251 - { 1252 - pMsg->KeyDesc.KeyInfo.EKD_DL = 1; 1253 - } 1254 - 1255 - // key Information element has done. 1256 - *(USHORT *)(&pMsg->KeyDesc.KeyInfo) = cpu2le16(*(USHORT *)(&pMsg->KeyDesc.KeyInfo)); 1257 - 1258 - // Fill in Key Length 1259 - { 1260 - if (MsgType >= EAPOL_GROUP_MSG_1) 1261 - { 1262 - // the length of group key cipher 1263 - pMsg->KeyDesc.KeyLength[1] = ((GroupKeyWepStatus == Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : LEN_AES_KEY); 1264 - } 1265 - else 1266 - { 1267 - // the length of pairwise key cipher 1268 - pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY); 1269 - } 1270 - } 1271 - 1272 - // Fill in replay counter 1273 - NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, ReplayCounter, LEN_KEY_DESC_REPLAY); 1274 - 1275 - // Fill Key Nonce field 1276 - // ANonce : pairwise_msg1 & pairwise_msg3 1277 - // SNonce : pairwise_msg2 1278 - // GNonce : group_msg1_wpa1 1279 - if ((MsgType <= EAPOL_PAIR_MSG_3) || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)))) 1280 - NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, LEN_KEY_DESC_NONCE); 1281 - 1282 - // Fill key IV - WPA2 as 0, WPA1 as random 1283 - if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) 1284 - { 1285 - // Suggest IV be random number plus some number, 1286 - NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], LEN_KEY_DESC_IV); 1287 - pMsg->KeyDesc.KeyIv[15] += 2; 1288 - } 1289 - 1290 - // Fill Key RSC field 1291 - // It contains the RSC for the GTK being installed. 1292 - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1)) 1293 - { 1294 - NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6); 1295 - } 1296 - 1297 - // Clear Key MIC field for MIC calculation later 1298 - NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); 1299 - 1300 - ConstructEapolKeyData(pAd, 1301 - AuthMode, 1302 - WepStatus, 1303 - GroupKeyWepStatus, 1304 - MsgType, 1305 - DefaultKeyIdx, 1306 - bWPA2, 1307 - PTK, 1308 - GTK, 1309 - RSNIE, 1310 - RSNIE_Len, 1311 - pMsg); 1312 - 1313 - // Calculate MIC and fill in KeyMic Field except Pairwise Msg 1. 1314 - if (MsgType != EAPOL_PAIR_MSG_1) 1315 - { 1316 - CalculateMIC(pAd, WepStatus, PTK, pMsg); 1317 - } 1318 - 1319 - DBGPRINT(RT_DEBUG_TRACE, ("===> ConstructEapolMsg for %s %s\n", ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType))); 1320 - DBGPRINT(RT_DEBUG_TRACE, (" Body length = %d \n", pMsg->Body_Len[1])); 1321 - DBGPRINT(RT_DEBUG_TRACE, (" Key length = %d \n", pMsg->KeyDesc.KeyLength[1])); 1322 - 1323 - 1324 - } 1325 - 1326 - /* 1327 - ======================================================================== 1328 - 1329 - Routine Description: 1330 - Construct the Key Data field of EAPoL message 1331 - 1332 - Arguments: 1333 - pAd Pointer to our adapter 1334 - Elem Message body 1335 - 1336 - Return Value: 1337 - None 1338 - 1339 - Note: 1340 - 1341 - ======================================================================== 1342 - */ 1343 - VOID ConstructEapolKeyData( 1344 - IN PRTMP_ADAPTER pAd, 1345 - IN UCHAR AuthMode, 1346 - IN UCHAR WepStatus, 1347 - IN UCHAR GroupKeyWepStatus, 1348 - IN UCHAR MsgType, 1349 - IN UCHAR DefaultKeyIdx, 1350 - IN BOOLEAN bWPA2Capable, 1351 - IN UCHAR *PTK, 1352 - IN UCHAR *GTK, 1353 - IN UCHAR *RSNIE, 1354 - IN UCHAR RSNIE_LEN, 1355 - OUT PEAPOL_PACKET pMsg) 1356 - { 1357 - UCHAR *mpool, *Key_Data, *Rc4GTK; 1358 - UCHAR ekey[(LEN_KEY_DESC_IV+LEN_EAP_EK)]; 1359 - UCHAR data_offset; 1360 - 1361 - 1362 - if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) 1363 - return; 1364 - 1365 - // allocate memory pool 1366 - os_alloc_mem(pAd, (PUCHAR *)&mpool, 1500); 1367 - 1368 - if (mpool == NULL) 1369 - return; 1370 - 1371 - /* Rc4GTK Len = 512 */ 1372 - Rc4GTK = (UCHAR *) ROUND_UP(mpool, 4); 1373 - /* Key_Data Len = 512 */ 1374 - Key_Data = (UCHAR *) ROUND_UP(Rc4GTK + 512, 4); 1375 - 1376 - NdisZeroMemory(Key_Data, 512); 1377 - pMsg->KeyDesc.KeyDataLen[1] = 0; 1378 - data_offset = 0; 1379 - 1380 - // Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3 1381 - if (RSNIE_LEN && ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3))) 1382 - { 1383 - if (bWPA2Capable) 1384 - Key_Data[data_offset + 0] = IE_WPA2; 1385 - else 1386 - Key_Data[data_offset + 0] = IE_WPA; 1387 - 1388 - Key_Data[data_offset + 1] = RSNIE_LEN; 1389 - NdisMoveMemory(&Key_Data[data_offset + 2], RSNIE, RSNIE_LEN); 1390 - data_offset += (2 + RSNIE_LEN); 1391 - } 1392 - 1393 - // Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2 1394 - if (bWPA2Capable && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))) 1395 - { 1396 - // Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h 1397 - Key_Data[data_offset + 0] = 0xDD; 1398 - 1399 - if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) 1400 - { 1401 - Key_Data[data_offset + 1] = 0x16;// 4+2+16(OUI+DataType+DataField) 1402 - } 1403 - else 1404 - { 1405 - Key_Data[data_offset + 1] = 0x26;// 4+2+32(OUI+DataType+DataField) 1406 - } 1407 - 1408 - Key_Data[data_offset + 2] = 0x00; 1409 - Key_Data[data_offset + 3] = 0x0F; 1410 - Key_Data[data_offset + 4] = 0xAC; 1411 - Key_Data[data_offset + 5] = 0x01; 1412 - 1413 - // GTK KDE format - 802.11i-2004 Figure-43x 1414 - Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03); 1415 - Key_Data[data_offset + 7] = 0x00; // Reserved Byte 1416 - 1417 - data_offset += 8; 1418 - } 1419 - 1420 - 1421 - // Encapsulate GTK and encrypt the key-data field with KEK. 1422 - // Only for pairwise_msg3_WPA2 and group_msg1 1423 - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) || (MsgType == EAPOL_GROUP_MSG_1)) 1424 - { 1425 - // Fill in GTK 1426 - if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) 1427 - { 1428 - NdisMoveMemory(&Key_Data[data_offset], GTK, LEN_AES_KEY); 1429 - data_offset += LEN_AES_KEY; 1430 - } 1431 - else 1432 - { 1433 - NdisMoveMemory(&Key_Data[data_offset], GTK, TKIP_GTK_LENGTH); 1434 - data_offset += TKIP_GTK_LENGTH; 1435 - } 1436 - 1437 - // Still dont know why, but if not append will occur "GTK not include in MSG3" 1438 - // Patch for compatibility between zero config and funk 1439 - if (MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) 1440 - { 1441 - if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) 1442 - { 1443 - Key_Data[data_offset + 0] = 0xDD; 1444 - Key_Data[data_offset + 1] = 0; 1445 - data_offset += 2; 1446 - } 1447 - else 1448 - { 1449 - Key_Data[data_offset + 0] = 0xDD; 1450 - Key_Data[data_offset + 1] = 0; 1451 - Key_Data[data_offset + 2] = 0; 1452 - Key_Data[data_offset + 3] = 0; 1453 - Key_Data[data_offset + 4] = 0; 1454 - Key_Data[data_offset + 5] = 0; 1455 - data_offset += 6; 1456 - } 1457 - } 1458 - 1459 - // Encrypt the data material in key data field 1460 - if (WepStatus == Ndis802_11Encryption3Enabled) 1461 - { 1462 - AES_GTK_KEY_WRAP(&PTK[16], Key_Data, data_offset, Rc4GTK); 1463 - // AES wrap function will grow 8 bytes in length 1464 - data_offset += 8; 1465 - } 1466 - else 1467 - { 1468 - // PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV) 1469 - // put TxTsc in Key RSC field 1470 - pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32. 1471 - 1472 - // ekey is the contanetion of IV-field, and PTK[16]->PTK[31] 1473 - NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, LEN_KEY_DESC_IV); 1474 - NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &PTK[16], LEN_EAP_EK); 1475 - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); //INIT SBOX, KEYLEN+3(IV) 1476 - pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, data_offset); 1477 - WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, Key_Data, data_offset); 1478 - } 1479 - 1480 - NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset); 1481 - } 1482 - else 1483 - { 1484 - NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset); 1485 - } 1486 - 1487 - // set key data length field and total length 1488 - pMsg->KeyDesc.KeyDataLen[1] = data_offset; 1489 - pMsg->Body_Len[1] += data_offset; 1490 - 1491 - os_free_mem(pAd, mpool); 1492 - 1493 - } 1494 - 1495 - /* 1496 - ======================================================================== 1497 - 1498 - Routine Description: 1499 - Calcaulate MIC. It is used during 4-ways handsharking. 1500 - 1501 - Arguments: 1502 - pAd - pointer to our pAdapter context 1503 - PeerWepStatus - indicate the encryption type 1504 - 1505 - Return Value: 1506 - 1507 - Note: 1508 - 1509 - ======================================================================== 1510 - */ 1511 - VOID CalculateMIC( 1512 - IN PRTMP_ADAPTER pAd, 1513 - IN UCHAR PeerWepStatus, 1514 - IN UCHAR *PTK, 1515 - OUT PEAPOL_PACKET pMsg) 1516 - { 1517 - UCHAR *OutBuffer; 1518 - ULONG FrameLen = 0; 1519 - UCHAR mic[LEN_KEY_DESC_MIC]; 1520 - UCHAR digest[80]; 1521 - 1522 - // allocate memory for MIC calculation 1523 - os_alloc_mem(pAd, (PUCHAR *)&OutBuffer, 512); 1524 - 1525 - if (OutBuffer == NULL) 1526 - { 1527 - DBGPRINT(RT_DEBUG_ERROR, ("!!!CalculateMIC: no memory!!!\n")); 1528 - return; 1529 - } 1530 - 1531 - // make a frame for calculating MIC. 1532 - MakeOutgoingFrame(OutBuffer, &FrameLen, 1533 - pMsg->Body_Len[1] + 4, pMsg, 1534 - END_OF_ARGS); 1535 - 1536 - NdisZeroMemory(mic, sizeof(mic)); 1537 - 1538 - // Calculate MIC 1539 - if (PeerWepStatus == Ndis802_11Encryption3Enabled) 1540 - { 1541 - HMAC_SHA1(OutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest); 1542 - NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC); 1543 - } 1544 - else 1545 - { 1546 - hmac_md5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic); 1547 - } 1548 - 1549 - // store the calculated MIC 1550 - NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC); 1551 - 1552 - os_free_mem(pAd, OutBuffer); 1553 - } 1554 - 1555 - /* 1556 - ======================================================================== 1557 - 1558 - Routine Description: 1559 - Some received frames can't decrypt by Asic, so decrypt them by software. 1560 - 1561 - Arguments: 1562 - pAd - pointer to our pAdapter context 1563 - PeerWepStatus - indicate the encryption type 1564 - 1565 - Return Value: 1566 - NDIS_STATUS_SUCCESS - decryption successful 1567 - NDIS_STATUS_FAILURE - decryption failure 1568 - 1569 - ======================================================================== 1570 - */ 1571 - NDIS_STATUS RTMPSoftDecryptBroadCastData( 1572 - IN PRTMP_ADAPTER pAd, 1573 - IN RX_BLK *pRxBlk, 1574 - IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher, 1575 - IN PCIPHER_KEY pShard_key) 1576 - { 1577 - PRXWI_STRUC pRxWI = pRxBlk->pRxWI; 1578 - 1579 - 1580 - 1581 - // handle WEP decryption 1582 - if (GroupCipher == Ndis802_11Encryption1Enabled) 1583 - { 1584 - if (RTMPSoftDecryptWEP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, pShard_key)) 1585 - { 1586 - 1587 - //Minus IV[4] & ICV[4] 1588 - pRxWI->MPDUtotalByteCount -= 8; 1589 - } 1590 - else 1591 - { 1592 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR : Software decrypt WEP data fails.\n")); 1593 - // give up this frame 1594 - return NDIS_STATUS_FAILURE; 1595 - } 1596 - } 1597 - // handle TKIP decryption 1598 - else if (GroupCipher == Ndis802_11Encryption2Enabled) 1599 - { 1600 - if (RTMPSoftDecryptTKIP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, pShard_key)) 1601 - { 1602 - 1603 - //Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV 1604 - pRxWI->MPDUtotalByteCount -= 20; 1605 - } 1606 - else 1607 - { 1608 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptTKIP Failed\n")); 1609 - // give up this frame 1610 - return NDIS_STATUS_FAILURE; 1611 - } 1612 - } 1613 - // handle AES decryption 1614 - else if (GroupCipher == Ndis802_11Encryption3Enabled) 1615 - { 1616 - if (RTMPSoftDecryptAES(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount , pShard_key)) 1617 - { 1618 - 1619 - //8 bytes MIC, 8 bytes IV/EIV (CCMP Header) 1620 - pRxWI->MPDUtotalByteCount -= 16; 1621 - } 1622 - else 1623 - { 1624 - DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptAES Failed\n")); 1625 - // give up this frame 1626 - return NDIS_STATUS_FAILURE; 1627 - } 1628 - } 1629 - else 1630 - { 1631 - // give up this frame 1632 - return NDIS_STATUS_FAILURE; 1633 - } 1634 - 1635 - return NDIS_STATUS_SUCCESS; 1636 - 1637 - } 1638 - 1 + #include "../../rt2860/common/cmm_wpa.c"
+1 -432
drivers/staging/rt2870/common/dfs.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - ap_dfs.c 29 - 30 - Abstract: 31 - Support DFS function. 32 - 33 - Revision History: 34 - Who When What 35 - -------- ---------- ---------------------------------------------- 36 - Fonchi 03-12-2007 created 37 - */ 38 - 39 - #include "../rt_config.h" 40 - 41 - typedef struct _RADAR_DURATION_TABLE 42 - { 43 - ULONG RDDurRegion; 44 - ULONG RadarSignalDuration; 45 - ULONG Tolerance; 46 - } RADAR_DURATION_TABLE, *PRADAR_DURATION_TABLE; 47 - 48 - 49 - static UCHAR RdIdleTimeTable[MAX_RD_REGION][4] = 50 - { 51 - {9, 250, 250, 250}, // CE 52 - {4, 250, 250, 250}, // FCC 53 - {4, 250, 250, 250}, // JAP 54 - {15, 250, 250, 250}, // JAP_W53 55 - {4, 250, 250, 250} // JAP_W56 56 - }; 57 - 58 - /* 59 - ======================================================================== 60 - 61 - Routine Description: 62 - Bbp Radar detection routine 63 - 64 - Arguments: 65 - pAd Pointer to our adapter 66 - 67 - Return Value: 68 - 69 - ======================================================================== 70 - */ 71 - VOID BbpRadarDetectionStart( 72 - IN PRTMP_ADAPTER pAd) 73 - { 74 - UINT8 RadarPeriod; 75 - 76 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 114, 0x02); 77 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 121, 0x20); 78 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 122, 0x00); 79 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 123, 0x08/*0x80*/); 80 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 124, 0x28); 81 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, 125, 0xff); 82 - 83 - RadarPeriod = ((UINT)RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + (UINT)pAd->CommonCfg.RadarDetect.DfsSessionTime) < 250 ? 84 - (RdIdleTimeTable[pAd->CommonCfg.RadarDetect.RDDurRegion][0] + pAd->CommonCfg.RadarDetect.DfsSessionTime) : 250; 85 - 86 - RTMP_IO_WRITE8(pAd, 0x7020, 0x1d); 87 - RTMP_IO_WRITE8(pAd, 0x7021, 0x40); 88 - 89 - RadarDetectionStart(pAd, 0, RadarPeriod); 90 - return; 91 - } 92 - 93 - /* 94 - ======================================================================== 95 - 96 - Routine Description: 97 - Bbp Radar detection routine 98 - 99 - Arguments: 100 - pAd Pointer to our adapter 101 - 102 - Return Value: 103 - 104 - ======================================================================== 105 - */ 106 - VOID BbpRadarDetectionStop( 107 - IN PRTMP_ADAPTER pAd) 108 - { 109 - RTMP_IO_WRITE8(pAd, 0x7020, 0x1d); 110 - RTMP_IO_WRITE8(pAd, 0x7021, 0x60); 111 - 112 - RadarDetectionStop(pAd); 113 - return; 114 - } 115 - 116 - /* 117 - ======================================================================== 118 - 119 - Routine Description: 120 - Radar detection routine 121 - 122 - Arguments: 123 - pAd Pointer to our adapter 124 - 125 - Return Value: 126 - 127 - ======================================================================== 128 - */ 129 - VOID RadarDetectionStart( 130 - IN PRTMP_ADAPTER pAd, 131 - IN BOOLEAN CTSProtect, 132 - IN UINT8 CTSPeriod) 133 - { 134 - UINT8 DfsActiveTime = (pAd->CommonCfg.RadarDetect.DfsSessionTime & 0x1f); 135 - UINT8 CtsProtect = (CTSProtect == 1) ? 0x02 : 0x01; // CTS protect. 136 - 137 - if (CTSProtect != 0) 138 - { 139 - switch(pAd->CommonCfg.RadarDetect.RDDurRegion) 140 - { 141 - case FCC: 142 - case JAP_W56: 143 - CtsProtect = 0x03; 144 - break; 145 - 146 - case CE: 147 - case JAP_W53: 148 - default: 149 - CtsProtect = 0x02; 150 - break; 151 - } 152 - } 153 - else 154 - CtsProtect = 0x01; 155 - 156 - 157 - // send start-RD with CTS protection command to MCU 158 - // highbyte [7] reserve 159 - // highbyte [6:5] 0x: stop Carrier/Radar detection 160 - // highbyte [10]: Start Carrier/Radar detection without CTS protection, 11: Start Carrier/Radar detection with CTS protection 161 - // highbyte [4:0] Radar/carrier detection duration. In 1ms. 162 - 163 - // lowbyte [7:0] Radar/carrier detection period, in 1ms. 164 - AsicSendCommandToMcu(pAd, 0x60, 0xff, CTSPeriod, DfsActiveTime | (CtsProtect << 5)); 165 - //AsicSendCommandToMcu(pAd, 0x63, 0xff, 10, 0); 166 - 167 - return; 168 - } 169 - 170 - /* 171 - ======================================================================== 172 - 173 - Routine Description: 174 - Radar detection routine 175 - 176 - Arguments: 177 - pAd Pointer to our adapter 178 - 179 - Return Value: 180 - TRUE Found radar signal 181 - FALSE Not found radar signal 182 - 183 - ======================================================================== 184 - */ 185 - VOID RadarDetectionStop( 186 - IN PRTMP_ADAPTER pAd) 187 - { 188 - DBGPRINT(RT_DEBUG_TRACE,("RadarDetectionStop.\n")); 189 - AsicSendCommandToMcu(pAd, 0x60, 0xff, 0x00, 0x00); // send start-RD with CTS protection command to MCU 190 - 191 - return; 192 - } 193 - 194 - /* 195 - ======================================================================== 196 - 197 - Routine Description: 198 - Radar channel check routine 199 - 200 - Arguments: 201 - pAd Pointer to our adapter 202 - 203 - Return Value: 204 - TRUE need to do radar detect 205 - FALSE need not to do radar detect 206 - 207 - ======================================================================== 208 - */ 209 - BOOLEAN RadarChannelCheck( 210 - IN PRTMP_ADAPTER pAd, 211 - IN UCHAR Ch) 212 - { 213 - #if 1 214 - INT i; 215 - BOOLEAN result = FALSE; 216 - 217 - for (i=0; i<pAd->ChannelListNum; i++) 218 - { 219 - if (Ch == pAd->ChannelList[i].Channel) 220 - { 221 - result = pAd->ChannelList[i].DfsReq; 222 - break; 223 - } 224 - } 225 - 226 - return result; 227 - #else 228 - INT i; 229 - UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}; 230 - 231 - for (i=0; i<15; i++) 232 - { 233 - if (Ch == Channel[i]) 234 - { 235 - break; 236 - } 237 - } 238 - 239 - if (i != 15) 240 - return TRUE; 241 - else 242 - return FALSE; 243 - #endif 244 - } 245 - 246 - ULONG JapRadarType( 247 - IN PRTMP_ADAPTER pAd) 248 - { 249 - ULONG i; 250 - const UCHAR Channel[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}; 251 - 252 - if (pAd->CommonCfg.RadarDetect.RDDurRegion != JAP) 253 - { 254 - return pAd->CommonCfg.RadarDetect.RDDurRegion; 255 - } 256 - 257 - for (i=0; i<15; i++) 258 - { 259 - if (pAd->CommonCfg.Channel == Channel[i]) 260 - { 261 - break; 262 - } 263 - } 264 - 265 - if (i < 4) 266 - return JAP_W53; 267 - else if (i < 15) 268 - return JAP_W56; 269 - else 270 - return JAP; // W52 271 - 272 - } 273 - 274 - ULONG RTMPBbpReadRadarDuration( 275 - IN PRTMP_ADAPTER pAd) 276 - { 277 - UINT8 byteValue = 0; 278 - ULONG result; 279 - 280 - BBP_IO_READ8_BY_REG_ID(pAd, BBP_R115, &byteValue); 281 - 282 - result = 0; 283 - switch (byteValue) 284 - { 285 - case 1: // radar signal detected by pulse mode. 286 - case 2: // radar signal detected by width mode. 287 - result = RTMPReadRadarDuration(pAd); 288 - break; 289 - 290 - case 0: // No radar signal. 291 - default: 292 - 293 - result = 0; 294 - break; 295 - } 296 - 297 - return result; 298 - } 299 - 300 - ULONG RTMPReadRadarDuration( 301 - IN PRTMP_ADAPTER pAd) 302 - { 303 - ULONG result = 0; 304 - 305 - return result; 306 - 307 - } 308 - 309 - VOID RTMPCleanRadarDuration( 310 - IN PRTMP_ADAPTER pAd) 311 - { 312 - return; 313 - } 314 - 315 - /* 316 - ======================================================================== 317 - Routine Description: 318 - Radar wave detection. The API should be invoke each second. 319 - 320 - Arguments: 321 - pAd - Adapter pointer 322 - 323 - Return Value: 324 - None 325 - 326 - ======================================================================== 327 - */ 328 - VOID ApRadarDetectPeriodic( 329 - IN PRTMP_ADAPTER pAd) 330 - { 331 - INT i; 332 - 333 - pAd->CommonCfg.RadarDetect.InServiceMonitorCount++; 334 - 335 - for (i=0; i<pAd->ChannelListNum; i++) 336 - { 337 - if (pAd->ChannelList[i].RemainingTimeForUse > 0) 338 - { 339 - pAd->ChannelList[i].RemainingTimeForUse --; 340 - if ((pAd->Mlme.PeriodicRound%5) == 0) 341 - { 342 - DBGPRINT(RT_DEBUG_TRACE, ("RadarDetectPeriodic - ch=%d, RemainingTimeForUse=%d\n", pAd->ChannelList[i].Channel, pAd->ChannelList[i].RemainingTimeForUse)); 343 - } 344 - } 345 - } 346 - 347 - //radar detect 348 - if ((pAd->CommonCfg.Channel > 14) 349 - && (pAd->CommonCfg.bIEEE80211H == 1) 350 - && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) 351 - { 352 - RadarDetectPeriodic(pAd); 353 - } 354 - 355 - return; 356 - } 357 - 358 - // Periodic Radar detection, switch channel will occur in RTMPHandleTBTTInterrupt() 359 - // Before switch channel, driver needs doing channel switch announcement. 360 - VOID RadarDetectPeriodic( 361 - IN PRTMP_ADAPTER pAd) 362 - { 363 - // need to check channel availability, after switch channel 364 - if (pAd->CommonCfg.RadarDetect.RDMode != RD_SILENCE_MODE) 365 - return; 366 - 367 - // channel availability check time is 60sec, use 65 for assurance 368 - if (pAd->CommonCfg.RadarDetect.RDCount++ > pAd->CommonCfg.RadarDetect.ChMovingTime) 369 - { 370 - DBGPRINT(RT_DEBUG_TRACE, ("Not found radar signal, start send beacon and radar detection in service monitor\n\n")); 371 - BbpRadarDetectionStop(pAd); 372 - AsicEnableBssSync(pAd); 373 - pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE; 374 - 375 - 376 - return; 377 - } 378 - 379 - return; 380 - } 381 - 382 - 383 - /* 384 - ========================================================================== 385 - Description: 386 - change channel moving time for DFS testing. 387 - 388 - Arguments: 389 - pAdapter Pointer to our adapter 390 - wrq Pointer to the ioctl argument 391 - 392 - Return Value: 393 - None 394 - 395 - Note: 396 - Usage: 397 - 1.) iwpriv ra0 set ChMovTime=[value] 398 - ========================================================================== 399 - */ 400 - INT Set_ChMovingTime_Proc( 401 - IN PRTMP_ADAPTER pAd, 402 - IN PUCHAR arg) 403 - { 404 - UINT8 Value; 405 - 406 - Value = simple_strtol(arg, 0, 10); 407 - 408 - pAd->CommonCfg.RadarDetect.ChMovingTime = Value; 409 - 410 - DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __func__, 411 - pAd->CommonCfg.RadarDetect.ChMovingTime)); 412 - 413 - return TRUE; 414 - } 415 - 416 - INT Set_LongPulseRadarTh_Proc( 417 - IN PRTMP_ADAPTER pAd, 418 - IN PUCHAR arg) 419 - { 420 - UINT8 Value; 421 - 422 - Value = simple_strtol(arg, 0, 10) > 10 ? 10 : simple_strtol(arg, 0, 10); 423 - 424 - pAd->CommonCfg.RadarDetect.LongPulseRadarTh = Value; 425 - 426 - DBGPRINT(RT_DEBUG_TRACE, ("%s:: %d\n", __func__, 427 - pAd->CommonCfg.RadarDetect.LongPulseRadarTh)); 428 - 429 - return TRUE; 430 - } 431 - 432 - 1 + #include "../../rt2860/common/dfs.c"
+1 -1510
drivers/staging/rt2870/common/eeprom.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - eeprom.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Name Date Modification logs 36 - */ 37 - #include "../rt_config.h" 38 - 39 - // IRQL = PASSIVE_LEVEL 40 - VOID RaiseClock( 41 - IN PRTMP_ADAPTER pAd, 42 - IN UINT32 *x) 43 - { 44 - *x = *x | EESK; 45 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x); 46 - RTMPusecDelay(1); // Max frequency = 1MHz in Spec. definition 47 - } 48 - 49 - // IRQL = PASSIVE_LEVEL 50 - VOID LowerClock( 51 - IN PRTMP_ADAPTER pAd, 52 - IN UINT32 *x) 53 - { 54 - *x = *x & ~EESK; 55 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x); 56 - RTMPusecDelay(1); 57 - } 58 - 59 - // IRQL = PASSIVE_LEVEL 60 - USHORT ShiftInBits( 61 - IN PRTMP_ADAPTER pAd) 62 - { 63 - UINT32 x,i; 64 - USHORT data=0; 65 - 66 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 67 - 68 - x &= ~( EEDO | EEDI); 69 - 70 - for(i=0; i<16; i++) 71 - { 72 - data = data << 1; 73 - RaiseClock(pAd, &x); 74 - 75 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 76 - #ifdef RT30xx 77 - LowerClock(pAd, &x); //prevent read failed 78 - #endif 79 - x &= ~(EEDI); 80 - if(x & EEDO) 81 - data |= 1; 82 - 83 - #ifndef RT30xx 84 - LowerClock(pAd, &x); 85 - #endif 86 - } 87 - 88 - return data; 89 - } 90 - 91 - // IRQL = PASSIVE_LEVEL 92 - VOID ShiftOutBits( 93 - IN PRTMP_ADAPTER pAd, 94 - IN USHORT data, 95 - IN USHORT count) 96 - { 97 - UINT32 x,mask; 98 - 99 - mask = 0x01 << (count - 1); 100 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 101 - 102 - x &= ~(EEDO | EEDI); 103 - 104 - do 105 - { 106 - x &= ~EEDI; 107 - if(data & mask) x |= EEDI; 108 - 109 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 110 - 111 - RaiseClock(pAd, &x); 112 - LowerClock(pAd, &x); 113 - 114 - mask = mask >> 1; 115 - } while(mask); 116 - 117 - x &= ~EEDI; 118 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 119 - } 120 - 121 - // IRQL = PASSIVE_LEVEL 122 - VOID EEpromCleanup( 123 - IN PRTMP_ADAPTER pAd) 124 - { 125 - UINT32 x; 126 - 127 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 128 - 129 - x &= ~(EECS | EEDI); 130 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 131 - 132 - RaiseClock(pAd, &x); 133 - LowerClock(pAd, &x); 134 - } 135 - 136 - VOID EWEN( 137 - IN PRTMP_ADAPTER pAd) 138 - { 139 - UINT32 x; 140 - 141 - // reset bits and set EECS 142 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 143 - x &= ~(EEDI | EEDO | EESK); 144 - x |= EECS; 145 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 146 - 147 - // kick a pulse 148 - RaiseClock(pAd, &x); 149 - LowerClock(pAd, &x); 150 - 151 - // output the read_opcode and six pulse in that order 152 - ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5); 153 - ShiftOutBits(pAd, 0, 6); 154 - 155 - EEpromCleanup(pAd); 156 - } 157 - 158 - VOID EWDS( 159 - IN PRTMP_ADAPTER pAd) 160 - { 161 - UINT32 x; 162 - 163 - // reset bits and set EECS 164 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 165 - x &= ~(EEDI | EEDO | EESK); 166 - x |= EECS; 167 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 168 - 169 - // kick a pulse 170 - RaiseClock(pAd, &x); 171 - LowerClock(pAd, &x); 172 - 173 - // output the read_opcode and six pulse in that order 174 - ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5); 175 - ShiftOutBits(pAd, 0, 6); 176 - 177 - EEpromCleanup(pAd); 178 - } 179 - 180 - // IRQL = PASSIVE_LEVEL 181 - USHORT RTMP_EEPROM_READ16( 182 - IN PRTMP_ADAPTER pAd, 183 - IN USHORT Offset) 184 - { 185 - UINT32 x; 186 - USHORT data; 187 - 188 - #ifdef RT30xx 189 - if (pAd->NicConfig2.field.AntDiversity) 190 - { 191 - pAd->EepromAccess = TRUE; 192 - } 193 - //2008/09/11:KH add to support efuse<-- 194 - //2008/09/11:KH add to support efuse--> 195 - { 196 - #endif 197 - Offset /= 2; 198 - // reset bits and set EECS 199 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 200 - x &= ~(EEDI | EEDO | EESK); 201 - x |= EECS; 202 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 203 - 204 - #ifdef RT30xx 205 - // patch can not access e-Fuse issue 206 - if (!IS_RT3090(pAd)) 207 - { 208 - #endif 209 - // kick a pulse 210 - RaiseClock(pAd, &x); 211 - LowerClock(pAd, &x); 212 - #ifdef RT30xx 213 - } 214 - #endif 215 - 216 - // output the read_opcode and register number in that order 217 - ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3); 218 - ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum); 219 - 220 - // Now read the data (16 bits) in from the selected EEPROM word 221 - data = ShiftInBits(pAd); 222 - 223 - EEpromCleanup(pAd); 224 - 225 - #ifdef RT30xx 226 - // Antenna and EEPROM access are both using EESK pin, 227 - // Therefor we should avoid accessing EESK at the same time 228 - // Then restore antenna after EEPROM access 229 - if ((pAd->NicConfig2.field.AntDiversity) || (pAd->RfIcType == RFIC_3020)) 230 - { 231 - pAd->EepromAccess = FALSE; 232 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); 233 - } 234 - } 235 - #endif 236 - return data; 237 - } //ReadEEprom 238 - 239 - VOID RTMP_EEPROM_WRITE16( 240 - IN PRTMP_ADAPTER pAd, 241 - IN USHORT Offset, 242 - IN USHORT Data) 243 - { 244 - UINT32 x; 245 - 246 - #ifdef RT30xx 247 - if (pAd->NicConfig2.field.AntDiversity) 248 - { 249 - pAd->EepromAccess = TRUE; 250 - } 251 - //2008/09/11:KH add to support efuse<-- 252 - //2008/09/11:KH add to support efuse--> 253 - { 254 - #endif 255 - Offset /= 2; 256 - 257 - EWEN(pAd); 258 - 259 - // reset bits and set EECS 260 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 261 - x &= ~(EEDI | EEDO | EESK); 262 - x |= EECS; 263 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 264 - 265 - #ifdef RT30xx 266 - // patch can not access e-Fuse issue 267 - if (!IS_RT3090(pAd)) 268 - { 269 - #endif 270 - // kick a pulse 271 - RaiseClock(pAd, &x); 272 - LowerClock(pAd, &x); 273 - #ifdef RT30xx 274 - } 275 - #endif 276 - 277 - // output the read_opcode ,register number and data in that order 278 - ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3); 279 - ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum); 280 - ShiftOutBits(pAd, Data, 16); // 16-bit access 281 - 282 - // read DO status 283 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 284 - 285 - EEpromCleanup(pAd); 286 - 287 - RTMPusecDelay(10000); //delay for twp(MAX)=10ms 288 - 289 - EWDS(pAd); 290 - 291 - EEpromCleanup(pAd); 292 - 293 - #ifdef RT30xx 294 - // Antenna and EEPROM access are both using EESK pin, 295 - // Therefor we should avoid accessing EESK at the same time 296 - // Then restore antenna after EEPROM access 297 - if ((pAd->NicConfig2.field.AntDiversity) || (pAd->RfIcType == RFIC_3020)) 298 - { 299 - pAd->EepromAccess = FALSE; 300 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); 301 - } 302 - } 303 - #endif 304 - } 305 - 306 - //2008/09/11:KH add to support efuse<-- 307 - #ifdef RT30xx 308 - /* 309 - ======================================================================== 310 - 311 - Routine Description: 312 - 313 - Arguments: 314 - 315 - Return Value: 316 - 317 - IRQL = 318 - 319 - Note: 320 - 321 - ======================================================================== 322 - */ 323 - UCHAR eFuseReadRegisters( 324 - IN PRTMP_ADAPTER pAd, 325 - IN USHORT Offset, 326 - IN USHORT Length, 327 - OUT USHORT* pData) 328 - { 329 - EFUSE_CTRL_STRUC eFuseCtrlStruc; 330 - int i; 331 - USHORT efuseDataOffset; 332 - UINT32 data; 333 - 334 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 335 - 336 - //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 337 - //Use the eeprom logical address and covert to address to block number 338 - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; 339 - 340 - //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 0. 341 - eFuseCtrlStruc.field.EFSROM_MODE = 0; 342 - 343 - //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. 344 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 345 - 346 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 347 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 348 - 349 - //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. 350 - i = 0; 351 - while(i < 100) 352 - { 353 - //rtmp.HwMemoryReadDword(EFUSE_CTRL, (DWORD *) &eFuseCtrlStruc, 4); 354 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 355 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 356 - { 357 - break; 358 - } 359 - RTMPusecDelay(2); 360 - i++; 361 - } 362 - 363 - //if EFSROM_AOUT is not found in physical address, write 0xffff 364 - if (eFuseCtrlStruc.field.EFSROM_AOUT == 0x3f) 365 - { 366 - for(i=0; i<Length/2; i++) 367 - *(pData+2*i) = 0xffff; 368 - } 369 - else 370 - { 371 - //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x590-0x59C) 372 - efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC) ; 373 - //data hold 4 bytes data. 374 - //In RTMP_IO_READ32 will automatically execute 32-bytes swapping 375 - RTMP_IO_READ32(pAd, efuseDataOffset, &data); 376 - //Decide the upper 2 bytes or the bottom 2 bytes. 377 - // Little-endian S | S Big-endian 378 - // addr 3 2 1 0 | 0 1 2 3 379 - // Ori-V D C B A | A B C D 380 - //After swapping 381 - // D C B A | D C B A 382 - //Return 2-bytes 383 - //The return byte statrs from S. Therefore, the little-endian will return BA, the Big-endian will return DC. 384 - //For returning the bottom 2 bytes, the Big-endian should shift right 2-bytes. 385 - data = data >> (8*(Offset & 0x3)); 386 - 387 - NdisMoveMemory(pData, &data, Length); 388 - } 389 - 390 - return (UCHAR) eFuseCtrlStruc.field.EFSROM_AOUT; 391 - 392 - } 393 - 394 - /* 395 - ======================================================================== 396 - 397 - Routine Description: 398 - 399 - Arguments: 400 - 401 - Return Value: 402 - 403 - IRQL = 404 - 405 - Note: 406 - 407 - ======================================================================== 408 - */ 409 - VOID eFusePhysicalReadRegisters( 410 - IN PRTMP_ADAPTER pAd, 411 - IN USHORT Offset, 412 - IN USHORT Length, 413 - OUT USHORT* pData) 414 - { 415 - EFUSE_CTRL_STRUC eFuseCtrlStruc; 416 - int i; 417 - USHORT efuseDataOffset; 418 - UINT32 data; 419 - 420 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 421 - 422 - //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 423 - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; 424 - 425 - //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1. 426 - //Read in physical view 427 - eFuseCtrlStruc.field.EFSROM_MODE = 1; 428 - 429 - //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. 430 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 431 - 432 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 433 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 434 - 435 - //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. 436 - i = 0; 437 - while(i < 100) 438 - { 439 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 440 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 441 - break; 442 - RTMPusecDelay(2); 443 - i++; 444 - } 445 - 446 - //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590) 447 - //Because the size of each EFUSE_DATA is 4 Bytes, the size of address of each is 2 bits. 448 - //The previous 2 bits is the EFUSE_DATA number, the last 2 bits is used to decide which bytes 449 - //Decide which EFUSE_DATA to read 450 - //590:F E D C 451 - //594:B A 9 8 452 - //598:7 6 5 4 453 - //59C:3 2 1 0 454 - efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC) ; 455 - 456 - RTMP_IO_READ32(pAd, efuseDataOffset, &data); 457 - 458 - data = data >> (8*(Offset & 0x3)); 459 - 460 - NdisMoveMemory(pData, &data, Length); 461 - 462 - } 463 - 464 - /* 465 - ======================================================================== 466 - 467 - Routine Description: 468 - 469 - Arguments: 470 - 471 - Return Value: 472 - 473 - IRQL = 474 - 475 - Note: 476 - 477 - ======================================================================== 478 - */ 479 - VOID eFuseReadPhysical( 480 - IN PRTMP_ADAPTER pAd, 481 - IN PUSHORT lpInBuffer, 482 - IN ULONG nInBufferSize, 483 - OUT PUSHORT lpOutBuffer, 484 - IN ULONG nOutBufferSize 485 - ) 486 - { 487 - USHORT* pInBuf = (USHORT*)lpInBuffer; 488 - USHORT* pOutBuf = (USHORT*)lpOutBuffer; 489 - 490 - USHORT Offset = pInBuf[0]; //addr 491 - USHORT Length = pInBuf[1]; //length 492 - int i; 493 - 494 - for(i=0; i<Length; i+=2) 495 - { 496 - eFusePhysicalReadRegisters(pAd,Offset+i, 2, &pOutBuf[i/2]); 497 - } 498 - } 499 - 500 - /* 501 - ======================================================================== 502 - 503 - Routine Description: 504 - 505 - Arguments: 506 - 507 - Return Value: 508 - 509 - IRQL = 510 - 511 - Note: 512 - 513 - ======================================================================== 514 - */ 515 - NTSTATUS eFuseRead( 516 - IN PRTMP_ADAPTER pAd, 517 - IN USHORT Offset, 518 - OUT PUCHAR pData, 519 - IN USHORT Length) 520 - { 521 - USHORT* pOutBuf = (USHORT*)pData; 522 - NTSTATUS Status = STATUS_SUCCESS; 523 - UCHAR EFSROM_AOUT; 524 - int i; 525 - 526 - for(i=0; i<Length; i+=2) 527 - { 528 - EFSROM_AOUT = eFuseReadRegisters(pAd, Offset+i, 2, &pOutBuf[i/2]); 529 - } 530 - return Status; 531 - } 532 - 533 - /* 534 - ======================================================================== 535 - 536 - Routine Description: 537 - 538 - Arguments: 539 - 540 - Return Value: 541 - 542 - IRQL = 543 - 544 - Note: 545 - 546 - ======================================================================== 547 - */ 548 - VOID eFusePhysicalWriteRegisters( 549 - IN PRTMP_ADAPTER pAd, 550 - IN USHORT Offset, 551 - IN USHORT Length, 552 - OUT USHORT* pData) 553 - { 554 - EFUSE_CTRL_STRUC eFuseCtrlStruc; 555 - int i; 556 - USHORT efuseDataOffset; 557 - UINT32 data, eFuseDataBuffer[4]; 558 - 559 - //Step0. Write 16-byte of data to EFUSE_DATA0-3 (0x590-0x59C), where EFUSE_DATA0 is the LSB DW, EFUSE_DATA3 is the MSB DW. 560 - 561 - ///////////////////////////////////////////////////////////////// 562 - //read current values of 16-byte block 563 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 564 - 565 - //Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 566 - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; 567 - 568 - //Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1. 569 - eFuseCtrlStruc.field.EFSROM_MODE = 1; 570 - 571 - //Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. 572 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 573 - 574 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 575 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 576 - 577 - //Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. 578 - i = 0; 579 - while(i < 100) 580 - { 581 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 582 - 583 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 584 - break; 585 - RTMPusecDelay(2); 586 - i++; 587 - } 588 - 589 - //Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590) 590 - efuseDataOffset = EFUSE_DATA3; 591 - for(i=0; i< 4; i++) 592 - { 593 - RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &eFuseDataBuffer[i]); 594 - efuseDataOffset -= 4; 595 - } 596 - 597 - //Update the value, the offset is multiple of 2, length is 2 598 - efuseDataOffset = (Offset & 0xc) >> 2; 599 - data = pData[0] & 0xffff; 600 - //The offset should be 0x***10 or 0x***00 601 - if((Offset % 4) != 0) 602 - { 603 - eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff) | (data << 16); 604 - } 605 - else 606 - { 607 - eFuseDataBuffer[efuseDataOffset] = (eFuseDataBuffer[efuseDataOffset] & 0xffff0000) | data; 608 - } 609 - 610 - efuseDataOffset = EFUSE_DATA3; 611 - for(i=0; i< 4; i++) 612 - { 613 - RTMP_IO_WRITE32(pAd, efuseDataOffset, eFuseDataBuffer[i]); 614 - efuseDataOffset -= 4; 615 - } 616 - ///////////////////////////////////////////////////////////////// 617 - 618 - //Step1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 619 - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; 620 - 621 - //Step2. Write EFSROM_MODE (0x580, bit7:bit6) to 3. 622 - eFuseCtrlStruc.field.EFSROM_MODE = 3; 623 - 624 - //Step3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure. 625 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 626 - 627 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 628 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 629 - 630 - //Step4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It��s done. 631 - i = 0; 632 - while(i < 100) 633 - { 634 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 635 - 636 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 637 - break; 638 - 639 - RTMPusecDelay(2); 640 - i++; 641 - } 642 - } 643 - 644 - /* 645 - ======================================================================== 646 - 647 - Routine Description: 648 - 649 - Arguments: 650 - 651 - Return Value: 652 - 653 - IRQL = 654 - 655 - Note: 656 - 657 - ======================================================================== 658 - */ 659 - NTSTATUS eFuseWriteRegisters( 660 - IN PRTMP_ADAPTER pAd, 661 - IN USHORT Offset, 662 - IN USHORT Length, 663 - IN USHORT* pData) 664 - { 665 - USHORT i; 666 - USHORT eFuseData; 667 - USHORT LogicalAddress, BlkNum = 0xffff; 668 - UCHAR EFSROM_AOUT; 669 - 670 - USHORT addr,tmpaddr, InBuf[3], tmpOffset; 671 - USHORT buffer[8]; 672 - BOOLEAN bWriteSuccess = TRUE; 673 - 674 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters Offset=%x, pData=%x\n", Offset, *pData)); 675 - 676 - //Step 0. find the entry in the mapping table 677 - //The address of EEPROM is 2-bytes alignment. 678 - //The last bit is used for alignment, so it must be 0. 679 - tmpOffset = Offset & 0xfffe; 680 - EFSROM_AOUT = eFuseReadRegisters(pAd, tmpOffset, 2, &eFuseData); 681 - 682 - if( EFSROM_AOUT == 0x3f) 683 - { //find available logical address pointer 684 - //the logical address does not exist, find an empty one 685 - //from the first address of block 45=16*45=0x2d0 to the last address of block 47 686 - //==>48*16-3(reserved)=2FC 687 - for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2) 688 - { 689 - //Retrive the logical block nubmer form each logical address pointer 690 - //It will access two logical address pointer each time. 691 - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); 692 - if( (LogicalAddress & 0xff) == 0) 693 - {//Not used logical address pointer 694 - BlkNum = i-EFUSE_USAGE_MAP_START; 695 - break; 696 - } 697 - else if(( (LogicalAddress >> 8) & 0xff) == 0) 698 - {//Not used logical address pointer 699 - if (i != EFUSE_USAGE_MAP_END) 700 - { 701 - BlkNum = i-EFUSE_USAGE_MAP_START+1; 702 - } 703 - break; 704 - } 705 - } 706 - } 707 - else 708 - { 709 - BlkNum = EFSROM_AOUT; 710 - } 711 - 712 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters BlkNum = %d \n", BlkNum)); 713 - 714 - if(BlkNum == 0xffff) 715 - { 716 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n")); 717 - return FALSE; 718 - } 719 - 720 - //Step 1. Save data of this block which is pointed by the avaible logical address pointer 721 - // read and save the original block data 722 - for(i =0; i<8; i++) 723 - { 724 - addr = BlkNum * 0x10 ; 725 - 726 - InBuf[0] = addr+2*i; 727 - InBuf[1] = 2; 728 - InBuf[2] = 0x0; 729 - 730 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 731 - 732 - buffer[i] = InBuf[2]; 733 - } 734 - 735 - //Step 2. Update the data in buffer, and write the data to Efuse 736 - buffer[ (Offset >> 1) % 8] = pData[0]; 737 - 738 - do 739 - { 740 - //Step 3. Write the data to Efuse 741 - if(!bWriteSuccess) 742 - { 743 - for(i =0; i<8; i++) 744 - { 745 - addr = BlkNum * 0x10 ; 746 - 747 - InBuf[0] = addr+2*i; 748 - InBuf[1] = 2; 749 - InBuf[2] = buffer[i]; 750 - 751 - eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2); 752 - } 753 - } 754 - else 755 - { 756 - addr = BlkNum * 0x10 ; 757 - 758 - InBuf[0] = addr+(Offset % 16); 759 - InBuf[1] = 2; 760 - InBuf[2] = pData[0]; 761 - 762 - eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2); 763 - } 764 - 765 - //Step 4. Write mapping table 766 - addr = EFUSE_USAGE_MAP_START+BlkNum; 767 - 768 - tmpaddr = addr; 769 - 770 - if(addr % 2 != 0) 771 - addr = addr -1; 772 - InBuf[0] = addr; 773 - InBuf[1] = 2; 774 - 775 - //convert the address from 10 to 8 bit ( bit7, 6 = parity and bit5 ~ 0 = bit9~4), and write to logical map entry 776 - tmpOffset = Offset; 777 - tmpOffset >>= 4; 778 - tmpOffset |= ((~((tmpOffset & 0x01) ^ ( tmpOffset >> 1 & 0x01) ^ (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01))) << 6) & 0x40; 779 - tmpOffset |= ((~( (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01) ^ (tmpOffset >> 4 & 0x01) ^ ( tmpOffset >> 5 & 0x01))) << 7) & 0x80; 780 - 781 - // write the logical address 782 - if(tmpaddr%2 != 0) 783 - InBuf[2] = tmpOffset<<8; 784 - else 785 - InBuf[2] = tmpOffset; 786 - 787 - eFuseWritePhysical(pAd,&InBuf[0], 6, NULL, 0); 788 - 789 - //Step 5. Compare data if not the same, invalidate the mapping entry, then re-write the data until E-fuse is exhausted 790 - bWriteSuccess = TRUE; 791 - for(i =0; i<8; i++) 792 - { 793 - addr = BlkNum * 0x10 ; 794 - 795 - InBuf[0] = addr+2*i; 796 - InBuf[1] = 2; 797 - InBuf[2] = 0x0; 798 - 799 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 800 - 801 - if(buffer[i] != InBuf[2]) 802 - { 803 - bWriteSuccess = FALSE; 804 - break; 805 - } 806 - } 807 - 808 - //Step 6. invlidate mapping entry and find a free mapping entry if not succeed 809 - if (!bWriteSuccess) 810 - { 811 - DBGPRINT(RT_DEBUG_TRACE, ("Not bWriteSuccess BlkNum = %d\n", BlkNum)); 812 - 813 - // the offset of current mapping entry 814 - addr = EFUSE_USAGE_MAP_START+BlkNum; 815 - 816 - //find a new mapping entry 817 - BlkNum = 0xffff; 818 - for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2) 819 - { 820 - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); 821 - if( (LogicalAddress & 0xff) == 0) 822 - { 823 - BlkNum = i-EFUSE_USAGE_MAP_START; 824 - break; 825 - } 826 - else if(( (LogicalAddress >> 8) & 0xff) == 0) 827 - { 828 - if (i != EFUSE_USAGE_MAP_END) 829 - { 830 - BlkNum = i+1-EFUSE_USAGE_MAP_START; 831 - } 832 - break; 833 - } 834 - } 835 - DBGPRINT(RT_DEBUG_TRACE, ("Not bWriteSuccess new BlkNum = %d\n", BlkNum)); 836 - if(BlkNum == 0xffff) 837 - { 838 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n")); 839 - return FALSE; 840 - } 841 - 842 - //invalidate the original mapping entry if new entry is not found 843 - tmpaddr = addr; 844 - 845 - if(addr % 2 != 0) 846 - addr = addr -1; 847 - InBuf[0] = addr; 848 - InBuf[1] = 2; 849 - 850 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 851 - 852 - // write the logical address 853 - if(tmpaddr%2 != 0) 854 - { 855 - // Invalidate the high byte 856 - for (i=8; i<15; i++) 857 - { 858 - if( ( (InBuf[2] >> i) & 0x01) == 0) 859 - { 860 - InBuf[2] |= (0x1 <<i); 861 - break; 862 - } 863 - } 864 - } 865 - else 866 - { 867 - // invalidate the low byte 868 - for (i=0; i<8; i++) 869 - { 870 - if( ( (InBuf[2] >> i) & 0x01) == 0) 871 - { 872 - InBuf[2] |= (0x1 <<i); 873 - break; 874 - } 875 - } 876 - } 877 - eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 0); 878 - } 879 - } 880 - while(!bWriteSuccess); 881 - 882 - return TRUE; 883 - } 884 - 885 - /* 886 - ======================================================================== 887 - 888 - Routine Description: 889 - 890 - Arguments: 891 - 892 - Return Value: 893 - 894 - IRQL = 895 - 896 - Note: 897 - 898 - ======================================================================== 899 - */ 900 - VOID eFuseWritePhysical( 901 - IN PRTMP_ADAPTER pAd, 902 - PUSHORT lpInBuffer, 903 - ULONG nInBufferSize, 904 - PUCHAR lpOutBuffer, 905 - ULONG nOutBufferSize 906 - ) 907 - { 908 - USHORT* pInBuf = (USHORT*)lpInBuffer; 909 - int i; 910 - //USHORT* pOutBuf = (USHORT*)ioBuffer; 911 - 912 - USHORT Offset = pInBuf[0]; //addr 913 - USHORT Length = pInBuf[1]; //length 914 - USHORT* pValueX = &pInBuf[2]; //value ... 915 - // Little-endian S | S Big-endian 916 - // addr 3 2 1 0 | 0 1 2 3 917 - // Ori-V D C B A | A B C D 918 - //After swapping 919 - // D C B A | D C B A 920 - //Both the little and big-endian use the same sequence to write data. 921 - //Therefore, we only need swap data when read the data. 922 - for(i=0; i<Length; i+=2) 923 - { 924 - eFusePhysicalWriteRegisters(pAd, Offset+i, 2, &pValueX[i/2]); 925 - } 926 - } 927 - 928 - 929 - /* 930 - ======================================================================== 931 - 932 - Routine Description: 933 - 934 - Arguments: 935 - 936 - Return Value: 937 - 938 - IRQL = 939 - 940 - Note: 941 - 942 - ======================================================================== 943 - */ 944 - NTSTATUS eFuseWrite( 945 - IN PRTMP_ADAPTER pAd, 946 - IN USHORT Offset, 947 - IN PUCHAR pData, 948 - IN USHORT length) 949 - { 950 - int i; 951 - 952 - USHORT* pValueX = (PUSHORT) pData; //value ... 953 - //The input value=3070 will be stored as following 954 - // Little-endian S | S Big-endian 955 - // addr 1 0 | 0 1 956 - // Ori-V 30 70 | 30 70 957 - //After swapping 958 - // 30 70 | 70 30 959 - //Casting 960 - // 3070 | 7030 (x) 961 - //The swapping should be removed for big-endian 962 - for(i=0; i<length; i+=2) 963 - { 964 - eFuseWriteRegisters(pAd, Offset+i, 2, &pValueX[i/2]); 965 - } 966 - 967 - return TRUE; 968 - } 969 - 970 - /* 971 - ======================================================================== 972 - 973 - Routine Description: 974 - 975 - Arguments: 976 - 977 - Return Value: 978 - 979 - IRQL = 980 - 981 - Note: 982 - 983 - ======================================================================== 984 - */ 985 - INT set_eFuseGetFreeBlockCount_Proc( 986 - IN PRTMP_ADAPTER pAd, 987 - IN PUCHAR arg) 988 - { 989 - USHORT i; 990 - USHORT LogicalAddress; 991 - USHORT efusefreenum=0; 992 - if(!pAd->bUseEfuse) 993 - return FALSE; 994 - for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i+=2) 995 - { 996 - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); 997 - if( (LogicalAddress & 0xff) == 0) 998 - { 999 - efusefreenum= (UCHAR) (EFUSE_USAGE_MAP_END-i+1); 1000 - break; 1001 - } 1002 - else if(( (LogicalAddress >> 8) & 0xff) == 0) 1003 - { 1004 - efusefreenum = (UCHAR) (EFUSE_USAGE_MAP_END-i); 1005 - break; 1006 - } 1007 - 1008 - if(i == EFUSE_USAGE_MAP_END) 1009 - efusefreenum = 0; 1010 - } 1011 - printk("efuseFreeNumber is %d\n",efusefreenum); 1012 - return TRUE; 1013 - } 1014 - INT set_eFusedump_Proc( 1015 - IN PRTMP_ADAPTER pAd, 1016 - IN PUCHAR arg) 1017 - { 1018 - USHORT InBuf[3]; 1019 - INT i=0; 1020 - if(!pAd->bUseEfuse) 1021 - return FALSE; 1022 - for(i =0; i<EFUSE_USAGE_MAP_END/2; i++) 1023 - { 1024 - InBuf[0] = 2*i; 1025 - InBuf[1] = 2; 1026 - InBuf[2] = 0x0; 1027 - 1028 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 1029 - if(i%4==0) 1030 - printk("\nBlock %x:",i/8); 1031 - printk("%04x ",InBuf[2]); 1032 - } 1033 - return TRUE; 1034 - } 1035 - INT set_eFuseLoadFromBin_Proc( 1036 - IN PRTMP_ADAPTER pAd, 1037 - IN PUCHAR arg) 1038 - { 1039 - CHAR *src; 1040 - struct file *srcf; 1041 - INT retval, orgfsuid, orgfsgid; 1042 - mm_segment_t orgfs; 1043 - UCHAR *buffer; 1044 - UCHAR BinFileSize=0; 1045 - INT i = 0,j=0,k=1; 1046 - USHORT *PDATA; 1047 - USHORT DATA; 1048 - BinFileSize=strlen("RT30xxEEPROM.bin"); 1049 - src = kmalloc(128, MEM_ALLOC_FLAG); 1050 - NdisZeroMemory(src, 128); 1051 - 1052 - if(strlen(arg)>0) 1053 - { 1054 - 1055 - NdisMoveMemory(src, arg, strlen(arg)); 1056 - } 1057 - 1058 - else 1059 - { 1060 - 1061 - NdisMoveMemory(src, "RT30xxEEPROM.bin", BinFileSize); 1062 - } 1063 - 1064 - DBGPRINT(RT_DEBUG_TRACE, ("FileName=%s\n",src)); 1065 - buffer = kmalloc(MAX_EEPROM_BIN_FILE_SIZE, MEM_ALLOC_FLAG); 1066 - 1067 - if(buffer == NULL) 1068 - { 1069 - kfree(src); 1070 - return FALSE; 1071 - } 1072 - PDATA=kmalloc(sizeof(USHORT)*8,MEM_ALLOC_FLAG); 1073 - 1074 - if(PDATA==NULL) 1075 - { 1076 - kfree(src); 1077 - 1078 - kfree(buffer); 1079 - return FALSE; 1080 - } 1081 - /* Don't change to uid 0, let the file be opened as the "normal" user */ 1082 - #if 0 1083 - orgfsuid = current->fsuid; 1084 - orgfsgid = current->fsgid; 1085 - current->fsuid=current->fsgid = 0; 1086 - #endif 1087 - orgfs = get_fs(); 1088 - set_fs(KERNEL_DS); 1089 - 1090 - if (src && *src) 1091 - { 1092 - srcf = filp_open(src, O_RDONLY, 0); 1093 - if (IS_ERR(srcf)) 1094 - { 1095 - DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src)); 1096 - return FALSE; 1097 - } 1098 - else 1099 - { 1100 - // The object must have a read method 1101 - if (srcf->f_op && srcf->f_op->read) 1102 - { 1103 - memset(buffer, 0x00, MAX_EEPROM_BIN_FILE_SIZE); 1104 - while(srcf->f_op->read(srcf, &buffer[i], 1, &srcf->f_pos)==1) 1105 - { 1106 - DBGPRINT(RT_DEBUG_TRACE, ("%02X ",buffer[i])); 1107 - if((i+1)%8==0) 1108 - DBGPRINT(RT_DEBUG_TRACE, ("\n")); 1109 - i++; 1110 - if(i>=MAX_EEPROM_BIN_FILE_SIZE) 1111 - { 1112 - DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld reading %s, The file is too large[1024]\n", -PTR_ERR(srcf),src)); 1113 - kfree(PDATA); 1114 - kfree(buffer); 1115 - kfree(src); 1116 - return FALSE; 1117 - } 1118 - } 1119 - } 1120 - else 1121 - { 1122 - DBGPRINT(RT_DEBUG_ERROR, ("--> Error!! System doest not support read function\n")); 1123 - kfree(PDATA); 1124 - kfree(buffer); 1125 - kfree(src); 1126 - return FALSE; 1127 - } 1128 - } 1129 - 1130 - 1131 - } 1132 - else 1133 - { 1134 - DBGPRINT(RT_DEBUG_ERROR, ("--> Error src or srcf is null\n")); 1135 - kfree(PDATA); 1136 - kfree(buffer); 1137 - return FALSE; 1138 - 1139 - } 1140 - 1141 - 1142 - retval=filp_close(srcf,NULL); 1143 - 1144 - if (retval) 1145 - { 1146 - DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src)); 1147 - } 1148 - set_fs(orgfs); 1149 - #if 0 1150 - current->fsuid = orgfsuid; 1151 - current->fsgid = orgfsgid; 1152 - #endif 1153 - for(j=0;j<i;j++) 1154 - { 1155 - DBGPRINT(RT_DEBUG_TRACE, ("%02X ",buffer[j])); 1156 - if((j+1)%2==0) 1157 - PDATA[j/2%8]=((buffer[j]<<8)&0xff00)|(buffer[j-1]&0xff); 1158 - if(j%16==0) 1159 - { 1160 - k=buffer[j]; 1161 - } 1162 - else 1163 - { 1164 - k&=buffer[j]; 1165 - if((j+1)%16==0) 1166 - { 1167 - 1168 - DBGPRINT(RT_DEBUG_TRACE, (" result=%02X,blk=%02x\n",k,j/16)); 1169 - 1170 - if(k!=0xff) 1171 - eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA); 1172 - else 1173 - { 1174 - if(eFuseReadRegisters(pAd,j, 2,(PUSHORT)&DATA)!=0x3f) 1175 - eFuseWriteRegistersFromBin(pAd,(USHORT)j-15, 16, PDATA); 1176 - } 1177 - /* 1178 - for(l=0;l<8;l++) 1179 - printk("%04x ",PDATA[l]); 1180 - printk("\n"); 1181 - */ 1182 - NdisZeroMemory(PDATA,16); 1183 - 1184 - 1185 - } 1186 - } 1187 - 1188 - 1189 - } 1190 - 1191 - 1192 - kfree(PDATA); 1193 - kfree(buffer); 1194 - kfree(src); 1195 - return TRUE; 1196 - } 1197 - NTSTATUS eFuseWriteRegistersFromBin( 1198 - IN PRTMP_ADAPTER pAd, 1199 - IN USHORT Offset, 1200 - IN USHORT Length, 1201 - IN USHORT* pData) 1202 - { 1203 - USHORT i; 1204 - USHORT eFuseData; 1205 - USHORT LogicalAddress, BlkNum = 0xffff; 1206 - UCHAR EFSROM_AOUT,Loop=0; 1207 - EFUSE_CTRL_STRUC eFuseCtrlStruc; 1208 - USHORT efuseDataOffset; 1209 - UINT32 data,tempbuffer; 1210 - USHORT addr,tmpaddr, InBuf[3], tmpOffset; 1211 - UINT32 buffer[4]; 1212 - BOOLEAN bWriteSuccess = TRUE; 1213 - BOOLEAN bNotWrite=TRUE; 1214 - BOOLEAN bAllocateNewBlk=TRUE; 1215 - 1216 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin Offset=%x, pData=%04x:%04x:%04x:%04x\n", Offset, *pData,*(pData+1),*(pData+2),*(pData+3))); 1217 - 1218 - do 1219 - { 1220 - //Step 0. find the entry in the mapping table 1221 - //The address of EEPROM is 2-bytes alignment. 1222 - //The last bit is used for alignment, so it must be 0. 1223 - Loop++; 1224 - tmpOffset = Offset & 0xfffe; 1225 - EFSROM_AOUT = eFuseReadRegisters(pAd, tmpOffset, 2, &eFuseData); 1226 - 1227 - if( EFSROM_AOUT == 0x3f) 1228 - { //find available logical address pointer 1229 - //the logical address does not exist, find an empty one 1230 - //from the first address of block 45=16*45=0x2d0 to the last address of block 47 1231 - //==>48*16-3(reserved)=2FC 1232 - bAllocateNewBlk=TRUE; 1233 - for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2) 1234 - { 1235 - //Retrive the logical block nubmer form each logical address pointer 1236 - //It will access two logical address pointer each time. 1237 - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); 1238 - if( (LogicalAddress & 0xff) == 0) 1239 - {//Not used logical address pointer 1240 - BlkNum = i-EFUSE_USAGE_MAP_START; 1241 - break; 1242 - } 1243 - else if(( (LogicalAddress >> 8) & 0xff) == 0) 1244 - {//Not used logical address pointer 1245 - if (i != EFUSE_USAGE_MAP_END) 1246 - { 1247 - BlkNum = i-EFUSE_USAGE_MAP_START+1; 1248 - } 1249 - break; 1250 - } 1251 - } 1252 - } 1253 - else 1254 - { 1255 - bAllocateNewBlk=FALSE; 1256 - BlkNum = EFSROM_AOUT; 1257 - } 1258 - 1259 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters BlkNum = %d \n", BlkNum)); 1260 - 1261 - if(BlkNum == 0xffff) 1262 - { 1263 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegisters: out of free E-fuse space!!!\n")); 1264 - return FALSE; 1265 - } 1266 - //Step 1.1.0 1267 - //If the block is not existing in mapping table, create one 1268 - //and write down the 16-bytes data to the new block 1269 - if(bAllocateNewBlk) 1270 - { 1271 - DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk\n")); 1272 - efuseDataOffset = EFUSE_DATA3; 1273 - for(i=0; i< 4; i++) 1274 - { 1275 - DBGPRINT(RT_DEBUG_TRACE, ("Allocate New Blk, Data%d=%04x%04x\n",3-i,pData[2*i+1],pData[2*i])); 1276 - tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i]; 1277 - 1278 - 1279 - RTMP_IO_WRITE32(pAd, efuseDataOffset,tempbuffer); 1280 - efuseDataOffset -= 4; 1281 - 1282 - } 1283 - ///////////////////////////////////////////////////////////////// 1284 - 1285 - //Step1.1.1. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 1286 - eFuseCtrlStruc.field.EFSROM_AIN = BlkNum* 0x10 ; 1287 - 1288 - //Step1.1.2. Write EFSROM_MODE (0x580, bit7:bit6) to 3. 1289 - eFuseCtrlStruc.field.EFSROM_MODE = 3; 1290 - 1291 - //Step1.1.3. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical write procedure. 1292 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 1293 - 1294 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 1295 - 1296 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 1297 - 1298 - //Step1.1.4. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. It��s done. 1299 - i = 0; 1300 - while(i < 100) 1301 - { 1302 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 1303 - 1304 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 1305 - break; 1306 - 1307 - RTMPusecDelay(2); 1308 - i++; 1309 - } 1310 - 1311 - } 1312 - else 1313 - { //Step1.2. 1314 - //If the same logical number is existing, check if the writting data and the data 1315 - //saving in this block are the same. 1316 - ///////////////////////////////////////////////////////////////// 1317 - //read current values of 16-byte block 1318 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 1319 - 1320 - //Step1.2.0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. 1321 - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; 1322 - 1323 - //Step1.2.1. Write EFSROM_MODE (0x580, bit7:bit6) to 1. 1324 - eFuseCtrlStruc.field.EFSROM_MODE = 0; 1325 - 1326 - //Step1.2.2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. 1327 - eFuseCtrlStruc.field.EFSROM_KICK = 1; 1328 - 1329 - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); 1330 - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); 1331 - 1332 - //Step1.2.3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. 1333 - i = 0; 1334 - while(i < 100) 1335 - { 1336 - RTMP_IO_READ32(pAd, EFUSE_CTRL, (PUINT32) &eFuseCtrlStruc); 1337 - 1338 - if(eFuseCtrlStruc.field.EFSROM_KICK == 0) 1339 - break; 1340 - RTMPusecDelay(2); 1341 - i++; 1342 - } 1343 - 1344 - //Step1.2.4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590) 1345 - efuseDataOffset = EFUSE_DATA3; 1346 - for(i=0; i< 4; i++) 1347 - { 1348 - RTMP_IO_READ32(pAd, efuseDataOffset, (PUINT32) &buffer[i]); 1349 - efuseDataOffset -= 4; 1350 - } 1351 - //Step1.2.5. Check if the data of efuse and the writing data are the same. 1352 - for(i =0; i<4; i++) 1353 - { 1354 - tempbuffer=((pData[2*i+1]<<16)&0xffff0000)|pData[2*i]; 1355 - DBGPRINT(RT_DEBUG_TRACE, ("buffer[%d]=%x,pData[%d]=%x,pData[%d]=%x,tempbuffer=%x\n",i,buffer[i],2*i,pData[2*i],2*i+1,pData[2*i+1],tempbuffer)); 1356 - 1357 - if(((buffer[i]&0xffff0000)==(pData[2*i+1]<<16))&&((buffer[i]&0xffff)==pData[2*i])) 1358 - bNotWrite&=TRUE; 1359 - else 1360 - { 1361 - bNotWrite&=FALSE; 1362 - break; 1363 - } 1364 - } 1365 - if(!bNotWrite) 1366 - { 1367 - printk("The data is not the same\n"); 1368 - 1369 - for(i =0; i<8; i++) 1370 - { 1371 - addr = BlkNum * 0x10 ; 1372 - 1373 - InBuf[0] = addr+2*i; 1374 - InBuf[1] = 2; 1375 - InBuf[2] = pData[i]; 1376 - 1377 - eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 2); 1378 - } 1379 - 1380 - } 1381 - else 1382 - return TRUE; 1383 - } 1384 - 1385 - 1386 - 1387 - //Step 2. Write mapping table 1388 - addr = EFUSE_USAGE_MAP_START+BlkNum; 1389 - 1390 - tmpaddr = addr; 1391 - 1392 - if(addr % 2 != 0) 1393 - addr = addr -1; 1394 - InBuf[0] = addr; 1395 - InBuf[1] = 2; 1396 - 1397 - //convert the address from 10 to 8 bit ( bit7, 6 = parity and bit5 ~ 0 = bit9~4), and write to logical map entry 1398 - tmpOffset = Offset; 1399 - tmpOffset >>= 4; 1400 - tmpOffset |= ((~((tmpOffset & 0x01) ^ ( tmpOffset >> 1 & 0x01) ^ (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01))) << 6) & 0x40; 1401 - tmpOffset |= ((~( (tmpOffset >> 2 & 0x01) ^ (tmpOffset >> 3 & 0x01) ^ (tmpOffset >> 4 & 0x01) ^ ( tmpOffset >> 5 & 0x01))) << 7) & 0x80; 1402 - 1403 - // write the logical address 1404 - if(tmpaddr%2 != 0) 1405 - InBuf[2] = tmpOffset<<8; 1406 - else 1407 - InBuf[2] = tmpOffset; 1408 - 1409 - eFuseWritePhysical(pAd,&InBuf[0], 6, NULL, 0); 1410 - 1411 - //Step 3. Compare data if not the same, invalidate the mapping entry, then re-write the data until E-fuse is exhausted 1412 - bWriteSuccess = TRUE; 1413 - for(i =0; i<8; i++) 1414 - { 1415 - addr = BlkNum * 0x10 ; 1416 - 1417 - InBuf[0] = addr+2*i; 1418 - InBuf[1] = 2; 1419 - InBuf[2] = 0x0; 1420 - 1421 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 1422 - DBGPRINT(RT_DEBUG_TRACE, ("addr=%x, buffer[i]=%x,InBuf[2]=%x\n",InBuf[0],pData[i],InBuf[2])); 1423 - if(pData[i] != InBuf[2]) 1424 - { 1425 - bWriteSuccess = FALSE; 1426 - break; 1427 - } 1428 - } 1429 - 1430 - //Step 4. invlidate mapping entry and find a free mapping entry if not succeed 1431 - 1432 - if (!bWriteSuccess&&Loop<2) 1433 - { 1434 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess BlkNum = %d\n", BlkNum)); 1435 - 1436 - // the offset of current mapping entry 1437 - addr = EFUSE_USAGE_MAP_START+BlkNum; 1438 - 1439 - //find a new mapping entry 1440 - BlkNum = 0xffff; 1441 - for (i=EFUSE_USAGE_MAP_START; i<=EFUSE_USAGE_MAP_END; i+=2) 1442 - { 1443 - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); 1444 - if( (LogicalAddress & 0xff) == 0) 1445 - { 1446 - BlkNum = i-EFUSE_USAGE_MAP_START; 1447 - break; 1448 - } 1449 - else if(( (LogicalAddress >> 8) & 0xff) == 0) 1450 - { 1451 - if (i != EFUSE_USAGE_MAP_END) 1452 - { 1453 - BlkNum = i+1-EFUSE_USAGE_MAP_START; 1454 - } 1455 - break; 1456 - } 1457 - } 1458 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin::Not bWriteSuccess new BlkNum = %d\n", BlkNum)); 1459 - if(BlkNum == 0xffff) 1460 - { 1461 - DBGPRINT(RT_DEBUG_TRACE, ("eFuseWriteRegistersFromBin: out of free E-fuse space!!!\n")); 1462 - return FALSE; 1463 - } 1464 - 1465 - //invalidate the original mapping entry if new entry is not found 1466 - tmpaddr = addr; 1467 - 1468 - if(addr % 2 != 0) 1469 - addr = addr -1; 1470 - InBuf[0] = addr; 1471 - InBuf[1] = 2; 1472 - 1473 - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 1474 - 1475 - // write the logical address 1476 - if(tmpaddr%2 != 0) 1477 - { 1478 - // Invalidate the high byte 1479 - for (i=8; i<15; i++) 1480 - { 1481 - if( ( (InBuf[2] >> i) & 0x01) == 0) 1482 - { 1483 - InBuf[2] |= (0x1 <<i); 1484 - break; 1485 - } 1486 - } 1487 - } 1488 - else 1489 - { 1490 - // invalidate the low byte 1491 - for (i=0; i<8; i++) 1492 - { 1493 - if( ( (InBuf[2] >> i) & 0x01) == 0) 1494 - { 1495 - InBuf[2] |= (0x1 <<i); 1496 - break; 1497 - } 1498 - } 1499 - } 1500 - eFuseWritePhysical(pAd, &InBuf[0], 6, NULL, 0); 1501 - } 1502 - 1503 - } 1504 - while(!bWriteSuccess&&Loop<2); 1505 - 1506 - return TRUE; 1507 - } 1508 - 1509 - #endif // RT30xx // 1510 - //2008/09/11:KH add to support efuse--> 1 + #include "../../rt2860/common/eeprom.c"
+1 -1415
drivers/staging/rt2870/common/md5.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - md5.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Name Date Modification logs 36 - jan 10-28-03 Initial 37 - Rita 11-23-04 Modify MD5 and SHA-1 38 - Rita 10-14-05 Modify SHA-1 in big-endian platform 39 - */ 40 - #include "../rt_config.h" 41 - 42 - /** 43 - * md5_mac: 44 - * @key: pointer to the key used for MAC generation 45 - * @key_len: length of the key in bytes 46 - * @data: pointer to the data area for which the MAC is generated 47 - * @data_len: length of the data in bytes 48 - * @mac: pointer to the buffer holding space for the MAC; the buffer should 49 - * have space for 128-bit (16 bytes) MD5 hash value 50 - * 51 - * md5_mac() determines the message authentication code by using secure hash 52 - * MD5(key | data | key). 53 - */ 54 - void md5_mac(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac) 55 - { 56 - MD5_CTX context; 57 - 58 - MD5Init(&context); 59 - MD5Update(&context, key, key_len); 60 - MD5Update(&context, data, data_len); 61 - MD5Update(&context, key, key_len); 62 - MD5Final(mac, &context); 63 - } 64 - 65 - /** 66 - * hmac_md5: 67 - * @key: pointer to the key used for MAC generation 68 - * @key_len: length of the key in bytes 69 - * @data: pointer to the data area for which the MAC is generated 70 - * @data_len: length of the data in bytes 71 - * @mac: pointer to the buffer holding space for the MAC; the buffer should 72 - * have space for 128-bit (16 bytes) MD5 hash value 73 - * 74 - * hmac_md5() determines the message authentication code using HMAC-MD5. 75 - * This implementation is based on the sample code presented in RFC 2104. 76 - */ 77 - void hmac_md5(u8 *key, size_t key_len, u8 *data, size_t data_len, u8 *mac) 78 - { 79 - MD5_CTX context; 80 - u8 k_ipad[65]; /* inner padding - key XORd with ipad */ 81 - u8 k_opad[65]; /* outer padding - key XORd with opad */ 82 - u8 tk[16]; 83 - int i; 84 - 85 - //assert(key != NULL && data != NULL && mac != NULL); 86 - 87 - /* if key is longer than 64 bytes reset it to key = MD5(key) */ 88 - if (key_len > 64) { 89 - MD5_CTX ttcontext; 90 - 91 - MD5Init(&ttcontext); 92 - MD5Update(&ttcontext, key, key_len); 93 - MD5Final(tk, &ttcontext); 94 - //key=(PUCHAR)ttcontext.buf; 95 - key = tk; 96 - key_len = 16; 97 - } 98 - 99 - /* the HMAC_MD5 transform looks like: 100 - * 101 - * MD5(K XOR opad, MD5(K XOR ipad, text)) 102 - * 103 - * where K is an n byte key 104 - * ipad is the byte 0x36 repeated 64 times 105 - * opad is the byte 0x5c repeated 64 times 106 - * and text is the data being protected */ 107 - 108 - /* start out by storing key in pads */ 109 - NdisZeroMemory(k_ipad, sizeof(k_ipad)); 110 - NdisZeroMemory(k_opad, sizeof(k_opad)); 111 - //assert(key_len < sizeof(k_ipad)); 112 - NdisMoveMemory(k_ipad, key, key_len); 113 - NdisMoveMemory(k_opad, key, key_len); 114 - 115 - /* XOR key with ipad and opad values */ 116 - for (i = 0; i < 64; i++) { 117 - k_ipad[i] ^= 0x36; 118 - k_opad[i] ^= 0x5c; 119 - } 120 - 121 - /* perform inner MD5 */ 122 - MD5Init(&context); /* init context for 1st pass */ 123 - MD5Update(&context, k_ipad, 64); /* start with inner pad */ 124 - MD5Update(&context, data, data_len); /* then text of datagram */ 125 - MD5Final(mac, &context); /* finish up 1st pass */ 126 - 127 - /* perform outer MD5 */ 128 - MD5Init(&context); /* init context for 2nd pass */ 129 - MD5Update(&context, k_opad, 64); /* start with outer pad */ 130 - MD5Update(&context, mac, 16); /* then results of 1st hash */ 131 - MD5Final(mac, &context); /* finish up 2nd pass */ 132 - } 133 - 134 - #define byteReverse(buf, len) /* Nothing */ 135 - 136 - /* ========================== MD5 implementation =========================== */ 137 - // four base functions for MD5 138 - #define MD5_F1(x, y, z) (((x) & (y)) | ((~x) & (z))) 139 - #define MD5_F2(x, y, z) (((x) & (z)) | ((y) & (~z))) 140 - #define MD5_F3(x, y, z) ((x) ^ (y) ^ (z)) 141 - #define MD5_F4(x, y, z) ((y) ^ ((x) | (~z))) 142 - #define CYCLIC_LEFT_SHIFT(w, s) (((w) << (s)) | ((w) >> (32-(s)))) 143 - 144 - #define MD5Step(f, w, x, y, z, data, t, s) \ 145 - ( w += f(x, y, z) + data + t, w = (CYCLIC_LEFT_SHIFT(w, s)) & 0xffffffff, w += x ) 146 - 147 - 148 - /* 149 - * Function Description: 150 - * Initiate MD5 Context satisfied in RFC 1321 151 - * 152 - * Arguments: 153 - * pCtx Pointer to MD5 context 154 - * 155 - * Return Value: 156 - * None 157 - */ 158 - VOID MD5Init(MD5_CTX *pCtx) 159 - { 160 - pCtx->Buf[0]=0x67452301; 161 - pCtx->Buf[1]=0xefcdab89; 162 - pCtx->Buf[2]=0x98badcfe; 163 - pCtx->Buf[3]=0x10325476; 164 - 165 - pCtx->LenInBitCount[0]=0; 166 - pCtx->LenInBitCount[1]=0; 167 - } 168 - 169 - 170 - /* 171 - * Function Description: 172 - * Update MD5 Context, allow of an arrary of octets as the next portion 173 - * of the message 174 - * 175 - * Arguments: 176 - * pCtx Pointer to MD5 context 177 - * pData Pointer to input data 178 - * LenInBytes The length of input data (unit: byte) 179 - * 180 - * Return Value: 181 - * None 182 - * 183 - * Note: 184 - * Called after MD5Init or MD5Update(itself) 185 - */ 186 - VOID MD5Update(MD5_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes) 187 - { 188 - 189 - UINT32 TfTimes; 190 - UINT32 temp; 191 - unsigned int i; 192 - 193 - temp = pCtx->LenInBitCount[0]; 194 - 195 - pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3)); 196 - 197 - if (pCtx->LenInBitCount[0] < temp) 198 - pCtx->LenInBitCount[1]++; //carry in 199 - 200 - pCtx->LenInBitCount[1] += LenInBytes >> 29; 201 - 202 - // mod 64 bytes 203 - temp = (temp >> 3) & 0x3f; 204 - 205 - // process lacks of 64-byte data 206 - if (temp) 207 - { 208 - UCHAR *pAds = (UCHAR *) pCtx->Input + temp; 209 - 210 - if ((temp+LenInBytes) < 64) 211 - { 212 - NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes); 213 - return; 214 - } 215 - 216 - NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp); 217 - byteReverse(pCtx->Input, 16); 218 - MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input); 219 - 220 - pData += 64-temp; 221 - LenInBytes -= 64-temp; 222 - } // end of if (temp) 223 - 224 - 225 - TfTimes = (LenInBytes >> 6); 226 - 227 - for (i=TfTimes; i>0; i--) 228 - { 229 - NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64); 230 - byteReverse(pCtx->Input, 16); 231 - MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input); 232 - pData += 64; 233 - LenInBytes -= 64; 234 - } // end of for 235 - 236 - // buffering lacks of 64-byte data 237 - if(LenInBytes) 238 - NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes); 239 - 240 - } 241 - 242 - 243 - /* 244 - * Function Description: 245 - * Append padding bits and length of original message in the tail 246 - * The message digest has to be completed in the end 247 - * 248 - * Arguments: 249 - * Digest Output of Digest-Message for MD5 250 - * pCtx Pointer to MD5 context 251 - * 252 - * Return Value: 253 - * None 254 - * 255 - * Note: 256 - * Called after MD5Update 257 - */ 258 - VOID MD5Final(UCHAR Digest[16], MD5_CTX *pCtx) 259 - { 260 - UCHAR Remainder; 261 - UCHAR PadLenInBytes; 262 - UCHAR *pAppend=0; 263 - unsigned int i; 264 - 265 - Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f); 266 - 267 - PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder); 268 - 269 - pAppend = (UCHAR *)pCtx->Input + Remainder; 270 - 271 - // padding bits without crossing block(64-byte based) boundary 272 - if (Remainder < 56) 273 - { 274 - *pAppend = 0x80; 275 - PadLenInBytes --; 276 - 277 - NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes); 278 - 279 - // add data-length field, from low to high 280 - for (i=0; i<4; i++) 281 - { 282 - pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff); 283 - pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff); 284 - } 285 - 286 - byteReverse(pCtx->Input, 16); 287 - MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input); 288 - } // end of if 289 - 290 - // padding bits with crossing block(64-byte based) boundary 291 - else 292 - { 293 - // the first block === 294 - *pAppend = 0x80; 295 - PadLenInBytes --; 296 - 297 - NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1)); 298 - PadLenInBytes -= (64 - Remainder - 1); 299 - 300 - byteReverse(pCtx->Input, 16); 301 - MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input); 302 - 303 - 304 - // the second block === 305 - NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes); 306 - 307 - // add data-length field 308 - for (i=0; i<4; i++) 309 - { 310 - pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[0] >> (i << 3)) & 0xff); 311 - pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[1] >> (i << 3)) & 0xff); 312 - } 313 - 314 - byteReverse(pCtx->Input, 16); 315 - MD5Transform(pCtx->Buf, (UINT32 *)pCtx->Input); 316 - } // end of else 317 - 318 - 319 - NdisMoveMemory((UCHAR *)Digest, (UINT32 *)pCtx->Buf, 16); // output 320 - byteReverse((UCHAR *)Digest, 4); 321 - NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free 322 - } 323 - 324 - 325 - /* 326 - * Function Description: 327 - * The central algorithm of MD5, consists of four rounds and sixteen 328 - * steps per round 329 - * 330 - * Arguments: 331 - * Buf Buffers of four states (output: 16 bytes) 332 - * Mes Input data (input: 64 bytes) 333 - * 334 - * Return Value: 335 - * None 336 - * 337 - * Note: 338 - * Called by MD5Update or MD5Final 339 - */ 340 - VOID MD5Transform(UINT32 Buf[4], UINT32 Mes[16]) 341 - { 342 - UINT32 Reg[4], Temp; 343 - unsigned int i; 344 - 345 - static UCHAR LShiftVal[16] = 346 - { 347 - 7, 12, 17, 22, 348 - 5, 9 , 14, 20, 349 - 4, 11, 16, 23, 350 - 6, 10, 15, 21, 351 - }; 352 - 353 - 354 - // [equal to 4294967296*abs(sin(index))] 355 - static UINT32 MD5Table[64] = 356 - { 357 - 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 358 - 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 359 - 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 360 - 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 361 - 362 - 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 363 - 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 364 - 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 365 - 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 366 - 367 - 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 368 - 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 369 - 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 370 - 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 371 - 372 - 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 373 - 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 374 - 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 375 - 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 376 - }; 377 - 378 - 379 - for (i=0; i<4; i++) 380 - Reg[i]=Buf[i]; 381 - 382 - 383 - // 64 steps in MD5 algorithm 384 - for (i=0; i<16; i++) 385 - { 386 - MD5Step(MD5_F1, Reg[0], Reg[1], Reg[2], Reg[3], Mes[i], 387 - MD5Table[i], LShiftVal[i & 0x3]); 388 - 389 - // one-word right shift 390 - Temp = Reg[3]; 391 - Reg[3] = Reg[2]; 392 - Reg[2] = Reg[1]; 393 - Reg[1] = Reg[0]; 394 - Reg[0] = Temp; 395 - } 396 - for (i=16; i<32; i++) 397 - { 398 - MD5Step(MD5_F2, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(5*(i & 0xf)+1) & 0xf], 399 - MD5Table[i], LShiftVal[(0x1 << 2)+(i & 0x3)]); 400 - 401 - // one-word right shift 402 - Temp = Reg[3]; 403 - Reg[3] = Reg[2]; 404 - Reg[2] = Reg[1]; 405 - Reg[1] = Reg[0]; 406 - Reg[0] = Temp; 407 - } 408 - for (i=32; i<48; i++) 409 - { 410 - MD5Step(MD5_F3, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(3*(i & 0xf)+5) & 0xf], 411 - MD5Table[i], LShiftVal[(0x1 << 3)+(i & 0x3)]); 412 - 413 - // one-word right shift 414 - Temp = Reg[3]; 415 - Reg[3] = Reg[2]; 416 - Reg[2] = Reg[1]; 417 - Reg[1] = Reg[0]; 418 - Reg[0] = Temp; 419 - } 420 - for (i=48; i<64; i++) 421 - { 422 - MD5Step(MD5_F4, Reg[0], Reg[1], Reg[2], Reg[3], Mes[(7*(i & 0xf)) & 0xf], 423 - MD5Table[i], LShiftVal[(0x3 << 2)+(i & 0x3)]); 424 - 425 - // one-word right shift 426 - Temp = Reg[3]; 427 - Reg[3] = Reg[2]; 428 - Reg[2] = Reg[1]; 429 - Reg[1] = Reg[0]; 430 - Reg[0] = Temp; 431 - } 432 - 433 - 434 - // (temporary)output 435 - for (i=0; i<4; i++) 436 - Buf[i] += Reg[i]; 437 - 438 - } 439 - 440 - 441 - 442 - /* ========================= SHA-1 implementation ========================== */ 443 - // four base functions for SHA-1 444 - #define SHA1_F1(b, c, d) (((b) & (c)) | ((~b) & (d))) 445 - #define SHA1_F2(b, c, d) ((b) ^ (c) ^ (d)) 446 - #define SHA1_F3(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) 447 - 448 - 449 - #define SHA1Step(f, a, b, c, d, e, w, k) \ 450 - ( e += ( f(b, c, d) + w + k + CYCLIC_LEFT_SHIFT(a, 5)) & 0xffffffff, \ 451 - b = CYCLIC_LEFT_SHIFT(b, 30) ) 452 - 453 - //Initiate SHA-1 Context satisfied in RFC 3174 454 - VOID SHAInit(SHA_CTX *pCtx) 455 - { 456 - pCtx->Buf[0]=0x67452301; 457 - pCtx->Buf[1]=0xefcdab89; 458 - pCtx->Buf[2]=0x98badcfe; 459 - pCtx->Buf[3]=0x10325476; 460 - pCtx->Buf[4]=0xc3d2e1f0; 461 - 462 - pCtx->LenInBitCount[0]=0; 463 - pCtx->LenInBitCount[1]=0; 464 - } 465 - 466 - /* 467 - * Function Description: 468 - * Update SHA-1 Context, allow of an arrary of octets as the next 469 - * portion of the message 470 - * 471 - * Arguments: 472 - * pCtx Pointer to SHA-1 context 473 - * pData Pointer to input data 474 - * LenInBytes The length of input data (unit: byte) 475 - * 476 - * Return Value: 477 - * error indicate more than pow(2,64) bits of data 478 - * 479 - * Note: 480 - * Called after SHAInit or SHAUpdate(itself) 481 - */ 482 - UCHAR SHAUpdate(SHA_CTX *pCtx, UCHAR *pData, UINT32 LenInBytes) 483 - { 484 - UINT32 TfTimes; 485 - UINT32 temp1,temp2; 486 - unsigned int i; 487 - UCHAR err=1; 488 - 489 - temp1 = pCtx->LenInBitCount[0]; 490 - temp2 = pCtx->LenInBitCount[1]; 491 - 492 - pCtx->LenInBitCount[0] = (UINT32) (pCtx->LenInBitCount[0] + (LenInBytes << 3)); 493 - if (pCtx->LenInBitCount[0] < temp1) 494 - pCtx->LenInBitCount[1]++; //carry in 495 - 496 - 497 - pCtx->LenInBitCount[1] = (UINT32) (pCtx->LenInBitCount[1] +(LenInBytes >> 29)); 498 - if (pCtx->LenInBitCount[1] < temp2) 499 - return (err); //check total length of original data 500 - 501 - 502 - // mod 64 bytes 503 - temp1 = (temp1 >> 3) & 0x3f; 504 - 505 - // process lacks of 64-byte data 506 - if (temp1) 507 - { 508 - UCHAR *pAds = (UCHAR *) pCtx->Input + temp1; 509 - 510 - if ((temp1+LenInBytes) < 64) 511 - { 512 - NdisMoveMemory(pAds, (UCHAR *)pData, LenInBytes); 513 - return (0); 514 - } 515 - 516 - NdisMoveMemory(pAds, (UCHAR *)pData, 64-temp1); 517 - byteReverse((UCHAR *)pCtx->Input, 16); 518 - 519 - NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16); 520 - SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input); 521 - 522 - pData += 64-temp1; 523 - LenInBytes -= 64-temp1; 524 - } // end of if (temp1) 525 - 526 - 527 - TfTimes = (LenInBytes >> 6); 528 - 529 - for (i=TfTimes; i>0; i--) 530 - { 531 - NdisMoveMemory(pCtx->Input, (UCHAR *)pData, 64); 532 - byteReverse((UCHAR *)pCtx->Input, 16); 533 - 534 - NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16); 535 - SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input); 536 - pData += 64; 537 - LenInBytes -= 64; 538 - } // end of for 539 - 540 - // buffering lacks of 64-byte data 541 - if(LenInBytes) 542 - NdisMoveMemory(pCtx->Input, (UCHAR *)pData, LenInBytes); 543 - 544 - return (0); 545 - 546 - } 547 - 548 - // Append padding bits and length of original message in the tail 549 - // The message digest has to be completed in the end 550 - VOID SHAFinal(SHA_CTX *pCtx, UCHAR Digest[20]) 551 - { 552 - UCHAR Remainder; 553 - UCHAR PadLenInBytes; 554 - UCHAR *pAppend=0; 555 - unsigned int i; 556 - 557 - Remainder = (UCHAR)((pCtx->LenInBitCount[0] >> 3) & 0x3f); 558 - 559 - pAppend = (UCHAR *)pCtx->Input + Remainder; 560 - 561 - PadLenInBytes = (Remainder < 56) ? (56-Remainder) : (120-Remainder); 562 - 563 - // padding bits without crossing block(64-byte based) boundary 564 - if (Remainder < 56) 565 - { 566 - *pAppend = 0x80; 567 - PadLenInBytes --; 568 - 569 - NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, PadLenInBytes); 570 - 571 - // add data-length field, from high to low 572 - for (i=0; i<4; i++) 573 - { 574 - pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff); 575 - pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff); 576 - } 577 - 578 - byteReverse((UCHAR *)pCtx->Input, 16); 579 - NdisZeroMemory((UCHAR *)pCtx->Input + 64, 14); 580 - SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input); 581 - } // end of if 582 - 583 - // padding bits with crossing block(64-byte based) boundary 584 - else 585 - { 586 - // the first block === 587 - *pAppend = 0x80; 588 - PadLenInBytes --; 589 - 590 - NdisZeroMemory((UCHAR *)pCtx->Input + Remainder+1, (64-Remainder-1)); 591 - PadLenInBytes -= (64 - Remainder - 1); 592 - 593 - byteReverse((UCHAR *)pCtx->Input, 16); 594 - NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16); 595 - SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input); 596 - 597 - 598 - // the second block === 599 - NdisZeroMemory((UCHAR *)pCtx->Input, PadLenInBytes); 600 - 601 - // add data-length field 602 - for (i=0; i<4; i++) 603 - { 604 - pCtx->Input[56+i] = (UCHAR)((pCtx->LenInBitCount[1] >> ((3-i) << 3)) & 0xff); 605 - pCtx->Input[60+i] = (UCHAR)((pCtx->LenInBitCount[0] >> ((3-i) << 3)) & 0xff); 606 - } 607 - 608 - byteReverse((UCHAR *)pCtx->Input, 16); 609 - NdisZeroMemory((UCHAR *)pCtx->Input + 64, 16); 610 - SHATransform(pCtx->Buf, (UINT32 *)pCtx->Input); 611 - } // end of else 612 - 613 - 614 - //Output, bytereverse 615 - for (i=0; i<20; i++) 616 - { 617 - Digest [i] = (UCHAR)(pCtx->Buf[i>>2] >> 8*(3-(i & 0x3))); 618 - } 619 - 620 - NdisZeroMemory(pCtx, sizeof(pCtx)); // memory free 621 - } 622 - 623 - 624 - // The central algorithm of SHA-1, consists of four rounds and 625 - // twenty steps per round 626 - VOID SHATransform(UINT32 Buf[5], UINT32 Mes[20]) 627 - { 628 - UINT32 Reg[5],Temp; 629 - unsigned int i; 630 - UINT32 W[80]; 631 - 632 - static UINT32 SHA1Table[4] = { 0x5a827999, 0x6ed9eba1, 633 - 0x8f1bbcdc, 0xca62c1d6 }; 634 - 635 - Reg[0]=Buf[0]; 636 - Reg[1]=Buf[1]; 637 - Reg[2]=Buf[2]; 638 - Reg[3]=Buf[3]; 639 - Reg[4]=Buf[4]; 640 - 641 - //the first octet of a word is stored in the 0th element, bytereverse 642 - for(i = 0; i < 16; i++) 643 - { 644 - W[i] = (Mes[i] >> 24) & 0xff; 645 - W[i] |= (Mes[i] >> 8 ) & 0xff00; 646 - W[i] |= (Mes[i] << 8 ) & 0xff0000; 647 - W[i] |= (Mes[i] << 24) & 0xff000000; 648 - } 649 - 650 - 651 - for (i = 0; i < 64; i++) 652 - W[16+i] = CYCLIC_LEFT_SHIFT(W[i] ^ W[2+i] ^ W[8+i] ^ W[13+i], 1); 653 - 654 - 655 - // 80 steps in SHA-1 algorithm 656 - for (i=0; i<80; i++) 657 - { 658 - if (i<20) 659 - SHA1Step(SHA1_F1, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4], 660 - W[i], SHA1Table[0]); 661 - 662 - else if (i>=20 && i<40) 663 - SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4], 664 - W[i], SHA1Table[1]); 665 - 666 - else if (i>=40 && i<60) 667 - SHA1Step(SHA1_F3, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4], 668 - W[i], SHA1Table[2]); 669 - 670 - else 671 - SHA1Step(SHA1_F2, Reg[0], Reg[1], Reg[2], Reg[3], Reg[4], 672 - W[i], SHA1Table[3]); 673 - 674 - 675 - // one-word right shift 676 - Temp = Reg[4]; 677 - Reg[4] = Reg[3]; 678 - Reg[3] = Reg[2]; 679 - Reg[2] = Reg[1]; 680 - Reg[1] = Reg[0]; 681 - Reg[0] = Temp; 682 - 683 - } // end of for-loop 684 - 685 - 686 - // (temporary)output 687 - for (i=0; i<5; i++) 688 - Buf[i] += Reg[i]; 689 - 690 - } 691 - 692 - 693 - /* ========================= AES En/Decryption ========================== */ 694 - 695 - /* forward S-box */ 696 - static uint32 FSb[256] = 697 - { 698 - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 699 - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 700 - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 701 - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 702 - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 703 - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 704 - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 705 - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 706 - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 707 - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 708 - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 709 - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, 710 - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 711 - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 712 - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 713 - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 714 - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 715 - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, 716 - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 717 - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 718 - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 719 - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 720 - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 721 - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, 722 - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 723 - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 724 - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 725 - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 726 - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 727 - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 728 - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 729 - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 730 - }; 731 - 732 - /* forward table */ 733 - #define FT \ 734 - \ 735 - V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \ 736 - V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \ 737 - V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \ 738 - V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \ 739 - V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \ 740 - V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \ 741 - V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \ 742 - V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \ 743 - V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \ 744 - V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \ 745 - V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \ 746 - V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \ 747 - V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \ 748 - V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \ 749 - V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \ 750 - V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \ 751 - V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \ 752 - V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \ 753 - V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \ 754 - V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \ 755 - V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \ 756 - V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \ 757 - V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \ 758 - V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \ 759 - V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \ 760 - V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \ 761 - V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \ 762 - V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \ 763 - V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \ 764 - V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \ 765 - V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \ 766 - V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \ 767 - V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \ 768 - V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \ 769 - V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \ 770 - V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \ 771 - V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \ 772 - V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \ 773 - V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \ 774 - V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \ 775 - V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \ 776 - V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \ 777 - V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \ 778 - V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \ 779 - V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \ 780 - V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \ 781 - V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \ 782 - V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \ 783 - V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \ 784 - V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \ 785 - V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \ 786 - V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \ 787 - V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \ 788 - V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \ 789 - V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \ 790 - V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \ 791 - V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \ 792 - V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \ 793 - V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \ 794 - V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \ 795 - V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \ 796 - V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \ 797 - V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \ 798 - V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A) 799 - 800 - #define V(a,b,c,d) 0x##a##b##c##d 801 - static uint32 FT0[256] = { FT }; 802 - #undef V 803 - 804 - #define V(a,b,c,d) 0x##d##a##b##c 805 - static uint32 FT1[256] = { FT }; 806 - #undef V 807 - 808 - #define V(a,b,c,d) 0x##c##d##a##b 809 - static uint32 FT2[256] = { FT }; 810 - #undef V 811 - 812 - #define V(a,b,c,d) 0x##b##c##d##a 813 - static uint32 FT3[256] = { FT }; 814 - #undef V 815 - 816 - #undef FT 817 - 818 - /* reverse S-box */ 819 - 820 - static uint32 RSb[256] = 821 - { 822 - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 823 - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 824 - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 825 - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 826 - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 827 - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, 828 - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 829 - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, 830 - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 831 - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 832 - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 833 - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, 834 - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 835 - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, 836 - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 837 - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 838 - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 839 - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, 840 - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 841 - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, 842 - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 843 - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 844 - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 845 - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, 846 - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 847 - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, 848 - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 849 - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 850 - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 851 - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, 852 - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 853 - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D 854 - }; 855 - 856 - /* reverse table */ 857 - 858 - #define RT \ 859 - \ 860 - V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \ 861 - V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \ 862 - V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \ 863 - V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \ 864 - V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \ 865 - V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \ 866 - V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \ 867 - V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \ 868 - V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \ 869 - V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \ 870 - V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \ 871 - V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \ 872 - V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \ 873 - V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \ 874 - V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \ 875 - V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \ 876 - V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \ 877 - V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \ 878 - V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \ 879 - V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \ 880 - V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \ 881 - V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \ 882 - V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \ 883 - V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \ 884 - V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \ 885 - V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \ 886 - V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \ 887 - V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \ 888 - V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \ 889 - V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \ 890 - V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \ 891 - V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \ 892 - V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \ 893 - V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \ 894 - V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \ 895 - V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \ 896 - V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \ 897 - V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \ 898 - V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \ 899 - V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \ 900 - V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \ 901 - V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \ 902 - V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \ 903 - V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \ 904 - V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \ 905 - V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \ 906 - V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \ 907 - V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \ 908 - V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \ 909 - V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \ 910 - V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \ 911 - V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \ 912 - V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \ 913 - V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \ 914 - V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \ 915 - V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \ 916 - V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \ 917 - V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \ 918 - V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \ 919 - V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \ 920 - V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \ 921 - V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \ 922 - V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \ 923 - V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42) 924 - 925 - #define V(a,b,c,d) 0x##a##b##c##d 926 - static uint32 RT0[256] = { RT }; 927 - #undef V 928 - 929 - #define V(a,b,c,d) 0x##d##a##b##c 930 - static uint32 RT1[256] = { RT }; 931 - #undef V 932 - 933 - #define V(a,b,c,d) 0x##c##d##a##b 934 - static uint32 RT2[256] = { RT }; 935 - #undef V 936 - 937 - #define V(a,b,c,d) 0x##b##c##d##a 938 - static uint32 RT3[256] = { RT }; 939 - #undef V 940 - 941 - #undef RT 942 - 943 - /* round constants */ 944 - 945 - static uint32 RCON[10] = 946 - { 947 - 0x01000000, 0x02000000, 0x04000000, 0x08000000, 948 - 0x10000000, 0x20000000, 0x40000000, 0x80000000, 949 - 0x1B000000, 0x36000000 950 - }; 951 - 952 - /* key schedule tables */ 953 - 954 - static int KT_init = 1; 955 - 956 - static uint32 KT0[256]; 957 - static uint32 KT1[256]; 958 - static uint32 KT2[256]; 959 - static uint32 KT3[256]; 960 - 961 - /* platform-independant 32-bit integer manipulation macros */ 962 - 963 - #define GET_UINT32(n,b,i) \ 964 - { \ 965 - (n) = ( (uint32) (b)[(i) ] << 24 ) \ 966 - | ( (uint32) (b)[(i) + 1] << 16 ) \ 967 - | ( (uint32) (b)[(i) + 2] << 8 ) \ 968 - | ( (uint32) (b)[(i) + 3] ); \ 969 - } 970 - 971 - #define PUT_UINT32(n,b,i) \ 972 - { \ 973 - (b)[(i) ] = (uint8) ( (n) >> 24 ); \ 974 - (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ 975 - (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \ 976 - (b)[(i) + 3] = (uint8) ( (n) ); \ 977 - } 978 - 979 - /* AES key scheduling routine */ 980 - 981 - int rtmp_aes_set_key( aes_context *ctx, uint8 *key, int nbits ) 982 - { 983 - int i; 984 - uint32 *RK, *SK; 985 - 986 - switch( nbits ) 987 - { 988 - case 128: ctx->nr = 10; break; 989 - case 192: ctx->nr = 12; break; 990 - case 256: ctx->nr = 14; break; 991 - default : return( 1 ); 992 - } 993 - 994 - RK = ctx->erk; 995 - 996 - for( i = 0; i < (nbits >> 5); i++ ) 997 - { 998 - GET_UINT32( RK[i], key, i * 4 ); 999 - } 1000 - 1001 - /* setup encryption round keys */ 1002 - 1003 - switch( nbits ) 1004 - { 1005 - case 128: 1006 - 1007 - for( i = 0; i < 10; i++, RK += 4 ) 1008 - { 1009 - RK[4] = RK[0] ^ RCON[i] ^ 1010 - ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^ 1011 - ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^ 1012 - ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^ 1013 - ( FSb[ (uint8) ( RK[3] >> 24 ) ] ); 1014 - 1015 - RK[5] = RK[1] ^ RK[4]; 1016 - RK[6] = RK[2] ^ RK[5]; 1017 - RK[7] = RK[3] ^ RK[6]; 1018 - } 1019 - break; 1020 - 1021 - case 192: 1022 - 1023 - for( i = 0; i < 8; i++, RK += 6 ) 1024 - { 1025 - RK[6] = RK[0] ^ RCON[i] ^ 1026 - ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^ 1027 - ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^ 1028 - ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^ 1029 - ( FSb[ (uint8) ( RK[5] >> 24 ) ] ); 1030 - 1031 - RK[7] = RK[1] ^ RK[6]; 1032 - RK[8] = RK[2] ^ RK[7]; 1033 - RK[9] = RK[3] ^ RK[8]; 1034 - RK[10] = RK[4] ^ RK[9]; 1035 - RK[11] = RK[5] ^ RK[10]; 1036 - } 1037 - break; 1038 - 1039 - case 256: 1040 - 1041 - for( i = 0; i < 7; i++, RK += 8 ) 1042 - { 1043 - RK[8] = RK[0] ^ RCON[i] ^ 1044 - ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^ 1045 - ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^ 1046 - ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^ 1047 - ( FSb[ (uint8) ( RK[7] >> 24 ) ] ); 1048 - 1049 - RK[9] = RK[1] ^ RK[8]; 1050 - RK[10] = RK[2] ^ RK[9]; 1051 - RK[11] = RK[3] ^ RK[10]; 1052 - 1053 - RK[12] = RK[4] ^ 1054 - ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^ 1055 - ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^ 1056 - ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^ 1057 - ( FSb[ (uint8) ( RK[11] ) ] ); 1058 - 1059 - RK[13] = RK[5] ^ RK[12]; 1060 - RK[14] = RK[6] ^ RK[13]; 1061 - RK[15] = RK[7] ^ RK[14]; 1062 - } 1063 - break; 1064 - } 1065 - 1066 - /* setup decryption round keys */ 1067 - 1068 - if( KT_init ) 1069 - { 1070 - for( i = 0; i < 256; i++ ) 1071 - { 1072 - KT0[i] = RT0[ FSb[i] ]; 1073 - KT1[i] = RT1[ FSb[i] ]; 1074 - KT2[i] = RT2[ FSb[i] ]; 1075 - KT3[i] = RT3[ FSb[i] ]; 1076 - } 1077 - 1078 - KT_init = 0; 1079 - } 1080 - 1081 - SK = ctx->drk; 1082 - 1083 - *SK++ = *RK++; 1084 - *SK++ = *RK++; 1085 - *SK++ = *RK++; 1086 - *SK++ = *RK++; 1087 - 1088 - for( i = 1; i < ctx->nr; i++ ) 1089 - { 1090 - RK -= 8; 1091 - 1092 - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ 1093 - KT1[ (uint8) ( *RK >> 16 ) ] ^ 1094 - KT2[ (uint8) ( *RK >> 8 ) ] ^ 1095 - KT3[ (uint8) ( *RK ) ]; RK++; 1096 - 1097 - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ 1098 - KT1[ (uint8) ( *RK >> 16 ) ] ^ 1099 - KT2[ (uint8) ( *RK >> 8 ) ] ^ 1100 - KT3[ (uint8) ( *RK ) ]; RK++; 1101 - 1102 - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ 1103 - KT1[ (uint8) ( *RK >> 16 ) ] ^ 1104 - KT2[ (uint8) ( *RK >> 8 ) ] ^ 1105 - KT3[ (uint8) ( *RK ) ]; RK++; 1106 - 1107 - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ 1108 - KT1[ (uint8) ( *RK >> 16 ) ] ^ 1109 - KT2[ (uint8) ( *RK >> 8 ) ] ^ 1110 - KT3[ (uint8) ( *RK ) ]; RK++; 1111 - } 1112 - 1113 - RK -= 8; 1114 - 1115 - *SK++ = *RK++; 1116 - *SK++ = *RK++; 1117 - *SK++ = *RK++; 1118 - *SK++ = *RK++; 1119 - 1120 - return( 0 ); 1121 - } 1122 - 1123 - /* AES 128-bit block encryption routine */ 1124 - 1125 - void rtmp_aes_encrypt(aes_context *ctx, uint8 input[16], uint8 output[16] ) 1126 - { 1127 - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; 1128 - 1129 - RK = ctx->erk; 1130 - GET_UINT32( X0, input, 0 ); X0 ^= RK[0]; 1131 - GET_UINT32( X1, input, 4 ); X1 ^= RK[1]; 1132 - GET_UINT32( X2, input, 8 ); X2 ^= RK[2]; 1133 - GET_UINT32( X3, input, 12 ); X3 ^= RK[3]; 1134 - 1135 - #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ 1136 - { \ 1137 - RK += 4; \ 1138 - \ 1139 - X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \ 1140 - FT1[ (uint8) ( Y1 >> 16 ) ] ^ \ 1141 - FT2[ (uint8) ( Y2 >> 8 ) ] ^ \ 1142 - FT3[ (uint8) ( Y3 ) ]; \ 1143 - \ 1144 - X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \ 1145 - FT1[ (uint8) ( Y2 >> 16 ) ] ^ \ 1146 - FT2[ (uint8) ( Y3 >> 8 ) ] ^ \ 1147 - FT3[ (uint8) ( Y0 ) ]; \ 1148 - \ 1149 - X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \ 1150 - FT1[ (uint8) ( Y3 >> 16 ) ] ^ \ 1151 - FT2[ (uint8) ( Y0 >> 8 ) ] ^ \ 1152 - FT3[ (uint8) ( Y1 ) ]; \ 1153 - \ 1154 - X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \ 1155 - FT1[ (uint8) ( Y0 >> 16 ) ] ^ \ 1156 - FT2[ (uint8) ( Y1 >> 8 ) ] ^ \ 1157 - FT3[ (uint8) ( Y2 ) ]; \ 1158 - } 1159 - 1160 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */ 1161 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */ 1162 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */ 1163 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */ 1164 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */ 1165 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */ 1166 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */ 1167 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */ 1168 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */ 1169 - 1170 - if( ctx->nr > 10 ) 1171 - { 1172 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */ 1173 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */ 1174 - } 1175 - 1176 - if( ctx->nr > 12 ) 1177 - { 1178 - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */ 1179 - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */ 1180 - } 1181 - 1182 - /* last round */ 1183 - 1184 - RK += 4; 1185 - 1186 - X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ 1187 - ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ 1188 - ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ 1189 - ( FSb[ (uint8) ( Y3 ) ] ); 1190 - 1191 - X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ 1192 - ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ 1193 - ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ 1194 - ( FSb[ (uint8) ( Y0 ) ] ); 1195 - 1196 - X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ 1197 - ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ 1198 - ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ 1199 - ( FSb[ (uint8) ( Y1 ) ] ); 1200 - 1201 - X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ 1202 - ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ 1203 - ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ 1204 - ( FSb[ (uint8) ( Y2 ) ] ); 1205 - 1206 - PUT_UINT32( X0, output, 0 ); 1207 - PUT_UINT32( X1, output, 4 ); 1208 - PUT_UINT32( X2, output, 8 ); 1209 - PUT_UINT32( X3, output, 12 ); 1210 - } 1211 - 1212 - /* AES 128-bit block decryption routine */ 1213 - 1214 - void rtmp_aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] ) 1215 - { 1216 - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; 1217 - 1218 - RK = ctx->drk; 1219 - 1220 - GET_UINT32( X0, input, 0 ); X0 ^= RK[0]; 1221 - GET_UINT32( X1, input, 4 ); X1 ^= RK[1]; 1222 - GET_UINT32( X2, input, 8 ); X2 ^= RK[2]; 1223 - GET_UINT32( X3, input, 12 ); X3 ^= RK[3]; 1224 - 1225 - #define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ 1226 - { \ 1227 - RK += 4; \ 1228 - \ 1229 - X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \ 1230 - RT1[ (uint8) ( Y3 >> 16 ) ] ^ \ 1231 - RT2[ (uint8) ( Y2 >> 8 ) ] ^ \ 1232 - RT3[ (uint8) ( Y1 ) ]; \ 1233 - \ 1234 - X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \ 1235 - RT1[ (uint8) ( Y0 >> 16 ) ] ^ \ 1236 - RT2[ (uint8) ( Y3 >> 8 ) ] ^ \ 1237 - RT3[ (uint8) ( Y2 ) ]; \ 1238 - \ 1239 - X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \ 1240 - RT1[ (uint8) ( Y1 >> 16 ) ] ^ \ 1241 - RT2[ (uint8) ( Y0 >> 8 ) ] ^ \ 1242 - RT3[ (uint8) ( Y3 ) ]; \ 1243 - \ 1244 - X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \ 1245 - RT1[ (uint8) ( Y2 >> 16 ) ] ^ \ 1246 - RT2[ (uint8) ( Y1 >> 8 ) ] ^ \ 1247 - RT3[ (uint8) ( Y0 ) ]; \ 1248 - } 1249 - 1250 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */ 1251 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */ 1252 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */ 1253 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */ 1254 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */ 1255 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */ 1256 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */ 1257 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */ 1258 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */ 1259 - 1260 - if( ctx->nr > 10 ) 1261 - { 1262 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */ 1263 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */ 1264 - } 1265 - 1266 - if( ctx->nr > 12 ) 1267 - { 1268 - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */ 1269 - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */ 1270 - } 1271 - 1272 - /* last round */ 1273 - 1274 - RK += 4; 1275 - 1276 - X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ 1277 - ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ 1278 - ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ 1279 - ( RSb[ (uint8) ( Y1 ) ] ); 1280 - 1281 - X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ 1282 - ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ 1283 - ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ 1284 - ( RSb[ (uint8) ( Y2 ) ] ); 1285 - 1286 - X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ 1287 - ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ 1288 - ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ 1289 - ( RSb[ (uint8) ( Y3 ) ] ); 1290 - 1291 - X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ 1292 - ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ 1293 - ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ 1294 - ( RSb[ (uint8) ( Y0 ) ] ); 1295 - 1296 - PUT_UINT32( X0, output, 0 ); 1297 - PUT_UINT32( X1, output, 4 ); 1298 - PUT_UINT32( X2, output, 8 ); 1299 - PUT_UINT32( X3, output, 12 ); 1300 - } 1301 - 1302 - /* 1303 - ======================================================================== 1304 - 1305 - Routine Description: 1306 - SHA1 function 1307 - 1308 - Arguments: 1309 - 1310 - Return Value: 1311 - 1312 - Note: 1313 - 1314 - ======================================================================== 1315 - */ 1316 - VOID HMAC_SHA1( 1317 - IN UCHAR *text, 1318 - IN UINT text_len, 1319 - IN UCHAR *key, 1320 - IN UINT key_len, 1321 - IN UCHAR *digest) 1322 - { 1323 - SHA_CTX context; 1324 - UCHAR k_ipad[65]; /* inner padding - key XORd with ipad */ 1325 - UCHAR k_opad[65]; /* outer padding - key XORd with opad */ 1326 - INT i; 1327 - 1328 - // if key is longer than 64 bytes reset it to key=SHA1(key) 1329 - if (key_len > 64) 1330 - { 1331 - SHA_CTX tctx; 1332 - SHAInit(&tctx); 1333 - SHAUpdate(&tctx, key, key_len); 1334 - SHAFinal(&tctx, key); 1335 - key_len = 20; 1336 - } 1337 - NdisZeroMemory(k_ipad, sizeof(k_ipad)); 1338 - NdisZeroMemory(k_opad, sizeof(k_opad)); 1339 - NdisMoveMemory(k_ipad, key, key_len); 1340 - NdisMoveMemory(k_opad, key, key_len); 1341 - 1342 - // XOR key with ipad and opad values 1343 - for (i = 0; i < 64; i++) 1344 - { 1345 - k_ipad[i] ^= 0x36; 1346 - k_opad[i] ^= 0x5c; 1347 - } 1348 - 1349 - // perform inner SHA1 1350 - SHAInit(&context); /* init context for 1st pass */ 1351 - SHAUpdate(&context, k_ipad, 64); /* start with inner pad */ 1352 - SHAUpdate(&context, text, text_len); /* then text of datagram */ 1353 - SHAFinal(&context, digest); /* finish up 1st pass */ 1354 - 1355 - //perform outer SHA1 1356 - SHAInit(&context); /* init context for 2nd pass */ 1357 - SHAUpdate(&context, k_opad, 64); /* start with outer pad */ 1358 - SHAUpdate(&context, digest, 20); /* then results of 1st hash */ 1359 - SHAFinal(&context, digest); /* finish up 2nd pass */ 1360 - 1361 - } 1362 - 1363 - /* 1364 - * F(P, S, c, i) = U1 xor U2 xor ... Uc 1365 - * U1 = PRF(P, S || Int(i)) 1366 - * U2 = PRF(P, U1) 1367 - * Uc = PRF(P, Uc-1) 1368 - */ 1369 - 1370 - void F(char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output) 1371 - { 1372 - unsigned char digest[36], digest1[SHA_DIGEST_LEN]; 1373 - int i, j; 1374 - 1375 - /* U1 = PRF(P, S || int(i)) */ 1376 - memcpy(digest, ssid, ssidlength); 1377 - digest[ssidlength] = (unsigned char)((count>>24) & 0xff); 1378 - digest[ssidlength+1] = (unsigned char)((count>>16) & 0xff); 1379 - digest[ssidlength+2] = (unsigned char)((count>>8) & 0xff); 1380 - digest[ssidlength+3] = (unsigned char)(count & 0xff); 1381 - HMAC_SHA1(digest, ssidlength+4, (unsigned char*) password, (int) strlen(password), digest1); // for WPA update 1382 - 1383 - /* output = U1 */ 1384 - memcpy(output, digest1, SHA_DIGEST_LEN); 1385 - 1386 - for (i = 1; i < iterations; i++) 1387 - { 1388 - /* Un = PRF(P, Un-1) */ 1389 - HMAC_SHA1(digest1, SHA_DIGEST_LEN, (unsigned char*) password, (int) strlen(password), digest); // for WPA update 1390 - memcpy(digest1, digest, SHA_DIGEST_LEN); 1391 - 1392 - /* output = output xor Un */ 1393 - for (j = 0; j < SHA_DIGEST_LEN; j++) 1394 - { 1395 - output[j] ^= digest[j]; 1396 - } 1397 - } 1398 - } 1399 - /* 1400 - * password - ascii string up to 63 characters in length 1401 - * ssid - octet string up to 32 octets 1402 - * ssidlength - length of ssid in octets 1403 - * output must be 40 octets in length and outputs 256 bits of key 1404 - */ 1405 - int PasswordHash(char *password, unsigned char *ssid, int ssidlength, unsigned char *output) 1406 - { 1407 - if ((strlen(password) > 63) || (ssidlength > 32)) 1408 - return 0; 1409 - 1410 - F(password, ssid, ssidlength, 4096, 1, output); 1411 - F(password, ssid, ssidlength, 4096, 2, &output[SHA_DIGEST_LEN]); 1412 - return 1; 1413 - } 1414 - 1415 - 1 + #include "../../rt2860/common/md5.c"
+1 -8693
drivers/staging/rt2870/common/mlme.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - mlme.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - John Chang 2004-08-25 Modify from RT2500 code base 36 - John Chang 2004-09-06 modified for RT2600 37 - */ 38 - 39 - #include "../rt_config.h" 40 - #include <stdarg.h> 41 - 42 - UCHAR CISCO_OUI[] = {0x00, 0x40, 0x96}; 43 - 44 - UCHAR WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01}; 45 - UCHAR RSN_OUI[] = {0x00, 0x0f, 0xac}; 46 - UCHAR WAPI_OUI[] = {0x00, 0x14, 0x72}; 47 - UCHAR WME_INFO_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01}; 48 - UCHAR WME_PARM_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01}; 49 - UCHAR Ccx2QosInfo[] = {0x00, 0x40, 0x96, 0x04}; 50 - UCHAR RALINK_OUI[] = {0x00, 0x0c, 0x43}; 51 - UCHAR BROADCOM_OUI[] = {0x00, 0x90, 0x4c}; 52 - UCHAR WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04}; 53 - UCHAR PRE_N_HT_OUI[] = {0x00, 0x90, 0x4c}; 54 - 55 - UCHAR RateSwitchTable[] = { 56 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 57 - 0x11, 0x00, 0, 0, 0, // Initial used item after association 58 - 0x00, 0x00, 0, 40, 101, 59 - 0x01, 0x00, 1, 40, 50, 60 - 0x02, 0x00, 2, 35, 45, 61 - 0x03, 0x00, 3, 20, 45, 62 - 0x04, 0x21, 0, 30, 50, 63 - 0x05, 0x21, 1, 20, 50, 64 - 0x06, 0x21, 2, 20, 50, 65 - 0x07, 0x21, 3, 15, 50, 66 - 0x08, 0x21, 4, 15, 30, 67 - 0x09, 0x21, 5, 10, 25, 68 - 0x0a, 0x21, 6, 8, 25, 69 - 0x0b, 0x21, 7, 8, 25, 70 - 0x0c, 0x20, 12, 15, 30, 71 - 0x0d, 0x20, 13, 8, 20, 72 - 0x0e, 0x20, 14, 8, 20, 73 - 0x0f, 0x20, 15, 8, 25, 74 - 0x10, 0x22, 15, 8, 25, 75 - 0x11, 0x00, 0, 0, 0, 76 - 0x12, 0x00, 0, 0, 0, 77 - 0x13, 0x00, 0, 0, 0, 78 - 0x14, 0x00, 0, 0, 0, 79 - 0x15, 0x00, 0, 0, 0, 80 - 0x16, 0x00, 0, 0, 0, 81 - 0x17, 0x00, 0, 0, 0, 82 - 0x18, 0x00, 0, 0, 0, 83 - 0x19, 0x00, 0, 0, 0, 84 - 0x1a, 0x00, 0, 0, 0, 85 - 0x1b, 0x00, 0, 0, 0, 86 - 0x1c, 0x00, 0, 0, 0, 87 - 0x1d, 0x00, 0, 0, 0, 88 - 0x1e, 0x00, 0, 0, 0, 89 - 0x1f, 0x00, 0, 0, 0, 90 - }; 91 - 92 - UCHAR RateSwitchTable11B[] = { 93 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 94 - 0x04, 0x03, 0, 0, 0, // Initial used item after association 95 - 0x00, 0x00, 0, 40, 101, 96 - 0x01, 0x00, 1, 40, 50, 97 - 0x02, 0x00, 2, 35, 45, 98 - 0x03, 0x00, 3, 20, 45, 99 - }; 100 - 101 - UCHAR RateSwitchTable11BG[] = { 102 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 103 - 0x0a, 0x00, 0, 0, 0, // Initial used item after association 104 - 0x00, 0x00, 0, 40, 101, 105 - 0x01, 0x00, 1, 40, 50, 106 - 0x02, 0x00, 2, 35, 45, 107 - 0x03, 0x00, 3, 20, 45, 108 - 0x04, 0x10, 2, 20, 35, 109 - 0x05, 0x10, 3, 16, 35, 110 - 0x06, 0x10, 4, 10, 25, 111 - 0x07, 0x10, 5, 16, 25, 112 - 0x08, 0x10, 6, 10, 25, 113 - 0x09, 0x10, 7, 10, 13, 114 - }; 115 - 116 - UCHAR RateSwitchTable11G[] = { 117 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 118 - 0x08, 0x00, 0, 0, 0, // Initial used item after association 119 - 0x00, 0x10, 0, 20, 101, 120 - 0x01, 0x10, 1, 20, 35, 121 - 0x02, 0x10, 2, 20, 35, 122 - 0x03, 0x10, 3, 16, 35, 123 - 0x04, 0x10, 4, 10, 25, 124 - 0x05, 0x10, 5, 16, 25, 125 - 0x06, 0x10, 6, 10, 25, 126 - 0x07, 0x10, 7, 10, 13, 127 - }; 128 - 129 - UCHAR RateSwitchTable11N1S[] = { 130 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 131 - 0x09, 0x00, 0, 0, 0, // Initial used item after association 132 - 0x00, 0x21, 0, 30, 101, 133 - 0x01, 0x21, 1, 20, 50, 134 - 0x02, 0x21, 2, 20, 50, 135 - 0x03, 0x21, 3, 15, 50, 136 - 0x04, 0x21, 4, 15, 30, 137 - 0x05, 0x21, 5, 10, 25, 138 - 0x06, 0x21, 6, 8, 14, 139 - 0x07, 0x21, 7, 8, 14, 140 - 0x08, 0x23, 7, 8, 14, 141 - }; 142 - 143 - UCHAR RateSwitchTable11N2S[] = { 144 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 145 - 0x0a, 0x00, 0, 0, 0, // Initial used item after association 146 - 0x00, 0x21, 0, 30, 101, 147 - 0x01, 0x21, 1, 20, 50, 148 - 0x02, 0x21, 2, 20, 50, 149 - 0x03, 0x21, 3, 15, 50, 150 - 0x04, 0x21, 4, 15, 30, 151 - 0x05, 0x20, 12, 15, 30, 152 - 0x06, 0x20, 13, 8, 20, 153 - 0x07, 0x20, 14, 8, 20, 154 - 0x08, 0x20, 15, 8, 25, 155 - 0x09, 0x22, 15, 8, 25, 156 - }; 157 - 158 - UCHAR RateSwitchTable11N3S[] = { 159 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 160 - 0x0a, 0x00, 0, 0, 0, // Initial used item after association 161 - 0x00, 0x21, 0, 30, 101, 162 - 0x01, 0x21, 1, 20, 50, 163 - 0x02, 0x21, 2, 20, 50, 164 - 0x03, 0x21, 3, 15, 50, 165 - 0x04, 0x21, 4, 15, 30, 166 - 0x05, 0x20, 12, 15, 30, 167 - 0x06, 0x20, 13, 8, 20, 168 - 0x07, 0x20, 14, 8, 20, 169 - 0x08, 0x20, 15, 8, 25, 170 - 0x09, 0x22, 15, 8, 25, 171 - }; 172 - 173 - UCHAR RateSwitchTable11N2SForABand[] = { 174 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 175 - 0x0b, 0x09, 0, 0, 0, // Initial used item after association 176 - 0x00, 0x21, 0, 30, 101, 177 - 0x01, 0x21, 1, 20, 50, 178 - 0x02, 0x21, 2, 20, 50, 179 - 0x03, 0x21, 3, 15, 50, 180 - 0x04, 0x21, 4, 15, 30, 181 - 0x05, 0x21, 5, 15, 30, 182 - 0x06, 0x20, 12, 15, 30, 183 - 0x07, 0x20, 13, 8, 20, 184 - 0x08, 0x20, 14, 8, 20, 185 - 0x09, 0x20, 15, 8, 25, 186 - 0x0a, 0x22, 15, 8, 25, 187 - }; 188 - 189 - UCHAR RateSwitchTable11N3SForABand[] = { // 3*3 190 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 191 - 0x0b, 0x09, 0, 0, 0, // Initial used item after association 192 - 0x00, 0x21, 0, 30, 101, 193 - 0x01, 0x21, 1, 20, 50, 194 - 0x02, 0x21, 2, 20, 50, 195 - 0x03, 0x21, 3, 15, 50, 196 - 0x04, 0x21, 4, 15, 30, 197 - 0x05, 0x21, 5, 15, 30, 198 - 0x06, 0x20, 12, 15, 30, 199 - 0x07, 0x20, 13, 8, 20, 200 - 0x08, 0x20, 14, 8, 20, 201 - 0x09, 0x20, 15, 8, 25, 202 - 0x0a, 0x22, 15, 8, 25, 203 - }; 204 - 205 - UCHAR RateSwitchTable11BGN1S[] = { 206 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 207 - 0x0d, 0x00, 0, 0, 0, // Initial used item after association 208 - 0x00, 0x00, 0, 40, 101, 209 - 0x01, 0x00, 1, 40, 50, 210 - 0x02, 0x00, 2, 35, 45, 211 - 0x03, 0x00, 3, 20, 45, 212 - 0x04, 0x21, 0, 30,101, //50 213 - 0x05, 0x21, 1, 20, 50, 214 - 0x06, 0x21, 2, 20, 50, 215 - 0x07, 0x21, 3, 15, 50, 216 - 0x08, 0x21, 4, 15, 30, 217 - 0x09, 0x21, 5, 10, 25, 218 - 0x0a, 0x21, 6, 8, 14, 219 - 0x0b, 0x21, 7, 8, 14, 220 - 0x0c, 0x23, 7, 8, 14, 221 - }; 222 - 223 - UCHAR RateSwitchTable11BGN2S[] = { 224 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 225 - 0x0a, 0x00, 0, 0, 0, // Initial used item after association 226 - 0x00, 0x21, 0, 30,101, //50 227 - 0x01, 0x21, 1, 20, 50, 228 - 0x02, 0x21, 2, 20, 50, 229 - 0x03, 0x21, 3, 15, 50, 230 - 0x04, 0x21, 4, 15, 30, 231 - 0x05, 0x20, 12, 15, 30, 232 - 0x06, 0x20, 13, 8, 20, 233 - 0x07, 0x20, 14, 8, 20, 234 - 0x08, 0x20, 15, 8, 25, 235 - 0x09, 0x22, 15, 8, 25, 236 - }; 237 - 238 - UCHAR RateSwitchTable11BGN3S[] = { // 3*3 239 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 240 - 0x0a, 0x00, 0, 0, 0, // Initial used item after association 241 - 0x00, 0x21, 0, 30,101, //50 242 - 0x01, 0x21, 1, 20, 50, 243 - 0x02, 0x21, 2, 20, 50, 244 - 0x03, 0x21, 3, 20, 50, 245 - 0x04, 0x21, 4, 15, 50, 246 - 0x05, 0x20, 20, 15, 30, 247 - 0x06, 0x20, 21, 8, 20, 248 - 0x07, 0x20, 22, 8, 20, 249 - 0x08, 0x20, 23, 8, 25, 250 - 0x09, 0x22, 23, 8, 25, 251 - }; 252 - 253 - UCHAR RateSwitchTable11BGN2SForABand[] = { 254 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 255 - 0x0b, 0x09, 0, 0, 0, // Initial used item after association 256 - 0x00, 0x21, 0, 30,101, //50 257 - 0x01, 0x21, 1, 20, 50, 258 - 0x02, 0x21, 2, 20, 50, 259 - 0x03, 0x21, 3, 15, 50, 260 - 0x04, 0x21, 4, 15, 30, 261 - 0x05, 0x21, 5, 15, 30, 262 - 0x06, 0x20, 12, 15, 30, 263 - 0x07, 0x20, 13, 8, 20, 264 - 0x08, 0x20, 14, 8, 20, 265 - 0x09, 0x20, 15, 8, 25, 266 - 0x0a, 0x22, 15, 8, 25, 267 - }; 268 - 269 - UCHAR RateSwitchTable11BGN3SForABand[] = { // 3*3 270 - // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 271 - 0x0c, 0x09, 0, 0, 0, // Initial used item after association 272 - 0x00, 0x21, 0, 30,101, //50 273 - 0x01, 0x21, 1, 20, 50, 274 - 0x02, 0x21, 2, 20, 50, 275 - 0x03, 0x21, 3, 15, 50, 276 - 0x04, 0x21, 4, 15, 30, 277 - 0x05, 0x21, 5, 15, 30, 278 - 0x06, 0x21, 12, 15, 30, 279 - 0x07, 0x20, 20, 15, 30, 280 - 0x08, 0x20, 21, 8, 20, 281 - 0x09, 0x20, 22, 8, 20, 282 - 0x0a, 0x20, 23, 8, 25, 283 - 0x0b, 0x22, 23, 8, 25, 284 - }; 285 - 286 - PUCHAR ReasonString[] = { 287 - /* 0 */ "Reserved", 288 - /* 1 */ "Unspecified Reason", 289 - /* 2 */ "Previous Auth no longer valid", 290 - /* 3 */ "STA is leaving / has left", 291 - /* 4 */ "DIS-ASSOC due to inactivity", 292 - /* 5 */ "AP unable to hanle all associations", 293 - /* 6 */ "class 2 error", 294 - /* 7 */ "class 3 error", 295 - /* 8 */ "STA is leaving / has left", 296 - /* 9 */ "require auth before assoc/re-assoc", 297 - /* 10 */ "Reserved", 298 - /* 11 */ "Reserved", 299 - /* 12 */ "Reserved", 300 - /* 13 */ "invalid IE", 301 - /* 14 */ "MIC error", 302 - /* 15 */ "4-way handshake timeout", 303 - /* 16 */ "2-way (group key) handshake timeout", 304 - /* 17 */ "4-way handshake IE diff among AssosReq/Rsp/Beacon", 305 - /* 18 */ 306 - }; 307 - 308 - extern UCHAR OfdmRateToRxwiMCS[]; 309 - // since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate. 310 - // otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rate 311 - ULONG BasicRateMask[12] = {0xfffff001 /* 1-Mbps */, 0xfffff003 /* 2 Mbps */, 0xfffff007 /* 5.5 */, 0xfffff00f /* 11 */, 312 - 0xfffff01f /* 6 */ , 0xfffff03f /* 9 */ , 0xfffff07f /* 12 */ , 0xfffff0ff /* 18 */, 313 - 0xfffff1ff /* 24 */ , 0xfffff3ff /* 36 */ , 0xfffff7ff /* 48 */ , 0xffffffff /* 54 */}; 314 - 315 - UCHAR MULTICAST_ADDR[MAC_ADDR_LEN] = {0x1, 0x00, 0x00, 0x00, 0x00, 0x00}; 316 - UCHAR BROADCAST_ADDR[MAC_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 317 - UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 318 - 319 - // e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than 320 - // this value, then it's quaranteed capable of operating in 36 mbps TX rate in 321 - // clean environment. 322 - // TxRate: 1 2 5.5 11 6 9 12 18 24 36 48 54 72 100 323 - CHAR RssiSafeLevelForTxRate[] ={ -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 }; 324 - 325 - UCHAR RateIdToMbps[] = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100}; 326 - USHORT RateIdTo500Kbps[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200}; 327 - 328 - UCHAR SsidIe = IE_SSID; 329 - UCHAR SupRateIe = IE_SUPP_RATES; 330 - UCHAR ExtRateIe = IE_EXT_SUPP_RATES; 331 - UCHAR HtCapIe = IE_HT_CAP; 332 - UCHAR AddHtInfoIe = IE_ADD_HT; 333 - UCHAR NewExtChanIe = IE_SECONDARY_CH_OFFSET; 334 - UCHAR ErpIe = IE_ERP; 335 - UCHAR DsIe = IE_DS_PARM; 336 - UCHAR TimIe = IE_TIM; 337 - UCHAR WpaIe = IE_WPA; 338 - UCHAR Wpa2Ie = IE_WPA2; 339 - UCHAR IbssIe = IE_IBSS_PARM; 340 - UCHAR Ccx2Ie = IE_CCX_V2; 341 - UCHAR WapiIe = IE_WAPI; 342 - 343 - extern UCHAR WPA_OUI[]; 344 - 345 - UCHAR SES_OUI[] = {0x00, 0x90, 0x4c}; 346 - 347 - UCHAR ZeroSsid[32] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 348 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 349 - 350 - // Reset the RFIC setting to new series 351 - RTMP_RF_REGS RF2850RegTable[] = { 352 - // ch R1 R2 R3(TX0~4=0) R4 353 - {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b}, 354 - {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f}, 355 - {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b}, 356 - {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f}, 357 - {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b}, 358 - {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f}, 359 - {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b}, 360 - {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f}, 361 - {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b}, 362 - {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f}, 363 - {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b}, 364 - {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f}, 365 - {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b}, 366 - {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193}, 367 - 368 - // 802.11 UNI / HyperLan 2 369 - {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3}, 370 - {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193}, 371 - {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183}, 372 - {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3}, 373 - {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b}, 374 - {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b}, 375 - {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193}, 376 - {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3}, 377 - {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b}, 378 - {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183}, 379 - {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193}, 380 - {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}, // Plugfest#4, Day4, change RFR3 left4th 9->5. 381 - 382 - // 802.11 HyperLan 2 383 - {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783}, 384 - 385 - // 2008.04.30 modified 386 - // The system team has AN to improve the EVM value 387 - // for channel 102 to 108 for the RT2850/RT2750 dual band solution. 388 - {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793}, 389 - {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3}, 390 - {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193}, 391 - 392 - {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183}, 393 - {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b}, 394 - {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3}, 395 - {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193}, 396 - {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183}, 397 - {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193}, 398 - {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}, // 0x980ed1bb->0x980ed15b required by Rory 20070927 399 - {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3}, 400 - {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b}, 401 - {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193}, 402 - {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b}, 403 - {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183}, 404 - 405 - // 802.11 UNII 406 - {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7}, 407 - {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187}, 408 - {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f}, 409 - {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f}, 410 - {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7}, 411 - {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187}, 412 - {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197}, 413 - 414 - // Japan 415 - {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b}, 416 - {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13}, 417 - {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b}, 418 - {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23}, 419 - {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13}, 420 - {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b}, 421 - {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23}, 422 - 423 - // still lack of MMAC(Japan) ch 34,38,42,46 424 - }; 425 - UCHAR NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(RTMP_RF_REGS)); 426 - 427 - FREQUENCY_ITEM FreqItems3020[] = 428 - { 429 - /**************************************************/ 430 - // ISM : 2.4 to 2.483 GHz // 431 - /**************************************************/ 432 - // 11g 433 - /**************************************************/ 434 - //-CH---N-------R---K----------- 435 - {1, 241, 2, 2}, 436 - {2, 241, 2, 7}, 437 - {3, 242, 2, 2}, 438 - {4, 242, 2, 7}, 439 - {5, 243, 2, 2}, 440 - {6, 243, 2, 7}, 441 - {7, 244, 2, 2}, 442 - {8, 244, 2, 7}, 443 - {9, 245, 2, 2}, 444 - {10, 245, 2, 7}, 445 - {11, 246, 2, 2}, 446 - {12, 246, 2, 7}, 447 - {13, 247, 2, 2}, 448 - {14, 248, 2, 4}, 449 - }; 450 - #ifndef RT30xx 451 - #define NUM_OF_3020_CHNL (sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM)) 452 - #endif 453 - #ifdef RT30xx 454 - //2008/07/10:KH Modified to share this variable 455 - UCHAR NUM_OF_3020_CHNL=(sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM)); 456 - #endif 457 - 458 - /* 459 - ========================================================================== 460 - Description: 461 - initialize the MLME task and its data structure (queue, spinlock, 462 - timer, state machines). 463 - 464 - IRQL = PASSIVE_LEVEL 465 - 466 - Return: 467 - always return NDIS_STATUS_SUCCESS 468 - 469 - ========================================================================== 470 - */ 471 - NDIS_STATUS MlmeInit( 472 - IN PRTMP_ADAPTER pAd) 473 - { 474 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 475 - 476 - DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n")); 477 - 478 - do 479 - { 480 - Status = MlmeQueueInit(&pAd->Mlme.Queue); 481 - if(Status != NDIS_STATUS_SUCCESS) 482 - break; 483 - 484 - pAd->Mlme.bRunning = FALSE; 485 - NdisAllocateSpinLock(&pAd->Mlme.TaskLock); 486 - 487 - { 488 - BssTableInit(&pAd->ScanTab); 489 - 490 - // init STA state machines 491 - AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine, pAd->Mlme.AssocFunc); 492 - AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine, pAd->Mlme.AuthFunc); 493 - AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine, pAd->Mlme.AuthRspFunc); 494 - SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine, pAd->Mlme.SyncFunc); 495 - WpaPskStateMachineInit(pAd, &pAd->Mlme.WpaPskMachine, pAd->Mlme.WpaPskFunc); 496 - AironetStateMachineInit(pAd, &pAd->Mlme.AironetMachine, pAd->Mlme.AironetFunc); 497 - 498 - // Since we are using switch/case to implement it, the init is different from the above 499 - // state machine init 500 - MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL); 501 - } 502 - 503 - ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine, pAd->Mlme.ActFunc); 504 - 505 - // Init mlme periodic timer 506 - RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer, GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE); 507 - 508 - // Set mlme periodic timer 509 - RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV); 510 - 511 - // software-based RX Antenna diversity 512 - RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE); 513 - 514 - } while (FALSE); 515 - 516 - DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n")); 517 - 518 - return Status; 519 - } 520 - 521 - /* 522 - ========================================================================== 523 - Description: 524 - main loop of the MLME 525 - Pre: 526 - Mlme has to be initialized, and there are something inside the queue 527 - Note: 528 - This function is invoked from MPSetInformation and MPReceive; 529 - This task guarantee only one MlmeHandler will run. 530 - 531 - IRQL = DISPATCH_LEVEL 532 - 533 - ========================================================================== 534 - */ 535 - VOID MlmeHandler( 536 - IN PRTMP_ADAPTER pAd) 537 - { 538 - MLME_QUEUE_ELEM *Elem = NULL; 539 - 540 - // Only accept MLME and Frame from peer side, no other (control/data) frame should 541 - // get into this state machine 542 - 543 - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); 544 - if(pAd->Mlme.bRunning) 545 - { 546 - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); 547 - return; 548 - } 549 - else 550 - { 551 - pAd->Mlme.bRunning = TRUE; 552 - } 553 - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); 554 - 555 - while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) 556 - { 557 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) || 558 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) || 559 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) 560 - { 561 - DBGPRINT(RT_DEBUG_TRACE, ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n", pAd->Mlme.Queue.Num)); 562 - break; 563 - } 564 - 565 - //From message type, determine which state machine I should drive 566 - if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) 567 - { 568 - #ifdef RT2870 569 - if (Elem->MsgType == MT2_RESET_CONF) 570 - { 571 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! reset MLME state machine !!!\n")); 572 - MlmeRestartStateMachine(pAd); 573 - Elem->Occupied = FALSE; 574 - Elem->MsgLen = 0; 575 - continue; 576 - } 577 - #endif // RT2870 // 578 - 579 - // if dequeue success 580 - switch (Elem->Machine) 581 - { 582 - // STA state machines 583 - case ASSOC_STATE_MACHINE: 584 - StateMachinePerformAction(pAd, &pAd->Mlme.AssocMachine, Elem); 585 - break; 586 - case AUTH_STATE_MACHINE: 587 - StateMachinePerformAction(pAd, &pAd->Mlme.AuthMachine, Elem); 588 - break; 589 - case AUTH_RSP_STATE_MACHINE: 590 - StateMachinePerformAction(pAd, &pAd->Mlme.AuthRspMachine, Elem); 591 - break; 592 - case SYNC_STATE_MACHINE: 593 - StateMachinePerformAction(pAd, &pAd->Mlme.SyncMachine, Elem); 594 - break; 595 - case MLME_CNTL_STATE_MACHINE: 596 - MlmeCntlMachinePerformAction(pAd, &pAd->Mlme.CntlMachine, Elem); 597 - break; 598 - case WPA_PSK_STATE_MACHINE: 599 - StateMachinePerformAction(pAd, &pAd->Mlme.WpaPskMachine, Elem); 600 - break; 601 - case AIRONET_STATE_MACHINE: 602 - StateMachinePerformAction(pAd, &pAd->Mlme.AironetMachine, Elem); 603 - break; 604 - case ACTION_STATE_MACHINE: 605 - StateMachinePerformAction(pAd, &pAd->Mlme.ActMachine, Elem); 606 - break; 607 - 608 - 609 - 610 - 611 - default: 612 - DBGPRINT(RT_DEBUG_TRACE, ("ERROR: Illegal machine %ld in MlmeHandler()\n", Elem->Machine)); 613 - break; 614 - } // end of switch 615 - 616 - // free MLME element 617 - Elem->Occupied = FALSE; 618 - Elem->MsgLen = 0; 619 - 620 - } 621 - else { 622 - DBGPRINT_ERR(("MlmeHandler: MlmeQueue empty\n")); 623 - } 624 - } 625 - 626 - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); 627 - pAd->Mlme.bRunning = FALSE; 628 - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); 629 - } 630 - 631 - /* 632 - ========================================================================== 633 - Description: 634 - Destructor of MLME (Destroy queue, state machine, spin lock and timer) 635 - Parameters: 636 - Adapter - NIC Adapter pointer 637 - Post: 638 - The MLME task will no longer work properly 639 - 640 - IRQL = PASSIVE_LEVEL 641 - 642 - ========================================================================== 643 - */ 644 - VOID MlmeHalt( 645 - IN PRTMP_ADAPTER pAd) 646 - { 647 - BOOLEAN Cancelled; 648 - #ifdef RT3070 649 - UINT32 TxPinCfg = 0x00050F0F; 650 - #endif // RT3070 // 651 - 652 - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n")); 653 - 654 - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) 655 - { 656 - // disable BEACON generation and other BEACON related hardware timers 657 - AsicDisableSync(pAd); 658 - } 659 - 660 - { 661 - // Cancel pending timers 662 - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); 663 - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled); 664 - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled); 665 - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); 666 - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); 667 - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); 668 - } 669 - 670 - RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled); 671 - RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled); 672 - 673 - 674 - 675 - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) 676 - { 677 - // Set LED 678 - RTMPSetLED(pAd, LED_HALT); 679 - RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it. 680 - #ifdef RT2870 681 - { 682 - LED_CFG_STRUC LedCfg; 683 - RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word); 684 - LedCfg.field.LedPolar = 0; 685 - LedCfg.field.RLedMode = 0; 686 - LedCfg.field.GLedMode = 0; 687 - LedCfg.field.YLedMode = 0; 688 - RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word); 689 - } 690 - #endif // RT2870 // 691 - #ifdef RT3070 692 - // 693 - // Turn off LNA_PE 694 - // 695 - if (IS_RT3070(pAd) || IS_RT3071(pAd)) 696 - { 697 - TxPinCfg &= 0xFFFFF0F0; 698 - RTUSBWriteMACRegister(pAd, TX_PIN_CFG, TxPinCfg); 699 - } 700 - #endif // RT3070 // 701 - } 702 - 703 - RTMPusecDelay(5000); // 5 msec to gurantee Ant Diversity timer canceled 704 - 705 - MlmeQueueDestroy(&pAd->Mlme.Queue); 706 - NdisFreeSpinLock(&pAd->Mlme.TaskLock); 707 - 708 - DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n")); 709 - } 710 - 711 - VOID MlmeResetRalinkCounters( 712 - IN PRTMP_ADAPTER pAd) 713 - { 714 - pAd->RalinkCounters.LastOneSecRxOkDataCnt = pAd->RalinkCounters.OneSecRxOkDataCnt; 715 - // clear all OneSecxxx counters. 716 - pAd->RalinkCounters.OneSecBeaconSentCnt = 0; 717 - pAd->RalinkCounters.OneSecFalseCCACnt = 0; 718 - pAd->RalinkCounters.OneSecRxFcsErrCnt = 0; 719 - pAd->RalinkCounters.OneSecRxOkCnt = 0; 720 - pAd->RalinkCounters.OneSecTxFailCount = 0; 721 - pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0; 722 - pAd->RalinkCounters.OneSecTxRetryOkCount = 0; 723 - pAd->RalinkCounters.OneSecRxOkDataCnt = 0; 724 - 725 - // TODO: for debug only. to be removed 726 - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0; 727 - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0; 728 - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0; 729 - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0; 730 - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0; 731 - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0; 732 - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0; 733 - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0; 734 - pAd->RalinkCounters.OneSecTxDoneCount = 0; 735 - pAd->RalinkCounters.OneSecRxCount = 0; 736 - pAd->RalinkCounters.OneSecTxAggregationCount = 0; 737 - pAd->RalinkCounters.OneSecRxAggregationCount = 0; 738 - 739 - return; 740 - } 741 - 742 - unsigned long rx_AMSDU; 743 - unsigned long rx_Total; 744 - 745 - /* 746 - ========================================================================== 747 - Description: 748 - This routine is executed periodically to - 749 - 1. Decide if it's a right time to turn on PwrMgmt bit of all 750 - outgoiing frames 751 - 2. Calculate ChannelQuality based on statistics of the last 752 - period, so that TX rate won't toggling very frequently between a 753 - successful TX and a failed TX. 754 - 3. If the calculated ChannelQuality indicated current connection not 755 - healthy, then a ROAMing attempt is tried here. 756 - 757 - IRQL = DISPATCH_LEVEL 758 - 759 - ========================================================================== 760 - */ 761 - #define ADHOC_BEACON_LOST_TIME (8*OS_HZ) // 8 sec 762 - VOID MlmePeriodicExec( 763 - IN PVOID SystemSpecific1, 764 - IN PVOID FunctionContext, 765 - IN PVOID SystemSpecific2, 766 - IN PVOID SystemSpecific3) 767 - { 768 - ULONG TxTotalCnt; 769 - PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext; 770 - 771 - // Do nothing if the driver is starting halt state. 772 - // This might happen when timer already been fired before cancel timer with mlmehalt 773 - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_HALT_IN_PROGRESS | 774 - fRTMP_ADAPTER_RADIO_OFF | 775 - fRTMP_ADAPTER_RADIO_MEASUREMENT | 776 - fRTMP_ADAPTER_RESET_IN_PROGRESS)))) 777 - return; 778 - 779 - RT28XX_MLME_PRE_SANITY_CHECK(pAd); 780 - 781 - { 782 - // Do nothing if monitor mode is on 783 - if (MONITOR_ON(pAd)) 784 - return; 785 - 786 - if (pAd->Mlme.PeriodicRound & 0x1) 787 - { 788 - // This is the fix for wifi 11n extension channel overlapping test case. for 2860D 789 - if (((pAd->MACVersion & 0xffff) == 0x0101) && 790 - (STA_TGN_WIFI_ON(pAd)) && 791 - (pAd->CommonCfg.IOTestParm.bToggle == FALSE)) 792 - 793 - { 794 - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf); 795 - pAd->CommonCfg.IOTestParm.bToggle = TRUE; 796 - } 797 - else if ((STA_TGN_WIFI_ON(pAd)) && 798 - ((pAd->MACVersion & 0xffff) == 0x0101)) 799 - { 800 - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f); 801 - pAd->CommonCfg.IOTestParm.bToggle = FALSE; 802 - } 803 - } 804 - } 805 - 806 - pAd->bUpdateBcnCntDone = FALSE; 807 - 808 - // RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3); 809 - pAd->Mlme.PeriodicRound ++; 810 - 811 - #ifdef RT3070 812 - // execute every 100ms, update the Tx FIFO Cnt for update Tx Rate. 813 - NICUpdateFifoStaCounters(pAd); 814 - #endif // RT3070 // 815 - // execute every 500ms 816 - if ((pAd->Mlme.PeriodicRound % 5 == 0) && RTMPAutoRateSwitchCheck(pAd)/*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED))*/) 817 - { 818 - // perform dynamic tx rate switching based on past TX history 819 - { 820 - if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) 821 - ) 822 - && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))) 823 - MlmeDynamicTxRateSwitching(pAd); 824 - } 825 - } 826 - 827 - // Normal 1 second Mlme PeriodicExec. 828 - if (pAd->Mlme.PeriodicRound %MLME_TASK_EXEC_MULTIPLE == 0) 829 - { 830 - pAd->Mlme.OneSecPeriodicRound ++; 831 - 832 - if (rx_Total) 833 - { 834 - 835 - // reset counters 836 - rx_AMSDU = 0; 837 - rx_Total = 0; 838 - } 839 - 840 - // Media status changed, report to NDIS 841 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE)) 842 - { 843 - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE); 844 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 845 - { 846 - pAd->IndicateMediaState = NdisMediaStateConnected; 847 - RTMP_IndicateMediaState(pAd); 848 - 849 - } 850 - else 851 - { 852 - pAd->IndicateMediaState = NdisMediaStateDisconnected; 853 - RTMP_IndicateMediaState(pAd); 854 - } 855 - } 856 - 857 - NdisGetSystemUpTime(&pAd->Mlme.Now32); 858 - 859 - // add the most up-to-date h/w raw counters into software variable, so that 860 - // the dynamic tuning mechanism below are based on most up-to-date information 861 - NICUpdateRawCounters(pAd); 862 - 863 - #ifdef RT2870 864 - RT2870_WatchDog(pAd); 865 - #endif // RT2870 // 866 - 867 - // Need statistics after read counter. So put after NICUpdateRawCounters 868 - ORIBATimerTimeout(pAd); 869 - 870 - 871 - // The time period for checking antenna is according to traffic 872 - if (pAd->Mlme.bEnableAutoAntennaCheck) 873 - { 874 - TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 875 - pAd->RalinkCounters.OneSecTxRetryOkCount + 876 - pAd->RalinkCounters.OneSecTxFailCount; 877 - 878 - // dynamic adjust antenna evaluation period according to the traffic 879 - if (TxTotalCnt > 50) 880 - { 881 - if (pAd->Mlme.OneSecPeriodicRound % 10 == 0) 882 - { 883 - AsicEvaluateRxAnt(pAd); 884 - } 885 - } 886 - else 887 - { 888 - if (pAd->Mlme.OneSecPeriodicRound % 3 == 0) 889 - { 890 - AsicEvaluateRxAnt(pAd); 891 - } 892 - } 893 - } 894 - 895 - STAMlmePeriodicExec(pAd); 896 - 897 - MlmeResetRalinkCounters(pAd); 898 - 899 - { 900 - { 901 - // When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock 902 - // and sending CTS-to-self over and over. 903 - // Software Patch Solution: 904 - // 1. Polling debug state register 0x10F4 every one second. 905 - // 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred. 906 - // 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again. 907 - 908 - UINT32 MacReg = 0; 909 - 910 - RTMP_IO_READ32(pAd, 0x10F4, &MacReg); 911 - if (((MacReg & 0x20000000) && (MacReg & 0x80)) || ((MacReg & 0x20000000) && (MacReg & 0x20))) 912 - { 913 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); 914 - RTMPusecDelay(1); 915 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC); 916 - 917 - DBGPRINT(RT_DEBUG_WARN,("Warning, MAC specific condition occurs \n")); 918 - } 919 - } 920 - } 921 - 922 - RT28XX_MLME_HANDLER(pAd); 923 - } 924 - 925 - 926 - pAd->bUpdateBcnCntDone = FALSE; 927 - } 928 - 929 - VOID STAMlmePeriodicExec( 930 - PRTMP_ADAPTER pAd) 931 - { 932 - ULONG TxTotalCnt; 933 - int i; 934 - 935 - if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) 936 - { 937 - // WPA MIC error should block association attempt for 60 seconds 938 - if (pAd->StaCfg.bBlockAssoc && (pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ) < pAd->Mlme.Now32)) 939 - pAd->StaCfg.bBlockAssoc = FALSE; 940 - } 941 - 942 - if ((pAd->PreMediaState != pAd->IndicateMediaState) && (pAd->CommonCfg.bWirelessEvent)) 943 - { 944 - if (pAd->IndicateMediaState == NdisMediaStateConnected) 945 - { 946 - RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0); 947 - } 948 - pAd->PreMediaState = pAd->IndicateMediaState; 949 - } 950 - 951 - 952 - 953 - 954 - AsicStaBbpTuning(pAd); 955 - 956 - TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 957 - pAd->RalinkCounters.OneSecTxRetryOkCount + 958 - pAd->RalinkCounters.OneSecTxFailCount; 959 - 960 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 961 - { 962 - // update channel quality for Roaming and UI LinkQuality display 963 - MlmeCalculateChannelQuality(pAd, pAd->Mlme.Now32); 964 - } 965 - 966 - // must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if 967 - // Radio is currently in noisy environment 968 - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) 969 - AsicAdjustTxPower(pAd); 970 - 971 - if (INFRA_ON(pAd)) 972 - { 973 - // Is PSM bit consistent with user power management policy? 974 - // This is the only place that will set PSM bit ON. 975 - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) 976 - MlmeCheckPsmChange(pAd, pAd->Mlme.Now32); 977 - 978 - pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt; 979 - 980 - if ((pAd->StaCfg.LastBeaconRxTime + 1*OS_HZ < pAd->Mlme.Now32) && 981 - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) && 982 - ((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt < 600))) 983 - { 984 - RTMPSetAGCInitValue(pAd, BW_20); 985 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n", (0x2E + GET_LNA_GAIN(pAd)))); 986 - } 987 - 988 - { 989 - if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) 990 - { 991 - // When APSD is enabled, the period changes as 20 sec 992 - if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8) 993 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); 994 - } 995 - else 996 - { 997 - // Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out) 998 - if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8) 999 - { 1000 - if (pAd->CommonCfg.bWmmCapable) 1001 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); 1002 - else 1003 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); 1004 - } 1005 - } 1006 - } 1007 - 1008 - if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality)) 1009 - { 1010 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount)); 1011 - pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE; 1012 - pAd->StaCfg.CCXAdjacentAPLinkDownTime = pAd->StaCfg.LastBeaconRxTime; 1013 - 1014 - // Lost AP, send disconnect & link down event 1015 - LinkDown(pAd, FALSE); 1016 - 1017 - { 1018 - union iwreq_data wrqu; 1019 - memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN); 1020 - wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL); 1021 - } 1022 - 1023 - MlmeAutoReconnectLastSSID(pAd); 1024 - } 1025 - else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality)) 1026 - { 1027 - pAd->RalinkCounters.BadCQIAutoRecoveryCount ++; 1028 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount)); 1029 - MlmeAutoReconnectLastSSID(pAd); 1030 - } 1031 - 1032 - // Add auto seamless roaming 1033 - if (pAd->StaCfg.bFastRoaming) 1034 - { 1035 - SHORT dBmToRoam = (SHORT)pAd->StaCfg.dBmToRoam; 1036 - 1037 - DBGPRINT(RT_DEBUG_TRACE, ("Rssi=%d, dBmToRoam=%d\n", RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2), (CHAR)dBmToRoam)); 1038 - 1039 - if (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) <= (CHAR)dBmToRoam) 1040 - { 1041 - MlmeCheckForFastRoaming(pAd, pAd->Mlme.Now32); 1042 - } 1043 - } 1044 - } 1045 - else if (ADHOC_ON(pAd)) 1046 - { 1047 - //radar detect 1048 - if ((pAd->CommonCfg.Channel > 14) 1049 - && (pAd->CommonCfg.bIEEE80211H == 1) 1050 - && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) 1051 - { 1052 - RadarDetectPeriodic(pAd); 1053 - } 1054 - 1055 - // If all peers leave, and this STA becomes the last one in this IBSS, then change MediaState 1056 - // to DISCONNECTED. But still holding this IBSS (i.e. sending BEACON) so that other STAs can 1057 - // join later. 1058 - if ((pAd->StaCfg.LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32) && 1059 - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 1060 - { 1061 - MLME_START_REQ_STRUCT StartReq; 1062 - 1063 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - excessive BEACON lost, last STA in this IBSS, MediaState=Disconnected\n")); 1064 - LinkDown(pAd, FALSE); 1065 - 1066 - StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen); 1067 - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq); 1068 - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; 1069 - } 1070 - 1071 - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) 1072 - { 1073 - MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[i]; 1074 - 1075 - if (pEntry->ValidAsCLI == FALSE) 1076 - continue; 1077 - 1078 - if (pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32) 1079 - MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr); 1080 - } 1081 - } 1082 - else // no INFRA nor ADHOC connection 1083 - { 1084 - 1085 - if (pAd->StaCfg.bScanReqIsFromWebUI && 1086 - ((pAd->StaCfg.LastScanTime + 30 * OS_HZ) > pAd->Mlme.Now32)) 1087 - goto SKIP_AUTO_SCAN_CONN; 1088 - else 1089 - pAd->StaCfg.bScanReqIsFromWebUI = FALSE; 1090 - 1091 - if ((pAd->StaCfg.bAutoReconnect == TRUE) 1092 - && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP) 1093 - && (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) 1094 - { 1095 - if ((pAd->ScanTab.BssNr==0) && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)) 1096 - { 1097 - MLME_SCAN_REQ_STRUCT ScanReq; 1098 - 1099 - if ((pAd->StaCfg.LastScanTime + 10 * OS_HZ) < pAd->Mlme.Now32) 1100 - { 1101 - DBGPRINT(RT_DEBUG_TRACE, ("STAMlmePeriodicExec():CNTL - ScanTab.BssNr==0, start a new ACTIVE scan SSID[%s]\n", pAd->MlmeAux.AutoReconnectSsid)); 1102 - ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen, BSS_ANY, SCAN_ACTIVE); 1103 - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq); 1104 - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN; 1105 - // Reset Missed scan number 1106 - pAd->StaCfg.LastScanTime = pAd->Mlme.Now32; 1107 - } 1108 - else if (pAd->StaCfg.BssType == BSS_ADHOC) // Quit the forever scan when in a very clean room 1109 - MlmeAutoReconnectLastSSID(pAd); 1110 - } 1111 - else if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) 1112 - { 1113 - if ((pAd->Mlme.OneSecPeriodicRound % 7) == 0) 1114 - { 1115 - MlmeAutoScan(pAd); 1116 - pAd->StaCfg.LastScanTime = pAd->Mlme.Now32; 1117 - } 1118 - else 1119 - { 1120 - MlmeAutoReconnectLastSSID(pAd); 1121 - } 1122 - } 1123 - } 1124 - } 1125 - 1126 - SKIP_AUTO_SCAN_CONN: 1127 - 1128 - if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap !=0) && (pAd->MacTab.fAnyBASession == FALSE)) 1129 - { 1130 - pAd->MacTab.fAnyBASession = TRUE; 1131 - AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, FALSE, FALSE); 1132 - } 1133 - else if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap ==0) && (pAd->MacTab.fAnyBASession == TRUE)) 1134 - { 1135 - pAd->MacTab.fAnyBASession = FALSE; 1136 - AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE); 1137 - } 1138 - 1139 - return; 1140 - } 1141 - 1142 - // Link down report 1143 - VOID LinkDownExec( 1144 - IN PVOID SystemSpecific1, 1145 - IN PVOID FunctionContext, 1146 - IN PVOID SystemSpecific2, 1147 - IN PVOID SystemSpecific3) 1148 - { 1149 - 1150 - RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext; 1151 - 1152 - pAd->IndicateMediaState = NdisMediaStateDisconnected; 1153 - RTMP_IndicateMediaState(pAd); 1154 - pAd->ExtraInfo = GENERAL_LINK_DOWN; 1155 - } 1156 - 1157 - // IRQL = DISPATCH_LEVEL 1158 - VOID MlmeAutoScan( 1159 - IN PRTMP_ADAPTER pAd) 1160 - { 1161 - // check CntlMachine.CurrState to avoid collision with NDIS SetOID request 1162 - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) 1163 - { 1164 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Driver auto scan\n")); 1165 - MlmeEnqueue(pAd, 1166 - MLME_CNTL_STATE_MACHINE, 1167 - OID_802_11_BSSID_LIST_SCAN, 1168 - 0, 1169 - NULL); 1170 - RT28XX_MLME_HANDLER(pAd); 1171 - } 1172 - } 1173 - 1174 - // IRQL = DISPATCH_LEVEL 1175 - VOID MlmeAutoReconnectLastSSID( 1176 - IN PRTMP_ADAPTER pAd) 1177 - { 1178 - 1179 - 1180 - // check CntlMachine.CurrState to avoid collision with NDIS SetOID request 1181 - if ((pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) && 1182 - (MlmeValidateSSID(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) 1183 - { 1184 - NDIS_802_11_SSID OidSsid; 1185 - OidSsid.SsidLength = pAd->MlmeAux.AutoReconnectSsidLen; 1186 - NdisMoveMemory(OidSsid.Ssid, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen); 1187 - 1188 - DBGPRINT(RT_DEBUG_TRACE, ("Driver auto reconnect to last OID_802_11_SSID setting - %s, len - %d\n", pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen)); 1189 - MlmeEnqueue(pAd, 1190 - MLME_CNTL_STATE_MACHINE, 1191 - OID_802_11_SSID, 1192 - sizeof(NDIS_802_11_SSID), 1193 - &OidSsid); 1194 - RT28XX_MLME_HANDLER(pAd); 1195 - } 1196 - } 1197 - 1198 - /* 1199 - ========================================================================== 1200 - Validate SSID for connection try and rescan purpose 1201 - Valid SSID will have visible chars only. 1202 - The valid length is from 0 to 32. 1203 - IRQL = DISPATCH_LEVEL 1204 - ========================================================================== 1205 - */ 1206 - BOOLEAN MlmeValidateSSID( 1207 - IN PUCHAR pSsid, 1208 - IN UCHAR SsidLen) 1209 - { 1210 - int index; 1211 - 1212 - if (SsidLen > MAX_LEN_OF_SSID) 1213 - return (FALSE); 1214 - 1215 - // Check each character value 1216 - for (index = 0; index < SsidLen; index++) 1217 - { 1218 - if (pSsid[index] < 0x20) 1219 - return (FALSE); 1220 - } 1221 - 1222 - // All checked 1223 - return (TRUE); 1224 - } 1225 - 1226 - VOID MlmeSelectTxRateTable( 1227 - IN PRTMP_ADAPTER pAd, 1228 - IN PMAC_TABLE_ENTRY pEntry, 1229 - IN PUCHAR *ppTable, 1230 - IN PUCHAR pTableSize, 1231 - IN PUCHAR pInitTxRateIdx) 1232 - { 1233 - do 1234 - { 1235 - // decide the rate table for tuning 1236 - if (pAd->CommonCfg.TxRateTableSize > 0) 1237 - { 1238 - *ppTable = RateSwitchTable; 1239 - *pTableSize = RateSwitchTable[0]; 1240 - *pInitTxRateIdx = RateSwitchTable[1]; 1241 - 1242 - break; 1243 - } 1244 - 1245 - if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd)) 1246 - { 1247 - if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && 1248 - (pEntry->HTCapability.MCSSet[0] == 0xff) && 1249 - ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) 1250 - {// 11N 1S Adhoc 1251 - *ppTable = RateSwitchTable11N1S; 1252 - *pTableSize = RateSwitchTable11N1S[0]; 1253 - *pInitTxRateIdx = RateSwitchTable11N1S[1]; 1254 - 1255 - } 1256 - else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && 1257 - (pEntry->HTCapability.MCSSet[0] == 0xff) && 1258 - (pEntry->HTCapability.MCSSet[1] == 0xff) && 1259 - (pAd->Antenna.field.TxPath == 2)) 1260 - {// 11N 2S Adhoc 1261 - if (pAd->LatchRfRegs.Channel <= 14) 1262 - { 1263 - *ppTable = RateSwitchTable11N2S; 1264 - *pTableSize = RateSwitchTable11N2S[0]; 1265 - *pInitTxRateIdx = RateSwitchTable11N2S[1]; 1266 - } 1267 - else 1268 - { 1269 - *ppTable = RateSwitchTable11N2SForABand; 1270 - *pTableSize = RateSwitchTable11N2SForABand[0]; 1271 - *pInitTxRateIdx = RateSwitchTable11N2SForABand[1]; 1272 - } 1273 - 1274 - } 1275 - else 1276 - if ((pEntry->RateLen == 4) 1277 - && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) 1278 - ) 1279 - { 1280 - *ppTable = RateSwitchTable11B; 1281 - *pTableSize = RateSwitchTable11B[0]; 1282 - *pInitTxRateIdx = RateSwitchTable11B[1]; 1283 - 1284 - } 1285 - else if (pAd->LatchRfRegs.Channel <= 14) 1286 - { 1287 - *ppTable = RateSwitchTable11BG; 1288 - *pTableSize = RateSwitchTable11BG[0]; 1289 - *pInitTxRateIdx = RateSwitchTable11BG[1]; 1290 - 1291 - } 1292 - else 1293 - { 1294 - *ppTable = RateSwitchTable11G; 1295 - *pTableSize = RateSwitchTable11G[0]; 1296 - *pInitTxRateIdx = RateSwitchTable11G[1]; 1297 - 1298 - } 1299 - break; 1300 - } 1301 - 1302 - if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) && 1303 - ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) 1304 - {// 11BGN 1S AP 1305 - *ppTable = RateSwitchTable11BGN1S; 1306 - *pTableSize = RateSwitchTable11BGN1S[0]; 1307 - *pInitTxRateIdx = RateSwitchTable11BGN1S[1]; 1308 - 1309 - break; 1310 - } 1311 - 1312 - if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) && 1313 - (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) 1314 - {// 11BGN 2S AP 1315 - if (pAd->LatchRfRegs.Channel <= 14) 1316 - { 1317 - *ppTable = RateSwitchTable11BGN2S; 1318 - *pTableSize = RateSwitchTable11BGN2S[0]; 1319 - *pInitTxRateIdx = RateSwitchTable11BGN2S[1]; 1320 - 1321 - } 1322 - else 1323 - { 1324 - *ppTable = RateSwitchTable11BGN2SForABand; 1325 - *pTableSize = RateSwitchTable11BGN2SForABand[0]; 1326 - *pInitTxRateIdx = RateSwitchTable11BGN2SForABand[1]; 1327 - 1328 - } 1329 - break; 1330 - } 1331 - 1332 - if ((pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) 1333 - {// 11N 1S AP 1334 - *ppTable = RateSwitchTable11N1S; 1335 - *pTableSize = RateSwitchTable11N1S[0]; 1336 - *pInitTxRateIdx = RateSwitchTable11N1S[1]; 1337 - 1338 - break; 1339 - } 1340 - 1341 - if ((pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) 1342 - {// 11N 2S AP 1343 - if (pAd->LatchRfRegs.Channel <= 14) 1344 - { 1345 - *ppTable = RateSwitchTable11N2S; 1346 - *pTableSize = RateSwitchTable11N2S[0]; 1347 - *pInitTxRateIdx = RateSwitchTable11N2S[1]; 1348 - } 1349 - else 1350 - { 1351 - *ppTable = RateSwitchTable11N2SForABand; 1352 - *pTableSize = RateSwitchTable11N2SForABand[0]; 1353 - *pInitTxRateIdx = RateSwitchTable11N2SForABand[1]; 1354 - } 1355 - 1356 - break; 1357 - } 1358 - 1359 - //else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) 1360 - if ((pEntry->RateLen == 4) 1361 - #ifndef RT30xx 1362 - //Iverson mark for Adhoc b mode,sta will use rate 54 Mbps when connect with sta b/g/n mode 1363 - && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) 1364 - #endif 1365 - ) 1366 - {// B only AP 1367 - *ppTable = RateSwitchTable11B; 1368 - *pTableSize = RateSwitchTable11B[0]; 1369 - *pInitTxRateIdx = RateSwitchTable11B[1]; 1370 - 1371 - break; 1372 - } 1373 - 1374 - //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) 1375 - if ((pEntry->RateLen > 8) 1376 - && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) 1377 - ) 1378 - {// B/G mixed AP 1379 - *ppTable = RateSwitchTable11BG; 1380 - *pTableSize = RateSwitchTable11BG[0]; 1381 - *pInitTxRateIdx = RateSwitchTable11BG[1]; 1382 - 1383 - break; 1384 - } 1385 - 1386 - //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) 1387 - if ((pEntry->RateLen == 8) 1388 - && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) 1389 - ) 1390 - {// G only AP 1391 - *ppTable = RateSwitchTable11G; 1392 - *pTableSize = RateSwitchTable11G[0]; 1393 - *pInitTxRateIdx = RateSwitchTable11G[1]; 1394 - 1395 - break; 1396 - } 1397 - 1398 - { 1399 - //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) 1400 - if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)) 1401 - { // Legacy mode 1402 - if (pAd->CommonCfg.MaxTxRate <= RATE_11) 1403 - { 1404 - *ppTable = RateSwitchTable11B; 1405 - *pTableSize = RateSwitchTable11B[0]; 1406 - *pInitTxRateIdx = RateSwitchTable11B[1]; 1407 - } 1408 - else if ((pAd->CommonCfg.MaxTxRate > RATE_11) && (pAd->CommonCfg.MinTxRate > RATE_11)) 1409 - { 1410 - *ppTable = RateSwitchTable11G; 1411 - *pTableSize = RateSwitchTable11G[0]; 1412 - *pInitTxRateIdx = RateSwitchTable11G[1]; 1413 - 1414 - } 1415 - else 1416 - { 1417 - *ppTable = RateSwitchTable11BG; 1418 - *pTableSize = RateSwitchTable11BG[0]; 1419 - *pInitTxRateIdx = RateSwitchTable11BG[1]; 1420 - } 1421 - break; 1422 - } 1423 - 1424 - if (pAd->LatchRfRegs.Channel <= 14) 1425 - { 1426 - if (pAd->CommonCfg.TxStream == 1) 1427 - { 1428 - *ppTable = RateSwitchTable11N1S; 1429 - *pTableSize = RateSwitchTable11N1S[0]; 1430 - *pInitTxRateIdx = RateSwitchTable11N1S[1]; 1431 - DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n")); 1432 - } 1433 - else 1434 - { 1435 - *ppTable = RateSwitchTable11N2S; 1436 - *pTableSize = RateSwitchTable11N2S[0]; 1437 - *pInitTxRateIdx = RateSwitchTable11N2S[1]; 1438 - DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n")); 1439 - } 1440 - } 1441 - else 1442 - { 1443 - if (pAd->CommonCfg.TxStream == 1) 1444 - { 1445 - *ppTable = RateSwitchTable11N1S; 1446 - *pTableSize = RateSwitchTable11N1S[0]; 1447 - *pInitTxRateIdx = RateSwitchTable11N1S[1]; 1448 - DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 1S AP \n")); 1449 - } 1450 - else 1451 - { 1452 - *ppTable = RateSwitchTable11N2SForABand; 1453 - *pTableSize = RateSwitchTable11N2SForABand[0]; 1454 - *pInitTxRateIdx = RateSwitchTable11N2SForABand[1]; 1455 - DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n")); 1456 - } 1457 - } 1458 - 1459 - DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n", 1460 - pAd->StaActive.SupRateLen, pAd->StaActive.ExtRateLen, pAd->StaActive.SupportedPhyInfo.MCSSet[0], pAd->StaActive.SupportedPhyInfo.MCSSet[1])); 1461 - } 1462 - } while(FALSE); 1463 - } 1464 - 1465 - /* 1466 - ========================================================================== 1467 - Description: 1468 - This routine checks if there're other APs out there capable for 1469 - roaming. Caller should call this routine only when Link up in INFRA mode 1470 - and channel quality is below CQI_GOOD_THRESHOLD. 1471 - 1472 - IRQL = DISPATCH_LEVEL 1473 - 1474 - Output: 1475 - ========================================================================== 1476 - */ 1477 - VOID MlmeCheckForRoaming( 1478 - IN PRTMP_ADAPTER pAd, 1479 - IN ULONG Now32) 1480 - { 1481 - USHORT i; 1482 - BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab; 1483 - BSS_ENTRY *pBss; 1484 - 1485 - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForRoaming\n")); 1486 - // put all roaming candidates into RoamTab, and sort in RSSI order 1487 - BssTableInit(pRoamTab); 1488 - for (i = 0; i < pAd->ScanTab.BssNr; i++) 1489 - { 1490 - pBss = &pAd->ScanTab.BssEntry[i]; 1491 - 1492 - if ((pBss->LastBeaconRxTime + BEACON_LOST_TIME) < Now32) 1493 - continue; // AP disappear 1494 - if (pBss->Rssi <= RSSI_THRESHOLD_FOR_ROAMING) 1495 - continue; // RSSI too weak. forget it. 1496 - if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid)) 1497 - continue; // skip current AP 1498 - if (pBss->Rssi < (pAd->StaCfg.RssiSample.LastRssi0 + RSSI_DELTA)) 1499 - continue; // only AP with stronger RSSI is eligible for roaming 1500 - 1501 - // AP passing all above rules is put into roaming candidate table 1502 - NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY)); 1503 - pRoamTab->BssNr += 1; 1504 - } 1505 - 1506 - if (pRoamTab->BssNr > 0) 1507 - { 1508 - // check CntlMachine.CurrState to avoid collision with NDIS SetOID request 1509 - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) 1510 - { 1511 - pAd->RalinkCounters.PoorCQIRoamingCount ++; 1512 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount)); 1513 - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL); 1514 - RT28XX_MLME_HANDLER(pAd); 1515 - } 1516 - } 1517 - DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForRoaming(# of candidate= %d)\n",pRoamTab->BssNr)); 1518 - } 1519 - 1520 - /* 1521 - ========================================================================== 1522 - Description: 1523 - This routine checks if there're other APs out there capable for 1524 - roaming. Caller should call this routine only when link up in INFRA mode 1525 - and channel quality is below CQI_GOOD_THRESHOLD. 1526 - 1527 - IRQL = DISPATCH_LEVEL 1528 - 1529 - Output: 1530 - ========================================================================== 1531 - */ 1532 - VOID MlmeCheckForFastRoaming( 1533 - IN PRTMP_ADAPTER pAd, 1534 - IN ULONG Now) 1535 - { 1536 - USHORT i; 1537 - BSS_TABLE *pRoamTab = &pAd->MlmeAux.RoamTab; 1538 - BSS_ENTRY *pBss; 1539 - 1540 - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForFastRoaming\n")); 1541 - // put all roaming candidates into RoamTab, and sort in RSSI order 1542 - BssTableInit(pRoamTab); 1543 - for (i = 0; i < pAd->ScanTab.BssNr; i++) 1544 - { 1545 - pBss = &pAd->ScanTab.BssEntry[i]; 1546 - 1547 - if ((pBss->Rssi <= -50) && (pBss->Channel == pAd->CommonCfg.Channel)) 1548 - continue; // RSSI too weak. forget it. 1549 - if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid)) 1550 - continue; // skip current AP 1551 - if (!SSID_EQUAL(pBss->Ssid, pBss->SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen)) 1552 - continue; // skip different SSID 1553 - if (pBss->Rssi < (RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2) + RSSI_DELTA)) 1554 - continue; // skip AP without better RSSI 1555 - 1556 - DBGPRINT(RT_DEBUG_TRACE, ("LastRssi0 = %d, pBss->Rssi = %d\n", RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2), pBss->Rssi)); 1557 - // AP passing all above rules is put into roaming candidate table 1558 - NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, sizeof(BSS_ENTRY)); 1559 - pRoamTab->BssNr += 1; 1560 - } 1561 - 1562 - if (pRoamTab->BssNr > 0) 1563 - { 1564 - // check CntlMachine.CurrState to avoid collision with NDIS SetOID request 1565 - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) 1566 - { 1567 - pAd->RalinkCounters.PoorCQIRoamingCount ++; 1568 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming attempt #%ld\n", pAd->RalinkCounters.PoorCQIRoamingCount)); 1569 - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_MLME_ROAMING_REQ, 0, NULL); 1570 - RT28XX_MLME_HANDLER(pAd); 1571 - } 1572 - } 1573 - // Maybe site survey required 1574 - else 1575 - { 1576 - if ((pAd->StaCfg.LastScanTime + 10 * 1000) < Now) 1577 - { 1578 - // check CntlMachine.CurrState to avoid collision with NDIS SetOID request 1579 - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Roaming, No eligable entry, try new scan!\n")); 1580 - pAd->StaCfg.ScanCnt = 2; 1581 - pAd->StaCfg.LastScanTime = Now; 1582 - MlmeAutoScan(pAd); 1583 - } 1584 - } 1585 - 1586 - DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeCheckForFastRoaming (BssNr=%d)\n", pRoamTab->BssNr)); 1587 - } 1588 - 1589 - /* 1590 - ========================================================================== 1591 - Description: 1592 - This routine calculates TxPER, RxPER of the past N-sec period. And 1593 - according to the calculation result, ChannelQuality is calculated here 1594 - to decide if current AP is still doing the job. 1595 - 1596 - If ChannelQuality is not good, a ROAMing attempt may be tried later. 1597 - Output: 1598 - StaCfg.ChannelQuality - 0..100 1599 - 1600 - IRQL = DISPATCH_LEVEL 1601 - 1602 - NOTE: This routine decide channle quality based on RX CRC error ratio. 1603 - Caller should make sure a function call to NICUpdateRawCounters(pAd) 1604 - is performed right before this routine, so that this routine can decide 1605 - channel quality based on the most up-to-date information 1606 - ========================================================================== 1607 - */ 1608 - VOID MlmeCalculateChannelQuality( 1609 - IN PRTMP_ADAPTER pAd, 1610 - IN ULONG Now32) 1611 - { 1612 - ULONG TxOkCnt, TxCnt, TxPER, TxPRR; 1613 - ULONG RxCnt, RxPER; 1614 - UCHAR NorRssi; 1615 - CHAR MaxRssi; 1616 - ULONG BeaconLostTime = BEACON_LOST_TIME; 1617 - 1618 - MaxRssi = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2); 1619 - 1620 - // 1621 - // calculate TX packet error ratio and TX retry ratio - if too few TX samples, skip TX related statistics 1622 - // 1623 - TxOkCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + pAd->RalinkCounters.OneSecTxRetryOkCount; 1624 - TxCnt = TxOkCnt + pAd->RalinkCounters.OneSecTxFailCount; 1625 - if (TxCnt < 5) 1626 - { 1627 - TxPER = 0; 1628 - TxPRR = 0; 1629 - } 1630 - else 1631 - { 1632 - TxPER = (pAd->RalinkCounters.OneSecTxFailCount * 100) / TxCnt; 1633 - TxPRR = ((TxCnt - pAd->RalinkCounters.OneSecTxNoRetryOkCount) * 100) / TxCnt; 1634 - } 1635 - 1636 - // 1637 - // calculate RX PER - don't take RxPER into consideration if too few sample 1638 - // 1639 - RxCnt = pAd->RalinkCounters.OneSecRxOkCnt + pAd->RalinkCounters.OneSecRxFcsErrCnt; 1640 - if (RxCnt < 5) 1641 - RxPER = 0; 1642 - else 1643 - RxPER = (pAd->RalinkCounters.OneSecRxFcsErrCnt * 100) / RxCnt; 1644 - 1645 - // 1646 - // decide ChannelQuality based on: 1)last BEACON received time, 2)last RSSI, 3)TxPER, and 4)RxPER 1647 - // 1648 - if (INFRA_ON(pAd) && 1649 - (pAd->RalinkCounters.OneSecTxNoRetryOkCount < 2) && // no heavy traffic 1650 - (pAd->StaCfg.LastBeaconRxTime + BeaconLostTime < Now32)) 1651 - { 1652 - DBGPRINT(RT_DEBUG_TRACE, ("BEACON lost > %ld msec with TxOkCnt=%ld -> CQI=0\n", BeaconLostTime, TxOkCnt)); 1653 - pAd->Mlme.ChannelQuality = 0; 1654 - } 1655 - else 1656 - { 1657 - // Normalize Rssi 1658 - if (MaxRssi > -40) 1659 - NorRssi = 100; 1660 - else if (MaxRssi < -90) 1661 - NorRssi = 0; 1662 - else 1663 - NorRssi = (MaxRssi + 90) * 2; 1664 - 1665 - // ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER (RSSI 0..100), (TxPER 100..0), (RxPER 100..0) 1666 - pAd->Mlme.ChannelQuality = (RSSI_WEIGHTING * NorRssi + 1667 - TX_WEIGHTING * (100 - TxPRR) + 1668 - RX_WEIGHTING* (100 - RxPER)) / 100; 1669 - if (pAd->Mlme.ChannelQuality >= 100) 1670 - pAd->Mlme.ChannelQuality = 100; 1671 - } 1672 - 1673 - } 1674 - 1675 - VOID MlmeSetTxRate( 1676 - IN PRTMP_ADAPTER pAd, 1677 - IN PMAC_TABLE_ENTRY pEntry, 1678 - IN PRTMP_TX_RATE_SWITCH pTxRate) 1679 - { 1680 - UCHAR MaxMode = MODE_OFDM; 1681 - 1682 - MaxMode = MODE_HTGREENFIELD; 1683 - 1684 - if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC) && (pAd->Antenna.field.TxPath == 2)) 1685 - pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE; 1686 - else 1687 - pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE; 1688 - 1689 - if (pTxRate->CurrMCS < MCS_AUTO) 1690 - pAd->StaCfg.HTPhyMode.field.MCS = pTxRate->CurrMCS; 1691 - 1692 - if (pAd->StaCfg.HTPhyMode.field.MCS > 7) 1693 - pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE; 1694 - 1695 - if (ADHOC_ON(pAd)) 1696 - { 1697 - // If peer adhoc is b-only mode, we can't send 11g rate. 1698 - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; 1699 - pEntry->HTPhyMode.field.STBC = STBC_NONE; 1700 - 1701 - // 1702 - // For Adhoc MODE_CCK, driver will use AdhocBOnlyJoined flag to roll back to B only if necessary 1703 - // 1704 - pEntry->HTPhyMode.field.MODE = pTxRate->Mode; 1705 - pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI; 1706 - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; 1707 - 1708 - // Patch speed error in status page 1709 - pAd->StaCfg.HTPhyMode.field.MODE = pEntry->HTPhyMode.field.MODE; 1710 - } 1711 - else 1712 - { 1713 - if (pTxRate->Mode <= MaxMode) 1714 - pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode; 1715 - 1716 - if (pTxRate->ShortGI && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI)) 1717 - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400; 1718 - else 1719 - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; 1720 - 1721 - // Reexam each bandwidth's SGI support. 1722 - if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400) 1723 - { 1724 - if ((pEntry->HTPhyMode.field.BW == BW_20) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI20_CAPABLE))) 1725 - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; 1726 - if ((pEntry->HTPhyMode.field.BW == BW_40) && (!CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_SGI40_CAPABLE))) 1727 - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; 1728 - } 1729 - 1730 - // Turn RTS/CTS rate to 6Mbps. 1731 - if ((pEntry->HTPhyMode.field.MCS == 0) && (pAd->StaCfg.HTPhyMode.field.MCS != 0)) 1732 - { 1733 - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; 1734 - if (pAd->MacTab.fAnyBASession) 1735 - { 1736 - AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1737 - } 1738 - else 1739 - { 1740 - AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1741 - } 1742 - } 1743 - else if ((pEntry->HTPhyMode.field.MCS == 8) && (pAd->StaCfg.HTPhyMode.field.MCS != 8)) 1744 - { 1745 - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; 1746 - if (pAd->MacTab.fAnyBASession) 1747 - { 1748 - AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1749 - } 1750 - else 1751 - { 1752 - AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1753 - } 1754 - } 1755 - else if ((pEntry->HTPhyMode.field.MCS != 0) && (pAd->StaCfg.HTPhyMode.field.MCS == 0)) 1756 - { 1757 - AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1758 - 1759 - } 1760 - else if ((pEntry->HTPhyMode.field.MCS != 8) && (pAd->StaCfg.HTPhyMode.field.MCS == 8)) 1761 - { 1762 - AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); 1763 - } 1764 - 1765 - pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC; 1766 - pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI; 1767 - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; 1768 - pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE; 1769 - 1770 - if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD) && 1771 - pAd->WIFItestbed.bGreenField) 1772 - pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD; 1773 - } 1774 - 1775 - pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word); 1776 - } 1777 - 1778 - /* 1779 - ========================================================================== 1780 - Description: 1781 - This routine calculates the acumulated TxPER of eaxh TxRate. And 1782 - according to the calculation result, change CommonCfg.TxRate which 1783 - is the stable TX Rate we expect the Radio situation could sustained. 1784 - 1785 - CommonCfg.TxRate will change dynamically within {RATE_1/RATE_6, MaxTxRate} 1786 - Output: 1787 - CommonCfg.TxRate - 1788 - 1789 - IRQL = DISPATCH_LEVEL 1790 - 1791 - NOTE: 1792 - call this routine every second 1793 - ========================================================================== 1794 - */ 1795 - VOID MlmeDynamicTxRateSwitching( 1796 - IN PRTMP_ADAPTER pAd) 1797 - { 1798 - UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx; 1799 - ULONG i, AccuTxTotalCnt = 0, TxTotalCnt; 1800 - ULONG TxErrorRatio = 0; 1801 - BOOLEAN bTxRateChanged, bUpgradeQuality = FALSE; 1802 - PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL; 1803 - PUCHAR pTable; 1804 - UCHAR TableSize = 0; 1805 - UCHAR InitTxRateIdx = 0, TrainUp, TrainDown; 1806 - CHAR Rssi, RssiOffset = 0; 1807 - TX_STA_CNT1_STRUC StaTx1; 1808 - TX_STA_CNT0_STRUC TxStaCnt0; 1809 - ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0; 1810 - MAC_TABLE_ENTRY *pEntry; 1811 - 1812 - // 1813 - // walk through MAC table, see if need to change AP's TX rate toward each entry 1814 - // 1815 - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) 1816 - { 1817 - pEntry = &pAd->MacTab.Content[i]; 1818 - 1819 - // check if this entry need to switch rate automatically 1820 - if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE) 1821 - continue; 1822 - 1823 - if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls)) 1824 - { 1825 - Rssi = RTMPMaxRssi(pAd, 1826 - pAd->StaCfg.RssiSample.AvgRssi0, 1827 - pAd->StaCfg.RssiSample.AvgRssi1, 1828 - pAd->StaCfg.RssiSample.AvgRssi2); 1829 - 1830 - // Update statistic counter 1831 - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); 1832 - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); 1833 - pAd->bUpdateBcnCntDone = TRUE; 1834 - TxRetransmit = StaTx1.field.TxRetransmit; 1835 - TxSuccess = StaTx1.field.TxSuccess; 1836 - TxFailCount = TxStaCnt0.field.TxFailCount; 1837 - TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount; 1838 - 1839 - pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit; 1840 - pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess; 1841 - pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount; 1842 - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess; 1843 - pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit; 1844 - pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount; 1845 - 1846 - // if no traffic in the past 1-sec period, don't change TX rate, 1847 - // but clear all bad history. because the bad history may affect the next 1848 - // Chariot throughput test 1849 - AccuTxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 1850 - pAd->RalinkCounters.OneSecTxRetryOkCount + 1851 - pAd->RalinkCounters.OneSecTxFailCount; 1852 - 1853 - if (TxTotalCnt) 1854 - TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt; 1855 - } 1856 - else 1857 - { 1858 - if (INFRA_ON(pAd) && (i == 1)) 1859 - Rssi = RTMPMaxRssi(pAd, 1860 - pAd->StaCfg.RssiSample.AvgRssi0, 1861 - pAd->StaCfg.RssiSample.AvgRssi1, 1862 - pAd->StaCfg.RssiSample.AvgRssi2); 1863 - else 1864 - Rssi = RTMPMaxRssi(pAd, 1865 - pEntry->RssiSample.AvgRssi0, 1866 - pEntry->RssiSample.AvgRssi1, 1867 - pEntry->RssiSample.AvgRssi2); 1868 - 1869 - TxTotalCnt = pEntry->OneSecTxNoRetryOkCount + 1870 - pEntry->OneSecTxRetryOkCount + 1871 - pEntry->OneSecTxFailCount; 1872 - 1873 - if (TxTotalCnt) 1874 - TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt; 1875 - } 1876 - 1877 - CurrRateIdx = pEntry->CurrTxRateIndex; 1878 - 1879 - MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx); 1880 - 1881 - if (CurrRateIdx >= TableSize) 1882 - { 1883 - CurrRateIdx = TableSize - 1; 1884 - } 1885 - 1886 - // When switch from Fixed rate -> auto rate, the REAL TX rate might be different from pAd->CommonCfg.TxRateIndex. 1887 - // So need to sync here. 1888 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5]; 1889 - if ((pEntry->HTPhyMode.field.MCS != pCurrTxRate->CurrMCS) 1890 - //&& (pAd->StaCfg.bAutoTxRateSwitch == TRUE) 1891 - ) 1892 - { 1893 - 1894 - // Need to sync Real Tx rate and our record. 1895 - // Then return for next DRS. 1896 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(InitTxRateIdx+1)*5]; 1897 - pEntry->CurrTxRateIndex = InitTxRateIdx; 1898 - MlmeSetTxRate(pAd, pEntry, pCurrTxRate); 1899 - 1900 - // reset all OneSecTx counters 1901 - RESET_ONE_SEC_TX_CNT(pEntry); 1902 - continue; 1903 - } 1904 - 1905 - // decide the next upgrade rate and downgrade rate, if any 1906 - if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) 1907 - { 1908 - UpRateIdx = CurrRateIdx + 1; 1909 - DownRateIdx = CurrRateIdx -1; 1910 - } 1911 - else if (CurrRateIdx == 0) 1912 - { 1913 - UpRateIdx = CurrRateIdx + 1; 1914 - DownRateIdx = CurrRateIdx; 1915 - } 1916 - else if (CurrRateIdx == (TableSize - 1)) 1917 - { 1918 - UpRateIdx = CurrRateIdx; 1919 - DownRateIdx = CurrRateIdx - 1; 1920 - } 1921 - 1922 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5]; 1923 - 1924 - if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) 1925 - { 1926 - TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1)); 1927 - TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1)); 1928 - } 1929 - else 1930 - { 1931 - TrainUp = pCurrTxRate->TrainUp; 1932 - TrainDown = pCurrTxRate->TrainDown; 1933 - } 1934 - 1935 - //pAd->DrsCounters.LastTimeTxRateChangeAction = pAd->DrsCounters.LastSecTxRateChangeAction; 1936 - 1937 - // 1938 - // Keep the last time TxRateChangeAction status. 1939 - // 1940 - pEntry->LastTimeTxRateChangeAction = pEntry->LastSecTxRateChangeAction; 1941 - 1942 - 1943 - 1944 - // 1945 - // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI 1946 - // (criteria copied from RT2500 for Netopia case) 1947 - // 1948 - if (TxTotalCnt <= 15) 1949 - { 1950 - CHAR idx = 0; 1951 - UCHAR TxRateIdx; 1952 - //UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS7 = 0, MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0; 1953 - UCHAR MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = 0, MCS5 =0, MCS6 = 0, MCS7 = 0; 1954 - UCHAR MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0; 1955 - UCHAR MCS20 = 0, MCS21 = 0, MCS22 = 0, MCS23 = 0; // 3*3 1956 - 1957 - // check the existence and index of each needed MCS 1958 - while (idx < pTable[0]) 1959 - { 1960 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(idx+1)*5]; 1961 - 1962 - if (pCurrTxRate->CurrMCS == MCS_0) 1963 - { 1964 - MCS0 = idx; 1965 - } 1966 - else if (pCurrTxRate->CurrMCS == MCS_1) 1967 - { 1968 - MCS1 = idx; 1969 - } 1970 - else if (pCurrTxRate->CurrMCS == MCS_2) 1971 - { 1972 - MCS2 = idx; 1973 - } 1974 - else if (pCurrTxRate->CurrMCS == MCS_3) 1975 - { 1976 - MCS3 = idx; 1977 - } 1978 - else if (pCurrTxRate->CurrMCS == MCS_4) 1979 - { 1980 - MCS4 = idx; 1981 - } 1982 - else if (pCurrTxRate->CurrMCS == MCS_5) 1983 - { 1984 - MCS5 = idx; 1985 - } 1986 - else if (pCurrTxRate->CurrMCS == MCS_6) 1987 - { 1988 - MCS6 = idx; 1989 - } 1990 - //else if (pCurrTxRate->CurrMCS == MCS_7) 1991 - else if ((pCurrTxRate->CurrMCS == MCS_7) && (pCurrTxRate->ShortGI == GI_800)) // prevent the highest MCS using short GI when 1T and low throughput 1992 - { 1993 - MCS7 = idx; 1994 - } 1995 - else if (pCurrTxRate->CurrMCS == MCS_12) 1996 - { 1997 - MCS12 = idx; 1998 - } 1999 - else if (pCurrTxRate->CurrMCS == MCS_13) 2000 - { 2001 - MCS13 = idx; 2002 - } 2003 - else if (pCurrTxRate->CurrMCS == MCS_14) 2004 - { 2005 - MCS14 = idx; 2006 - } 2007 - else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800)) //we hope to use ShortGI as initial rate, however Atheros's chip has bugs when short GI 2008 - { 2009 - MCS15 = idx; 2010 - } 2011 - else if (pCurrTxRate->CurrMCS == MCS_20) // 3*3 2012 - { 2013 - MCS20 = idx; 2014 - } 2015 - else if (pCurrTxRate->CurrMCS == MCS_21) 2016 - { 2017 - MCS21 = idx; 2018 - } 2019 - else if (pCurrTxRate->CurrMCS == MCS_22) 2020 - { 2021 - MCS22 = idx; 2022 - } 2023 - else if (pCurrTxRate->CurrMCS == MCS_23) 2024 - { 2025 - MCS23 = idx; 2026 - } 2027 - idx ++; 2028 - } 2029 - 2030 - if (pAd->LatchRfRegs.Channel <= 14) 2031 - { 2032 - if (pAd->NicConfig2.field.ExternalLNAForG) 2033 - { 2034 - RssiOffset = 2; 2035 - } 2036 - else 2037 - { 2038 - RssiOffset = 5; 2039 - } 2040 - } 2041 - else 2042 - { 2043 - if (pAd->NicConfig2.field.ExternalLNAForA) 2044 - { 2045 - RssiOffset = 5; 2046 - } 2047 - else 2048 - { 2049 - RssiOffset = 8; 2050 - } 2051 - } 2052 - 2053 - /*if (MCS15)*/ 2054 - if ((pTable == RateSwitchTable11BGN3S) || 2055 - (pTable == RateSwitchTable11N3S) || 2056 - (pTable == RateSwitchTable)) 2057 - {// N mode with 3 stream // 3*3 2058 - if (MCS23 && (Rssi >= -70)) 2059 - TxRateIdx = MCS15; 2060 - else if (MCS22 && (Rssi >= -72)) 2061 - TxRateIdx = MCS14; 2062 - else if (MCS21 && (Rssi >= -76)) 2063 - TxRateIdx = MCS13; 2064 - else if (MCS20 && (Rssi >= -78)) 2065 - TxRateIdx = MCS12; 2066 - else if (MCS4 && (Rssi >= -82)) 2067 - TxRateIdx = MCS4; 2068 - else if (MCS3 && (Rssi >= -84)) 2069 - TxRateIdx = MCS3; 2070 - else if (MCS2 && (Rssi >= -86)) 2071 - TxRateIdx = MCS2; 2072 - else if (MCS1 && (Rssi >= -88)) 2073 - TxRateIdx = MCS1; 2074 - else 2075 - TxRateIdx = MCS0; 2076 - } 2077 - else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand)) // 3*3 2078 - {// N mode with 2 stream 2079 - if (MCS15 && (Rssi >= (-70+RssiOffset))) 2080 - TxRateIdx = MCS15; 2081 - else if (MCS14 && (Rssi >= (-72+RssiOffset))) 2082 - TxRateIdx = MCS14; 2083 - else if (MCS13 && (Rssi >= (-76+RssiOffset))) 2084 - TxRateIdx = MCS13; 2085 - else if (MCS12 && (Rssi >= (-78+RssiOffset))) 2086 - TxRateIdx = MCS12; 2087 - else if (MCS4 && (Rssi >= (-82+RssiOffset))) 2088 - TxRateIdx = MCS4; 2089 - else if (MCS3 && (Rssi >= (-84+RssiOffset))) 2090 - TxRateIdx = MCS3; 2091 - else if (MCS2 && (Rssi >= (-86+RssiOffset))) 2092 - TxRateIdx = MCS2; 2093 - else if (MCS1 && (Rssi >= (-88+RssiOffset))) 2094 - TxRateIdx = MCS1; 2095 - else 2096 - TxRateIdx = MCS0; 2097 - } 2098 - else if ((pTable == RateSwitchTable11BGN1S) || (pTable == RateSwitchTable11N1S)) 2099 - {// N mode with 1 stream 2100 - if (MCS7 && (Rssi > (-72+RssiOffset))) 2101 - TxRateIdx = MCS7; 2102 - else if (MCS6 && (Rssi > (-74+RssiOffset))) 2103 - TxRateIdx = MCS6; 2104 - else if (MCS5 && (Rssi > (-77+RssiOffset))) 2105 - TxRateIdx = MCS5; 2106 - else if (MCS4 && (Rssi > (-79+RssiOffset))) 2107 - TxRateIdx = MCS4; 2108 - else if (MCS3 && (Rssi > (-81+RssiOffset))) 2109 - TxRateIdx = MCS3; 2110 - else if (MCS2 && (Rssi > (-83+RssiOffset))) 2111 - TxRateIdx = MCS2; 2112 - else if (MCS1 && (Rssi > (-86+RssiOffset))) 2113 - TxRateIdx = MCS1; 2114 - else 2115 - TxRateIdx = MCS0; 2116 - } 2117 - else 2118 - {// Legacy mode 2119 - if (MCS7 && (Rssi > -70)) 2120 - TxRateIdx = MCS7; 2121 - else if (MCS6 && (Rssi > -74)) 2122 - TxRateIdx = MCS6; 2123 - else if (MCS5 && (Rssi > -78)) 2124 - TxRateIdx = MCS5; 2125 - else if (MCS4 && (Rssi > -82)) 2126 - TxRateIdx = MCS4; 2127 - else if (MCS4 == 0) // for B-only mode 2128 - TxRateIdx = MCS3; 2129 - else if (MCS3 && (Rssi > -85)) 2130 - TxRateIdx = MCS3; 2131 - else if (MCS2 && (Rssi > -87)) 2132 - TxRateIdx = MCS2; 2133 - else if (MCS1 && (Rssi > -90)) 2134 - TxRateIdx = MCS1; 2135 - else 2136 - TxRateIdx = MCS0; 2137 - } 2138 - 2139 - { 2140 - pEntry->CurrTxRateIndex = TxRateIdx; 2141 - pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5]; 2142 - MlmeSetTxRate(pAd, pEntry, pNextTxRate); 2143 - } 2144 - 2145 - NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH); 2146 - NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH); 2147 - pEntry->fLastSecAccordingRSSI = TRUE; 2148 - // reset all OneSecTx counters 2149 - RESET_ONE_SEC_TX_CNT(pEntry); 2150 - 2151 - continue; 2152 - } 2153 - 2154 - if (pEntry->fLastSecAccordingRSSI == TRUE) 2155 - { 2156 - pEntry->fLastSecAccordingRSSI = FALSE; 2157 - pEntry->LastSecTxRateChangeAction = 0; 2158 - // reset all OneSecTx counters 2159 - RESET_ONE_SEC_TX_CNT(pEntry); 2160 - 2161 - continue; 2162 - } 2163 - 2164 - do 2165 - { 2166 - BOOLEAN bTrainUpDown = FALSE; 2167 - 2168 - pEntry->CurrTxRateStableTime ++; 2169 - 2170 - // downgrade TX quality if PER >= Rate-Down threshold 2171 - if (TxErrorRatio >= TrainDown) 2172 - { 2173 - bTrainUpDown = TRUE; 2174 - pEntry->TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND; 2175 - } 2176 - // upgrade TX quality if PER <= Rate-Up threshold 2177 - else if (TxErrorRatio <= TrainUp) 2178 - { 2179 - bTrainUpDown = TRUE; 2180 - bUpgradeQuality = TRUE; 2181 - if (pEntry->TxQuality[CurrRateIdx]) 2182 - pEntry->TxQuality[CurrRateIdx] --; // quality very good in CurrRate 2183 - 2184 - if (pEntry->TxRateUpPenalty) 2185 - pEntry->TxRateUpPenalty --; 2186 - else if (pEntry->TxQuality[UpRateIdx]) 2187 - pEntry->TxQuality[UpRateIdx] --; // may improve next UP rate's quality 2188 - } 2189 - 2190 - pEntry->PER[CurrRateIdx] = (UCHAR)TxErrorRatio; 2191 - 2192 - if (bTrainUpDown) 2193 - { 2194 - // perform DRS - consider TxRate Down first, then rate up. 2195 - if ((CurrRateIdx != DownRateIdx) && (pEntry->TxQuality[CurrRateIdx] >= DRS_TX_QUALITY_WORST_BOUND)) 2196 - { 2197 - pEntry->CurrTxRateIndex = DownRateIdx; 2198 - } 2199 - else if ((CurrRateIdx != UpRateIdx) && (pEntry->TxQuality[UpRateIdx] <= 0)) 2200 - { 2201 - pEntry->CurrTxRateIndex = UpRateIdx; 2202 - } 2203 - } 2204 - } while (FALSE); 2205 - 2206 - // if rate-up happen, clear all bad history of all TX rates 2207 - if (pEntry->CurrTxRateIndex > CurrRateIdx) 2208 - { 2209 - pEntry->CurrTxRateStableTime = 0; 2210 - pEntry->TxRateUpPenalty = 0; 2211 - pEntry->LastSecTxRateChangeAction = 1; // rate UP 2212 - NdisZeroMemory(pEntry->TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH); 2213 - NdisZeroMemory(pEntry->PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH); 2214 - 2215 - // 2216 - // For TxRate fast train up 2217 - // 2218 - if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) 2219 - { 2220 - RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100); 2221 - 2222 - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE; 2223 - } 2224 - bTxRateChanged = TRUE; 2225 - } 2226 - // if rate-down happen, only clear DownRate's bad history 2227 - else if (pEntry->CurrTxRateIndex < CurrRateIdx) 2228 - { 2229 - pEntry->CurrTxRateStableTime = 0; 2230 - pEntry->TxRateUpPenalty = 0; // no penalty 2231 - pEntry->LastSecTxRateChangeAction = 2; // rate DOWN 2232 - pEntry->TxQuality[pEntry->CurrTxRateIndex] = 0; 2233 - pEntry->PER[pEntry->CurrTxRateIndex] = 0; 2234 - 2235 - // 2236 - // For TxRate fast train down 2237 - // 2238 - if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) 2239 - { 2240 - RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100); 2241 - 2242 - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = TRUE; 2243 - } 2244 - bTxRateChanged = TRUE; 2245 - } 2246 - else 2247 - { 2248 - pEntry->LastSecTxRateChangeAction = 0; // rate no change 2249 - bTxRateChanged = FALSE; 2250 - } 2251 - 2252 - pEntry->LastTxOkCount = TxSuccess; 2253 - 2254 - // reset all OneSecTx counters 2255 - RESET_ONE_SEC_TX_CNT(pEntry); 2256 - 2257 - pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pEntry->CurrTxRateIndex+1)*5]; 2258 - if (bTxRateChanged && pNextTxRate) 2259 - { 2260 - MlmeSetTxRate(pAd, pEntry, pNextTxRate); 2261 - } 2262 - } 2263 - } 2264 - 2265 - /* 2266 - ======================================================================== 2267 - Routine Description: 2268 - Station side, Auto TxRate faster train up timer call back function. 2269 - 2270 - Arguments: 2271 - SystemSpecific1 - Not used. 2272 - FunctionContext - Pointer to our Adapter context. 2273 - SystemSpecific2 - Not used. 2274 - SystemSpecific3 - Not used. 2275 - 2276 - Return Value: 2277 - None 2278 - 2279 - ======================================================================== 2280 - */ 2281 - VOID StaQuickResponeForRateUpExec( 2282 - IN PVOID SystemSpecific1, 2283 - IN PVOID FunctionContext, 2284 - IN PVOID SystemSpecific2, 2285 - IN PVOID SystemSpecific3) 2286 - { 2287 - PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext; 2288 - UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0; 2289 - ULONG TxTotalCnt; 2290 - ULONG TxErrorRatio = 0; 2291 - BOOLEAN bTxRateChanged; //, bUpgradeQuality = FALSE; 2292 - PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL; 2293 - PUCHAR pTable; 2294 - UCHAR TableSize = 0; 2295 - UCHAR InitTxRateIdx = 0, TrainUp, TrainDown; 2296 - TX_STA_CNT1_STRUC StaTx1; 2297 - TX_STA_CNT0_STRUC TxStaCnt0; 2298 - CHAR Rssi, ratio; 2299 - ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0; 2300 - MAC_TABLE_ENTRY *pEntry; 2301 - ULONG i; 2302 - 2303 - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE; 2304 - 2305 - // 2306 - // walk through MAC table, see if need to change AP's TX rate toward each entry 2307 - // 2308 - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) 2309 - { 2310 - pEntry = &pAd->MacTab.Content[i]; 2311 - 2312 - // check if this entry need to switch rate automatically 2313 - if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE) 2314 - continue; 2315 - 2316 - if (INFRA_ON(pAd) && (i == 1)) 2317 - Rssi = RTMPMaxRssi(pAd, 2318 - pAd->StaCfg.RssiSample.AvgRssi0, 2319 - pAd->StaCfg.RssiSample.AvgRssi1, 2320 - pAd->StaCfg.RssiSample.AvgRssi2); 2321 - else 2322 - Rssi = RTMPMaxRssi(pAd, 2323 - pEntry->RssiSample.AvgRssi0, 2324 - pEntry->RssiSample.AvgRssi1, 2325 - pEntry->RssiSample.AvgRssi2); 2326 - 2327 - CurrRateIdx = pAd->CommonCfg.TxRateIndex; 2328 - 2329 - MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, &InitTxRateIdx); 2330 - 2331 - // decide the next upgrade rate and downgrade rate, if any 2332 - if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) 2333 - { 2334 - UpRateIdx = CurrRateIdx + 1; 2335 - DownRateIdx = CurrRateIdx -1; 2336 - } 2337 - else if (CurrRateIdx == 0) 2338 - { 2339 - UpRateIdx = CurrRateIdx + 1; 2340 - DownRateIdx = CurrRateIdx; 2341 - } 2342 - else if (CurrRateIdx == (TableSize - 1)) 2343 - { 2344 - UpRateIdx = CurrRateIdx; 2345 - DownRateIdx = CurrRateIdx - 1; 2346 - } 2347 - 2348 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5]; 2349 - 2350 - if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) 2351 - { 2352 - TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1)); 2353 - TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1)); 2354 - } 2355 - else 2356 - { 2357 - TrainUp = pCurrTxRate->TrainUp; 2358 - TrainDown = pCurrTxRate->TrainDown; 2359 - } 2360 - 2361 - if (pAd->MacTab.Size == 1) 2362 - { 2363 - // Update statistic counter 2364 - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); 2365 - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); 2366 - 2367 - TxRetransmit = StaTx1.field.TxRetransmit; 2368 - TxSuccess = StaTx1.field.TxSuccess; 2369 - TxFailCount = TxStaCnt0.field.TxFailCount; 2370 - TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount; 2371 - 2372 - pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit; 2373 - pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess; 2374 - pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount; 2375 - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess; 2376 - pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit; 2377 - pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount; 2378 - 2379 - if (TxTotalCnt) 2380 - TxErrorRatio = ((TxRetransmit + TxFailCount) * 100) / TxTotalCnt; 2381 - } 2382 - else 2383 - { 2384 - TxTotalCnt = pEntry->OneSecTxNoRetryOkCount + 2385 - pEntry->OneSecTxRetryOkCount + 2386 - pEntry->OneSecTxFailCount; 2387 - 2388 - if (TxTotalCnt) 2389 - TxErrorRatio = ((pEntry->OneSecTxRetryOkCount + pEntry->OneSecTxFailCount) * 100) / TxTotalCnt; 2390 - } 2391 - 2392 - 2393 - // 2394 - // CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI 2395 - // (criteria copied from RT2500 for Netopia case) 2396 - // 2397 - if (TxTotalCnt <= 12) 2398 - { 2399 - NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH); 2400 - NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH); 2401 - 2402 - if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx)) 2403 - { 2404 - pAd->CommonCfg.TxRateIndex = DownRateIdx; 2405 - pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND; 2406 - } 2407 - else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx)) 2408 - { 2409 - pAd->CommonCfg.TxRateIndex = UpRateIdx; 2410 - } 2411 - 2412 - DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: TxTotalCnt <= 15, train back to original rate \n")); 2413 - return; 2414 - } 2415 - 2416 - do 2417 - { 2418 - ULONG OneSecTxNoRetryOKRationCount; 2419 - 2420 - if (pAd->DrsCounters.LastTimeTxRateChangeAction == 0) 2421 - ratio = 5; 2422 - else 2423 - ratio = 4; 2424 - 2425 - // downgrade TX quality if PER >= Rate-Down threshold 2426 - if (TxErrorRatio >= TrainDown) 2427 - { 2428 - pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND; 2429 - } 2430 - 2431 - pAd->DrsCounters.PER[CurrRateIdx] = (UCHAR)TxErrorRatio; 2432 - 2433 - OneSecTxNoRetryOKRationCount = (TxSuccess * ratio); 2434 - 2435 - // perform DRS - consider TxRate Down first, then rate up. 2436 - if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) && (CurrRateIdx != DownRateIdx)) 2437 - { 2438 - if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount) 2439 - { 2440 - pAd->CommonCfg.TxRateIndex = DownRateIdx; 2441 - pAd->DrsCounters.TxQuality[CurrRateIdx] = DRS_TX_QUALITY_WORST_BOUND; 2442 - 2443 - } 2444 - 2445 - } 2446 - else if ((pAd->DrsCounters.LastSecTxRateChangeAction == 2) && (CurrRateIdx != UpRateIdx)) 2447 - { 2448 - if ((TxErrorRatio >= 50) || (TxErrorRatio >= TrainDown)) 2449 - { 2450 - 2451 - } 2452 - else if ((pAd->DrsCounters.LastTxOkCount + 2) >= OneSecTxNoRetryOKRationCount) 2453 - { 2454 - pAd->CommonCfg.TxRateIndex = UpRateIdx; 2455 - } 2456 - } 2457 - }while (FALSE); 2458 - 2459 - // if rate-up happen, clear all bad history of all TX rates 2460 - if (pAd->CommonCfg.TxRateIndex > CurrRateIdx) 2461 - { 2462 - pAd->DrsCounters.TxRateUpPenalty = 0; 2463 - NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH); 2464 - NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH); 2465 - bTxRateChanged = TRUE; 2466 - } 2467 - // if rate-down happen, only clear DownRate's bad history 2468 - else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx) 2469 - { 2470 - DBGPRINT_RAW(RT_DEBUG_TRACE,("QuickDRS: --TX rate from %d to %d \n", CurrRateIdx, pAd->CommonCfg.TxRateIndex)); 2471 - 2472 - pAd->DrsCounters.TxRateUpPenalty = 0; // no penalty 2473 - pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] = 0; 2474 - pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0; 2475 - bTxRateChanged = TRUE; 2476 - } 2477 - else 2478 - { 2479 - bTxRateChanged = FALSE; 2480 - } 2481 - 2482 - pNextTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(pAd->CommonCfg.TxRateIndex+1)*5]; 2483 - if (bTxRateChanged && pNextTxRate) 2484 - { 2485 - MlmeSetTxRate(pAd, pEntry, pNextTxRate); 2486 - } 2487 - } 2488 - } 2489 - 2490 - /* 2491 - ========================================================================== 2492 - Description: 2493 - This routine is executed periodically inside MlmePeriodicExec() after 2494 - association with an AP. 2495 - It checks if StaCfg.Psm is consistent with user policy (recorded in 2496 - StaCfg.WindowsPowerMode). If not, enforce user policy. However, 2497 - there're some conditions to consider: 2498 - 1. we don't support power-saving in ADHOC mode, so Psm=PWR_ACTIVE all 2499 - the time when Mibss==TRUE 2500 - 2. When link up in INFRA mode, Psm should not be switch to PWR_SAVE 2501 - if outgoing traffic available in TxRing or MgmtRing. 2502 - Output: 2503 - 1. change pAd->StaCfg.Psm to PWR_SAVE or leave it untouched 2504 - 2505 - IRQL = DISPATCH_LEVEL 2506 - 2507 - ========================================================================== 2508 - */ 2509 - VOID MlmeCheckPsmChange( 2510 - IN PRTMP_ADAPTER pAd, 2511 - IN ULONG Now32) 2512 - { 2513 - ULONG PowerMode; 2514 - 2515 - // condition - 2516 - // 1. Psm maybe ON only happen in INFRASTRUCTURE mode 2517 - // 2. user wants either MAX_PSP or FAST_PSP 2518 - // 3. but current psm is not in PWR_SAVE 2519 - // 4. CNTL state machine is not doing SCANning 2520 - // 5. no TX SUCCESS event for the past 1-sec period 2521 - #ifdef NDIS51_MINIPORT 2522 - if (pAd->StaCfg.WindowsPowerProfile == NdisPowerProfileBattery) 2523 - PowerMode = pAd->StaCfg.WindowsBatteryPowerMode; 2524 - else 2525 - #endif 2526 - PowerMode = pAd->StaCfg.WindowsPowerMode; 2527 - 2528 - if (INFRA_ON(pAd) && 2529 - (PowerMode != Ndis802_11PowerModeCAM) && 2530 - (pAd->StaCfg.Psm == PWR_ACTIVE) && 2531 - #ifndef RT30xx 2532 - (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)) 2533 - { 2534 - NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime); 2535 - pAd->RalinkCounters.RxCountSinceLastNULL = 0; 2536 - MlmeSetPsmBit(pAd, PWR_SAVE); 2537 - if (!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) 2538 - { 2539 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); 2540 - } 2541 - else 2542 - { 2543 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); 2544 - } 2545 - } 2546 - #endif 2547 - #ifdef RT30xx 2548 - // (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) 2549 - (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) /*&& 2550 - (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && 2551 - (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)*/) 2552 - { 2553 - // add by johnli, use Rx OK data count per second to calculate throughput 2554 - // If Ttraffic is too high ( > 400 Rx per second), don't go to sleep mode. If tx rate is low, use low criteria 2555 - // Mode=CCK/MCS=3 => 11 Mbps, Mode=OFDM/MCS=3 => 18 Mbps 2556 - if (((pAd->StaCfg.HTPhyMode.field.MCS <= 3) && 2557 - /* Iverson mark 2558 - (pAd->StaCfg.HTPhyMode.field.MODE <= MODE_OFDM) && 2559 - */ 2560 - (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)100)) || 2561 - ((pAd->StaCfg.HTPhyMode.field.MCS > 3) && 2562 - /* Iverson mark 2563 - (pAd->StaCfg.HTPhyMode.field.MODE > MODE_OFDM) && 2564 - */ 2565 - (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)400))) 2566 - { 2567 - // Get this time 2568 - NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime); 2569 - pAd->RalinkCounters.RxCountSinceLastNULL = 0; 2570 - MlmeSetPsmBit(pAd, PWR_SAVE); 2571 - if (!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) 2572 - { 2573 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); 2574 - } 2575 - else 2576 - { 2577 - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); 2578 - } 2579 - } 2580 - } 2581 - #endif 2582 - } 2583 - 2584 - // IRQL = PASSIVE_LEVEL 2585 - // IRQL = DISPATCH_LEVEL 2586 - VOID MlmeSetPsmBit( 2587 - IN PRTMP_ADAPTER pAd, 2588 - IN USHORT psm) 2589 - { 2590 - AUTO_RSP_CFG_STRUC csr4; 2591 - 2592 - pAd->StaCfg.Psm = psm; 2593 - RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word); 2594 - csr4.field.AckCtsPsmBit = (psm == PWR_SAVE)? 1:0; 2595 - RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word); 2596 - #ifndef RT30xx 2597 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetPsmBit = %d\n", psm)); 2598 - #endif 2599 - } 2600 - 2601 - // IRQL = DISPATCH_LEVEL 2602 - VOID MlmeSetTxPreamble( 2603 - IN PRTMP_ADAPTER pAd, 2604 - IN USHORT TxPreamble) 2605 - { 2606 - AUTO_RSP_CFG_STRUC csr4; 2607 - 2608 - // 2609 - // Always use Long preamble before verifiation short preamble functionality works well. 2610 - // Todo: remove the following line if short preamble functionality works 2611 - // 2612 - //TxPreamble = Rt802_11PreambleLong; 2613 - 2614 - RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word); 2615 - if (TxPreamble == Rt802_11PreambleLong) 2616 - { 2617 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= LONG PREAMBLE)\n")); 2618 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); 2619 - csr4.field.AutoResponderPreamble = 0; 2620 - } 2621 - else 2622 - { 2623 - // NOTE: 1Mbps should always use long preamble 2624 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetTxPreamble (= SHORT PREAMBLE)\n")); 2625 - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); 2626 - csr4.field.AutoResponderPreamble = 1; 2627 - } 2628 - 2629 - RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word); 2630 - } 2631 - 2632 - /* 2633 - ========================================================================== 2634 - Description: 2635 - Update basic rate bitmap 2636 - ========================================================================== 2637 - */ 2638 - 2639 - VOID UpdateBasicRateBitmap( 2640 - IN PRTMP_ADAPTER pAdapter) 2641 - { 2642 - INT i, j; 2643 - /* 1 2 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */ 2644 - UCHAR rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 }; 2645 - UCHAR *sup_p = pAdapter->CommonCfg.SupRate; 2646 - UCHAR *ext_p = pAdapter->CommonCfg.ExtRate; 2647 - ULONG bitmap = pAdapter->CommonCfg.BasicRateBitmap; 2648 - 2649 - 2650 - /* if A mode, always use fix BasicRateBitMap */ 2651 - //if (pAdapter->CommonCfg.Channel == PHY_11A) 2652 - if (pAdapter->CommonCfg.Channel > 14) 2653 - pAdapter->CommonCfg.BasicRateBitmap = 0x150; /* 6, 12, 24M */ 2654 - /* End of if */ 2655 - 2656 - if (pAdapter->CommonCfg.BasicRateBitmap > 4095) 2657 - { 2658 - /* (2 ^ MAX_LEN_OF_SUPPORTED_RATES) -1 */ 2659 - return; 2660 - } /* End of if */ 2661 - 2662 - for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++) 2663 - { 2664 - sup_p[i] &= 0x7f; 2665 - ext_p[i] &= 0x7f; 2666 - } /* End of for */ 2667 - 2668 - for(i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++) 2669 - { 2670 - if (bitmap & (1 << i)) 2671 - { 2672 - for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++) 2673 - { 2674 - if (sup_p[j] == rate[i]) 2675 - sup_p[j] |= 0x80; 2676 - /* End of if */ 2677 - } /* End of for */ 2678 - 2679 - for(j=0; j<MAX_LEN_OF_SUPPORTED_RATES; j++) 2680 - { 2681 - if (ext_p[j] == rate[i]) 2682 - ext_p[j] |= 0x80; 2683 - /* End of if */ 2684 - } /* End of for */ 2685 - } /* End of if */ 2686 - } /* End of for */ 2687 - } /* End of UpdateBasicRateBitmap */ 2688 - 2689 - // IRQL = PASSIVE_LEVEL 2690 - // IRQL = DISPATCH_LEVEL 2691 - // bLinkUp is to identify the inital link speed. 2692 - // TRUE indicates the rate update at linkup, we should not try to set the rate at 54Mbps. 2693 - VOID MlmeUpdateTxRates( 2694 - IN PRTMP_ADAPTER pAd, 2695 - IN BOOLEAN bLinkUp, 2696 - IN UCHAR apidx) 2697 - { 2698 - int i, num; 2699 - UCHAR Rate = RATE_6, MaxDesire = RATE_1, MaxSupport = RATE_1; 2700 - UCHAR MinSupport = RATE_54; 2701 - ULONG BasicRateBitmap = 0; 2702 - UCHAR CurrBasicRate = RATE_1; 2703 - UCHAR *pSupRate, SupRateLen, *pExtRate, ExtRateLen; 2704 - PHTTRANSMIT_SETTING pHtPhy = NULL; 2705 - PHTTRANSMIT_SETTING pMaxHtPhy = NULL; 2706 - PHTTRANSMIT_SETTING pMinHtPhy = NULL; 2707 - BOOLEAN *auto_rate_cur_p; 2708 - UCHAR HtMcs = MCS_AUTO; 2709 - 2710 - // find max desired rate 2711 - UpdateBasicRateBitmap(pAd); 2712 - 2713 - num = 0; 2714 - auto_rate_cur_p = NULL; 2715 - for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++) 2716 - { 2717 - switch (pAd->CommonCfg.DesireRate[i] & 0x7f) 2718 - { 2719 - case 2: Rate = RATE_1; num++; break; 2720 - case 4: Rate = RATE_2; num++; break; 2721 - case 11: Rate = RATE_5_5; num++; break; 2722 - case 22: Rate = RATE_11; num++; break; 2723 - case 12: Rate = RATE_6; num++; break; 2724 - case 18: Rate = RATE_9; num++; break; 2725 - case 24: Rate = RATE_12; num++; break; 2726 - case 36: Rate = RATE_18; num++; break; 2727 - case 48: Rate = RATE_24; num++; break; 2728 - case 72: Rate = RATE_36; num++; break; 2729 - case 96: Rate = RATE_48; num++; break; 2730 - case 108: Rate = RATE_54; num++; break; 2731 - //default: Rate = RATE_1; break; 2732 - } 2733 - if (MaxDesire < Rate) MaxDesire = Rate; 2734 - } 2735 - 2736 - //=========================================================================== 2737 - //=========================================================================== 2738 - { 2739 - pHtPhy = &pAd->StaCfg.HTPhyMode; 2740 - pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode; 2741 - pMinHtPhy = &pAd->StaCfg.MinHTPhyMode; 2742 - 2743 - auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch; 2744 - HtMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS; 2745 - 2746 - if ((pAd->StaCfg.BssType == BSS_ADHOC) && 2747 - (pAd->CommonCfg.PhyMode == PHY_11B) && 2748 - (MaxDesire > RATE_11)) 2749 - { 2750 - MaxDesire = RATE_11; 2751 - } 2752 - } 2753 - 2754 - pAd->CommonCfg.MaxDesiredRate = MaxDesire; 2755 - pMinHtPhy->word = 0; 2756 - pMaxHtPhy->word = 0; 2757 - pHtPhy->word = 0; 2758 - 2759 - // Auto rate switching is enabled only if more than one DESIRED RATES are 2760 - // specified; otherwise disabled 2761 - if (num <= 1) 2762 - { 2763 - *auto_rate_cur_p = FALSE; 2764 - } 2765 - else 2766 - { 2767 - *auto_rate_cur_p = TRUE; 2768 - } 2769 - 2770 - #if 1 2771 - if (HtMcs != MCS_AUTO) 2772 - { 2773 - *auto_rate_cur_p = FALSE; 2774 - } 2775 - else 2776 - { 2777 - *auto_rate_cur_p = TRUE; 2778 - } 2779 - #endif 2780 - 2781 - if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) 2782 - { 2783 - pSupRate = &pAd->StaActive.SupRate[0]; 2784 - pExtRate = &pAd->StaActive.ExtRate[0]; 2785 - SupRateLen = pAd->StaActive.SupRateLen; 2786 - ExtRateLen = pAd->StaActive.ExtRateLen; 2787 - } 2788 - else 2789 - { 2790 - pSupRate = &pAd->CommonCfg.SupRate[0]; 2791 - pExtRate = &pAd->CommonCfg.ExtRate[0]; 2792 - SupRateLen = pAd->CommonCfg.SupRateLen; 2793 - ExtRateLen = pAd->CommonCfg.ExtRateLen; 2794 - } 2795 - 2796 - // find max supported rate 2797 - for (i=0; i<SupRateLen; i++) 2798 - { 2799 - switch (pSupRate[i] & 0x7f) 2800 - { 2801 - case 2: Rate = RATE_1; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0001; break; 2802 - case 4: Rate = RATE_2; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0002; break; 2803 - case 11: Rate = RATE_5_5; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0004; break; 2804 - case 22: Rate = RATE_11; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0008; break; 2805 - case 12: Rate = RATE_6; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break; 2806 - case 18: Rate = RATE_9; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0020; break; 2807 - case 24: Rate = RATE_12; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break; 2808 - case 36: Rate = RATE_18; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0080; break; 2809 - case 48: Rate = RATE_24; /*if (pSupRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break; 2810 - case 72: Rate = RATE_36; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0200; break; 2811 - case 96: Rate = RATE_48; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0400; break; 2812 - case 108: Rate = RATE_54; if (pSupRate[i] & 0x80) BasicRateBitmap |= 0x0800; break; 2813 - default: Rate = RATE_1; break; 2814 - } 2815 - if (MaxSupport < Rate) MaxSupport = Rate; 2816 - 2817 - if (MinSupport > Rate) MinSupport = Rate; 2818 - } 2819 - 2820 - for (i=0; i<ExtRateLen; i++) 2821 - { 2822 - switch (pExtRate[i] & 0x7f) 2823 - { 2824 - case 2: Rate = RATE_1; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0001; break; 2825 - case 4: Rate = RATE_2; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0002; break; 2826 - case 11: Rate = RATE_5_5; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0004; break; 2827 - case 22: Rate = RATE_11; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0008; break; 2828 - case 12: Rate = RATE_6; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0010; break; 2829 - case 18: Rate = RATE_9; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0020; break; 2830 - case 24: Rate = RATE_12; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0040; break; 2831 - case 36: Rate = RATE_18; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0080; break; 2832 - case 48: Rate = RATE_24; /*if (pExtRate[i] & 0x80)*/ BasicRateBitmap |= 0x0100; break; 2833 - case 72: Rate = RATE_36; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0200; break; 2834 - case 96: Rate = RATE_48; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0400; break; 2835 - case 108: Rate = RATE_54; if (pExtRate[i] & 0x80) BasicRateBitmap |= 0x0800; break; 2836 - default: Rate = RATE_1; break; 2837 - } 2838 - if (MaxSupport < Rate) MaxSupport = Rate; 2839 - 2840 - if (MinSupport > Rate) MinSupport = Rate; 2841 - } 2842 - 2843 - RTMP_IO_WRITE32(pAd, LEGACY_BASIC_RATE, BasicRateBitmap); 2844 - 2845 - // calculate the exptected ACK rate for each TX rate. This info is used to caculate 2846 - // the DURATION field of outgoing uniicast DATA/MGMT frame 2847 - for (i=0; i<MAX_LEN_OF_SUPPORTED_RATES; i++) 2848 - { 2849 - if (BasicRateBitmap & (0x01 << i)) 2850 - CurrBasicRate = (UCHAR)i; 2851 - pAd->CommonCfg.ExpectedACKRate[i] = CurrBasicRate; 2852 - } 2853 - 2854 - DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateTxRates[MaxSupport = %d] = MaxDesire %d Mbps\n", RateIdToMbps[MaxSupport], RateIdToMbps[MaxDesire])); 2855 - // max tx rate = min {max desire rate, max supported rate} 2856 - if (MaxSupport < MaxDesire) 2857 - pAd->CommonCfg.MaxTxRate = MaxSupport; 2858 - else 2859 - pAd->CommonCfg.MaxTxRate = MaxDesire; 2860 - 2861 - pAd->CommonCfg.MinTxRate = MinSupport; 2862 - if (*auto_rate_cur_p) 2863 - { 2864 - short dbm = 0; 2865 - 2866 - dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta; 2867 - 2868 - if (bLinkUp == TRUE) 2869 - pAd->CommonCfg.TxRate = RATE_24; 2870 - else 2871 - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; 2872 - 2873 - if (dbm < -75) 2874 - pAd->CommonCfg.TxRate = RATE_11; 2875 - else if (dbm < -70) 2876 - pAd->CommonCfg.TxRate = RATE_24; 2877 - 2878 - // should never exceed MaxTxRate (consider 11B-only mode) 2879 - if (pAd->CommonCfg.TxRate > pAd->CommonCfg.MaxTxRate) 2880 - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; 2881 - 2882 - pAd->CommonCfg.TxRateIndex = 0; 2883 - } 2884 - else 2885 - { 2886 - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; 2887 - pHtPhy->field.MCS = (pAd->CommonCfg.MaxTxRate > 3) ? (pAd->CommonCfg.MaxTxRate - 4) : pAd->CommonCfg.MaxTxRate; 2888 - pHtPhy->field.MODE = (pAd->CommonCfg.MaxTxRate > 3) ? MODE_OFDM : MODE_CCK; 2889 - 2890 - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC = pHtPhy->field.STBC; 2891 - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI = pHtPhy->field.ShortGI; 2892 - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS = pHtPhy->field.MCS; 2893 - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE = pHtPhy->field.MODE; 2894 - } 2895 - 2896 - if (pAd->CommonCfg.TxRate <= RATE_11) 2897 - { 2898 - pMaxHtPhy->field.MODE = MODE_CCK; 2899 - pMaxHtPhy->field.MCS = pAd->CommonCfg.TxRate; 2900 - pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate; 2901 - } 2902 - else 2903 - { 2904 - pMaxHtPhy->field.MODE = MODE_OFDM; 2905 - pMaxHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.TxRate]; 2906 - if (pAd->CommonCfg.MinTxRate >= RATE_6 && (pAd->CommonCfg.MinTxRate <= RATE_54)) 2907 - {pMinHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MinTxRate];} 2908 - else 2909 - {pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;} 2910 - } 2911 - 2912 - pHtPhy->word = (pMaxHtPhy->word); 2913 - if (bLinkUp && (pAd->OpMode == OPMODE_STA)) 2914 - { 2915 - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word = pHtPhy->word; 2916 - pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word = pMaxHtPhy->word; 2917 - pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word = pMinHtPhy->word; 2918 - } 2919 - else 2920 - { 2921 - switch (pAd->CommonCfg.PhyMode) 2922 - { 2923 - case PHY_11BG_MIXED: 2924 - case PHY_11B: 2925 - case PHY_11BGN_MIXED: 2926 - pAd->CommonCfg.MlmeRate = RATE_1; 2927 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; 2928 - pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1; 2929 - 2930 - pAd->CommonCfg.RtsRate = RATE_11; 2931 - break; 2932 - case PHY_11G: 2933 - case PHY_11A: 2934 - case PHY_11AGN_MIXED: 2935 - case PHY_11GN_MIXED: 2936 - case PHY_11N_2_4G: 2937 - case PHY_11AN_MIXED: 2938 - case PHY_11N_5G: 2939 - pAd->CommonCfg.MlmeRate = RATE_6; 2940 - pAd->CommonCfg.RtsRate = RATE_6; 2941 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; 2942 - pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; 2943 - break; 2944 - case PHY_11ABG_MIXED: 2945 - case PHY_11ABGN_MIXED: 2946 - if (pAd->CommonCfg.Channel <= 14) 2947 - { 2948 - pAd->CommonCfg.MlmeRate = RATE_1; 2949 - pAd->CommonCfg.RtsRate = RATE_1; 2950 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; 2951 - pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1; 2952 - } 2953 - else 2954 - { 2955 - pAd->CommonCfg.MlmeRate = RATE_6; 2956 - pAd->CommonCfg.RtsRate = RATE_6; 2957 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; 2958 - pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; 2959 - } 2960 - break; 2961 - default: // error 2962 - pAd->CommonCfg.MlmeRate = RATE_6; 2963 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; 2964 - pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; 2965 - pAd->CommonCfg.RtsRate = RATE_1; 2966 - break; 2967 - } 2968 - // 2969 - // Keep Basic Mlme Rate. 2970 - // 2971 - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.word = pAd->CommonCfg.MlmeTransmit.word; 2972 - if (pAd->CommonCfg.MlmeTransmit.field.MODE == MODE_OFDM) 2973 - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[RATE_24]; 2974 - else 2975 - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = RATE_1; 2976 - pAd->CommonCfg.BasicMlmeRate = pAd->CommonCfg.MlmeRate; 2977 - } 2978 - 2979 - DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (MaxDesire=%d, MaxSupport=%d, MaxTxRate=%d, MinRate=%d, Rate Switching =%d)\n", 2980 - RateIdToMbps[MaxDesire], RateIdToMbps[MaxSupport], RateIdToMbps[pAd->CommonCfg.MaxTxRate], RateIdToMbps[pAd->CommonCfg.MinTxRate], 2981 - /*OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)*/*auto_rate_cur_p)); 2982 - DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (TxRate=%d, RtsRate=%d, BasicRateBitmap=0x%04lx)\n", 2983 - RateIdToMbps[pAd->CommonCfg.TxRate], RateIdToMbps[pAd->CommonCfg.RtsRate], BasicRateBitmap)); 2984 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateTxRates (MlmeTransmit=0x%x, MinHTPhyMode=%x, MaxHTPhyMode=0x%x, HTPhyMode=0x%x)\n", 2985 - pAd->CommonCfg.MlmeTransmit.word, pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word )); 2986 - } 2987 - 2988 - /* 2989 - ========================================================================== 2990 - Description: 2991 - This function update HT Rate setting. 2992 - Input Wcid value is valid for 2 case : 2993 - 1. it's used for Station in infra mode that copy AP rate to Mactable. 2994 - 2. OR Station in adhoc mode to copy peer's HT rate to Mactable. 2995 - 2996 - IRQL = DISPATCH_LEVEL 2997 - 2998 - ========================================================================== 2999 - */ 3000 - VOID MlmeUpdateHtTxRates( 3001 - IN PRTMP_ADAPTER pAd, 3002 - IN UCHAR apidx) 3003 - { 3004 - UCHAR StbcMcs; //j, StbcMcs, bitmask; 3005 - CHAR i; // 3*3 3006 - RT_HT_CAPABILITY *pRtHtCap = NULL; 3007 - RT_HT_PHY_INFO *pActiveHtPhy = NULL; 3008 - ULONG BasicMCS; 3009 - UCHAR j, bitmask; 3010 - PRT_HT_PHY_INFO pDesireHtPhy = NULL; 3011 - PHTTRANSMIT_SETTING pHtPhy = NULL; 3012 - PHTTRANSMIT_SETTING pMaxHtPhy = NULL; 3013 - PHTTRANSMIT_SETTING pMinHtPhy = NULL; 3014 - BOOLEAN *auto_rate_cur_p; 3015 - 3016 - DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates===> \n")); 3017 - 3018 - auto_rate_cur_p = NULL; 3019 - 3020 - { 3021 - pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; 3022 - pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; 3023 - pHtPhy = &pAd->StaCfg.HTPhyMode; 3024 - pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode; 3025 - pMinHtPhy = &pAd->StaCfg.MinHTPhyMode; 3026 - 3027 - auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch; 3028 - } 3029 - 3030 - if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) 3031 - { 3032 - if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) 3033 - return; 3034 - 3035 - pRtHtCap = &pAd->StaActive.SupportedHtPhy; 3036 - pActiveHtPhy = &pAd->StaActive.SupportedPhyInfo; 3037 - StbcMcs = (UCHAR)pAd->MlmeAux.AddHtInfo.AddHtInfo3.StbcMcs; 3038 - BasicMCS =pAd->MlmeAux.AddHtInfo.MCSSet[0]+(pAd->MlmeAux.AddHtInfo.MCSSet[1]<<8)+(StbcMcs<<16); 3039 - if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2)) 3040 - pMaxHtPhy->field.STBC = STBC_USE; 3041 - else 3042 - pMaxHtPhy->field.STBC = STBC_NONE; 3043 - } 3044 - else 3045 - { 3046 - if (pDesireHtPhy->bHtEnable == FALSE) 3047 - return; 3048 - 3049 - pRtHtCap = &pAd->CommonCfg.DesiredHtPhy; 3050 - StbcMcs = (UCHAR)pAd->CommonCfg.AddHTInfo.AddHtInfo3.StbcMcs; 3051 - BasicMCS = pAd->CommonCfg.AddHTInfo.MCSSet[0]+(pAd->CommonCfg.AddHTInfo.MCSSet[1]<<8)+(StbcMcs<<16); 3052 - if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) && (pAd->Antenna.field.TxPath == 2)) 3053 - pMaxHtPhy->field.STBC = STBC_USE; 3054 - else 3055 - pMaxHtPhy->field.STBC = STBC_NONE; 3056 - } 3057 - 3058 - // Decide MAX ht rate. 3059 - if ((pRtHtCap->GF) && (pAd->CommonCfg.DesiredHtPhy.GF)) 3060 - pMaxHtPhy->field.MODE = MODE_HTGREENFIELD; 3061 - else 3062 - pMaxHtPhy->field.MODE = MODE_HTMIX; 3063 - 3064 - if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth) && (pRtHtCap->ChannelWidth)) 3065 - pMaxHtPhy->field.BW = BW_40; 3066 - else 3067 - pMaxHtPhy->field.BW = BW_20; 3068 - 3069 - if (pMaxHtPhy->field.BW == BW_20) 3070 - pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 & pRtHtCap->ShortGIfor20); 3071 - else 3072 - pMaxHtPhy->field.ShortGI = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 & pRtHtCap->ShortGIfor40); 3073 - 3074 - for (i=23; i>=0; i--) // 3*3 3075 - { 3076 - j = i/8; 3077 - bitmask = (1<<(i-(j*8))); 3078 - 3079 - if ((pActiveHtPhy->MCSSet[j] & bitmask) && (pDesireHtPhy->MCSSet[j] & bitmask)) 3080 - { 3081 - pMaxHtPhy->field.MCS = i; 3082 - break; 3083 - } 3084 - 3085 - if (i==0) 3086 - break; 3087 - } 3088 - 3089 - // Copy MIN ht rate. rt2860??? 3090 - pMinHtPhy->field.BW = BW_20; 3091 - pMinHtPhy->field.MCS = 0; 3092 - pMinHtPhy->field.STBC = 0; 3093 - pMinHtPhy->field.ShortGI = 0; 3094 - //If STA assigns fixed rate. update to fixed here. 3095 - if ( (pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff)) 3096 - { 3097 - if (pDesireHtPhy->MCSSet[4] != 0) 3098 - { 3099 - pMaxHtPhy->field.MCS = 32; 3100 - pMinHtPhy->field.MCS = 32; 3101 - DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== Use Fixed MCS = %d\n",pMinHtPhy->field.MCS)); 3102 - } 3103 - 3104 - for (i=23; (CHAR)i >= 0; i--) // 3*3 3105 - { 3106 - j = i/8; 3107 - bitmask = (1<<(i-(j*8))); 3108 - if ( (pDesireHtPhy->MCSSet[j] & bitmask) && (pActiveHtPhy->MCSSet[j] & bitmask)) 3109 - { 3110 - pMaxHtPhy->field.MCS = i; 3111 - pMinHtPhy->field.MCS = i; 3112 - break; 3113 - } 3114 - if (i==0) 3115 - break; 3116 - } 3117 - } 3118 - 3119 - // Decide ht rate 3120 - pHtPhy->field.STBC = pMaxHtPhy->field.STBC; 3121 - pHtPhy->field.BW = pMaxHtPhy->field.BW; 3122 - pHtPhy->field.MODE = pMaxHtPhy->field.MODE; 3123 - pHtPhy->field.MCS = pMaxHtPhy->field.MCS; 3124 - pHtPhy->field.ShortGI = pMaxHtPhy->field.ShortGI; 3125 - 3126 - // use default now. rt2860 3127 - if (pDesireHtPhy->MCSSet[0] != 0xff) 3128 - *auto_rate_cur_p = FALSE; 3129 - else 3130 - *auto_rate_cur_p = TRUE; 3131 - 3132 - DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateHtTxRates<---.AMsduSize = %d \n", pAd->CommonCfg.DesiredHtPhy.AmsduSize )); 3133 - DBGPRINT(RT_DEBUG_TRACE,("TX: MCS[0] = %x (choose %d), BW = %d, ShortGI = %d, MODE = %d, \n", pActiveHtPhy->MCSSet[0],pHtPhy->field.MCS, 3134 - pHtPhy->field.BW, pHtPhy->field.ShortGI, pHtPhy->field.MODE)); 3135 - DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== \n")); 3136 - } 3137 - 3138 - // IRQL = DISPATCH_LEVEL 3139 - VOID MlmeRadioOff( 3140 - IN PRTMP_ADAPTER pAd) 3141 - { 3142 - RT28XX_MLME_RADIO_OFF(pAd); 3143 - } 3144 - 3145 - // IRQL = DISPATCH_LEVEL 3146 - VOID MlmeRadioOn( 3147 - IN PRTMP_ADAPTER pAd) 3148 - { 3149 - RT28XX_MLME_RADIO_ON(pAd); 3150 - } 3151 - 3152 - // =========================================================================================== 3153 - // bss_table.c 3154 - // =========================================================================================== 3155 - 3156 - 3157 - /*! \brief initialize BSS table 3158 - * \param p_tab pointer to the table 3159 - * \return none 3160 - * \pre 3161 - * \post 3162 - 3163 - IRQL = PASSIVE_LEVEL 3164 - IRQL = DISPATCH_LEVEL 3165 - 3166 - */ 3167 - VOID BssTableInit( 3168 - IN BSS_TABLE *Tab) 3169 - { 3170 - int i; 3171 - 3172 - Tab->BssNr = 0; 3173 - Tab->BssOverlapNr = 0; 3174 - for (i = 0; i < MAX_LEN_OF_BSS_TABLE; i++) 3175 - { 3176 - NdisZeroMemory(&Tab->BssEntry[i], sizeof(BSS_ENTRY)); 3177 - Tab->BssEntry[i].Rssi = -127; // initial the rssi as a minimum value 3178 - } 3179 - } 3180 - 3181 - VOID BATableInit( 3182 - IN PRTMP_ADAPTER pAd, 3183 - IN BA_TABLE *Tab) 3184 - { 3185 - int i; 3186 - 3187 - Tab->numAsOriginator = 0; 3188 - Tab->numAsRecipient = 0; 3189 - NdisAllocateSpinLock(&pAd->BATabLock); 3190 - for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) 3191 - { 3192 - Tab->BARecEntry[i].REC_BA_Status = Recipient_NONE; 3193 - NdisAllocateSpinLock(&(Tab->BARecEntry[i].RxReRingLock)); 3194 - } 3195 - for (i = 0; i < MAX_LEN_OF_BA_ORI_TABLE; i++) 3196 - { 3197 - Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE; 3198 - } 3199 - } 3200 - 3201 - /*! \brief search the BSS table by SSID 3202 - * \param p_tab pointer to the bss table 3203 - * \param ssid SSID string 3204 - * \return index of the table, BSS_NOT_FOUND if not in the table 3205 - * \pre 3206 - * \post 3207 - * \note search by sequential search 3208 - 3209 - IRQL = DISPATCH_LEVEL 3210 - 3211 - */ 3212 - ULONG BssTableSearch( 3213 - IN BSS_TABLE *Tab, 3214 - IN PUCHAR pBssid, 3215 - IN UCHAR Channel) 3216 - { 3217 - UCHAR i; 3218 - 3219 - for (i = 0; i < Tab->BssNr; i++) 3220 - { 3221 - // 3222 - // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. 3223 - // We should distinguish this case. 3224 - // 3225 - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || 3226 - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && 3227 - MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid)) 3228 - { 3229 - return i; 3230 - } 3231 - } 3232 - return (ULONG)BSS_NOT_FOUND; 3233 - } 3234 - 3235 - ULONG BssSsidTableSearch( 3236 - IN BSS_TABLE *Tab, 3237 - IN PUCHAR pBssid, 3238 - IN PUCHAR pSsid, 3239 - IN UCHAR SsidLen, 3240 - IN UCHAR Channel) 3241 - { 3242 - UCHAR i; 3243 - 3244 - for (i = 0; i < Tab->BssNr; i++) 3245 - { 3246 - // 3247 - // Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. 3248 - // We should distinguish this case. 3249 - // 3250 - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || 3251 - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && 3252 - MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid) && 3253 - SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen)) 3254 - { 3255 - return i; 3256 - } 3257 - } 3258 - return (ULONG)BSS_NOT_FOUND; 3259 - } 3260 - 3261 - ULONG BssTableSearchWithSSID( 3262 - IN BSS_TABLE *Tab, 3263 - IN PUCHAR Bssid, 3264 - IN PUCHAR pSsid, 3265 - IN UCHAR SsidLen, 3266 - IN UCHAR Channel) 3267 - { 3268 - UCHAR i; 3269 - 3270 - for (i = 0; i < Tab->BssNr; i++) 3271 - { 3272 - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || 3273 - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && 3274 - MAC_ADDR_EQUAL(&(Tab->BssEntry[i].Bssid), Bssid) && 3275 - (SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, Tab->BssEntry[i].SsidLen) || 3276 - (NdisEqualMemory(pSsid, ZeroSsid, SsidLen)) || 3277 - (NdisEqualMemory(Tab->BssEntry[i].Ssid, ZeroSsid, Tab->BssEntry[i].SsidLen)))) 3278 - { 3279 - return i; 3280 - } 3281 - } 3282 - return (ULONG)BSS_NOT_FOUND; 3283 - } 3284 - 3285 - // IRQL = DISPATCH_LEVEL 3286 - VOID BssTableDeleteEntry( 3287 - IN OUT BSS_TABLE *Tab, 3288 - IN PUCHAR pBssid, 3289 - IN UCHAR Channel) 3290 - { 3291 - UCHAR i, j; 3292 - 3293 - for (i = 0; i < Tab->BssNr; i++) 3294 - { 3295 - if ((Tab->BssEntry[i].Channel == Channel) && 3296 - (MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid))) 3297 - { 3298 - for (j = i; j < Tab->BssNr - 1; j++) 3299 - { 3300 - NdisMoveMemory(&(Tab->BssEntry[j]), &(Tab->BssEntry[j + 1]), sizeof(BSS_ENTRY)); 3301 - } 3302 - NdisZeroMemory(&(Tab->BssEntry[Tab->BssNr - 1]), sizeof(BSS_ENTRY)); 3303 - Tab->BssNr -= 1; 3304 - return; 3305 - } 3306 - } 3307 - } 3308 - 3309 - /* 3310 - ======================================================================== 3311 - Routine Description: 3312 - Delete the Originator Entry in BAtable. Or decrease numAs Originator by 1 if needed. 3313 - 3314 - Arguments: 3315 - // IRQL = DISPATCH_LEVEL 3316 - ======================================================================== 3317 - */ 3318 - VOID BATableDeleteORIEntry( 3319 - IN OUT PRTMP_ADAPTER pAd, 3320 - IN BA_ORI_ENTRY *pBAORIEntry) 3321 - { 3322 - 3323 - if (pBAORIEntry->ORI_BA_Status != Originator_NONE) 3324 - { 3325 - NdisAcquireSpinLock(&pAd->BATabLock); 3326 - if (pBAORIEntry->ORI_BA_Status == Originator_Done) 3327 - { 3328 - pAd->BATable.numAsOriginator -= 1; 3329 - DBGPRINT(RT_DEBUG_TRACE, ("BATableDeleteORIEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient)); 3330 - // Erase Bitmap flag. 3331 - } 3332 - pAd->MacTab.Content[pBAORIEntry->Wcid].TXBAbitmap &= (~(1<<(pBAORIEntry->TID) )); // If STA mode, erase flag here 3333 - pAd->MacTab.Content[pBAORIEntry->Wcid].BAOriWcidArray[pBAORIEntry->TID] = 0; // If STA mode, erase flag here 3334 - pBAORIEntry->ORI_BA_Status = Originator_NONE; 3335 - pBAORIEntry->Token = 1; 3336 - // Not clear Sequence here. 3337 - NdisReleaseSpinLock(&pAd->BATabLock); 3338 - } 3339 - } 3340 - 3341 - /*! \brief 3342 - * \param 3343 - * \return 3344 - * \pre 3345 - * \post 3346 - 3347 - IRQL = DISPATCH_LEVEL 3348 - 3349 - */ 3350 - VOID BssEntrySet( 3351 - IN PRTMP_ADAPTER pAd, 3352 - OUT BSS_ENTRY *pBss, 3353 - IN PUCHAR pBssid, 3354 - IN CHAR Ssid[], 3355 - IN UCHAR SsidLen, 3356 - IN UCHAR BssType, 3357 - IN USHORT BeaconPeriod, 3358 - IN PCF_PARM pCfParm, 3359 - IN USHORT AtimWin, 3360 - IN USHORT CapabilityInfo, 3361 - IN UCHAR SupRate[], 3362 - IN UCHAR SupRateLen, 3363 - IN UCHAR ExtRate[], 3364 - IN UCHAR ExtRateLen, 3365 - IN HT_CAPABILITY_IE *pHtCapability, 3366 - IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE 3367 - IN UCHAR HtCapabilityLen, 3368 - IN UCHAR AddHtInfoLen, 3369 - IN UCHAR NewExtChanOffset, 3370 - IN UCHAR Channel, 3371 - IN CHAR Rssi, 3372 - IN LARGE_INTEGER TimeStamp, 3373 - IN UCHAR CkipFlag, 3374 - IN PEDCA_PARM pEdcaParm, 3375 - IN PQOS_CAPABILITY_PARM pQosCapability, 3376 - IN PQBSS_LOAD_PARM pQbssLoad, 3377 - IN USHORT LengthVIE, 3378 - IN PNDIS_802_11_VARIABLE_IEs pVIE) 3379 - { 3380 - COPY_MAC_ADDR(pBss->Bssid, pBssid); 3381 - // Default Hidden SSID to be TRUE, it will be turned to FALSE after coping SSID 3382 - pBss->Hidden = 1; 3383 - if (SsidLen > 0) 3384 - { 3385 - // For hidden SSID AP, it might send beacon with SSID len equal to 0 3386 - // Or send beacon /probe response with SSID len matching real SSID length, 3387 - // but SSID is all zero. such as "00-00-00-00" with length 4. 3388 - // We have to prevent this case overwrite correct table 3389 - if (NdisEqualMemory(Ssid, ZeroSsid, SsidLen) == 0) 3390 - { 3391 - NdisZeroMemory(pBss->Ssid, MAX_LEN_OF_SSID); 3392 - NdisMoveMemory(pBss->Ssid, Ssid, SsidLen); 3393 - pBss->SsidLen = SsidLen; 3394 - pBss->Hidden = 0; 3395 - } 3396 - } 3397 - else 3398 - pBss->SsidLen = 0; 3399 - pBss->BssType = BssType; 3400 - pBss->BeaconPeriod = BeaconPeriod; 3401 - if (BssType == BSS_INFRA) 3402 - { 3403 - if (pCfParm->bValid) 3404 - { 3405 - pBss->CfpCount = pCfParm->CfpCount; 3406 - pBss->CfpPeriod = pCfParm->CfpPeriod; 3407 - pBss->CfpMaxDuration = pCfParm->CfpMaxDuration; 3408 - pBss->CfpDurRemaining = pCfParm->CfpDurRemaining; 3409 - } 3410 - } 3411 - else 3412 - { 3413 - pBss->AtimWin = AtimWin; 3414 - } 3415 - 3416 - pBss->CapabilityInfo = CapabilityInfo; 3417 - // The privacy bit indicate security is ON, it maight be WEP, TKIP or AES 3418 - // Combine with AuthMode, they will decide the connection methods. 3419 - pBss->Privacy = CAP_IS_PRIVACY_ON(pBss->CapabilityInfo); 3420 - ASSERT(SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES); 3421 - if (SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES) 3422 - NdisMoveMemory(pBss->SupRate, SupRate, SupRateLen); 3423 - else 3424 - NdisMoveMemory(pBss->SupRate, SupRate, MAX_LEN_OF_SUPPORTED_RATES); 3425 - pBss->SupRateLen = SupRateLen; 3426 - ASSERT(ExtRateLen <= MAX_LEN_OF_SUPPORTED_RATES); 3427 - NdisMoveMemory(pBss->ExtRate, ExtRate, ExtRateLen); 3428 - NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen); 3429 - NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen); 3430 - pBss->NewExtChanOffset = NewExtChanOffset; 3431 - pBss->ExtRateLen = ExtRateLen; 3432 - pBss->Channel = Channel; 3433 - pBss->CentralChannel = Channel; 3434 - pBss->Rssi = Rssi; 3435 - // Update CkipFlag. if not exists, the value is 0x0 3436 - pBss->CkipFlag = CkipFlag; 3437 - 3438 - // New for microsoft Fixed IEs 3439 - NdisMoveMemory(pBss->FixIEs.Timestamp, &TimeStamp, 8); 3440 - pBss->FixIEs.BeaconInterval = BeaconPeriod; 3441 - pBss->FixIEs.Capabilities = CapabilityInfo; 3442 - 3443 - // New for microsoft Variable IEs 3444 - if (LengthVIE != 0) 3445 - { 3446 - pBss->VarIELen = LengthVIE; 3447 - NdisMoveMemory(pBss->VarIEs, pVIE, pBss->VarIELen); 3448 - } 3449 - else 3450 - { 3451 - pBss->VarIELen = 0; 3452 - } 3453 - 3454 - pBss->AddHtInfoLen = 0; 3455 - pBss->HtCapabilityLen = 0; 3456 - 3457 - if (HtCapabilityLen> 0) 3458 - { 3459 - pBss->HtCapabilityLen = HtCapabilityLen; 3460 - NdisMoveMemory(&pBss->HtCapability, pHtCapability, HtCapabilityLen); 3461 - if (AddHtInfoLen > 0) 3462 - { 3463 - pBss->AddHtInfoLen = AddHtInfoLen; 3464 - NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, AddHtInfoLen); 3465 - 3466 - if ((pAddHtInfo->ControlChan > 2)&& (pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40)) 3467 - { 3468 - pBss->CentralChannel = pAddHtInfo->ControlChan - 2; 3469 - } 3470 - else if ((pAddHtInfo->AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (pHtCapability->HtCapInfo.ChannelWidth == BW_40)) 3471 - { 3472 - pBss->CentralChannel = pAddHtInfo->ControlChan + 2; 3473 - } 3474 - } 3475 - } 3476 - 3477 - BssCipherParse(pBss); 3478 - 3479 - // new for QOS 3480 - if (pEdcaParm) 3481 - NdisMoveMemory(&pBss->EdcaParm, pEdcaParm, sizeof(EDCA_PARM)); 3482 - else 3483 - pBss->EdcaParm.bValid = FALSE; 3484 - if (pQosCapability) 3485 - NdisMoveMemory(&pBss->QosCapability, pQosCapability, sizeof(QOS_CAPABILITY_PARM)); 3486 - else 3487 - pBss->QosCapability.bValid = FALSE; 3488 - if (pQbssLoad) 3489 - NdisMoveMemory(&pBss->QbssLoad, pQbssLoad, sizeof(QBSS_LOAD_PARM)); 3490 - else 3491 - pBss->QbssLoad.bValid = FALSE; 3492 - 3493 - { 3494 - PEID_STRUCT pEid; 3495 - USHORT Length = 0; 3496 - 3497 - 3498 - NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN); 3499 - NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN); 3500 - 3501 - pEid = (PEID_STRUCT) pVIE; 3502 - 3503 - while ((Length + 2 + (USHORT)pEid->Len) <= LengthVIE) 3504 - { 3505 - switch(pEid->Eid) 3506 - { 3507 - case IE_WPA: 3508 - if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) 3509 - { 3510 - if ((pEid->Len + 2) > MAX_CUSTOM_LEN) 3511 - { 3512 - pBss->WpaIE.IELen = 0; 3513 - break; 3514 - } 3515 - pBss->WpaIE.IELen = pEid->Len + 2; 3516 - NdisMoveMemory(pBss->WpaIE.IE, pEid, pBss->WpaIE.IELen); 3517 - } 3518 - break; 3519 - case IE_RSN: 3520 - if (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)) 3521 - { 3522 - if ((pEid->Len + 2) > MAX_CUSTOM_LEN) 3523 - { 3524 - pBss->RsnIE.IELen = 0; 3525 - break; 3526 - } 3527 - pBss->RsnIE.IELen = pEid->Len + 2; 3528 - NdisMoveMemory(pBss->RsnIE.IE, pEid, pBss->RsnIE.IELen); 3529 - } 3530 - break; 3531 - } 3532 - Length = Length + 2 + (USHORT)pEid->Len; // Eid[1] + Len[1]+ content[Len] 3533 - pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len); 3534 - } 3535 - } 3536 - } 3537 - 3538 - /*! 3539 - * \brief insert an entry into the bss table 3540 - * \param p_tab The BSS table 3541 - * \param Bssid BSSID 3542 - * \param ssid SSID 3543 - * \param ssid_len Length of SSID 3544 - * \param bss_type 3545 - * \param beacon_period 3546 - * \param timestamp 3547 - * \param p_cf 3548 - * \param atim_win 3549 - * \param cap 3550 - * \param rates 3551 - * \param rates_len 3552 - * \param channel_idx 3553 - * \return none 3554 - * \pre 3555 - * \post 3556 - * \note If SSID is identical, the old entry will be replaced by the new one 3557 - 3558 - IRQL = DISPATCH_LEVEL 3559 - 3560 - */ 3561 - ULONG BssTableSetEntry( 3562 - IN PRTMP_ADAPTER pAd, 3563 - OUT BSS_TABLE *Tab, 3564 - IN PUCHAR pBssid, 3565 - IN CHAR Ssid[], 3566 - IN UCHAR SsidLen, 3567 - IN UCHAR BssType, 3568 - IN USHORT BeaconPeriod, 3569 - IN CF_PARM *CfParm, 3570 - IN USHORT AtimWin, 3571 - IN USHORT CapabilityInfo, 3572 - IN UCHAR SupRate[], 3573 - IN UCHAR SupRateLen, 3574 - IN UCHAR ExtRate[], 3575 - IN UCHAR ExtRateLen, 3576 - IN HT_CAPABILITY_IE *pHtCapability, 3577 - IN ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE 3578 - IN UCHAR HtCapabilityLen, 3579 - IN UCHAR AddHtInfoLen, 3580 - IN UCHAR NewExtChanOffset, 3581 - IN UCHAR ChannelNo, 3582 - IN CHAR Rssi, 3583 - IN LARGE_INTEGER TimeStamp, 3584 - IN UCHAR CkipFlag, 3585 - IN PEDCA_PARM pEdcaParm, 3586 - IN PQOS_CAPABILITY_PARM pQosCapability, 3587 - IN PQBSS_LOAD_PARM pQbssLoad, 3588 - IN USHORT LengthVIE, 3589 - IN PNDIS_802_11_VARIABLE_IEs pVIE) 3590 - { 3591 - ULONG Idx; 3592 - 3593 - Idx = BssTableSearchWithSSID(Tab, pBssid, Ssid, SsidLen, ChannelNo); 3594 - if (Idx == BSS_NOT_FOUND) 3595 - { 3596 - if (Tab->BssNr >= MAX_LEN_OF_BSS_TABLE) 3597 - { 3598 - // 3599 - // It may happen when BSS Table was full. 3600 - // The desired AP will not be added into BSS Table 3601 - // In this case, if we found the desired AP then overwrite BSS Table. 3602 - // 3603 - if(!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 3604 - { 3605 - if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, pBssid) || 3606 - SSID_EQUAL(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Ssid, SsidLen)) 3607 - { 3608 - Idx = Tab->BssOverlapNr; 3609 - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin, 3610 - CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen, 3611 - NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE); 3612 - Tab->BssOverlapNr = (Tab->BssOverlapNr++) % MAX_LEN_OF_BSS_TABLE; 3613 - } 3614 - return Idx; 3615 - } 3616 - else 3617 - { 3618 - return BSS_NOT_FOUND; 3619 - } 3620 - } 3621 - Idx = Tab->BssNr; 3622 - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod, CfParm, AtimWin, 3623 - CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen, 3624 - NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE); 3625 - Tab->BssNr++; 3626 - } 3627 - else 3628 - { 3629 - #ifndef RT30xx 3630 - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod,CfParm, AtimWin, 3631 - CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen, 3632 - NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE); 3633 - #endif 3634 - #ifdef RT30xx 3635 - /* avoid Hidden SSID form beacon to overwirite correct SSID from probe response */ 3636 - if ((SSID_EQUAL(Ssid, SsidLen, Tab->BssEntry[Idx].Ssid, Tab->BssEntry[Idx].SsidLen)) || 3637 - (NdisEqualMemory(Tab->BssEntry[Idx].Ssid, ZeroSsid, Tab->BssEntry[Idx].SsidLen))) 3638 - { 3639 - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod,CfParm, AtimWin, 3640 - CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen, 3641 - NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE); 3642 - } 3643 - #endif 3644 - } 3645 - 3646 - return Idx; 3647 - } 3648 - 3649 - // IRQL = DISPATCH_LEVEL 3650 - VOID BssTableSsidSort( 3651 - IN PRTMP_ADAPTER pAd, 3652 - OUT BSS_TABLE *OutTab, 3653 - IN CHAR Ssid[], 3654 - IN UCHAR SsidLen) 3655 - { 3656 - INT i; 3657 - BssTableInit(OutTab); 3658 - 3659 - for (i = 0; i < pAd->ScanTab.BssNr; i++) 3660 - { 3661 - BSS_ENTRY *pInBss = &pAd->ScanTab.BssEntry[i]; 3662 - BOOLEAN bIsHiddenApIncluded = FALSE; 3663 - 3664 - if (((pAd->CommonCfg.bIEEE80211H == 1) && 3665 - (pAd->MlmeAux.Channel > 14) && 3666 - RadarChannelCheck(pAd, pInBss->Channel)) 3667 - ) 3668 - { 3669 - if (pInBss->Hidden) 3670 - bIsHiddenApIncluded = TRUE; 3671 - } 3672 - 3673 - if ((pInBss->BssType == pAd->StaCfg.BssType) && 3674 - (SSID_EQUAL(Ssid, SsidLen, pInBss->Ssid, pInBss->SsidLen) || bIsHiddenApIncluded)) 3675 - { 3676 - BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; 3677 - 3678 - // 2.4G/5G N only mode 3679 - if ((pInBss->HtCapabilityLen == 0) && 3680 - ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) 3681 - { 3682 - DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); 3683 - continue; 3684 - } 3685 - 3686 - // New for WPA2 3687 - // Check the Authmode first 3688 - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) 3689 - { 3690 - // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode 3691 - if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux)) 3692 - // None matched 3693 - continue; 3694 - 3695 - // Check cipher suite, AP must have more secured cipher than station setting 3696 - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) 3697 - { 3698 - // If it's not mixed mode, we should only let BSS pass with the same encryption 3699 - if (pInBss->WPA.bMixMode == FALSE) 3700 - if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher) 3701 - continue; 3702 - 3703 - // check group cipher 3704 - #ifndef RT30xx 3705 - if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) && 3706 - (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP40Enabled) && 3707 - (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP104Enabled)) 3708 - #endif 3709 - #ifdef RT30xx 3710 - if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) 3711 - #endif 3712 - continue; 3713 - 3714 - // check pairwise cipher, skip if none matched 3715 - // If profile set to AES, let it pass without question. 3716 - // If profile set to TKIP, we must find one mateched 3717 - if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) && 3718 - (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) && 3719 - (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux)) 3720 - continue; 3721 - } 3722 - else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) 3723 - { 3724 - // If it's not mixed mode, we should only let BSS pass with the same encryption 3725 - if (pInBss->WPA2.bMixMode == FALSE) 3726 - if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher) 3727 - continue; 3728 - 3729 - // check group cipher 3730 - #ifndef RT30xx 3731 - if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) && 3732 - (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP40Enabled) && 3733 - (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP104Enabled)) 3734 - #endif 3735 - #ifdef RT30xx 3736 - if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher) 3737 - #endif 3738 - continue; 3739 - 3740 - // check pairwise cipher, skip if none matched 3741 - // If profile set to AES, let it pass without question. 3742 - // If profile set to TKIP, we must find one mateched 3743 - if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) && 3744 - (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) && 3745 - (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux)) 3746 - continue; 3747 - } 3748 - } 3749 - // Bss Type matched, SSID matched. 3750 - // We will check wepstatus for qualification Bss 3751 - else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) 3752 - { 3753 - DBGPRINT(RT_DEBUG_TRACE,("StaCfg.WepStatus=%d, while pInBss->WepStatus=%d\n", pAd->StaCfg.WepStatus, pInBss->WepStatus)); 3754 - // 3755 - // For the SESv2 case, we will not qualify WepStatus. 3756 - // 3757 - if (!pInBss->bSES) 3758 - continue; 3759 - } 3760 - 3761 - // Since the AP is using hidden SSID, and we are trying to connect to ANY 3762 - // It definitely will fail. So, skip it. 3763 - // CCX also require not even try to connect it!! 3764 - if (SsidLen == 0) 3765 - continue; 3766 - 3767 - // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region 3768 - // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, 3769 - if ((pInBss->CentralChannel != pInBss->Channel) && 3770 - (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)) 3771 - { 3772 - if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE) 3773 - { 3774 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20; 3775 - SetCommonHT(pAd); 3776 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40; 3777 - } 3778 - else 3779 - { 3780 - if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BAND_WIDTH_20) 3781 - { 3782 - SetCommonHT(pAd); 3783 - } 3784 - } 3785 - } 3786 - 3787 - // copy matching BSS from InTab to OutTab 3788 - NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY)); 3789 - 3790 - OutTab->BssNr++; 3791 - } 3792 - else if ((pInBss->BssType == pAd->StaCfg.BssType) && (SsidLen == 0)) 3793 - { 3794 - BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; 3795 - 3796 - // 2.4G/5G N only mode 3797 - if ((pInBss->HtCapabilityLen == 0) && 3798 - ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) 3799 - { 3800 - DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); 3801 - continue; 3802 - } 3803 - 3804 - // New for WPA2 3805 - // Check the Authmode first 3806 - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) 3807 - { 3808 - // Check AuthMode and AuthModeAux for matching, in case AP support dual-mode 3809 - if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) && (pAd->StaCfg.AuthMode != pInBss->AuthModeAux)) 3810 - // None matched 3811 - continue; 3812 - 3813 - // Check cipher suite, AP must have more secured cipher than station setting 3814 - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) 3815 - { 3816 - // If it's not mixed mode, we should only let BSS pass with the same encryption 3817 - if (pInBss->WPA.bMixMode == FALSE) 3818 - if (pAd->StaCfg.WepStatus != pInBss->WPA.GroupCipher) 3819 - continue; 3820 - 3821 - // check group cipher 3822 - if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) 3823 - continue; 3824 - 3825 - // check pairwise cipher, skip if none matched 3826 - // If profile set to AES, let it pass without question. 3827 - // If profile set to TKIP, we must find one mateched 3828 - if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) && 3829 - (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipher) && 3830 - (pAd->StaCfg.WepStatus != pInBss->WPA.PairCipherAux)) 3831 - continue; 3832 - } 3833 - else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) 3834 - { 3835 - // If it's not mixed mode, we should only let BSS pass with the same encryption 3836 - if (pInBss->WPA2.bMixMode == FALSE) 3837 - if (pAd->StaCfg.WepStatus != pInBss->WPA2.GroupCipher) 3838 - continue; 3839 - 3840 - // check group cipher 3841 - if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher) 3842 - continue; 3843 - 3844 - // check pairwise cipher, skip if none matched 3845 - // If profile set to AES, let it pass without question. 3846 - // If profile set to TKIP, we must find one mateched 3847 - if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) && 3848 - (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipher) && 3849 - (pAd->StaCfg.WepStatus != pInBss->WPA2.PairCipherAux)) 3850 - continue; 3851 - } 3852 - } 3853 - // Bss Type matched, SSID matched. 3854 - // We will check wepstatus for qualification Bss 3855 - else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) 3856 - continue; 3857 - 3858 - // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region 3859 - // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, 3860 - if ((pInBss->CentralChannel != pInBss->Channel) && 3861 - (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)) 3862 - { 3863 - if (RTMPCheckChannel(pAd, pInBss->CentralChannel, pInBss->Channel) == FALSE) 3864 - { 3865 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20; 3866 - SetCommonHT(pAd); 3867 - pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40; 3868 - } 3869 - } 3870 - 3871 - // copy matching BSS from InTab to OutTab 3872 - NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY)); 3873 - 3874 - OutTab->BssNr++; 3875 - } 3876 - 3877 - if (OutTab->BssNr >= MAX_LEN_OF_BSS_TABLE) 3878 - break; 3879 - } 3880 - 3881 - BssTableSortByRssi(OutTab); 3882 - } 3883 - 3884 - 3885 - // IRQL = DISPATCH_LEVEL 3886 - VOID BssTableSortByRssi( 3887 - IN OUT BSS_TABLE *OutTab) 3888 - { 3889 - INT i, j; 3890 - BSS_ENTRY TmpBss; 3891 - 3892 - for (i = 0; i < OutTab->BssNr - 1; i++) 3893 - { 3894 - for (j = i+1; j < OutTab->BssNr; j++) 3895 - { 3896 - if (OutTab->BssEntry[j].Rssi > OutTab->BssEntry[i].Rssi) 3897 - { 3898 - NdisMoveMemory(&TmpBss, &OutTab->BssEntry[j], sizeof(BSS_ENTRY)); 3899 - NdisMoveMemory(&OutTab->BssEntry[j], &OutTab->BssEntry[i], sizeof(BSS_ENTRY)); 3900 - NdisMoveMemory(&OutTab->BssEntry[i], &TmpBss, sizeof(BSS_ENTRY)); 3901 - } 3902 - } 3903 - } 3904 - } 3905 - 3906 - VOID BssCipherParse( 3907 - IN OUT PBSS_ENTRY pBss) 3908 - { 3909 - PEID_STRUCT pEid; 3910 - PUCHAR pTmp; 3911 - PRSN_IE_HEADER_STRUCT pRsnHeader; 3912 - PCIPHER_SUITE_STRUCT pCipher; 3913 - PAKM_SUITE_STRUCT pAKM; 3914 - USHORT Count; 3915 - INT Length; 3916 - NDIS_802_11_ENCRYPTION_STATUS TmpCipher; 3917 - 3918 - // 3919 - // WepStatus will be reset later, if AP announce TKIP or AES on the beacon frame. 3920 - // 3921 - if (pBss->Privacy) 3922 - { 3923 - pBss->WepStatus = Ndis802_11WEPEnabled; 3924 - } 3925 - else 3926 - { 3927 - pBss->WepStatus = Ndis802_11WEPDisabled; 3928 - } 3929 - // Set default to disable & open authentication before parsing variable IE 3930 - pBss->AuthMode = Ndis802_11AuthModeOpen; 3931 - pBss->AuthModeAux = Ndis802_11AuthModeOpen; 3932 - 3933 - // Init WPA setting 3934 - pBss->WPA.PairCipher = Ndis802_11WEPDisabled; 3935 - pBss->WPA.PairCipherAux = Ndis802_11WEPDisabled; 3936 - pBss->WPA.GroupCipher = Ndis802_11WEPDisabled; 3937 - pBss->WPA.RsnCapability = 0; 3938 - pBss->WPA.bMixMode = FALSE; 3939 - 3940 - // Init WPA2 setting 3941 - pBss->WPA2.PairCipher = Ndis802_11WEPDisabled; 3942 - pBss->WPA2.PairCipherAux = Ndis802_11WEPDisabled; 3943 - pBss->WPA2.GroupCipher = Ndis802_11WEPDisabled; 3944 - pBss->WPA2.RsnCapability = 0; 3945 - pBss->WPA2.bMixMode = FALSE; 3946 - 3947 - 3948 - Length = (INT) pBss->VarIELen; 3949 - 3950 - while (Length > 0) 3951 - { 3952 - // Parse cipher suite base on WPA1 & WPA2, they should be parsed differently 3953 - pTmp = ((PUCHAR) pBss->VarIEs) + pBss->VarIELen - Length; 3954 - pEid = (PEID_STRUCT) pTmp; 3955 - switch (pEid->Eid) 3956 - { 3957 - case IE_WPA: 3958 - //Parse Cisco IE_WPA (LEAP, CCKM, etc.) 3959 - if ( NdisEqualMemory((pTmp+8), CISCO_OUI, 3)) 3960 - { 3961 - pTmp += 11; 3962 - switch (*pTmp) 3963 - { 3964 - case 1: 3965 - case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway 3966 - pBss->WepStatus = Ndis802_11Encryption1Enabled; 3967 - pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled; 3968 - pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled; 3969 - break; 3970 - case 2: 3971 - pBss->WepStatus = Ndis802_11Encryption2Enabled; 3972 - pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled; 3973 - pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled; 3974 - break; 3975 - case 4: 3976 - pBss->WepStatus = Ndis802_11Encryption3Enabled; 3977 - pBss->WPA.PairCipher = Ndis802_11Encryption1Enabled; 3978 - pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled; 3979 - break; 3980 - default: 3981 - break; 3982 - } 3983 - 3984 - // if Cisco IE_WPA, break 3985 - break; 3986 - } 3987 - else if (NdisEqualMemory(pEid->Octet, SES_OUI, 3) && (pEid->Len == 7)) 3988 - { 3989 - pBss->bSES = TRUE; 3990 - break; 3991 - } 3992 - else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4) != 1) 3993 - { 3994 - // if unsupported vendor specific IE 3995 - break; 3996 - } 3997 - // Skip OUI, version, and multicast suite 3998 - // This part should be improved in the future when AP supported multiple cipher suite. 3999 - // For now, it's OK since almost all APs have fixed cipher suite supported. 4000 - // pTmp = (PUCHAR) pEid->Octet; 4001 - pTmp += 11; 4002 - 4003 - // Cipher Suite Selectors from Spec P802.11i/D3.2 P26. 4004 - // Value Meaning 4005 - // 0 None 4006 - // 1 WEP-40 4007 - // 2 Tkip 4008 - // 3 WRAP 4009 - // 4 AES 4010 - // 5 WEP-104 4011 - // Parse group cipher 4012 - switch (*pTmp) 4013 - { 4014 - case 1: 4015 - #ifndef RT30xx 4016 - pBss->WPA.GroupCipher = Ndis802_11GroupWEP40Enabled; 4017 - break; 4018 - case 5: 4019 - pBss->WPA.GroupCipher = Ndis802_11GroupWEP104Enabled; 4020 - #endif 4021 - #ifdef RT30xx 4022 - case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway 4023 - pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled; 4024 - #endif 4025 - break; 4026 - case 2: 4027 - pBss->WPA.GroupCipher = Ndis802_11Encryption2Enabled; 4028 - break; 4029 - case 4: 4030 - pBss->WPA.GroupCipher = Ndis802_11Encryption3Enabled; 4031 - break; 4032 - default: 4033 - break; 4034 - } 4035 - // number of unicast suite 4036 - pTmp += 1; 4037 - 4038 - // skip all unicast cipher suites 4039 - //Count = *(PUSHORT) pTmp; 4040 - Count = (pTmp[1]<<8) + pTmp[0]; 4041 - pTmp += sizeof(USHORT); 4042 - 4043 - // Parsing all unicast cipher suite 4044 - while (Count > 0) 4045 - { 4046 - // Skip OUI 4047 - pTmp += 3; 4048 - TmpCipher = Ndis802_11WEPDisabled; 4049 - switch (*pTmp) 4050 - { 4051 - case 1: 4052 - case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway 4053 - TmpCipher = Ndis802_11Encryption1Enabled; 4054 - break; 4055 - case 2: 4056 - TmpCipher = Ndis802_11Encryption2Enabled; 4057 - break; 4058 - case 4: 4059 - TmpCipher = Ndis802_11Encryption3Enabled; 4060 - break; 4061 - default: 4062 - break; 4063 - } 4064 - if (TmpCipher > pBss->WPA.PairCipher) 4065 - { 4066 - // Move the lower cipher suite to PairCipherAux 4067 - pBss->WPA.PairCipherAux = pBss->WPA.PairCipher; 4068 - pBss->WPA.PairCipher = TmpCipher; 4069 - } 4070 - else 4071 - { 4072 - pBss->WPA.PairCipherAux = TmpCipher; 4073 - } 4074 - pTmp++; 4075 - Count--; 4076 - } 4077 - 4078 - // 4. get AKM suite counts 4079 - //Count = *(PUSHORT) pTmp; 4080 - Count = (pTmp[1]<<8) + pTmp[0]; 4081 - pTmp += sizeof(USHORT); 4082 - pTmp += 3; 4083 - 4084 - switch (*pTmp) 4085 - { 4086 - case 1: 4087 - // Set AP support WPA mode 4088 - if (pBss->AuthMode == Ndis802_11AuthModeOpen) 4089 - pBss->AuthMode = Ndis802_11AuthModeWPA; 4090 - else 4091 - pBss->AuthModeAux = Ndis802_11AuthModeWPA; 4092 - break; 4093 - case 2: 4094 - // Set AP support WPA mode 4095 - if (pBss->AuthMode == Ndis802_11AuthModeOpen) 4096 - pBss->AuthMode = Ndis802_11AuthModeWPAPSK; 4097 - else 4098 - pBss->AuthModeAux = Ndis802_11AuthModeWPAPSK; 4099 - break; 4100 - default: 4101 - break; 4102 - } 4103 - pTmp += 1; 4104 - 4105 - // Fixed for WPA-None 4106 - if (pBss->BssType == BSS_ADHOC) 4107 - { 4108 - pBss->AuthMode = Ndis802_11AuthModeWPANone; 4109 - pBss->AuthModeAux = Ndis802_11AuthModeWPANone; 4110 - pBss->WepStatus = pBss->WPA.GroupCipher; 4111 - if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled) 4112 - pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher; 4113 - } 4114 - else 4115 - pBss->WepStatus = pBss->WPA.PairCipher; 4116 - 4117 - // Check the Pair & Group, if different, turn on mixed mode flag 4118 - if (pBss->WPA.GroupCipher != pBss->WPA.PairCipher) 4119 - pBss->WPA.bMixMode = TRUE; 4120 - 4121 - break; 4122 - 4123 - case IE_RSN: 4124 - pRsnHeader = (PRSN_IE_HEADER_STRUCT) pTmp; 4125 - 4126 - // 0. Version must be 1 4127 - if (le2cpu16(pRsnHeader->Version) != 1) 4128 - break; 4129 - pTmp += sizeof(RSN_IE_HEADER_STRUCT); 4130 - 4131 - // 1. Check group cipher 4132 - pCipher = (PCIPHER_SUITE_STRUCT) pTmp; 4133 - if (!RTMPEqualMemory(pTmp, RSN_OUI, 3)) 4134 - break; 4135 - 4136 - // Parse group cipher 4137 - switch (pCipher->Type) 4138 - { 4139 - case 1: 4140 - #ifndef RT30xx 4141 - pBss->WPA2.GroupCipher = Ndis802_11GroupWEP40Enabled; 4142 - break; 4143 - case 5: 4144 - pBss->WPA2.GroupCipher = Ndis802_11GroupWEP104Enabled; 4145 - #endif 4146 - #ifdef RT30xx 4147 - case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway 4148 - pBss->WPA2.GroupCipher = Ndis802_11Encryption1Enabled; 4149 - #endif 4150 - break; 4151 - case 2: 4152 - pBss->WPA2.GroupCipher = Ndis802_11Encryption2Enabled; 4153 - break; 4154 - case 4: 4155 - pBss->WPA2.GroupCipher = Ndis802_11Encryption3Enabled; 4156 - break; 4157 - default: 4158 - break; 4159 - } 4160 - // set to correct offset for next parsing 4161 - pTmp += sizeof(CIPHER_SUITE_STRUCT); 4162 - 4163 - // 2. Get pairwise cipher counts 4164 - //Count = *(PUSHORT) pTmp; 4165 - Count = (pTmp[1]<<8) + pTmp[0]; 4166 - pTmp += sizeof(USHORT); 4167 - 4168 - // 3. Get pairwise cipher 4169 - // Parsing all unicast cipher suite 4170 - while (Count > 0) 4171 - { 4172 - // Skip OUI 4173 - pCipher = (PCIPHER_SUITE_STRUCT) pTmp; 4174 - TmpCipher = Ndis802_11WEPDisabled; 4175 - switch (pCipher->Type) 4176 - { 4177 - case 1: 4178 - case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway 4179 - TmpCipher = Ndis802_11Encryption1Enabled; 4180 - break; 4181 - case 2: 4182 - TmpCipher = Ndis802_11Encryption2Enabled; 4183 - break; 4184 - case 4: 4185 - TmpCipher = Ndis802_11Encryption3Enabled; 4186 - break; 4187 - default: 4188 - break; 4189 - } 4190 - if (TmpCipher > pBss->WPA2.PairCipher) 4191 - { 4192 - // Move the lower cipher suite to PairCipherAux 4193 - pBss->WPA2.PairCipherAux = pBss->WPA2.PairCipher; 4194 - pBss->WPA2.PairCipher = TmpCipher; 4195 - } 4196 - else 4197 - { 4198 - pBss->WPA2.PairCipherAux = TmpCipher; 4199 - } 4200 - pTmp += sizeof(CIPHER_SUITE_STRUCT); 4201 - Count--; 4202 - } 4203 - 4204 - // 4. get AKM suite counts 4205 - //Count = *(PUSHORT) pTmp; 4206 - Count = (pTmp[1]<<8) + pTmp[0]; 4207 - pTmp += sizeof(USHORT); 4208 - 4209 - // 5. Get AKM ciphers 4210 - pAKM = (PAKM_SUITE_STRUCT) pTmp; 4211 - if (!RTMPEqualMemory(pTmp, RSN_OUI, 3)) 4212 - break; 4213 - 4214 - switch (pAKM->Type) 4215 - { 4216 - case 1: 4217 - // Set AP support WPA mode 4218 - if (pBss->AuthMode == Ndis802_11AuthModeOpen) 4219 - pBss->AuthMode = Ndis802_11AuthModeWPA2; 4220 - else 4221 - pBss->AuthModeAux = Ndis802_11AuthModeWPA2; 4222 - break; 4223 - case 2: 4224 - // Set AP support WPA mode 4225 - if (pBss->AuthMode == Ndis802_11AuthModeOpen) 4226 - pBss->AuthMode = Ndis802_11AuthModeWPA2PSK; 4227 - else 4228 - pBss->AuthModeAux = Ndis802_11AuthModeWPA2PSK; 4229 - break; 4230 - default: 4231 - break; 4232 - } 4233 - pTmp += (Count * sizeof(AKM_SUITE_STRUCT)); 4234 - 4235 - // Fixed for WPA-None 4236 - if (pBss->BssType == BSS_ADHOC) 4237 - { 4238 - pBss->AuthMode = Ndis802_11AuthModeWPANone; 4239 - pBss->AuthModeAux = Ndis802_11AuthModeWPANone; 4240 - pBss->WPA.PairCipherAux = pBss->WPA2.PairCipherAux; 4241 - pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher; 4242 - pBss->WepStatus = pBss->WPA.GroupCipher; 4243 - if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled) 4244 - pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher; 4245 - } 4246 - pBss->WepStatus = pBss->WPA2.PairCipher; 4247 - 4248 - // 6. Get RSN capability 4249 - //pBss->WPA2.RsnCapability = *(PUSHORT) pTmp; 4250 - pBss->WPA2.RsnCapability = (pTmp[1]<<8) + pTmp[0]; 4251 - pTmp += sizeof(USHORT); 4252 - 4253 - // Check the Pair & Group, if different, turn on mixed mode flag 4254 - if (pBss->WPA2.GroupCipher != pBss->WPA2.PairCipher) 4255 - pBss->WPA2.bMixMode = TRUE; 4256 - 4257 - break; 4258 - default: 4259 - break; 4260 - } 4261 - Length -= (pEid->Len + 2); 4262 - } 4263 - } 4264 - 4265 - // =========================================================================================== 4266 - // mac_table.c 4267 - // =========================================================================================== 4268 - 4269 - /*! \brief generates a random mac address value for IBSS BSSID 4270 - * \param Addr the bssid location 4271 - * \return none 4272 - * \pre 4273 - * \post 4274 - */ 4275 - VOID MacAddrRandomBssid( 4276 - IN PRTMP_ADAPTER pAd, 4277 - OUT PUCHAR pAddr) 4278 - { 4279 - INT i; 4280 - 4281 - for (i = 0; i < MAC_ADDR_LEN; i++) 4282 - { 4283 - pAddr[i] = RandomByte(pAd); 4284 - } 4285 - 4286 - pAddr[0] = (pAddr[0] & 0xfe) | 0x02; // the first 2 bits must be 01xxxxxxxx 4287 - } 4288 - 4289 - /*! \brief init the management mac frame header 4290 - * \param p_hdr mac header 4291 - * \param subtype subtype of the frame 4292 - * \param p_ds destination address, don't care if it is a broadcast address 4293 - * \return none 4294 - * \pre the station has the following information in the pAd->StaCfg 4295 - * - bssid 4296 - * - station address 4297 - * \post 4298 - * \note this function initializes the following field 4299 - 4300 - IRQL = PASSIVE_LEVEL 4301 - IRQL = DISPATCH_LEVEL 4302 - 4303 - */ 4304 - VOID MgtMacHeaderInit( 4305 - IN PRTMP_ADAPTER pAd, 4306 - IN OUT PHEADER_802_11 pHdr80211, 4307 - IN UCHAR SubType, 4308 - IN UCHAR ToDs, 4309 - IN PUCHAR pDA, 4310 - IN PUCHAR pBssid) 4311 - { 4312 - NdisZeroMemory(pHdr80211, sizeof(HEADER_802_11)); 4313 - 4314 - pHdr80211->FC.Type = BTYPE_MGMT; 4315 - pHdr80211->FC.SubType = SubType; 4316 - pHdr80211->FC.ToDs = ToDs; 4317 - COPY_MAC_ADDR(pHdr80211->Addr1, pDA); 4318 - 4319 - COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); 4320 - 4321 - COPY_MAC_ADDR(pHdr80211->Addr3, pBssid); 4322 - } 4323 - 4324 - // =========================================================================================== 4325 - // mem_mgmt.c 4326 - // =========================================================================================== 4327 - 4328 - /*!*************************************************************************** 4329 - * This routine build an outgoing frame, and fill all information specified 4330 - * in argument list to the frame body. The actual frame size is the summation 4331 - * of all arguments. 4332 - * input params: 4333 - * Buffer - pointer to a pre-allocated memory segment 4334 - * args - a list of <int arg_size, arg> pairs. 4335 - * NOTE NOTE NOTE!!!! the last argument must be NULL, otherwise this 4336 - * function will FAIL!!! 4337 - * return: 4338 - * Size of the buffer 4339 - * usage: 4340 - * MakeOutgoingFrame(Buffer, output_length, 2, &fc, 2, &dur, 6, p_addr1, 6,p_addr2, END_OF_ARGS); 4341 - 4342 - IRQL = PASSIVE_LEVEL 4343 - IRQL = DISPATCH_LEVEL 4344 - 4345 - ****************************************************************************/ 4346 - ULONG MakeOutgoingFrame( 4347 - OUT CHAR *Buffer, 4348 - OUT ULONG *FrameLen, ...) 4349 - { 4350 - CHAR *p; 4351 - int leng; 4352 - ULONG TotLeng; 4353 - va_list Args; 4354 - 4355 - // calculates the total length 4356 - TotLeng = 0; 4357 - va_start(Args, FrameLen); 4358 - do 4359 - { 4360 - leng = va_arg(Args, int); 4361 - if (leng == END_OF_ARGS) 4362 - { 4363 - break; 4364 - } 4365 - p = va_arg(Args, PVOID); 4366 - NdisMoveMemory(&Buffer[TotLeng], p, leng); 4367 - TotLeng = TotLeng + leng; 4368 - } while(TRUE); 4369 - 4370 - va_end(Args); /* clean up */ 4371 - *FrameLen = TotLeng; 4372 - return TotLeng; 4373 - } 4374 - 4375 - // =========================================================================================== 4376 - // mlme_queue.c 4377 - // =========================================================================================== 4378 - 4379 - /*! \brief Initialize The MLME Queue, used by MLME Functions 4380 - * \param *Queue The MLME Queue 4381 - * \return Always Return NDIS_STATE_SUCCESS in this implementation 4382 - * \pre 4383 - * \post 4384 - * \note Because this is done only once (at the init stage), no need to be locked 4385 - 4386 - IRQL = PASSIVE_LEVEL 4387 - 4388 - */ 4389 - NDIS_STATUS MlmeQueueInit( 4390 - IN MLME_QUEUE *Queue) 4391 - { 4392 - INT i; 4393 - 4394 - NdisAllocateSpinLock(&Queue->Lock); 4395 - 4396 - Queue->Num = 0; 4397 - Queue->Head = 0; 4398 - Queue->Tail = 0; 4399 - 4400 - for (i = 0; i < MAX_LEN_OF_MLME_QUEUE; i++) 4401 - { 4402 - Queue->Entry[i].Occupied = FALSE; 4403 - Queue->Entry[i].MsgLen = 0; 4404 - NdisZeroMemory(Queue->Entry[i].Msg, MGMT_DMA_BUFFER_SIZE); 4405 - } 4406 - 4407 - return NDIS_STATUS_SUCCESS; 4408 - } 4409 - 4410 - /*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread 4411 - * \param *Queue The MLME Queue 4412 - * \param Machine The State Machine Id 4413 - * \param MsgType The Message Type 4414 - * \param MsgLen The Message length 4415 - * \param *Msg The message pointer 4416 - * \return TRUE if enqueue is successful, FALSE if the queue is full 4417 - * \pre 4418 - * \post 4419 - * \note The message has to be initialized 4420 - 4421 - IRQL = PASSIVE_LEVEL 4422 - IRQL = DISPATCH_LEVEL 4423 - 4424 - */ 4425 - BOOLEAN MlmeEnqueue( 4426 - IN PRTMP_ADAPTER pAd, 4427 - IN ULONG Machine, 4428 - IN ULONG MsgType, 4429 - IN ULONG MsgLen, 4430 - IN VOID *Msg) 4431 - { 4432 - INT Tail; 4433 - MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue; 4434 - 4435 - // Do nothing if the driver is starting halt state. 4436 - // This might happen when timer already been fired before cancel timer with mlmehalt 4437 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) 4438 - return FALSE; 4439 - 4440 - // First check the size, it MUST not exceed the mlme queue size 4441 - if (MsgLen > MGMT_DMA_BUFFER_SIZE) 4442 - { 4443 - DBGPRINT_ERR(("MlmeEnqueue: msg too large, size = %ld \n", MsgLen)); 4444 - return FALSE; 4445 - } 4446 - 4447 - if (MlmeQueueFull(Queue)) 4448 - { 4449 - return FALSE; 4450 - } 4451 - 4452 - NdisAcquireSpinLock(&(Queue->Lock)); 4453 - Tail = Queue->Tail; 4454 - Queue->Tail++; 4455 - Queue->Num++; 4456 - if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) 4457 - { 4458 - Queue->Tail = 0; 4459 - } 4460 - 4461 - Queue->Entry[Tail].Wcid = RESERVED_WCID; 4462 - Queue->Entry[Tail].Occupied = TRUE; 4463 - Queue->Entry[Tail].Machine = Machine; 4464 - Queue->Entry[Tail].MsgType = MsgType; 4465 - Queue->Entry[Tail].MsgLen = MsgLen; 4466 - 4467 - if (Msg != NULL) 4468 - { 4469 - NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen); 4470 - } 4471 - 4472 - NdisReleaseSpinLock(&(Queue->Lock)); 4473 - return TRUE; 4474 - } 4475 - 4476 - /*! \brief This function is used when Recv gets a MLME message 4477 - * \param *Queue The MLME Queue 4478 - * \param TimeStampHigh The upper 32 bit of timestamp 4479 - * \param TimeStampLow The lower 32 bit of timestamp 4480 - * \param Rssi The receiving RSSI strength 4481 - * \param MsgLen The length of the message 4482 - * \param *Msg The message pointer 4483 - * \return TRUE if everything ok, FALSE otherwise (like Queue Full) 4484 - * \pre 4485 - * \post 4486 - 4487 - IRQL = DISPATCH_LEVEL 4488 - 4489 - */ 4490 - BOOLEAN MlmeEnqueueForRecv( 4491 - IN PRTMP_ADAPTER pAd, 4492 - IN ULONG Wcid, 4493 - IN ULONG TimeStampHigh, 4494 - IN ULONG TimeStampLow, 4495 - IN UCHAR Rssi0, 4496 - IN UCHAR Rssi1, 4497 - IN UCHAR Rssi2, 4498 - IN ULONG MsgLen, 4499 - IN VOID *Msg, 4500 - IN UCHAR Signal) 4501 - { 4502 - INT Tail, Machine; 4503 - PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; 4504 - INT MsgType; 4505 - MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue; 4506 - 4507 - // Do nothing if the driver is starting halt state. 4508 - // This might happen when timer already been fired before cancel timer with mlmehalt 4509 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) 4510 - { 4511 - DBGPRINT_ERR(("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n")); 4512 - return FALSE; 4513 - } 4514 - 4515 - // First check the size, it MUST not exceed the mlme queue size 4516 - if (MsgLen > MGMT_DMA_BUFFER_SIZE) 4517 - { 4518 - DBGPRINT_ERR(("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen)); 4519 - return FALSE; 4520 - } 4521 - 4522 - if (MlmeQueueFull(Queue)) 4523 - { 4524 - return FALSE; 4525 - } 4526 - 4527 - { 4528 - if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) 4529 - { 4530 - DBGPRINT_ERR(("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n",pFrame->Hdr.FC.SubType)); 4531 - return FALSE; 4532 - } 4533 - } 4534 - 4535 - // OK, we got all the informations, it is time to put things into queue 4536 - NdisAcquireSpinLock(&(Queue->Lock)); 4537 - Tail = Queue->Tail; 4538 - Queue->Tail++; 4539 - Queue->Num++; 4540 - if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) 4541 - { 4542 - Queue->Tail = 0; 4543 - } 4544 - Queue->Entry[Tail].Occupied = TRUE; 4545 - Queue->Entry[Tail].Machine = Machine; 4546 - Queue->Entry[Tail].MsgType = MsgType; 4547 - Queue->Entry[Tail].MsgLen = MsgLen; 4548 - Queue->Entry[Tail].TimeStamp.u.LowPart = TimeStampLow; 4549 - Queue->Entry[Tail].TimeStamp.u.HighPart = TimeStampHigh; 4550 - Queue->Entry[Tail].Rssi0 = Rssi0; 4551 - Queue->Entry[Tail].Rssi1 = Rssi1; 4552 - Queue->Entry[Tail].Rssi2 = Rssi2; 4553 - Queue->Entry[Tail].Signal = Signal; 4554 - Queue->Entry[Tail].Wcid = (UCHAR)Wcid; 4555 - 4556 - Queue->Entry[Tail].Channel = pAd->LatchRfRegs.Channel; 4557 - 4558 - if (Msg != NULL) 4559 - { 4560 - NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen); 4561 - } 4562 - 4563 - NdisReleaseSpinLock(&(Queue->Lock)); 4564 - 4565 - RT28XX_MLME_HANDLER(pAd); 4566 - 4567 - return TRUE; 4568 - } 4569 - 4570 - 4571 - /*! \brief Dequeue a message from the MLME Queue 4572 - * \param *Queue The MLME Queue 4573 - * \param *Elem The message dequeued from MLME Queue 4574 - * \return TRUE if the Elem contains something, FALSE otherwise 4575 - * \pre 4576 - * \post 4577 - 4578 - IRQL = DISPATCH_LEVEL 4579 - 4580 - */ 4581 - BOOLEAN MlmeDequeue( 4582 - IN MLME_QUEUE *Queue, 4583 - OUT MLME_QUEUE_ELEM **Elem) 4584 - { 4585 - NdisAcquireSpinLock(&(Queue->Lock)); 4586 - *Elem = &(Queue->Entry[Queue->Head]); 4587 - Queue->Num--; 4588 - Queue->Head++; 4589 - if (Queue->Head == MAX_LEN_OF_MLME_QUEUE) 4590 - { 4591 - Queue->Head = 0; 4592 - } 4593 - NdisReleaseSpinLock(&(Queue->Lock)); 4594 - return TRUE; 4595 - } 4596 - 4597 - // IRQL = DISPATCH_LEVEL 4598 - VOID MlmeRestartStateMachine( 4599 - IN PRTMP_ADAPTER pAd) 4600 - { 4601 - BOOLEAN Cancelled; 4602 - 4603 - DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n")); 4604 - 4605 - { 4606 - // Cancel all timer events 4607 - // Be careful to cancel new added timer 4608 - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); 4609 - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled); 4610 - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled); 4611 - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); 4612 - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); 4613 - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); 4614 - } 4615 - 4616 - // Change back to original channel in case of doing scan 4617 - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); 4618 - AsicLockChannel(pAd, pAd->CommonCfg.Channel); 4619 - 4620 - // Resume MSDU which is turned off durning scan 4621 - RTMPResumeMsduTransmission(pAd); 4622 - 4623 - { 4624 - // Set all state machines back IDLE 4625 - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; 4626 - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; 4627 - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; 4628 - pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE; 4629 - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 4630 - pAd->Mlme.ActMachine.CurrState = ACT_IDLE; 4631 - } 4632 - } 4633 - 4634 - /*! \brief test if the MLME Queue is empty 4635 - * \param *Queue The MLME Queue 4636 - * \return TRUE if the Queue is empty, FALSE otherwise 4637 - * \pre 4638 - * \post 4639 - 4640 - IRQL = DISPATCH_LEVEL 4641 - 4642 - */ 4643 - BOOLEAN MlmeQueueEmpty( 4644 - IN MLME_QUEUE *Queue) 4645 - { 4646 - BOOLEAN Ans; 4647 - 4648 - NdisAcquireSpinLock(&(Queue->Lock)); 4649 - Ans = (Queue->Num == 0); 4650 - NdisReleaseSpinLock(&(Queue->Lock)); 4651 - 4652 - return Ans; 4653 - } 4654 - 4655 - /*! \brief test if the MLME Queue is full 4656 - * \param *Queue The MLME Queue 4657 - * \return TRUE if the Queue is empty, FALSE otherwise 4658 - * \pre 4659 - * \post 4660 - 4661 - IRQL = PASSIVE_LEVEL 4662 - IRQL = DISPATCH_LEVEL 4663 - 4664 - */ 4665 - BOOLEAN MlmeQueueFull( 4666 - IN MLME_QUEUE *Queue) 4667 - { 4668 - BOOLEAN Ans; 4669 - 4670 - NdisAcquireSpinLock(&(Queue->Lock)); 4671 - Ans = (Queue->Num == MAX_LEN_OF_MLME_QUEUE || Queue->Entry[Queue->Tail].Occupied); 4672 - NdisReleaseSpinLock(&(Queue->Lock)); 4673 - 4674 - return Ans; 4675 - } 4676 - 4677 - /*! \brief The destructor of MLME Queue 4678 - * \param 4679 - * \return 4680 - * \pre 4681 - * \post 4682 - * \note Clear Mlme Queue, Set Queue->Num to Zero. 4683 - 4684 - IRQL = PASSIVE_LEVEL 4685 - 4686 - */ 4687 - VOID MlmeQueueDestroy( 4688 - IN MLME_QUEUE *pQueue) 4689 - { 4690 - NdisAcquireSpinLock(&(pQueue->Lock)); 4691 - pQueue->Num = 0; 4692 - pQueue->Head = 0; 4693 - pQueue->Tail = 0; 4694 - NdisReleaseSpinLock(&(pQueue->Lock)); 4695 - NdisFreeSpinLock(&(pQueue->Lock)); 4696 - } 4697 - 4698 - /*! \brief To substitute the message type if the message is coming from external 4699 - * \param pFrame The frame received 4700 - * \param *Machine The state machine 4701 - * \param *MsgType the message type for the state machine 4702 - * \return TRUE if the substitution is successful, FALSE otherwise 4703 - * \pre 4704 - * \post 4705 - 4706 - IRQL = DISPATCH_LEVEL 4707 - 4708 - */ 4709 - BOOLEAN MsgTypeSubst( 4710 - IN PRTMP_ADAPTER pAd, 4711 - IN PFRAME_802_11 pFrame, 4712 - OUT INT *Machine, 4713 - OUT INT *MsgType) 4714 - { 4715 - USHORT Seq; 4716 - UCHAR EAPType; 4717 - PUCHAR pData; 4718 - 4719 - // Pointer to start of data frames including SNAP header 4720 - pData = (PUCHAR) pFrame + LENGTH_802_11; 4721 - 4722 - // The only data type will pass to this function is EAPOL frame 4723 - if (pFrame->Hdr.FC.Type == BTYPE_DATA) 4724 - { 4725 - if (NdisEqualMemory(SNAP_AIRONET, pData, LENGTH_802_1_H)) 4726 - { 4727 - // Cisco Aironet SNAP header 4728 - *Machine = AIRONET_STATE_MACHINE; 4729 - *MsgType = MT2_AIRONET_MSG; 4730 - return (TRUE); 4731 - } 4732 - { 4733 - *Machine = WPA_PSK_STATE_MACHINE; 4734 - EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1); 4735 - return(WpaMsgTypeSubst(EAPType, MsgType)); 4736 - } 4737 - } 4738 - 4739 - switch (pFrame->Hdr.FC.SubType) 4740 - { 4741 - case SUBTYPE_ASSOC_REQ: 4742 - *Machine = ASSOC_STATE_MACHINE; 4743 - *MsgType = MT2_PEER_ASSOC_REQ; 4744 - break; 4745 - case SUBTYPE_ASSOC_RSP: 4746 - *Machine = ASSOC_STATE_MACHINE; 4747 - *MsgType = MT2_PEER_ASSOC_RSP; 4748 - break; 4749 - case SUBTYPE_REASSOC_REQ: 4750 - *Machine = ASSOC_STATE_MACHINE; 4751 - *MsgType = MT2_PEER_REASSOC_REQ; 4752 - break; 4753 - case SUBTYPE_REASSOC_RSP: 4754 - *Machine = ASSOC_STATE_MACHINE; 4755 - *MsgType = MT2_PEER_REASSOC_RSP; 4756 - break; 4757 - case SUBTYPE_PROBE_REQ: 4758 - *Machine = SYNC_STATE_MACHINE; 4759 - *MsgType = MT2_PEER_PROBE_REQ; 4760 - break; 4761 - case SUBTYPE_PROBE_RSP: 4762 - *Machine = SYNC_STATE_MACHINE; 4763 - *MsgType = MT2_PEER_PROBE_RSP; 4764 - break; 4765 - case SUBTYPE_BEACON: 4766 - *Machine = SYNC_STATE_MACHINE; 4767 - *MsgType = MT2_PEER_BEACON; 4768 - break; 4769 - case SUBTYPE_ATIM: 4770 - *Machine = SYNC_STATE_MACHINE; 4771 - *MsgType = MT2_PEER_ATIM; 4772 - break; 4773 - case SUBTYPE_DISASSOC: 4774 - *Machine = ASSOC_STATE_MACHINE; 4775 - *MsgType = MT2_PEER_DISASSOC_REQ; 4776 - break; 4777 - case SUBTYPE_AUTH: 4778 - // get the sequence number from payload 24 Mac Header + 2 bytes algorithm 4779 - NdisMoveMemory(&Seq, &pFrame->Octet[2], sizeof(USHORT)); 4780 - if (Seq == 1 || Seq == 3) 4781 - { 4782 - *Machine = AUTH_RSP_STATE_MACHINE; 4783 - *MsgType = MT2_PEER_AUTH_ODD; 4784 - } 4785 - else if (Seq == 2 || Seq == 4) 4786 - { 4787 - *Machine = AUTH_STATE_MACHINE; 4788 - *MsgType = MT2_PEER_AUTH_EVEN; 4789 - } 4790 - else 4791 - { 4792 - return FALSE; 4793 - } 4794 - break; 4795 - case SUBTYPE_DEAUTH: 4796 - *Machine = AUTH_RSP_STATE_MACHINE; 4797 - *MsgType = MT2_PEER_DEAUTH; 4798 - break; 4799 - case SUBTYPE_ACTION: 4800 - *Machine = ACTION_STATE_MACHINE; 4801 - // Sometimes Sta will return with category bytes with MSB = 1, if they receive catogory out of their support 4802 - if ((pFrame->Octet[0]&0x7F) > MAX_PEER_CATE_MSG) 4803 - { 4804 - *MsgType = MT2_ACT_INVALID; 4805 - } 4806 - else 4807 - { 4808 - *MsgType = (pFrame->Octet[0]&0x7F); 4809 - } 4810 - break; 4811 - default: 4812 - return FALSE; 4813 - break; 4814 - } 4815 - 4816 - return TRUE; 4817 - } 4818 - 4819 - // =========================================================================================== 4820 - // state_machine.c 4821 - // =========================================================================================== 4822 - 4823 - /*! \brief Initialize the state machine. 4824 - * \param *S pointer to the state machine 4825 - * \param Trans State machine transition function 4826 - * \param StNr number of states 4827 - * \param MsgNr number of messages 4828 - * \param DefFunc default function, when there is invalid state/message combination 4829 - * \param InitState initial state of the state machine 4830 - * \param Base StateMachine base, internal use only 4831 - * \pre p_sm should be a legal pointer 4832 - * \post 4833 - 4834 - IRQL = PASSIVE_LEVEL 4835 - 4836 - */ 4837 - VOID StateMachineInit( 4838 - IN STATE_MACHINE *S, 4839 - IN STATE_MACHINE_FUNC Trans[], 4840 - IN ULONG StNr, 4841 - IN ULONG MsgNr, 4842 - IN STATE_MACHINE_FUNC DefFunc, 4843 - IN ULONG InitState, 4844 - IN ULONG Base) 4845 - { 4846 - ULONG i, j; 4847 - 4848 - // set number of states and messages 4849 - S->NrState = StNr; 4850 - S->NrMsg = MsgNr; 4851 - S->Base = Base; 4852 - 4853 - S->TransFunc = Trans; 4854 - 4855 - // init all state transition to default function 4856 - for (i = 0; i < StNr; i++) 4857 - { 4858 - for (j = 0; j < MsgNr; j++) 4859 - { 4860 - S->TransFunc[i * MsgNr + j] = DefFunc; 4861 - } 4862 - } 4863 - 4864 - // set the starting state 4865 - S->CurrState = InitState; 4866 - } 4867 - 4868 - /*! \brief This function fills in the function pointer into the cell in the state machine 4869 - * \param *S pointer to the state machine 4870 - * \param St state 4871 - * \param Msg incoming message 4872 - * \param f the function to be executed when (state, message) combination occurs at the state machine 4873 - * \pre *S should be a legal pointer to the state machine, st, msg, should be all within the range, Base should be set in the initial state 4874 - * \post 4875 - 4876 - IRQL = PASSIVE_LEVEL 4877 - 4878 - */ 4879 - VOID StateMachineSetAction( 4880 - IN STATE_MACHINE *S, 4881 - IN ULONG St, 4882 - IN ULONG Msg, 4883 - IN STATE_MACHINE_FUNC Func) 4884 - { 4885 - ULONG MsgIdx; 4886 - 4887 - MsgIdx = Msg - S->Base; 4888 - 4889 - if (St < S->NrState && MsgIdx < S->NrMsg) 4890 - { 4891 - // boundary checking before setting the action 4892 - S->TransFunc[St * S->NrMsg + MsgIdx] = Func; 4893 - } 4894 - } 4895 - 4896 - /*! \brief This function does the state transition 4897 - * \param *Adapter the NIC adapter pointer 4898 - * \param *S the state machine 4899 - * \param *Elem the message to be executed 4900 - * \return None 4901 - 4902 - IRQL = DISPATCH_LEVEL 4903 - 4904 - */ 4905 - VOID StateMachinePerformAction( 4906 - IN PRTMP_ADAPTER pAd, 4907 - IN STATE_MACHINE *S, 4908 - IN MLME_QUEUE_ELEM *Elem) 4909 - { 4910 - (*(S->TransFunc[S->CurrState * S->NrMsg + Elem->MsgType - S->Base]))(pAd, Elem); 4911 - } 4912 - 4913 - /* 4914 - ========================================================================== 4915 - Description: 4916 - The drop function, when machine executes this, the message is simply 4917 - ignored. This function does nothing, the message is freed in 4918 - StateMachinePerformAction() 4919 - ========================================================================== 4920 - */ 4921 - VOID Drop( 4922 - IN PRTMP_ADAPTER pAd, 4923 - IN MLME_QUEUE_ELEM *Elem) 4924 - { 4925 - } 4926 - 4927 - // =========================================================================================== 4928 - // lfsr.c 4929 - // =========================================================================================== 4930 - 4931 - /* 4932 - ========================================================================== 4933 - Description: 4934 - 4935 - IRQL = PASSIVE_LEVEL 4936 - 4937 - ========================================================================== 4938 - */ 4939 - VOID LfsrInit( 4940 - IN PRTMP_ADAPTER pAd, 4941 - IN ULONG Seed) 4942 - { 4943 - if (Seed == 0) 4944 - pAd->Mlme.ShiftReg = 1; 4945 - else 4946 - pAd->Mlme.ShiftReg = Seed; 4947 - } 4948 - 4949 - /* 4950 - ========================================================================== 4951 - Description: 4952 - ========================================================================== 4953 - */ 4954 - UCHAR RandomByte( 4955 - IN PRTMP_ADAPTER pAd) 4956 - { 4957 - ULONG i; 4958 - UCHAR R, Result; 4959 - 4960 - R = 0; 4961 - 4962 - if (pAd->Mlme.ShiftReg == 0) 4963 - NdisGetSystemUpTime((ULONG *)&pAd->Mlme.ShiftReg); 4964 - 4965 - for (i = 0; i < 8; i++) 4966 - { 4967 - if (pAd->Mlme.ShiftReg & 0x00000001) 4968 - { 4969 - pAd->Mlme.ShiftReg = ((pAd->Mlme.ShiftReg ^ LFSR_MASK) >> 1) | 0x80000000; 4970 - Result = 1; 4971 - } 4972 - else 4973 - { 4974 - pAd->Mlme.ShiftReg = pAd->Mlme.ShiftReg >> 1; 4975 - Result = 0; 4976 - } 4977 - R = (R << 1) | Result; 4978 - } 4979 - 4980 - return R; 4981 - } 4982 - 4983 - VOID AsicUpdateAutoFallBackTable( 4984 - IN PRTMP_ADAPTER pAd, 4985 - IN PUCHAR pRateTable) 4986 - { 4987 - UCHAR i; 4988 - HT_FBK_CFG0_STRUC HtCfg0; 4989 - HT_FBK_CFG1_STRUC HtCfg1; 4990 - LG_FBK_CFG0_STRUC LgCfg0; 4991 - LG_FBK_CFG1_STRUC LgCfg1; 4992 - PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate; 4993 - 4994 - // set to initial value 4995 - HtCfg0.word = 0x65432100; 4996 - HtCfg1.word = 0xedcba988; 4997 - LgCfg0.word = 0xedcba988; 4998 - LgCfg1.word = 0x00002100; 4999 - 5000 - pNextTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1; 5001 - for (i = 1; i < *((PUCHAR) pRateTable); i++) 5002 - { 5003 - pCurrTxRate = (PRTMP_TX_RATE_SWITCH)pRateTable+1+i; 5004 - switch (pCurrTxRate->Mode) 5005 - { 5006 - case 0: //CCK 5007 - break; 5008 - case 1: //OFDM 5009 - { 5010 - switch(pCurrTxRate->CurrMCS) 5011 - { 5012 - case 0: 5013 - LgCfg0.field.OFDMMCS0FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5014 - break; 5015 - case 1: 5016 - LgCfg0.field.OFDMMCS1FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5017 - break; 5018 - case 2: 5019 - LgCfg0.field.OFDMMCS2FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5020 - break; 5021 - case 3: 5022 - LgCfg0.field.OFDMMCS3FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5023 - break; 5024 - case 4: 5025 - LgCfg0.field.OFDMMCS4FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5026 - break; 5027 - case 5: 5028 - LgCfg0.field.OFDMMCS5FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5029 - break; 5030 - case 6: 5031 - LgCfg0.field.OFDMMCS6FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5032 - break; 5033 - case 7: 5034 - LgCfg0.field.OFDMMCS7FBK = (pNextTxRate->Mode == MODE_OFDM) ? (pNextTxRate->CurrMCS+8): pNextTxRate->CurrMCS; 5035 - break; 5036 - } 5037 - } 5038 - break; 5039 - case 2: //HT-MIX 5040 - case 3: //HT-GF 5041 - { 5042 - if ((pNextTxRate->Mode >= MODE_HTMIX) && (pCurrTxRate->CurrMCS != pNextTxRate->CurrMCS)) 5043 - { 5044 - switch(pCurrTxRate->CurrMCS) 5045 - { 5046 - case 0: 5047 - HtCfg0.field.HTMCS0FBK = pNextTxRate->CurrMCS; 5048 - break; 5049 - case 1: 5050 - HtCfg0.field.HTMCS1FBK = pNextTxRate->CurrMCS; 5051 - break; 5052 - case 2: 5053 - HtCfg0.field.HTMCS2FBK = pNextTxRate->CurrMCS; 5054 - break; 5055 - case 3: 5056 - HtCfg0.field.HTMCS3FBK = pNextTxRate->CurrMCS; 5057 - break; 5058 - case 4: 5059 - HtCfg0.field.HTMCS4FBK = pNextTxRate->CurrMCS; 5060 - break; 5061 - case 5: 5062 - HtCfg0.field.HTMCS5FBK = pNextTxRate->CurrMCS; 5063 - break; 5064 - case 6: 5065 - HtCfg0.field.HTMCS6FBK = pNextTxRate->CurrMCS; 5066 - break; 5067 - case 7: 5068 - HtCfg0.field.HTMCS7FBK = pNextTxRate->CurrMCS; 5069 - break; 5070 - case 8: 5071 - HtCfg1.field.HTMCS8FBK = pNextTxRate->CurrMCS; 5072 - break; 5073 - case 9: 5074 - HtCfg1.field.HTMCS9FBK = pNextTxRate->CurrMCS; 5075 - break; 5076 - case 10: 5077 - HtCfg1.field.HTMCS10FBK = pNextTxRate->CurrMCS; 5078 - break; 5079 - case 11: 5080 - HtCfg1.field.HTMCS11FBK = pNextTxRate->CurrMCS; 5081 - break; 5082 - case 12: 5083 - HtCfg1.field.HTMCS12FBK = pNextTxRate->CurrMCS; 5084 - break; 5085 - case 13: 5086 - HtCfg1.field.HTMCS13FBK = pNextTxRate->CurrMCS; 5087 - break; 5088 - case 14: 5089 - HtCfg1.field.HTMCS14FBK = pNextTxRate->CurrMCS; 5090 - break; 5091 - case 15: 5092 - HtCfg1.field.HTMCS15FBK = pNextTxRate->CurrMCS; 5093 - break; 5094 - default: 5095 - DBGPRINT(RT_DEBUG_ERROR, ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n", pCurrTxRate->CurrMCS)); 5096 - } 5097 - } 5098 - } 5099 - break; 5100 - } 5101 - 5102 - pNextTxRate = pCurrTxRate; 5103 - } 5104 - 5105 - RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word); 5106 - RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word); 5107 - RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word); 5108 - RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word); 5109 - } 5110 - 5111 - /* 5112 - ======================================================================== 5113 - 5114 - Routine Description: 5115 - Set MAC register value according operation mode. 5116 - OperationMode AND bNonGFExist are for MM and GF Proteciton. 5117 - If MM or GF mask is not set, those passing argument doesn't not take effect. 5118 - 5119 - Operation mode meaning: 5120 - = 0 : Pure HT, no preotection. 5121 - = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS. 5122 - = 0x10: No Transmission in 40M is protected. 5123 - = 0x11: Transmission in both 40M and 20M shall be protected 5124 - if (bNonGFExist) 5125 - we should choose not to use GF. But still set correct ASIC registers. 5126 - ======================================================================== 5127 - */ 5128 - VOID AsicUpdateProtect( 5129 - IN PRTMP_ADAPTER pAd, 5130 - IN USHORT OperationMode, 5131 - IN UCHAR SetMask, 5132 - IN BOOLEAN bDisableBGProtect, 5133 - IN BOOLEAN bNonGFExist) 5134 - { 5135 - PROT_CFG_STRUC ProtCfg, ProtCfg4; 5136 - UINT32 Protect[6]; 5137 - USHORT offset; 5138 - UCHAR i; 5139 - UINT32 MacReg = 0; 5140 - 5141 - if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8)) 5142 - { 5143 - return; 5144 - } 5145 - 5146 - if (pAd->BATable.numAsOriginator) 5147 - { 5148 - // 5149 - // enable the RTS/CTS to avoid channel collision 5150 - // 5151 - SetMask = ALLN_SETPROTECT; 5152 - OperationMode = 8; 5153 - } 5154 - 5155 - // Config ASIC RTS threshold register 5156 - RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg); 5157 - MacReg &= 0xFF0000FF; 5158 - 5159 - // If the user want disable RtsThreshold and enable Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096 5160 - if (( 5161 - (pAd->CommonCfg.BACapability.field.AmsduEnable) || 5162 - (pAd->CommonCfg.bAggregationCapable == TRUE)) 5163 - && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD) 5164 - { 5165 - MacReg |= (0x1000 << 8); 5166 - } 5167 - else 5168 - { 5169 - MacReg |= (pAd->CommonCfg.RtsThreshold << 8); 5170 - } 5171 - 5172 - RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg); 5173 - 5174 - // Initial common protection settings 5175 - RTMPZeroMemory(Protect, sizeof(Protect)); 5176 - ProtCfg4.word = 0; 5177 - ProtCfg.word = 0; 5178 - ProtCfg.field.TxopAllowGF40 = 1; 5179 - ProtCfg.field.TxopAllowGF20 = 1; 5180 - ProtCfg.field.TxopAllowMM40 = 1; 5181 - ProtCfg.field.TxopAllowMM20 = 1; 5182 - ProtCfg.field.TxopAllowOfdm = 1; 5183 - ProtCfg.field.TxopAllowCck = 1; 5184 - ProtCfg.field.RTSThEn = 1; 5185 - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; 5186 - 5187 - // update PHY mode and rate 5188 - if (pAd->CommonCfg.Channel > 14) 5189 - ProtCfg.field.ProtectRate = 0x4000; 5190 - ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate; 5191 - 5192 - // Handle legacy(B/G) protection 5193 - if (bDisableBGProtect) 5194 - { 5195 - //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; 5196 - ProtCfg.field.ProtectCtrl = 0; 5197 - Protect[0] = ProtCfg.word; 5198 - Protect[1] = ProtCfg.word; 5199 - } 5200 - else 5201 - { 5202 - //ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; 5203 - ProtCfg.field.ProtectCtrl = 0; // CCK do not need to be protected 5204 - Protect[0] = ProtCfg.word; 5205 - ProtCfg.field.ProtectCtrl = ASIC_CTS; // OFDM needs using CCK to protect 5206 - Protect[1] = ProtCfg.word; 5207 - } 5208 - 5209 - // Decide HT frame protection. 5210 - if ((SetMask & ALLN_SETPROTECT) != 0) 5211 - { 5212 - switch(OperationMode) 5213 - { 5214 - case 0x0: 5215 - // NO PROTECT 5216 - // 1.All STAs in the BSS are 20/40 MHz HT 5217 - // 2. in ai 20/40MHz BSS 5218 - // 3. all STAs are 20MHz in a 20MHz BSS 5219 - // Pure HT. no protection. 5220 - 5221 - // MM20_PROT_CFG 5222 - // Reserved (31:27) 5223 - // PROT_TXOP(25:20) -- 010111 5224 - // PROT_NAV(19:18) -- 01 (Short NAV protection) 5225 - // PROT_CTRL(17:16) -- 00 (None) 5226 - // PROT_RATE(15:0) -- 0x4004 (OFDM 24M) 5227 - Protect[2] = 0x01744004; 5228 - 5229 - // MM40_PROT_CFG 5230 - // Reserved (31:27) 5231 - // PROT_TXOP(25:20) -- 111111 5232 - // PROT_NAV(19:18) -- 01 (Short NAV protection) 5233 - // PROT_CTRL(17:16) -- 00 (None) 5234 - // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) 5235 - Protect[3] = 0x03f44084; 5236 - 5237 - // CF20_PROT_CFG 5238 - // Reserved (31:27) 5239 - // PROT_TXOP(25:20) -- 010111 5240 - // PROT_NAV(19:18) -- 01 (Short NAV protection) 5241 - // PROT_CTRL(17:16) -- 00 (None) 5242 - // PROT_RATE(15:0) -- 0x4004 (OFDM 24M) 5243 - Protect[4] = 0x01744004; 5244 - 5245 - // CF40_PROT_CFG 5246 - // Reserved (31:27) 5247 - // PROT_TXOP(25:20) -- 111111 5248 - // PROT_NAV(19:18) -- 01 (Short NAV protection) 5249 - // PROT_CTRL(17:16) -- 00 (None) 5250 - // PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) 5251 - Protect[5] = 0x03f44084; 5252 - 5253 - if (bNonGFExist) 5254 - { 5255 - // PROT_NAV(19:18) -- 01 (Short NAV protectiion) 5256 - // PROT_CTRL(17:16) -- 01 (RTS/CTS) 5257 - Protect[4] = 0x01754004; 5258 - Protect[5] = 0x03f54084; 5259 - } 5260 - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE; 5261 - break; 5262 - 5263 - case 1: 5264 - // This is "HT non-member protection mode." 5265 - // If there may be non-HT STAs my BSS 5266 - ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None) 5267 - ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1. 5268 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED)) 5269 - { 5270 - ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18.. 5271 - ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083; 5272 - } 5273 - //Assign Protection method for 20&40 MHz packets 5274 - ProtCfg.field.ProtectCtrl = ASIC_RTS; 5275 - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; 5276 - ProtCfg4.field.ProtectCtrl = ASIC_RTS; 5277 - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; 5278 - Protect[2] = ProtCfg.word; 5279 - Protect[3] = ProtCfg4.word; 5280 - Protect[4] = ProtCfg.word; 5281 - Protect[5] = ProtCfg4.word; 5282 - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; 5283 - break; 5284 - 5285 - case 2: 5286 - // If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets 5287 - ProtCfg.word = 0x01744004; // PROT_CTRL(17:16) : 0 (None) 5288 - ProtCfg4.word = 0x03f44084; // duplicaet legacy 24M. BW set 1. 5289 - 5290 - //Assign Protection method for 40MHz packets 5291 - ProtCfg4.field.ProtectCtrl = ASIC_RTS; 5292 - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; 5293 - Protect[2] = ProtCfg.word; 5294 - Protect[3] = ProtCfg4.word; 5295 - if (bNonGFExist) 5296 - { 5297 - ProtCfg.field.ProtectCtrl = ASIC_RTS; 5298 - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; 5299 - } 5300 - Protect[4] = ProtCfg.word; 5301 - Protect[5] = ProtCfg4.word; 5302 - 5303 - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE; 5304 - break; 5305 - 5306 - case 3: 5307 - // HT mixed mode. PROTECT ALL! 5308 - // Assign Rate 5309 - ProtCfg.word = 0x01744004; //duplicaet legacy 24M. BW set 1. 5310 - ProtCfg4.word = 0x03f44084; 5311 - // both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the 5312 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED)) 5313 - { 5314 - ProtCfg.word = 0x01740003; //ERP use Protection bit is set, use protection rate at Clause 18.. 5315 - ProtCfg4.word = 0x03f40003; // Don't duplicate RTS/CTS in CCK mode. 0x03f40083 5316 - } 5317 - //Assign Protection method for 20&40 MHz packets 5318 - ProtCfg.field.ProtectCtrl = ASIC_RTS; 5319 - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; 5320 - ProtCfg4.field.ProtectCtrl = ASIC_RTS; 5321 - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; 5322 - Protect[2] = ProtCfg.word; 5323 - Protect[3] = ProtCfg4.word; 5324 - Protect[4] = ProtCfg.word; 5325 - Protect[5] = ProtCfg4.word; 5326 - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; 5327 - break; 5328 - 5329 - case 8: 5330 - // Special on for Atheros problem n chip. 5331 - Protect[2] = 0x01754004; 5332 - Protect[3] = 0x03f54084; 5333 - Protect[4] = 0x01754004; 5334 - Protect[5] = 0x03f54084; 5335 - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; 5336 - break; 5337 - } 5338 - } 5339 - 5340 - offset = CCK_PROT_CFG; 5341 - for (i = 0;i < 6;i++) 5342 - { 5343 - if ((SetMask & (1<< i))) 5344 - { 5345 - RTMP_IO_WRITE32(pAd, offset + i*4, Protect[i]); 5346 - } 5347 - } 5348 - } 5349 - 5350 - 5351 - #ifdef RT30xx 5352 - /* 5353 - ======================================================================== 5354 - 5355 - Routine Description: Write RT30xx RF register through MAC 5356 - 5357 - Arguments: 5358 - 5359 - Return Value: 5360 - 5361 - IRQL = 5362 - 5363 - Note: 5364 - 5365 - ======================================================================== 5366 - */ 5367 - NTSTATUS RT30xxWriteRFRegister( 5368 - IN PRTMP_ADAPTER pAd, 5369 - IN UCHAR RegID, 5370 - IN UCHAR Value) 5371 - { 5372 - RF_CSR_CFG_STRUC rfcsr; 5373 - UINT i = 0; 5374 - 5375 - do 5376 - { 5377 - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); 5378 - 5379 - if (!rfcsr.field.RF_CSR_KICK) 5380 - break; 5381 - i++; 5382 - } 5383 - while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); 5384 - 5385 - if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) 5386 - { 5387 - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n")); 5388 - return STATUS_UNSUCCESSFUL; 5389 - } 5390 - 5391 - rfcsr.field.RF_CSR_WR = 1; 5392 - rfcsr.field.RF_CSR_KICK = 1; 5393 - rfcsr.field.TESTCSR_RFACC_REGNUM = RegID; 5394 - rfcsr.field.RF_CSR_DATA = Value; 5395 - 5396 - RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); 5397 - 5398 - return STATUS_SUCCESS; 5399 - } 5400 - 5401 - 5402 - /* 5403 - ======================================================================== 5404 - 5405 - Routine Description: Read RT30xx RF register through MAC 5406 - 5407 - Arguments: 5408 - 5409 - Return Value: 5410 - 5411 - IRQL = 5412 - 5413 - Note: 5414 - 5415 - ======================================================================== 5416 - */ 5417 - NTSTATUS RT30xxReadRFRegister( 5418 - IN PRTMP_ADAPTER pAd, 5419 - IN UCHAR RegID, 5420 - IN PUCHAR pValue) 5421 - { 5422 - RF_CSR_CFG_STRUC rfcsr; 5423 - UINT i=0, k=0; 5424 - 5425 - for (i=0; i<MAX_BUSY_COUNT; i++) 5426 - { 5427 - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); 5428 - 5429 - if (rfcsr.field.RF_CSR_KICK == BUSY) 5430 - { 5431 - continue; 5432 - } 5433 - rfcsr.word = 0; 5434 - rfcsr.field.RF_CSR_WR = 0; 5435 - rfcsr.field.RF_CSR_KICK = 1; 5436 - rfcsr.field.TESTCSR_RFACC_REGNUM = RegID; 5437 - RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); 5438 - for (k=0; k<MAX_BUSY_COUNT; k++) 5439 - { 5440 - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); 5441 - 5442 - if (rfcsr.field.RF_CSR_KICK == IDLE) 5443 - break; 5444 - } 5445 - if ((rfcsr.field.RF_CSR_KICK == IDLE) && 5446 - (rfcsr.field.TESTCSR_RFACC_REGNUM == RegID)) 5447 - { 5448 - *pValue = (UCHAR)rfcsr.field.RF_CSR_DATA; 5449 - break; 5450 - } 5451 - } 5452 - if (rfcsr.field.RF_CSR_KICK == BUSY) 5453 - { 5454 - DBGPRINT_ERR(("RF read R%d=0x%x fail, i[%d], k[%d]\n", RegID, rfcsr.word,i,k)); 5455 - return STATUS_UNSUCCESSFUL; 5456 - } 5457 - 5458 - return STATUS_SUCCESS; 5459 - } 5460 - #endif // RT30xx // 5461 - 5462 - #ifdef RT30xx 5463 - // add by johnli, RF power sequence setup 5464 - /* 5465 - ========================================================================== 5466 - Description: 5467 - 5468 - Load RF normal operation-mode setup 5469 - 5470 - ========================================================================== 5471 - */ 5472 - VOID RT30xxLoadRFNormalModeSetup( 5473 - IN PRTMP_ADAPTER pAd) 5474 - { 5475 - UCHAR RFValue; 5476 - 5477 - // RX0_PD & TX0_PD, RF R1 register Bit 2 & Bit 3 to 0 and RF_BLOCK_en,RX1_PD & TX1_PD, Bit0, Bit 4 & Bit5 to 1 5478 - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); 5479 - RFValue = (RFValue & (~0x0C)) | 0x31; 5480 - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); 5481 - 5482 - // TX_LO2_en, RF R15 register Bit 3 to 0 5483 - RT30xxReadRFRegister(pAd, RF_R15, &RFValue); 5484 - RFValue &= (~0x08); 5485 - RT30xxWriteRFRegister(pAd, RF_R15, RFValue); 5486 - 5487 - // TX_LO1_en, RF R17 register Bit 3 to 0 5488 - RT30xxReadRFRegister(pAd, RF_R17, &RFValue); 5489 - RFValue &= (~0x08); 5490 - // to fix rx long range issue 5491 - if (((pAd->MACVersion & 0xffff) >= 0x0211) && (pAd->NicConfig2.field.ExternalLNAForG == 0)) 5492 - { 5493 - RFValue |= 0x20; 5494 - } 5495 - RT30xxWriteRFRegister(pAd, RF_R17, RFValue); 5496 - 5497 - // RX_LO1_en, RF R20 register Bit 3 to 0 5498 - RT30xxReadRFRegister(pAd, RF_R20, &RFValue); 5499 - RFValue &= (~0x08); 5500 - RT30xxWriteRFRegister(pAd, RF_R20, RFValue); 5501 - 5502 - // RX_LO2_en, RF R21 register Bit 3 to 0 5503 - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); 5504 - RFValue &= (~0x08); 5505 - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); 5506 - 5507 - // LDORF_VC, RF R27 register Bit 2 to 0 5508 - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); 5509 - if ((pAd->MACVersion & 0xffff) < 0x0211) 5510 - RFValue = (RFValue & (~0x77)) | 0x3; 5511 - else 5512 - RFValue = (RFValue & (~0x77)); 5513 - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); 5514 - /* end johnli */ 5515 - } 5516 - 5517 - /* 5518 - ========================================================================== 5519 - Description: 5520 - 5521 - Load RF sleep-mode setup 5522 - 5523 - ========================================================================== 5524 - */ 5525 - VOID RT30xxLoadRFSleepModeSetup( 5526 - IN PRTMP_ADAPTER pAd) 5527 - { 5528 - UCHAR RFValue; 5529 - UINT32 MACValue; 5530 - 5531 - // RF_BLOCK_en. RF R1 register Bit 0 to 0 5532 - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); 5533 - RFValue &= (~0x01); 5534 - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); 5535 - 5536 - // VCO_IC, RF R7 register Bit 4 & Bit 5 to 0 5537 - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); 5538 - RFValue &= (~0x30); 5539 - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); 5540 - 5541 - // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 0 5542 - RT30xxReadRFRegister(pAd, RF_R09, &RFValue); 5543 - RFValue &= (~0x0E); 5544 - RT30xxWriteRFRegister(pAd, RF_R09, RFValue); 5545 - 5546 - // RX_CTB_en, RF R21 register Bit 7 to 0 5547 - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); 5548 - RFValue &= (~0x80); 5549 - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); 5550 - 5551 - // LDORF_VC, RF R27 register Bit 0, Bit 1 & Bit 2 to 1 5552 - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); 5553 - RFValue |= 0x77; 5554 - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); 5555 - 5556 - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); 5557 - MACValue |= 0x1D000000; 5558 - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); 5559 - } 5560 - 5561 - /* 5562 - ========================================================================== 5563 - Description: 5564 - 5565 - Reverse RF sleep-mode setup 5566 - 5567 - ========================================================================== 5568 - */ 5569 - VOID RT30xxReverseRFSleepModeSetup( 5570 - IN PRTMP_ADAPTER pAd) 5571 - { 5572 - UCHAR RFValue; 5573 - UINT32 MACValue; 5574 - 5575 - // RF_BLOCK_en, RF R1 register Bit 0 to 1 5576 - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); 5577 - RFValue |= 0x01; 5578 - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); 5579 - 5580 - // VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 5581 - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); 5582 - RFValue |= 0x30; 5583 - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); 5584 - 5585 - // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 5586 - RT30xxReadRFRegister(pAd, RF_R09, &RFValue); 5587 - RFValue |= 0x0E; 5588 - RT30xxWriteRFRegister(pAd, RF_R09, RFValue); 5589 - 5590 - // RX_CTB_en, RF R21 register Bit 7 to 1 5591 - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); 5592 - RFValue |= 0x80; 5593 - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); 5594 - 5595 - // LDORF_VC, RF R27 register Bit 2 to 0 5596 - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); 5597 - if ((pAd->MACVersion & 0xffff) < 0x0211) 5598 - RFValue = (RFValue & (~0x77)) | 0x3; 5599 - else 5600 - RFValue = (RFValue & (~0x77)); 5601 - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); 5602 - 5603 - // RT3071 version E has fixed this issue 5604 - if ((pAd->NicConfig2.field.DACTestBit == 1) && ((pAd->MACVersion & 0xffff) < 0x0211)) 5605 - { 5606 - // patch tx EVM issue temporarily 5607 - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); 5608 - MACValue = ((MACValue & 0xE0FFFFFF) | 0x0D000000); 5609 - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); 5610 - } 5611 - else 5612 - { 5613 - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); 5614 - MACValue = ((MACValue & 0xE0FFFFFF) | 0x01000000); 5615 - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); 5616 - } 5617 - } 5618 - // end johnli 5619 - #endif // RT30xx // 5620 - 5621 - /* 5622 - ========================================================================== 5623 - Description: 5624 - 5625 - IRQL = PASSIVE_LEVEL 5626 - IRQL = DISPATCH_LEVEL 5627 - 5628 - ========================================================================== 5629 - */ 5630 - VOID AsicSwitchChannel( 5631 - IN PRTMP_ADAPTER pAd, 5632 - IN UCHAR Channel, 5633 - IN BOOLEAN bScan) 5634 - { 5635 - ULONG R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0; 5636 - CHAR TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; //Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER; 5637 - UCHAR index; 5638 - UINT32 Value = 0; //BbpReg, Value; 5639 - RTMP_RF_REGS *RFRegTable; 5640 - 5641 - // Search Tx power value 5642 - #ifdef RT30xx 5643 - // We can't use ChannelList to search channel, since some central channl's txpowr doesn't list 5644 - // in ChannelList, so use TxPower array instead. 5645 - // 5646 - for (index = 0; index < MAX_NUM_OF_CHANNELS; index++) 5647 - { 5648 - if (Channel == pAd->TxPower[index].Channel) 5649 - { 5650 - TxPwer = pAd->TxPower[index].Power; 5651 - TxPwer2 = pAd->TxPower[index].Power2; 5652 - break; 5653 - } 5654 - } 5655 - #endif 5656 - #ifndef RT30xx 5657 - for (index = 0; index < pAd->ChannelListNum; index++) 5658 - { 5659 - if (Channel == pAd->ChannelList[index].Channel) 5660 - { 5661 - TxPwer = pAd->ChannelList[index].Power; 5662 - TxPwer2 = pAd->ChannelList[index].Power2; 5663 - break; 5664 - } 5665 - } 5666 - #endif 5667 - 5668 - if (index == MAX_NUM_OF_CHANNELS) 5669 - { 5670 - #ifndef RT30xx 5671 - DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Cant find the Channel#%d \n", Channel)); 5672 - #endif 5673 - #ifdef RT30xx 5674 - DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Can't find the Channel#%d \n", Channel)); 5675 - #endif 5676 - } 5677 - 5678 - #ifdef RT2870 5679 - // The RF programming sequence is difference between 3xxx and 2xxx 5680 - #ifdef RT30xx 5681 - if ((IS_RT3070(pAd) || IS_RT3090(pAd)) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020) || 5682 - (pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022))) 5683 - #endif 5684 - #ifndef RT30xx 5685 - if (IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020))) 5686 - #endif 5687 - { 5688 - /* modify by WY for Read RF Reg. error */ 5689 - UCHAR RFValue; 5690 - 5691 - for (index = 0; index < NUM_OF_3020_CHNL; index++) 5692 - { 5693 - if (Channel == FreqItems3020[index].Channel) 5694 - { 5695 - // Programming channel parameters 5696 - RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N); 5697 - RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K); 5698 - 5699 - #ifndef RT30xx 5700 - RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue); 5701 - RFValue = (RFValue & 0xFC) | FreqItems3020[index].R; 5702 - RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue); 5703 - 5704 - // Set Tx Power 5705 - RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue); 5706 - RFValue = (RFValue & 0xE0) | TxPwer; 5707 - RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue); 5708 - 5709 - // Set RF offset 5710 - RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue); 5711 - RFValue = (RFValue & 0x80) | pAd->RfFreqOffset; 5712 - RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue); 5713 - #endif 5714 - #ifdef RT30xx 5715 - RT30xxReadRFRegister(pAd, RF_R06, &RFValue); 5716 - RFValue = (RFValue & 0xFC) | FreqItems3020[index].R; 5717 - RT30xxWriteRFRegister(pAd, RF_R06, RFValue); 5718 - 5719 - // Set Tx0 Power 5720 - RT30xxReadRFRegister(pAd, RF_R12, &RFValue); 5721 - RFValue = (RFValue & 0xE0) | TxPwer; 5722 - RT30xxWriteRFRegister(pAd, RF_R12, RFValue); 5723 - 5724 - // Set Tx1 Power 5725 - RT30xxReadRFRegister(pAd, RF_R13, &RFValue); 5726 - RFValue = (RFValue & 0xE0) | TxPwer2; 5727 - RT30xxWriteRFRegister(pAd, RF_R13, RFValue); 5728 - 5729 - // Tx/Rx Stream setting 5730 - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); 5731 - //if (IS_RT3090(pAd)) 5732 - // RFValue |= 0x01; // Enable RF block. 5733 - RFValue &= 0x03; //clear bit[7~2] 5734 - if (pAd->Antenna.field.TxPath == 1) 5735 - RFValue |= 0xA0; 5736 - else if (pAd->Antenna.field.TxPath == 2) 5737 - RFValue |= 0x80; 5738 - if (pAd->Antenna.field.RxPath == 1) 5739 - RFValue |= 0x50; 5740 - else if (pAd->Antenna.field.RxPath == 2) 5741 - RFValue |= 0x40; 5742 - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); 5743 - 5744 - // Set RF offset 5745 - RT30xxReadRFRegister(pAd, RF_R23, &RFValue); 5746 - RFValue = (RFValue & 0x80) | pAd->RfFreqOffset; 5747 - RT30xxWriteRFRegister(pAd, RF_R23, RFValue); 5748 - #endif 5749 - // Set BW 5750 - if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40)) 5751 - { 5752 - RFValue = pAd->Mlme.CaliBW40RfR24; 5753 - //DISABLE_11N_CHECK(pAd); 5754 - } 5755 - else 5756 - { 5757 - RFValue = pAd->Mlme.CaliBW20RfR24; 5758 - } 5759 - #ifndef RT30xx 5760 - RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue); 5761 - 5762 - // Enable RF tuning 5763 - RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue); 5764 - RFValue = RFValue | 0x1; 5765 - RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue); 5766 - 5767 - // latch channel for future usage. 5768 - pAd->LatchRfRegs.Channel = Channel; 5769 - #endif 5770 - #ifdef RT30xx 5771 - RT30xxWriteRFRegister(pAd, RF_R24, RFValue); 5772 - RT30xxWriteRFRegister(pAd, RF_R31, RFValue); 5773 - 5774 - // Enable RF tuning 5775 - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); 5776 - RFValue = RFValue | 0x1; 5777 - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); 5778 - 5779 - // latch channel for future usage. 5780 - pAd->LatchRfRegs.Channel = Channel; 5781 - 5782 - DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n", 5783 - Channel, 5784 - pAd->RfIcType, 5785 - TxPwer, 5786 - TxPwer2, 5787 - pAd->Antenna.field.TxPath, 5788 - FreqItems3020[index].N, 5789 - FreqItems3020[index].K, 5790 - FreqItems3020[index].R)); 5791 - #endif 5792 - break; 5793 - } 5794 - } 5795 - 5796 - #ifndef RT30xx 5797 - DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n", 5798 - Channel, 5799 - pAd->RfIcType, 5800 - TxPwer, 5801 - TxPwer2, 5802 - pAd->Antenna.field.TxPath, 5803 - FreqItems3020[index].N, 5804 - FreqItems3020[index].K, 5805 - FreqItems3020[index].R)); 5806 - #endif 5807 - } 5808 - else 5809 - #endif // RT2870 // 5810 - { 5811 - RFRegTable = RF2850RegTable; 5812 - 5813 - switch (pAd->RfIcType) 5814 - { 5815 - case RFIC_2820: 5816 - case RFIC_2850: 5817 - case RFIC_2720: 5818 - case RFIC_2750: 5819 - 5820 - for (index = 0; index < NUM_OF_2850_CHNL; index++) 5821 - { 5822 - if (Channel == RFRegTable[index].Channel) 5823 - { 5824 - R2 = RFRegTable[index].R2; 5825 - if (pAd->Antenna.field.TxPath == 1) 5826 - { 5827 - R2 |= 0x4000; // If TXpath is 1, bit 14 = 1; 5828 - } 5829 - 5830 - if (pAd->Antenna.field.RxPath == 2) 5831 - { 5832 - R2 |= 0x40; // write 1 to off Rxpath. 5833 - } 5834 - else if (pAd->Antenna.field.RxPath == 1) 5835 - { 5836 - R2 |= 0x20040; // write 1 to off RxPath 5837 - } 5838 - 5839 - if (Channel > 14) 5840 - { 5841 - // initialize R3, R4 5842 - R3 = (RFRegTable[index].R3 & 0xffffc1ff); 5843 - R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15); 5844 - 5845 - // 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB 5846 - // R3 5847 - if ((TxPwer >= -7) && (TxPwer < 0)) 5848 - { 5849 - TxPwer = (7+TxPwer); 5850 - TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer); 5851 - R3 |= (TxPwer << 10); 5852 - DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer=%d \n", TxPwer)); 5853 - } 5854 - else 5855 - { 5856 - TxPwer = (TxPwer > 0xF) ? (0xF) : (TxPwer); 5857 - R3 |= (TxPwer << 10) | (1 << 9); 5858 - } 5859 - 5860 - // R4 5861 - if ((TxPwer2 >= -7) && (TxPwer2 < 0)) 5862 - { 5863 - TxPwer2 = (7+TxPwer2); 5864 - TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2); 5865 - R4 |= (TxPwer2 << 7); 5866 - DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: TxPwer2=%d \n", TxPwer2)); 5867 - } 5868 - else 5869 - { 5870 - TxPwer2 = (TxPwer2 > 0xF) ? (0xF) : (TxPwer2); 5871 - R4 |= (TxPwer2 << 7) | (1 << 6); 5872 - } 5873 - } 5874 - else 5875 - { 5876 - R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); // set TX power0 5877 - R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 <<6);// Set freq Offset & TxPwr1 5878 - } 5879 - 5880 - // Based on BBP current mode before changing RF channel. 5881 - if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40)) 5882 - { 5883 - R4 |=0x200000; 5884 - } 5885 - 5886 - // Update variables 5887 - pAd->LatchRfRegs.Channel = Channel; 5888 - pAd->LatchRfRegs.R1 = RFRegTable[index].R1; 5889 - pAd->LatchRfRegs.R2 = R2; 5890 - pAd->LatchRfRegs.R3 = R3; 5891 - pAd->LatchRfRegs.R4 = R4; 5892 - 5893 - // Set RF value 1's set R3[bit2] = [0] 5894 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1); 5895 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2); 5896 - RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04))); 5897 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4); 5898 - 5899 - RTMPusecDelay(200); 5900 - 5901 - // Set RF value 2's set R3[bit2] = [1] 5902 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1); 5903 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2); 5904 - RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 | 0x04)); 5905 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4); 5906 - 5907 - RTMPusecDelay(200); 5908 - 5909 - // Set RF value 3's set R3[bit2] = [0] 5910 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R1); 5911 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R2); 5912 - RTMP_RF_IO_WRITE32(pAd, (pAd->LatchRfRegs.R3 & (~0x04))); 5913 - RTMP_RF_IO_WRITE32(pAd, pAd->LatchRfRegs.R4); 5914 - 5915 - break; 5916 - } 5917 - } 5918 - break; 5919 - 5920 - default: 5921 - break; 5922 - } 5923 - } 5924 - 5925 - // Change BBP setting during siwtch from a->g, g->a 5926 - if (Channel <= 14) 5927 - { 5928 - ULONG TxPinCfg = 0x00050F0A;//Gary 2007/08/09 0x050A0A 5929 - 5930 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd))); 5931 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd))); 5932 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd))); 5933 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0);//(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. 5934 - //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); 5935 - 5936 - // Rx High power VGA offset for LNA select 5937 - if (pAd->NicConfig2.field.ExternalLNAForG) 5938 - { 5939 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); 5940 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46); 5941 - } 5942 - else 5943 - { 5944 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84); 5945 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50); 5946 - } 5947 - 5948 - // 5G band selection PIN, bit1 and bit2 are complement 5949 - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); 5950 - Value &= (~0x6); 5951 - Value |= (0x04); 5952 - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); 5953 - 5954 - // Turn off unused PA or LNA when only 1T or 1R 5955 - if (pAd->Antenna.field.TxPath == 1) 5956 - { 5957 - TxPinCfg &= 0xFFFFFFF3; 5958 - } 5959 - if (pAd->Antenna.field.RxPath == 1) 5960 - { 5961 - TxPinCfg &= 0xFFFFF3FF; 5962 - } 5963 - 5964 - RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg); 5965 - } 5966 - else 5967 - { 5968 - ULONG TxPinCfg = 0x00050F05;//Gary 2007/8/9 0x050505 5969 - 5970 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, (0x37 - GET_LNA_GAIN(pAd))); 5971 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, (0x37 - GET_LNA_GAIN(pAd))); 5972 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, (0x37 - GET_LNA_GAIN(pAd))); 5973 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0);//(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. 5974 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2); 5975 - 5976 - // Rx High power VGA offset for LNA select 5977 - if (pAd->NicConfig2.field.ExternalLNAForA) 5978 - { 5979 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46); 5980 - } 5981 - else 5982 - { 5983 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50); 5984 - } 5985 - 5986 - // 5G band selection PIN, bit1 and bit2 are complement 5987 - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); 5988 - Value &= (~0x6); 5989 - Value |= (0x02); 5990 - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); 5991 - 5992 - // Turn off unused PA or LNA when only 1T or 1R 5993 - if (pAd->Antenna.field.TxPath == 1) 5994 - { 5995 - TxPinCfg &= 0xFFFFFFF3; 5996 - } 5997 - if (pAd->Antenna.field.RxPath == 1) 5998 - { 5999 - TxPinCfg &= 0xFFFFF3FF; 6000 - } 6001 - 6002 - RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg); 6003 - } 6004 - 6005 - // R66 should be set according to Channel and use 20MHz when scanning 6006 - //RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd))); 6007 - if (bScan) 6008 - RTMPSetAGCInitValue(pAd, BW_20); 6009 - else 6010 - RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW); 6011 - 6012 - // 6013 - // On 11A, We should delay and wait RF/BBP to be stable 6014 - // and the appropriate time should be 1000 micro seconds 6015 - // 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL. 6016 - // 6017 - RTMPusecDelay(1000); 6018 - 6019 - DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%lu, Pwr1=%lu, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n", 6020 - Channel, 6021 - pAd->RfIcType, 6022 - (R3 & 0x00003e00) >> 9, 6023 - (R4 & 0x000007c0) >> 6, 6024 - pAd->Antenna.field.TxPath, 6025 - pAd->LatchRfRegs.R1, 6026 - pAd->LatchRfRegs.R2, 6027 - pAd->LatchRfRegs.R3, 6028 - pAd->LatchRfRegs.R4)); 6029 - } 6030 - 6031 - /* 6032 - ========================================================================== 6033 - Description: 6034 - This function is required for 2421 only, and should not be used during 6035 - site survey. It's only required after NIC decided to stay at a channel 6036 - for a longer period. 6037 - When this function is called, it's always after AsicSwitchChannel(). 6038 - 6039 - IRQL = PASSIVE_LEVEL 6040 - IRQL = DISPATCH_LEVEL 6041 - 6042 - ========================================================================== 6043 - */ 6044 - VOID AsicLockChannel( 6045 - IN PRTMP_ADAPTER pAd, 6046 - IN UCHAR Channel) 6047 - { 6048 - } 6049 - 6050 - /* 6051 - ========================================================================== 6052 - Description: 6053 - 6054 - IRQL = PASSIVE_LEVEL 6055 - IRQL = DISPATCH_LEVEL 6056 - 6057 - ========================================================================== 6058 - */ 6059 - VOID AsicAntennaSelect( 6060 - IN PRTMP_ADAPTER pAd, 6061 - IN UCHAR Channel) 6062 - { 6063 - #ifdef RT30xx 6064 - if (pAd->Mlme.OneSecPeriodicRound % 2 == 1) 6065 - { 6066 - // patch for AsicSetRxAnt failed 6067 - pAd->RxAnt.EvaluatePeriod = 0; 6068 - 6069 - // check every 2 second. If rcv-beacon less than 5 in the past 2 second, then AvgRSSI is no longer a 6070 - // valid indication of the distance between this AP and its clients. 6071 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 6072 - { 6073 - SHORT realavgrssi1; 6074 - 6075 - // if no traffic then reset average rssi to trigger evaluation 6076 - if (pAd->StaCfg.NumOfAvgRssiSample < 5) 6077 - { 6078 - pAd->RxAnt.Pair1LastAvgRssi = (-99); 6079 - pAd->RxAnt.Pair2LastAvgRssi = (-99); 6080 - DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no traffic/beacon, reset RSSI\n")); 6081 - } 6082 - 6083 - pAd->StaCfg.NumOfAvgRssiSample = 0; 6084 - realavgrssi1 = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt] >> 3); 6085 - 6086 - DBGPRINT(RT_DEBUG_TRACE,("Ant-realrssi0(%d), Lastrssi0(%d), EvaluateStableCnt=%d\n", realavgrssi1, pAd->RxAnt.Pair1LastAvgRssi, pAd->RxAnt.EvaluateStableCnt)); 6087 - 6088 - // if the difference between two rssi is larger or less than 5, then evaluate the other antenna 6089 - if ((pAd->RxAnt.EvaluateStableCnt < 2) || (realavgrssi1 > (pAd->RxAnt.Pair1LastAvgRssi + 5)) || (realavgrssi1 < (pAd->RxAnt.Pair1LastAvgRssi - 5))) 6090 - { 6091 - pAd->RxAnt.Pair1LastAvgRssi = realavgrssi1; 6092 - AsicEvaluateRxAnt(pAd); 6093 - } 6094 - } 6095 - else 6096 - { 6097 - // if not connected, always switch antenna to try to connect 6098 - UCHAR temp; 6099 - 6100 - temp = pAd->RxAnt.Pair1PrimaryRxAnt; 6101 - pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt; 6102 - pAd->RxAnt.Pair1SecondaryRxAnt = temp; 6103 - 6104 - DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no connect, switch to another one to try connection\n")); 6105 - 6106 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); 6107 - } 6108 - } 6109 - #endif /* RT30xx */ 6110 - } 6111 - 6112 - /* 6113 - ======================================================================== 6114 - 6115 - Routine Description: 6116 - Antenna miscellaneous setting. 6117 - 6118 - Arguments: 6119 - pAd Pointer to our adapter 6120 - BandState Indicate current Band State. 6121 - 6122 - Return Value: 6123 - None 6124 - 6125 - IRQL <= DISPATCH_LEVEL 6126 - 6127 - Note: 6128 - 1.) Frame End type control 6129 - only valid for G only (RF_2527 & RF_2529) 6130 - 0: means DPDT, set BBP R4 bit 5 to 1 6131 - 1: means SPDT, set BBP R4 bit 5 to 0 6132 - 6133 - 6134 - ======================================================================== 6135 - */ 6136 - VOID AsicAntennaSetting( 6137 - IN PRTMP_ADAPTER pAd, 6138 - IN ABGBAND_STATE BandState) 6139 - { 6140 - } 6141 - 6142 - VOID AsicRfTuningExec( 6143 - IN PVOID SystemSpecific1, 6144 - IN PVOID FunctionContext, 6145 - IN PVOID SystemSpecific2, 6146 - IN PVOID SystemSpecific3) 6147 - { 6148 - } 6149 - 6150 - /* 6151 - ========================================================================== 6152 - Description: 6153 - Gives CCK TX rate 2 more dB TX power. 6154 - This routine works only in LINK UP in INFRASTRUCTURE mode. 6155 - 6156 - calculate desired Tx power in RF R3.Tx0~5, should consider - 6157 - 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment) 6158 - 1. TxPowerPercentage 6159 - 2. auto calibration based on TSSI feedback 6160 - 3. extra 2 db for CCK 6161 - 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP 6162 - 6163 - NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment), 6164 - it should be called AFTER MlmeDynamicTxRatSwitching() 6165 - ========================================================================== 6166 - */ 6167 - VOID AsicAdjustTxPower( 6168 - IN PRTMP_ADAPTER pAd) 6169 - { 6170 - INT i, j; 6171 - CHAR DeltaPwr = 0; 6172 - BOOLEAN bAutoTxAgc = FALSE; 6173 - UCHAR TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep; 6174 - UCHAR BbpR1 = 0, BbpR49 = 0, idx; 6175 - PCHAR pTxAgcCompensate; 6176 - ULONG TxPwr[5]; 6177 - CHAR Value; 6178 - 6179 - if (pAd->CommonCfg.BBPCurrentBW == BW_40) 6180 - { 6181 - if (pAd->CommonCfg.CentralChannel > 14) 6182 - { 6183 - TxPwr[0] = pAd->Tx40MPwrCfgABand[0]; 6184 - TxPwr[1] = pAd->Tx40MPwrCfgABand[1]; 6185 - TxPwr[2] = pAd->Tx40MPwrCfgABand[2]; 6186 - TxPwr[3] = pAd->Tx40MPwrCfgABand[3]; 6187 - TxPwr[4] = pAd->Tx40MPwrCfgABand[4]; 6188 - } 6189 - else 6190 - { 6191 - TxPwr[0] = pAd->Tx40MPwrCfgGBand[0]; 6192 - TxPwr[1] = pAd->Tx40MPwrCfgGBand[1]; 6193 - TxPwr[2] = pAd->Tx40MPwrCfgGBand[2]; 6194 - TxPwr[3] = pAd->Tx40MPwrCfgGBand[3]; 6195 - TxPwr[4] = pAd->Tx40MPwrCfgGBand[4]; 6196 - } 6197 - } 6198 - else 6199 - { 6200 - if (pAd->CommonCfg.Channel > 14) 6201 - { 6202 - TxPwr[0] = pAd->Tx20MPwrCfgABand[0]; 6203 - TxPwr[1] = pAd->Tx20MPwrCfgABand[1]; 6204 - TxPwr[2] = pAd->Tx20MPwrCfgABand[2]; 6205 - TxPwr[3] = pAd->Tx20MPwrCfgABand[3]; 6206 - TxPwr[4] = pAd->Tx20MPwrCfgABand[4]; 6207 - } 6208 - else 6209 - { 6210 - TxPwr[0] = pAd->Tx20MPwrCfgGBand[0]; 6211 - TxPwr[1] = pAd->Tx20MPwrCfgGBand[1]; 6212 - TxPwr[2] = pAd->Tx20MPwrCfgGBand[2]; 6213 - TxPwr[3] = pAd->Tx20MPwrCfgGBand[3]; 6214 - TxPwr[4] = pAd->Tx20MPwrCfgGBand[4]; 6215 - } 6216 - } 6217 - 6218 - // TX power compensation for temperature variation based on TSSI. try every 4 second 6219 - if (pAd->Mlme.OneSecPeriodicRound % 4 == 0) 6220 - { 6221 - if (pAd->CommonCfg.Channel <= 14) 6222 - { 6223 - /* bg channel */ 6224 - bAutoTxAgc = pAd->bAutoTxAgcG; 6225 - TssiRef = pAd->TssiRefG; 6226 - pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0]; 6227 - pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0]; 6228 - TxAgcStep = pAd->TxAgcStepG; 6229 - pTxAgcCompensate = &pAd->TxAgcCompensateG; 6230 - } 6231 - else 6232 - { 6233 - /* a channel */ 6234 - bAutoTxAgc = pAd->bAutoTxAgcA; 6235 - TssiRef = pAd->TssiRefA; 6236 - pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0]; 6237 - pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0]; 6238 - TxAgcStep = pAd->TxAgcStepA; 6239 - pTxAgcCompensate = &pAd->TxAgcCompensateA; 6240 - } 6241 - 6242 - if (bAutoTxAgc) 6243 - { 6244 - /* BbpR1 is unsigned char */ 6245 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49); 6246 - 6247 - /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */ 6248 - /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */ 6249 - /* step value is defined in pAd->TxAgcStepG for tx power value */ 6250 - 6251 - /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */ 6252 - /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0 6253 - above value are examined in mass factory production */ 6254 - /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */ 6255 - 6256 - /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */ 6257 - /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */ 6258 - /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */ 6259 - 6260 - if (BbpR49 > pTssiMinusBoundary[1]) 6261 - { 6262 - // Reading is larger than the reference value 6263 - // check for how large we need to decrease the Tx power 6264 - for (idx = 1; idx < 5; idx++) 6265 - { 6266 - if (BbpR49 <= pTssiMinusBoundary[idx]) // Found the range 6267 - break; 6268 - } 6269 - // The index is the step we should decrease, idx = 0 means there is nothing to compensate 6270 - *pTxAgcCompensate = -(TxAgcStep * (idx-1)); 6271 - 6272 - DeltaPwr += (*pTxAgcCompensate); 6273 - DBGPRINT(RT_DEBUG_TRACE, ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n", 6274 - BbpR49, TssiRef, TxAgcStep, idx-1)); 6275 - } 6276 - else if (BbpR49 < pTssiPlusBoundary[1]) 6277 - { 6278 - // Reading is smaller than the reference value 6279 - // check for how large we need to increase the Tx power 6280 - for (idx = 1; idx < 5; idx++) 6281 - { 6282 - if (BbpR49 >= pTssiPlusBoundary[idx]) // Found the range 6283 - break; 6284 - } 6285 - // The index is the step we should increase, idx = 0 means there is nothing to compensate 6286 - *pTxAgcCompensate = TxAgcStep * (idx-1); 6287 - DeltaPwr += (*pTxAgcCompensate); 6288 - DBGPRINT(RT_DEBUG_TRACE, ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n", 6289 - BbpR49, TssiRef, TxAgcStep, idx-1)); 6290 - } 6291 - else 6292 - { 6293 - *pTxAgcCompensate = 0; 6294 - DBGPRINT(RT_DEBUG_TRACE, (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n", 6295 - BbpR49, TssiRef, TxAgcStep, 0)); 6296 - } 6297 - } 6298 - } 6299 - else 6300 - { 6301 - if (pAd->CommonCfg.Channel <= 14) 6302 - { 6303 - bAutoTxAgc = pAd->bAutoTxAgcG; 6304 - pTxAgcCompensate = &pAd->TxAgcCompensateG; 6305 - } 6306 - else 6307 - { 6308 - bAutoTxAgc = pAd->bAutoTxAgcA; 6309 - pTxAgcCompensate = &pAd->TxAgcCompensateA; 6310 - } 6311 - 6312 - if (bAutoTxAgc) 6313 - DeltaPwr += (*pTxAgcCompensate); 6314 - } 6315 - 6316 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1); 6317 - BbpR1 &= 0xFC; 6318 - 6319 - /* calculate delta power based on the percentage specified from UI */ 6320 - // E2PROM setting is calibrated for maximum TX power (i.e. 100%) 6321 - // We lower TX power here according to the percentage specified from UI 6322 - if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) // AUTO TX POWER control 6323 - ; 6324 - else if (pAd->CommonCfg.TxPowerPercentage > 90) // 91 ~ 100% & AUTO, treat as 100% in terms of mW 6325 - ; 6326 - else if (pAd->CommonCfg.TxPowerPercentage > 60) // 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1; 6327 - { 6328 - DeltaPwr -= 1; 6329 - } 6330 - else if (pAd->CommonCfg.TxPowerPercentage > 30) // 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3; 6331 - { 6332 - DeltaPwr -= 3; 6333 - } 6334 - else if (pAd->CommonCfg.TxPowerPercentage > 15) // 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6; 6335 - { 6336 - BbpR1 |= 0x01; 6337 - } 6338 - else if (pAd->CommonCfg.TxPowerPercentage > 9) // 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9; 6339 - { 6340 - BbpR1 |= 0x01; 6341 - DeltaPwr -= 3; 6342 - } 6343 - else // 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12; 6344 - { 6345 - BbpR1 |= 0x02; 6346 - } 6347 - 6348 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1); 6349 - 6350 - /* reset different new tx power for different TX rate */ 6351 - for(i=0; i<5; i++) 6352 - { 6353 - if (TxPwr[i] != 0xffffffff) 6354 - { 6355 - for (j=0; j<8; j++) 6356 - { 6357 - Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); /* 0 ~ 15 */ 6358 - 6359 - if ((Value + DeltaPwr) < 0) 6360 - { 6361 - Value = 0; /* min */ 6362 - } 6363 - else if ((Value + DeltaPwr) > 0xF) 6364 - { 6365 - Value = 0xF; /* max */ 6366 - } 6367 - else 6368 - { 6369 - Value += DeltaPwr; /* temperature compensation */ 6370 - } 6371 - 6372 - /* fill new value to CSR offset */ 6373 - TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4); 6374 - } 6375 - 6376 - /* write tx power value to CSR */ 6377 - /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M 6378 - TX power for OFDM 6M/9M 6379 - TX power for CCK5.5M/11M 6380 - TX power for CCK1M/2M */ 6381 - /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */ 6382 - RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, TxPwr[i]); 6383 - } 6384 - } 6385 - 6386 - } 6387 - 6388 - /* 6389 - ========================================================================== 6390 - Description: 6391 - put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup 6392 - automatically. Instead, MCU will issue a TwakeUpInterrupt to host after 6393 - the wakeup timer timeout. Driver has to issue a separate command to wake 6394 - PHY up. 6395 - 6396 - IRQL = DISPATCH_LEVEL 6397 - 6398 - ========================================================================== 6399 - */ 6400 - VOID AsicSleepThenAutoWakeup( 6401 - IN PRTMP_ADAPTER pAd, 6402 - IN USHORT TbttNumToNextWakeUp) 6403 - { 6404 - RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp); 6405 - } 6406 - 6407 - /* 6408 - ========================================================================== 6409 - Description: 6410 - AsicForceWakeup() is used whenever manual wakeup is required 6411 - AsicForceSleep() should only be used when not in INFRA BSS. When 6412 - in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead. 6413 - ========================================================================== 6414 - */ 6415 - VOID AsicForceSleep( 6416 - IN PRTMP_ADAPTER pAd) 6417 - { 6418 - 6419 - } 6420 - 6421 - /* 6422 - ========================================================================== 6423 - Description: 6424 - AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup) 6425 - expired. 6426 - 6427 - IRQL = PASSIVE_LEVEL 6428 - IRQL = DISPATCH_LEVEL 6429 - ========================================================================== 6430 - */ 6431 - VOID AsicForceWakeup( 6432 - IN PRTMP_ADAPTER pAd, 6433 - IN BOOLEAN bFromTx) 6434 - { 6435 - DBGPRINT(RT_DEBUG_TRACE, ("--> AsicForceWakeup \n")); 6436 - RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx); 6437 - } 6438 - 6439 - /* 6440 - ========================================================================== 6441 - Description: 6442 - Set My BSSID 6443 - 6444 - IRQL = DISPATCH_LEVEL 6445 - 6446 - ========================================================================== 6447 - */ 6448 - VOID AsicSetBssid( 6449 - IN PRTMP_ADAPTER pAd, 6450 - IN PUCHAR pBssid) 6451 - { 6452 - ULONG Addr4; 6453 - DBGPRINT(RT_DEBUG_TRACE, ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n", 6454 - pBssid[0],pBssid[1],pBssid[2],pBssid[3], pBssid[4],pBssid[5])); 6455 - 6456 - Addr4 = (ULONG)(pBssid[0]) | 6457 - (ULONG)(pBssid[1] << 8) | 6458 - (ULONG)(pBssid[2] << 16) | 6459 - (ULONG)(pBssid[3] << 24); 6460 - RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4); 6461 - 6462 - Addr4 = 0; 6463 - // always one BSSID in STA mode 6464 - Addr4 = (ULONG)(pBssid[4]) | (ULONG)(pBssid[5] << 8); 6465 - 6466 - RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4); 6467 - } 6468 - 6469 - VOID AsicSetMcastWC( 6470 - IN PRTMP_ADAPTER pAd) 6471 - { 6472 - MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[MCAST_WCID]; 6473 - USHORT offset; 6474 - 6475 - pEntry->Sst = SST_ASSOC; 6476 - pEntry->Aid = MCAST_WCID; // Softap supports 1 BSSID and use WCID=0 as multicast Wcid index 6477 - pEntry->PsMode = PWR_ACTIVE; 6478 - pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate; 6479 - offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE; 6480 - } 6481 - 6482 - /* 6483 - ========================================================================== 6484 - Description: 6485 - 6486 - IRQL = DISPATCH_LEVEL 6487 - 6488 - ========================================================================== 6489 - */ 6490 - VOID AsicDelWcidTab( 6491 - IN PRTMP_ADAPTER pAd, 6492 - IN UCHAR Wcid) 6493 - { 6494 - ULONG Addr0 = 0x0, Addr1 = 0x0; 6495 - ULONG offset; 6496 - 6497 - DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n",Wcid)); 6498 - offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE; 6499 - RTMP_IO_WRITE32(pAd, offset, Addr0); 6500 - offset += 4; 6501 - RTMP_IO_WRITE32(pAd, offset, Addr1); 6502 - } 6503 - 6504 - /* 6505 - ========================================================================== 6506 - Description: 6507 - 6508 - IRQL = DISPATCH_LEVEL 6509 - 6510 - ========================================================================== 6511 - */ 6512 - VOID AsicEnableRDG( 6513 - IN PRTMP_ADAPTER pAd) 6514 - { 6515 - TX_LINK_CFG_STRUC TxLinkCfg; 6516 - UINT32 Data = 0; 6517 - 6518 - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); 6519 - TxLinkCfg.field.TxRDGEn = 1; 6520 - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); 6521 - 6522 - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); 6523 - Data &= 0xFFFFFF00; 6524 - Data |= 0x80; 6525 - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); 6526 - 6527 - //OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); 6528 - } 6529 - 6530 - /* 6531 - ========================================================================== 6532 - Description: 6533 - 6534 - IRQL = DISPATCH_LEVEL 6535 - 6536 - ========================================================================== 6537 - */ 6538 - VOID AsicDisableRDG( 6539 - IN PRTMP_ADAPTER pAd) 6540 - { 6541 - TX_LINK_CFG_STRUC TxLinkCfg; 6542 - UINT32 Data = 0; 6543 - 6544 - 6545 - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); 6546 - TxLinkCfg.field.TxRDGEn = 0; 6547 - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); 6548 - 6549 - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); 6550 - 6551 - Data &= 0xFFFFFF00; 6552 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE) 6553 - && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE) 6554 - ) 6555 - { 6556 - // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode 6557 - if (pAd->CommonCfg.bEnableTxBurst) 6558 - Data |= 0x20; 6559 - } 6560 - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); 6561 - } 6562 - 6563 - /* 6564 - ========================================================================== 6565 - Description: 6566 - 6567 - IRQL = PASSIVE_LEVEL 6568 - IRQL = DISPATCH_LEVEL 6569 - 6570 - ========================================================================== 6571 - */ 6572 - VOID AsicDisableSync( 6573 - IN PRTMP_ADAPTER pAd) 6574 - { 6575 - BCN_TIME_CFG_STRUC csr; 6576 - 6577 - DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n")); 6578 - 6579 - // 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect 6580 - // that NIC will never wakes up because TSF stops and no more 6581 - // TBTT interrupts 6582 - pAd->TbttTickCount = 0; 6583 - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); 6584 - csr.field.bBeaconGen = 0; 6585 - csr.field.bTBTTEnable = 0; 6586 - csr.field.TsfSyncMode = 0; 6587 - csr.field.bTsfTicking = 0; 6588 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); 6589 - 6590 - } 6591 - 6592 - /* 6593 - ========================================================================== 6594 - Description: 6595 - 6596 - IRQL = DISPATCH_LEVEL 6597 - 6598 - ========================================================================== 6599 - */ 6600 - VOID AsicEnableBssSync( 6601 - IN PRTMP_ADAPTER pAd) 6602 - { 6603 - BCN_TIME_CFG_STRUC csr; 6604 - 6605 - DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n")); 6606 - 6607 - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); 6608 - 6609 - { 6610 - csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU 6611 - csr.field.bTsfTicking = 1; 6612 - csr.field.TsfSyncMode = 1; // sync TSF in INFRASTRUCTURE mode 6613 - csr.field.bBeaconGen = 0; // do NOT generate BEACON 6614 - csr.field.bTBTTEnable = 1; 6615 - } 6616 - 6617 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); 6618 - } 6619 - 6620 - /* 6621 - ========================================================================== 6622 - Description: 6623 - Note: 6624 - BEACON frame in shared memory should be built ok before this routine 6625 - can be called. Otherwise, a garbage frame maybe transmitted out every 6626 - Beacon period. 6627 - 6628 - IRQL = DISPATCH_LEVEL 6629 - 6630 - ========================================================================== 6631 - */ 6632 - VOID AsicEnableIbssSync( 6633 - IN PRTMP_ADAPTER pAd) 6634 - { 6635 - BCN_TIME_CFG_STRUC csr9; 6636 - PUCHAR ptr; 6637 - UINT i; 6638 - 6639 - DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n", pAd->BeaconTxWI.MPDUtotalByteCount)); 6640 - 6641 - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word); 6642 - csr9.field.bBeaconGen = 0; 6643 - csr9.field.bTBTTEnable = 0; 6644 - csr9.field.bTsfTicking = 0; 6645 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word); 6646 - 6647 - 6648 - #ifdef RT2870 6649 - // move BEACON TXD and frame content to on-chip memory 6650 - ptr = (PUCHAR)&pAd->BeaconTxWI; 6651 - for (i=0; i<TXWI_SIZE; i+=2) // 16-byte TXWI field 6652 - { 6653 - RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2); 6654 - ptr += 2; 6655 - } 6656 - 6657 - // start right after the 16-byte TXWI field 6658 - ptr = pAd->BeaconBuf; 6659 - for (i=0; i< pAd->BeaconTxWI.MPDUtotalByteCount; i+=2) 6660 - { 6661 - RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2); 6662 - ptr +=2; 6663 - } 6664 - #endif // RT2870 // 6665 - 6666 - // start sending BEACON 6667 - csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU 6668 - csr9.field.bTsfTicking = 1; 6669 - csr9.field.TsfSyncMode = 2; // sync TSF in IBSS mode 6670 - csr9.field.bTBTTEnable = 1; 6671 - csr9.field.bBeaconGen = 1; 6672 - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word); 6673 - } 6674 - 6675 - /* 6676 - ========================================================================== 6677 - Description: 6678 - 6679 - IRQL = PASSIVE_LEVEL 6680 - IRQL = DISPATCH_LEVEL 6681 - 6682 - ========================================================================== 6683 - */ 6684 - VOID AsicSetEdcaParm( 6685 - IN PRTMP_ADAPTER pAd, 6686 - IN PEDCA_PARM pEdcaParm) 6687 - { 6688 - EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg; 6689 - AC_TXOP_CSR0_STRUC csr0; 6690 - AC_TXOP_CSR1_STRUC csr1; 6691 - AIFSN_CSR_STRUC AifsnCsr; 6692 - CWMIN_CSR_STRUC CwminCsr; 6693 - CWMAX_CSR_STRUC CwmaxCsr; 6694 - int i; 6695 - 6696 - Ac0Cfg.word = 0; 6697 - Ac1Cfg.word = 0; 6698 - Ac2Cfg.word = 0; 6699 - Ac3Cfg.word = 0; 6700 - if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE)) 6701 - { 6702 - DBGPRINT(RT_DEBUG_TRACE,("AsicSetEdcaParm\n")); 6703 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED); 6704 - for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++) 6705 - { 6706 - if (pAd->MacTab.Content[i].ValidAsCLI || pAd->MacTab.Content[i].ValidAsApCli) 6707 - CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[i], fCLIENT_STATUS_WMM_CAPABLE); 6708 - } 6709 - 6710 - //======================================================== 6711 - // MAC Register has a copy . 6712 - //======================================================== 6713 - if( pAd->CommonCfg.bEnableTxBurst ) 6714 - { 6715 - // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode 6716 - Ac0Cfg.field.AcTxop = 0x20; // Suggest by John for TxBurst in HT Mode 6717 - } 6718 - else 6719 - Ac0Cfg.field.AcTxop = 0; // QID_AC_BE 6720 - Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS; 6721 - Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS; 6722 - Ac0Cfg.field.Aifsn = 2; 6723 - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word); 6724 - 6725 - Ac1Cfg.field.AcTxop = 0; // QID_AC_BK 6726 - Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS; 6727 - Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS; 6728 - Ac1Cfg.field.Aifsn = 2; 6729 - RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word); 6730 - 6731 - if (pAd->CommonCfg.PhyMode == PHY_11B) 6732 - { 6733 - Ac2Cfg.field.AcTxop = 192; // AC_VI: 192*32us ~= 6ms 6734 - Ac3Cfg.field.AcTxop = 96; // AC_VO: 96*32us ~= 3ms 6735 - } 6736 - else 6737 - { 6738 - Ac2Cfg.field.AcTxop = 96; // AC_VI: 96*32us ~= 3ms 6739 - Ac3Cfg.field.AcTxop = 48; // AC_VO: 48*32us ~= 1.5ms 6740 - } 6741 - Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS; 6742 - Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS; 6743 - Ac2Cfg.field.Aifsn = 2; 6744 - RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word); 6745 - Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS; 6746 - Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS; 6747 - Ac3Cfg.field.Aifsn = 2; 6748 - RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word); 6749 - 6750 - //======================================================== 6751 - // DMA Register has a copy too. 6752 - //======================================================== 6753 - csr0.field.Ac0Txop = 0; // QID_AC_BE 6754 - csr0.field.Ac1Txop = 0; // QID_AC_BK 6755 - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); 6756 - if (pAd->CommonCfg.PhyMode == PHY_11B) 6757 - { 6758 - csr1.field.Ac2Txop = 192; // AC_VI: 192*32us ~= 6ms 6759 - csr1.field.Ac3Txop = 96; // AC_VO: 96*32us ~= 3ms 6760 - } 6761 - else 6762 - { 6763 - csr1.field.Ac2Txop = 96; // AC_VI: 96*32us ~= 3ms 6764 - csr1.field.Ac3Txop = 48; // AC_VO: 48*32us ~= 1.5ms 6765 - } 6766 - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word); 6767 - 6768 - CwminCsr.word = 0; 6769 - CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS; 6770 - CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS; 6771 - CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS; 6772 - CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS; 6773 - RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word); 6774 - 6775 - CwmaxCsr.word = 0; 6776 - CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS; 6777 - CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS; 6778 - CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS; 6779 - CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS; 6780 - RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word); 6781 - 6782 - RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222); 6783 - 6784 - NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(EDCA_PARM)); 6785 - } 6786 - else 6787 - { 6788 - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED); 6789 - //======================================================== 6790 - // MAC Register has a copy. 6791 - //======================================================== 6792 - // 6793 - // Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27 6794 - // To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue. 6795 - // 6796 - //pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this 6797 - 6798 - Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE]; 6799 - Ac0Cfg.field.Cwmin= pEdcaParm->Cwmin[QID_AC_BE]; 6800 - Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE]; 6801 - Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; //+1; 6802 - 6803 - Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK]; 6804 - Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; //+2; 6805 - Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK]; 6806 - Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; //+1; 6807 - 6808 - Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10; 6809 - Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI]; 6810 - Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI]; 6811 - Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI]; 6812 - 6813 - { 6814 - // Tuning for Wi-Fi WMM S06 6815 - if (pAd->CommonCfg.bWiFiTest && 6816 - pEdcaParm->Aifsn[QID_AC_VI] == 10) 6817 - Ac2Cfg.field.Aifsn -= 1; 6818 - 6819 - // Tuning for TGn Wi-Fi 5.2.32 6820 - // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta 6821 - if (STA_TGN_WIFI_ON(pAd) && 6822 - pEdcaParm->Aifsn[QID_AC_VI] == 10) 6823 - { 6824 - Ac0Cfg.field.Aifsn = 3; 6825 - Ac2Cfg.field.AcTxop = 5; 6826 - } 6827 - 6828 - #ifdef RT30xx 6829 - if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020) 6830 - { 6831 - // Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta. 6832 - Ac2Cfg.field.Aifsn = 5; 6833 - } 6834 - #endif // RT30xx // 6835 - } 6836 - 6837 - Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO]; 6838 - Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO]; 6839 - Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO]; 6840 - Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO]; 6841 - 6842 - //#ifdef WIFI_TEST 6843 - if (pAd->CommonCfg.bWiFiTest) 6844 - { 6845 - if (Ac3Cfg.field.AcTxop == 102) 6846 - { 6847 - Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm->Txop[QID_AC_BE] : 10; 6848 - Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]-1; /* AIFSN must >= 1 */ 6849 - Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK]; 6850 - Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; 6851 - Ac2Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VI]; 6852 - } /* End of if */ 6853 - } 6854 - //#endif // WIFI_TEST // 6855 - 6856 - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word); 6857 - RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word); 6858 - RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word); 6859 - RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word); 6860 - 6861 - 6862 - //======================================================== 6863 - // DMA Register has a copy too. 6864 - //======================================================== 6865 - csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop; 6866 - csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop; 6867 - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); 6868 - 6869 - csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop; 6870 - csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop; 6871 - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word); 6872 - 6873 - CwminCsr.word = 0; 6874 - CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE]; 6875 - CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK]; 6876 - CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI]; 6877 - 6878 - CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; //for TGn wifi test 6879 - 6880 - RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word); 6881 - 6882 - CwmaxCsr.word = 0; 6883 - CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE]; 6884 - CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK]; 6885 - CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI]; 6886 - CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO]; 6887 - RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word); 6888 - 6889 - AifsnCsr.word = 0; 6890 - AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BE]; 6891 - AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BK]; 6892 - AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_VI]; 6893 - 6894 - { 6895 - // Tuning for Wi-Fi WMM S06 6896 - if (pAd->CommonCfg.bWiFiTest && 6897 - pEdcaParm->Aifsn[QID_AC_VI] == 10) 6898 - AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4; 6899 - 6900 - // Tuning for TGn Wi-Fi 5.2.32 6901 - // STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta 6902 - if (STA_TGN_WIFI_ON(pAd) && 6903 - pEdcaParm->Aifsn[QID_AC_VI] == 10) 6904 - { 6905 - AifsnCsr.field.Aifsn0 = 3; 6906 - AifsnCsr.field.Aifsn2 = 7; 6907 - } 6908 - 6909 - if (INFRA_ON(pAd)) 6910 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_WMM_CAPABLE); 6911 - } 6912 - 6913 - AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; //pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test 6914 - #ifdef RT30xx 6915 - if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020) 6916 - AifsnCsr.field.Aifsn2 = 0x2; //pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04. 6917 - #endif // RT30xx // 6918 - 6919 - RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word); 6920 - 6921 - NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM)); 6922 - if (!ADHOC_ON(pAd)) 6923 - { 6924 - DBGPRINT(RT_DEBUG_TRACE,("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n", pEdcaParm->EdcaUpdateCount)); 6925 - DBGPRINT(RT_DEBUG_TRACE,(" AC_BE %2d %2d %2d %4d %d\n", 6926 - pEdcaParm->Aifsn[0], 6927 - pEdcaParm->Cwmin[0], 6928 - pEdcaParm->Cwmax[0], 6929 - pEdcaParm->Txop[0]<<5, 6930 - pEdcaParm->bACM[0])); 6931 - DBGPRINT(RT_DEBUG_TRACE,(" AC_BK %2d %2d %2d %4d %d\n", 6932 - pEdcaParm->Aifsn[1], 6933 - pEdcaParm->Cwmin[1], 6934 - pEdcaParm->Cwmax[1], 6935 - pEdcaParm->Txop[1]<<5, 6936 - pEdcaParm->bACM[1])); 6937 - DBGPRINT(RT_DEBUG_TRACE,(" AC_VI %2d %2d %2d %4d %d\n", 6938 - pEdcaParm->Aifsn[2], 6939 - pEdcaParm->Cwmin[2], 6940 - pEdcaParm->Cwmax[2], 6941 - pEdcaParm->Txop[2]<<5, 6942 - pEdcaParm->bACM[2])); 6943 - DBGPRINT(RT_DEBUG_TRACE,(" AC_VO %2d %2d %2d %4d %d\n", 6944 - pEdcaParm->Aifsn[3], 6945 - pEdcaParm->Cwmin[3], 6946 - pEdcaParm->Cwmax[3], 6947 - pEdcaParm->Txop[3]<<5, 6948 - pEdcaParm->bACM[3])); 6949 - } 6950 - } 6951 - } 6952 - 6953 - /* 6954 - ========================================================================== 6955 - Description: 6956 - 6957 - IRQL = PASSIVE_LEVEL 6958 - IRQL = DISPATCH_LEVEL 6959 - 6960 - ========================================================================== 6961 - */ 6962 - VOID AsicSetSlotTime( 6963 - IN PRTMP_ADAPTER pAd, 6964 - IN BOOLEAN bUseShortSlotTime) 6965 - { 6966 - ULONG SlotTime; 6967 - UINT32 RegValue = 0; 6968 - 6969 - if (pAd->CommonCfg.Channel > 14) 6970 - bUseShortSlotTime = TRUE; 6971 - 6972 - if (bUseShortSlotTime) 6973 - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); 6974 - else 6975 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); 6976 - 6977 - SlotTime = (bUseShortSlotTime)? 9 : 20; 6978 - 6979 - { 6980 - #ifndef RT30xx 6981 - // force using short SLOT time for FAE to demo performance when TxBurst is ON 6982 - if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))) 6983 - || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)) 6984 - ) 6985 - { 6986 - // In this case, we will think it is doing Wi-Fi test 6987 - // And we will not set to short slot when bEnableTxBurst is TRUE. 6988 - } 6989 - else if (pAd->CommonCfg.bEnableTxBurst) 6990 - #endif 6991 - #ifdef RT30xx 6992 - if (pAd->CommonCfg.bEnableTxBurst) 6993 - #endif 6994 - SlotTime = 9; 6995 - } 6996 - 6997 - // 6998 - // For some reasons, always set it to short slot time. 6999 - // 7000 - // ToDo: Should consider capability with 11B 7001 - // 7002 - if (pAd->StaCfg.BssType == BSS_ADHOC) 7003 - SlotTime = 20; 7004 - 7005 - RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue); 7006 - RegValue = RegValue & 0xFFFFFF00; 7007 - 7008 - RegValue |= SlotTime; 7009 - 7010 - RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue); 7011 - } 7012 - 7013 - /* 7014 - ======================================================================== 7015 - Description: 7016 - Add Shared key information into ASIC. 7017 - Update shared key, TxMic and RxMic to Asic Shared key table 7018 - Update its cipherAlg to Asic Shared key Mode. 7019 - 7020 - Return: 7021 - ======================================================================== 7022 - */ 7023 - VOID AsicAddSharedKeyEntry( 7024 - IN PRTMP_ADAPTER pAd, 7025 - IN UCHAR BssIndex, 7026 - IN UCHAR KeyIdx, 7027 - IN UCHAR CipherAlg, 7028 - IN PUCHAR pKey, 7029 - IN PUCHAR pTxMic, 7030 - IN PUCHAR pRxMic) 7031 - { 7032 - ULONG offset; //, csr0; 7033 - SHAREDKEY_MODE_STRUC csr1; 7034 - 7035 - DBGPRINT(RT_DEBUG_TRACE, ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,KeyIdx)); 7036 - //============================================================================================ 7037 - 7038 - DBGPRINT(RT_DEBUG_TRACE,("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg], BssIndex*4 + KeyIdx)); 7039 - DBGPRINT_RAW(RT_DEBUG_TRACE, (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7040 - pKey[0],pKey[1],pKey[2],pKey[3],pKey[4],pKey[5],pKey[6],pKey[7],pKey[8],pKey[9],pKey[10],pKey[11],pKey[12],pKey[13],pKey[14],pKey[15])); 7041 - if (pRxMic) 7042 - { 7043 - DBGPRINT_RAW(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7044 - pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7])); 7045 - } 7046 - if (pTxMic) 7047 - { 7048 - DBGPRINT_RAW(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7049 - pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7])); 7050 - } 7051 - //============================================================================================ 7052 - // 7053 - // fill key material - key + TX MIC + RX MIC 7054 - // 7055 - 7056 - #ifdef RT2870 7057 - { 7058 - offset = SHARED_KEY_TABLE_BASE + (4*BssIndex + KeyIdx)*HW_KEY_ENTRY_SIZE; 7059 - RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY); 7060 - 7061 - offset += MAX_LEN_OF_SHARE_KEY; 7062 - if (pTxMic) 7063 - { 7064 - RTUSBMultiWrite(pAd, offset, pTxMic, 8); 7065 - } 7066 - 7067 - offset += 8; 7068 - if (pRxMic) 7069 - { 7070 - RTUSBMultiWrite(pAd, offset, pRxMic, 8); 7071 - } 7072 - } 7073 - #endif // RT2870 // 7074 - 7075 - // 7076 - // Update cipher algorithm. WSTA always use BSS0 7077 - // 7078 - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word); 7079 - DBGPRINT(RT_DEBUG_TRACE,("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n", BssIndex,KeyIdx, csr1.word)); 7080 - if ((BssIndex%2) == 0) 7081 - { 7082 - if (KeyIdx == 0) 7083 - csr1.field.Bss0Key0CipherAlg = CipherAlg; 7084 - else if (KeyIdx == 1) 7085 - csr1.field.Bss0Key1CipherAlg = CipherAlg; 7086 - else if (KeyIdx == 2) 7087 - csr1.field.Bss0Key2CipherAlg = CipherAlg; 7088 - else 7089 - csr1.field.Bss0Key3CipherAlg = CipherAlg; 7090 - } 7091 - else 7092 - { 7093 - if (KeyIdx == 0) 7094 - csr1.field.Bss1Key0CipherAlg = CipherAlg; 7095 - else if (KeyIdx == 1) 7096 - csr1.field.Bss1Key1CipherAlg = CipherAlg; 7097 - else if (KeyIdx == 2) 7098 - csr1.field.Bss1Key2CipherAlg = CipherAlg; 7099 - else 7100 - csr1.field.Bss1Key3CipherAlg = CipherAlg; 7101 - } 7102 - DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word)); 7103 - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word); 7104 - 7105 - } 7106 - 7107 - // IRQL = DISPATCH_LEVEL 7108 - VOID AsicRemoveSharedKeyEntry( 7109 - IN PRTMP_ADAPTER pAd, 7110 - IN UCHAR BssIndex, 7111 - IN UCHAR KeyIdx) 7112 - { 7113 - //ULONG SecCsr0; 7114 - SHAREDKEY_MODE_STRUC csr1; 7115 - 7116 - DBGPRINT(RT_DEBUG_TRACE,("AsicRemoveSharedKeyEntry: #%d \n", BssIndex*4 + KeyIdx)); 7117 - 7118 - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), &csr1.word); 7119 - if ((BssIndex%2) == 0) 7120 - { 7121 - if (KeyIdx == 0) 7122 - csr1.field.Bss0Key0CipherAlg = 0; 7123 - else if (KeyIdx == 1) 7124 - csr1.field.Bss0Key1CipherAlg = 0; 7125 - else if (KeyIdx == 2) 7126 - csr1.field.Bss0Key2CipherAlg = 0; 7127 - else 7128 - csr1.field.Bss0Key3CipherAlg = 0; 7129 - } 7130 - else 7131 - { 7132 - if (KeyIdx == 0) 7133 - csr1.field.Bss1Key0CipherAlg = 0; 7134 - else if (KeyIdx == 1) 7135 - csr1.field.Bss1Key1CipherAlg = 0; 7136 - else if (KeyIdx == 2) 7137 - csr1.field.Bss1Key2CipherAlg = 0; 7138 - else 7139 - csr1.field.Bss1Key3CipherAlg = 0; 7140 - } 7141 - DBGPRINT(RT_DEBUG_TRACE,("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", BssIndex, csr1.word)); 7142 - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE+4*(BssIndex/2), csr1.word); 7143 - ASSERT(BssIndex < 4); 7144 - ASSERT(KeyIdx < 4); 7145 - 7146 - } 7147 - 7148 - 7149 - VOID AsicUpdateWCIDAttribute( 7150 - IN PRTMP_ADAPTER pAd, 7151 - IN USHORT WCID, 7152 - IN UCHAR BssIndex, 7153 - IN UCHAR CipherAlg, 7154 - IN BOOLEAN bUsePairewiseKeyTable) 7155 - { 7156 - ULONG WCIDAttri = 0, offset; 7157 - 7158 - // 7159 - // Update WCID attribute. 7160 - // Only TxKey could update WCID attribute. 7161 - // 7162 - offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE); 7163 - WCIDAttri = (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable); 7164 - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); 7165 - } 7166 - 7167 - VOID AsicUpdateWCIDIVEIV( 7168 - IN PRTMP_ADAPTER pAd, 7169 - IN USHORT WCID, 7170 - IN ULONG uIV, 7171 - IN ULONG uEIV) 7172 - { 7173 - ULONG offset; 7174 - 7175 - offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE); 7176 - 7177 - RTMP_IO_WRITE32(pAd, offset, uIV); 7178 - RTMP_IO_WRITE32(pAd, offset + 4, uEIV); 7179 - } 7180 - 7181 - VOID AsicUpdateRxWCIDTable( 7182 - IN PRTMP_ADAPTER pAd, 7183 - IN USHORT WCID, 7184 - IN PUCHAR pAddr) 7185 - { 7186 - ULONG offset; 7187 - ULONG Addr; 7188 - 7189 - offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE); 7190 - Addr = pAddr[0] + (pAddr[1] << 8) +(pAddr[2] << 16) +(pAddr[3] << 24); 7191 - RTMP_IO_WRITE32(pAd, offset, Addr); 7192 - Addr = pAddr[4] + (pAddr[5] << 8); 7193 - RTMP_IO_WRITE32(pAd, offset + 4, Addr); 7194 - } 7195 - 7196 - 7197 - /* 7198 - ======================================================================== 7199 - 7200 - Routine Description: 7201 - Set Cipher Key, Cipher algorithm, IV/EIV to Asic 7202 - 7203 - Arguments: 7204 - pAd Pointer to our adapter 7205 - WCID WCID Entry number. 7206 - BssIndex BSSID index, station or none multiple BSSID support 7207 - this value should be 0. 7208 - KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled 7209 - pCipherKey Pointer to Cipher Key. 7210 - bUsePairewiseKeyTable TRUE means saved the key in SharedKey table, 7211 - otherwise PairewiseKey table 7212 - bTxKey This is the transmit key if enabled. 7213 - 7214 - Return Value: 7215 - None 7216 - 7217 - Note: 7218 - This routine will set the relative key stuff to Asic including WCID attribute, 7219 - Cipher Key, Cipher algorithm and IV/EIV. 7220 - 7221 - IV/EIV will be update if this CipherKey is the transmission key because 7222 - ASIC will base on IV's KeyID value to select Cipher Key. 7223 - 7224 - If bTxKey sets to FALSE, this is not the TX key, but it could be 7225 - RX key 7226 - 7227 - For AP mode bTxKey must be always set to TRUE. 7228 - ======================================================================== 7229 - */ 7230 - VOID AsicAddKeyEntry( 7231 - IN PRTMP_ADAPTER pAd, 7232 - IN USHORT WCID, 7233 - IN UCHAR BssIndex, 7234 - IN UCHAR KeyIdx, 7235 - IN PCIPHER_KEY pCipherKey, 7236 - IN BOOLEAN bUsePairewiseKeyTable, 7237 - IN BOOLEAN bTxKey) 7238 - { 7239 - ULONG offset; 7240 - UCHAR IV4 = 0; 7241 - PUCHAR pKey = pCipherKey->Key; 7242 - PUCHAR pTxMic = pCipherKey->TxMic; 7243 - PUCHAR pRxMic = pCipherKey->RxMic; 7244 - PUCHAR pTxtsc = pCipherKey->TxTsc; 7245 - UCHAR CipherAlg = pCipherKey->CipherAlg; 7246 - SHAREDKEY_MODE_STRUC csr1; 7247 - 7248 - DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n")); 7249 - // 7250 - // 1.) decide key table offset 7251 - // 7252 - if (bUsePairewiseKeyTable) 7253 - offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE); 7254 - else 7255 - offset = SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE; 7256 - 7257 - // 7258 - // 2.) Set Key to Asic 7259 - // 7260 - //for (i = 0; i < KeyLen; i++) 7261 - 7262 - #ifdef RT2870 7263 - RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY); 7264 - offset += MAX_LEN_OF_PEER_KEY; 7265 - 7266 - // 7267 - // 3.) Set MIC key if available 7268 - // 7269 - if (pTxMic) 7270 - { 7271 - RTUSBMultiWrite(pAd, offset, pTxMic, 8); 7272 - } 7273 - offset += LEN_TKIP_TXMICK; 7274 - 7275 - if (pRxMic) 7276 - { 7277 - RTUSBMultiWrite(pAd, offset, pRxMic, 8); 7278 - } 7279 - #endif // RT2870 // 7280 - 7281 - // 7282 - // 4.) Modify IV/EIV if needs 7283 - // This will force Asic to use this key ID by setting IV. 7284 - // 7285 - if (bTxKey) 7286 - { 7287 - 7288 - #ifdef RT2870 7289 - UINT32 tmpVal; 7290 - 7291 - // 7292 - // Write IV 7293 - // 7294 - IV4 = (KeyIdx << 6); 7295 - if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) ||(CipherAlg == CIPHER_AES)) 7296 - IV4 |= 0x20; // turn on extension bit means EIV existence 7297 - 7298 - tmpVal = pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) + (pTxtsc[0] << 16) + (IV4 << 24); 7299 - RTMP_IO_WRITE32(pAd, offset, tmpVal); 7300 - 7301 - // 7302 - // Write EIV 7303 - // 7304 - offset += 4; 7305 - RTMP_IO_WRITE32(pAd, offset, *(PUINT32)&pCipherKey->TxTsc[2]); 7306 - #endif // RT2870 // 7307 - AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg, bUsePairewiseKeyTable); 7308 - } 7309 - 7310 - if (!bUsePairewiseKeyTable) 7311 - { 7312 - // 7313 - // Only update the shared key security mode 7314 - // 7315 - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), &csr1.word); 7316 - if ((BssIndex % 2) == 0) 7317 - { 7318 - if (KeyIdx == 0) 7319 - csr1.field.Bss0Key0CipherAlg = CipherAlg; 7320 - else if (KeyIdx == 1) 7321 - csr1.field.Bss0Key1CipherAlg = CipherAlg; 7322 - else if (KeyIdx == 2) 7323 - csr1.field.Bss0Key2CipherAlg = CipherAlg; 7324 - else 7325 - csr1.field.Bss0Key3CipherAlg = CipherAlg; 7326 - } 7327 - else 7328 - { 7329 - if (KeyIdx == 0) 7330 - csr1.field.Bss1Key0CipherAlg = CipherAlg; 7331 - else if (KeyIdx == 1) 7332 - csr1.field.Bss1Key1CipherAlg = CipherAlg; 7333 - else if (KeyIdx == 2) 7334 - csr1.field.Bss1Key2CipherAlg = CipherAlg; 7335 - else 7336 - csr1.field.Bss1Key3CipherAlg = CipherAlg; 7337 - } 7338 - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), csr1.word); 7339 - } 7340 - 7341 - DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n")); 7342 - } 7343 - 7344 - 7345 - /* 7346 - ======================================================================== 7347 - Description: 7348 - Add Pair-wise key material into ASIC. 7349 - Update pairwise key, TxMic and RxMic to Asic Pair-wise key table 7350 - 7351 - Return: 7352 - ======================================================================== 7353 - */ 7354 - VOID AsicAddPairwiseKeyEntry( 7355 - IN PRTMP_ADAPTER pAd, 7356 - IN PUCHAR pAddr, 7357 - IN UCHAR WCID, 7358 - IN CIPHER_KEY *pCipherKey) 7359 - { 7360 - INT i; 7361 - ULONG offset; 7362 - PUCHAR pKey = pCipherKey->Key; 7363 - PUCHAR pTxMic = pCipherKey->TxMic; 7364 - PUCHAR pRxMic = pCipherKey->RxMic; 7365 - #ifdef DBG 7366 - UCHAR CipherAlg = pCipherKey->CipherAlg; 7367 - #endif // DBG // 7368 - 7369 - // EKEY 7370 - offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE); 7371 - #ifdef RT2870 7372 - RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY); 7373 - #endif // RT2870 // 7374 - for (i=0; i<MAX_LEN_OF_PEER_KEY; i+=4) 7375 - { 7376 - UINT32 Value; 7377 - RTMP_IO_READ32(pAd, offset + i, &Value); 7378 - } 7379 - 7380 - offset += MAX_LEN_OF_PEER_KEY; 7381 - 7382 - // MIC KEY 7383 - if (pTxMic) 7384 - { 7385 - #ifdef RT2870 7386 - RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8); 7387 - #endif // RT2870 // 7388 - } 7389 - offset += 8; 7390 - if (pRxMic) 7391 - { 7392 - #ifdef RT2870 7393 - RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8); 7394 - #endif // RT2870 // 7395 - } 7396 - 7397 - DBGPRINT(RT_DEBUG_TRACE,("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n",WCID, CipherName[CipherAlg])); 7398 - DBGPRINT(RT_DEBUG_TRACE,(" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7399 - pKey[0],pKey[1],pKey[2],pKey[3],pKey[4],pKey[5],pKey[6],pKey[7],pKey[8],pKey[9],pKey[10],pKey[11],pKey[12],pKey[13],pKey[14],pKey[15])); 7400 - if (pRxMic) 7401 - { 7402 - DBGPRINT(RT_DEBUG_TRACE, (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7403 - pRxMic[0],pRxMic[1],pRxMic[2],pRxMic[3],pRxMic[4],pRxMic[5],pRxMic[6],pRxMic[7])); 7404 - } 7405 - if (pTxMic) 7406 - { 7407 - DBGPRINT(RT_DEBUG_TRACE, (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 7408 - pTxMic[0],pTxMic[1],pTxMic[2],pTxMic[3],pTxMic[4],pTxMic[5],pTxMic[6],pTxMic[7])); 7409 - } 7410 - } 7411 - /* 7412 - ======================================================================== 7413 - Description: 7414 - Remove Pair-wise key material from ASIC. 7415 - 7416 - Return: 7417 - ======================================================================== 7418 - */ 7419 - VOID AsicRemovePairwiseKeyEntry( 7420 - IN PRTMP_ADAPTER pAd, 7421 - IN UCHAR BssIdx, 7422 - IN UCHAR Wcid) 7423 - { 7424 - ULONG WCIDAttri; 7425 - USHORT offset; 7426 - 7427 - // re-set the entry's WCID attribute as OPEN-NONE. 7428 - offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE); 7429 - WCIDAttri = (BssIdx<<4) | PAIRWISEKEYTABLE; 7430 - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); 7431 - } 7432 - 7433 - BOOLEAN AsicSendCommandToMcu( 7434 - IN PRTMP_ADAPTER pAd, 7435 - IN UCHAR Command, 7436 - IN UCHAR Token, 7437 - IN UCHAR Arg0, 7438 - IN UCHAR Arg1) 7439 - { 7440 - HOST_CMD_CSR_STRUC H2MCmd; 7441 - H2M_MAILBOX_STRUC H2MMailbox; 7442 - ULONG i = 0; 7443 - do 7444 - { 7445 - RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word); 7446 - if (H2MMailbox.field.Owner == 0) 7447 - break; 7448 - 7449 - RTMPusecDelay(2); 7450 - } while(i++ < 100); 7451 - 7452 - if (i >= 100) 7453 - { 7454 - { 7455 - DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n")); 7456 - } 7457 - return FALSE; 7458 - } 7459 - 7460 - 7461 - H2MMailbox.field.Owner = 1; // pass ownership to MCU 7462 - H2MMailbox.field.CmdToken = Token; 7463 - H2MMailbox.field.HighByte = Arg1; 7464 - H2MMailbox.field.LowByte = Arg0; 7465 - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word); 7466 - 7467 - H2MCmd.word = 0; 7468 - H2MCmd.field.HostCommand = Command; 7469 - RTMP_IO_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word); 7470 - 7471 - if (Command != 0x80) 7472 - { 7473 - } 7474 - 7475 - return TRUE; 7476 - } 7477 - 7478 - 7479 - /* 7480 - ======================================================================== 7481 - 7482 - Routine Description: 7483 - Verify the support rate for different PHY type 7484 - 7485 - Arguments: 7486 - pAd Pointer to our adapter 7487 - 7488 - Return Value: 7489 - None 7490 - 7491 - IRQL = PASSIVE_LEVEL 7492 - 7493 - ======================================================================== 7494 - */ 7495 - VOID RTMPCheckRates( 7496 - IN PRTMP_ADAPTER pAd, 7497 - IN OUT UCHAR SupRate[], 7498 - IN OUT UCHAR *SupRateLen) 7499 - { 7500 - UCHAR RateIdx, i, j; 7501 - UCHAR NewRate[12], NewRateLen; 7502 - 7503 - NewRateLen = 0; 7504 - 7505 - if (pAd->CommonCfg.PhyMode == PHY_11B) 7506 - RateIdx = 4; 7507 - else 7508 - RateIdx = 12; 7509 - 7510 - // Check for support rates exclude basic rate bit 7511 - for (i = 0; i < *SupRateLen; i++) 7512 - for (j = 0; j < RateIdx; j++) 7513 - if ((SupRate[i] & 0x7f) == RateIdTo500Kbps[j]) 7514 - NewRate[NewRateLen++] = SupRate[i]; 7515 - 7516 - *SupRateLen = NewRateLen; 7517 - NdisMoveMemory(SupRate, NewRate, NewRateLen); 7518 - } 7519 - 7520 - BOOLEAN RTMPCheckChannel( 7521 - IN PRTMP_ADAPTER pAd, 7522 - IN UCHAR CentralChannel, 7523 - IN UCHAR Channel) 7524 - { 7525 - UCHAR k; 7526 - UCHAR UpperChannel = 0, LowerChannel = 0; 7527 - UCHAR NoEffectChannelinList = 0; 7528 - 7529 - // Find upper and lower channel according to 40MHz current operation. 7530 - if (CentralChannel < Channel) 7531 - { 7532 - UpperChannel = Channel; 7533 - if (CentralChannel > 2) 7534 - LowerChannel = CentralChannel - 2; 7535 - else 7536 - return FALSE; 7537 - } 7538 - else if (CentralChannel > Channel) 7539 - { 7540 - UpperChannel = CentralChannel + 2; 7541 - LowerChannel = Channel; 7542 - } 7543 - 7544 - for (k = 0;k < pAd->ChannelListNum;k++) 7545 - { 7546 - if (pAd->ChannelList[k].Channel == UpperChannel) 7547 - { 7548 - NoEffectChannelinList ++; 7549 - } 7550 - if (pAd->ChannelList[k].Channel == LowerChannel) 7551 - { 7552 - NoEffectChannelinList ++; 7553 - } 7554 - } 7555 - 7556 - DBGPRINT(RT_DEBUG_TRACE,("Total Channel in Channel List = [%d]\n", NoEffectChannelinList)); 7557 - if (NoEffectChannelinList == 2) 7558 - return TRUE; 7559 - else 7560 - return FALSE; 7561 - } 7562 - 7563 - /* 7564 - ======================================================================== 7565 - 7566 - Routine Description: 7567 - Verify the support rate for HT phy type 7568 - 7569 - Arguments: 7570 - pAd Pointer to our adapter 7571 - 7572 - Return Value: 7573 - FALSE if pAd->CommonCfg.SupportedHtPhy doesn't accept the pHtCapability. (AP Mode) 7574 - 7575 - IRQL = PASSIVE_LEVEL 7576 - 7577 - ======================================================================== 7578 - */ 7579 - BOOLEAN RTMPCheckHt( 7580 - IN PRTMP_ADAPTER pAd, 7581 - IN UCHAR Wcid, 7582 - IN HT_CAPABILITY_IE *pHtCapability, 7583 - IN ADD_HT_INFO_IE *pAddHtInfo) 7584 - { 7585 - if (Wcid >= MAX_LEN_OF_MAC_TABLE) 7586 - return FALSE; 7587 - 7588 - // If use AMSDU, set flag. 7589 - if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable) 7590 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_AMSDU_INUSED); 7591 - // Save Peer Capability 7592 - if (pHtCapability->HtCapInfo.ShortGIfor20) 7593 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI20_CAPABLE); 7594 - if (pHtCapability->HtCapInfo.ShortGIfor40) 7595 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_SGI40_CAPABLE); 7596 - if (pHtCapability->HtCapInfo.TxSTBC) 7597 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_TxSTBC_CAPABLE); 7598 - if (pHtCapability->HtCapInfo.RxSTBC) 7599 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RxSTBC_CAPABLE); 7600 - if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport) 7601 - { 7602 - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], fCLIENT_STATUS_RDG_CAPABLE); 7603 - } 7604 - 7605 - if (Wcid < MAX_LEN_OF_MAC_TABLE) 7606 - { 7607 - pAd->MacTab.Content[Wcid].MpduDensity = pHtCapability->HtCapParm.MpduDensity; 7608 - } 7609 - 7610 - // Will check ChannelWidth for MCSSet[4] below 7611 - pAd->MlmeAux.HtCapability.MCSSet[4] = 0x1; 7612 - switch (pAd->CommonCfg.RxStream) 7613 - { 7614 - case 1: 7615 - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; 7616 - pAd->MlmeAux.HtCapability.MCSSet[1] = 0x00; 7617 - pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00; 7618 - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; 7619 - break; 7620 - case 2: 7621 - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; 7622 - pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff; 7623 - pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00; 7624 - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; 7625 - break; 7626 - case 3: 7627 - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; 7628 - pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff; 7629 - pAd->MlmeAux.HtCapability.MCSSet[2] = 0xff; 7630 - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; 7631 - break; 7632 - } 7633 - 7634 - pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth = pAddHtInfo->AddHtInfo.RecomWidth & pAd->CommonCfg.DesiredHtPhy.ChannelWidth; 7635 - 7636 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPCheckHt:: HtCapInfo.ChannelWidth=%d, RecomWidth=%d, DesiredHtPhy.ChannelWidth=%d, BW40MAvailForA/G=%d/%d, PhyMode=%d \n", 7637 - pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth, pAddHtInfo->AddHtInfo.RecomWidth, pAd->CommonCfg.DesiredHtPhy.ChannelWidth, 7638 - pAd->NicConfig2.field.BW40MAvailForA, pAd->NicConfig2.field.BW40MAvailForG, pAd->CommonCfg.PhyMode)); 7639 - 7640 - pAd->MlmeAux.HtCapability.HtCapInfo.GF = pHtCapability->HtCapInfo.GF &pAd->CommonCfg.DesiredHtPhy.GF; 7641 - 7642 - // Send Assoc Req with my HT capability. 7643 - pAd->MlmeAux.HtCapability.HtCapInfo.AMsduSize = pAd->CommonCfg.DesiredHtPhy.AmsduSize; 7644 - pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs = pAd->CommonCfg.DesiredHtPhy.MimoPs; 7645 - pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (pHtCapability->HtCapInfo.ShortGIfor20); 7646 - pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40 = (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (pHtCapability->HtCapInfo.ShortGIfor40); 7647 - pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC = (pAd->CommonCfg.DesiredHtPhy.TxSTBC)&(pHtCapability->HtCapInfo.RxSTBC); 7648 - pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC = (pAd->CommonCfg.DesiredHtPhy.RxSTBC)&(pHtCapability->HtCapInfo.TxSTBC); 7649 - pAd->MlmeAux.HtCapability.HtCapParm.MaxRAmpduFactor = pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor; 7650 - pAd->MlmeAux.HtCapability.HtCapParm.MpduDensity = pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity; 7651 - pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC; 7652 - pAd->MacTab.Content[Wcid].HTCapability.ExtHtCapInfo.PlusHTC = pHtCapability->ExtHtCapInfo.PlusHTC; 7653 - if (pAd->CommonCfg.bRdg) 7654 - { 7655 - pAd->MlmeAux.HtCapability.ExtHtCapInfo.RDGSupport = pHtCapability->ExtHtCapInfo.RDGSupport; 7656 - pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = 1; 7657 - } 7658 - 7659 - if (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_20) 7660 - pAd->MlmeAux.HtCapability.MCSSet[4] = 0x0; // BW20 can't transmit MCS32 7661 - 7662 - COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability); 7663 - return TRUE; 7664 - } 7665 - 7666 - /* 7667 - ======================================================================== 7668 - 7669 - Routine Description: 7670 - Verify the support rate for different PHY type 7671 - 7672 - Arguments: 7673 - pAd Pointer to our adapter 7674 - 7675 - Return Value: 7676 - None 7677 - 7678 - IRQL = PASSIVE_LEVEL 7679 - 7680 - ======================================================================== 7681 - */ 7682 - VOID RTMPUpdateMlmeRate( 7683 - IN PRTMP_ADAPTER pAd) 7684 - { 7685 - UCHAR MinimumRate; 7686 - UCHAR ProperMlmeRate; //= RATE_54; 7687 - UCHAR i, j, RateIdx = 12; //1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 7688 - BOOLEAN bMatch = FALSE; 7689 - 7690 - switch (pAd->CommonCfg.PhyMode) 7691 - { 7692 - case PHY_11B: 7693 - ProperMlmeRate = RATE_11; 7694 - MinimumRate = RATE_1; 7695 - break; 7696 - case PHY_11BG_MIXED: 7697 - case PHY_11ABGN_MIXED: 7698 - case PHY_11BGN_MIXED: 7699 - if ((pAd->MlmeAux.SupRateLen == 4) && 7700 - (pAd->MlmeAux.ExtRateLen == 0)) 7701 - // B only AP 7702 - ProperMlmeRate = RATE_11; 7703 - else 7704 - ProperMlmeRate = RATE_24; 7705 - 7706 - if (pAd->MlmeAux.Channel <= 14) 7707 - MinimumRate = RATE_1; 7708 - else 7709 - MinimumRate = RATE_6; 7710 - break; 7711 - case PHY_11A: 7712 - case PHY_11N_2_4G: // rt2860 need to check mlmerate for 802.11n 7713 - case PHY_11GN_MIXED: 7714 - case PHY_11AGN_MIXED: 7715 - case PHY_11AN_MIXED: 7716 - case PHY_11N_5G: 7717 - ProperMlmeRate = RATE_24; 7718 - MinimumRate = RATE_6; 7719 - break; 7720 - case PHY_11ABG_MIXED: 7721 - ProperMlmeRate = RATE_24; 7722 - if (pAd->MlmeAux.Channel <= 14) 7723 - MinimumRate = RATE_1; 7724 - else 7725 - MinimumRate = RATE_6; 7726 - break; 7727 - default: // error 7728 - ProperMlmeRate = RATE_1; 7729 - MinimumRate = RATE_1; 7730 - break; 7731 - } 7732 - 7733 - for (i = 0; i < pAd->MlmeAux.SupRateLen; i++) 7734 - { 7735 - for (j = 0; j < RateIdx; j++) 7736 - { 7737 - if ((pAd->MlmeAux.SupRate[i] & 0x7f) == RateIdTo500Kbps[j]) 7738 - { 7739 - if (j == ProperMlmeRate) 7740 - { 7741 - bMatch = TRUE; 7742 - break; 7743 - } 7744 - } 7745 - } 7746 - 7747 - if (bMatch) 7748 - break; 7749 - } 7750 - 7751 - if (bMatch == FALSE) 7752 - { 7753 - for (i = 0; i < pAd->MlmeAux.ExtRateLen; i++) 7754 - { 7755 - for (j = 0; j < RateIdx; j++) 7756 - { 7757 - if ((pAd->MlmeAux.ExtRate[i] & 0x7f) == RateIdTo500Kbps[j]) 7758 - { 7759 - if (j == ProperMlmeRate) 7760 - { 7761 - bMatch = TRUE; 7762 - break; 7763 - } 7764 - } 7765 - } 7766 - 7767 - if (bMatch) 7768 - break; 7769 - } 7770 - } 7771 - 7772 - if (bMatch == FALSE) 7773 - { 7774 - ProperMlmeRate = MinimumRate; 7775 - } 7776 - 7777 - pAd->CommonCfg.MlmeRate = MinimumRate; 7778 - pAd->CommonCfg.RtsRate = ProperMlmeRate; 7779 - if (pAd->CommonCfg.MlmeRate >= RATE_6) 7780 - { 7781 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; 7782 - pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; 7783 - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM; 7784 - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; 7785 - } 7786 - else 7787 - { 7788 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; 7789 - pAd->CommonCfg.MlmeTransmit.field.MCS = pAd->CommonCfg.MlmeRate; 7790 - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_CCK; 7791 - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = pAd->CommonCfg.MlmeRate; 7792 - } 7793 - 7794 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateMlmeRate ==> MlmeTransmit = 0x%x \n" , pAd->CommonCfg.MlmeTransmit.word)); 7795 - } 7796 - 7797 - CHAR RTMPMaxRssi( 7798 - IN PRTMP_ADAPTER pAd, 7799 - IN CHAR Rssi0, 7800 - IN CHAR Rssi1, 7801 - IN CHAR Rssi2) 7802 - { 7803 - CHAR larger = -127; 7804 - 7805 - if ((pAd->Antenna.field.RxPath == 1) && (Rssi0 != 0)) 7806 - { 7807 - larger = Rssi0; 7808 - } 7809 - 7810 - if ((pAd->Antenna.field.RxPath >= 2) && (Rssi1 != 0)) 7811 - { 7812 - larger = max(Rssi0, Rssi1); 7813 - } 7814 - 7815 - if ((pAd->Antenna.field.RxPath == 3) && (Rssi2 != 0)) 7816 - { 7817 - larger = max(larger, Rssi2); 7818 - } 7819 - 7820 - if (larger == -127) 7821 - larger = 0; 7822 - 7823 - return larger; 7824 - } 7825 - 7826 - #ifdef RT30xx 7827 - // Antenna divesity use GPIO3 and EESK pin for control 7828 - // Antenna and EEPROM access are both using EESK pin, 7829 - // Therefor we should avoid accessing EESK at the same time 7830 - // Then restore antenna after EEPROM access 7831 - VOID AsicSetRxAnt( 7832 - IN PRTMP_ADAPTER pAd, 7833 - IN UCHAR Ant) 7834 - { 7835 - #ifdef RT30xx 7836 - UINT32 Value; 7837 - UINT32 x; 7838 - 7839 - if ((pAd->EepromAccess) || 7840 - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) || 7841 - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) || 7842 - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) || 7843 - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) 7844 - { 7845 - return; 7846 - } 7847 - 7848 - // the antenna selection is through firmware and MAC register(GPIO3) 7849 - if (Ant == 0) 7850 - { 7851 - // Main antenna 7852 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 7853 - x |= (EESK); 7854 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 7855 - 7856 - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); 7857 - Value &= ~(0x0808); 7858 - RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); 7859 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to main antenna\n")); 7860 - } 7861 - else 7862 - { 7863 - // Aux antenna 7864 - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); 7865 - x &= ~(EESK); 7866 - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); 7867 - 7868 - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); 7869 - Value &= ~(0x0808); 7870 - Value |= 0x08; 7871 - RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); 7872 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to aux antenna\n")); 7873 - } 7874 - #endif // RT30xx // 7875 - } 7876 - #endif /* RT30xx */ 7877 - 7878 - /* 7879 - ======================================================================== 7880 - Routine Description: 7881 - Periodic evaluate antenna link status 7882 - 7883 - Arguments: 7884 - pAd - Adapter pointer 7885 - 7886 - Return Value: 7887 - None 7888 - 7889 - ======================================================================== 7890 - */ 7891 - VOID AsicEvaluateRxAnt( 7892 - IN PRTMP_ADAPTER pAd) 7893 - { 7894 - UCHAR BBPR3 = 0; 7895 - 7896 - #ifndef RT30xx 7897 - { 7898 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | 7899 - fRTMP_ADAPTER_HALT_IN_PROGRESS | 7900 - fRTMP_ADAPTER_RADIO_OFF | 7901 - fRTMP_ADAPTER_NIC_NOT_EXIST | 7902 - fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) 7903 - return; 7904 - 7905 - if (pAd->StaCfg.Psm == PWR_SAVE) 7906 - return; 7907 - } 7908 - 7909 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); 7910 - BBPR3 &= (~0x18); 7911 - if(pAd->Antenna.field.RxPath == 3) 7912 - { 7913 - BBPR3 |= (0x10); 7914 - } 7915 - else if(pAd->Antenna.field.RxPath == 2) 7916 - { 7917 - BBPR3 |= (0x8); 7918 - } 7919 - else if(pAd->Antenna.field.RxPath == 1) 7920 - { 7921 - BBPR3 |= (0x0); 7922 - } 7923 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); 7924 - 7925 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) 7926 - ) 7927 - { 7928 - ULONG TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 7929 - pAd->RalinkCounters.OneSecTxRetryOkCount + 7930 - pAd->RalinkCounters.OneSecTxFailCount; 7931 - 7932 - if (TxTotalCnt > 50) 7933 - { 7934 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 20); 7935 - pAd->Mlme.bLowThroughput = FALSE; 7936 - } 7937 - else 7938 - { 7939 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300); 7940 - pAd->Mlme.bLowThroughput = TRUE; 7941 - } 7942 - } 7943 - #endif /* RT30xx */ 7944 - #ifdef RT30xx 7945 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | 7946 - fRTMP_ADAPTER_HALT_IN_PROGRESS | 7947 - fRTMP_ADAPTER_RADIO_OFF | 7948 - fRTMP_ADAPTER_NIC_NOT_EXIST | 7949 - fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) || 7950 - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) 7951 - #ifdef RT30xx 7952 - || (pAd->EepromAccess) 7953 - #endif // RT30xx // 7954 - ) 7955 - return; 7956 - 7957 - 7958 - { 7959 - //if (pAd->StaCfg.Psm == PWR_SAVE) 7960 - // return; 7961 - } 7962 - 7963 - // two antenna selection mechanism- one is antenna diversity, the other is failed antenna remove 7964 - // one is antenna diversity:there is only one antenna can rx and tx 7965 - // the other is failed antenna remove:two physical antenna can rx and tx 7966 - if (pAd->NicConfig2.field.AntDiversity) 7967 - { 7968 - DBGPRINT(RT_DEBUG_TRACE,("AntDiv - before evaluate Pair1-Ant (%d,%d)\n", 7969 - pAd->RxAnt.Pair1PrimaryRxAnt, pAd->RxAnt.Pair1SecondaryRxAnt)); 7970 - 7971 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1SecondaryRxAnt); 7972 - 7973 - pAd->RxAnt.EvaluatePeriod = 1; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt 7974 - pAd->RxAnt.FirstPktArrivedWhenEvaluate = FALSE; 7975 - pAd->RxAnt.RcvPktNumWhenEvaluate = 0; 7976 - 7977 - // a one-shot timer to end the evalution 7978 - // dynamic adjust antenna evaluation period according to the traffic 7979 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 7980 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 100); 7981 - else 7982 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300); 7983 - } 7984 - else 7985 - { 7986 - if (pAd->StaCfg.Psm == PWR_SAVE) 7987 - return; 7988 - 7989 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); 7990 - BBPR3 &= (~0x18); 7991 - if(pAd->Antenna.field.RxPath == 3) 7992 - { 7993 - BBPR3 |= (0x10); 7994 - } 7995 - else if(pAd->Antenna.field.RxPath == 2) 7996 - { 7997 - BBPR3 |= (0x8); 7998 - } 7999 - else if(pAd->Antenna.field.RxPath == 1) 8000 - { 8001 - BBPR3 |= (0x0); 8002 - } 8003 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); 8004 - 8005 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) 8006 - ) 8007 - { 8008 - ULONG TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 8009 - pAd->RalinkCounters.OneSecTxRetryOkCount + 8010 - pAd->RalinkCounters.OneSecTxFailCount; 8011 - 8012 - // dynamic adjust antenna evaluation period according to the traffic 8013 - if (TxTotalCnt > 50) 8014 - { 8015 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 20); 8016 - pAd->Mlme.bLowThroughput = FALSE; 8017 - } 8018 - else 8019 - { 8020 - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300); 8021 - pAd->Mlme.bLowThroughput = TRUE; 8022 - } 8023 - } 8024 - } 8025 - #endif /* RT30xx */ 8026 - } 8027 - 8028 - /* 8029 - ======================================================================== 8030 - Routine Description: 8031 - After evaluation, check antenna link status 8032 - 8033 - Arguments: 8034 - pAd - Adapter pointer 8035 - 8036 - Return Value: 8037 - None 8038 - 8039 - ======================================================================== 8040 - */ 8041 - VOID AsicRxAntEvalTimeout( 8042 - IN PVOID SystemSpecific1, 8043 - IN PVOID FunctionContext, 8044 - IN PVOID SystemSpecific2, 8045 - IN PVOID SystemSpecific3) 8046 - { 8047 - RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext; 8048 - UCHAR BBPR3 = 0; 8049 - CHAR larger = -127, rssi0, rssi1, rssi2; 8050 - 8051 - #ifndef RT30xx 8052 - { 8053 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || 8054 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) || 8055 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF) || 8056 - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) 8057 - return; 8058 - 8059 - if (pAd->StaCfg.Psm == PWR_SAVE) 8060 - return; 8061 - 8062 - 8063 - // if the traffic is low, use average rssi as the criteria 8064 - if (pAd->Mlme.bLowThroughput == TRUE) 8065 - { 8066 - rssi0 = pAd->StaCfg.RssiSample.LastRssi0; 8067 - rssi1 = pAd->StaCfg.RssiSample.LastRssi1; 8068 - rssi2 = pAd->StaCfg.RssiSample.LastRssi2; 8069 - } 8070 - else 8071 - { 8072 - rssi0 = pAd->StaCfg.RssiSample.AvgRssi0; 8073 - rssi1 = pAd->StaCfg.RssiSample.AvgRssi1; 8074 - rssi2 = pAd->StaCfg.RssiSample.AvgRssi2; 8075 - } 8076 - 8077 - if(pAd->Antenna.field.RxPath == 3) 8078 - { 8079 - larger = max(rssi0, rssi1); 8080 - 8081 - if (larger > (rssi2 + 20)) 8082 - pAd->Mlme.RealRxPath = 2; 8083 - else 8084 - pAd->Mlme.RealRxPath = 3; 8085 - } 8086 - else if(pAd->Antenna.field.RxPath == 2) 8087 - { 8088 - if (rssi0 > (rssi1 + 20)) 8089 - pAd->Mlme.RealRxPath = 1; 8090 - else 8091 - pAd->Mlme.RealRxPath = 2; 8092 - } 8093 - 8094 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); 8095 - BBPR3 &= (~0x18); 8096 - if(pAd->Mlme.RealRxPath == 3) 8097 - { 8098 - BBPR3 |= (0x10); 8099 - } 8100 - else if(pAd->Mlme.RealRxPath == 2) 8101 - { 8102 - BBPR3 |= (0x8); 8103 - } 8104 - else if(pAd->Mlme.RealRxPath == 1) 8105 - { 8106 - BBPR3 |= (0x0); 8107 - } 8108 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); 8109 - } 8110 - #endif /* RT30xx */ 8111 - #ifdef RT30xx 8112 - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | 8113 - fRTMP_ADAPTER_HALT_IN_PROGRESS | 8114 - fRTMP_ADAPTER_RADIO_OFF | 8115 - fRTMP_ADAPTER_NIC_NOT_EXIST) || 8116 - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) 8117 - #ifdef RT30xx 8118 - || (pAd->EepromAccess) 8119 - #endif // RT30xx // 8120 - ) 8121 - return; 8122 - 8123 - { 8124 - //if (pAd->StaCfg.Psm == PWR_SAVE) 8125 - // return; 8126 - 8127 - if (pAd->NicConfig2.field.AntDiversity) 8128 - { 8129 - if ((pAd->RxAnt.RcvPktNumWhenEvaluate != 0) && (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >= pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt])) 8130 - { 8131 - UCHAR temp; 8132 - 8133 - // 8134 - // select PrimaryRxAntPair 8135 - // Role change, Used Pair1SecondaryRxAnt as PrimaryRxAntPair. 8136 - // Since Pair1SecondaryRxAnt Quality good than Pair1PrimaryRxAnt 8137 - // 8138 - temp = pAd->RxAnt.Pair1PrimaryRxAnt; 8139 - pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt; 8140 - pAd->RxAnt.Pair1SecondaryRxAnt = temp; 8141 - 8142 - pAd->RxAnt.Pair1LastAvgRssi = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >> 3); 8143 - pAd->RxAnt.EvaluateStableCnt = 0; 8144 - } 8145 - else 8146 - { 8147 - // if the evaluated antenna is not better than original, switch back to original antenna 8148 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); 8149 - pAd->RxAnt.EvaluateStableCnt ++; 8150 - } 8151 - 8152 - pAd->RxAnt.EvaluatePeriod = 0; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt 8153 - 8154 - DBGPRINT(RT_DEBUG_TRACE,("AsicRxAntEvalAction::After Eval(fix in #%d), <%d, %d>, RcvPktNumWhenEvaluate=%ld\n", 8155 - pAd->RxAnt.Pair1PrimaryRxAnt, (pAd->RxAnt.Pair1AvgRssi[0] >> 3), (pAd->RxAnt.Pair1AvgRssi[1] >> 3), pAd->RxAnt.RcvPktNumWhenEvaluate)); 8156 - } 8157 - else 8158 - { 8159 - if (pAd->StaCfg.Psm == PWR_SAVE) 8160 - return; 8161 - 8162 - // if the traffic is low, use average rssi as the criteria 8163 - if (pAd->Mlme.bLowThroughput == TRUE) 8164 - { 8165 - rssi0 = pAd->StaCfg.RssiSample.LastRssi0; 8166 - rssi1 = pAd->StaCfg.RssiSample.LastRssi1; 8167 - rssi2 = pAd->StaCfg.RssiSample.LastRssi2; 8168 - } 8169 - else 8170 - { 8171 - rssi0 = pAd->StaCfg.RssiSample.AvgRssi0; 8172 - rssi1 = pAd->StaCfg.RssiSample.AvgRssi1; 8173 - rssi2 = pAd->StaCfg.RssiSample.AvgRssi2; 8174 - } 8175 - 8176 - if(pAd->Antenna.field.RxPath == 3) 8177 - { 8178 - larger = max(rssi0, rssi1); 8179 - 8180 - if (larger > (rssi2 + 20)) 8181 - pAd->Mlme.RealRxPath = 2; 8182 - else 8183 - pAd->Mlme.RealRxPath = 3; 8184 - } 8185 - else if(pAd->Antenna.field.RxPath == 2) 8186 - { 8187 - if (rssi0 > (rssi1 + 20)) 8188 - pAd->Mlme.RealRxPath = 1; 8189 - else 8190 - pAd->Mlme.RealRxPath = 2; 8191 - } 8192 - 8193 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); 8194 - BBPR3 &= (~0x18); 8195 - if(pAd->Mlme.RealRxPath == 3) 8196 - { 8197 - BBPR3 |= (0x10); 8198 - } 8199 - else if(pAd->Mlme.RealRxPath == 2) 8200 - { 8201 - BBPR3 |= (0x8); 8202 - } 8203 - else if(pAd->Mlme.RealRxPath == 1) 8204 - { 8205 - BBPR3 |= (0x0); 8206 - } 8207 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); 8208 - } 8209 - } 8210 - #endif /* RT30xx */ 8211 - } 8212 - 8213 - 8214 - 8215 - VOID APSDPeriodicExec( 8216 - IN PVOID SystemSpecific1, 8217 - IN PVOID FunctionContext, 8218 - IN PVOID SystemSpecific2, 8219 - IN PVOID SystemSpecific3) 8220 - { 8221 - RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext; 8222 - 8223 - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) 8224 - return; 8225 - 8226 - pAd->CommonCfg.TriggerTimerCount++; 8227 - 8228 - } 8229 - 8230 - /* 8231 - ======================================================================== 8232 - Routine Description: 8233 - Set/reset MAC registers according to bPiggyBack parameter 8234 - 8235 - Arguments: 8236 - pAd - Adapter pointer 8237 - bPiggyBack - Enable / Disable Piggy-Back 8238 - 8239 - Return Value: 8240 - None 8241 - 8242 - ======================================================================== 8243 - */ 8244 - VOID RTMPSetPiggyBack( 8245 - IN PRTMP_ADAPTER pAd, 8246 - IN BOOLEAN bPiggyBack) 8247 - { 8248 - TX_LINK_CFG_STRUC TxLinkCfg; 8249 - 8250 - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); 8251 - 8252 - TxLinkCfg.field.TxCFAckEn = bPiggyBack; 8253 - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); 8254 - } 8255 - 8256 - /* 8257 - ======================================================================== 8258 - Routine Description: 8259 - check if this entry need to switch rate automatically 8260 - 8261 - Arguments: 8262 - pAd 8263 - pEntry 8264 - 8265 - Return Value: 8266 - TURE 8267 - FALSE 8268 - 8269 - ======================================================================== 8270 - */ 8271 - BOOLEAN RTMPCheckEntryEnableAutoRateSwitch( 8272 - IN PRTMP_ADAPTER pAd, 8273 - IN PMAC_TABLE_ENTRY pEntry) 8274 - { 8275 - BOOLEAN result = TRUE; 8276 - 8277 - { 8278 - // only associated STA counts 8279 - if (pEntry && (pEntry->ValidAsCLI) && (pEntry->Sst == SST_ASSOC)) 8280 - { 8281 - result = pAd->StaCfg.bAutoTxRateSwitch; 8282 - } 8283 - else 8284 - result = FALSE; 8285 - } 8286 - 8287 - return result; 8288 - } 8289 - 8290 - 8291 - BOOLEAN RTMPAutoRateSwitchCheck( 8292 - IN PRTMP_ADAPTER pAd) 8293 - { 8294 - if (pAd->StaCfg.bAutoTxRateSwitch) 8295 - return TRUE; 8296 - 8297 - return FALSE; 8298 - } 8299 - 8300 - 8301 - /* 8302 - ======================================================================== 8303 - Routine Description: 8304 - check if this entry need to fix tx legacy rate 8305 - 8306 - Arguments: 8307 - pAd 8308 - pEntry 8309 - 8310 - Return Value: 8311 - TURE 8312 - FALSE 8313 - 8314 - ======================================================================== 8315 - */ 8316 - UCHAR RTMPStaFixedTxMode( 8317 - IN PRTMP_ADAPTER pAd, 8318 - IN PMAC_TABLE_ENTRY pEntry) 8319 - { 8320 - UCHAR tx_mode = FIXED_TXMODE_HT; 8321 - 8322 - { 8323 - tx_mode = (UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode; 8324 - } 8325 - 8326 - return tx_mode; 8327 - } 8328 - 8329 - /* 8330 - ======================================================================== 8331 - Routine Description: 8332 - Overwrite HT Tx Mode by Fixed Legency Tx Mode, if specified. 8333 - 8334 - Arguments: 8335 - pAd 8336 - pEntry 8337 - 8338 - Return Value: 8339 - TURE 8340 - FALSE 8341 - 8342 - ======================================================================== 8343 - */ 8344 - VOID RTMPUpdateLegacyTxSetting( 8345 - UCHAR fixed_tx_mode, 8346 - PMAC_TABLE_ENTRY pEntry) 8347 - { 8348 - HTTRANSMIT_SETTING TransmitSetting; 8349 - 8350 - if (fixed_tx_mode == FIXED_TXMODE_HT) 8351 - return; 8352 - 8353 - TransmitSetting.word = 0; 8354 - 8355 - TransmitSetting.field.MODE = pEntry->HTPhyMode.field.MODE; 8356 - TransmitSetting.field.MCS = pEntry->HTPhyMode.field.MCS; 8357 - 8358 - if (fixed_tx_mode == FIXED_TXMODE_CCK) 8359 - { 8360 - TransmitSetting.field.MODE = MODE_CCK; 8361 - // CCK mode allow MCS 0~3 8362 - if (TransmitSetting.field.MCS > MCS_3) 8363 - TransmitSetting.field.MCS = MCS_3; 8364 - } 8365 - else 8366 - { 8367 - TransmitSetting.field.MODE = MODE_OFDM; 8368 - // OFDM mode allow MCS 0~7 8369 - if (TransmitSetting.field.MCS > MCS_7) 8370 - TransmitSetting.field.MCS = MCS_7; 8371 - } 8372 - 8373 - if (pEntry->HTPhyMode.field.MODE >= TransmitSetting.field.MODE) 8374 - { 8375 - pEntry->HTPhyMode.word = TransmitSetting.word; 8376 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateLegacyTxSetting : wcid-%d, MODE=%s, MCS=%d \n", 8377 - pEntry->Aid, GetPhyMode(pEntry->HTPhyMode.field.MODE), pEntry->HTPhyMode.field.MCS)); 8378 - } 8379 - } 8380 - 8381 - /* 8382 - ========================================================================== 8383 - Description: 8384 - dynamic tune BBP R66 to find a balance between sensibility and 8385 - noise isolation 8386 - 8387 - IRQL = DISPATCH_LEVEL 8388 - 8389 - ========================================================================== 8390 - */ 8391 - VOID AsicStaBbpTuning( 8392 - IN PRTMP_ADAPTER pAd) 8393 - { 8394 - UCHAR OrigR66Value = 0, R66;//, R66UpperBound = 0x30, R66LowerBound = 0x30; 8395 - CHAR Rssi; 8396 - 8397 - // 2860C did not support Fase CCA, therefore can't tune 8398 - if (pAd->MACVersion == 0x28600100) 8399 - return; 8400 - 8401 - // 8402 - // work as a STA 8403 - // 8404 - if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) // no R66 tuning when SCANNING 8405 - return; 8406 - 8407 - if ((pAd->OpMode == OPMODE_STA) 8408 - && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) 8409 - ) 8410 - && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) 8411 - ) 8412 - { 8413 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value); 8414 - R66 = OrigR66Value; 8415 - 8416 - if (pAd->Antenna.field.RxPath > 1) 8417 - Rssi = (pAd->StaCfg.RssiSample.AvgRssi0 + pAd->StaCfg.RssiSample.AvgRssi1) >> 1; 8418 - else 8419 - Rssi = pAd->StaCfg.RssiSample.AvgRssi0; 8420 - 8421 - if (pAd->LatchRfRegs.Channel <= 14) 8422 - { //BG band 8423 - #ifdef RT2870 8424 - // RT3070 is a no LNA solution, it should have different control regarding to AGC gain control 8425 - // Otherwise, it will have some throughput side effect when low RSSI 8426 - #ifndef RT30xx 8427 - if (IS_RT3070(pAd)) 8428 - #endif 8429 - #ifdef RT30xx 8430 - if (IS_RT30xx(pAd)) 8431 - #endif 8432 - { 8433 - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) 8434 - { 8435 - R66 = 0x1C + 2*GET_LNA_GAIN(pAd) + 0x20; 8436 - if (OrigR66Value != R66) 8437 - { 8438 - #ifndef RT30xx 8439 - RTUSBWriteBBPRegister(pAd, BBP_R66, R66); 8440 - #endif 8441 - #ifdef RT30xx 8442 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8443 - #endif 8444 - } 8445 - } 8446 - else 8447 - { 8448 - R66 = 0x1C + 2*GET_LNA_GAIN(pAd); 8449 - if (OrigR66Value != R66) 8450 - { 8451 - #ifndef RT30xx 8452 - RTUSBWriteBBPRegister(pAd, BBP_R66, R66); 8453 - #endif 8454 - #ifdef RT30xx 8455 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8456 - #endif 8457 - } 8458 - } 8459 - } 8460 - else 8461 - #endif // RT2870 // 8462 - { 8463 - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) 8464 - { 8465 - R66 = (0x2E + GET_LNA_GAIN(pAd)) + 0x10; 8466 - if (OrigR66Value != R66) 8467 - { 8468 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8469 - } 8470 - } 8471 - else 8472 - { 8473 - R66 = 0x2E + GET_LNA_GAIN(pAd); 8474 - if (OrigR66Value != R66) 8475 - { 8476 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8477 - } 8478 - } 8479 - } 8480 - } 8481 - else 8482 - { //A band 8483 - if (pAd->CommonCfg.BBPCurrentBW == BW_20) 8484 - { 8485 - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) 8486 - { 8487 - R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3 + 0x10; 8488 - if (OrigR66Value != R66) 8489 - { 8490 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8491 - } 8492 - } 8493 - else 8494 - { 8495 - R66 = 0x32 + (GET_LNA_GAIN(pAd)*5)/3; 8496 - if (OrigR66Value != R66) 8497 - { 8498 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8499 - } 8500 - } 8501 - } 8502 - else 8503 - { 8504 - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) 8505 - { 8506 - R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3 + 0x10; 8507 - if (OrigR66Value != R66) 8508 - { 8509 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8510 - } 8511 - } 8512 - else 8513 - { 8514 - R66 = 0x3A + (GET_LNA_GAIN(pAd)*5)/3; 8515 - if (OrigR66Value != R66) 8516 - { 8517 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8518 - } 8519 - } 8520 - } 8521 - } 8522 - 8523 - 8524 - } 8525 - } 8526 - 8527 - VOID RTMPSetAGCInitValue( 8528 - IN PRTMP_ADAPTER pAd, 8529 - IN UCHAR BandWidth) 8530 - { 8531 - UCHAR R66 = 0x30; 8532 - 8533 - if (pAd->LatchRfRegs.Channel <= 14) 8534 - { // BG band 8535 - R66 = 0x2E + GET_LNA_GAIN(pAd); 8536 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8537 - } 8538 - else 8539 - { //A band 8540 - if (BandWidth == BW_20) 8541 - { 8542 - R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3); 8543 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8544 - } 8545 - else 8546 - { 8547 - R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3); 8548 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); 8549 - } 8550 - } 8551 - 8552 - } 8553 - 8554 - VOID AsicTurnOffRFClk( 8555 - IN PRTMP_ADAPTER pAd, 8556 - IN UCHAR Channel) 8557 - { 8558 - // RF R2 bit 18 = 0 8559 - UINT32 R1 = 0, R2 = 0, R3 = 0; 8560 - UCHAR index; 8561 - RTMP_RF_REGS *RFRegTable; 8562 - 8563 - #ifdef RT30xx 8564 - // The RF programming sequence is difference between 3xxx and 2xxx 8565 - if (IS_RT3090(pAd)) 8566 - { 8567 - RT30xxLoadRFSleepModeSetup(pAd); // add by johnli, RF power sequence setup, load RF sleep-mode setup 8568 - } 8569 - else 8570 - { 8571 - #endif // RT30xx // 8572 - RFRegTable = RF2850RegTable; 8573 - 8574 - switch (pAd->RfIcType) 8575 - { 8576 - case RFIC_2820: 8577 - case RFIC_2850: 8578 - case RFIC_2720: 8579 - case RFIC_2750: 8580 - 8581 - for (index = 0; index < NUM_OF_2850_CHNL; index++) 8582 - { 8583 - if (Channel == RFRegTable[index].Channel) 8584 - { 8585 - R1 = RFRegTable[index].R1 & 0xffffdfff; 8586 - R2 = RFRegTable[index].R2 & 0xfffbffff; 8587 - R3 = RFRegTable[index].R3 & 0xfff3ffff; 8588 - 8589 - RTMP_RF_IO_WRITE32(pAd, R1); 8590 - RTMP_RF_IO_WRITE32(pAd, R2); 8591 - 8592 - // Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0. 8593 - // Set RF R2 bit18=0, R3 bit[18:19]=0 8594 - //if (pAd->StaCfg.bRadio == FALSE) 8595 - if (1) 8596 - { 8597 - RTMP_RF_IO_WRITE32(pAd, R3); 8598 - 8599 - DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n", 8600 - Channel, pAd->RfIcType, R2, R3)); 8601 - } 8602 - else 8603 - DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n", 8604 - Channel, pAd->RfIcType, R2)); 8605 - break; 8606 - } 8607 - } 8608 - break; 8609 - 8610 - default: 8611 - break; 8612 - } 8613 - #ifdef RT30xx 8614 - } 8615 - #endif // RT30xx // 8616 - 8617 - } 8618 - 8619 - 8620 - VOID AsicTurnOnRFClk( 8621 - IN PRTMP_ADAPTER pAd, 8622 - IN UCHAR Channel) 8623 - { 8624 - // RF R2 bit 18 = 0 8625 - UINT32 R1 = 0, R2 = 0, R3 = 0; 8626 - UCHAR index; 8627 - RTMP_RF_REGS *RFRegTable; 8628 - 8629 - #ifdef RT30xx 8630 - // The RF programming sequence is difference between 3xxx and 2xxx 8631 - if (IS_RT3090(pAd)) 8632 - { 8633 - } 8634 - else 8635 - { 8636 - #endif // RT30xx // 8637 - RFRegTable = RF2850RegTable; 8638 - 8639 - switch (pAd->RfIcType) 8640 - { 8641 - case RFIC_2820: 8642 - case RFIC_2850: 8643 - case RFIC_2720: 8644 - case RFIC_2750: 8645 - 8646 - for (index = 0; index < NUM_OF_2850_CHNL; index++) 8647 - { 8648 - if (Channel == RFRegTable[index].Channel) 8649 - { 8650 - R3 = pAd->LatchRfRegs.R3; 8651 - R3 &= 0xfff3ffff; 8652 - R3 |= 0x00080000; 8653 - RTMP_RF_IO_WRITE32(pAd, R3); 8654 - 8655 - R1 = RFRegTable[index].R1; 8656 - RTMP_RF_IO_WRITE32(pAd, R1); 8657 - 8658 - R2 = RFRegTable[index].R2; 8659 - if (pAd->Antenna.field.TxPath == 1) 8660 - { 8661 - R2 |= 0x4000; // If TXpath is 1, bit 14 = 1; 8662 - } 8663 - 8664 - if (pAd->Antenna.field.RxPath == 2) 8665 - { 8666 - R2 |= 0x40; // write 1 to off Rxpath. 8667 - } 8668 - else if (pAd->Antenna.field.RxPath == 1) 8669 - { 8670 - R2 |= 0x20040; // write 1 to off RxPath 8671 - } 8672 - RTMP_RF_IO_WRITE32(pAd, R2); 8673 - 8674 - break; 8675 - } 8676 - } 8677 - break; 8678 - 8679 - default: 8680 - break; 8681 - } 8682 - 8683 - #ifndef RT30xx 8684 - DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n", 8685 - Channel, 8686 - pAd->RfIcType, 8687 - R2)); 8688 - #endif 8689 - #ifdef RT30xx 8690 - } 8691 - #endif // RT30xx // 8692 - } 8693 - 1 + #include "../../rt2860/common/mlme.c"
+1 -4024
drivers/staging/rt2870/common/rtmp_init.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - rtmp_init.c 29 - 30 - Abstract: 31 - Miniport generic portion header file 32 - 33 - Revision History: 34 - Who When What 35 - -------- ---------- ---------------------------------------------- 36 - Paul Lin 2002-08-01 created 37 - John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme 38 - Jan Lee 2006-09-15 RT2860. Change for 802.11n , EEPROM, Led, BA, HT. 39 - */ 40 - #include "../rt_config.h" 41 - #ifndef RT30xx 42 - #include "firmware.h" 43 - #endif 44 - #ifdef RT30xx 45 - #include "../../rt3070/firmware.h" 46 - #endif 47 - 48 - UCHAR BIT8[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; 49 - ULONG BIT32[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008, 50 - 0x00000010, 0x00000020, 0x00000040, 0x00000080, 51 - 0x00000100, 0x00000200, 0x00000400, 0x00000800, 52 - 0x00001000, 0x00002000, 0x00004000, 0x00008000, 53 - 0x00010000, 0x00020000, 0x00040000, 0x00080000, 54 - 0x00100000, 0x00200000, 0x00400000, 0x00800000, 55 - 0x01000000, 0x02000000, 0x04000000, 0x08000000, 56 - 0x10000000, 0x20000000, 0x40000000, 0x80000000}; 57 - 58 - char* CipherName[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"}; 59 - 60 - const unsigned short ccitt_16Table[] = { 61 - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 62 - 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 63 - 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 64 - 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 65 - 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 66 - 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 67 - 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 68 - 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 69 - 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 70 - 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, 71 - 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 72 - 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, 73 - 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 74 - 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 75 - 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 76 - 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 77 - 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 78 - 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, 79 - 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 80 - 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, 81 - 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 82 - 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 83 - 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 84 - 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, 85 - 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 86 - 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, 87 - 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 88 - 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 89 - 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 90 - 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 91 - 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 92 - 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 93 - }; 94 - #define ByteCRC16(v, crc) \ 95 - (unsigned short)((crc << 8) ^ ccitt_16Table[((crc >> 8) ^ (v)) & 255]) 96 - 97 - unsigned char BitReverse(unsigned char x) 98 - { 99 - int i; 100 - unsigned char Temp=0; 101 - for(i=0; ; i++) 102 - { 103 - if(x & 0x80) Temp |= 0x80; 104 - if(i==7) break; 105 - x <<= 1; 106 - Temp >>= 1; 107 - } 108 - return Temp; 109 - } 110 - 111 - // 112 - // BBP register initialization set 113 - // 114 - REG_PAIR BBPRegTable[] = { 115 - {BBP_R65, 0x2C}, // fix rssi issue 116 - {BBP_R66, 0x38}, // Also set this default value to pAd->BbpTuning.R66CurrentValue at initial 117 - {BBP_R69, 0x12}, 118 - {BBP_R70, 0xa}, // BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa 119 - {BBP_R73, 0x10}, 120 - {BBP_R81, 0x37}, 121 - {BBP_R82, 0x62}, 122 - {BBP_R83, 0x6A}, 123 - {BBP_R84, 0x99}, // 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before 124 - {BBP_R86, 0x00}, // middle range issue, Rory @2008-01-28 125 - {BBP_R91, 0x04}, // middle range issue, Rory @2008-01-28 126 - {BBP_R92, 0x00}, // middle range issue, Rory @2008-01-28 127 - {BBP_R103, 0x00}, // near range high-power issue, requested from Gary @2008-0528 128 - {BBP_R105, 0x05}, // 0x05 is for rt2860E to turn on FEQ control. It is safe for rt2860D and before, because Bit 7:2 are reserved in rt2860D and before. 129 - }; 130 - #define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(REG_PAIR)) 131 - 132 - // 133 - // RF register initialization set 134 - // 135 - #ifdef RT2870 136 - REG_PAIR RT30xx_RFRegTable[] = { 137 - {RF_R04, 0x40}, 138 - {RF_R05, 0x03}, 139 - {RF_R06, 0x02}, 140 - {RF_R07, 0x70}, 141 - {RF_R09, 0x0F}, 142 - #ifndef RT30xx 143 - {RF_R10, 0x71}, 144 - #endif 145 - #ifdef RT30xx 146 - {RF_R10, 0x41}, 147 - #endif 148 - {RF_R11, 0x21}, 149 - {RF_R12, 0x7B}, 150 - {RF_R14, 0x90}, 151 - {RF_R15, 0x58}, 152 - {RF_R16, 0xB3}, 153 - {RF_R17, 0x92}, 154 - {RF_R18, 0x2C}, 155 - {RF_R19, 0x02}, 156 - {RF_R20, 0xBA}, 157 - {RF_R21, 0xDB}, 158 - {RF_R24, 0x16}, 159 - {RF_R25, 0x01}, 160 - #ifndef RT30xx 161 - {RF_R27, 0x03}, 162 - #endif 163 - {RF_R29, 0x1F}, 164 - }; 165 - #define NUM_RF_REG_PARMS (sizeof(RT30xx_RFRegTable) / sizeof(REG_PAIR)) 166 - #endif // RT2870 // 167 - 168 - // 169 - // ASIC register initialization sets 170 - // 171 - 172 - RTMP_REG_PAIR MACRegTable[] = { 173 - #if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200) 174 - {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */ 175 - {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */ 176 - #elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100) 177 - {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */ 178 - {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */ 179 - #else 180 - #error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!!! 181 - #endif // HW_BEACON_OFFSET // 182 - 183 - {LEGACY_BASIC_RATE, 0x0000013f}, // Basic rate set bitmap 184 - {HT_BASIC_RATE, 0x00008003}, // Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI. 185 - {MAC_SYS_CTRL, 0x00}, // 0x1004, , default Disable RX 186 - {RX_FILTR_CFG, 0x17f97}, //0x1400 , RX filter control, 187 - {BKOFF_SLOT_CFG, 0x209}, // default set short slot time, CC_DELAY_TIME should be 2 188 - {TX_SW_CFG0, 0x0}, // Gary,2008-05-21 for CWC test 189 - {TX_SW_CFG1, 0x80606}, // Gary,2006-08-23 190 - {TX_LINK_CFG, 0x1020}, // Gary,2006-08-23 191 - {TX_TIMEOUT_CFG, 0x000a2090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01 192 - {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, // 0x3018, MAX frame length. Max PSDU = 16kbytes. 193 - {LED_CFG, 0x7f031e46}, // Gary, 2006-08-23 194 - {PBF_MAX_PCNT, 0x1F3FBF9F}, //0x1F3f7f9f}, //Jan, 2006/04/20 195 - {TX_RTY_CFG, 0x47d01f0f}, // Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03 196 - {AUTO_RSP_CFG, 0x00000013}, // Initial Auto_Responder, because QA will turn off Auto-Responder 197 - {CCK_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. 198 - {OFDM_PROT_CFG, 0x05740003 /*0x01740003*/}, // Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. 199 - //PS packets use Tx1Q (for HCCA) when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA) 200 - #ifdef RT2870 201 - {PBF_CFG, 0xf40006}, // Only enable Queue 2 202 - {MM40_PROT_CFG, 0x3F44084}, // Initial Auto_Responder, because QA will turn off Auto-Responder 203 - {WPDMA_GLO_CFG, 0x00000030}, 204 - #endif // RT2870 // 205 - {GF20_PROT_CFG, 0x01744004}, // set 19:18 --> Short NAV for MIMO PS 206 - {GF40_PROT_CFG, 0x03F44084}, 207 - {MM20_PROT_CFG, 0x01744004}, 208 - {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f*/ /*0x000024bf*/}, //Extension channel backoff. 209 - {TX_RTS_CFG, 0x00092b20}, 210 - {EXP_ACK_TIME, 0x002400ca}, // default value 211 - {TXOP_HLDR_ET, 0x00000002}, 212 - 213 - /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us 214 - is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0 215 - and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping 216 - will always lost. So we change the SIFS of CCK from 10us to 16us. */ 217 - {XIFS_TIME_CFG, 0x33a41010}, 218 - {PWR_PIN_CFG, 0x00000003}, // patch for 2880-E 219 - }; 220 - 221 - RTMP_REG_PAIR STAMACRegTable[] = { 222 - {WMM_AIFSN_CFG, 0x00002273}, 223 - {WMM_CWMIN_CFG, 0x00002344}, 224 - {WMM_CWMAX_CFG, 0x000034aa}, 225 - }; 226 - 227 - #define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR)) 228 - #define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(RTMP_REG_PAIR)) 229 - 230 - #ifdef RT2870 231 - // 232 - // RT2870 Firmware Spec only used 1 oct for version expression 233 - // 234 - #define FIRMWARE_MINOR_VERSION 7 235 - 236 - #endif // RT2870 // 237 - 238 - // New 8k byte firmware size for RT3071/RT3072 239 - #define FIRMWAREIMAGE_MAX_LENGTH 0x2000 240 - #define FIRMWAREIMAGE_LENGTH (sizeof (FirmwareImage) / sizeof(UCHAR)) 241 - #define FIRMWARE_MAJOR_VERSION 0 242 - 243 - #define FIRMWAREIMAGEV1_LENGTH 0x1000 244 - #define FIRMWAREIMAGEV2_LENGTH 0x1000 245 - 246 - 247 - 248 - /* 249 - ======================================================================== 250 - 251 - Routine Description: 252 - Allocate RTMP_ADAPTER data block and do some initialization 253 - 254 - Arguments: 255 - Adapter Pointer to our adapter 256 - 257 - Return Value: 258 - NDIS_STATUS_SUCCESS 259 - NDIS_STATUS_FAILURE 260 - 261 - IRQL = PASSIVE_LEVEL 262 - 263 - Note: 264 - 265 - ======================================================================== 266 - */ 267 - NDIS_STATUS RTMPAllocAdapterBlock( 268 - IN PVOID handle, 269 - OUT PRTMP_ADAPTER *ppAdapter) 270 - { 271 - PRTMP_ADAPTER pAd; 272 - NDIS_STATUS Status; 273 - INT index; 274 - UCHAR *pBeaconBuf = NULL; 275 - 276 - DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n")); 277 - 278 - *ppAdapter = NULL; 279 - 280 - do 281 - { 282 - // Allocate RTMP_ADAPTER memory block 283 - pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG); 284 - if (pBeaconBuf == NULL) 285 - { 286 - Status = NDIS_STATUS_FAILURE; 287 - DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n")); 288 - break; 289 - } 290 - 291 - Status = AdapterBlockAllocateMemory(handle, (PVOID *)&pAd); 292 - if (Status != NDIS_STATUS_SUCCESS) 293 - { 294 - DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n")); 295 - break; 296 - } 297 - pAd->BeaconBuf = pBeaconBuf; 298 - printk("\n\n=== pAd = %p, size = %d ===\n\n", pAd, (UINT32)sizeof(RTMP_ADAPTER)); 299 - 300 - 301 - // Init spin locks 302 - NdisAllocateSpinLock(&pAd->MgmtRingLock); 303 - 304 - for (index =0 ; index < NUM_OF_TX_RING; index++) 305 - { 306 - NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]); 307 - NdisAllocateSpinLock(&pAd->DeQueueLock[index]); 308 - pAd->DeQueueRunning[index] = FALSE; 309 - } 310 - 311 - NdisAllocateSpinLock(&pAd->irq_lock); 312 - 313 - } while (FALSE); 314 - 315 - if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf)) 316 - kfree(pBeaconBuf); 317 - 318 - *ppAdapter = pAd; 319 - 320 - DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status)); 321 - return Status; 322 - } 323 - 324 - /* 325 - ======================================================================== 326 - 327 - Routine Description: 328 - Read initial Tx power per MCS and BW from EEPROM 329 - 330 - Arguments: 331 - Adapter Pointer to our adapter 332 - 333 - Return Value: 334 - None 335 - 336 - IRQL = PASSIVE_LEVEL 337 - 338 - Note: 339 - 340 - ======================================================================== 341 - */ 342 - VOID RTMPReadTxPwrPerRate( 343 - IN PRTMP_ADAPTER pAd) 344 - { 345 - ULONG data, Adata, Gdata; 346 - USHORT i, value, value2; 347 - INT Apwrdelta, Gpwrdelta; 348 - UCHAR t1,t2,t3,t4; 349 - BOOLEAN bValid, bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE; 350 - 351 - // 352 - // Get power delta for 20MHz and 40MHz. 353 - // 354 - DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n")); 355 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2); 356 - Apwrdelta = 0; 357 - Gpwrdelta = 0; 358 - 359 - if ((value2 & 0xff) != 0xff) 360 - { 361 - if ((value2 & 0x80)) 362 - Gpwrdelta = (value2&0xf); 363 - 364 - if ((value2 & 0x40)) 365 - bGpwrdeltaMinus = FALSE; 366 - else 367 - bGpwrdeltaMinus = TRUE; 368 - } 369 - if ((value2 & 0xff00) != 0xff00) 370 - { 371 - if ((value2 & 0x8000)) 372 - Apwrdelta = ((value2&0xf00)>>8); 373 - 374 - if ((value2 & 0x4000)) 375 - bApwrdeltaMinus = FALSE; 376 - else 377 - bApwrdeltaMinus = TRUE; 378 - } 379 - DBGPRINT(RT_DEBUG_TRACE, ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta)); 380 - 381 - // 382 - // Get Txpower per MCS for 20MHz in 2.4G. 383 - // 384 - for (i=0; i<5; i++) 385 - { 386 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4, value); 387 - data = value; 388 - if (bApwrdeltaMinus == FALSE) 389 - { 390 - t1 = (value&0xf)+(Apwrdelta); 391 - if (t1 > 0xf) 392 - t1 = 0xf; 393 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 394 - if (t2 > 0xf) 395 - t2 = 0xf; 396 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 397 - if (t3 > 0xf) 398 - t3 = 0xf; 399 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 400 - if (t4 > 0xf) 401 - t4 = 0xf; 402 - } 403 - else 404 - { 405 - if ((value&0xf) > Apwrdelta) 406 - t1 = (value&0xf)-(Apwrdelta); 407 - else 408 - t1 = 0; 409 - if (((value&0xf0)>>4) > Apwrdelta) 410 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 411 - else 412 - t2 = 0; 413 - if (((value&0xf00)>>8) > Apwrdelta) 414 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 415 - else 416 - t3 = 0; 417 - if (((value&0xf000)>>12) > Apwrdelta) 418 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 419 - else 420 - t4 = 0; 421 - } 422 - Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12); 423 - if (bGpwrdeltaMinus == FALSE) 424 - { 425 - t1 = (value&0xf)+(Gpwrdelta); 426 - if (t1 > 0xf) 427 - t1 = 0xf; 428 - t2 = ((value&0xf0)>>4)+(Gpwrdelta); 429 - if (t2 > 0xf) 430 - t2 = 0xf; 431 - t3 = ((value&0xf00)>>8)+(Gpwrdelta); 432 - if (t3 > 0xf) 433 - t3 = 0xf; 434 - t4 = ((value&0xf000)>>12)+(Gpwrdelta); 435 - if (t4 > 0xf) 436 - t4 = 0xf; 437 - } 438 - else 439 - { 440 - if ((value&0xf) > Gpwrdelta) 441 - t1 = (value&0xf)-(Gpwrdelta); 442 - else 443 - t1 = 0; 444 - if (((value&0xf0)>>4) > Gpwrdelta) 445 - t2 = ((value&0xf0)>>4)-(Gpwrdelta); 446 - else 447 - t2 = 0; 448 - if (((value&0xf00)>>8) > Gpwrdelta) 449 - t3 = ((value&0xf00)>>8)-(Gpwrdelta); 450 - else 451 - t3 = 0; 452 - if (((value&0xf000)>>12) > Gpwrdelta) 453 - t4 = ((value&0xf000)>>12)-(Gpwrdelta); 454 - else 455 - t4 = 0; 456 - } 457 - Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12); 458 - 459 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i*4 + 2, value); 460 - if (bApwrdeltaMinus == FALSE) 461 - { 462 - t1 = (value&0xf)+(Apwrdelta); 463 - if (t1 > 0xf) 464 - t1 = 0xf; 465 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 466 - if (t2 > 0xf) 467 - t2 = 0xf; 468 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 469 - if (t3 > 0xf) 470 - t3 = 0xf; 471 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 472 - if (t4 > 0xf) 473 - t4 = 0xf; 474 - } 475 - else 476 - { 477 - if ((value&0xf) > Apwrdelta) 478 - t1 = (value&0xf)-(Apwrdelta); 479 - else 480 - t1 = 0; 481 - if (((value&0xf0)>>4) > Apwrdelta) 482 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 483 - else 484 - t2 = 0; 485 - if (((value&0xf00)>>8) > Apwrdelta) 486 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 487 - else 488 - t3 = 0; 489 - if (((value&0xf000)>>12) > Apwrdelta) 490 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 491 - else 492 - t4 = 0; 493 - } 494 - Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28)); 495 - if (bGpwrdeltaMinus == FALSE) 496 - { 497 - t1 = (value&0xf)+(Gpwrdelta); 498 - if (t1 > 0xf) 499 - t1 = 0xf; 500 - t2 = ((value&0xf0)>>4)+(Gpwrdelta); 501 - if (t2 > 0xf) 502 - t2 = 0xf; 503 - t3 = ((value&0xf00)>>8)+(Gpwrdelta); 504 - if (t3 > 0xf) 505 - t3 = 0xf; 506 - t4 = ((value&0xf000)>>12)+(Gpwrdelta); 507 - if (t4 > 0xf) 508 - t4 = 0xf; 509 - } 510 - else 511 - { 512 - if ((value&0xf) > Gpwrdelta) 513 - t1 = (value&0xf)-(Gpwrdelta); 514 - else 515 - t1 = 0; 516 - if (((value&0xf0)>>4) > Gpwrdelta) 517 - t2 = ((value&0xf0)>>4)-(Gpwrdelta); 518 - else 519 - t2 = 0; 520 - if (((value&0xf00)>>8) > Gpwrdelta) 521 - t3 = ((value&0xf00)>>8)-(Gpwrdelta); 522 - else 523 - t3 = 0; 524 - if (((value&0xf000)>>12) > Gpwrdelta) 525 - t4 = ((value&0xf000)>>12)-(Gpwrdelta); 526 - else 527 - t4 = 0; 528 - } 529 - Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28)); 530 - data |= (value<<16); 531 - 532 - pAd->Tx20MPwrCfgABand[i] = pAd->Tx40MPwrCfgABand[i] = Adata; 533 - pAd->Tx20MPwrCfgGBand[i] = pAd->Tx40MPwrCfgGBand[i] = Gdata; 534 - 535 - if (data != 0xffffffff) 536 - RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i*4, data); 537 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n", data, Adata, Gdata)); 538 - } 539 - 540 - // 541 - // Check this block is valid for 40MHz in 2.4G. If invalid, use parameter for 20MHz in 2.4G 542 - // 543 - bValid = TRUE; 544 - for (i=0; i<6; i++) 545 - { 546 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + 2 + i*2, value); 547 - if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00)) 548 - { 549 - bValid = FALSE; 550 - break; 551 - } 552 - } 553 - 554 - // 555 - // Get Txpower per MCS for 40MHz in 2.4G. 556 - // 557 - if (bValid) 558 - { 559 - for (i=0; i<4; i++) 560 - { 561 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4, value); 562 - if (bGpwrdeltaMinus == FALSE) 563 - { 564 - t1 = (value&0xf)+(Gpwrdelta); 565 - if (t1 > 0xf) 566 - t1 = 0xf; 567 - t2 = ((value&0xf0)>>4)+(Gpwrdelta); 568 - if (t2 > 0xf) 569 - t2 = 0xf; 570 - t3 = ((value&0xf00)>>8)+(Gpwrdelta); 571 - if (t3 > 0xf) 572 - t3 = 0xf; 573 - t4 = ((value&0xf000)>>12)+(Gpwrdelta); 574 - if (t4 > 0xf) 575 - t4 = 0xf; 576 - } 577 - else 578 - { 579 - if ((value&0xf) > Gpwrdelta) 580 - t1 = (value&0xf)-(Gpwrdelta); 581 - else 582 - t1 = 0; 583 - if (((value&0xf0)>>4) > Gpwrdelta) 584 - t2 = ((value&0xf0)>>4)-(Gpwrdelta); 585 - else 586 - t2 = 0; 587 - if (((value&0xf00)>>8) > Gpwrdelta) 588 - t3 = ((value&0xf00)>>8)-(Gpwrdelta); 589 - else 590 - t3 = 0; 591 - if (((value&0xf000)>>12) > Gpwrdelta) 592 - t4 = ((value&0xf000)>>12)-(Gpwrdelta); 593 - else 594 - t4 = 0; 595 - } 596 - Gdata = t1 + (t2<<4) + (t3<<8) + (t4<<12); 597 - 598 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_2_4G + i*4 + 2, value); 599 - if (bGpwrdeltaMinus == FALSE) 600 - { 601 - t1 = (value&0xf)+(Gpwrdelta); 602 - if (t1 > 0xf) 603 - t1 = 0xf; 604 - t2 = ((value&0xf0)>>4)+(Gpwrdelta); 605 - if (t2 > 0xf) 606 - t2 = 0xf; 607 - t3 = ((value&0xf00)>>8)+(Gpwrdelta); 608 - if (t3 > 0xf) 609 - t3 = 0xf; 610 - t4 = ((value&0xf000)>>12)+(Gpwrdelta); 611 - if (t4 > 0xf) 612 - t4 = 0xf; 613 - } 614 - else 615 - { 616 - if ((value&0xf) > Gpwrdelta) 617 - t1 = (value&0xf)-(Gpwrdelta); 618 - else 619 - t1 = 0; 620 - if (((value&0xf0)>>4) > Gpwrdelta) 621 - t2 = ((value&0xf0)>>4)-(Gpwrdelta); 622 - else 623 - t2 = 0; 624 - if (((value&0xf00)>>8) > Gpwrdelta) 625 - t3 = ((value&0xf00)>>8)-(Gpwrdelta); 626 - else 627 - t3 = 0; 628 - if (((value&0xf000)>>12) > Gpwrdelta) 629 - t4 = ((value&0xf000)>>12)-(Gpwrdelta); 630 - else 631 - t4 = 0; 632 - } 633 - Gdata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28)); 634 - 635 - if (i == 0) 636 - pAd->Tx40MPwrCfgGBand[i+1] = (pAd->Tx40MPwrCfgGBand[i+1] & 0x0000FFFF) | (Gdata & 0xFFFF0000); 637 - else 638 - pAd->Tx40MPwrCfgGBand[i+1] = Gdata; 639 - 640 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 2.4G band, Gdata = %lx \n", Gdata)); 641 - } 642 - } 643 - 644 - // 645 - // Check this block is valid for 20MHz in 5G. If invalid, use parameter for 20MHz in 2.4G 646 - // 647 - bValid = TRUE; 648 - for (i=0; i<8; i++) 649 - { 650 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + 2 + i*2, value); 651 - if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00)) 652 - { 653 - bValid = FALSE; 654 - break; 655 - } 656 - } 657 - 658 - // 659 - // Get Txpower per MCS for 20MHz in 5G. 660 - // 661 - if (bValid) 662 - { 663 - for (i=0; i<5; i++) 664 - { 665 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4, value); 666 - if (bApwrdeltaMinus == FALSE) 667 - { 668 - t1 = (value&0xf)+(Apwrdelta); 669 - if (t1 > 0xf) 670 - t1 = 0xf; 671 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 672 - if (t2 > 0xf) 673 - t2 = 0xf; 674 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 675 - if (t3 > 0xf) 676 - t3 = 0xf; 677 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 678 - if (t4 > 0xf) 679 - t4 = 0xf; 680 - } 681 - else 682 - { 683 - if ((value&0xf) > Apwrdelta) 684 - t1 = (value&0xf)-(Apwrdelta); 685 - else 686 - t1 = 0; 687 - if (((value&0xf0)>>4) > Apwrdelta) 688 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 689 - else 690 - t2 = 0; 691 - if (((value&0xf00)>>8) > Apwrdelta) 692 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 693 - else 694 - t3 = 0; 695 - if (((value&0xf000)>>12) > Apwrdelta) 696 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 697 - else 698 - t4 = 0; 699 - } 700 - Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12); 701 - 702 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_20MHZ_5G + i*4 + 2, value); 703 - if (bApwrdeltaMinus == FALSE) 704 - { 705 - t1 = (value&0xf)+(Apwrdelta); 706 - if (t1 > 0xf) 707 - t1 = 0xf; 708 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 709 - if (t2 > 0xf) 710 - t2 = 0xf; 711 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 712 - if (t3 > 0xf) 713 - t3 = 0xf; 714 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 715 - if (t4 > 0xf) 716 - t4 = 0xf; 717 - } 718 - else 719 - { 720 - if ((value&0xf) > Apwrdelta) 721 - t1 = (value&0xf)-(Apwrdelta); 722 - else 723 - t1 = 0; 724 - if (((value&0xf0)>>4) > Apwrdelta) 725 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 726 - else 727 - t2 = 0; 728 - if (((value&0xf00)>>8) > Apwrdelta) 729 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 730 - else 731 - t3 = 0; 732 - if (((value&0xf000)>>12) > Apwrdelta) 733 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 734 - else 735 - t4 = 0; 736 - } 737 - Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28)); 738 - 739 - if (i == 0) 740 - pAd->Tx20MPwrCfgABand[i] = (pAd->Tx20MPwrCfgABand[i] & 0x0000FFFF) | (Adata & 0xFFFF0000); 741 - else 742 - pAd->Tx20MPwrCfgABand[i] = Adata; 743 - 744 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("20MHz BW, 5GHz band, Adata = %lx \n", Adata)); 745 - } 746 - } 747 - 748 - // 749 - // Check this block is valid for 40MHz in 5G. If invalid, use parameter for 20MHz in 2.4G 750 - // 751 - bValid = TRUE; 752 - for (i=0; i<6; i++) 753 - { 754 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + 2 + i*2, value); 755 - if (((value & 0x00FF) == 0x00FF) || ((value & 0xFF00) == 0xFF00)) 756 - { 757 - bValid = FALSE; 758 - break; 759 - } 760 - } 761 - 762 - // 763 - // Get Txpower per MCS for 40MHz in 5G. 764 - // 765 - if (bValid) 766 - { 767 - for (i=0; i<4; i++) 768 - { 769 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4, value); 770 - if (bApwrdeltaMinus == FALSE) 771 - { 772 - t1 = (value&0xf)+(Apwrdelta); 773 - if (t1 > 0xf) 774 - t1 = 0xf; 775 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 776 - if (t2 > 0xf) 777 - t2 = 0xf; 778 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 779 - if (t3 > 0xf) 780 - t3 = 0xf; 781 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 782 - if (t4 > 0xf) 783 - t4 = 0xf; 784 - } 785 - else 786 - { 787 - if ((value&0xf) > Apwrdelta) 788 - t1 = (value&0xf)-(Apwrdelta); 789 - else 790 - t1 = 0; 791 - if (((value&0xf0)>>4) > Apwrdelta) 792 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 793 - else 794 - t2 = 0; 795 - if (((value&0xf00)>>8) > Apwrdelta) 796 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 797 - else 798 - t3 = 0; 799 - if (((value&0xf000)>>12) > Apwrdelta) 800 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 801 - else 802 - t4 = 0; 803 - } 804 - Adata = t1 + (t2<<4) + (t3<<8) + (t4<<12); 805 - 806 - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_BYRATE_40MHZ_5G + i*4 + 2, value); 807 - if (bApwrdeltaMinus == FALSE) 808 - { 809 - t1 = (value&0xf)+(Apwrdelta); 810 - if (t1 > 0xf) 811 - t1 = 0xf; 812 - t2 = ((value&0xf0)>>4)+(Apwrdelta); 813 - if (t2 > 0xf) 814 - t2 = 0xf; 815 - t3 = ((value&0xf00)>>8)+(Apwrdelta); 816 - if (t3 > 0xf) 817 - t3 = 0xf; 818 - t4 = ((value&0xf000)>>12)+(Apwrdelta); 819 - if (t4 > 0xf) 820 - t4 = 0xf; 821 - } 822 - else 823 - { 824 - if ((value&0xf) > Apwrdelta) 825 - t1 = (value&0xf)-(Apwrdelta); 826 - else 827 - t1 = 0; 828 - if (((value&0xf0)>>4) > Apwrdelta) 829 - t2 = ((value&0xf0)>>4)-(Apwrdelta); 830 - else 831 - t2 = 0; 832 - if (((value&0xf00)>>8) > Apwrdelta) 833 - t3 = ((value&0xf00)>>8)-(Apwrdelta); 834 - else 835 - t3 = 0; 836 - if (((value&0xf000)>>12) > Apwrdelta) 837 - t4 = ((value&0xf000)>>12)-(Apwrdelta); 838 - else 839 - t4 = 0; 840 - } 841 - Adata |= ((t1<<16) + (t2<<20) + (t3<<24) + (t4<<28)); 842 - 843 - if (i == 0) 844 - pAd->Tx40MPwrCfgABand[i+1] = (pAd->Tx40MPwrCfgABand[i+1] & 0x0000FFFF) | (Adata & 0xFFFF0000); 845 - else 846 - pAd->Tx40MPwrCfgABand[i+1] = Adata; 847 - 848 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("40MHz BW, 5GHz band, Adata = %lx \n", Adata)); 849 - } 850 - } 851 - } 852 - 853 - 854 - /* 855 - ======================================================================== 856 - 857 - Routine Description: 858 - Read initial channel power parameters from EEPROM 859 - 860 - Arguments: 861 - Adapter Pointer to our adapter 862 - 863 - Return Value: 864 - None 865 - 866 - IRQL = PASSIVE_LEVEL 867 - 868 - Note: 869 - 870 - ======================================================================== 871 - */ 872 - VOID RTMPReadChannelPwr( 873 - IN PRTMP_ADAPTER pAd) 874 - { 875 - UCHAR i, choffset; 876 - EEPROM_TX_PWR_STRUC Power; 877 - EEPROM_TX_PWR_STRUC Power2; 878 - 879 - // Read Tx power value for all channels 880 - // Value from 1 - 0x7f. Default value is 24. 881 - // Power value : 2.4G 0x00 (0) ~ 0x1F (31) 882 - // : 5.5G 0xF9 (-7) ~ 0x0F (15) 883 - 884 - // 0. 11b/g, ch1 - ch 14 885 - for (i = 0; i < 7; i++) 886 - { 887 - RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2, Power.word); 888 - RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2, Power2.word); 889 - pAd->TxPower[i * 2].Channel = i * 2 + 1; 890 - pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2; 891 - 892 - if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0)) 893 - pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER; 894 - else 895 - pAd->TxPower[i * 2].Power = Power.field.Byte0; 896 - 897 - if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0)) 898 - pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER; 899 - else 900 - pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1; 901 - 902 - if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0)) 903 - pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER; 904 - else 905 - pAd->TxPower[i * 2].Power2 = Power2.field.Byte0; 906 - 907 - if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0)) 908 - pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER; 909 - else 910 - pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1; 911 - } 912 - 913 - // 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz) 914 - // 1.1 Fill up channel 915 - choffset = 14; 916 - for (i = 0; i < 4; i++) 917 - { 918 - pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0; 919 - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; 920 - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; 921 - 922 - pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2; 923 - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; 924 - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; 925 - 926 - pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4; 927 - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; 928 - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; 929 - } 930 - 931 - // 1.2 Fill up power 932 - for (i = 0; i < 6; i++) 933 - { 934 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2, Power.word); 935 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2, Power2.word); 936 - 937 - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) 938 - pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0; 939 - 940 - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) 941 - pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1; 942 - 943 - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) 944 - pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0; 945 - 946 - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) 947 - pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1; 948 - } 949 - 950 - // 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz) 951 - // 2.1 Fill up channel 952 - choffset = 14 + 12; 953 - for (i = 0; i < 5; i++) 954 - { 955 - pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0; 956 - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; 957 - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; 958 - 959 - pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2; 960 - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; 961 - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; 962 - 963 - pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4; 964 - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; 965 - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; 966 - } 967 - pAd->TxPower[3 * 5 + choffset + 0].Channel = 140; 968 - pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER; 969 - pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; 970 - 971 - // 2.2 Fill up power 972 - for (i = 0; i < 8; i++) 973 - { 974 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word); 975 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word); 976 - 977 - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) 978 - pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0; 979 - 980 - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) 981 - pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1; 982 - 983 - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) 984 - pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0; 985 - 986 - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) 987 - pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1; 988 - } 989 - 990 - // 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165 (including central frequency in BW 40MHz) 991 - // 3.1 Fill up channel 992 - choffset = 14 + 12 + 16; 993 - for (i = 0; i < 2; i++) 994 - { 995 - pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0; 996 - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; 997 - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; 998 - 999 - pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2; 1000 - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; 1001 - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; 1002 - 1003 - pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4; 1004 - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; 1005 - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; 1006 - } 1007 - pAd->TxPower[3 * 2 + choffset + 0].Channel = 165; 1008 - pAd->TxPower[3 * 2 + choffset + 0].Power = DEFAULT_RF_TX_POWER; 1009 - pAd->TxPower[3 * 2 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; 1010 - 1011 - // 3.2 Fill up power 1012 - for (i = 0; i < 4; i++) 1013 - { 1014 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + i * 2, Power.word); 1015 - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + i * 2, Power2.word); 1016 - 1017 - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) 1018 - pAd->TxPower[i * 2 + choffset + 0].Power = Power.field.Byte0; 1019 - 1020 - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) 1021 - pAd->TxPower[i * 2 + choffset + 1].Power = Power.field.Byte1; 1022 - 1023 - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) 1024 - pAd->TxPower[i * 2 + choffset + 0].Power2 = Power2.field.Byte0; 1025 - 1026 - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) 1027 - pAd->TxPower[i * 2 + choffset + 1].Power2 = Power2.field.Byte1; 1028 - } 1029 - 1030 - // 4. Print and Debug 1031 - choffset = 14 + 12 + 16 + 7; 1032 - 1033 - } 1034 - 1035 - /* 1036 - ======================================================================== 1037 - 1038 - Routine Description: 1039 - Read the following from the registry 1040 - 1. All the parameters 1041 - 2. NetworkAddres 1042 - 1043 - Arguments: 1044 - Adapter Pointer to our adapter 1045 - WrapperConfigurationContext For use by NdisOpenConfiguration 1046 - 1047 - Return Value: 1048 - NDIS_STATUS_SUCCESS 1049 - NDIS_STATUS_FAILURE 1050 - NDIS_STATUS_RESOURCES 1051 - 1052 - IRQL = PASSIVE_LEVEL 1053 - 1054 - Note: 1055 - 1056 - ======================================================================== 1057 - */ 1058 - NDIS_STATUS NICReadRegParameters( 1059 - IN PRTMP_ADAPTER pAd, 1060 - IN NDIS_HANDLE WrapperConfigurationContext 1061 - ) 1062 - { 1063 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 1064 - DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status)); 1065 - return Status; 1066 - } 1067 - 1068 - 1069 - #ifdef RT2870 1070 - /* 1071 - ======================================================================== 1072 - 1073 - Routine Description: 1074 - For RF filter calibration purpose 1075 - 1076 - Arguments: 1077 - pAd Pointer to our adapter 1078 - 1079 - Return Value: 1080 - None 1081 - 1082 - IRQL = PASSIVE_LEVEL 1083 - 1084 - ======================================================================== 1085 - */ 1086 - #ifndef RT30xx 1087 - VOID RTUSBFilterCalibration( 1088 - IN PRTMP_ADAPTER pAd) 1089 - { 1090 - UCHAR R55x = 0, value, FilterTarget = 0x1E, BBPValue; 1091 - UINT loop = 0, count = 0, loopcnt = 0, ReTry = 0; 1092 - UCHAR RF_R24_Value = 0; 1093 - 1094 - // Give bbp filter initial value 1095 - pAd->Mlme.CaliBW20RfR24 = 0x16; 1096 - pAd->Mlme.CaliBW40RfR24 = 0x36; //Bit[5] must be 1 for BW 40 1097 - 1098 - do 1099 - { 1100 - if (loop == 1) //BandWidth = 40 MHz 1101 - { 1102 - // Write 0x27 to RF_R24 to program filter 1103 - RF_R24_Value = 0x27; 1104 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1105 - FilterTarget = 0x19; 1106 - 1107 - // when calibrate BW40, BBP mask must set to BW40. 1108 - RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue); 1109 - BBPValue&= (~0x18); 1110 - BBPValue|= (0x10); 1111 - RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue); 1112 - } 1113 - else //BandWidth = 20 MHz 1114 - { 1115 - // Write 0x07 to RF_R24 to program filter 1116 - RF_R24_Value = 0x07; 1117 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1118 - FilterTarget = 0x16; 1119 - } 1120 - 1121 - // Write 0x01 to RF_R22 to enable baseband loopback mode 1122 - RT30xxReadRFRegister(pAd, RF_R22, &value); 1123 - value |= 0x01; 1124 - RT30xxWriteRFRegister(pAd, RF_R22, value); 1125 - 1126 - // Write 0x00 to BBP_R24 to set power & frequency of passband test tone 1127 - RTUSBWriteBBPRegister(pAd, BBP_R24, 0); 1128 - 1129 - do 1130 - { 1131 - // Write 0x90 to BBP_R25 to transmit test tone 1132 - RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90); 1133 - 1134 - RTMPusecDelay(1000); 1135 - // Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0] 1136 - RTUSBReadBBPRegister(pAd, BBP_R55, &value); 1137 - R55x = value & 0xFF; 1138 - 1139 - } while ((ReTry++ < 100) && (R55x == 0)); 1140 - 1141 - // Write 0x06 to BBP_R24 to set power & frequency of stopband test tone 1142 - RTUSBWriteBBPRegister(pAd, BBP_R24, 0x06); 1143 - 1144 - while(TRUE) 1145 - { 1146 - // Write 0x90 to BBP_R25 to transmit test tone 1147 - RTUSBWriteBBPRegister(pAd, BBP_R25, 0x90); 1148 - 1149 - //We need to wait for calibration 1150 - RTMPusecDelay(1000); 1151 - RTUSBReadBBPRegister(pAd, BBP_R55, &value); 1152 - value &= 0xFF; 1153 - if ((R55x - value) < FilterTarget) 1154 - { 1155 - RF_R24_Value ++; 1156 - } 1157 - else if ((R55x - value) == FilterTarget) 1158 - { 1159 - RF_R24_Value ++; 1160 - count ++; 1161 - } 1162 - else 1163 - { 1164 - break; 1165 - } 1166 - 1167 - // prevent infinite loop cause driver hang. 1168 - if (loopcnt++ > 100) 1169 - { 1170 - DBGPRINT(RT_DEBUG_ERROR, ("RTUSBFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt)); 1171 - break; 1172 - } 1173 - 1174 - // Write RF_R24 to program filter 1175 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1176 - } 1177 - 1178 - if (count > 0) 1179 - { 1180 - RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0)); 1181 - } 1182 - 1183 - // Store for future usage 1184 - if (loopcnt < 100) 1185 - { 1186 - if (loop++ == 0) 1187 - { 1188 - //BandWidth = 20 MHz 1189 - pAd->Mlme.CaliBW20RfR24 = (UCHAR)RF_R24_Value; 1190 - } 1191 - else 1192 - { 1193 - //BandWidth = 40 MHz 1194 - pAd->Mlme.CaliBW40RfR24 = (UCHAR)RF_R24_Value; 1195 - break; 1196 - } 1197 - } 1198 - else 1199 - break; 1200 - 1201 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1202 - 1203 - // reset count 1204 - count = 0; 1205 - } while(TRUE); 1206 - 1207 - // 1208 - // Set back to initial state 1209 - // 1210 - RTUSBWriteBBPRegister(pAd, BBP_R24, 0); 1211 - 1212 - RT30xxReadRFRegister(pAd, RF_R22, &value); 1213 - value &= ~(0x01); 1214 - RT30xxWriteRFRegister(pAd, RF_R22, value); 1215 - 1216 - // set BBP back to BW20 1217 - RTUSBReadBBPRegister(pAd, BBP_R4, &BBPValue); 1218 - BBPValue&= (~0x18); 1219 - RTUSBWriteBBPRegister(pAd, BBP_R4, BBPValue); 1220 - 1221 - DBGPRINT(RT_DEBUG_TRACE, ("RTUSBFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24)); 1222 - } 1223 - #endif /* RT30xx */ 1224 - #ifdef RT30xx 1225 - VOID RTMPFilterCalibration( 1226 - IN PRTMP_ADAPTER pAd) 1227 - { 1228 - UCHAR R55x = 0, value, FilterTarget = 0x1E, BBPValue=0; 1229 - UINT loop = 0, count = 0, loopcnt = 0, ReTry = 0; 1230 - UCHAR RF_R24_Value = 0; 1231 - 1232 - // Give bbp filter initial value 1233 - pAd->Mlme.CaliBW20RfR24 = 0x1F; 1234 - pAd->Mlme.CaliBW40RfR24 = 0x2F; //Bit[5] must be 1 for BW 40 1235 - 1236 - do 1237 - { 1238 - if (loop == 1) //BandWidth = 40 MHz 1239 - { 1240 - // Write 0x27 to RF_R24 to program filter 1241 - RF_R24_Value = 0x27; 1242 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1243 - if (IS_RT3090(pAd)) 1244 - FilterTarget = 0x15; 1245 - else 1246 - FilterTarget = 0x19; 1247 - 1248 - // when calibrate BW40, BBP mask must set to BW40. 1249 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); 1250 - BBPValue&= (~0x18); 1251 - BBPValue|= (0x10); 1252 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); 1253 - 1254 - // set to BW40 1255 - RT30xxReadRFRegister(pAd, RF_R31, &value); 1256 - value |= 0x20; 1257 - RT30xxWriteRFRegister(pAd, RF_R31, value); 1258 - } 1259 - else //BandWidth = 20 MHz 1260 - { 1261 - // Write 0x07 to RF_R24 to program filter 1262 - RF_R24_Value = 0x07; 1263 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1264 - if (IS_RT3090(pAd)) 1265 - FilterTarget = 0x13; 1266 - else 1267 - FilterTarget = 0x16; 1268 - 1269 - // set to BW20 1270 - RT30xxReadRFRegister(pAd, RF_R31, &value); 1271 - value &= (~0x20); 1272 - RT30xxWriteRFRegister(pAd, RF_R31, value); 1273 - } 1274 - 1275 - // Write 0x01 to RF_R22 to enable baseband loopback mode 1276 - RT30xxReadRFRegister(pAd, RF_R22, &value); 1277 - value |= 0x01; 1278 - RT30xxWriteRFRegister(pAd, RF_R22, value); 1279 - 1280 - // Write 0x00 to BBP_R24 to set power & frequency of passband test tone 1281 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0); 1282 - 1283 - do 1284 - { 1285 - // Write 0x90 to BBP_R25 to transmit test tone 1286 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90); 1287 - 1288 - RTMPusecDelay(1000); 1289 - // Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0] 1290 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value); 1291 - R55x = value & 0xFF; 1292 - 1293 - } while ((ReTry++ < 100) && (R55x == 0)); 1294 - 1295 - // Write 0x06 to BBP_R24 to set power & frequency of stopband test tone 1296 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0x06); 1297 - 1298 - while(TRUE) 1299 - { 1300 - // Write 0x90 to BBP_R25 to transmit test tone 1301 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90); 1302 - 1303 - //We need to wait for calibration 1304 - RTMPusecDelay(1000); 1305 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value); 1306 - value &= 0xFF; 1307 - if ((R55x - value) < FilterTarget) 1308 - { 1309 - RF_R24_Value ++; 1310 - } 1311 - else if ((R55x - value) == FilterTarget) 1312 - { 1313 - RF_R24_Value ++; 1314 - count ++; 1315 - } 1316 - else 1317 - { 1318 - break; 1319 - } 1320 - 1321 - // prevent infinite loop cause driver hang. 1322 - if (loopcnt++ > 100) 1323 - { 1324 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", loopcnt)); 1325 - break; 1326 - } 1327 - 1328 - // Write RF_R24 to program filter 1329 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1330 - } 1331 - 1332 - if (count > 0) 1333 - { 1334 - RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0)); 1335 - } 1336 - 1337 - // Store for future usage 1338 - if (loopcnt < 100) 1339 - { 1340 - if (loop++ == 0) 1341 - { 1342 - //BandWidth = 20 MHz 1343 - pAd->Mlme.CaliBW20RfR24 = (UCHAR)RF_R24_Value; 1344 - } 1345 - else 1346 - { 1347 - //BandWidth = 40 MHz 1348 - pAd->Mlme.CaliBW40RfR24 = (UCHAR)RF_R24_Value; 1349 - break; 1350 - } 1351 - } 1352 - else 1353 - break; 1354 - 1355 - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); 1356 - 1357 - // reset count 1358 - count = 0; 1359 - } while(TRUE); 1360 - 1361 - // 1362 - // Set back to initial state 1363 - // 1364 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0); 1365 - 1366 - RT30xxReadRFRegister(pAd, RF_R22, &value); 1367 - value &= ~(0x01); 1368 - RT30xxWriteRFRegister(pAd, RF_R22, value); 1369 - 1370 - // set BBP back to BW20 1371 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); 1372 - BBPValue&= (~0x18); 1373 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); 1374 - 1375 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24)); 1376 - } 1377 - #endif /* RT30xx */ 1378 - 1379 - VOID NICInitRT30xxRFRegisters(IN PRTMP_ADAPTER pAd) 1380 - { 1381 - INT i; 1382 - // Driver must read EEPROM to get RfIcType before initial RF registers 1383 - // Initialize RF register to default value 1384 - #ifndef RT30xx 1385 - if (IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) ||(pAd->RfIcType == RFIC_2020))) 1386 - { 1387 - // Init RF calibration 1388 - // Driver should toggle RF R30 bit7 before init RF registers 1389 - ULONG RfReg = 0; 1390 - RT30xxReadRFRegister(pAd, RF_R30, (PUCHAR)&RfReg); 1391 - RfReg |= 0x80; 1392 - RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg); 1393 - RTMPusecDelay(1000); 1394 - RfReg &= 0x7F; 1395 - RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg); 1396 - 1397 - // Initialize RF register to default value 1398 - for (i = 0; i < NUM_RF_REG_PARMS; i++) 1399 - { 1400 - RT30xxWriteRFRegister(pAd, RT30xx_RFRegTable[i].Register, RT30xx_RFRegTable[i].Value); 1401 - } 1402 - 1403 - //For RF filter Calibration 1404 - RTUSBFilterCalibration(pAd); 1405 - } 1406 - #endif 1407 - #ifdef RT30xx 1408 - if (IS_RT3070(pAd) || IS_RT3071(pAd)) 1409 - { 1410 - // Init RF calibration 1411 - // Driver should toggle RF R30 bit7 before init RF registers 1412 - UINT32 RfReg = 0; 1413 - UINT32 data; 1414 - 1415 - RT30xxReadRFRegister(pAd, RF_R30, (PUCHAR)&RfReg); 1416 - RfReg |= 0x80; 1417 - RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg); 1418 - RTMPusecDelay(1000); 1419 - RfReg &= 0x7F; 1420 - RT30xxWriteRFRegister(pAd, RF_R30, (UCHAR)RfReg); 1421 - 1422 - // Initialize RF register to default value 1423 - for (i = 0; i < NUM_RF_REG_PARMS; i++) 1424 - { 1425 - RT30xxWriteRFRegister(pAd, RT30xx_RFRegTable[i].Register, RT30xx_RFRegTable[i].Value); 1426 - } 1427 - 1428 - // add by johnli 1429 - if (IS_RT3070(pAd)) 1430 - { 1431 - // Update MAC 0x05D4 from 01xxxxxx to 0Dxxxxxx (voltage 1.2V to 1.35V) for RT3070 to improve yield rate 1432 - RTUSBReadMACRegister(pAd, LDO_CFG0, &data); 1433 - data = ((data & 0xF0FFFFFF) | 0x0D000000); 1434 - RTUSBWriteMACRegister(pAd, LDO_CFG0, data); 1435 - } 1436 - else if (IS_RT3071(pAd)) 1437 - { 1438 - // Driver should set RF R6 bit6 on before init RF registers 1439 - RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RfReg); 1440 - RfReg |= 0x40; 1441 - RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RfReg); 1442 - 1443 - // init R31 1444 - RT30xxWriteRFRegister(pAd, RF_R31, 0x14); 1445 - 1446 - // RT3071 version E has fixed this issue 1447 - if ((pAd->NicConfig2.field.DACTestBit == 1) && ((pAd->MACVersion & 0xffff) < 0x0211)) 1448 - { 1449 - // patch tx EVM issue temporarily 1450 - RTUSBReadMACRegister(pAd, LDO_CFG0, &data); 1451 - data = ((data & 0xE0FFFFFF) | 0x0D000000); 1452 - RTUSBWriteMACRegister(pAd, LDO_CFG0, data); 1453 - } 1454 - else 1455 - { 1456 - RTMP_IO_READ32(pAd, LDO_CFG0, &data); 1457 - data = ((data & 0xE0FFFFFF) | 0x01000000); 1458 - RTMP_IO_WRITE32(pAd, LDO_CFG0, data); 1459 - } 1460 - 1461 - // patch LNA_PE_G1 failed issue 1462 - RTUSBReadMACRegister(pAd, GPIO_SWITCH, &data); 1463 - data &= ~(0x20); 1464 - RTUSBWriteMACRegister(pAd, GPIO_SWITCH, data); 1465 - } 1466 - 1467 - //For RF filter Calibration 1468 - RTMPFilterCalibration(pAd); 1469 - 1470 - // Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() 1471 - if ((pAd->MACVersion & 0xffff) < 0x0211) 1472 - RT30xxWriteRFRegister(pAd, RF_R27, 0x3); 1473 - 1474 - // set led open drain enable 1475 - RTUSBReadMACRegister(pAd, OPT_14, &data); 1476 - data |= 0x01; 1477 - RTUSBWriteMACRegister(pAd, OPT_14, data); 1478 - 1479 - if (IS_RT3071(pAd)) 1480 - { 1481 - // add by johnli, RF power sequence setup, load RF normal operation-mode setup 1482 - RT30xxLoadRFNormalModeSetup(pAd); 1483 - } 1484 - } 1485 - #endif 1486 - } 1487 - #endif // RT2870 // 1488 - 1489 - 1490 - /* 1491 - ======================================================================== 1492 - 1493 - Routine Description: 1494 - Read initial parameters from EEPROM 1495 - 1496 - Arguments: 1497 - Adapter Pointer to our adapter 1498 - 1499 - Return Value: 1500 - None 1501 - 1502 - IRQL = PASSIVE_LEVEL 1503 - 1504 - Note: 1505 - 1506 - ======================================================================== 1507 - */ 1508 - VOID NICReadEEPROMParameters( 1509 - IN PRTMP_ADAPTER pAd, 1510 - IN PUCHAR mac_addr) 1511 - { 1512 - UINT32 data = 0; 1513 - USHORT i, value, value2; 1514 - UCHAR TmpPhy; 1515 - EEPROM_TX_PWR_STRUC Power; 1516 - EEPROM_VERSION_STRUC Version; 1517 - EEPROM_ANTENNA_STRUC Antenna; 1518 - EEPROM_NIC_CONFIG2_STRUC NicConfig2; 1519 - 1520 - DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n")); 1521 - 1522 - // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8 1523 - RTMP_IO_READ32(pAd, E2PROM_CSR, &data); 1524 - DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data)); 1525 - 1526 - if((data & 0x30) == 0) 1527 - pAd->EEPROMAddressNum = 6; // 93C46 1528 - else if((data & 0x30) == 0x10) 1529 - pAd->EEPROMAddressNum = 8; // 93C66 1530 - else 1531 - pAd->EEPROMAddressNum = 8; // 93C86 1532 - DBGPRINT(RT_DEBUG_TRACE, ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum )); 1533 - 1534 - // RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to intialize 1535 - // MAC address registers according to E2PROM setting 1536 - if (mac_addr == NULL || 1537 - strlen(mac_addr) != 17 || 1538 - mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' || 1539 - mac_addr[11] != ':' || mac_addr[14] != ':') 1540 - { 1541 - USHORT Addr01,Addr23,Addr45 ; 1542 - 1543 - RT28xx_EEPROM_READ16(pAd, 0x04, Addr01); 1544 - RT28xx_EEPROM_READ16(pAd, 0x06, Addr23); 1545 - RT28xx_EEPROM_READ16(pAd, 0x08, Addr45); 1546 - 1547 - pAd->PermanentAddress[0] = (UCHAR)(Addr01 & 0xff); 1548 - pAd->PermanentAddress[1] = (UCHAR)(Addr01 >> 8); 1549 - pAd->PermanentAddress[2] = (UCHAR)(Addr23 & 0xff); 1550 - pAd->PermanentAddress[3] = (UCHAR)(Addr23 >> 8); 1551 - pAd->PermanentAddress[4] = (UCHAR)(Addr45 & 0xff); 1552 - pAd->PermanentAddress[5] = (UCHAR)(Addr45 >> 8); 1553 - 1554 - DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from E2PROM \n")); 1555 - } 1556 - else 1557 - { 1558 - INT j; 1559 - PUCHAR macptr; 1560 - 1561 - macptr = mac_addr; 1562 - 1563 - for (j=0; j<MAC_ADDR_LEN; j++) 1564 - { 1565 - AtoH(macptr, &pAd->PermanentAddress[j], 1); 1566 - macptr=macptr+3; 1567 - } 1568 - 1569 - DBGPRINT(RT_DEBUG_TRACE, ("Initialize MAC Address from module parameter \n")); 1570 - } 1571 - 1572 - 1573 - { 1574 - //more conveninet to test mbssid, so ap's bssid &0xf1 1575 - if (pAd->PermanentAddress[0] == 0xff) 1576 - pAd->PermanentAddress[0] = RandomByte(pAd)&0xf8; 1577 - 1578 - //if (pAd->PermanentAddress[5] == 0xff) 1579 - // pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8; 1580 - 1581 - DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n", 1582 - pAd->PermanentAddress[0], pAd->PermanentAddress[1], 1583 - pAd->PermanentAddress[2], pAd->PermanentAddress[3], 1584 - pAd->PermanentAddress[4], pAd->PermanentAddress[5])); 1585 - if (pAd->bLocalAdminMAC == FALSE) 1586 - { 1587 - MAC_DW0_STRUC csr2; 1588 - MAC_DW1_STRUC csr3; 1589 - COPY_MAC_ADDR(pAd->CurrentAddress, pAd->PermanentAddress); 1590 - csr2.field.Byte0 = pAd->CurrentAddress[0]; 1591 - csr2.field.Byte1 = pAd->CurrentAddress[1]; 1592 - csr2.field.Byte2 = pAd->CurrentAddress[2]; 1593 - csr2.field.Byte3 = pAd->CurrentAddress[3]; 1594 - RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word); 1595 - csr3.word = 0; 1596 - csr3.field.Byte4 = pAd->CurrentAddress[4]; 1597 - csr3.field.Byte5 = pAd->CurrentAddress[5]; 1598 - csr3.field.U2MeMask = 0xff; 1599 - RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word); 1600 - DBGPRINT_RAW(RT_DEBUG_TRACE,("E2PROM MAC: =%02x:%02x:%02x:%02x:%02x:%02x\n", 1601 - pAd->PermanentAddress[0], pAd->PermanentAddress[1], 1602 - pAd->PermanentAddress[2], pAd->PermanentAddress[3], 1603 - pAd->PermanentAddress[4], pAd->PermanentAddress[5])); 1604 - } 1605 - } 1606 - 1607 - // if not return early. cause fail at emulation. 1608 - // Init the channel number for TX channel power 1609 - RTMPReadChannelPwr(pAd); 1610 - 1611 - // if E2PROM version mismatch with driver's expectation, then skip 1612 - // all subsequent E2RPOM retieval and set a system error bit to notify GUI 1613 - RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word); 1614 - pAd->EepromVersion = Version.field.Version + Version.field.FaeReleaseNumber * 256; 1615 - DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: Version = %d, FAE release #%d\n", Version.field.Version, Version.field.FaeReleaseNumber)); 1616 - 1617 - if (Version.field.Version > VALID_EEPROM_VERSION) 1618 - { 1619 - DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n",Version.field.Version, VALID_EEPROM_VERSION)); 1620 - /*pAd->SystemErrorBitmap |= 0x00000001; 1621 - 1622 - // hard-code default value when no proper E2PROM installed 1623 - pAd->bAutoTxAgcA = FALSE; 1624 - pAd->bAutoTxAgcG = FALSE; 1625 - 1626 - // Default the channel power 1627 - for (i = 0; i < MAX_NUM_OF_CHANNELS; i++) 1628 - pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER; 1629 - 1630 - // Default the channel power 1631 - for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++) 1632 - pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER; 1633 - 1634 - for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++) 1635 - pAd->EEPROMDefaultValue[i] = 0xffff; 1636 - return; */ 1637 - } 1638 - 1639 - // Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd 1640 - RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value); 1641 - pAd->EEPROMDefaultValue[0] = value; 1642 - 1643 - RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value); 1644 - pAd->EEPROMDefaultValue[1] = value; 1645 - 1646 - RT28xx_EEPROM_READ16(pAd, 0x38, value); // Country Region 1647 - pAd->EEPROMDefaultValue[2] = value; 1648 - 1649 - for(i = 0; i < 8; i++) 1650 - { 1651 - RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i*2, value); 1652 - pAd->EEPROMDefaultValue[i+3] = value; 1653 - } 1654 - 1655 - // We have to parse NIC configuration 0 at here. 1656 - // If TSSI did not have preloaded value, it should reset the TxAutoAgc to false 1657 - // Therefore, we have to read TxAutoAgc control beforehand. 1658 - // Read Tx AGC control bit 1659 - Antenna.word = pAd->EEPROMDefaultValue[0]; 1660 - if (Antenna.word == 0xFFFF) 1661 - { 1662 - #ifdef RT30xx 1663 - if(IS_RT3090(pAd)) 1664 - { 1665 - Antenna.word = 0; 1666 - Antenna.field.RfIcType = RFIC_3020; 1667 - Antenna.field.TxPath = 1; 1668 - Antenna.field.RxPath = 1; 1669 - } 1670 - else 1671 - { 1672 - #endif // RT30xx // 1673 - Antenna.word = 0; 1674 - Antenna.field.RfIcType = RFIC_2820; 1675 - Antenna.field.TxPath = 1; 1676 - Antenna.field.RxPath = 2; 1677 - DBGPRINT(RT_DEBUG_WARN, ("E2PROM error, hard code as 0x%04x\n", Antenna.word)); 1678 - #ifdef RT30xx 1679 - } 1680 - #endif // RT30xx // 1681 - } 1682 - 1683 - // Choose the desired Tx&Rx stream. 1684 - if ((pAd->CommonCfg.TxStream == 0) || (pAd->CommonCfg.TxStream > Antenna.field.TxPath)) 1685 - pAd->CommonCfg.TxStream = Antenna.field.TxPath; 1686 - 1687 - if ((pAd->CommonCfg.RxStream == 0) || (pAd->CommonCfg.RxStream > Antenna.field.RxPath)) 1688 - { 1689 - pAd->CommonCfg.RxStream = Antenna.field.RxPath; 1690 - 1691 - if ((pAd->MACVersion < RALINK_2883_VERSION) && 1692 - (pAd->CommonCfg.RxStream > 2)) 1693 - { 1694 - // only 2 Rx streams for RT2860 series 1695 - pAd->CommonCfg.RxStream = 2; 1696 - } 1697 - } 1698 - 1699 - // 3*3 1700 - // read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2 1701 - // yet implement 1702 - for(i=0; i<3; i++) 1703 - { 1704 - } 1705 - 1706 - NicConfig2.word = pAd->EEPROMDefaultValue[1]; 1707 - 1708 - { 1709 - #ifndef RT30xx 1710 - NicConfig2.word = 0; 1711 - #endif 1712 - if ((NicConfig2.word & 0x00ff) == 0xff) 1713 - { 1714 - NicConfig2.word &= 0xff00; 1715 - } 1716 - 1717 - if ((NicConfig2.word >> 8) == 0xff) 1718 - { 1719 - NicConfig2.word &= 0x00ff; 1720 - } 1721 - } 1722 - 1723 - if (NicConfig2.field.DynamicTxAgcControl == 1) 1724 - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE; 1725 - else 1726 - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE; 1727 - 1728 - DBGPRINT_RAW(RT_DEBUG_TRACE, ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n", Antenna.field.RxPath, Antenna.field.TxPath)); 1729 - 1730 - // Save the antenna for future use 1731 - pAd->Antenna.word = Antenna.word; 1732 - 1733 - // 1734 - // Reset PhyMode if we don't support 802.11a 1735 - // Only RFIC_2850 & RFIC_2750 support 802.11a 1736 - // 1737 - if ((Antenna.field.RfIcType != RFIC_2850) && (Antenna.field.RfIcType != RFIC_2750)) 1738 - { 1739 - if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) || 1740 - (pAd->CommonCfg.PhyMode == PHY_11A)) 1741 - pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; 1742 - else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || 1743 - (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) || 1744 - (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) || 1745 - (pAd->CommonCfg.PhyMode == PHY_11N_5G)) 1746 - pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED; 1747 - } 1748 - 1749 - // Read TSSI reference and TSSI boundary for temperature compensation. This is ugly 1750 - // 0. 11b/g 1751 - { 1752 - /* these are tempature reference value (0x00 ~ 0xFE) 1753 - ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0 1754 - TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) + 1755 - TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */ 1756 - RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word); 1757 - pAd->TssiMinusBoundaryG[4] = Power.field.Byte0; 1758 - pAd->TssiMinusBoundaryG[3] = Power.field.Byte1; 1759 - RT28xx_EEPROM_READ16(pAd, 0x70, Power.word); 1760 - pAd->TssiMinusBoundaryG[2] = Power.field.Byte0; 1761 - pAd->TssiMinusBoundaryG[1] = Power.field.Byte1; 1762 - RT28xx_EEPROM_READ16(pAd, 0x72, Power.word); 1763 - pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */ 1764 - pAd->TssiPlusBoundaryG[1] = Power.field.Byte1; 1765 - RT28xx_EEPROM_READ16(pAd, 0x74, Power.word); 1766 - pAd->TssiPlusBoundaryG[2] = Power.field.Byte0; 1767 - pAd->TssiPlusBoundaryG[3] = Power.field.Byte1; 1768 - RT28xx_EEPROM_READ16(pAd, 0x76, Power.word); 1769 - pAd->TssiPlusBoundaryG[4] = Power.field.Byte0; 1770 - pAd->TxAgcStepG = Power.field.Byte1; 1771 - pAd->TxAgcCompensateG = 0; 1772 - pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG; 1773 - pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG; 1774 - 1775 - // Disable TxAgc if the based value is not right 1776 - if (pAd->TssiRefG == 0xff) 1777 - pAd->bAutoTxAgcG = FALSE; 1778 - 1779 - DBGPRINT(RT_DEBUG_TRACE,("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n", 1780 - pAd->TssiMinusBoundaryG[4], pAd->TssiMinusBoundaryG[3], pAd->TssiMinusBoundaryG[2], pAd->TssiMinusBoundaryG[1], 1781 - pAd->TssiRefG, 1782 - pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2], pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4], 1783 - pAd->TxAgcStepG, pAd->bAutoTxAgcG)); 1784 - } 1785 - // 1. 11a 1786 - { 1787 - RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word); 1788 - pAd->TssiMinusBoundaryA[4] = Power.field.Byte0; 1789 - pAd->TssiMinusBoundaryA[3] = Power.field.Byte1; 1790 - RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word); 1791 - pAd->TssiMinusBoundaryA[2] = Power.field.Byte0; 1792 - pAd->TssiMinusBoundaryA[1] = Power.field.Byte1; 1793 - RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word); 1794 - pAd->TssiRefA = Power.field.Byte0; 1795 - pAd->TssiPlusBoundaryA[1] = Power.field.Byte1; 1796 - RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word); 1797 - pAd->TssiPlusBoundaryA[2] = Power.field.Byte0; 1798 - pAd->TssiPlusBoundaryA[3] = Power.field.Byte1; 1799 - RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word); 1800 - pAd->TssiPlusBoundaryA[4] = Power.field.Byte0; 1801 - pAd->TxAgcStepA = Power.field.Byte1; 1802 - pAd->TxAgcCompensateA = 0; 1803 - pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA; 1804 - pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA; 1805 - 1806 - // Disable TxAgc if the based value is not right 1807 - if (pAd->TssiRefA == 0xff) 1808 - pAd->bAutoTxAgcA = FALSE; 1809 - 1810 - DBGPRINT(RT_DEBUG_TRACE,("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n", 1811 - pAd->TssiMinusBoundaryA[4], pAd->TssiMinusBoundaryA[3], pAd->TssiMinusBoundaryA[2], pAd->TssiMinusBoundaryA[1], 1812 - pAd->TssiRefA, 1813 - pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2], pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4], 1814 - pAd->TxAgcStepA, pAd->bAutoTxAgcA)); 1815 - } 1816 - pAd->BbpRssiToDbmDelta = 0x0; 1817 - 1818 - // Read frequency offset setting for RF 1819 - RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value); 1820 - if ((value & 0x00FF) != 0x00FF) 1821 - pAd->RfFreqOffset = (ULONG) (value & 0x00FF); 1822 - else 1823 - pAd->RfFreqOffset = 0; 1824 - DBGPRINT(RT_DEBUG_TRACE, ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset)); 1825 - 1826 - //CountryRegion byte offset (38h) 1827 - value = pAd->EEPROMDefaultValue[2] >> 8; // 2.4G band 1828 - value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; // 5G band 1829 - 1830 - if ((value <= REGION_MAXIMUM_BG_BAND) && (value2 <= REGION_MAXIMUM_A_BAND)) 1831 - { 1832 - pAd->CommonCfg.CountryRegion = ((UCHAR) value) | 0x80; 1833 - pAd->CommonCfg.CountryRegionForABand = ((UCHAR) value2) | 0x80; 1834 - TmpPhy = pAd->CommonCfg.PhyMode; 1835 - pAd->CommonCfg.PhyMode = 0xff; 1836 - RTMPSetPhyMode(pAd, TmpPhy); 1837 - SetCommonHT(pAd); 1838 - } 1839 - 1840 - // 1841 - // Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch. 1842 - // The valid value are (-10 ~ 10) 1843 - // 1844 - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value); 1845 - pAd->BGRssiOffset0 = value & 0x00ff; 1846 - pAd->BGRssiOffset1 = (value >> 8); 1847 - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET+2, value); 1848 - pAd->BGRssiOffset2 = value & 0x00ff; 1849 - pAd->ALNAGain1 = (value >> 8); 1850 - RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value); 1851 - pAd->BLNAGain = value & 0x00ff; 1852 - pAd->ALNAGain0 = (value >> 8); 1853 - 1854 - // Validate 11b/g RSSI_0 offset. 1855 - if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10)) 1856 - pAd->BGRssiOffset0 = 0; 1857 - 1858 - // Validate 11b/g RSSI_1 offset. 1859 - if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10)) 1860 - pAd->BGRssiOffset1 = 0; 1861 - 1862 - // Validate 11b/g RSSI_2 offset. 1863 - if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10)) 1864 - pAd->BGRssiOffset2 = 0; 1865 - 1866 - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value); 1867 - pAd->ARssiOffset0 = value & 0x00ff; 1868 - pAd->ARssiOffset1 = (value >> 8); 1869 - RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET+2), value); 1870 - pAd->ARssiOffset2 = value & 0x00ff; 1871 - pAd->ALNAGain2 = (value >> 8); 1872 - 1873 - if (((UCHAR)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00)) 1874 - pAd->ALNAGain1 = pAd->ALNAGain0; 1875 - if (((UCHAR)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00)) 1876 - pAd->ALNAGain2 = pAd->ALNAGain0; 1877 - 1878 - // Validate 11a RSSI_0 offset. 1879 - if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10)) 1880 - pAd->ARssiOffset0 = 0; 1881 - 1882 - // Validate 11a RSSI_1 offset. 1883 - if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10)) 1884 - pAd->ARssiOffset1 = 0; 1885 - 1886 - //Validate 11a RSSI_2 offset. 1887 - if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10)) 1888 - pAd->ARssiOffset2 = 0; 1889 - 1890 - // 1891 - // Get LED Setting. 1892 - // 1893 - RT28xx_EEPROM_READ16(pAd, 0x3a, value); 1894 - pAd->LedCntl.word = (value&0xff00) >> 8; 1895 - RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value); 1896 - pAd->Led1 = value; 1897 - RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value); 1898 - pAd->Led2 = value; 1899 - RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value); 1900 - pAd->Led3 = value; 1901 - 1902 - RTMPReadTxPwrPerRate(pAd); 1903 - 1904 - #ifdef RT30xx 1905 - if (IS_RT30xx(pAd)) 1906 - { 1907 - eFusePhysicalReadRegisters(pAd, EFUSE_TAG, 2, &value); 1908 - pAd->EFuseTag = (value & 0xff); 1909 - } 1910 - #endif // RT30xx // 1911 - 1912 - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n")); 1913 - } 1914 - 1915 - /* 1916 - ======================================================================== 1917 - 1918 - Routine Description: 1919 - Set default value from EEPROM 1920 - 1921 - Arguments: 1922 - Adapter Pointer to our adapter 1923 - 1924 - Return Value: 1925 - None 1926 - 1927 - IRQL = PASSIVE_LEVEL 1928 - 1929 - Note: 1930 - 1931 - ======================================================================== 1932 - */ 1933 - VOID NICInitAsicFromEEPROM( 1934 - IN PRTMP_ADAPTER pAd) 1935 - { 1936 - UINT32 data = 0; 1937 - UCHAR BBPR1 = 0; 1938 - USHORT i; 1939 - EEPROM_ANTENNA_STRUC Antenna; 1940 - EEPROM_NIC_CONFIG2_STRUC NicConfig2; 1941 - UCHAR BBPR3 = 0; 1942 - 1943 - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n")); 1944 - for(i = 3; i < NUM_EEPROM_BBP_PARMS; i++) 1945 - { 1946 - UCHAR BbpRegIdx, BbpValue; 1947 - 1948 - if ((pAd->EEPROMDefaultValue[i] != 0xFFFF) && (pAd->EEPROMDefaultValue[i] != 0)) 1949 - { 1950 - BbpRegIdx = (UCHAR)(pAd->EEPROMDefaultValue[i] >> 8); 1951 - BbpValue = (UCHAR)(pAd->EEPROMDefaultValue[i] & 0xff); 1952 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue); 1953 - } 1954 - } 1955 - 1956 - #ifndef RT30xx 1957 - Antenna.word = pAd->Antenna.word; 1958 - #endif 1959 - #ifdef RT30xx 1960 - Antenna.word = pAd->EEPROMDefaultValue[0]; 1961 - if (Antenna.word == 0xFFFF) 1962 - { 1963 - DBGPRINT(RT_DEBUG_ERROR, ("E2PROM error, hard code as 0x%04x\n", Antenna.word)); 1964 - BUG_ON(Antenna.word == 0xFFFF); 1965 - } 1966 - #endif 1967 - pAd->Mlme.RealRxPath = (UCHAR) Antenna.field.RxPath; 1968 - pAd->RfIcType = (UCHAR) Antenna.field.RfIcType; 1969 - 1970 - #ifdef RT30xx 1971 - DBGPRINT(RT_DEBUG_WARN, ("pAd->RfIcType = %d, RealRxPath=%d, TxPath = %d\n", pAd->RfIcType, pAd->Mlme.RealRxPath,Antenna.field.TxPath)); 1972 - 1973 - // Save the antenna for future use 1974 - pAd->Antenna.word = Antenna.word; 1975 - #endif 1976 - NicConfig2.word = pAd->EEPROMDefaultValue[1]; 1977 - 1978 - #ifdef RT30xx 1979 - { 1980 - if ((NicConfig2.word & 0x00ff) == 0xff) 1981 - { 1982 - NicConfig2.word &= 0xff00; 1983 - } 1984 - 1985 - if ((NicConfig2.word >> 8) == 0xff) 1986 - { 1987 - NicConfig2.word &= 0x00ff; 1988 - } 1989 - } 1990 - #endif 1991 - // Save the antenna for future use 1992 - pAd->NicConfig2.word = NicConfig2.word; 1993 - 1994 - #ifdef RT30xx 1995 - // set default antenna as main 1996 - if (pAd->RfIcType == RFIC_3020) 1997 - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); 1998 - #endif 1999 - // 2000 - // Send LED Setting to MCU. 2001 - // 2002 - if (pAd->LedCntl.word == 0xFF) 2003 - { 2004 - pAd->LedCntl.word = 0x01; 2005 - pAd->Led1 = 0x5555; 2006 - pAd->Led2 = 0x2221; 2007 - 2008 - #ifdef RT2870 2009 - pAd->Led3 = 0x5627; 2010 - #endif // RT2870 // 2011 - } 2012 - 2013 - AsicSendCommandToMcu(pAd, 0x52, 0xff, (UCHAR)pAd->Led1, (UCHAR)(pAd->Led1 >> 8)); 2014 - AsicSendCommandToMcu(pAd, 0x53, 0xff, (UCHAR)pAd->Led2, (UCHAR)(pAd->Led2 >> 8)); 2015 - AsicSendCommandToMcu(pAd, 0x54, 0xff, (UCHAR)pAd->Led3, (UCHAR)(pAd->Led3 >> 8)); 2016 - pAd->LedIndicatorStregth = 0xFF; 2017 - RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, before link up 2018 - 2019 - { 2020 - // Read Hardware controlled Radio state enable bit 2021 - if (NicConfig2.field.HardwareRadioControl == 1) 2022 - { 2023 - pAd->StaCfg.bHardwareRadio = TRUE; 2024 - 2025 - // Read GPIO pin2 as Hardware controlled radio state 2026 - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data); 2027 - if ((data & 0x04) == 0) 2028 - { 2029 - pAd->StaCfg.bHwRadio = FALSE; 2030 - pAd->StaCfg.bRadio = FALSE; 2031 - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); 2032 - } 2033 - } 2034 - else 2035 - pAd->StaCfg.bHardwareRadio = FALSE; 2036 - 2037 - if (pAd->StaCfg.bRadio == FALSE) 2038 - { 2039 - RTMPSetLED(pAd, LED_RADIO_OFF); 2040 - } 2041 - else 2042 - { 2043 - RTMPSetLED(pAd, LED_RADIO_ON); 2044 - } 2045 - } 2046 - 2047 - // Turn off patching for cardbus controller 2048 - if (NicConfig2.field.CardbusAcceleration == 1) 2049 - { 2050 - } 2051 - 2052 - if (NicConfig2.field.DynamicTxAgcControl == 1) 2053 - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE; 2054 - else 2055 - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE; 2056 - // 2057 - // Since BBP has been progamed, to make sure BBP setting will be 2058 - // upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND!! 2059 - // 2060 - pAd->CommonCfg.BandState = UNKNOWN_BAND; 2061 - 2062 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); 2063 - BBPR3 &= (~0x18); 2064 - if(pAd->Antenna.field.RxPath == 3) 2065 - { 2066 - BBPR3 |= (0x10); 2067 - } 2068 - else if(pAd->Antenna.field.RxPath == 2) 2069 - { 2070 - BBPR3 |= (0x8); 2071 - } 2072 - else if(pAd->Antenna.field.RxPath == 1) 2073 - { 2074 - BBPR3 |= (0x0); 2075 - } 2076 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); 2077 - 2078 - { 2079 - // Handle the difference when 1T 2080 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1); 2081 - if(pAd->Antenna.field.TxPath == 1) 2082 - { 2083 - BBPR1 &= (~0x18); 2084 - } 2085 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1); 2086 - 2087 - DBGPRINT(RT_DEBUG_TRACE, ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n", pAd->CommonCfg.bHardwareRadio, pAd->CommonCfg.bHardwareRadio)); 2088 - } 2089 - 2090 - DBGPRINT(RT_DEBUG_TRACE, ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n", pAd->Antenna.field.TxPath, pAd->Antenna.field.RxPath, pAd->RfIcType, pAd->LedCntl.word)); 2091 - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n")); 2092 - } 2093 - 2094 - /* 2095 - ======================================================================== 2096 - 2097 - Routine Description: 2098 - Initialize NIC hardware 2099 - 2100 - Arguments: 2101 - Adapter Pointer to our adapter 2102 - 2103 - Return Value: 2104 - None 2105 - 2106 - IRQL = PASSIVE_LEVEL 2107 - 2108 - Note: 2109 - 2110 - ======================================================================== 2111 - */ 2112 - NDIS_STATUS NICInitializeAdapter( 2113 - IN PRTMP_ADAPTER pAd, 2114 - IN BOOLEAN bHardReset) 2115 - { 2116 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 2117 - WPDMA_GLO_CFG_STRUC GloCfg; 2118 - ULONG i =0, j=0; 2119 - AC_TXOP_CSR0_STRUC csr0; 2120 - 2121 - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n")); 2122 - 2123 - // 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: 2124 - retry: 2125 - i = 0; 2126 - do 2127 - { 2128 - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); 2129 - if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0)) 2130 - break; 2131 - 2132 - RTMPusecDelay(1000); 2133 - i++; 2134 - }while ( i<100); 2135 - DBGPRINT(RT_DEBUG_TRACE, ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word)); 2136 - GloCfg.word &= 0xff0; 2137 - GloCfg.field.EnTXWriteBackDDONE =1; 2138 - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); 2139 - 2140 - // Record HW Beacon offset 2141 - pAd->BeaconOffset[0] = HW_BEACON_BASE0; 2142 - pAd->BeaconOffset[1] = HW_BEACON_BASE1; 2143 - pAd->BeaconOffset[2] = HW_BEACON_BASE2; 2144 - pAd->BeaconOffset[3] = HW_BEACON_BASE3; 2145 - pAd->BeaconOffset[4] = HW_BEACON_BASE4; 2146 - pAd->BeaconOffset[5] = HW_BEACON_BASE5; 2147 - pAd->BeaconOffset[6] = HW_BEACON_BASE6; 2148 - pAd->BeaconOffset[7] = HW_BEACON_BASE7; 2149 - 2150 - // 2151 - // write all shared Ring's base address into ASIC 2152 - // 2153 - 2154 - // asic simulation sequence put this ahead before loading firmware. 2155 - // pbf hardware reset 2156 - 2157 - // Initialze ASIC for TX & Rx operation 2158 - if (NICInitializeAsic(pAd , bHardReset) != NDIS_STATUS_SUCCESS) 2159 - { 2160 - if (j++ == 0) 2161 - { 2162 - NICLoadFirmware(pAd); 2163 - goto retry; 2164 - } 2165 - return NDIS_STATUS_FAILURE; 2166 - } 2167 - 2168 - 2169 - 2170 - 2171 - // WMM parameter 2172 - csr0.word = 0; 2173 - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); 2174 - if (pAd->CommonCfg.PhyMode == PHY_11B) 2175 - { 2176 - csr0.field.Ac0Txop = 192; // AC_VI: 192*32us ~= 6ms 2177 - csr0.field.Ac1Txop = 96; // AC_VO: 96*32us ~= 3ms 2178 - } 2179 - else 2180 - { 2181 - csr0.field.Ac0Txop = 96; // AC_VI: 96*32us ~= 3ms 2182 - csr0.field.Ac1Txop = 48; // AC_VO: 48*32us ~= 1.5ms 2183 - } 2184 - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word); 2185 - 2186 - 2187 - 2188 - 2189 - // reset action 2190 - // Load firmware 2191 - // Status = NICLoadFirmware(pAd); 2192 - 2193 - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n")); 2194 - return Status; 2195 - } 2196 - 2197 - /* 2198 - ======================================================================== 2199 - 2200 - Routine Description: 2201 - Initialize ASIC 2202 - 2203 - Arguments: 2204 - Adapter Pointer to our adapter 2205 - 2206 - Return Value: 2207 - None 2208 - 2209 - IRQL = PASSIVE_LEVEL 2210 - 2211 - Note: 2212 - 2213 - ======================================================================== 2214 - */ 2215 - NDIS_STATUS NICInitializeAsic( 2216 - IN PRTMP_ADAPTER pAd, 2217 - IN BOOLEAN bHardReset) 2218 - { 2219 - ULONG Index = 0; 2220 - UCHAR R0 = 0xff; 2221 - UINT32 MacCsr12 = 0, Counter = 0; 2222 - #ifdef RT2870 2223 - UINT32 MacCsr0 = 0; 2224 - NTSTATUS Status; 2225 - UCHAR Value = 0xff; 2226 - #endif // RT2870 // 2227 - #ifdef RT30xx 2228 - UINT32 eFuseCtrl; 2229 - #endif // RT30xx // 2230 - USHORT KeyIdx; 2231 - INT i,apidx; 2232 - 2233 - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n")); 2234 - 2235 - 2236 - #ifdef RT2870 2237 - // 2238 - // Make sure MAC gets ready after NICLoadFirmware(). 2239 - // 2240 - Index = 0; 2241 - 2242 - //To avoid hang-on issue when interface up in kernel 2.4, 2243 - //we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly. 2244 - do 2245 - { 2246 - RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); 2247 - 2248 - if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) 2249 - break; 2250 - 2251 - RTMPusecDelay(10); 2252 - } while (Index++ < 100); 2253 - 2254 - pAd->MACVersion = MacCsr0; 2255 - DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion)); 2256 - // turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue. 2257 - RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12); 2258 - MacCsr12 &= (~0x2000); 2259 - RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12); 2260 - 2261 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3); 2262 - RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0); 2263 - Status = RTUSBVenderReset(pAd); 2264 - 2265 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0); 2266 - 2267 - // Initialize MAC register to default value 2268 - for(Index=0; Index<NUM_MAC_REG_PARMS; Index++) 2269 - { 2270 - #ifdef RT3070 2271 - if ((MACRegTable[Index].Register == TX_SW_CFG0) && (IS_RT3070(pAd) || IS_RT3071(pAd))) 2272 - { 2273 - MACRegTable[Index].Value = 0x00000400; 2274 - } 2275 - #endif // RT3070 // 2276 - RTMP_IO_WRITE32(pAd, (USHORT)MACRegTable[Index].Register, MACRegTable[Index].Value); 2277 - } 2278 - 2279 - #ifndef RT30xx 2280 - if(IS_RT3070(pAd)) 2281 - { 2282 - // According to Frank Hsu (from Gary Tsao) 2283 - RTMP_IO_WRITE32(pAd, (USHORT)TX_SW_CFG0, 0x00000400); 2284 - 2285 - // Initialize RT3070 serial MAC registers which is different from RT2870 serial 2286 - RTUSBWriteMACRegister(pAd, TX_SW_CFG1, 0); 2287 - RTUSBWriteMACRegister(pAd, TX_SW_CFG2, 0); 2288 - } 2289 - #endif 2290 - 2291 - { 2292 - for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) 2293 - { 2294 - RTMP_IO_WRITE32(pAd, (USHORT)STAMACRegTable[Index].Register, STAMACRegTable[Index].Value); 2295 - } 2296 - } 2297 - #endif // RT2870 // 2298 - 2299 - #ifdef RT30xx 2300 - // Initialize RT3070 serial MAc registers which is different from RT2870 serial 2301 - if (IS_RT3090(pAd)) 2302 - { 2303 - RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0); 2304 - 2305 - // RT3071 version E has fixed this issue 2306 - if ((pAd->MACVersion & 0xffff) < 0x0211) 2307 - { 2308 - if (pAd->NicConfig2.field.DACTestBit == 1) 2309 - { 2310 - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x1F); // To fix throughput drop drastically 2311 - } 2312 - else 2313 - { 2314 - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0F); // To fix throughput drop drastically 2315 - } 2316 - } 2317 - else 2318 - { 2319 - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0); 2320 - } 2321 - } 2322 - else if (IS_RT3070(pAd)) 2323 - { 2324 - RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0); 2325 - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x1F); // To fix throughput drop drastically 2326 - } 2327 - #endif // RT30xx // 2328 - 2329 - // 2330 - // Before program BBP, we need to wait BBP/RF get wake up. 2331 - // 2332 - Index = 0; 2333 - do 2334 - { 2335 - RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12); 2336 - 2337 - if ((MacCsr12 & 0x03) == 0) // if BB.RF is stable 2338 - break; 2339 - 2340 - DBGPRINT(RT_DEBUG_TRACE, ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12)); 2341 - RTMPusecDelay(1000); 2342 - } while (Index++ < 100); 2343 - 2344 - // The commands to firmware should be after these commands, these commands will init firmware 2345 - // PCI and USB are not the same because PCI driver needs to wait for PCI bus ready 2346 - RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); // initialize BBP R/W access agent 2347 - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0); 2348 - RTMPusecDelay(1000); 2349 - 2350 - // Read BBP register, make sure BBP is up and running before write new data 2351 - Index = 0; 2352 - do 2353 - { 2354 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0); 2355 - DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0)); 2356 - } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00))); 2357 - //ASSERT(Index < 20); //this will cause BSOD on Check-build driver 2358 - 2359 - if ((R0 == 0xff) || (R0 == 0x00)) 2360 - return NDIS_STATUS_FAILURE; 2361 - 2362 - // Initialize BBP register to default value 2363 - for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++) 2364 - { 2365 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, BBPRegTable[Index].Value); 2366 - } 2367 - 2368 - #ifndef RT30xx 2369 - // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT. 2370 - if ((pAd->MACVersion&0xffff) != 0x0101) 2371 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19); 2372 - 2373 - #ifdef RT2870 2374 - //write RT3070 BBP wchich different with 2870 after write RT2870 BBP 2375 - if (IS_RT3070(pAd)) 2376 - { 2377 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0a); 2378 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x99); 2379 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R105, 0x05); 2380 - } 2381 - #endif // RT2870 // 2382 - #endif 2383 - #ifdef RT30xx 2384 - // for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT. 2385 - // RT3090 should not program BBP R84 to 0x19, otherwise TX will block. 2386 - if (((pAd->MACVersion&0xffff) != 0x0101) && (!IS_RT30xx(pAd))) 2387 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19); 2388 - 2389 - // add by johnli, RF power sequence setup 2390 - if (IS_RT30xx(pAd)) 2391 - { //update for RT3070/71/72/90/91/92. 2392 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R79, 0x13); 2393 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R80, 0x05); 2394 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R81, 0x33); 2395 - } 2396 - 2397 - if (IS_RT3090(pAd)) 2398 - { 2399 - UCHAR bbpreg=0; 2400 - 2401 - // enable DC filter 2402 - if ((pAd->MACVersion & 0xffff) >= 0x0211) 2403 - { 2404 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0); 2405 - } 2406 - 2407 - // improve power consumption 2408 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R138, &bbpreg); 2409 - if (pAd->Antenna.field.TxPath == 1) 2410 - { 2411 - // turn off tx DAC_1 2412 - bbpreg = (bbpreg | 0x20); 2413 - } 2414 - 2415 - if (pAd->Antenna.field.RxPath == 1) 2416 - { 2417 - // turn off tx ADC_1 2418 - bbpreg &= (~0x2); 2419 - } 2420 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R138, bbpreg); 2421 - 2422 - // improve power consumption in RT3071 Ver.E 2423 - if ((pAd->MACVersion & 0xffff) >= 0x0211) 2424 - { 2425 - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg); 2426 - bbpreg &= (~0x3); 2427 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg); 2428 - } 2429 - } 2430 - #endif 2431 - if (pAd->MACVersion == 0x28600100) 2432 - { 2433 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16); 2434 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12); 2435 - } 2436 - 2437 - if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) // 3*3 2438 - { 2439 - // enlarge MAX_LEN_CFG 2440 - UINT32 csr; 2441 - RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr); 2442 - csr &= 0xFFF; 2443 - csr |= 0x2000; 2444 - RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr); 2445 - } 2446 - 2447 - #ifdef RT2870 2448 - { 2449 - UCHAR MAC_Value[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0}; 2450 - 2451 - //Initialize WCID table 2452 - Value = 0xff; 2453 - for(Index =0 ;Index < 254;Index++) 2454 - { 2455 - RTUSBMultiWrite(pAd, (USHORT)(MAC_WCID_BASE + Index * 8), MAC_Value, 8); 2456 - } 2457 - } 2458 - #endif // RT2870 // 2459 - 2460 - // Add radio off control 2461 - { 2462 - if (pAd->StaCfg.bRadio == FALSE) 2463 - { 2464 - // RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); 2465 - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); 2466 - DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n")); 2467 - } 2468 - } 2469 - 2470 - // Clear raw counters 2471 - RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter); 2472 - RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter); 2473 - RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter); 2474 - RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter); 2475 - RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter); 2476 - RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter); 2477 - 2478 - // ASIC will keep garbage value after boot 2479 - // Clear all seared key table when initial 2480 - // This routine can be ignored in radio-ON/OFF operation. 2481 - if (bHardReset) 2482 - { 2483 - for (KeyIdx = 0; KeyIdx < 4; KeyIdx++) 2484 - { 2485 - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4*KeyIdx, 0); 2486 - } 2487 - 2488 - // Clear all pairwise key table when initial 2489 - for (KeyIdx = 0; KeyIdx < 256; KeyIdx++) 2490 - { 2491 - RTMP_IO_WRITE32(pAd, MAC_WCID_ATTRIBUTE_BASE + (KeyIdx * HW_WCID_ATTRI_SIZE), 1); 2492 - } 2493 - } 2494 - 2495 - // It isn't necessary to clear this space when not hard reset. 2496 - if (bHardReset == TRUE) 2497 - { 2498 - // clear all on-chip BEACON frame space 2499 - for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++) 2500 - { 2501 - for (i = 0; i < HW_BEACON_OFFSET>>2; i+=4) 2502 - RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[apidx] + i, 0x00); 2503 - } 2504 - } 2505 - #ifdef RT2870 2506 - AsicDisableSync(pAd); 2507 - // Clear raw counters 2508 - RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter); 2509 - RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter); 2510 - RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter); 2511 - RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter); 2512 - RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter); 2513 - RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter); 2514 - // Default PCI clock cycle per ms is different as default setting, which is based on PCI. 2515 - RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter); 2516 - Counter&=0xffffff00; 2517 - Counter|=0x000001e; 2518 - RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter); 2519 - #endif // RT2870 // 2520 - #ifdef RT30xx 2521 - pAd->bUseEfuse=FALSE; 2522 - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrl); 2523 - pAd->bUseEfuse = ( (eFuseCtrl & 0x80000000) == 0x80000000) ? 1 : 0; 2524 - if(pAd->bUseEfuse) 2525 - { 2526 - DBGPRINT(RT_DEBUG_TRACE, ("NVM is Efuse\n")); 2527 - } 2528 - else 2529 - { 2530 - DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n")); 2531 - 2532 - } 2533 - #endif // RT30xx // 2534 - 2535 - { 2536 - // for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT. 2537 - if ((pAd->MACVersion&0xffff) != 0x0101) 2538 - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f); 2539 - } 2540 - 2541 - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n")); 2542 - return NDIS_STATUS_SUCCESS; 2543 - } 2544 - 2545 - /* 2546 - ======================================================================== 2547 - 2548 - Routine Description: 2549 - Reset NIC Asics 2550 - 2551 - Arguments: 2552 - Adapter Pointer to our adapter 2553 - 2554 - Return Value: 2555 - None 2556 - 2557 - IRQL = PASSIVE_LEVEL 2558 - 2559 - Note: 2560 - Reset NIC to initial state AS IS system boot up time. 2561 - 2562 - ======================================================================== 2563 - */ 2564 - VOID NICIssueReset( 2565 - IN PRTMP_ADAPTER pAd) 2566 - { 2567 - UINT32 Value = 0; 2568 - DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n")); 2569 - 2570 - // Disable Rx, register value supposed will remain after reset 2571 - RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value); 2572 - Value &= (0xfffffff3); 2573 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value); 2574 - 2575 - // Issue reset and clear from reset state 2576 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); // 2004-09-17 change from 0x01 2577 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00); 2578 - 2579 - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n")); 2580 - } 2581 - 2582 - /* 2583 - ======================================================================== 2584 - 2585 - Routine Description: 2586 - Check ASIC registers and find any reason the system might hang 2587 - 2588 - Arguments: 2589 - Adapter Pointer to our adapter 2590 - 2591 - Return Value: 2592 - None 2593 - 2594 - IRQL = DISPATCH_LEVEL 2595 - 2596 - ======================================================================== 2597 - */ 2598 - BOOLEAN NICCheckForHang( 2599 - IN PRTMP_ADAPTER pAd) 2600 - { 2601 - return (FALSE); 2602 - } 2603 - 2604 - VOID NICUpdateFifoStaCounters( 2605 - IN PRTMP_ADAPTER pAd) 2606 - { 2607 - TX_STA_FIFO_STRUC StaFifo; 2608 - MAC_TABLE_ENTRY *pEntry; 2609 - UCHAR i = 0; 2610 - UCHAR pid = 0, wcid = 0; 2611 - CHAR reTry; 2612 - UCHAR succMCS; 2613 - 2614 - do 2615 - { 2616 - RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word); 2617 - 2618 - if (StaFifo.field.bValid == 0) 2619 - break; 2620 - 2621 - wcid = (UCHAR)StaFifo.field.wcid; 2622 - 2623 - 2624 - /* ignore NoACK and MGMT frame use 0xFF as WCID */ 2625 - if ((StaFifo.field.TxAckRequired == 0) || (wcid >= MAX_LEN_OF_MAC_TABLE)) 2626 - { 2627 - i++; 2628 - continue; 2629 - } 2630 - 2631 - /* PID store Tx MCS Rate */ 2632 - pid = (UCHAR)StaFifo.field.PidType; 2633 - 2634 - pEntry = &pAd->MacTab.Content[wcid]; 2635 - 2636 - pEntry->DebugFIFOCount++; 2637 - 2638 - if (StaFifo.field.TxBF) // 3*3 2639 - pEntry->TxBFCount++; 2640 - 2641 - #ifdef UAPSD_AP_SUPPORT 2642 - UAPSD_SP_AUE_Handle(pAd, pEntry, StaFifo.field.TxSuccess); 2643 - #endif // UAPSD_AP_SUPPORT // 2644 - 2645 - if (!StaFifo.field.TxSuccess) 2646 - { 2647 - pEntry->FIFOCount++; 2648 - pEntry->OneSecTxFailCount++; 2649 - 2650 - if (pEntry->FIFOCount >= 1) 2651 - { 2652 - DBGPRINT(RT_DEBUG_TRACE, ("#")); 2653 - pEntry->NoBADataCountDown = 64; 2654 - 2655 - if(pEntry->PsMode == PWR_ACTIVE) 2656 - { 2657 - int tid; 2658 - for (tid=0; tid<NUM_OF_TID; tid++) 2659 - { 2660 - BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, FALSE); 2661 - } 2662 - 2663 - // Update the continuous transmission counter except PS mode 2664 - pEntry->ContinueTxFailCnt++; 2665 - } 2666 - else 2667 - { 2668 - // Clear the FIFOCount when sta in Power Save mode. Basically we assume 2669 - // this tx error happened due to sta just go to sleep. 2670 - pEntry->FIFOCount = 0; 2671 - pEntry->ContinueTxFailCnt = 0; 2672 - } 2673 - } 2674 - } 2675 - else 2676 - { 2677 - if ((pEntry->PsMode != PWR_SAVE) && (pEntry->NoBADataCountDown > 0)) 2678 - { 2679 - pEntry->NoBADataCountDown--; 2680 - if (pEntry->NoBADataCountDown==0) 2681 - { 2682 - DBGPRINT(RT_DEBUG_TRACE, ("@\n")); 2683 - } 2684 - } 2685 - 2686 - pEntry->FIFOCount = 0; 2687 - pEntry->OneSecTxNoRetryOkCount++; 2688 - // update NoDataIdleCount when sucessful send packet to STA. 2689 - pEntry->NoDataIdleCount = 0; 2690 - pEntry->ContinueTxFailCnt = 0; 2691 - } 2692 - 2693 - succMCS = StaFifo.field.SuccessRate & 0x7F; 2694 - 2695 - reTry = pid - succMCS; 2696 - 2697 - if (StaFifo.field.TxSuccess) 2698 - { 2699 - pEntry->TXMCSExpected[pid]++; 2700 - if (pid == succMCS) 2701 - { 2702 - pEntry->TXMCSSuccessful[pid]++; 2703 - } 2704 - else 2705 - { 2706 - pEntry->TXMCSAutoFallBack[pid][succMCS]++; 2707 - } 2708 - } 2709 - else 2710 - { 2711 - pEntry->TXMCSFailed[pid]++; 2712 - } 2713 - 2714 - if (reTry > 0) 2715 - { 2716 - if ((pid >= 12) && succMCS <=7) 2717 - { 2718 - reTry -= 4; 2719 - } 2720 - pEntry->OneSecTxRetryOkCount += reTry; 2721 - } 2722 - 2723 - i++; 2724 - // ASIC store 16 stack 2725 - } while ( i < (2*TX_RING_SIZE) ); 2726 - 2727 - } 2728 - 2729 - /* 2730 - ======================================================================== 2731 - 2732 - Routine Description: 2733 - Read statistical counters from hardware registers and record them 2734 - in software variables for later on query 2735 - 2736 - Arguments: 2737 - pAd Pointer to our adapter 2738 - 2739 - Return Value: 2740 - None 2741 - 2742 - IRQL = DISPATCH_LEVEL 2743 - 2744 - ======================================================================== 2745 - */ 2746 - VOID NICUpdateRawCounters( 2747 - IN PRTMP_ADAPTER pAd) 2748 - { 2749 - UINT32 OldValue; 2750 - RX_STA_CNT0_STRUC RxStaCnt0; 2751 - RX_STA_CNT1_STRUC RxStaCnt1; 2752 - RX_STA_CNT2_STRUC RxStaCnt2; 2753 - TX_STA_CNT0_STRUC TxStaCnt0; 2754 - TX_STA_CNT1_STRUC StaTx1; 2755 - TX_STA_CNT2_STRUC StaTx2; 2756 - TX_AGG_CNT_STRUC TxAggCnt; 2757 - TX_AGG_CNT0_STRUC TxAggCnt0; 2758 - TX_AGG_CNT1_STRUC TxAggCnt1; 2759 - TX_AGG_CNT2_STRUC TxAggCnt2; 2760 - TX_AGG_CNT3_STRUC TxAggCnt3; 2761 - TX_AGG_CNT4_STRUC TxAggCnt4; 2762 - TX_AGG_CNT5_STRUC TxAggCnt5; 2763 - TX_AGG_CNT6_STRUC TxAggCnt6; 2764 - TX_AGG_CNT7_STRUC TxAggCnt7; 2765 - 2766 - 2767 - RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word); 2768 - RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word); 2769 - 2770 - { 2771 - RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word); 2772 - // Update RX PLCP error counter 2773 - pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr; 2774 - // Update False CCA counter 2775 - pAd->RalinkCounters.OneSecFalseCCACnt += RxStaCnt1.field.FalseCca; 2776 - } 2777 - 2778 - // Update FCS counters 2779 - OldValue= pAd->WlanCounters.FCSErrorCount.u.LowPart; 2780 - pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); // >> 7); 2781 - if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue) 2782 - pAd->WlanCounters.FCSErrorCount.u.HighPart++; 2783 - 2784 - // Add FCS error count to private counters 2785 - pAd->RalinkCounters.OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr; 2786 - OldValue = pAd->RalinkCounters.RealFcsErrCount.u.LowPart; 2787 - pAd->RalinkCounters.RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr; 2788 - if (pAd->RalinkCounters.RealFcsErrCount.u.LowPart < OldValue) 2789 - pAd->RalinkCounters.RealFcsErrCount.u.HighPart++; 2790 - 2791 - // Update Duplicate Rcv check 2792 - pAd->RalinkCounters.DuplicateRcv += RxStaCnt2.field.RxDupliCount; 2793 - pAd->WlanCounters.FrameDuplicateCount.u.LowPart += RxStaCnt2.field.RxDupliCount; 2794 - // Update RX Overflow counter 2795 - pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount); 2796 - 2797 - #ifdef RT2870 2798 - if (pAd->RalinkCounters.RxCount != pAd->watchDogRxCnt) 2799 - { 2800 - pAd->watchDogRxCnt = pAd->RalinkCounters.RxCount; 2801 - pAd->watchDogRxOverFlowCnt = 0; 2802 - } 2803 - else 2804 - { 2805 - if (RxStaCnt2.field.RxFifoOverflowCount) 2806 - pAd->watchDogRxOverFlowCnt++; 2807 - else 2808 - pAd->watchDogRxOverFlowCnt = 0; 2809 - } 2810 - #endif // RT2870 // 2811 - 2812 - 2813 - if (!pAd->bUpdateBcnCntDone) 2814 - { 2815 - // Update BEACON sent count 2816 - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); 2817 - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); 2818 - RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word); 2819 - pAd->RalinkCounters.OneSecBeaconSentCnt += TxStaCnt0.field.TxBeaconCount; 2820 - pAd->RalinkCounters.OneSecTxRetryOkCount += StaTx1.field.TxRetransmit; 2821 - pAd->RalinkCounters.OneSecTxNoRetryOkCount += StaTx1.field.TxSuccess; 2822 - pAd->RalinkCounters.OneSecTxFailCount += TxStaCnt0.field.TxFailCount; 2823 - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += StaTx1.field.TxSuccess; 2824 - pAd->WlanCounters.RetryCount.u.LowPart += StaTx1.field.TxRetransmit; 2825 - pAd->WlanCounters.FailedCount.u.LowPart += TxStaCnt0.field.TxFailCount; 2826 - } 2827 - 2828 - { 2829 - RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word); 2830 - RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word); 2831 - RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word); 2832 - RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word); 2833 - RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word); 2834 - RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word); 2835 - RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word); 2836 - RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word); 2837 - RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word); 2838 - pAd->RalinkCounters.TxAggCount += TxAggCnt.field.AggTxCount; 2839 - pAd->RalinkCounters.TxNonAggCount += TxAggCnt.field.NonAggTxCount; 2840 - pAd->RalinkCounters.TxAgg1MPDUCount += TxAggCnt0.field.AggSize1Count; 2841 - pAd->RalinkCounters.TxAgg2MPDUCount += TxAggCnt0.field.AggSize2Count; 2842 - 2843 - pAd->RalinkCounters.TxAgg3MPDUCount += TxAggCnt1.field.AggSize3Count; 2844 - pAd->RalinkCounters.TxAgg4MPDUCount += TxAggCnt1.field.AggSize4Count; 2845 - pAd->RalinkCounters.TxAgg5MPDUCount += TxAggCnt2.field.AggSize5Count; 2846 - pAd->RalinkCounters.TxAgg6MPDUCount += TxAggCnt2.field.AggSize6Count; 2847 - 2848 - pAd->RalinkCounters.TxAgg7MPDUCount += TxAggCnt3.field.AggSize7Count; 2849 - pAd->RalinkCounters.TxAgg8MPDUCount += TxAggCnt3.field.AggSize8Count; 2850 - pAd->RalinkCounters.TxAgg9MPDUCount += TxAggCnt4.field.AggSize9Count; 2851 - pAd->RalinkCounters.TxAgg10MPDUCount += TxAggCnt4.field.AggSize10Count; 2852 - 2853 - pAd->RalinkCounters.TxAgg11MPDUCount += TxAggCnt5.field.AggSize11Count; 2854 - pAd->RalinkCounters.TxAgg12MPDUCount += TxAggCnt5.field.AggSize12Count; 2855 - pAd->RalinkCounters.TxAgg13MPDUCount += TxAggCnt6.field.AggSize13Count; 2856 - pAd->RalinkCounters.TxAgg14MPDUCount += TxAggCnt6.field.AggSize14Count; 2857 - 2858 - pAd->RalinkCounters.TxAgg15MPDUCount += TxAggCnt7.field.AggSize15Count; 2859 - pAd->RalinkCounters.TxAgg16MPDUCount += TxAggCnt7.field.AggSize16Count; 2860 - 2861 - // Calculate the transmitted A-MPDU count 2862 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += TxAggCnt0.field.AggSize1Count; 2863 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt0.field.AggSize2Count / 2); 2864 - 2865 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize3Count / 3); 2866 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt1.field.AggSize4Count / 4); 2867 - 2868 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize5Count / 5); 2869 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt2.field.AggSize6Count / 6); 2870 - 2871 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize7Count / 7); 2872 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt3.field.AggSize8Count / 8); 2873 - 2874 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize9Count / 9); 2875 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt4.field.AggSize10Count / 10); 2876 - 2877 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize11Count / 11); 2878 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt5.field.AggSize12Count / 12); 2879 - 2880 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize13Count / 13); 2881 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt6.field.AggSize14Count / 14); 2882 - 2883 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize15Count / 15); 2884 - pAd->RalinkCounters.TransmittedAMPDUCount.u.LowPart += (TxAggCnt7.field.AggSize16Count / 16); 2885 - } 2886 - 2887 - #ifdef DBG_DIAGNOSE 2888 - { 2889 - RtmpDiagStruct *pDiag; 2890 - COUNTER_RALINK *pRalinkCounters; 2891 - UCHAR ArrayCurIdx, i; 2892 - 2893 - pDiag = &pAd->DiagStruct; 2894 - pRalinkCounters = &pAd->RalinkCounters; 2895 - ArrayCurIdx = pDiag->ArrayCurIdx; 2896 - 2897 - if (pDiag->inited == 0) 2898 - { 2899 - NdisZeroMemory(pDiag, sizeof(struct _RtmpDiagStrcut_)); 2900 - pDiag->ArrayStartIdx = pDiag->ArrayCurIdx = 0; 2901 - pDiag->inited = 1; 2902 - } 2903 - else 2904 - { 2905 - // Tx 2906 - pDiag->TxFailCnt[ArrayCurIdx] = TxStaCnt0.field.TxFailCount; 2907 - pDiag->TxAggCnt[ArrayCurIdx] = TxAggCnt.field.AggTxCount; 2908 - pDiag->TxNonAggCnt[ArrayCurIdx] = TxAggCnt.field.NonAggTxCount; 2909 - pDiag->TxAMPDUCnt[ArrayCurIdx][0] = TxAggCnt0.field.AggSize1Count; 2910 - pDiag->TxAMPDUCnt[ArrayCurIdx][1] = TxAggCnt0.field.AggSize2Count; 2911 - pDiag->TxAMPDUCnt[ArrayCurIdx][2] = TxAggCnt1.field.AggSize3Count; 2912 - pDiag->TxAMPDUCnt[ArrayCurIdx][3] = TxAggCnt1.field.AggSize4Count; 2913 - pDiag->TxAMPDUCnt[ArrayCurIdx][4] = TxAggCnt2.field.AggSize5Count; 2914 - pDiag->TxAMPDUCnt[ArrayCurIdx][5] = TxAggCnt2.field.AggSize6Count; 2915 - pDiag->TxAMPDUCnt[ArrayCurIdx][6] = TxAggCnt3.field.AggSize7Count; 2916 - pDiag->TxAMPDUCnt[ArrayCurIdx][7] = TxAggCnt3.field.AggSize8Count; 2917 - pDiag->TxAMPDUCnt[ArrayCurIdx][8] = TxAggCnt4.field.AggSize9Count; 2918 - pDiag->TxAMPDUCnt[ArrayCurIdx][9] = TxAggCnt4.field.AggSize10Count; 2919 - pDiag->TxAMPDUCnt[ArrayCurIdx][10] = TxAggCnt5.field.AggSize11Count; 2920 - pDiag->TxAMPDUCnt[ArrayCurIdx][11] = TxAggCnt5.field.AggSize12Count; 2921 - pDiag->TxAMPDUCnt[ArrayCurIdx][12] = TxAggCnt6.field.AggSize13Count; 2922 - pDiag->TxAMPDUCnt[ArrayCurIdx][13] = TxAggCnt6.field.AggSize14Count; 2923 - pDiag->TxAMPDUCnt[ArrayCurIdx][14] = TxAggCnt7.field.AggSize15Count; 2924 - pDiag->TxAMPDUCnt[ArrayCurIdx][15] = TxAggCnt7.field.AggSize16Count; 2925 - 2926 - pDiag->RxCrcErrCnt[ArrayCurIdx] = RxStaCnt0.field.CrcErr; 2927 - 2928 - INC_RING_INDEX(pDiag->ArrayCurIdx, DIAGNOSE_TIME); 2929 - ArrayCurIdx = pDiag->ArrayCurIdx; 2930 - for (i =0; i < 9; i++) 2931 - { 2932 - pDiag->TxDescCnt[ArrayCurIdx][i]= 0; 2933 - pDiag->TxSWQueCnt[ArrayCurIdx][i] =0; 2934 - pDiag->TxMcsCnt[ArrayCurIdx][i] = 0; 2935 - pDiag->RxMcsCnt[ArrayCurIdx][i] = 0; 2936 - } 2937 - pDiag->TxDataCnt[ArrayCurIdx] = 0; 2938 - pDiag->TxFailCnt[ArrayCurIdx] = 0; 2939 - pDiag->RxDataCnt[ArrayCurIdx] = 0; 2940 - pDiag->RxCrcErrCnt[ArrayCurIdx] = 0; 2941 - 2942 - for (i = 9; i < 24; i++) // 3*3 2943 - { 2944 - pDiag->TxDescCnt[ArrayCurIdx][i] = 0; 2945 - pDiag->TxMcsCnt[ArrayCurIdx][i] = 0; 2946 - pDiag->RxMcsCnt[ArrayCurIdx][i] = 0; 2947 - } 2948 - 2949 - if (pDiag->ArrayCurIdx == pDiag->ArrayStartIdx) 2950 - INC_RING_INDEX(pDiag->ArrayStartIdx, DIAGNOSE_TIME); 2951 - } 2952 - 2953 - } 2954 - #endif // DBG_DIAGNOSE // 2955 - 2956 - 2957 - } 2958 - 2959 - 2960 - /* 2961 - ======================================================================== 2962 - 2963 - Routine Description: 2964 - Reset NIC from error 2965 - 2966 - Arguments: 2967 - Adapter Pointer to our adapter 2968 - 2969 - Return Value: 2970 - None 2971 - 2972 - IRQL = PASSIVE_LEVEL 2973 - 2974 - Note: 2975 - Reset NIC from error state 2976 - 2977 - ======================================================================== 2978 - */ 2979 - VOID NICResetFromError( 2980 - IN PRTMP_ADAPTER pAd) 2981 - { 2982 - // Reset BBP (according to alex, reset ASIC will force reset BBP 2983 - // Therefore, skip the reset BBP 2984 - // RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2); 2985 - 2986 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); 2987 - // Remove ASIC from reset state 2988 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0); 2989 - 2990 - NICInitializeAdapter(pAd, FALSE); 2991 - NICInitAsicFromEEPROM(pAd); 2992 - 2993 - // Switch to current channel, since during reset process, the connection should remains on. 2994 - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); 2995 - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); 2996 - } 2997 - 2998 - /* 2999 - ======================================================================== 3000 - 3001 - Routine Description: 3002 - erase 8051 firmware image in MAC ASIC 3003 - 3004 - Arguments: 3005 - Adapter Pointer to our adapter 3006 - 3007 - IRQL = PASSIVE_LEVEL 3008 - 3009 - ======================================================================== 3010 - */ 3011 - VOID NICEraseFirmware( 3012 - IN PRTMP_ADAPTER pAd) 3013 - { 3014 - ULONG i; 3015 - 3016 - for(i=0; i<MAX_FIRMWARE_IMAGE_SIZE; i+=4) 3017 - RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, 0); 3018 - 3019 - }/* End of NICEraseFirmware */ 3020 - 3021 - /* 3022 - ======================================================================== 3023 - 3024 - Routine Description: 3025 - Load 8051 firmware RT2561.BIN file into MAC ASIC 3026 - 3027 - Arguments: 3028 - Adapter Pointer to our adapter 3029 - 3030 - Return Value: 3031 - NDIS_STATUS_SUCCESS firmware image load ok 3032 - NDIS_STATUS_FAILURE image not found 3033 - 3034 - IRQL = PASSIVE_LEVEL 3035 - 3036 - ======================================================================== 3037 - */ 3038 - NDIS_STATUS NICLoadFirmware( 3039 - IN PRTMP_ADAPTER pAd) 3040 - { 3041 - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 3042 - PUCHAR pFirmwareImage; 3043 - ULONG FileLength, Index; 3044 - //ULONG firm; 3045 - UINT32 MacReg = 0; 3046 - UINT32 Version = (pAd->MACVersion >> 16); 3047 - 3048 - pFirmwareImage = FirmwareImage; 3049 - FileLength = sizeof(FirmwareImage); 3050 - 3051 - // New 8k byte firmware size for RT3071/RT3072 3052 - //printk("Usb Chip\n"); 3053 - if (FIRMWAREIMAGE_LENGTH == FIRMWAREIMAGE_MAX_LENGTH) 3054 - //The firmware image consists of two parts. One is the origianl and the other is the new. 3055 - //Use Second Part 3056 - { 3057 - #ifdef RT2870 3058 - if ((Version != 0x2860) && (Version != 0x2872) && (Version != 0x3070)) 3059 - { // Use Firmware V2. 3060 - //printk("KH:Use New Version,part2\n"); 3061 - pFirmwareImage = (PUCHAR)&FirmwareImage[FIRMWAREIMAGEV1_LENGTH]; 3062 - FileLength = FIRMWAREIMAGEV2_LENGTH; 3063 - } 3064 - else 3065 - { 3066 - //printk("KH:Use New Version,part1\n"); 3067 - pFirmwareImage = FirmwareImage; 3068 - FileLength = FIRMWAREIMAGEV1_LENGTH; 3069 - } 3070 - #endif // RT2870 // 3071 - } 3072 - else 3073 - { 3074 - DBGPRINT(RT_DEBUG_ERROR, ("KH: bin file should be 8KB.\n")); 3075 - Status = NDIS_STATUS_FAILURE; 3076 - } 3077 - 3078 - RT28XX_WRITE_FIRMWARE(pAd, pFirmwareImage, FileLength); 3079 - 3080 - /* check if MCU is ready */ 3081 - Index = 0; 3082 - do 3083 - { 3084 - RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacReg); 3085 - 3086 - if (MacReg & 0x80) 3087 - break; 3088 - 3089 - RTMPusecDelay(1000); 3090 - } while (Index++ < 1000); 3091 - 3092 - if (Index >= 1000) 3093 - { 3094 - Status = NDIS_STATUS_FAILURE; 3095 - DBGPRINT(RT_DEBUG_ERROR, ("NICLoadFirmware: MCU is not ready\n\n\n")); 3096 - } /* End of if */ 3097 - 3098 - DBGPRINT(RT_DEBUG_TRACE, 3099 - ("<=== %s (status=%d)\n", __func__, Status)); 3100 - 3101 - return Status; 3102 - } /* End of NICLoadFirmware */ 3103 - 3104 - 3105 - /* 3106 - ======================================================================== 3107 - 3108 - Routine Description: 3109 - Load Tx rate switching parameters 3110 - 3111 - Arguments: 3112 - Adapter Pointer to our adapter 3113 - 3114 - Return Value: 3115 - NDIS_STATUS_SUCCESS firmware image load ok 3116 - NDIS_STATUS_FAILURE image not found 3117 - 3118 - IRQL = PASSIVE_LEVEL 3119 - 3120 - Rate Table Format: 3121 - 1. (B0: Valid Item number) (B1:Initial item from zero) 3122 - 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec) 3123 - 3124 - ======================================================================== 3125 - */ 3126 - NDIS_STATUS NICLoadRateSwitchingParams( 3127 - IN PRTMP_ADAPTER pAd) 3128 - { 3129 - return NDIS_STATUS_SUCCESS; 3130 - } 3131 - 3132 - /* 3133 - ======================================================================== 3134 - 3135 - Routine Description: 3136 - if pSrc1 all zero with length Length, return 0. 3137 - If not all zero, return 1 3138 - 3139 - Arguments: 3140 - pSrc1 3141 - 3142 - Return Value: 3143 - 1: not all zero 3144 - 0: all zero 3145 - 3146 - IRQL = DISPATCH_LEVEL 3147 - 3148 - Note: 3149 - 3150 - ======================================================================== 3151 - */ 3152 - ULONG RTMPNotAllZero( 3153 - IN PVOID pSrc1, 3154 - IN ULONG Length) 3155 - { 3156 - PUCHAR pMem1; 3157 - ULONG Index = 0; 3158 - 3159 - pMem1 = (PUCHAR) pSrc1; 3160 - 3161 - for (Index = 0; Index < Length; Index++) 3162 - { 3163 - if (pMem1[Index] != 0x0) 3164 - { 3165 - break; 3166 - } 3167 - } 3168 - 3169 - if (Index == Length) 3170 - { 3171 - return (0); 3172 - } 3173 - else 3174 - { 3175 - return (1); 3176 - } 3177 - } 3178 - 3179 - /* 3180 - ======================================================================== 3181 - 3182 - Routine Description: 3183 - Compare two memory block 3184 - 3185 - Arguments: 3186 - pSrc1 Pointer to first memory address 3187 - pSrc2 Pointer to second memory address 3188 - 3189 - Return Value: 3190 - 0: memory is equal 3191 - 1: pSrc1 memory is larger 3192 - 2: pSrc2 memory is larger 3193 - 3194 - IRQL = DISPATCH_LEVEL 3195 - 3196 - Note: 3197 - 3198 - ======================================================================== 3199 - */ 3200 - ULONG RTMPCompareMemory( 3201 - IN PVOID pSrc1, 3202 - IN PVOID pSrc2, 3203 - IN ULONG Length) 3204 - { 3205 - PUCHAR pMem1; 3206 - PUCHAR pMem2; 3207 - ULONG Index = 0; 3208 - 3209 - pMem1 = (PUCHAR) pSrc1; 3210 - pMem2 = (PUCHAR) pSrc2; 3211 - 3212 - for (Index = 0; Index < Length; Index++) 3213 - { 3214 - if (pMem1[Index] > pMem2[Index]) 3215 - return (1); 3216 - else if (pMem1[Index] < pMem2[Index]) 3217 - return (2); 3218 - } 3219 - 3220 - // Equal 3221 - return (0); 3222 - } 3223 - 3224 - /* 3225 - ======================================================================== 3226 - 3227 - Routine Description: 3228 - Zero out memory block 3229 - 3230 - Arguments: 3231 - pSrc1 Pointer to memory address 3232 - Length Size 3233 - 3234 - Return Value: 3235 - None 3236 - 3237 - IRQL = PASSIVE_LEVEL 3238 - IRQL = DISPATCH_LEVEL 3239 - 3240 - Note: 3241 - 3242 - ======================================================================== 3243 - */ 3244 - VOID RTMPZeroMemory( 3245 - IN PVOID pSrc, 3246 - IN ULONG Length) 3247 - { 3248 - PUCHAR pMem; 3249 - ULONG Index = 0; 3250 - 3251 - pMem = (PUCHAR) pSrc; 3252 - 3253 - for (Index = 0; Index < Length; Index++) 3254 - { 3255 - pMem[Index] = 0x00; 3256 - } 3257 - } 3258 - 3259 - VOID RTMPFillMemory( 3260 - IN PVOID pSrc, 3261 - IN ULONG Length, 3262 - IN UCHAR Fill) 3263 - { 3264 - PUCHAR pMem; 3265 - ULONG Index = 0; 3266 - 3267 - pMem = (PUCHAR) pSrc; 3268 - 3269 - for (Index = 0; Index < Length; Index++) 3270 - { 3271 - pMem[Index] = Fill; 3272 - } 3273 - } 3274 - 3275 - /* 3276 - ======================================================================== 3277 - 3278 - Routine Description: 3279 - Copy data from memory block 1 to memory block 2 3280 - 3281 - Arguments: 3282 - pDest Pointer to destination memory address 3283 - pSrc Pointer to source memory address 3284 - Length Copy size 3285 - 3286 - Return Value: 3287 - None 3288 - 3289 - IRQL = PASSIVE_LEVEL 3290 - IRQL = DISPATCH_LEVEL 3291 - 3292 - Note: 3293 - 3294 - ======================================================================== 3295 - */ 3296 - VOID RTMPMoveMemory( 3297 - OUT PVOID pDest, 3298 - IN PVOID pSrc, 3299 - IN ULONG Length) 3300 - { 3301 - PUCHAR pMem1; 3302 - PUCHAR pMem2; 3303 - UINT Index; 3304 - 3305 - ASSERT((Length==0) || (pDest && pSrc)); 3306 - 3307 - pMem1 = (PUCHAR) pDest; 3308 - pMem2 = (PUCHAR) pSrc; 3309 - 3310 - for (Index = 0; Index < Length; Index++) 3311 - { 3312 - pMem1[Index] = pMem2[Index]; 3313 - } 3314 - } 3315 - 3316 - /* 3317 - ======================================================================== 3318 - 3319 - Routine Description: 3320 - Initialize port configuration structure 3321 - 3322 - Arguments: 3323 - Adapter Pointer to our adapter 3324 - 3325 - Return Value: 3326 - None 3327 - 3328 - IRQL = PASSIVE_LEVEL 3329 - 3330 - Note: 3331 - 3332 - ======================================================================== 3333 - */ 3334 - VOID UserCfgInit( 3335 - IN PRTMP_ADAPTER pAd) 3336 - { 3337 - UINT key_index, bss_index; 3338 - 3339 - DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n")); 3340 - 3341 - // 3342 - // part I. intialize common configuration 3343 - // 3344 - #ifdef RT2870 3345 - pAd->BulkOutReq = 0; 3346 - 3347 - pAd->BulkOutComplete = 0; 3348 - pAd->BulkOutCompleteOther = 0; 3349 - pAd->BulkOutCompleteCancel = 0; 3350 - pAd->BulkInReq = 0; 3351 - pAd->BulkInComplete = 0; 3352 - pAd->BulkInCompleteFail = 0; 3353 - 3354 - //pAd->QuickTimerP = 100; 3355 - //pAd->TurnAggrBulkInCount = 0; 3356 - pAd->bUsbTxBulkAggre = 0; 3357 - 3358 - // init as unsed value to ensure driver will set to MCU once. 3359 - pAd->LedIndicatorStregth = 0xFF; 3360 - 3361 - pAd->CommonCfg.MaxPktOneTxBulk = 2; 3362 - pAd->CommonCfg.TxBulkFactor = 1; 3363 - pAd->CommonCfg.RxBulkFactor =1; 3364 - 3365 - pAd->CommonCfg.TxPower = 100; //mW 3366 - 3367 - NdisZeroMemory(&pAd->CommonCfg.IOTestParm, sizeof(pAd->CommonCfg.IOTestParm)); 3368 - #endif // RT2870 // 3369 - 3370 - for(key_index=0; key_index<SHARE_KEY_NUM; key_index++) 3371 - { 3372 - for(bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++) 3373 - { 3374 - pAd->SharedKey[bss_index][key_index].KeyLen = 0; 3375 - pAd->SharedKey[bss_index][key_index].CipherAlg = CIPHER_NONE; 3376 - } 3377 - } 3378 - #ifdef RT30xx 3379 - pAd->EepromAccess = FALSE; 3380 - #endif 3381 - pAd->Antenna.word = 0; 3382 - pAd->CommonCfg.BBPCurrentBW = BW_20; 3383 - 3384 - pAd->LedCntl.word = 0; 3385 - 3386 - pAd->bAutoTxAgcA = FALSE; // Default is OFF 3387 - pAd->bAutoTxAgcG = FALSE; // Default is OFF 3388 - pAd->RfIcType = RFIC_2820; 3389 - 3390 - // Init timer for reset complete event 3391 - pAd->CommonCfg.CentralChannel = 1; 3392 - pAd->bForcePrintTX = FALSE; 3393 - pAd->bForcePrintRX = FALSE; 3394 - pAd->bStaFifoTest = FALSE; 3395 - pAd->bProtectionTest = FALSE; 3396 - pAd->bHCCATest = FALSE; 3397 - pAd->bGenOneHCCA = FALSE; 3398 - pAd->CommonCfg.Dsifs = 10; // in units of usec 3399 - pAd->CommonCfg.TxPower = 100; //mW 3400 - pAd->CommonCfg.TxPowerPercentage = 0xffffffff; // AUTO 3401 - pAd->CommonCfg.TxPowerDefault = 0xffffffff; // AUTO 3402 - pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; // use Long preamble on TX by defaut 3403 - pAd->CommonCfg.bUseZeroToDisableFragment = FALSE; 3404 - pAd->CommonCfg.RtsThreshold = 2347; 3405 - pAd->CommonCfg.FragmentThreshold = 2346; 3406 - pAd->CommonCfg.UseBGProtection = 0; // 0: AUTO 3407 - pAd->CommonCfg.bEnableTxBurst = TRUE; //0; 3408 - pAd->CommonCfg.PhyMode = 0xff; // unknown 3409 - pAd->CommonCfg.BandState = UNKNOWN_BAND; 3410 - pAd->CommonCfg.RadarDetect.CSPeriod = 10; 3411 - pAd->CommonCfg.RadarDetect.CSCount = 0; 3412 - pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE; 3413 - pAd->CommonCfg.RadarDetect.ChMovingTime = 65; 3414 - pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3; 3415 - pAd->CommonCfg.bAPSDCapable = FALSE; 3416 - pAd->CommonCfg.bNeedSendTriggerFrame = FALSE; 3417 - pAd->CommonCfg.TriggerTimerCount = 0; 3418 - pAd->CommonCfg.bAPSDForcePowerSave = FALSE; 3419 - pAd->CommonCfg.bCountryFlag = FALSE; 3420 - pAd->CommonCfg.TxStream = 0; 3421 - pAd->CommonCfg.RxStream = 0; 3422 - 3423 - NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI)); 3424 - 3425 - NdisZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability)); 3426 - pAd->HTCEnable = FALSE; 3427 - pAd->bBroadComHT = FALSE; 3428 - pAd->CommonCfg.bRdg = FALSE; 3429 - 3430 - NdisZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo)); 3431 - pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE; 3432 - pAd->CommonCfg.BACapability.field.MpduDensity = 0; 3433 - pAd->CommonCfg.BACapability.field.Policy = IMMED_BA; 3434 - pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; //32; 3435 - pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; //32; 3436 - DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit. BACapability = 0x%x\n", pAd->CommonCfg.BACapability.word)); 3437 - 3438 - pAd->CommonCfg.BACapability.field.AutoBA = FALSE; 3439 - BATableInit(pAd, &pAd->BATable); 3440 - 3441 - pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1; 3442 - pAd->CommonCfg.bHTProtect = 1; 3443 - pAd->CommonCfg.bMIMOPSEnable = TRUE; 3444 - pAd->CommonCfg.bBADecline = FALSE; 3445 - pAd->CommonCfg.bDisableReordering = FALSE; 3446 - 3447 - pAd->CommonCfg.TxBASize = 7; 3448 - 3449 - pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word; 3450 - 3451 - //pAd->CommonCfg.HTPhyMode.field.BW = BW_20; 3452 - //pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO; 3453 - //pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800; 3454 - //pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE; 3455 - pAd->CommonCfg.TxRate = RATE_6; 3456 - 3457 - pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6; 3458 - pAd->CommonCfg.MlmeTransmit.field.BW = BW_20; 3459 - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; 3460 - 3461 - pAd->CommonCfg.BeaconPeriod = 100; // in mSec 3462 - 3463 - // 3464 - // part II. intialize STA specific configuration 3465 - // 3466 - { 3467 - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT); 3468 - RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST); 3469 - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST); 3470 - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST); 3471 - 3472 - pAd->StaCfg.Psm = PWR_ACTIVE; 3473 - 3474 - pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled; 3475 - pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled; 3476 - pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled; 3477 - pAd->StaCfg.bMixCipher = FALSE; 3478 - pAd->StaCfg.DefaultKeyId = 0; 3479 - 3480 - // 802.1x port control 3481 - pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP; 3482 - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED; 3483 - pAd->StaCfg.LastMicErrorTime = 0; 3484 - pAd->StaCfg.MicErrCnt = 0; 3485 - pAd->StaCfg.bBlockAssoc = FALSE; 3486 - pAd->StaCfg.WpaState = SS_NOTUSE; 3487 - 3488 - pAd->CommonCfg.NdisRadioStateOff = FALSE; // New to support microsoft disable radio with OID command 3489 - 3490 - pAd->StaCfg.RssiTrigger = 0; 3491 - NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(RSSI_SAMPLE)); 3492 - pAd->StaCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_BELOW_THRESHOLD; 3493 - pAd->StaCfg.AtimWin = 0; 3494 - pAd->StaCfg.DefaultListenCount = 3;//default listen count; 3495 - pAd->StaCfg.BssType = BSS_INFRA; // BSS_INFRA or BSS_ADHOC or BSS_MONITOR 3496 - pAd->StaCfg.bScanReqIsFromWebUI = FALSE; 3497 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); 3498 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW); 3499 - 3500 - pAd->StaCfg.bAutoTxRateSwitch = TRUE; 3501 - pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; 3502 - } 3503 - 3504 - // global variables mXXXX used in MAC protocol state machines 3505 - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM); 3506 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON); 3507 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON); 3508 - 3509 - // PHY specification 3510 - pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; // default PHY mode 3511 - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); // CCK use LONG preamble 3512 - 3513 - { 3514 - // user desired power mode 3515 - pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM; 3516 - pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM; 3517 - pAd->StaCfg.bWindowsACCAMEnable = FALSE; 3518 - 3519 - RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer, GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec), pAd, FALSE); 3520 - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE; 3521 - 3522 - // Patch for Ndtest 3523 - pAd->StaCfg.ScanCnt = 0; 3524 - 3525 - // CCX 2.0 control flag init 3526 - pAd->StaCfg.CCXEnable = FALSE; 3527 - pAd->StaCfg.CCXReqType = MSRN_TYPE_UNUSED; 3528 - pAd->StaCfg.CCXQosECWMin = 4; 3529 - pAd->StaCfg.CCXQosECWMax = 10; 3530 - 3531 - pAd->StaCfg.bHwRadio = TRUE; // Default Hardware Radio status is On 3532 - pAd->StaCfg.bSwRadio = TRUE; // Default Software Radio status is On 3533 - pAd->StaCfg.bRadio = TRUE; // bHwRadio && bSwRadio 3534 - pAd->StaCfg.bHardwareRadio = FALSE; // Default is OFF 3535 - pAd->StaCfg.bShowHiddenSSID = FALSE; // Default no show 3536 - 3537 - // Nitro mode control 3538 - pAd->StaCfg.bAutoReconnect = TRUE; 3539 - 3540 - // Save the init time as last scan time, the system should do scan after 2 seconds. 3541 - // This patch is for driver wake up from standby mode, system will do scan right away. 3542 - pAd->StaCfg.LastScanTime = 0; 3543 - NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE+1); 3544 - sprintf(pAd->nickname, "%s", STA_NIC_DEVICE_NAME); 3545 - RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer, GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc), pAd, FALSE); 3546 - pAd->StaCfg.IEEE8021X = FALSE; 3547 - pAd->StaCfg.IEEE8021x_required_keys = FALSE; 3548 - pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE; 3549 - pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE; 3550 - } 3551 - 3552 - // Default for extra information is not valid 3553 - pAd->ExtraInfo = EXTRA_INFO_CLEAR; 3554 - 3555 - // Default Config change flag 3556 - pAd->bConfigChanged = FALSE; 3557 - 3558 - // 3559 - // part III. AP configurations 3560 - // 3561 - 3562 - 3563 - // 3564 - // part IV. others 3565 - // 3566 - // dynamic BBP R66:sensibity tuning to overcome background noise 3567 - pAd->BbpTuning.bEnable = TRUE; 3568 - pAd->BbpTuning.FalseCcaLowerThreshold = 100; 3569 - pAd->BbpTuning.FalseCcaUpperThreshold = 512; 3570 - pAd->BbpTuning.R66Delta = 4; 3571 - pAd->Mlme.bEnableAutoAntennaCheck = TRUE; 3572 - 3573 - // 3574 - // Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value. 3575 - // if not initial this value, the default value will be 0. 3576 - // 3577 - pAd->BbpTuning.R66CurrentValue = 0x38; 3578 - 3579 - pAd->Bbp94 = BBPR94_DEFAULT; 3580 - pAd->BbpForCCK = FALSE; 3581 - 3582 - // initialize MAC table and allocate spin lock 3583 - NdisZeroMemory(&pAd->MacTab, sizeof(MAC_TABLE)); 3584 - InitializeQueueHeader(&pAd->MacTab.McastPsQueue); 3585 - NdisAllocateSpinLock(&pAd->MacTabLock); 3586 - 3587 - pAd->CommonCfg.bWiFiTest = FALSE; 3588 - 3589 - 3590 - DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n")); 3591 - } 3592 - 3593 - // IRQL = PASSIVE_LEVEL 3594 - UCHAR BtoH(char ch) 3595 - { 3596 - if (ch >= '0' && ch <= '9') return (ch - '0'); // Handle numerals 3597 - if (ch >= 'A' && ch <= 'F') return (ch - 'A' + 0xA); // Handle capitol hex digits 3598 - if (ch >= 'a' && ch <= 'f') return (ch - 'a' + 0xA); // Handle small hex digits 3599 - return(255); 3600 - } 3601 - 3602 - // 3603 - // FUNCTION: AtoH(char *, UCHAR *, int) 3604 - // 3605 - // PURPOSE: Converts ascii string to network order hex 3606 - // 3607 - // PARAMETERS: 3608 - // src - pointer to input ascii string 3609 - // dest - pointer to output hex 3610 - // destlen - size of dest 3611 - // 3612 - // COMMENTS: 3613 - // 3614 - // 2 ascii bytes make a hex byte so must put 1st ascii byte of pair 3615 - // into upper nibble and 2nd ascii byte of pair into lower nibble. 3616 - // 3617 - // IRQL = PASSIVE_LEVEL 3618 - 3619 - void AtoH(char * src, UCHAR * dest, int destlen) 3620 - { 3621 - char * srcptr; 3622 - PUCHAR destTemp; 3623 - 3624 - srcptr = src; 3625 - destTemp = (PUCHAR) dest; 3626 - 3627 - while(destlen--) 3628 - { 3629 - *destTemp = BtoH(*srcptr++) << 4; // Put 1st ascii byte in upper nibble. 3630 - *destTemp += BtoH(*srcptr++); // Add 2nd ascii byte to above. 3631 - destTemp++; 3632 - } 3633 - } 3634 - 3635 - VOID RTMPPatchMacBbpBug( 3636 - IN PRTMP_ADAPTER pAd) 3637 - { 3638 - ULONG Index; 3639 - 3640 - // Initialize BBP register to default value 3641 - for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++) 3642 - { 3643 - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, (UCHAR)BBPRegTable[Index].Value); 3644 - } 3645 - 3646 - // Initialize RF register to default value 3647 - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); 3648 - AsicLockChannel(pAd, pAd->CommonCfg.Channel); 3649 - 3650 - // Re-init BBP register from EEPROM value 3651 - NICInitAsicFromEEPROM(pAd); 3652 - } 3653 - 3654 - /* 3655 - ======================================================================== 3656 - 3657 - Routine Description: 3658 - Init timer objects 3659 - 3660 - Arguments: 3661 - pAd Pointer to our adapter 3662 - pTimer Timer structure 3663 - pTimerFunc Function to execute when timer expired 3664 - Repeat Ture for period timer 3665 - 3666 - Return Value: 3667 - None 3668 - 3669 - Note: 3670 - 3671 - ======================================================================== 3672 - */ 3673 - VOID RTMPInitTimer( 3674 - IN PRTMP_ADAPTER pAd, 3675 - IN PRALINK_TIMER_STRUCT pTimer, 3676 - IN PVOID pTimerFunc, 3677 - IN PVOID pData, 3678 - IN BOOLEAN Repeat) 3679 - { 3680 - // 3681 - // Set Valid to TRUE for later used. 3682 - // It will crash if we cancel a timer or set a timer 3683 - // that we haven't initialize before. 3684 - // 3685 - pTimer->Valid = TRUE; 3686 - 3687 - pTimer->PeriodicType = Repeat; 3688 - pTimer->State = FALSE; 3689 - pTimer->cookie = (ULONG) pData; 3690 - 3691 - #ifdef RT2870 3692 - pTimer->pAd = pAd; 3693 - #endif // RT2870 // 3694 - 3695 - RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (PVOID) pTimer); 3696 - } 3697 - 3698 - /* 3699 - ======================================================================== 3700 - 3701 - Routine Description: 3702 - Init timer objects 3703 - 3704 - Arguments: 3705 - pTimer Timer structure 3706 - Value Timer value in milliseconds 3707 - 3708 - Return Value: 3709 - None 3710 - 3711 - Note: 3712 - To use this routine, must call RTMPInitTimer before. 3713 - 3714 - ======================================================================== 3715 - */ 3716 - VOID RTMPSetTimer( 3717 - IN PRALINK_TIMER_STRUCT pTimer, 3718 - IN ULONG Value) 3719 - { 3720 - if (pTimer->Valid) 3721 - { 3722 - pTimer->TimerValue = Value; 3723 - pTimer->State = FALSE; 3724 - if (pTimer->PeriodicType == TRUE) 3725 - { 3726 - pTimer->Repeat = TRUE; 3727 - RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value); 3728 - } 3729 - else 3730 - { 3731 - pTimer->Repeat = FALSE; 3732 - RTMP_OS_Add_Timer(&pTimer->TimerObj, Value); 3733 - } 3734 - } 3735 - else 3736 - { 3737 - DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n")); 3738 - } 3739 - } 3740 - 3741 - 3742 - /* 3743 - ======================================================================== 3744 - 3745 - Routine Description: 3746 - Init timer objects 3747 - 3748 - Arguments: 3749 - pTimer Timer structure 3750 - Value Timer value in milliseconds 3751 - 3752 - Return Value: 3753 - None 3754 - 3755 - Note: 3756 - To use this routine, must call RTMPInitTimer before. 3757 - 3758 - ======================================================================== 3759 - */ 3760 - VOID RTMPModTimer( 3761 - IN PRALINK_TIMER_STRUCT pTimer, 3762 - IN ULONG Value) 3763 - { 3764 - BOOLEAN Cancel; 3765 - 3766 - if (pTimer->Valid) 3767 - { 3768 - pTimer->TimerValue = Value; 3769 - pTimer->State = FALSE; 3770 - if (pTimer->PeriodicType == TRUE) 3771 - { 3772 - RTMPCancelTimer(pTimer, &Cancel); 3773 - RTMPSetTimer(pTimer, Value); 3774 - } 3775 - else 3776 - { 3777 - RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value); 3778 - } 3779 - } 3780 - else 3781 - { 3782 - DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n")); 3783 - } 3784 - } 3785 - 3786 - /* 3787 - ======================================================================== 3788 - 3789 - Routine Description: 3790 - Cancel timer objects 3791 - 3792 - Arguments: 3793 - Adapter Pointer to our adapter 3794 - 3795 - Return Value: 3796 - None 3797 - 3798 - IRQL = PASSIVE_LEVEL 3799 - IRQL = DISPATCH_LEVEL 3800 - 3801 - Note: 3802 - 1.) To use this routine, must call RTMPInitTimer before. 3803 - 2.) Reset NIC to initial state AS IS system boot up time. 3804 - 3805 - ======================================================================== 3806 - */ 3807 - VOID RTMPCancelTimer( 3808 - IN PRALINK_TIMER_STRUCT pTimer, 3809 - OUT BOOLEAN *pCancelled) 3810 - { 3811 - if (pTimer->Valid) 3812 - { 3813 - if (pTimer->State == FALSE) 3814 - pTimer->Repeat = FALSE; 3815 - RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled); 3816 - 3817 - if (*pCancelled == TRUE) 3818 - pTimer->State = TRUE; 3819 - 3820 - #ifdef RT2870 3821 - // We need to go-through the TimerQ to findout this timer handler and remove it if 3822 - // it's still waiting for execution. 3823 - 3824 - RT2870_TimerQ_Remove(pTimer->pAd, pTimer); 3825 - #endif // RT2870 // 3826 - } 3827 - else 3828 - { 3829 - // 3830 - // NdisMCancelTimer just canced the timer and not mean release the timer. 3831 - // And don't set the "Valid" to False. So that we can use this timer again. 3832 - // 3833 - DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n")); 3834 - } 3835 - } 3836 - 3837 - /* 3838 - ======================================================================== 3839 - 3840 - Routine Description: 3841 - Set LED Status 3842 - 3843 - Arguments: 3844 - pAd Pointer to our adapter 3845 - Status LED Status 3846 - 3847 - Return Value: 3848 - None 3849 - 3850 - IRQL = PASSIVE_LEVEL 3851 - IRQL = DISPATCH_LEVEL 3852 - 3853 - Note: 3854 - 3855 - ======================================================================== 3856 - */ 3857 - VOID RTMPSetLED( 3858 - IN PRTMP_ADAPTER pAd, 3859 - IN UCHAR Status) 3860 - { 3861 - //ULONG data; 3862 - UCHAR HighByte = 0; 3863 - UCHAR LowByte; 3864 - 3865 - LowByte = pAd->LedCntl.field.LedMode&0x7f; 3866 - switch (Status) 3867 - { 3868 - case LED_LINK_DOWN: 3869 - HighByte = 0x20; 3870 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3871 - pAd->LedIndicatorStregth = 0; 3872 - break; 3873 - case LED_LINK_UP: 3874 - if (pAd->CommonCfg.Channel > 14) 3875 - HighByte = 0xa0; 3876 - else 3877 - HighByte = 0x60; 3878 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3879 - break; 3880 - case LED_RADIO_ON: 3881 - HighByte = 0x20; 3882 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3883 - break; 3884 - case LED_HALT: 3885 - LowByte = 0; // Driver sets MAC register and MAC controls LED 3886 - case LED_RADIO_OFF: 3887 - HighByte = 0; 3888 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3889 - break; 3890 - case LED_WPS: 3891 - HighByte = 0x10; 3892 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3893 - break; 3894 - case LED_ON_SITE_SURVEY: 3895 - HighByte = 0x08; 3896 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3897 - break; 3898 - case LED_POWER_UP: 3899 - HighByte = 0x04; 3900 - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); 3901 - break; 3902 - default: 3903 - DBGPRINT(RT_DEBUG_WARN, ("RTMPSetLED::Unknown Status %d\n", Status)); 3904 - break; 3905 - } 3906 - 3907 - // 3908 - // Keep LED status for LED SiteSurvey mode. 3909 - // After SiteSurvey, we will set the LED mode to previous status. 3910 - // 3911 - if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP)) 3912 - pAd->LedStatus = Status; 3913 - 3914 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n", pAd->LedCntl.field.LedMode, HighByte, LowByte)); 3915 - } 3916 - 3917 - /* 3918 - ======================================================================== 3919 - 3920 - Routine Description: 3921 - Set LED Signal Stregth 3922 - 3923 - Arguments: 3924 - pAd Pointer to our adapter 3925 - Dbm Signal Stregth 3926 - 3927 - Return Value: 3928 - None 3929 - 3930 - IRQL = PASSIVE_LEVEL 3931 - 3932 - Note: 3933 - Can be run on any IRQL level. 3934 - 3935 - According to Microsoft Zero Config Wireless Signal Stregth definition as belows. 3936 - <= -90 No Signal 3937 - <= -81 Very Low 3938 - <= -71 Low 3939 - <= -67 Good 3940 - <= -57 Very Good 3941 - > -57 Excellent 3942 - ======================================================================== 3943 - */ 3944 - VOID RTMPSetSignalLED( 3945 - IN PRTMP_ADAPTER pAd, 3946 - IN NDIS_802_11_RSSI Dbm) 3947 - { 3948 - UCHAR nLed = 0; 3949 - 3950 - // 3951 - // if not Signal Stregth, then do nothing. 3952 - // 3953 - if (pAd->LedCntl.field.LedMode != LED_MODE_SIGNAL_STREGTH) 3954 - { 3955 - return; 3956 - } 3957 - 3958 - if (Dbm <= -90) 3959 - nLed = 0; 3960 - else if (Dbm <= -81) 3961 - nLed = 1; 3962 - else if (Dbm <= -71) 3963 - nLed = 3; 3964 - else if (Dbm <= -67) 3965 - nLed = 7; 3966 - else if (Dbm <= -57) 3967 - nLed = 15; 3968 - else 3969 - nLed = 31; 3970 - 3971 - // 3972 - // Update Signal Stregth to firmware if changed. 3973 - // 3974 - if (pAd->LedIndicatorStregth != nLed) 3975 - { 3976 - AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed, pAd->LedCntl.field.Polarity); 3977 - pAd->LedIndicatorStregth = nLed; 3978 - } 3979 - } 3980 - 3981 - /* 3982 - ======================================================================== 3983 - 3984 - Routine Description: 3985 - Enable RX 3986 - 3987 - Arguments: 3988 - pAd Pointer to our adapter 3989 - 3990 - Return Value: 3991 - None 3992 - 3993 - IRQL <= DISPATCH_LEVEL 3994 - 3995 - Note: 3996 - Before Enable RX, make sure you have enabled Interrupt. 3997 - ======================================================================== 3998 - */ 3999 - VOID RTMPEnableRxTx( 4000 - IN PRTMP_ADAPTER pAd) 4001 - { 4002 - DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n")); 4003 - 4004 - // Enable Rx DMA. 4005 - RT28XXDMAEnable(pAd); 4006 - 4007 - // enable RX of MAC block 4008 - if (pAd->OpMode == OPMODE_AP) 4009 - { 4010 - UINT32 rx_filter_flag = APNORMAL; 4011 - 4012 - 4013 - RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); // enable RX of DMA block 4014 - } 4015 - else 4016 - { 4017 - RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, STANORMAL); // Staion not drop control frame will fail WiFi Certification. 4018 - } 4019 - 4020 - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc); 4021 - DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n")); 4022 - } 4023 - 4024 - 1 + #include "../../rt2860/common/rtmp_init.c"
+1 -1586
drivers/staging/rt2870/common/rtmp_tkip.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - rtmp_tkip.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Paul Wu 02-25-02 Initial 36 - */ 37 - 38 - #include "../rt_config.h" 39 - 40 - // Rotation functions on 32 bit values 41 - #define ROL32( A, n ) \ 42 - ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) ) 43 - #define ROR32( A, n ) ROL32( (A), 32-(n) ) 44 - 45 - UINT Tkip_Sbox_Lower[256] = 46 - { 47 - 0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54, 48 - 0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A, 49 - 0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B, 50 - 0xEC,0x67,0xFD,0xEA,0xBF,0xF7,0x96,0x5B, 51 - 0xC2,0x1C,0xAE,0x6A,0x5A,0x41,0x02,0x4F, 52 - 0x5C,0xF4,0x34,0x08,0x93,0x73,0x53,0x3F, 53 - 0x0C,0x52,0x65,0x5E,0x28,0xA1,0x0F,0xB5, 54 - 0x09,0x36,0x9B,0x3D,0x26,0x69,0xCD,0x9F, 55 - 0x1B,0x9E,0x74,0x2E,0x2D,0xB2,0xEE,0xFB, 56 - 0xF6,0x4D,0x61,0xCE,0x7B,0x3E,0x71,0x97, 57 - 0xF5,0x68,0x00,0x2C,0x60,0x1F,0xC8,0xED, 58 - 0xBE,0x46,0xD9,0x4B,0xDE,0xD4,0xE8,0x4A, 59 - 0x6B,0x2A,0xE5,0x16,0xC5,0xD7,0x55,0x94, 60 - 0xCF,0x10,0x06,0x81,0xF0,0x44,0xBA,0xE3, 61 - 0xF3,0xFE,0xC0,0x8A,0xAD,0xBC,0x48,0x04, 62 - 0xDF,0xC1,0x75,0x63,0x30,0x1A,0x0E,0x6D, 63 - 0x4C,0x14,0x35,0x2F,0xE1,0xA2,0xCC,0x39, 64 - 0x57,0xF2,0x82,0x47,0xAC,0xE7,0x2B,0x95, 65 - 0xA0,0x98,0xD1,0x7F,0x66,0x7E,0xAB,0x83, 66 - 0xCA,0x29,0xD3,0x3C,0x79,0xE2,0x1D,0x76, 67 - 0x3B,0x56,0x4E,0x1E,0xDB,0x0A,0x6C,0xE4, 68 - 0x5D,0x6E,0xEF,0xA6,0xA8,0xA4,0x37,0x8B, 69 - 0x32,0x43,0x59,0xB7,0x8C,0x64,0xD2,0xE0, 70 - 0xB4,0xFA,0x07,0x25,0xAF,0x8E,0xE9,0x18, 71 - 0xD5,0x88,0x6F,0x72,0x24,0xF1,0xC7,0x51, 72 - 0x23,0x7C,0x9C,0x21,0xDD,0xDC,0x86,0x85, 73 - 0x90,0x42,0xC4,0xAA,0xD8,0x05,0x01,0x12, 74 - 0xA3,0x5F,0xF9,0xD0,0x91,0x58,0x27,0xB9, 75 - 0x38,0x13,0xB3,0x33,0xBB,0x70,0x89,0xA7, 76 - 0xB6,0x22,0x92,0x20,0x49,0xFF,0x78,0x7A, 77 - 0x8F,0xF8,0x80,0x17,0xDA,0x31,0xC6,0xB8, 78 - 0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A 79 - }; 80 - 81 - UINT Tkip_Sbox_Upper[256] = 82 - { 83 - 0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91, 84 - 0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC, 85 - 0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB, 86 - 0x41,0xB3,0x5F,0x45,0x23,0x53,0xE4,0x9B, 87 - 0x75,0xE1,0x3D,0x4C,0x6C,0x7E,0xF5,0x83, 88 - 0x68,0x51,0xD1,0xF9,0xE2,0xAB,0x62,0x2A, 89 - 0x08,0x95,0x46,0x9D,0x30,0x37,0x0A,0x2F, 90 - 0x0E,0x24,0x1B,0xDF,0xCD,0x4E,0x7F,0xEA, 91 - 0x12,0x1D,0x58,0x34,0x36,0xDC,0xB4,0x5B, 92 - 0xA4,0x76,0xB7,0x7D,0x52,0xDD,0x5E,0x13, 93 - 0xA6,0xB9,0x00,0xC1,0x40,0xE3,0x79,0xB6, 94 - 0xD4,0x8D,0x67,0x72,0x94,0x98,0xB0,0x85, 95 - 0xBB,0xC5,0x4F,0xED,0x86,0x9A,0x66,0x11, 96 - 0x8A,0xE9,0x04,0xFE,0xA0,0x78,0x25,0x4B, 97 - 0xA2,0x5D,0x80,0x05,0x3F,0x21,0x70,0xF1, 98 - 0x63,0x77,0xAF,0x42,0x20,0xE5,0xFD,0xBF, 99 - 0x81,0x18,0x26,0xC3,0xBE,0x35,0x88,0x2E, 100 - 0x93,0x55,0xFC,0x7A,0xC8,0xBA,0x32,0xE6, 101 - 0xC0,0x19,0x9E,0xA3,0x44,0x54,0x3B,0x0B, 102 - 0x8C,0xC7,0x6B,0x28,0xA7,0xBC,0x16,0xAD, 103 - 0xDB,0x64,0x74,0x14,0x92,0x0C,0x48,0xB8, 104 - 0x9F,0xBD,0x43,0xC4,0x39,0x31,0xD3,0xF2, 105 - 0xD5,0x8B,0x6E,0xDA,0x01,0xB1,0x9C,0x49, 106 - 0xD8,0xAC,0xF3,0xCF,0xCA,0xF4,0x47,0x10, 107 - 0x6F,0xF0,0x4A,0x5C,0x38,0x57,0x73,0x97, 108 - 0xCB,0xA1,0xE8,0x3E,0x96,0x61,0x0D,0x0F, 109 - 0xE0,0x7C,0x71,0xCC,0x90,0x06,0xF7,0x1C, 110 - 0xC2,0x6A,0xAE,0x69,0x17,0x99,0x3A,0x27, 111 - 0xD9,0xEB,0x2B,0x22,0xD2,0xA9,0x07,0x33, 112 - 0x2D,0x3C,0x15,0xC9,0x87,0xAA,0x50,0xA5, 113 - 0x03,0x59,0x09,0x1A,0x65,0xD7,0x84,0xD0, 114 - 0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C 115 - }; 116 - 117 - /*****************************/ 118 - /******** SBOX Table *********/ 119 - /*****************************/ 120 - 121 - UCHAR SboxTable[256] = 122 - { 123 - 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 124 - 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 125 - 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 126 - 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 127 - 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 128 - 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 129 - 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 130 - 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 131 - 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 132 - 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 133 - 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 134 - 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 135 - 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 136 - 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 137 - 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 138 - 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 139 - 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 140 - 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 141 - 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 142 - 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 143 - 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 144 - 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 145 - 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 146 - 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 147 - 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 148 - 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 149 - 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 150 - 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 151 - 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 152 - 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 153 - 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 154 - 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 155 - }; 156 - 157 - VOID xor_32( 158 - IN PUCHAR a, 159 - IN PUCHAR b, 160 - OUT PUCHAR out); 161 - 162 - VOID xor_128( 163 - IN PUCHAR a, 164 - IN PUCHAR b, 165 - OUT PUCHAR out); 166 - 167 - VOID next_key( 168 - IN PUCHAR key, 169 - IN INT round); 170 - 171 - VOID byte_sub( 172 - IN PUCHAR in, 173 - OUT PUCHAR out); 174 - 175 - VOID shift_row( 176 - IN PUCHAR in, 177 - OUT PUCHAR out); 178 - 179 - VOID mix_column( 180 - IN PUCHAR in, 181 - OUT PUCHAR out); 182 - 183 - UCHAR RTMPCkipSbox( 184 - IN UCHAR a); 185 - // 186 - // Expanded IV for TKIP function. 187 - // 188 - typedef struct PACKED _IV_CONTROL_ 189 - { 190 - union PACKED 191 - { 192 - struct PACKED 193 - { 194 - UCHAR rc0; 195 - UCHAR rc1; 196 - UCHAR rc2; 197 - 198 - union PACKED 199 - { 200 - struct PACKED 201 - { 202 - UCHAR Rsvd:5; 203 - UCHAR ExtIV:1; 204 - UCHAR KeyID:2; 205 - } field; 206 - UCHAR Byte; 207 - } CONTROL; 208 - } field; 209 - 210 - ULONG word; 211 - } IV16; 212 - 213 - ULONG IV32; 214 - } TKIP_IV, *PTKIP_IV; 215 - 216 - 217 - /* 218 - ======================================================================== 219 - 220 - Routine Description: 221 - Convert from UCHAR[] to ULONG in a portable way 222 - 223 - Arguments: 224 - pMICKey pointer to MIC Key 225 - 226 - Return Value: 227 - None 228 - 229 - Note: 230 - 231 - ======================================================================== 232 - */ 233 - ULONG RTMPTkipGetUInt32( 234 - IN PUCHAR pMICKey) 235 - { 236 - ULONG res = 0; 237 - INT i; 238 - 239 - for (i = 0; i < 4; i++) 240 - { 241 - res |= (*pMICKey++) << (8 * i); 242 - } 243 - 244 - return res; 245 - } 246 - 247 - /* 248 - ======================================================================== 249 - 250 - Routine Description: 251 - Convert from ULONG to UCHAR[] in a portable way 252 - 253 - Arguments: 254 - pDst pointer to destination for convert ULONG to UCHAR[] 255 - val the value for convert 256 - 257 - Return Value: 258 - None 259 - 260 - IRQL = DISPATCH_LEVEL 261 - 262 - Note: 263 - 264 - ======================================================================== 265 - */ 266 - VOID RTMPTkipPutUInt32( 267 - IN OUT PUCHAR pDst, 268 - IN ULONG val) 269 - { 270 - INT i; 271 - 272 - for(i = 0; i < 4; i++) 273 - { 274 - *pDst++ = (UCHAR) (val & 0xff); 275 - val >>= 8; 276 - } 277 - } 278 - 279 - /* 280 - ======================================================================== 281 - 282 - Routine Description: 283 - Set the MIC Key. 284 - 285 - Arguments: 286 - pAd Pointer to our adapter 287 - pMICKey pointer to MIC Key 288 - 289 - Return Value: 290 - None 291 - 292 - IRQL = DISPATCH_LEVEL 293 - 294 - Note: 295 - 296 - ======================================================================== 297 - */ 298 - VOID RTMPTkipSetMICKey( 299 - IN PTKIP_KEY_INFO pTkip, 300 - IN PUCHAR pMICKey) 301 - { 302 - // Set the key 303 - pTkip->K0 = RTMPTkipGetUInt32(pMICKey); 304 - pTkip->K1 = RTMPTkipGetUInt32(pMICKey + 4); 305 - // and reset the message 306 - pTkip->L = pTkip->K0; 307 - pTkip->R = pTkip->K1; 308 - pTkip->nBytesInM = 0; 309 - pTkip->M = 0; 310 - } 311 - 312 - /* 313 - ======================================================================== 314 - 315 - Routine Description: 316 - Calculate the MIC Value. 317 - 318 - Arguments: 319 - pAd Pointer to our adapter 320 - uChar Append this uChar 321 - 322 - Return Value: 323 - None 324 - 325 - IRQL = DISPATCH_LEVEL 326 - 327 - Note: 328 - 329 - ======================================================================== 330 - */ 331 - VOID RTMPTkipAppendByte( 332 - IN PTKIP_KEY_INFO pTkip, 333 - IN UCHAR uChar) 334 - { 335 - // Append the byte to our word-sized buffer 336 - pTkip->M |= (uChar << (8* pTkip->nBytesInM)); 337 - pTkip->nBytesInM++; 338 - // Process the word if it is full. 339 - if( pTkip->nBytesInM >= 4 ) 340 - { 341 - pTkip->L ^= pTkip->M; 342 - pTkip->R ^= ROL32( pTkip->L, 17 ); 343 - pTkip->L += pTkip->R; 344 - pTkip->R ^= ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->L & 0x00ff00ff) << 8); 345 - pTkip->L += pTkip->R; 346 - pTkip->R ^= ROL32( pTkip->L, 3 ); 347 - pTkip->L += pTkip->R; 348 - pTkip->R ^= ROR32( pTkip->L, 2 ); 349 - pTkip->L += pTkip->R; 350 - // Clear the buffer 351 - pTkip->M = 0; 352 - pTkip->nBytesInM = 0; 353 - } 354 - } 355 - 356 - /* 357 - ======================================================================== 358 - 359 - Routine Description: 360 - Calculate the MIC Value. 361 - 362 - Arguments: 363 - pAd Pointer to our adapter 364 - pSrc Pointer to source data for Calculate MIC Value 365 - Len Indicate the length of the source data 366 - 367 - Return Value: 368 - None 369 - 370 - IRQL = DISPATCH_LEVEL 371 - 372 - Note: 373 - 374 - ======================================================================== 375 - */ 376 - VOID RTMPTkipAppend( 377 - IN PTKIP_KEY_INFO pTkip, 378 - IN PUCHAR pSrc, 379 - IN UINT nBytes) 380 - { 381 - // This is simple 382 - while(nBytes > 0) 383 - { 384 - RTMPTkipAppendByte(pTkip, *pSrc++); 385 - nBytes--; 386 - } 387 - } 388 - 389 - /* 390 - ======================================================================== 391 - 392 - Routine Description: 393 - Get the MIC Value. 394 - 395 - Arguments: 396 - pAd Pointer to our adapter 397 - 398 - Return Value: 399 - None 400 - 401 - IRQL = DISPATCH_LEVEL 402 - 403 - Note: 404 - the MIC Value is store in pAd->PrivateInfo.MIC 405 - ======================================================================== 406 - */ 407 - VOID RTMPTkipGetMIC( 408 - IN PTKIP_KEY_INFO pTkip) 409 - { 410 - // Append the minimum padding 411 - RTMPTkipAppendByte(pTkip, 0x5a ); 412 - RTMPTkipAppendByte(pTkip, 0 ); 413 - RTMPTkipAppendByte(pTkip, 0 ); 414 - RTMPTkipAppendByte(pTkip, 0 ); 415 - RTMPTkipAppendByte(pTkip, 0 ); 416 - // and then zeroes until the length is a multiple of 4 417 - while( pTkip->nBytesInM != 0 ) 418 - { 419 - RTMPTkipAppendByte(pTkip, 0 ); 420 - } 421 - // The appendByte function has already computed the result. 422 - RTMPTkipPutUInt32(pTkip->MIC, pTkip->L); 423 - RTMPTkipPutUInt32(pTkip->MIC + 4, pTkip->R); 424 - } 425 - 426 - /* 427 - ======================================================================== 428 - 429 - Routine Description: 430 - Init Tkip function. 431 - 432 - Arguments: 433 - pAd Pointer to our adapter 434 - pTKey Pointer to the Temporal Key (TK), TK shall be 128bits. 435 - KeyId TK Key ID 436 - pTA Pointer to transmitter address 437 - pMICKey pointer to MIC Key 438 - 439 - Return Value: 440 - None 441 - 442 - IRQL = DISPATCH_LEVEL 443 - 444 - Note: 445 - 446 - ======================================================================== 447 - */ 448 - VOID RTMPInitTkipEngine( 449 - IN PRTMP_ADAPTER pAd, 450 - IN PUCHAR pKey, 451 - IN UCHAR KeyId, 452 - IN PUCHAR pTA, 453 - IN PUCHAR pMICKey, 454 - IN PUCHAR pTSC, 455 - OUT PULONG pIV16, 456 - OUT PULONG pIV32) 457 - { 458 - TKIP_IV tkipIv; 459 - 460 - // Prepare 8 bytes TKIP encapsulation for MPDU 461 - NdisZeroMemory(&tkipIv, sizeof(TKIP_IV)); 462 - tkipIv.IV16.field.rc0 = *(pTSC + 1); 463 - tkipIv.IV16.field.rc1 = (tkipIv.IV16.field.rc0 | 0x20) & 0x7f; 464 - tkipIv.IV16.field.rc2 = *pTSC; 465 - tkipIv.IV16.field.CONTROL.field.ExtIV = 1; // 0: non-extended IV, 1: an extended IV 466 - tkipIv.IV16.field.CONTROL.field.KeyID = KeyId; 467 - NdisMoveMemory(&tkipIv.IV32, (pTSC + 2), 4); // Copy IV 468 - 469 - *pIV16 = tkipIv.IV16.word; 470 - *pIV32 = tkipIv.IV32; 471 - } 472 - 473 - /* 474 - ======================================================================== 475 - 476 - Routine Description: 477 - Init MIC Value calculation function which include set MIC key & 478 - calculate first 16 bytes (DA + SA + priority + 0) 479 - 480 - Arguments: 481 - pAd Pointer to our adapter 482 - pTKey Pointer to the Temporal Key (TK), TK shall be 128bits. 483 - pDA Pointer to DA address 484 - pSA Pointer to SA address 485 - pMICKey pointer to MIC Key 486 - 487 - Return Value: 488 - None 489 - 490 - Note: 491 - 492 - ======================================================================== 493 - */ 494 - VOID RTMPInitMICEngine( 495 - IN PRTMP_ADAPTER pAd, 496 - IN PUCHAR pKey, 497 - IN PUCHAR pDA, 498 - IN PUCHAR pSA, 499 - IN UCHAR UserPriority, 500 - IN PUCHAR pMICKey) 501 - { 502 - ULONG Priority = UserPriority; 503 - 504 - // Init MIC value calculation 505 - RTMPTkipSetMICKey(&pAd->PrivateInfo.Tx, pMICKey); 506 - // DA 507 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pDA, MAC_ADDR_LEN); 508 - // SA 509 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSA, MAC_ADDR_LEN); 510 - // Priority + 3 bytes of 0 511 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, (PUCHAR)&Priority, 4); 512 - } 513 - 514 - /* 515 - ======================================================================== 516 - 517 - Routine Description: 518 - Compare MIC value of received MSDU 519 - 520 - Arguments: 521 - pAd Pointer to our adapter 522 - pSrc Pointer to the received Plain text data 523 - pDA Pointer to DA address 524 - pSA Pointer to SA address 525 - pMICKey pointer to MIC Key 526 - Len the length of the received plain text data exclude MIC value 527 - 528 - Return Value: 529 - TRUE MIC value matched 530 - FALSE MIC value mismatched 531 - 532 - IRQL = DISPATCH_LEVEL 533 - 534 - Note: 535 - 536 - ======================================================================== 537 - */ 538 - BOOLEAN RTMPTkipCompareMICValue( 539 - IN PRTMP_ADAPTER pAd, 540 - IN PUCHAR pSrc, 541 - IN PUCHAR pDA, 542 - IN PUCHAR pSA, 543 - IN PUCHAR pMICKey, 544 - IN UCHAR UserPriority, 545 - IN UINT Len) 546 - { 547 - UCHAR OldMic[8]; 548 - ULONG Priority = UserPriority; 549 - 550 - // Init MIC value calculation 551 - RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey); 552 - // DA 553 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN); 554 - // SA 555 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN); 556 - // Priority + 3 bytes of 0 557 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4); 558 - 559 - // Calculate MIC value from plain text data 560 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len); 561 - 562 - // Get MIC valude from received frame 563 - NdisMoveMemory(OldMic, pSrc + Len, 8); 564 - 565 - // Get MIC value from decrypted plain data 566 - RTMPTkipGetMIC(&pAd->PrivateInfo.Rx); 567 - 568 - // Move MIC value from MSDU, this steps should move to data path. 569 - // Since the MIC value might cross MPDUs. 570 - if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8)) 571 - { 572 - DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValue(): TKIP MIC Error !\n")); //MIC error. 573 - 574 - 575 - return (FALSE); 576 - } 577 - return (TRUE); 578 - } 579 - 580 - /* 581 - ======================================================================== 582 - 583 - Routine Description: 584 - Compare MIC value of received MSDU 585 - 586 - Arguments: 587 - pAd Pointer to our adapter 588 - pLLC LLC header 589 - pSrc Pointer to the received Plain text data 590 - pDA Pointer to DA address 591 - pSA Pointer to SA address 592 - pMICKey pointer to MIC Key 593 - Len the length of the received plain text data exclude MIC value 594 - 595 - Return Value: 596 - TRUE MIC value matched 597 - FALSE MIC value mismatched 598 - 599 - IRQL = DISPATCH_LEVEL 600 - 601 - Note: 602 - 603 - ======================================================================== 604 - */ 605 - BOOLEAN RTMPTkipCompareMICValueWithLLC( 606 - IN PRTMP_ADAPTER pAd, 607 - IN PUCHAR pLLC, 608 - IN PUCHAR pSrc, 609 - IN PUCHAR pDA, 610 - IN PUCHAR pSA, 611 - IN PUCHAR pMICKey, 612 - IN UINT Len) 613 - { 614 - UCHAR OldMic[8]; 615 - ULONG Priority = 0; 616 - 617 - // Init MIC value calculation 618 - RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey); 619 - // DA 620 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN); 621 - // SA 622 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN); 623 - // Priority + 3 bytes of 0 624 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, (PUCHAR)&Priority, 4); 625 - 626 - // Start with LLC header 627 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pLLC, 8); 628 - 629 - // Calculate MIC value from plain text data 630 - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len); 631 - 632 - // Get MIC valude from received frame 633 - NdisMoveMemory(OldMic, pSrc + Len, 8); 634 - 635 - // Get MIC value from decrypted plain data 636 - RTMPTkipGetMIC(&pAd->PrivateInfo.Rx); 637 - 638 - // Move MIC value from MSDU, this steps should move to data path. 639 - // Since the MIC value might cross MPDUs. 640 - if(!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8)) 641 - { 642 - DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValueWithLLC(): TKIP MIC Error !\n")); //MIC error. 643 - 644 - 645 - return (FALSE); 646 - } 647 - return (TRUE); 648 - } 649 - /* 650 - ======================================================================== 651 - 652 - Routine Description: 653 - Copy frame from waiting queue into relative ring buffer and set 654 - appropriate ASIC register to kick hardware transmit function 655 - 656 - Arguments: 657 - pAd Pointer to our adapter 658 - PNDIS_PACKET Pointer to Ndis Packet for MIC calculation 659 - pEncap Pointer to LLC encap data 660 - LenEncap Total encap length, might be 0 which indicates no encap 661 - 662 - Return Value: 663 - None 664 - 665 - IRQL = DISPATCH_LEVEL 666 - 667 - Note: 668 - 669 - ======================================================================== 670 - */ 671 - VOID RTMPCalculateMICValue( 672 - IN PRTMP_ADAPTER pAd, 673 - IN PNDIS_PACKET pPacket, 674 - IN PUCHAR pEncap, 675 - IN PCIPHER_KEY pKey, 676 - IN UCHAR apidx) 677 - { 678 - PACKET_INFO PacketInfo; 679 - PUCHAR pSrcBufVA; 680 - UINT SrcBufLen; 681 - PUCHAR pSrc; 682 - UCHAR UserPriority; 683 - UCHAR vlan_offset = 0; 684 - 685 - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); 686 - 687 - UserPriority = RTMP_GET_PACKET_UP(pPacket); 688 - pSrc = pSrcBufVA; 689 - 690 - // determine if this is a vlan packet 691 - if (((*(pSrc + 12) << 8) + *(pSrc + 13)) == 0x8100) 692 - vlan_offset = 4; 693 - { 694 - RTMPInitMICEngine( 695 - pAd, 696 - pKey->Key, 697 - pSrc, 698 - pSrc + 6, 699 - UserPriority, 700 - pKey->TxMic); 701 - } 702 - 703 - 704 - if (pEncap != NULL) 705 - { 706 - // LLC encapsulation 707 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pEncap, 6); 708 - // Protocol Type 709 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc + 12 + vlan_offset, 2); 710 - } 711 - SrcBufLen -= (14 + vlan_offset); 712 - pSrc += (14 + vlan_offset); 713 - do 714 - { 715 - if (SrcBufLen > 0) 716 - { 717 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc, SrcBufLen); 718 - } 719 - 720 - break; // No need handle next packet 721 - 722 - } while (TRUE); // End of copying payload 723 - 724 - // Compute the final MIC Value 725 - RTMPTkipGetMIC(&pAd->PrivateInfo.Tx); 726 - } 727 - 728 - 729 - /************************************************************/ 730 - /* tkip_sbox() */ 731 - /* Returns a 16 bit value from a 64K entry table. The Table */ 732 - /* is synthesized from two 256 entry byte wide tables. */ 733 - /************************************************************/ 734 - 735 - UINT tkip_sbox(UINT index) 736 - { 737 - UINT index_low; 738 - UINT index_high; 739 - UINT left, right; 740 - 741 - index_low = (index % 256); 742 - index_high = ((index >> 8) % 256); 743 - 744 - left = Tkip_Sbox_Lower[index_low] + (Tkip_Sbox_Upper[index_low] * 256); 745 - right = Tkip_Sbox_Upper[index_high] + (Tkip_Sbox_Lower[index_high] * 256); 746 - 747 - return (left ^ right); 748 - } 749 - 750 - UINT rotr1(UINT a) 751 - { 752 - unsigned int b; 753 - 754 - if ((a & 0x01) == 0x01) 755 - { 756 - b = (a >> 1) | 0x8000; 757 - } 758 - else 759 - { 760 - b = (a >> 1) & 0x7fff; 761 - } 762 - b = b % 65536; 763 - return b; 764 - } 765 - 766 - VOID RTMPTkipMixKey( 767 - UCHAR *key, 768 - UCHAR *ta, 769 - ULONG pnl, /* Least significant 16 bits of PN */ 770 - ULONG pnh, /* Most significant 32 bits of PN */ 771 - UCHAR *rc4key, 772 - UINT *p1k) 773 - { 774 - 775 - UINT tsc0; 776 - UINT tsc1; 777 - UINT tsc2; 778 - 779 - UINT ppk0; 780 - UINT ppk1; 781 - UINT ppk2; 782 - UINT ppk3; 783 - UINT ppk4; 784 - UINT ppk5; 785 - 786 - INT i; 787 - INT j; 788 - 789 - tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */ 790 - tsc1 = (unsigned int)(pnh % 65536); 791 - tsc2 = (unsigned int)(pnl % 65536); /* lsb */ 792 - 793 - /* Phase 1, step 1 */ 794 - p1k[0] = tsc1; 795 - p1k[1] = tsc0; 796 - p1k[2] = (UINT)(ta[0] + (ta[1]*256)); 797 - p1k[3] = (UINT)(ta[2] + (ta[3]*256)); 798 - p1k[4] = (UINT)(ta[4] + (ta[5]*256)); 799 - 800 - /* Phase 1, step 2 */ 801 - for (i=0; i<8; i++) 802 - { 803 - j = 2*(i & 1); 804 - p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*key[1+j]) + key[j])) % 65536 )) % 65536; 805 - p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*key[5+j]) + key[4+j])) % 65536 )) % 65536; 806 - p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*key[9+j]) + key[8+j])) % 65536 )) % 65536; 807 - p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*key[13+j]) + key[12+j])) % 65536 )) % 65536; 808 - p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*key[1+j]) + key[j]))) % 65536 )) % 65536; 809 - p1k[4] = (p1k[4] + i) % 65536; 810 - } 811 - 812 - /* Phase 2, Step 1 */ 813 - ppk0 = p1k[0]; 814 - ppk1 = p1k[1]; 815 - ppk2 = p1k[2]; 816 - ppk3 = p1k[3]; 817 - ppk4 = p1k[4]; 818 - ppk5 = (p1k[4] + tsc2) % 65536; 819 - 820 - /* Phase2, Step 2 */ 821 - ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*key[1]) + key[0])) % 65536); 822 - ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*key[3]) + key[2])) % 65536); 823 - ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*key[5]) + key[4])) % 65536); 824 - ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*key[7]) + key[6])) % 65536); 825 - ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*key[9]) + key[8])) % 65536); 826 - ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*key[11]) + key[10])) % 65536); 827 - 828 - ppk0 = ppk0 + rotr1(ppk5 ^ ((256*key[13]) + key[12])); 829 - ppk1 = ppk1 + rotr1(ppk0 ^ ((256*key[15]) + key[14])); 830 - ppk2 = ppk2 + rotr1(ppk1); 831 - ppk3 = ppk3 + rotr1(ppk2); 832 - ppk4 = ppk4 + rotr1(ppk3); 833 - ppk5 = ppk5 + rotr1(ppk4); 834 - 835 - /* Phase 2, Step 3 */ 836 - /* Phase 2, Step 3 */ 837 - 838 - tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */ 839 - tsc1 = (unsigned int)(pnh % 65536); 840 - tsc2 = (unsigned int)(pnl % 65536); /* lsb */ 841 - 842 - rc4key[0] = (tsc2 >> 8) % 256; 843 - rc4key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f; 844 - rc4key[2] = tsc2 % 256; 845 - rc4key[3] = ((ppk5 ^ ((256*key[1]) + key[0])) >> 1) % 256; 846 - 847 - rc4key[4] = ppk0 % 256; 848 - rc4key[5] = (ppk0 >> 8) % 256; 849 - 850 - rc4key[6] = ppk1 % 256; 851 - rc4key[7] = (ppk1 >> 8) % 256; 852 - 853 - rc4key[8] = ppk2 % 256; 854 - rc4key[9] = (ppk2 >> 8) % 256; 855 - 856 - rc4key[10] = ppk3 % 256; 857 - rc4key[11] = (ppk3 >> 8) % 256; 858 - 859 - rc4key[12] = ppk4 % 256; 860 - rc4key[13] = (ppk4 >> 8) % 256; 861 - 862 - rc4key[14] = ppk5 % 256; 863 - rc4key[15] = (ppk5 >> 8) % 256; 864 - } 865 - 866 - 867 - /************************************************/ 868 - /* construct_mic_header1() */ 869 - /* Builds the first MIC header block from */ 870 - /* header fields. */ 871 - /************************************************/ 872 - 873 - void construct_mic_header1( 874 - unsigned char *mic_header1, 875 - int header_length, 876 - unsigned char *mpdu) 877 - { 878 - mic_header1[0] = (unsigned char)((header_length - 2) / 256); 879 - mic_header1[1] = (unsigned char)((header_length - 2) % 256); 880 - mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */ 881 - mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */ 882 - mic_header1[4] = mpdu[4]; /* A1 */ 883 - mic_header1[5] = mpdu[5]; 884 - mic_header1[6] = mpdu[6]; 885 - mic_header1[7] = mpdu[7]; 886 - mic_header1[8] = mpdu[8]; 887 - mic_header1[9] = mpdu[9]; 888 - mic_header1[10] = mpdu[10]; /* A2 */ 889 - mic_header1[11] = mpdu[11]; 890 - mic_header1[12] = mpdu[12]; 891 - mic_header1[13] = mpdu[13]; 892 - mic_header1[14] = mpdu[14]; 893 - mic_header1[15] = mpdu[15]; 894 - } 895 - 896 - /************************************************/ 897 - /* construct_mic_header2() */ 898 - /* Builds the last MIC header block from */ 899 - /* header fields. */ 900 - /************************************************/ 901 - 902 - void construct_mic_header2( 903 - unsigned char *mic_header2, 904 - unsigned char *mpdu, 905 - int a4_exists, 906 - int qc_exists) 907 - { 908 - int i; 909 - 910 - for (i = 0; i<16; i++) mic_header2[i]=0x00; 911 - 912 - mic_header2[0] = mpdu[16]; /* A3 */ 913 - mic_header2[1] = mpdu[17]; 914 - mic_header2[2] = mpdu[18]; 915 - mic_header2[3] = mpdu[19]; 916 - mic_header2[4] = mpdu[20]; 917 - mic_header2[5] = mpdu[21]; 918 - 919 - // In Sequence Control field, mute sequence numer bits (12-bit) 920 - mic_header2[6] = mpdu[22] & 0x0f; /* SC */ 921 - mic_header2[7] = 0x00; /* mpdu[23]; */ 922 - 923 - if ((!qc_exists) & a4_exists) 924 - { 925 - for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */ 926 - 927 - } 928 - 929 - if (qc_exists && (!a4_exists)) 930 - { 931 - mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */ 932 - mic_header2[9] = mpdu[25] & 0x00; 933 - } 934 - 935 - if (qc_exists && a4_exists) 936 - { 937 - for (i=0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */ 938 - 939 - mic_header2[14] = mpdu[30] & 0x0f; 940 - mic_header2[15] = mpdu[31] & 0x00; 941 - } 942 - } 943 - 944 - 945 - /************************************************/ 946 - /* construct_mic_iv() */ 947 - /* Builds the MIC IV from header fields and PN */ 948 - /************************************************/ 949 - 950 - void construct_mic_iv( 951 - unsigned char *mic_iv, 952 - int qc_exists, 953 - int a4_exists, 954 - unsigned char *mpdu, 955 - unsigned int payload_length, 956 - unsigned char *pn_vector) 957 - { 958 - int i; 959 - 960 - mic_iv[0] = 0x59; 961 - if (qc_exists && a4_exists) 962 - mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */ 963 - if (qc_exists && !a4_exists) 964 - mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */ 965 - if (!qc_exists) 966 - mic_iv[1] = 0x00; 967 - for (i = 2; i < 8; i++) 968 - mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */ 969 - #ifdef CONSISTENT_PN_ORDER 970 - for (i = 8; i < 14; i++) 971 - mic_iv[i] = pn_vector[i - 8]; /* mic_iv[8:13] = PN[0:5] */ 972 - #else 973 - for (i = 8; i < 14; i++) 974 - mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ 975 - #endif 976 - i = (payload_length / 256); 977 - i = (payload_length % 256); 978 - mic_iv[14] = (unsigned char) (payload_length / 256); 979 - mic_iv[15] = (unsigned char) (payload_length % 256); 980 - 981 - } 982 - 983 - 984 - 985 - /************************************/ 986 - /* bitwise_xor() */ 987 - /* A 128 bit, bitwise exclusive or */ 988 - /************************************/ 989 - 990 - void bitwise_xor(unsigned char *ina, unsigned char *inb, unsigned char *out) 991 - { 992 - int i; 993 - for (i=0; i<16; i++) 994 - { 995 - out[i] = ina[i] ^ inb[i]; 996 - } 997 - } 998 - 999 - 1000 - void aes128k128d(unsigned char *key, unsigned char *data, unsigned char *ciphertext) 1001 - { 1002 - int round; 1003 - int i; 1004 - unsigned char intermediatea[16]; 1005 - unsigned char intermediateb[16]; 1006 - unsigned char round_key[16]; 1007 - 1008 - for(i=0; i<16; i++) round_key[i] = key[i]; 1009 - 1010 - for (round = 0; round < 11; round++) 1011 - { 1012 - if (round == 0) 1013 - { 1014 - xor_128(round_key, data, ciphertext); 1015 - next_key(round_key, round); 1016 - } 1017 - else if (round == 10) 1018 - { 1019 - byte_sub(ciphertext, intermediatea); 1020 - shift_row(intermediatea, intermediateb); 1021 - xor_128(intermediateb, round_key, ciphertext); 1022 - } 1023 - else /* 1 - 9 */ 1024 - { 1025 - byte_sub(ciphertext, intermediatea); 1026 - shift_row(intermediatea, intermediateb); 1027 - mix_column(&intermediateb[0], &intermediatea[0]); 1028 - mix_column(&intermediateb[4], &intermediatea[4]); 1029 - mix_column(&intermediateb[8], &intermediatea[8]); 1030 - mix_column(&intermediateb[12], &intermediatea[12]); 1031 - xor_128(intermediatea, round_key, ciphertext); 1032 - next_key(round_key, round); 1033 - } 1034 - } 1035 - 1036 - } 1037 - 1038 - void construct_ctr_preload( 1039 - unsigned char *ctr_preload, 1040 - int a4_exists, 1041 - int qc_exists, 1042 - unsigned char *mpdu, 1043 - unsigned char *pn_vector, 1044 - int c) 1045 - { 1046 - 1047 - int i = 0; 1048 - for (i=0; i<16; i++) ctr_preload[i] = 0x00; 1049 - i = 0; 1050 - 1051 - ctr_preload[0] = 0x01; /* flag */ 1052 - if (qc_exists && a4_exists) ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */ 1053 - if (qc_exists && !a4_exists) ctr_preload[1] = mpdu[24] & 0x0f; 1054 - 1055 - for (i = 2; i < 8; i++) 1056 - ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */ 1057 - #ifdef CONSISTENT_PN_ORDER 1058 - for (i = 8; i < 14; i++) 1059 - ctr_preload[i] = pn_vector[i - 8]; /* ctr_preload[8:13] = PN[0:5] */ 1060 - #else 1061 - for (i = 8; i < 14; i++) 1062 - ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */ 1063 - #endif 1064 - ctr_preload[14] = (unsigned char) (c / 256); // Ctr 1065 - ctr_preload[15] = (unsigned char) (c % 256); 1066 - 1067 - } 1068 - 1069 - 1070 - // 1071 - // TRUE: Success! 1072 - // FALSE: Decrypt Error! 1073 - // 1074 - BOOLEAN RTMPSoftDecryptTKIP( 1075 - IN PRTMP_ADAPTER pAd, 1076 - IN PUCHAR pData, 1077 - IN ULONG DataByteCnt, 1078 - IN UCHAR UserPriority, 1079 - IN PCIPHER_KEY pWpaKey) 1080 - { 1081 - UCHAR KeyID; 1082 - UINT HeaderLen; 1083 - UCHAR fc0; 1084 - UCHAR fc1; 1085 - USHORT fc; 1086 - UINT frame_type; 1087 - UINT frame_subtype; 1088 - UINT from_ds; 1089 - UINT to_ds; 1090 - INT a4_exists; 1091 - INT qc_exists; 1092 - USHORT duration; 1093 - USHORT seq_control; 1094 - USHORT qos_control; 1095 - UCHAR TA[MAC_ADDR_LEN]; 1096 - UCHAR DA[MAC_ADDR_LEN]; 1097 - UCHAR SA[MAC_ADDR_LEN]; 1098 - UCHAR RC4Key[16]; 1099 - UINT p1k[5]; //for mix_key; 1100 - ULONG pnl;/* Least significant 16 bits of PN */ 1101 - ULONG pnh;/* Most significant 32 bits of PN */ 1102 - UINT num_blocks; 1103 - UINT payload_remainder; 1104 - ARCFOURCONTEXT ArcFourContext; 1105 - UINT crc32 = 0; 1106 - UINT trailfcs = 0; 1107 - UCHAR MIC[8]; 1108 - UCHAR TrailMIC[8]; 1109 - 1110 - fc0 = *pData; 1111 - fc1 = *(pData + 1); 1112 - 1113 - fc = *((PUSHORT)pData); 1114 - 1115 - frame_type = ((fc0 >> 2) & 0x03); 1116 - frame_subtype = ((fc0 >> 4) & 0x0f); 1117 - 1118 - from_ds = (fc1 & 0x2) >> 1; 1119 - to_ds = (fc1 & 0x1); 1120 - 1121 - a4_exists = (from_ds & to_ds); 1122 - qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */ 1123 - (frame_subtype == 0x09) || /* Likely to change. */ 1124 - (frame_subtype == 0x0a) || 1125 - (frame_subtype == 0x0b) 1126 - ); 1127 - 1128 - HeaderLen = 24; 1129 - if (a4_exists) 1130 - HeaderLen += 6; 1131 - 1132 - KeyID = *((PUCHAR)(pData+ HeaderLen + 3)); 1133 - KeyID = KeyID >> 6; 1134 - 1135 - if (pWpaKey[KeyID].KeyLen == 0) 1136 - { 1137 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP failed!(KeyID[%d] Length can not be 0)\n", KeyID)); 1138 - return FALSE; 1139 - } 1140 - 1141 - duration = *((PUSHORT)(pData+2)); 1142 - 1143 - seq_control = *((PUSHORT)(pData+22)); 1144 - 1145 - if (qc_exists) 1146 - { 1147 - if (a4_exists) 1148 - { 1149 - qos_control = *((PUSHORT)(pData+30)); 1150 - } 1151 - else 1152 - { 1153 - qos_control = *((PUSHORT)(pData+24)); 1154 - } 1155 - } 1156 - 1157 - if (to_ds == 0 && from_ds == 1) 1158 - { 1159 - NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN); 1160 - NdisMoveMemory(SA, pData+16, MAC_ADDR_LEN); 1161 - NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); //BSSID 1162 - } 1163 - else if (to_ds == 0 && from_ds == 0 ) 1164 - { 1165 - NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); 1166 - NdisMoveMemory(DA, pData+4, MAC_ADDR_LEN); 1167 - NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN); 1168 - } 1169 - else if (to_ds == 1 && from_ds == 0) 1170 - { 1171 - NdisMoveMemory(SA, pData+10, MAC_ADDR_LEN); 1172 - NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); 1173 - NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN); 1174 - } 1175 - else if (to_ds == 1 && from_ds == 1) 1176 - { 1177 - NdisMoveMemory(TA, pData+10, MAC_ADDR_LEN); 1178 - NdisMoveMemory(DA, pData+16, MAC_ADDR_LEN); 1179 - NdisMoveMemory(SA, pData+22, MAC_ADDR_LEN); 1180 - } 1181 - 1182 - num_blocks = (DataByteCnt - 16) / 16; 1183 - payload_remainder = (DataByteCnt - 16) % 16; 1184 - 1185 - pnl = (*(pData + HeaderLen)) * 256 + *(pData + HeaderLen + 2); 1186 - pnh = *((PULONG)(pData + HeaderLen + 4)); 1187 - pnh = cpu2le32(pnh); 1188 - RTMPTkipMixKey(pWpaKey[KeyID].Key, TA, pnl, pnh, RC4Key, p1k); 1189 - 1190 - ARCFOUR_INIT(&ArcFourContext, RC4Key, 16); 1191 - 1192 - ARCFOUR_DECRYPT(&ArcFourContext, pData + HeaderLen, pData + HeaderLen + 8, DataByteCnt - HeaderLen - 8); 1193 - NdisMoveMemory(&trailfcs, pData + DataByteCnt - 8 - 4, 4); 1194 - crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 4); //Skip IV+EIV 8 bytes & Skip last 4 bytes(FCS). 1195 - crc32 ^= 0xffffffff; /* complement */ 1196 - 1197 - if(crc32 != cpu2le32(trailfcs)) 1198 - { 1199 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP, WEP Data ICV Error !\n")); //ICV error. 1200 - 1201 - return (FALSE); 1202 - } 1203 - 1204 - NdisMoveMemory(TrailMIC, pData + DataByteCnt - 8 - 8 - 4, 8); 1205 - RTMPInitMICEngine(pAd, pWpaKey[KeyID].Key, DA, SA, UserPriority, pWpaKey[KeyID].RxMic); 1206 - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 12); 1207 - RTMPTkipGetMIC(&pAd->PrivateInfo.Tx); 1208 - NdisMoveMemory(MIC, pAd->PrivateInfo.Tx.MIC, 8); 1209 - 1210 - if (!NdisEqualMemory(MIC, TrailMIC, 8)) 1211 - { 1212 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptTKIP, WEP Data MIC Error !\n")); //MIC error. 1213 - return (FALSE); 1214 - } 1215 - 1216 - return TRUE; 1217 - } 1218 - 1219 - 1220 - 1221 - 1222 - BOOLEAN RTMPSoftDecryptAES( 1223 - IN PRTMP_ADAPTER pAd, 1224 - IN PUCHAR pData, 1225 - IN ULONG DataByteCnt, 1226 - IN PCIPHER_KEY pWpaKey) 1227 - { 1228 - UCHAR KeyID; 1229 - UINT HeaderLen; 1230 - UCHAR PN[6]; 1231 - UINT payload_len; 1232 - UINT num_blocks; 1233 - UINT payload_remainder; 1234 - USHORT fc; 1235 - UCHAR fc0; 1236 - UCHAR fc1; 1237 - UINT frame_type; 1238 - UINT frame_subtype; 1239 - UINT from_ds; 1240 - UINT to_ds; 1241 - INT a4_exists; 1242 - INT qc_exists; 1243 - UCHAR aes_out[16]; 1244 - int payload_index; 1245 - UINT i; 1246 - UCHAR ctr_preload[16]; 1247 - UCHAR chain_buffer[16]; 1248 - UCHAR padded_buffer[16]; 1249 - UCHAR mic_iv[16]; 1250 - UCHAR mic_header1[16]; 1251 - UCHAR mic_header2[16]; 1252 - UCHAR MIC[8]; 1253 - UCHAR TrailMIC[8]; 1254 - 1255 - fc0 = *pData; 1256 - fc1 = *(pData + 1); 1257 - 1258 - fc = *((PUSHORT)pData); 1259 - 1260 - frame_type = ((fc0 >> 2) & 0x03); 1261 - frame_subtype = ((fc0 >> 4) & 0x0f); 1262 - 1263 - from_ds = (fc1 & 0x2) >> 1; 1264 - to_ds = (fc1 & 0x1); 1265 - 1266 - a4_exists = (from_ds & to_ds); 1267 - qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */ 1268 - (frame_subtype == 0x09) || /* Likely to change. */ 1269 - (frame_subtype == 0x0a) || 1270 - (frame_subtype == 0x0b) 1271 - ); 1272 - 1273 - HeaderLen = 24; 1274 - if (a4_exists) 1275 - HeaderLen += 6; 1276 - 1277 - KeyID = *((PUCHAR)(pData+ HeaderLen + 3)); 1278 - KeyID = KeyID >> 6; 1279 - 1280 - if (pWpaKey[KeyID].KeyLen == 0) 1281 - { 1282 - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptAES failed!(KeyID[%d] Length can not be 0)\n", KeyID)); 1283 - return FALSE; 1284 - } 1285 - 1286 - PN[0] = *(pData+ HeaderLen); 1287 - PN[1] = *(pData+ HeaderLen + 1); 1288 - PN[2] = *(pData+ HeaderLen + 4); 1289 - PN[3] = *(pData+ HeaderLen + 5); 1290 - PN[4] = *(pData+ HeaderLen + 6); 1291 - PN[5] = *(pData+ HeaderLen + 7); 1292 - 1293 - payload_len = DataByteCnt - HeaderLen - 8 - 8; // 8 bytes for CCMP header , 8 bytes for MIC 1294 - payload_remainder = (payload_len) % 16; 1295 - num_blocks = (payload_len) / 16; 1296 - 1297 - 1298 - 1299 - // Find start of payload 1300 - payload_index = HeaderLen + 8; //IV+EIV 1301 - 1302 - for (i=0; i< num_blocks; i++) 1303 - { 1304 - construct_ctr_preload(ctr_preload, 1305 - a4_exists, 1306 - qc_exists, 1307 - pData, 1308 - PN, 1309 - i+1 ); 1310 - 1311 - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); 1312 - 1313 - bitwise_xor(aes_out, pData + payload_index, chain_buffer); 1314 - NdisMoveMemory(pData + payload_index - 8, chain_buffer, 16); 1315 - payload_index += 16; 1316 - } 1317 - 1318 - // 1319 - // If there is a short final block, then pad it 1320 - // encrypt it and copy the unpadded part back 1321 - // 1322 - if (payload_remainder > 0) 1323 - { 1324 - construct_ctr_preload(ctr_preload, 1325 - a4_exists, 1326 - qc_exists, 1327 - pData, 1328 - PN, 1329 - num_blocks + 1); 1330 - 1331 - NdisZeroMemory(padded_buffer, 16); 1332 - NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder); 1333 - 1334 - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); 1335 - 1336 - bitwise_xor(aes_out, padded_buffer, chain_buffer); 1337 - NdisMoveMemory(pData + payload_index - 8, chain_buffer, payload_remainder); 1338 - payload_index += payload_remainder; 1339 - } 1340 - 1341 - // 1342 - // Descrypt the MIC 1343 - // 1344 - construct_ctr_preload(ctr_preload, 1345 - a4_exists, 1346 - qc_exists, 1347 - pData, 1348 - PN, 1349 - 0); 1350 - NdisZeroMemory(padded_buffer, 16); 1351 - NdisMoveMemory(padded_buffer, pData + payload_index, 8); 1352 - 1353 - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); 1354 - 1355 - bitwise_xor(aes_out, padded_buffer, chain_buffer); 1356 - 1357 - NdisMoveMemory(TrailMIC, chain_buffer, 8); 1358 - 1359 - // 1360 - // Calculate MIC 1361 - // 1362 - 1363 - //Force the protected frame bit on 1364 - *(pData + 1) = *(pData + 1) | 0x40; 1365 - 1366 - // Find start of payload 1367 - // Because the CCMP header has been removed 1368 - payload_index = HeaderLen; 1369 - 1370 - construct_mic_iv( 1371 - mic_iv, 1372 - qc_exists, 1373 - a4_exists, 1374 - pData, 1375 - payload_len, 1376 - PN); 1377 - 1378 - construct_mic_header1( 1379 - mic_header1, 1380 - HeaderLen, 1381 - pData); 1382 - 1383 - construct_mic_header2( 1384 - mic_header2, 1385 - pData, 1386 - a4_exists, 1387 - qc_exists); 1388 - 1389 - aes128k128d(pWpaKey[KeyID].Key, mic_iv, aes_out); 1390 - bitwise_xor(aes_out, mic_header1, chain_buffer); 1391 - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); 1392 - bitwise_xor(aes_out, mic_header2, chain_buffer); 1393 - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); 1394 - 1395 - // iterate through each 16 byte payload block 1396 - for (i = 0; i < num_blocks; i++) 1397 - { 1398 - bitwise_xor(aes_out, pData + payload_index, chain_buffer); 1399 - payload_index += 16; 1400 - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); 1401 - } 1402 - 1403 - // Add on the final payload block if it needs padding 1404 - if (payload_remainder > 0) 1405 - { 1406 - NdisZeroMemory(padded_buffer, 16); 1407 - NdisMoveMemory(padded_buffer, pData + payload_index, payload_remainder); 1408 - 1409 - bitwise_xor(aes_out, padded_buffer, chain_buffer); 1410 - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); 1411 - } 1412 - 1413 - // aes_out contains padded mic, discard most significant 1414 - // 8 bytes to generate 64 bit MIC 1415 - for (i = 0 ; i < 8; i++) MIC[i] = aes_out[i]; 1416 - 1417 - if (!NdisEqualMemory(MIC, TrailMIC, 8)) 1418 - { 1419 - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptAES, MIC Error !\n")); //MIC error. 1420 - return FALSE; 1421 - } 1422 - 1423 - return TRUE; 1424 - } 1425 - 1426 - /****************************************/ 1427 - /* aes128k128d() */ 1428 - /* Performs a 128 bit AES encrypt with */ 1429 - /* 128 bit data. */ 1430 - /****************************************/ 1431 - VOID xor_128( 1432 - IN PUCHAR a, 1433 - IN PUCHAR b, 1434 - OUT PUCHAR out) 1435 - { 1436 - INT i; 1437 - 1438 - for (i=0;i<16; i++) 1439 - { 1440 - out[i] = a[i] ^ b[i]; 1441 - } 1442 - } 1443 - 1444 - VOID next_key( 1445 - IN PUCHAR key, 1446 - IN INT round) 1447 - { 1448 - UCHAR rcon; 1449 - UCHAR sbox_key[4]; 1450 - UCHAR rcon_table[12] = 1451 - { 1452 - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 1453 - 0x1b, 0x36, 0x36, 0x36 1454 - }; 1455 - 1456 - sbox_key[0] = RTMPCkipSbox(key[13]); 1457 - sbox_key[1] = RTMPCkipSbox(key[14]); 1458 - sbox_key[2] = RTMPCkipSbox(key[15]); 1459 - sbox_key[3] = RTMPCkipSbox(key[12]); 1460 - 1461 - rcon = rcon_table[round]; 1462 - 1463 - xor_32(&key[0], sbox_key, &key[0]); 1464 - key[0] = key[0] ^ rcon; 1465 - 1466 - xor_32(&key[4], &key[0], &key[4]); 1467 - xor_32(&key[8], &key[4], &key[8]); 1468 - xor_32(&key[12], &key[8], &key[12]); 1469 - } 1470 - 1471 - VOID xor_32( 1472 - IN PUCHAR a, 1473 - IN PUCHAR b, 1474 - OUT PUCHAR out) 1475 - { 1476 - INT i; 1477 - 1478 - for (i=0;i<4; i++) 1479 - { 1480 - out[i] = a[i] ^ b[i]; 1481 - } 1482 - } 1483 - 1484 - VOID byte_sub( 1485 - IN PUCHAR in, 1486 - OUT PUCHAR out) 1487 - { 1488 - INT i; 1489 - 1490 - for (i=0; i< 16; i++) 1491 - { 1492 - out[i] = RTMPCkipSbox(in[i]); 1493 - } 1494 - } 1495 - 1496 - UCHAR RTMPCkipSbox( 1497 - IN UCHAR a) 1498 - { 1499 - return SboxTable[(int)a]; 1500 - } 1501 - 1502 - VOID shift_row( 1503 - IN PUCHAR in, 1504 - OUT PUCHAR out) 1505 - { 1506 - out[0] = in[0]; 1507 - out[1] = in[5]; 1508 - out[2] = in[10]; 1509 - out[3] = in[15]; 1510 - out[4] = in[4]; 1511 - out[5] = in[9]; 1512 - out[6] = in[14]; 1513 - out[7] = in[3]; 1514 - out[8] = in[8]; 1515 - out[9] = in[13]; 1516 - out[10] = in[2]; 1517 - out[11] = in[7]; 1518 - out[12] = in[12]; 1519 - out[13] = in[1]; 1520 - out[14] = in[6]; 1521 - out[15] = in[11]; 1522 - } 1523 - 1524 - VOID mix_column( 1525 - IN PUCHAR in, 1526 - OUT PUCHAR out) 1527 - { 1528 - INT i; 1529 - UCHAR add1b[4]; 1530 - UCHAR add1bf7[4]; 1531 - UCHAR rotl[4]; 1532 - UCHAR swap_halfs[4]; 1533 - UCHAR andf7[4]; 1534 - UCHAR rotr[4]; 1535 - UCHAR temp[4]; 1536 - UCHAR tempb[4]; 1537 - 1538 - for (i=0 ; i<4; i++) 1539 - { 1540 - if ((in[i] & 0x80)== 0x80) 1541 - add1b[i] = 0x1b; 1542 - else 1543 - add1b[i] = 0x00; 1544 - } 1545 - 1546 - swap_halfs[0] = in[2]; /* Swap halfs */ 1547 - swap_halfs[1] = in[3]; 1548 - swap_halfs[2] = in[0]; 1549 - swap_halfs[3] = in[1]; 1550 - 1551 - rotl[0] = in[3]; /* Rotate left 8 bits */ 1552 - rotl[1] = in[0]; 1553 - rotl[2] = in[1]; 1554 - rotl[3] = in[2]; 1555 - 1556 - andf7[0] = in[0] & 0x7f; 1557 - andf7[1] = in[1] & 0x7f; 1558 - andf7[2] = in[2] & 0x7f; 1559 - andf7[3] = in[3] & 0x7f; 1560 - 1561 - for (i = 3; i>0; i--) /* logical shift left 1 bit */ 1562 - { 1563 - andf7[i] = andf7[i] << 1; 1564 - if ((andf7[i-1] & 0x80) == 0x80) 1565 - { 1566 - andf7[i] = (andf7[i] | 0x01); 1567 - } 1568 - } 1569 - andf7[0] = andf7[0] << 1; 1570 - andf7[0] = andf7[0] & 0xfe; 1571 - 1572 - xor_32(add1b, andf7, add1bf7); 1573 - 1574 - xor_32(in, add1bf7, rotr); 1575 - 1576 - temp[0] = rotr[0]; /* Rotate right 8 bits */ 1577 - rotr[0] = rotr[1]; 1578 - rotr[1] = rotr[2]; 1579 - rotr[2] = rotr[3]; 1580 - rotr[3] = temp[0]; 1581 - 1582 - xor_32(add1bf7, rotr, temp); 1583 - xor_32(swap_halfs, rotl,tempb); 1584 - xor_32(temp, tempb, out); 1585 - } 1586 - 1 + #include "../../rt2860/common/rtmp_tkip.c"
+1 -497
drivers/staging/rt2870/common/rtmp_wep.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - rtmp_wep.c 29 - 30 - Abstract: 31 - 32 - Revision History: 33 - Who When What 34 - -------- ---------- ---------------------------------------------- 35 - Paul Wu 10-28-02 Initial 36 - */ 37 - 38 - #include "../rt_config.h" 39 - 40 - UINT FCSTAB_32[256] = 41 - { 42 - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 43 - 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 44 - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 45 - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 46 - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 47 - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 48 - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 49 - 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 50 - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 51 - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 52 - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 53 - 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 54 - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 55 - 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 56 - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 57 - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 58 - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 59 - 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 60 - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 61 - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 62 - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 63 - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 64 - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 65 - 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 66 - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 67 - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 68 - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 69 - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 70 - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 71 - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 72 - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 73 - 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 74 - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 75 - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 76 - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 77 - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 78 - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 79 - 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 80 - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 81 - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 82 - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 83 - 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 84 - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 85 - 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 86 - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 87 - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 88 - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 89 - 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 90 - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 91 - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 92 - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 93 - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 94 - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 95 - 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 96 - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 97 - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 98 - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 99 - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 100 - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 101 - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 102 - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 103 - 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 104 - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 105 - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 106 - }; 107 - 108 - /* 109 - ======================================================================== 110 - 111 - Routine Description: 112 - Init WEP function. 113 - 114 - Arguments: 115 - pAd Pointer to our adapter 116 - pKey Pointer to the WEP KEY 117 - KeyId WEP Key ID 118 - KeyLen the length of WEP KEY 119 - pDest Pointer to the destination which Encryption data will store in. 120 - 121 - Return Value: 122 - None 123 - 124 - IRQL = DISPATCH_LEVEL 125 - 126 - Note: 127 - 128 - ======================================================================== 129 - */ 130 - VOID RTMPInitWepEngine( 131 - IN PRTMP_ADAPTER pAd, 132 - IN PUCHAR pKey, 133 - IN UCHAR KeyId, 134 - IN UCHAR KeyLen, 135 - IN OUT PUCHAR pDest) 136 - { 137 - UINT i; 138 - UCHAR WEPKEY[] = { 139 - //IV 140 - 0x00, 0x11, 0x22, 141 - //WEP KEY 142 - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC 143 - }; 144 - 145 - pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32. 146 - 147 - if (pAd->StaCfg.bCkipOn && (pAd->StaCfg.CkipFlag & 0x10) && (pAd->OpMode == OPMODE_STA)) 148 - { 149 - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, pKey, KeyLen); //INIT SBOX, KEYLEN+3(IV) 150 - NdisMoveMemory(pDest, pKey, 3); //Append Init Vector 151 - } 152 - else 153 - { 154 - NdisMoveMemory(WEPKEY + 3, pKey, KeyLen); 155 - 156 - for(i = 0; i < 3; i++) 157 - WEPKEY[i] = RandomByte(pAd); //Call mlme RandomByte() function. 158 - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, KeyLen + 3); //INIT SBOX, KEYLEN+3(IV) 159 - 160 - NdisMoveMemory(pDest, WEPKEY, 3); //Append Init Vector 161 - } 162 - *(pDest+3) = (KeyId << 6); //Append KEYID 163 - 164 - } 165 - 166 - /* 167 - ======================================================================== 168 - 169 - Routine Description: 170 - Encrypt transimitted data 171 - 172 - Arguments: 173 - pAd Pointer to our adapter 174 - pSrc Pointer to the transimitted source data that will be encrypt 175 - pDest Pointer to the destination where entryption data will be store in. 176 - Len Indicate the length of the source data 177 - 178 - Return Value: 179 - None 180 - 181 - IRQL = DISPATCH_LEVEL 182 - 183 - Note: 184 - 185 - ======================================================================== 186 - */ 187 - VOID RTMPEncryptData( 188 - IN PRTMP_ADAPTER pAd, 189 - IN PUCHAR pSrc, 190 - IN PUCHAR pDest, 191 - IN UINT Len) 192 - { 193 - pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, pSrc, Len); 194 - ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, pSrc, Len); 195 - } 196 - 197 - 198 - /* 199 - ======================================================================== 200 - 201 - Routine Description: 202 - Decrypt received WEP data 203 - 204 - Arguments: 205 - pAdapter Pointer to our adapter 206 - pSrc Pointer to the received data 207 - Len the length of the received data 208 - 209 - Return Value: 210 - TRUE Decrypt WEP data success 211 - FALSE Decrypt WEP data failed 212 - 213 - Note: 214 - 215 - ======================================================================== 216 - */ 217 - BOOLEAN RTMPSoftDecryptWEP( 218 - IN PRTMP_ADAPTER pAd, 219 - IN PUCHAR pData, 220 - IN ULONG DataByteCnt, 221 - IN PCIPHER_KEY pGroupKey) 222 - { 223 - UINT trailfcs; 224 - UINT crc32; 225 - UCHAR KeyIdx; 226 - UCHAR WEPKEY[] = { 227 - //IV 228 - 0x00, 0x11, 0x22, 229 - //WEP KEY 230 - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC 231 - }; 232 - UCHAR *pPayload = (UCHAR *)pData + LENGTH_802_11; 233 - ULONG payload_len = DataByteCnt - LENGTH_802_11; 234 - 235 - NdisMoveMemory(WEPKEY, pPayload, 3); //Get WEP IV 236 - 237 - KeyIdx = (*(pPayload + 3) & 0xc0) >> 6; 238 - if (pGroupKey[KeyIdx].KeyLen == 0) 239 - return (FALSE); 240 - 241 - NdisMoveMemory(WEPKEY + 3, pGroupKey[KeyIdx].Key, pGroupKey[KeyIdx].KeyLen); 242 - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, pGroupKey[KeyIdx].KeyLen + 3); 243 - ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, pPayload, pPayload + 4, payload_len - 4); 244 - NdisMoveMemory(&trailfcs, pPayload + payload_len - 8, 4); 245 - crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pPayload, payload_len - 8); //Skip last 4 bytes(FCS). 246 - crc32 ^= 0xffffffff; /* complement */ 247 - 248 - if(crc32 != cpu2le32(trailfcs)) 249 - { 250 - DBGPRINT(RT_DEBUG_TRACE, ("! WEP Data CRC Error !\n")); //CRC error. 251 - return (FALSE); 252 - } 253 - return (TRUE); 254 - } 255 - 256 - /* 257 - ======================================================================== 258 - 259 - Routine Description: 260 - The Stream Cipher Encryption Algorithm "ARCFOUR" initialize 261 - 262 - Arguments: 263 - Ctx Pointer to ARCFOUR CONTEXT (SBOX) 264 - pKey Pointer to the WEP KEY 265 - KeyLen Indicate the length fo the WEP KEY 266 - 267 - Return Value: 268 - None 269 - 270 - IRQL = DISPATCH_LEVEL 271 - 272 - Note: 273 - 274 - ======================================================================== 275 - */ 276 - VOID ARCFOUR_INIT( 277 - IN PARCFOURCONTEXT Ctx, 278 - IN PUCHAR pKey, 279 - IN UINT KeyLen) 280 - { 281 - UCHAR t, u; 282 - UINT keyindex; 283 - UINT stateindex; 284 - PUCHAR state; 285 - UINT counter; 286 - 287 - state = Ctx->STATE; 288 - Ctx->X = 0; 289 - Ctx->Y = 0; 290 - for (counter = 0; counter < 256; counter++) 291 - state[counter] = (UCHAR)counter; 292 - keyindex = 0; 293 - stateindex = 0; 294 - for (counter = 0; counter < 256; counter++) 295 - { 296 - t = state[counter]; 297 - stateindex = (stateindex + pKey[keyindex] + t) & 0xff; 298 - u = state[stateindex]; 299 - state[stateindex] = t; 300 - state[counter] = u; 301 - if (++keyindex >= KeyLen) 302 - keyindex = 0; 303 - } 304 - } 305 - 306 - /* 307 - ======================================================================== 308 - 309 - Routine Description: 310 - Get bytes from ARCFOUR CONTEXT (S-BOX) 311 - 312 - Arguments: 313 - Ctx Pointer to ARCFOUR CONTEXT (SBOX) 314 - 315 - Return Value: 316 - UCHAR - the value of the ARCFOUR CONTEXT (S-BOX) 317 - 318 - Note: 319 - 320 - ======================================================================== 321 - */ 322 - UCHAR ARCFOUR_BYTE( 323 - IN PARCFOURCONTEXT Ctx) 324 - { 325 - UINT x; 326 - UINT y; 327 - UCHAR sx, sy; 328 - PUCHAR state; 329 - 330 - state = Ctx->STATE; 331 - x = (Ctx->X + 1) & 0xff; 332 - sx = state[x]; 333 - y = (sx + Ctx->Y) & 0xff; 334 - sy = state[y]; 335 - Ctx->X = x; 336 - Ctx->Y = y; 337 - state[y] = sx; 338 - state[x] = sy; 339 - 340 - return(state[(sx + sy) & 0xff]); 341 - 342 - } 343 - 344 - /* 345 - ======================================================================== 346 - 347 - Routine Description: 348 - The Stream Cipher Decryption Algorithm 349 - 350 - Arguments: 351 - Ctx Pointer to ARCFOUR CONTEXT (SBOX) 352 - pDest Pointer to the Destination 353 - pSrc Pointer to the Source data 354 - Len Indicate the length of the Source data 355 - 356 - Return Value: 357 - None 358 - 359 - Note: 360 - 361 - ======================================================================== 362 - */ 363 - VOID ARCFOUR_DECRYPT( 364 - IN PARCFOURCONTEXT Ctx, 365 - IN PUCHAR pDest, 366 - IN PUCHAR pSrc, 367 - IN UINT Len) 368 - { 369 - UINT i; 370 - 371 - for (i = 0; i < Len; i++) 372 - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); 373 - } 374 - 375 - /* 376 - ======================================================================== 377 - 378 - Routine Description: 379 - The Stream Cipher Encryption Algorithm 380 - 381 - Arguments: 382 - Ctx Pointer to ARCFOUR CONTEXT (SBOX) 383 - pDest Pointer to the Destination 384 - pSrc Pointer to the Source data 385 - Len Indicate the length of the Source dta 386 - 387 - Return Value: 388 - None 389 - 390 - IRQL = DISPATCH_LEVEL 391 - 392 - Note: 393 - 394 - ======================================================================== 395 - */ 396 - VOID ARCFOUR_ENCRYPT( 397 - IN PARCFOURCONTEXT Ctx, 398 - IN PUCHAR pDest, 399 - IN PUCHAR pSrc, 400 - IN UINT Len) 401 - { 402 - UINT i; 403 - 404 - for (i = 0; i < Len; i++) 405 - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); 406 - } 407 - 408 - /* 409 - ======================================================================== 410 - 411 - Routine Description: 412 - The Stream Cipher Encryption Algorithm which conform to the special requirement to encrypt GTK. 413 - 414 - Arguments: 415 - Ctx Pointer to ARCFOUR CONTEXT (SBOX) 416 - pDest Pointer to the Destination 417 - pSrc Pointer to the Source data 418 - Len Indicate the length of the Source dta 419 - 420 - 421 - ======================================================================== 422 - */ 423 - 424 - VOID WPAARCFOUR_ENCRYPT( 425 - IN PARCFOURCONTEXT Ctx, 426 - IN PUCHAR pDest, 427 - IN PUCHAR pSrc, 428 - IN UINT Len) 429 - { 430 - UINT i; 431 - //discard first 256 bytes 432 - for (i = 0; i < 256; i++) 433 - ARCFOUR_BYTE(Ctx); 434 - 435 - for (i = 0; i < Len; i++) 436 - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); 437 - } 438 - 439 - 440 - /* 441 - ======================================================================== 442 - 443 - Routine Description: 444 - Calculate a new FCS given the current FCS and the new data. 445 - 446 - Arguments: 447 - Fcs the original FCS value 448 - Cp pointer to the data which will be calculate the FCS 449 - Len the length of the data 450 - 451 - Return Value: 452 - UINT - FCS 32 bits 453 - 454 - IRQL = DISPATCH_LEVEL 455 - 456 - Note: 457 - 458 - ======================================================================== 459 - */ 460 - UINT RTMP_CALC_FCS32( 461 - IN UINT Fcs, 462 - IN PUCHAR Cp, 463 - IN INT Len) 464 - { 465 - while (Len--) 466 - Fcs = (((Fcs) >> 8) ^ FCSTAB_32[((Fcs) ^ (*Cp++)) & 0xff]); 467 - 468 - return (Fcs); 469 - } 470 - 471 - 472 - /* 473 - ======================================================================== 474 - 475 - Routine Description: 476 - Get last FCS and encrypt it to the destination 477 - 478 - Arguments: 479 - pDest Pointer to the Destination 480 - 481 - Return Value: 482 - None 483 - 484 - Note: 485 - 486 - ======================================================================== 487 - */ 488 - VOID RTMPSetICV( 489 - IN PRTMP_ADAPTER pAd, 490 - IN PUCHAR pDest) 491 - { 492 - pAd->PrivateInfo.FCSCRC32 ^= 0xffffffff; /* complement */ 493 - pAd->PrivateInfo.FCSCRC32 = cpu2le32(pAd->PrivateInfo.FCSCRC32); 494 - 495 - ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, (PUCHAR) &pAd->PrivateInfo.FCSCRC32, 4); 496 - } 497 - 1 + #include "../../rt2860/common/rtmp_wep.c"
+1 -1833
drivers/staging/rt2870/common/spectrum.c
··· 1 - /* 2 - ************************************************************************* 3 - * Ralink Tech Inc. 4 - * 5F., No.36, Taiyuan St., Jhubei City, 5 - * Hsinchu County 302, 6 - * Taiwan, R.O.C. 7 - * 8 - * (c) Copyright 2002-2007, Ralink Technology, Inc. 9 - * 10 - * This program is free software; you can redistribute it and/or modify * 11 - * it under the terms of the GNU General Public License as published by * 12 - * the Free Software Foundation; either version 2 of the License, or * 13 - * (at your option) any later version. * 14 - * * 15 - * This program is distributed in the hope that it will be useful, * 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 - * GNU General Public License for more details. * 19 - * * 20 - * You should have received a copy of the GNU General Public License * 21 - * along with this program; if not, write to the * 22 - * Free Software Foundation, Inc., * 23 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 24 - * * 25 - ************************************************************************* 26 - 27 - Module Name: 28 - action.c 29 - 30 - Abstract: 31 - Handle association related requests either from WSTA or from local MLME 32 - 33 - Revision History: 34 - Who When What 35 - --------- ---------- ---------------------------------------------- 36 - Fonchi Wu 2008 created for 802.11h 37 - */ 38 - 39 - #include "../rt_config.h" 40 - #include "action.h" 41 - 42 - VOID MeasureReqTabInit( 43 - IN PRTMP_ADAPTER pAd) 44 - { 45 - NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock); 46 - 47 - pAd->CommonCfg.pMeasureReqTab = kmalloc(sizeof(MEASURE_REQ_TAB), GFP_ATOMIC); 48 - if (pAd->CommonCfg.pMeasureReqTab) 49 - NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab, sizeof(MEASURE_REQ_TAB)); 50 - else 51 - DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n", __func__)); 52 - 53 - return; 54 - } 55 - 56 - VOID MeasureReqTabExit( 57 - IN PRTMP_ADAPTER pAd) 58 - { 59 - NdisFreeSpinLock(pAd->CommonCfg.MeasureReqTabLock); 60 - 61 - if (pAd->CommonCfg.pMeasureReqTab) 62 - kfree(pAd->CommonCfg.pMeasureReqTab); 63 - pAd->CommonCfg.pMeasureReqTab = NULL; 64 - 65 - return; 66 - } 67 - 68 - static PMEASURE_REQ_ENTRY MeasureReqLookUp( 69 - IN PRTMP_ADAPTER pAd, 70 - IN UINT8 DialogToken) 71 - { 72 - UINT HashIdx; 73 - PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab; 74 - PMEASURE_REQ_ENTRY pEntry = NULL; 75 - PMEASURE_REQ_ENTRY pPrevEntry = NULL; 76 - 77 - if (pTab == NULL) 78 - { 79 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__)); 80 - return NULL; 81 - } 82 - 83 - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); 84 - 85 - HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken); 86 - pEntry = pTab->Hash[HashIdx]; 87 - 88 - while (pEntry) 89 - { 90 - if (pEntry->DialogToken == DialogToken) 91 - break; 92 - else 93 - { 94 - pPrevEntry = pEntry; 95 - pEntry = pEntry->pNext; 96 - } 97 - } 98 - 99 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); 100 - 101 - return pEntry; 102 - } 103 - 104 - static PMEASURE_REQ_ENTRY MeasureReqInsert( 105 - IN PRTMP_ADAPTER pAd, 106 - IN UINT8 DialogToken) 107 - { 108 - INT i; 109 - ULONG HashIdx; 110 - PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab; 111 - PMEASURE_REQ_ENTRY pEntry = NULL, pCurrEntry; 112 - ULONG Now; 113 - 114 - if(pTab == NULL) 115 - { 116 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__)); 117 - return NULL; 118 - } 119 - 120 - pEntry = MeasureReqLookUp(pAd, DialogToken); 121 - if (pEntry == NULL) 122 - { 123 - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); 124 - for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++) 125 - { 126 - NdisGetSystemUpTime(&Now); 127 - pEntry = &pTab->Content[i]; 128 - 129 - if ((pEntry->Valid == TRUE) 130 - && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + MQ_REQ_AGE_OUT))) 131 - { 132 - PMEASURE_REQ_ENTRY pPrevEntry = NULL; 133 - ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); 134 - PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx]; 135 - 136 - // update Hash list 137 - do 138 - { 139 - if (pProbeEntry == pEntry) 140 - { 141 - if (pPrevEntry == NULL) 142 - { 143 - pTab->Hash[HashIdx] = pEntry->pNext; 144 - } 145 - else 146 - { 147 - pPrevEntry->pNext = pEntry->pNext; 148 - } 149 - break; 150 - } 151 - 152 - pPrevEntry = pProbeEntry; 153 - pProbeEntry = pProbeEntry->pNext; 154 - } while (pProbeEntry); 155 - 156 - NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY)); 157 - pTab->Size--; 158 - 159 - break; 160 - } 161 - 162 - if (pEntry->Valid == FALSE) 163 - break; 164 - } 165 - 166 - if (i < MAX_MEASURE_REQ_TAB_SIZE) 167 - { 168 - NdisGetSystemUpTime(&Now); 169 - pEntry->lastTime = Now; 170 - pEntry->Valid = TRUE; 171 - pEntry->DialogToken = DialogToken; 172 - pTab->Size++; 173 - } 174 - else 175 - { 176 - pEntry = NULL; 177 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab tab full.\n", __func__)); 178 - } 179 - 180 - // add this Neighbor entry into HASH table 181 - if (pEntry) 182 - { 183 - HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken); 184 - if (pTab->Hash[HashIdx] == NULL) 185 - { 186 - pTab->Hash[HashIdx] = pEntry; 187 - } 188 - else 189 - { 190 - pCurrEntry = pTab->Hash[HashIdx]; 191 - while (pCurrEntry->pNext != NULL) 192 - pCurrEntry = pCurrEntry->pNext; 193 - pCurrEntry->pNext = pEntry; 194 - } 195 - } 196 - 197 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); 198 - } 199 - 200 - return pEntry; 201 - } 202 - 203 - static VOID MeasureReqDelete( 204 - IN PRTMP_ADAPTER pAd, 205 - IN UINT8 DialogToken) 206 - { 207 - PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab; 208 - PMEASURE_REQ_ENTRY pEntry = NULL; 209 - 210 - if(pTab == NULL) 211 - { 212 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__)); 213 - return; 214 - } 215 - 216 - // if empty, return 217 - if (pTab->Size == 0) 218 - { 219 - DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n")); 220 - return; 221 - } 222 - 223 - pEntry = MeasureReqLookUp(pAd, DialogToken); 224 - if (pEntry != NULL) 225 - { 226 - PMEASURE_REQ_ENTRY pPrevEntry = NULL; 227 - ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); 228 - PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx]; 229 - 230 - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); 231 - // update Hash list 232 - do 233 - { 234 - if (pProbeEntry == pEntry) 235 - { 236 - if (pPrevEntry == NULL) 237 - { 238 - pTab->Hash[HashIdx] = pEntry->pNext; 239 - } 240 - else 241 - { 242 - pPrevEntry->pNext = pEntry->pNext; 243 - } 244 - break; 245 - } 246 - 247 - pPrevEntry = pProbeEntry; 248 - pProbeEntry = pProbeEntry->pNext; 249 - } while (pProbeEntry); 250 - 251 - NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY)); 252 - pTab->Size--; 253 - 254 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); 255 - } 256 - 257 - return; 258 - } 259 - 260 - VOID TpcReqTabInit( 261 - IN PRTMP_ADAPTER pAd) 262 - { 263 - NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock); 264 - 265 - pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(TPC_REQ_TAB), GFP_ATOMIC); 266 - if (pAd->CommonCfg.pTpcReqTab) 267 - NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(TPC_REQ_TAB)); 268 - else 269 - DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n", __func__)); 270 - 271 - return; 272 - } 273 - 274 - VOID TpcReqTabExit( 275 - IN PRTMP_ADAPTER pAd) 276 - { 277 - NdisFreeSpinLock(pAd->CommonCfg.TpcReqTabLock); 278 - 279 - if (pAd->CommonCfg.pTpcReqTab) 280 - kfree(pAd->CommonCfg.pTpcReqTab); 281 - pAd->CommonCfg.pTpcReqTab = NULL; 282 - 283 - return; 284 - } 285 - 286 - static PTPC_REQ_ENTRY TpcReqLookUp( 287 - IN PRTMP_ADAPTER pAd, 288 - IN UINT8 DialogToken) 289 - { 290 - UINT HashIdx; 291 - PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab; 292 - PTPC_REQ_ENTRY pEntry = NULL; 293 - PTPC_REQ_ENTRY pPrevEntry = NULL; 294 - 295 - if (pTab == NULL) 296 - { 297 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__)); 298 - return NULL; 299 - } 300 - 301 - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); 302 - 303 - HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken); 304 - pEntry = pTab->Hash[HashIdx]; 305 - 306 - while (pEntry) 307 - { 308 - if (pEntry->DialogToken == DialogToken) 309 - break; 310 - else 311 - { 312 - pPrevEntry = pEntry; 313 - pEntry = pEntry->pNext; 314 - } 315 - } 316 - 317 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); 318 - 319 - return pEntry; 320 - } 321 - 322 - 323 - static PTPC_REQ_ENTRY TpcReqInsert( 324 - IN PRTMP_ADAPTER pAd, 325 - IN UINT8 DialogToken) 326 - { 327 - INT i; 328 - ULONG HashIdx; 329 - PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab; 330 - PTPC_REQ_ENTRY pEntry = NULL, pCurrEntry; 331 - ULONG Now; 332 - 333 - if(pTab == NULL) 334 - { 335 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__)); 336 - return NULL; 337 - } 338 - 339 - pEntry = TpcReqLookUp(pAd, DialogToken); 340 - if (pEntry == NULL) 341 - { 342 - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); 343 - for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++) 344 - { 345 - NdisGetSystemUpTime(&Now); 346 - pEntry = &pTab->Content[i]; 347 - 348 - if ((pEntry->Valid == TRUE) 349 - && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + TPC_REQ_AGE_OUT))) 350 - { 351 - PTPC_REQ_ENTRY pPrevEntry = NULL; 352 - ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); 353 - PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx]; 354 - 355 - // update Hash list 356 - do 357 - { 358 - if (pProbeEntry == pEntry) 359 - { 360 - if (pPrevEntry == NULL) 361 - { 362 - pTab->Hash[HashIdx] = pEntry->pNext; 363 - } 364 - else 365 - { 366 - pPrevEntry->pNext = pEntry->pNext; 367 - } 368 - break; 369 - } 370 - 371 - pPrevEntry = pProbeEntry; 372 - pProbeEntry = pProbeEntry->pNext; 373 - } while (pProbeEntry); 374 - 375 - NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY)); 376 - pTab->Size--; 377 - 378 - break; 379 - } 380 - 381 - if (pEntry->Valid == FALSE) 382 - break; 383 - } 384 - 385 - if (i < MAX_TPC_REQ_TAB_SIZE) 386 - { 387 - NdisGetSystemUpTime(&Now); 388 - pEntry->lastTime = Now; 389 - pEntry->Valid = TRUE; 390 - pEntry->DialogToken = DialogToken; 391 - pTab->Size++; 392 - } 393 - else 394 - { 395 - pEntry = NULL; 396 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab tab full.\n", __func__)); 397 - } 398 - 399 - // add this Neighbor entry into HASH table 400 - if (pEntry) 401 - { 402 - HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken); 403 - if (pTab->Hash[HashIdx] == NULL) 404 - { 405 - pTab->Hash[HashIdx] = pEntry; 406 - } 407 - else 408 - { 409 - pCurrEntry = pTab->Hash[HashIdx]; 410 - while (pCurrEntry->pNext != NULL) 411 - pCurrEntry = pCurrEntry->pNext; 412 - pCurrEntry->pNext = pEntry; 413 - } 414 - } 415 - 416 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); 417 - } 418 - 419 - return pEntry; 420 - } 421 - 422 - static VOID TpcReqDelete( 423 - IN PRTMP_ADAPTER pAd, 424 - IN UINT8 DialogToken) 425 - { 426 - PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab; 427 - PTPC_REQ_ENTRY pEntry = NULL; 428 - 429 - if(pTab == NULL) 430 - { 431 - DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__)); 432 - return; 433 - } 434 - 435 - // if empty, return 436 - if (pTab->Size == 0) 437 - { 438 - DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n")); 439 - return; 440 - } 441 - 442 - pEntry = TpcReqLookUp(pAd, DialogToken); 443 - if (pEntry != NULL) 444 - { 445 - PTPC_REQ_ENTRY pPrevEntry = NULL; 446 - ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); 447 - PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx]; 448 - 449 - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); 450 - // update Hash list 451 - do 452 - { 453 - if (pProbeEntry == pEntry) 454 - { 455 - if (pPrevEntry == NULL) 456 - { 457 - pTab->Hash[HashIdx] = pEntry->pNext; 458 - } 459 - else 460 - { 461 - pPrevEntry->pNext = pEntry->pNext; 462 - } 463 - break; 464 - } 465 - 466 - pPrevEntry = pProbeEntry; 467 - pProbeEntry = pProbeEntry->pNext; 468 - } while (pProbeEntry); 469 - 470 - NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY)); 471 - pTab->Size--; 472 - 473 - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); 474 - } 475 - 476 - return; 477 - } 478 - 479 - /* 480 - ========================================================================== 481 - Description: 482 - Get Current TimeS tamp. 483 - 484 - Parametrs: 485 - 486 - Return : Current Time Stamp. 487 - ========================================================================== 488 - */ 489 - static UINT64 GetCurrentTimeStamp( 490 - IN PRTMP_ADAPTER pAd) 491 - { 492 - // get current time stamp. 493 - return 0; 494 - } 495 - 496 - /* 497 - ========================================================================== 498 - Description: 499 - Get Current Transmit Power. 500 - 501 - Parametrs: 502 - 503 - Return : Current Time Stamp. 504 - ========================================================================== 505 - */ 506 - static UINT8 GetCurTxPwr( 507 - IN PRTMP_ADAPTER pAd, 508 - IN UINT8 Wcid) 509 - { 510 - return 16; /* 16 dBm */ 511 - } 512 - 513 - /* 514 - ========================================================================== 515 - Description: 516 - Insert Dialog Token into frame. 517 - 518 - Parametrs: 519 - 1. frame buffer pointer. 520 - 2. frame length. 521 - 3. Dialog token. 522 - 523 - Return : None. 524 - ========================================================================== 525 - */ 526 - static VOID InsertDialogToken( 527 - IN PRTMP_ADAPTER pAd, 528 - OUT PUCHAR pFrameBuf, 529 - OUT PULONG pFrameLen, 530 - IN UINT8 DialogToken) 531 - { 532 - ULONG TempLen; 533 - MakeOutgoingFrame(pFrameBuf, &TempLen, 534 - 1, &DialogToken, 535 - END_OF_ARGS); 536 - 537 - *pFrameLen = *pFrameLen + TempLen; 538 - 539 - return; 540 - } 541 - 542 - /* 543 - ========================================================================== 544 - Description: 545 - Insert TPC Request IE into frame. 546 - 547 - Parametrs: 548 - 1. frame buffer pointer. 549 - 2. frame length. 550 - 551 - Return : None. 552 - ========================================================================== 553 - */ 554 - static VOID InsertTpcReqIE( 555 - IN PRTMP_ADAPTER pAd, 556 - OUT PUCHAR pFrameBuf, 557 - OUT PULONG pFrameLen) 558 - { 559 - ULONG TempLen; 560 - ULONG Len = 0; 561 - UINT8 ElementID = IE_TPC_REQUEST; 562 - 563 - MakeOutgoingFrame(pFrameBuf, &TempLen, 564 - 1, &ElementID, 565 - 1, &Len, 566 - END_OF_ARGS); 567 - 568 - *pFrameLen = *pFrameLen + TempLen; 569 - 570 - return; 571 - } 572 - 573 - /* 574 - ========================================================================== 575 - Description: 576 - Insert TPC Report IE into frame. 577 - 578 - Parametrs: 579 - 1. frame buffer pointer. 580 - 2. frame length. 581 - 3. Transmit Power. 582 - 4. Link Margin. 583 - 584 - Return : None. 585 - ========================================================================== 586 - */ 587 - static VOID InsertTpcReportIE( 588 - IN PRTMP_ADAPTER pAd, 589 - OUT PUCHAR pFrameBuf, 590 - OUT PULONG pFrameLen, 591 - IN UINT8 TxPwr, 592 - IN UINT8 LinkMargin) 593 - { 594 - ULONG TempLen; 595 - ULONG Len = sizeof(TPC_REPORT_INFO); 596 - UINT8 ElementID = IE_TPC_REPORT; 597 - TPC_REPORT_INFO TpcReportIE; 598 - 599 - TpcReportIE.TxPwr = TxPwr; 600 - TpcReportIE.LinkMargin = LinkMargin; 601 - 602 - MakeOutgoingFrame(pFrameBuf, &TempLen, 603 - 1, &ElementID, 604 - 1, &Len, 605 - Len, &TpcReportIE, 606 - END_OF_ARGS); 607 - 608 - *pFrameLen = *pFrameLen + TempLen; 609 - 610 - 611 - return; 612 - } 613 - 614 - /* 615 - ========================================================================== 616 - Description: 617 - Insert Channel Switch Announcement IE into frame. 618 - 619 - Parametrs: 620 - 1. frame buffer pointer. 621 - 2. frame length. 622 - 3. channel switch announcement mode. 623 - 4. new selected channel. 624 - 5. channel switch announcement count. 625 - 626 - Return : None. 627 - ========================================================================== 628 - */ 629 - static VOID InsertChSwAnnIE( 630 - IN PRTMP_ADAPTER pAd, 631 - OUT PUCHAR pFrameBuf, 632 - OUT PULONG pFrameLen, 633 - IN UINT8 ChSwMode, 634 - IN UINT8 NewChannel, 635 - IN UINT8 ChSwCnt) 636 - { 637 - ULONG TempLen; 638 - ULONG Len = sizeof(CH_SW_ANN_INFO); 639 - UINT8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT; 640 - CH_SW_ANN_INFO ChSwAnnIE; 641 - 642 - ChSwAnnIE.ChSwMode = ChSwMode; 643 - ChSwAnnIE.Channel = NewChannel; 644 - ChSwAnnIE.ChSwCnt = ChSwCnt; 645 - 646 - MakeOutgoingFrame(pFrameBuf, &TempLen, 647 - 1, &ElementID, 648 - 1, &Len, 649 - Len, &ChSwAnnIE, 650 - END_OF_ARGS); 651 - 652 - *pFrameLen = *pFrameLen + TempLen; 653 - 654 - 655 - return; 656 - } 657 - 658 - /* 659 - ========================================================================== 660 - Description: 661 - Insert Measure Request IE into frame. 662 - 663 - Parametrs: 664 - 1. frame buffer pointer. 665 - 2. frame length. 666 - 3. Measure Token. 667 - 4. Measure Request Mode. 668 - 5. Measure Request Type. 669 - 6. Measure Channel. 670 - 7. Measure Start time. 671 - 8. Measure Duration. 672 - 673 - 674 - Return : None. 675 - ========================================================================== 676 - */ 677 - static VOID InsertMeasureReqIE( 678 - IN PRTMP_ADAPTER pAd, 679 - OUT PUCHAR pFrameBuf, 680 - OUT PULONG pFrameLen, 681 - IN PMEASURE_REQ_INFO pMeasureReqIE) 682 - { 683 - ULONG TempLen; 684 - UINT8 Len = sizeof(MEASURE_REQ_INFO); 685 - UINT8 ElementID = IE_MEASUREMENT_REQUEST; 686 - 687 - MakeOutgoingFrame(pFrameBuf, &TempLen, 688 - 1, &ElementID, 689 - 1, &Len, 690 - Len, pMeasureReqIE, 691 - END_OF_ARGS); 692 - 693 - *pFrameLen = *pFrameLen + TempLen; 694 - 695 - return; 696 - } 697 - 698 - /* 699 - ========================================================================== 700 - Description: 701 - Insert Measure Report IE into frame. 702 - 703 - Parametrs: 704 - 1. frame buffer pointer. 705 - 2. frame length. 706 - 3. Measure Token. 707 - 4. Measure Request Mode. 708 - 5. Measure Request Type. 709 - 6. Length of Report Infomation 710 - 7. Pointer of Report Infomation Buffer. 711 - 712 - Return : None. 713 - ========================================================================== 714 - */ 715 - static VOID InsertMeasureReportIE( 716 - IN PRTMP_ADAPTER pAd, 717 - OUT PUCHAR pFrameBuf, 718 - OUT PULONG pFrameLen, 719 - IN PMEASURE_REPORT_INFO pMeasureReportIE, 720 - IN UINT8 ReportLnfoLen, 721 - IN PUINT8 pReportInfo) 722 - { 723 - ULONG TempLen; 724 - ULONG Len; 725 - UINT8 ElementID = IE_MEASUREMENT_REPORT; 726 - 727 - Len = sizeof(MEASURE_REPORT_INFO) + ReportLnfoLen; 728 - 729 - MakeOutgoingFrame(pFrameBuf, &TempLen, 730 - 1, &ElementID, 731 - 1, &Len, 732 - Len, pMeasureReportIE, 733 - END_OF_ARGS); 734 - 735 - *pFrameLen = *pFrameLen + TempLen; 736 - 737 - if ((ReportLnfoLen > 0) && (pReportInfo != NULL)) 738 - { 739 - MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen, 740 - ReportLnfoLen, pReportInfo, 741 - END_OF_ARGS); 742 - 743 - *pFrameLen = *pFrameLen + TempLen; 744 - } 745 - return; 746 - } 747 - 748 - /* 749 - ========================================================================== 750 - Description: 751 - Prepare Measurement request action frame and enqueue it into 752 - management queue waiting for transmition. 753 - 754 - Parametrs: 755 - 1. the destination mac address of the frame. 756 - 757 - Return : None. 758 - ========================================================================== 759 - */ 760 - VOID EnqueueMeasurementReq( 761 - IN PRTMP_ADAPTER pAd, 762 - IN PUCHAR pDA, 763 - IN UINT8 MeasureToken, 764 - IN UINT8 MeasureReqMode, 765 - IN UINT8 MeasureReqType, 766 - IN UINT8 MeasureCh, 767 - IN UINT16 MeasureDuration) 768 - { 769 - PUCHAR pOutBuffer = NULL; 770 - NDIS_STATUS NStatus; 771 - ULONG FrameLen; 772 - HEADER_802_11 ActHdr; 773 - MEASURE_REQ_INFO MeasureReqIE; 774 - UINT8 RmReqDailogToken = RandomByte(pAd); 775 - UINT64 MeasureStartTime = GetCurrentTimeStamp(pAd); 776 - 777 - // build action frame header. 778 - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, 779 - pAd->CurrentAddress); 780 - 781 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory 782 - if(NStatus != NDIS_STATUS_SUCCESS) 783 - { 784 - DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__)); 785 - return; 786 - } 787 - NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11)); 788 - FrameLen = sizeof(HEADER_802_11); 789 - 790 - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRQ); 791 - 792 - // fill Dialog Token 793 - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, MeasureToken); 794 - 795 - // prepare Measurement IE. 796 - NdisZeroMemory(&MeasureReqIE, sizeof(MEASURE_REQ_INFO)); 797 - MeasureReqIE.Token = RmReqDailogToken; 798 - MeasureReqIE.ReqMode.word = MeasureReqMode; 799 - MeasureReqIE.ReqType = MeasureReqType; 800 - MeasureReqIE.MeasureReq.ChNum = MeasureCh; 801 - MeasureReqIE.MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime); 802 - MeasureReqIE.MeasureReq.MeasureDuration = cpu2le16(MeasureDuration); 803 - InsertMeasureReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureReqIE); 804 - 805 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 806 - MlmeFreeMemory(pAd, pOutBuffer); 807 - 808 - return; 809 - } 810 - 811 - /* 812 - ========================================================================== 813 - Description: 814 - Prepare Measurement report action frame and enqueue it into 815 - management queue waiting for transmition. 816 - 817 - Parametrs: 818 - 1. the destination mac address of the frame. 819 - 820 - Return : None. 821 - ========================================================================== 822 - */ 823 - VOID EnqueueMeasurementRep( 824 - IN PRTMP_ADAPTER pAd, 825 - IN PUCHAR pDA, 826 - IN UINT8 DialogToken, 827 - IN UINT8 MeasureToken, 828 - IN UINT8 MeasureReqMode, 829 - IN UINT8 MeasureReqType, 830 - IN UINT8 ReportInfoLen, 831 - IN PUINT8 pReportInfo) 832 - { 833 - PUCHAR pOutBuffer = NULL; 834 - NDIS_STATUS NStatus; 835 - ULONG FrameLen; 836 - HEADER_802_11 ActHdr; 837 - MEASURE_REPORT_INFO MeasureRepIE; 838 - 839 - // build action frame header. 840 - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, 841 - pAd->CurrentAddress); 842 - 843 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory 844 - if(NStatus != NDIS_STATUS_SUCCESS) 845 - { 846 - DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__)); 847 - return; 848 - } 849 - NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11)); 850 - FrameLen = sizeof(HEADER_802_11); 851 - 852 - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRP); 853 - 854 - // fill Dialog Token 855 - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); 856 - 857 - // prepare Measurement IE. 858 - NdisZeroMemory(&MeasureRepIE, sizeof(MEASURE_REPORT_INFO)); 859 - MeasureRepIE.Token = MeasureToken; 860 - MeasureRepIE.ReportMode.word = MeasureReqMode; 861 - MeasureRepIE.ReportType = MeasureReqType; 862 - InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureRepIE, ReportInfoLen, pReportInfo); 863 - 864 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 865 - MlmeFreeMemory(pAd, pOutBuffer); 866 - 867 - return; 868 - } 869 - 870 - /* 871 - ========================================================================== 872 - Description: 873 - Prepare TPC Request action frame and enqueue it into 874 - management queue waiting for transmition. 875 - 876 - Parametrs: 877 - 1. the destination mac address of the frame. 878 - 879 - Return : None. 880 - ========================================================================== 881 - */ 882 - VOID EnqueueTPCReq( 883 - IN PRTMP_ADAPTER pAd, 884 - IN PUCHAR pDA, 885 - IN UCHAR DialogToken) 886 - { 887 - PUCHAR pOutBuffer = NULL; 888 - NDIS_STATUS NStatus; 889 - ULONG FrameLen; 890 - 891 - HEADER_802_11 ActHdr; 892 - 893 - // build action frame header. 894 - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, 895 - pAd->CurrentAddress); 896 - 897 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory 898 - if(NStatus != NDIS_STATUS_SUCCESS) 899 - { 900 - DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__)); 901 - return; 902 - } 903 - NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11)); 904 - FrameLen = sizeof(HEADER_802_11); 905 - 906 - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRQ); 907 - 908 - // fill Dialog Token 909 - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); 910 - 911 - // Insert TPC Request IE. 912 - InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen); 913 - 914 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 915 - MlmeFreeMemory(pAd, pOutBuffer); 916 - 917 - return; 918 - } 919 - 920 - /* 921 - ========================================================================== 922 - Description: 923 - Prepare TPC Report action frame and enqueue it into 924 - management queue waiting for transmition. 925 - 926 - Parametrs: 927 - 1. the destination mac address of the frame. 928 - 929 - Return : None. 930 - ========================================================================== 931 - */ 932 - VOID EnqueueTPCRep( 933 - IN PRTMP_ADAPTER pAd, 934 - IN PUCHAR pDA, 935 - IN UINT8 DialogToken, 936 - IN UINT8 TxPwr, 937 - IN UINT8 LinkMargin) 938 - { 939 - PUCHAR pOutBuffer = NULL; 940 - NDIS_STATUS NStatus; 941 - ULONG FrameLen; 942 - 943 - HEADER_802_11 ActHdr; 944 - 945 - // build action frame header. 946 - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, 947 - pAd->CurrentAddress); 948 - 949 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory 950 - if(NStatus != NDIS_STATUS_SUCCESS) 951 - { 952 - DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__)); 953 - return; 954 - } 955 - NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11)); 956 - FrameLen = sizeof(HEADER_802_11); 957 - 958 - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRP); 959 - 960 - // fill Dialog Token 961 - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); 962 - 963 - // Insert TPC Request IE. 964 - InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr, LinkMargin); 965 - 966 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 967 - MlmeFreeMemory(pAd, pOutBuffer); 968 - 969 - return; 970 - } 971 - 972 - /* 973 - ========================================================================== 974 - Description: 975 - Prepare Channel Switch Announcement action frame and enqueue it into 976 - management queue waiting for transmition. 977 - 978 - Parametrs: 979 - 1. the destination mac address of the frame. 980 - 2. Channel switch announcement mode. 981 - 2. a New selected channel. 982 - 983 - Return : None. 984 - ========================================================================== 985 - */ 986 - VOID EnqueueChSwAnn( 987 - IN PRTMP_ADAPTER pAd, 988 - IN PUCHAR pDA, 989 - IN UINT8 ChSwMode, 990 - IN UINT8 NewCh) 991 - { 992 - PUCHAR pOutBuffer = NULL; 993 - NDIS_STATUS NStatus; 994 - ULONG FrameLen; 995 - 996 - HEADER_802_11 ActHdr; 997 - 998 - // build action frame header. 999 - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, 1000 - pAd->CurrentAddress); 1001 - 1002 - NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory 1003 - if(NStatus != NDIS_STATUS_SUCCESS) 1004 - { 1005 - DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__)); 1006 - return; 1007 - } 1008 - NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11)); 1009 - FrameLen = sizeof(HEADER_802_11); 1010 - 1011 - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH); 1012 - 1013 - InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode, NewCh, 0); 1014 - 1015 - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); 1016 - MlmeFreeMemory(pAd, pOutBuffer); 1017 - 1018 - return; 1019 - } 1020 - 1021 - static BOOLEAN DfsRequirementCheck( 1022 - IN PRTMP_ADAPTER pAd, 1023 - IN UINT8 Channel) 1024 - { 1025 - BOOLEAN Result = FALSE; 1026 - INT i; 1027 - 1028 - do 1029 - { 1030 - // check DFS procedure is running. 1031 - // make sure DFS procedure won't start twice. 1032 - if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) 1033 - { 1034 - Result = FALSE; 1035 - break; 1036 - } 1037 - 1038 - // check the new channel carried from Channel Switch Announcemnet is valid. 1039 - for (i=0; i<pAd->ChannelListNum; i++) 1040 - { 1041 - if ((Channel == pAd->ChannelList[i].Channel) 1042 - &&(pAd->ChannelList[i].RemainingTimeForUse == 0)) 1043 - { 1044 - // found radar signal in the channel. the channel can't use at least for 30 minutes. 1045 - pAd->ChannelList[i].RemainingTimeForUse = 1800;//30 min = 1800 sec 1046 - Result = TRUE; 1047 - break; 1048 - } 1049 - } 1050 - } while(FALSE); 1051 - 1052 - return Result; 1053 - } 1054 - 1055 - VOID NotifyChSwAnnToPeerAPs( 1056 - IN PRTMP_ADAPTER pAd, 1057 - IN PUCHAR pRA, 1058 - IN PUCHAR pTA, 1059 - IN UINT8 ChSwMode, 1060 - IN UINT8 Channel) 1061 - { 1062 - } 1063 - 1064 - static VOID StartDFSProcedure( 1065 - IN PRTMP_ADAPTER pAd, 1066 - IN UCHAR Channel, 1067 - IN UINT8 ChSwMode) 1068 - { 1069 - // start DFS procedure 1070 - pAd->CommonCfg.Channel = Channel; 1071 - 1072 - N_ChannelCheck(pAd); 1073 - 1074 - pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE; 1075 - pAd->CommonCfg.RadarDetect.CSCount = 0; 1076 - } 1077 - 1078 - /* 1079 - ========================================================================== 1080 - Description: 1081 - Channel Switch Announcement action frame sanity check. 1082 - 1083 - Parametrs: 1084 - 1. MLME message containing the received frame 1085 - 2. message length. 1086 - 3. Channel switch announcement infomation buffer. 1087 - 1088 - 1089 - Return : None. 1090 - ========================================================================== 1091 - */ 1092 - 1093 - /* 1094 - Channel Switch Announcement IE. 1095 - +----+-----+-----------+------------+-----------+ 1096 - | ID | Len |Ch Sw Mode | New Ch Num | Ch Sw Cnt | 1097 - +----+-----+-----------+------------+-----------+ 1098 - 1 1 1 1 1 1099 - */ 1100 - static BOOLEAN PeerChSwAnnSanity( 1101 - IN PRTMP_ADAPTER pAd, 1102 - IN VOID *pMsg, 1103 - IN ULONG MsgLen, 1104 - OUT PCH_SW_ANN_INFO pChSwAnnInfo) 1105 - { 1106 - PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; 1107 - PUCHAR pFramePtr = Fr->Octet; 1108 - BOOLEAN result = FALSE; 1109 - PEID_STRUCT eid_ptr; 1110 - 1111 - // skip 802.11 header. 1112 - MsgLen -= sizeof(HEADER_802_11); 1113 - 1114 - // skip category and action code. 1115 - pFramePtr += 2; 1116 - MsgLen -= 2; 1117 - 1118 - if (pChSwAnnInfo == NULL) 1119 - return result; 1120 - 1121 - eid_ptr = (PEID_STRUCT)pFramePtr; 1122 - while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) 1123 - { 1124 - switch(eid_ptr->Eid) 1125 - { 1126 - case IE_CHANNEL_SWITCH_ANNOUNCEMENT: 1127 - NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet, 1); 1128 - NdisMoveMemory(&pChSwAnnInfo->Channel, eid_ptr->Octet + 1, 1); 1129 - NdisMoveMemory(&pChSwAnnInfo->ChSwCnt, eid_ptr->Octet + 2, 1); 1130 - 1131 - result = TRUE; 1132 - break; 1133 - 1134 - default: 1135 - break; 1136 - } 1137 - eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); 1138 - } 1139 - 1140 - return result; 1141 - } 1142 - 1143 - /* 1144 - ========================================================================== 1145 - Description: 1146 - Measurement request action frame sanity check. 1147 - 1148 - Parametrs: 1149 - 1. MLME message containing the received frame 1150 - 2. message length. 1151 - 3. Measurement request infomation buffer. 1152 - 1153 - Return : None. 1154 - ========================================================================== 1155 - */ 1156 - static BOOLEAN PeerMeasureReqSanity( 1157 - IN PRTMP_ADAPTER pAd, 1158 - IN VOID *pMsg, 1159 - IN ULONG MsgLen, 1160 - OUT PUINT8 pDialogToken, 1161 - OUT PMEASURE_REQ_INFO pMeasureReqInfo) 1162 - { 1163 - PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; 1164 - PUCHAR pFramePtr = Fr->Octet; 1165 - BOOLEAN result = FALSE; 1166 - PEID_STRUCT eid_ptr; 1167 - PUCHAR ptr; 1168 - UINT64 MeasureStartTime; 1169 - UINT16 MeasureDuration; 1170 - 1171 - // skip 802.11 header. 1172 - MsgLen -= sizeof(HEADER_802_11); 1173 - 1174 - // skip category and action code. 1175 - pFramePtr += 2; 1176 - MsgLen -= 2; 1177 - 1178 - if (pMeasureReqInfo == NULL) 1179 - return result; 1180 - 1181 - NdisMoveMemory(pDialogToken, pFramePtr, 1); 1182 - pFramePtr += 1; 1183 - MsgLen -= 1; 1184 - 1185 - eid_ptr = (PEID_STRUCT)pFramePtr; 1186 - while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) 1187 - { 1188 - switch(eid_ptr->Eid) 1189 - { 1190 - case IE_MEASUREMENT_REQUEST: 1191 - NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, 1); 1192 - NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, eid_ptr->Octet + 1, 1); 1193 - NdisMoveMemory(&pMeasureReqInfo->ReqType, eid_ptr->Octet + 2, 1); 1194 - ptr = eid_ptr->Octet + 3; 1195 - NdisMoveMemory(&pMeasureReqInfo->MeasureReq.ChNum, ptr, 1); 1196 - NdisMoveMemory(&MeasureStartTime, ptr + 1, 8); 1197 - pMeasureReqInfo->MeasureReq.MeasureStartTime = SWAP64(MeasureStartTime); 1198 - NdisMoveMemory(&MeasureDuration, ptr + 9, 2); 1199 - pMeasureReqInfo->MeasureReq.MeasureDuration = SWAP16(MeasureDuration); 1200 - 1201 - result = TRUE; 1202 - break; 1203 - 1204 - default: 1205 - break; 1206 - } 1207 - eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); 1208 - } 1209 - 1210 - return result; 1211 - } 1212 - 1213 - /* 1214 - ========================================================================== 1215 - Description: 1216 - Measurement report action frame sanity check. 1217 - 1218 - Parametrs: 1219 - 1. MLME message containing the received frame 1220 - 2. message length. 1221 - 3. Measurement report infomation buffer. 1222 - 4. basic report infomation buffer. 1223 - 1224 - Return : None. 1225 - ========================================================================== 1226 - */ 1227 - 1228 - /* 1229 - Measurement Report IE. 1230 - +----+-----+-------+-------------+--------------+----------------+ 1231 - | ID | Len | Token | Report Mode | Measure Type | Measure Report | 1232 - +----+-----+-------+-------------+--------------+----------------+ 1233 - 1 1 1 1 1 variable 1234 - 1235 - Basic Report. 1236 - +--------+------------+----------+-----+ 1237 - | Ch Num | Start Time | Duration | Map | 1238 - +--------+------------+----------+-----+ 1239 - 1 8 2 1 1240 - 1241 - Map Field Bit Format. 1242 - +-----+---------------+---------------------+-------+------------+----------+ 1243 - | Bss | OFDM Preamble | Unidentified signal | Radar | Unmeasured | Reserved | 1244 - +-----+---------------+---------------------+-------+------------+----------+ 1245 - 0 1 2 3 4 5-7 1246 - */ 1247 - static BOOLEAN PeerMeasureReportSanity( 1248 - IN PRTMP_ADAPTER pAd, 1249 - IN VOID *pMsg, 1250 - IN ULONG MsgLen, 1251 - OUT PUINT8 pDialogToken, 1252 - OUT PMEASURE_REPORT_INFO pMeasureReportInfo, 1253 - OUT PUINT8 pReportBuf) 1254 - { 1255 - PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; 1256 - PUCHAR pFramePtr = Fr->Octet; 1257 - BOOLEAN result = FALSE; 1258 - PEID_STRUCT eid_ptr; 1259 - PUCHAR ptr; 1260 - 1261 - // skip 802.11 header. 1262 - MsgLen -= sizeof(HEADER_802_11); 1263 - 1264 - // skip category and action code. 1265 - pFramePtr += 2; 1266 - MsgLen -= 2; 1267 - 1268 - if (pMeasureReportInfo == NULL) 1269 - return result; 1270 - 1271 - NdisMoveMemory(pDialogToken, pFramePtr, 1); 1272 - pFramePtr += 1; 1273 - MsgLen -= 1; 1274 - 1275 - eid_ptr = (PEID_STRUCT)pFramePtr; 1276 - while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) 1277 - { 1278 - switch(eid_ptr->Eid) 1279 - { 1280 - case IE_MEASUREMENT_REPORT: 1281 - NdisMoveMemory(&pMeasureReportInfo->Token, eid_ptr->Octet, 1); 1282 - NdisMoveMemory(&pMeasureReportInfo->ReportMode, eid_ptr->Octet + 1, 1); 1283 - NdisMoveMemory(&pMeasureReportInfo->ReportType, eid_ptr->Octet + 2, 1); 1284 - if (pMeasureReportInfo->ReportType == RM_BASIC) 1285 - { 1286 - PMEASURE_BASIC_REPORT pReport = (PMEASURE_BASIC_REPORT)pReportBuf; 1287 - ptr = eid_ptr->Octet + 3; 1288 - NdisMoveMemory(&pReport->ChNum, ptr, 1); 1289 - NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8); 1290 - NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2); 1291 - NdisMoveMemory(&pReport->Map, ptr + 11, 1); 1292 - 1293 - } 1294 - else if (pMeasureReportInfo->ReportType == RM_CCA) 1295 - { 1296 - PMEASURE_CCA_REPORT pReport = (PMEASURE_CCA_REPORT)pReportBuf; 1297 - ptr = eid_ptr->Octet + 3; 1298 - NdisMoveMemory(&pReport->ChNum, ptr, 1); 1299 - NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8); 1300 - NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2); 1301 - NdisMoveMemory(&pReport->CCA_Busy_Fraction, ptr + 11, 1); 1302 - 1303 - } 1304 - else if (pMeasureReportInfo->ReportType == RM_RPI_HISTOGRAM) 1305 - { 1306 - PMEASURE_RPI_REPORT pReport = (PMEASURE_RPI_REPORT)pReportBuf; 1307 - ptr = eid_ptr->Octet + 3; 1308 - NdisMoveMemory(&pReport->ChNum, ptr, 1); 1309 - NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8); 1310 - NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2); 1311 - NdisMoveMemory(&pReport->RPI_Density, ptr + 11, 8); 1312 - } 1313 - result = TRUE; 1314 - break; 1315 - 1316 - default: 1317 - break; 1318 - } 1319 - eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); 1320 - } 1321 - 1322 - return result; 1323 - } 1324 - 1325 - /* 1326 - ========================================================================== 1327 - Description: 1328 - TPC Request action frame sanity check. 1329 - 1330 - Parametrs: 1331 - 1. MLME message containing the received frame 1332 - 2. message length. 1333 - 3. Dialog Token. 1334 - 1335 - Return : None. 1336 - ========================================================================== 1337 - */ 1338 - static BOOLEAN PeerTpcReqSanity( 1339 - IN PRTMP_ADAPTER pAd, 1340 - IN VOID *pMsg, 1341 - IN ULONG MsgLen, 1342 - OUT PUINT8 pDialogToken) 1343 - { 1344 - PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; 1345 - PUCHAR pFramePtr = Fr->Octet; 1346 - BOOLEAN result = FALSE; 1347 - PEID_STRUCT eid_ptr; 1348 - 1349 - MsgLen -= sizeof(HEADER_802_11); 1350 - 1351 - // skip category and action code. 1352 - pFramePtr += 2; 1353 - MsgLen -= 2; 1354 - 1355 - if (pDialogToken == NULL) 1356 - return result; 1357 - 1358 - NdisMoveMemory(pDialogToken, pFramePtr, 1); 1359 - pFramePtr += 1; 1360 - MsgLen -= 1; 1361 - 1362 - eid_ptr = (PEID_STRUCT)pFramePtr; 1363 - while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) 1364 - { 1365 - switch(eid_ptr->Eid) 1366 - { 1367 - case IE_TPC_REQUEST: 1368 - result = TRUE; 1369 - break; 1370 - 1371 - default: 1372 - break; 1373 - } 1374 - eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); 1375 - } 1376 - 1377 - return result; 1378 - } 1379 - 1380 - /* 1381 - ========================================================================== 1382 - Description: 1383 - TPC Report action frame sanity check. 1384 - 1385 - Parametrs: 1386 - 1. MLME message containing the received frame 1387 - 2. message length. 1388 - 3. Dialog Token. 1389 - 4. TPC Report IE. 1390 - 1391 - Return : None. 1392 - ========================================================================== 1393 - */ 1394 - static BOOLEAN PeerTpcRepSanity( 1395 - IN PRTMP_ADAPTER pAd, 1396 - IN VOID *pMsg, 1397 - IN ULONG MsgLen, 1398 - OUT PUINT8 pDialogToken, 1399 - OUT PTPC_REPORT_INFO pTpcRepInfo) 1400 - { 1401 - PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; 1402 - PUCHAR pFramePtr = Fr->Octet; 1403 - BOOLEAN result = FALSE; 1404 - PEID_STRUCT eid_ptr; 1405 - 1406 - MsgLen -= sizeof(HEADER_802_11); 1407 - 1408 - // skip category and action code. 1409 - pFramePtr += 2; 1410 - MsgLen -= 2; 1411 - 1412 - if (pDialogToken == NULL) 1413 - return result; 1414 - 1415 - NdisMoveMemory(pDialogToken, pFramePtr, 1); 1416 - pFramePtr += 1; 1417 - MsgLen -= 1; 1418 - 1419 - eid_ptr = (PEID_STRUCT)pFramePtr; 1420 - while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) 1421 - { 1422 - switch(eid_ptr->Eid) 1423 - { 1424 - case IE_TPC_REPORT: 1425 - NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1); 1426 - NdisMoveMemory(&pTpcRepInfo->LinkMargin, eid_ptr->Octet + 1, 1); 1427 - result = TRUE; 1428 - break; 1429 - 1430 - default: 1431 - break; 1432 - } 1433 - eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); 1434 - } 1435 - 1436 - return result; 1437 - } 1438 - 1439 - /* 1440 - ========================================================================== 1441 - Description: 1442 - Channel Switch Announcement action frame handler. 1443 - 1444 - Parametrs: 1445 - Elme - MLME message containing the received frame 1446 - 1447 - Return : None. 1448 - ========================================================================== 1449 - */ 1450 - static VOID PeerChSwAnnAction( 1451 - IN PRTMP_ADAPTER pAd, 1452 - IN MLME_QUEUE_ELEM *Elem) 1453 - { 1454 - CH_SW_ANN_INFO ChSwAnnInfo; 1455 - PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg; 1456 - UCHAR index = 0, Channel = 0, NewChannel = 0; 1457 - ULONG Bssidx = 0; 1458 - 1459 - NdisZeroMemory(&ChSwAnnInfo, sizeof(CH_SW_ANN_INFO)); 1460 - if (! PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo)) 1461 - { 1462 - DBGPRINT(RT_DEBUG_TRACE, ("Invalid Channel Switch Action Frame.\n")); 1463 - return; 1464 - } 1465 - 1466 - if (pAd->OpMode == OPMODE_STA) 1467 - { 1468 - Bssidx = BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3, pAd->CommonCfg.Channel); 1469 - if (Bssidx == BSS_NOT_FOUND) 1470 - { 1471 - DBGPRINT(RT_DEBUG_TRACE, ("PeerChSwAnnAction - Bssidx is not found\n")); 1472 - return; 1473 - } 1474 - 1475 - DBGPRINT(RT_DEBUG_TRACE, ("\n****Bssidx is %d, Channel = %d\n", index, pAd->ScanTab.BssEntry[Bssidx].Channel)); 1476 - hex_dump("SSID",pAd->ScanTab.BssEntry[Bssidx].Bssid ,6); 1477 - 1478 - Channel = pAd->CommonCfg.Channel; 1479 - NewChannel = ChSwAnnInfo.Channel; 1480 - 1481 - if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel)) 1482 - { 1483 - // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). 1484 - // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. 1485 - AsicSwitchChannel(pAd, 1, FALSE); 1486 - AsicLockChannel(pAd, 1); 1487 - LinkDown(pAd, FALSE); 1488 - MlmeQueueInit(&pAd->Mlme.Queue); 1489 - BssTableInit(&pAd->ScanTab); 1490 - RTMPusecDelay(1000000); // use delay to prevent STA do reassoc 1491 - 1492 - // channel sanity check 1493 - for (index = 0 ; index < pAd->ChannelListNum; index++) 1494 - { 1495 - if (pAd->ChannelList[index].Channel == NewChannel) 1496 - { 1497 - pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel; 1498 - pAd->CommonCfg.Channel = NewChannel; 1499 - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); 1500 - AsicLockChannel(pAd, pAd->CommonCfg.Channel); 1501 - DBGPRINT(RT_DEBUG_TRACE, ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel)); 1502 - break; 1503 - } 1504 - } 1505 - 1506 - if (index >= pAd->ChannelListNum) 1507 - { 1508 - DBGPRINT_ERR(("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum)); 1509 - } 1510 - } 1511 - } 1512 - 1513 - return; 1514 - } 1515 - 1516 - 1517 - /* 1518 - ========================================================================== 1519 - Description: 1520 - Measurement Request action frame handler. 1521 - 1522 - Parametrs: 1523 - Elme - MLME message containing the received frame 1524 - 1525 - Return : None. 1526 - ========================================================================== 1527 - */ 1528 - static VOID PeerMeasureReqAction( 1529 - IN PRTMP_ADAPTER pAd, 1530 - IN MLME_QUEUE_ELEM *Elem) 1531 - { 1532 - PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg; 1533 - UINT8 DialogToken; 1534 - MEASURE_REQ_INFO MeasureReqInfo; 1535 - MEASURE_REPORT_MODE ReportMode; 1536 - 1537 - if(PeerMeasureReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo)) 1538 - { 1539 - ReportMode.word = 0; 1540 - ReportMode.field.Incapable = 1; 1541 - EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken, MeasureReqInfo.Token, ReportMode.word, MeasureReqInfo.ReqType, 0, NULL); 1542 - } 1543 - 1544 - return; 1545 - } 1546 - 1547 - /* 1548 - ========================================================================== 1549 - Description: 1550 - Measurement Report action frame handler. 1551 - 1552 - Parametrs: 1553 - Elme - MLME message containing the received frame 1554 - 1555 - Return : None. 1556 - ========================================================================== 1557 - */ 1558 - static VOID PeerMeasureReportAction( 1559 - IN PRTMP_ADAPTER pAd, 1560 - IN MLME_QUEUE_ELEM *Elem) 1561 - { 1562 - MEASURE_REPORT_INFO MeasureReportInfo; 1563 - PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg; 1564 - UINT8 DialogToken; 1565 - PUINT8 pMeasureReportInfo; 1566 - 1567 - // if (pAd->CommonCfg.bIEEE80211H != TRUE) 1568 - // return; 1569 - 1570 - if ((pMeasureReportInfo = kmalloc(sizeof(MEASURE_RPI_REPORT), GFP_ATOMIC)) == NULL) 1571 - { 1572 - #ifndef RT30xx 1573 - DBGPRINT(RT_DEBUG_ERROR, ("%s unable to alloc memory for measure report buffer (size=%zu).\n", __func__, sizeof(MEASURE_RPI_REPORT))); 1574 - #endif 1575 - #ifdef RT30xx 1576 - DBGPRINT(RT_DEBUG_ERROR, ("%s unable to alloc memory for measure report buffer (size=%d).\n", __func__, sizeof(MEASURE_RPI_REPORT))); 1577 - #endif 1578 - return; 1579 - } 1580 - 1581 - NdisZeroMemory(&MeasureReportInfo, sizeof(MEASURE_REPORT_INFO)); 1582 - NdisZeroMemory(pMeasureReportInfo, sizeof(MEASURE_RPI_REPORT)); 1583 - if (PeerMeasureReportSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo, pMeasureReportInfo)) 1584 - { 1585 - do { 1586 - PMEASURE_REQ_ENTRY pEntry = NULL; 1587 - 1588 - // Not a autonomous measure report. 1589 - // check the dialog token field. drop it if the dialog token doesn't match. 1590 - if ((DialogToken != 0) 1591 - && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) == NULL)) 1592 - break; 1593 - 1594 - if (pEntry != NULL) 1595 - MeasureReqDelete(pAd, pEntry->DialogToken); 1596 - 1597 - if (MeasureReportInfo.ReportType == RM_BASIC) 1598 - { 1599 - PMEASURE_BASIC_REPORT pBasicReport = (PMEASURE_BASIC_REPORT)pMeasureReportInfo; 1600 - if ((pBasicReport->Map.field.Radar) 1601 - && (DfsRequirementCheck(pAd, pBasicReport->ChNum) == TRUE)) 1602 - { 1603 - NotifyChSwAnnToPeerAPs(pAd, pFr->Hdr.Addr1, pFr->Hdr.Addr2, 1, pBasicReport->ChNum); 1604 - StartDFSProcedure(pAd, pBasicReport->ChNum, 1); 1605 - } 1606 - } 1607 - } while (FALSE); 1608 - } 1609 - else 1610 - DBGPRINT(RT_DEBUG_TRACE, ("Invalid Measurement Report Frame.\n")); 1611 - 1612 - kfree(pMeasureReportInfo); 1613 - 1614 - return; 1615 - } 1616 - 1617 - /* 1618 - ========================================================================== 1619 - Description: 1620 - TPC Request action frame handler. 1621 - 1622 - Parametrs: 1623 - Elme - MLME message containing the received frame 1624 - 1625 - Return : None. 1626 - ========================================================================== 1627 - */ 1628 - static VOID PeerTpcReqAction( 1629 - IN PRTMP_ADAPTER pAd, 1630 - IN MLME_QUEUE_ELEM *Elem) 1631 - { 1632 - PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg; 1633 - PUCHAR pFramePtr = pFr->Octet; 1634 - UINT8 DialogToken; 1635 - UINT8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid); 1636 - UINT8 LinkMargin = 0; 1637 - CHAR RealRssi; 1638 - 1639 - // link margin: Ratio of the received signal power to the minimum desired by the station (STA). The 1640 - // STA may incorporate rate information and channel conditions, including interference, into its computation 1641 - // of link margin. 1642 - 1643 - RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), 1644 - ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), 1645 - ConvertToRssi(pAd, Elem->Rssi2, RSSI_2)); 1646 - 1647 - // skip Category and action code. 1648 - pFramePtr += 2; 1649 - 1650 - // Dialog token. 1651 - NdisMoveMemory(&DialogToken, pFramePtr, 1); 1652 - 1653 - LinkMargin = (RealRssi / MIN_RCV_PWR); 1654 - if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken)) 1655 - EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr, LinkMargin); 1656 - 1657 - return; 1658 - } 1659 - 1660 - /* 1661 - ========================================================================== 1662 - Description: 1663 - TPC Report action frame handler. 1664 - 1665 - Parametrs: 1666 - Elme - MLME message containing the received frame 1667 - 1668 - Return : None. 1669 - ========================================================================== 1670 - */ 1671 - static VOID PeerTpcRepAction( 1672 - IN PRTMP_ADAPTER pAd, 1673 - IN MLME_QUEUE_ELEM *Elem) 1674 - { 1675 - UINT8 DialogToken; 1676 - TPC_REPORT_INFO TpcRepInfo; 1677 - PTPC_REQ_ENTRY pEntry = NULL; 1678 - 1679 - NdisZeroMemory(&TpcRepInfo, sizeof(TPC_REPORT_INFO)); 1680 - if (PeerTpcRepSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo)) 1681 - { 1682 - if ((pEntry = TpcReqLookUp(pAd, DialogToken)) != NULL) 1683 - { 1684 - TpcReqDelete(pAd, pEntry->DialogToken); 1685 - DBGPRINT(RT_DEBUG_TRACE, ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n", 1686 - __func__, DialogToken, TpcRepInfo.TxPwr, TpcRepInfo.LinkMargin)); 1687 - } 1688 - } 1689 - 1690 - return; 1691 - } 1692 - 1693 - /* 1694 - ========================================================================== 1695 - Description: 1696 - Spectrun action frames Handler such as channel switch annoucement, 1697 - measurement report, measurement request actions frames. 1698 - 1699 - Parametrs: 1700 - Elme - MLME message containing the received frame 1701 - 1702 - Return : None. 1703 - ========================================================================== 1704 - */ 1705 - VOID PeerSpectrumAction( 1706 - IN PRTMP_ADAPTER pAd, 1707 - IN MLME_QUEUE_ELEM *Elem) 1708 - { 1709 - 1710 - UCHAR Action = Elem->Msg[LENGTH_802_11+1]; 1711 - 1712 - if (pAd->CommonCfg.bIEEE80211H != TRUE) 1713 - return; 1714 - 1715 - switch(Action) 1716 - { 1717 - case SPEC_MRQ: 1718 - // current rt2860 unable do such measure specified in Measurement Request. 1719 - // reject all measurement request. 1720 - PeerMeasureReqAction(pAd, Elem); 1721 - break; 1722 - 1723 - case SPEC_MRP: 1724 - PeerMeasureReportAction(pAd, Elem); 1725 - break; 1726 - 1727 - case SPEC_TPCRQ: 1728 - PeerTpcReqAction(pAd, Elem); 1729 - break; 1730 - 1731 - case SPEC_TPCRP: 1732 - PeerTpcRepAction(pAd, Elem); 1733 - break; 1734 - 1735 - case SPEC_CHANNEL_SWITCH: 1736 - { 1737 - } 1738 - PeerChSwAnnAction(pAd, Elem); 1739 - break; 1740 - } 1741 - 1742 - return; 1743 - } 1744 - 1745 - /* 1746 - ========================================================================== 1747 - Description: 1748 - 1749 - Parametrs: 1750 - 1751 - Return : None. 1752 - ========================================================================== 1753 - */ 1754 - INT Set_MeasureReq_Proc( 1755 - IN PRTMP_ADAPTER pAd, 1756 - IN PUCHAR arg) 1757 - { 1758 - UINT Aid = 1; 1759 - UINT ArgIdx; 1760 - PUCHAR thisChar; 1761 - 1762 - MEASURE_REQ_MODE MeasureReqMode; 1763 - UINT8 MeasureReqToken = RandomByte(pAd); 1764 - UINT8 MeasureReqType = RM_BASIC; 1765 - UINT8 MeasureCh = 1; 1766 - 1767 - ArgIdx = 1; 1768 - while ((thisChar = strsep((char **)&arg, "-")) != NULL) 1769 - { 1770 - switch(ArgIdx) 1771 - { 1772 - case 1: // Aid. 1773 - Aid = simple_strtol(thisChar, 0, 16); 1774 - break; 1775 - 1776 - case 2: // Measurement Request Type. 1777 - MeasureReqType = simple_strtol(thisChar, 0, 16); 1778 - if (MeasureReqType > 3) 1779 - { 1780 - DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow MeasureReqType(%d)\n", __func__, MeasureReqType)); 1781 - return TRUE; 1782 - } 1783 - break; 1784 - 1785 - case 3: // Measurement channel. 1786 - MeasureCh = simple_strtol(thisChar, 0, 16); 1787 - break; 1788 - } 1789 - ArgIdx++; 1790 - } 1791 - 1792 - DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __func__, Aid, MeasureReqType, MeasureCh)); 1793 - if (!VALID_WCID(Aid)) 1794 - { 1795 - DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __func__, Aid)); 1796 - return TRUE; 1797 - } 1798 - 1799 - MeasureReqMode.word = 0; 1800 - MeasureReqMode.field.Enable = 1; 1801 - 1802 - MeasureReqInsert(pAd, MeasureReqToken); 1803 - 1804 - EnqueueMeasurementReq(pAd, pAd->MacTab.Content[Aid].Addr, 1805 - MeasureReqToken, MeasureReqMode.word, MeasureReqType, MeasureCh, 2000); 1806 - 1807 - return TRUE; 1808 - } 1809 - 1810 - INT Set_TpcReq_Proc( 1811 - IN PRTMP_ADAPTER pAd, 1812 - IN PUCHAR arg) 1813 - { 1814 - UINT Aid; 1815 - 1816 - UINT8 TpcReqToken = RandomByte(pAd); 1817 - 1818 - Aid = simple_strtol(arg, 0, 16); 1819 - 1820 - DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __func__, Aid)); 1821 - if (!VALID_WCID(Aid)) 1822 - { 1823 - DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __func__, Aid)); 1824 - return TRUE; 1825 - } 1826 - 1827 - TpcReqInsert(pAd, TpcReqToken); 1828 - 1829 - EnqueueTPCReq(pAd, pAd->MacTab.Content[Aid].Addr, TpcReqToken); 1830 - 1831 - return TRUE; 1832 - } 1833 - 1 + #include "../../rt2860/common/spectrum.c"