staging: vt6656: Remove WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT macro
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / vt6656 / wcmd.c
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wcmd.c
20 *
21 * Purpose: Handles the management command interface functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2003
26 *
27 * Functions:
28 * s_vProbeChannel - Active scan channel
29 * s_MgrMakeProbeRequest - Make ProbeRequest packet
30 * CommandTimer - Timer function to handle command
31 * s_bCommandComplete - Command Complete function
32 * bScheduleCommand - Push Command and wait Command Scheduler to do
33 * vCommandTimer- Command call back functions
34 * vCommandTimerWait- Call back timer
35 * s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
36 *
37 * Revision History:
38 *
39 */
40
41 #include "ttype.h"
42 #include "tmacro.h"
43 #include "device.h"
44 #include "mac.h"
45 #include "card.h"
46 #include "80211hdr.h"
47 #include "wcmd.h"
48 #include "wmgr.h"
49 #include "power.h"
50 #include "wctl.h"
51 #include "baseband.h"
52 #include "control.h"
53 #include "rxtx.h"
54 #include "rf.h"
55 #include "rndis.h"
56 #include "channel.h"
57 #include "iowpa.h"
58
59 /*--------------------- Static Definitions -------------------------*/
60
61
62
63
64 /*--------------------- Static Classes ----------------------------*/
65
66 /*--------------------- Static Variables --------------------------*/
67 static int msglevel =MSG_LEVEL_INFO;
68 //static int msglevel =MSG_LEVEL_DEBUG;
69 /*--------------------- Static Functions --------------------------*/
70
71 static
72 void
73 s_vProbeChannel(
74 PSDevice pDevice
75 );
76
77
78 static
79 PSTxMgmtPacket
80 s_MgrMakeProbeRequest(
81 PSDevice pDevice,
82 PSMgmtObject pMgmt,
83 PBYTE pScanBSSID,
84 PWLAN_IE_SSID pSSID,
85 PWLAN_IE_SUPP_RATES pCurrRates,
86 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
87 );
88
89
90 static
91 BOOL
92 s_bCommandComplete (
93 PSDevice pDevice
94 );
95
96
97 static BOOL s_bClearBSSID_SCAN(void *hDeviceContext);
98
99 /*--------------------- Export Variables --------------------------*/
100
101 /*--------------------- Export Functions --------------------------*/
102
103 /*
104 * Description:
105 * Stop AdHoc beacon during scan process
106 *
107 * Parameters:
108 * In:
109 * pDevice - Pointer to the adapter
110 * Out:
111 * none
112 *
113 * Return Value: none
114 *
115 */
116
117 static
118 void
119 vAdHocBeaconStop(PSDevice pDevice)
120 {
121
122 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
123 BOOL bStop;
124
125 /*
126 * temporarily stop Beacon packet for AdHoc Server
127 * if all of the following coditions are met:
128 * (1) STA is in AdHoc mode
129 * (2) VT3253 is programmed as automatic Beacon Transmitting
130 * (3) One of the following conditions is met
131 * (3.1) AdHoc channel is in B/G band and the
132 * current scan channel is in A band
133 * or
134 * (3.2) AdHoc channel is in A mode
135 */
136 bStop = FALSE;
137 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
138 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
139 {
140 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
141 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
142 {
143 bStop = TRUE;
144 }
145 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
146 {
147 bStop = TRUE;
148 }
149 }
150
151 if (bStop)
152 {
153 //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
154 // pMgmt->uIBSSChannel, pMgmt->uScanChannel));
155 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
156 }
157
158 } /* vAdHocBeaconStop */
159
160
161 /*
162 * Description:
163 * Restart AdHoc beacon after scan process complete
164 *
165 * Parameters:
166 * In:
167 * pDevice - Pointer to the adapter
168 * Out:
169 * none
170 *
171 * Return Value: none
172 *
173 */
174 static
175 void
176 vAdHocBeaconRestart(PSDevice pDevice)
177 {
178 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
179
180 /*
181 * Restart Beacon packet for AdHoc Server
182 * if all of the following coditions are met:
183 * (1) STA is in AdHoc mode
184 * (2) VT3253 is programmed as automatic Beacon Transmitting
185 */
186 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
187 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
188 {
189 //PMESG(("RESTART_BEACON\n"));
190 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
191 }
192
193 }
194
195
196 /*+
197 *
198 * Routine Description:
199 * Prepare and send probe request management frames.
200 *
201 *
202 * Return Value:
203 * none.
204 *
205 -*/
206
207 static
208 void
209 s_vProbeChannel(
210 PSDevice pDevice
211 )
212 {
213 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
214 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
215 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
216 //6M, 9M, 12M, 48M
217 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
218 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
219 PBYTE pbyRate;
220 PSTxMgmtPacket pTxPacket;
221 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
222 unsigned int ii;
223
224
225 if (pDevice->byBBType == BB_TYPE_11A) {
226 pbyRate = &abyCurrSuppRatesA[0];
227 } else if (pDevice->byBBType == BB_TYPE_11B) {
228 pbyRate = &abyCurrSuppRatesB[0];
229 } else {
230 pbyRate = &abyCurrSuppRatesG[0];
231 }
232 // build an assocreq frame and send it
233 pTxPacket = s_MgrMakeProbeRequest
234 (
235 pDevice,
236 pMgmt,
237 pMgmt->abyScanBSSID,
238 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
239 (PWLAN_IE_SUPP_RATES)pbyRate,
240 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
241 );
242
243 if (pTxPacket != NULL ){
244 for (ii = 0; ii < 1 ; ii++) {
245 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
247 }
248 else {
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
250 }
251 }
252 }
253
254 }
255
256
257
258
259 /*+
260 *
261 * Routine Description:
262 * Constructs an probe request frame
263 *
264 *
265 * Return Value:
266 * A ptr to Tx frame or NULL on allocation failure
267 *
268 -*/
269
270
271 PSTxMgmtPacket
272 s_MgrMakeProbeRequest(
273 PSDevice pDevice,
274 PSMgmtObject pMgmt,
275 PBYTE pScanBSSID,
276 PWLAN_IE_SSID pSSID,
277 PWLAN_IE_SUPP_RATES pCurrRates,
278 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
279
280 )
281 {
282 PSTxMgmtPacket pTxPacket = NULL;
283 WLAN_FR_PROBEREQ sFrame;
284
285
286 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
287 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
288 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
289 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
290 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
291 vMgrEncodeProbeRequest(&sFrame);
292 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
293 (
294 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
295 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
296 ));
297 memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
298 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
299 memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
300 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
301 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
302 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
303 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
304 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
305 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
306 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
307 // Copy the extension rate set
308 if (pDevice->byBBType == BB_TYPE_11G) {
309 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
310 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
311 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
312 }
313 pTxPacket->cbMPDULen = sFrame.len;
314 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
315
316 return pTxPacket;
317 }
318
319 void vCommandTimerWait(void *hDeviceContext, unsigned long MSecond)
320 {
321 PSDevice pDevice = (PSDevice)hDeviceContext;
322
323 init_timer(&pDevice->sTimerCommand);
324
325 pDevice->sTimerCommand.data = (unsigned long)pDevice;
326 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
327 pDevice->sTimerCommand.expires = RUN_AT((MSecond * HZ) / 1000);
328
329 add_timer(&pDevice->sTimerCommand);
330
331 return;
332 }
333
334 void vRunCommand(void *hDeviceContext)
335 {
336 PSDevice pDevice = (PSDevice)hDeviceContext;
337 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
338 PWLAN_IE_SSID pItemSSID;
339 PWLAN_IE_SSID pItemSSIDCurr;
340 CMD_STATUS Status;
341 unsigned int ii;
342 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
343 struct sk_buff *skb;
344 BYTE byData;
345
346
347 if (pDevice->dwDiagRefCount != 0)
348 return;
349 if (pDevice->bCmdRunning != TRUE)
350 return;
351
352 spin_lock_irq(&pDevice->lock);
353
354 switch ( pDevice->eCommandState ) {
355
356 case WLAN_CMD_SCAN_START:
357
358 pDevice->byReAssocCount = 0;
359 if (pDevice->bRadioOff == TRUE) {
360 s_bCommandComplete(pDevice);
361 spin_unlock_irq(&pDevice->lock);
362 return;
363 }
364
365 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
366 s_bCommandComplete(pDevice);
367 spin_unlock_irq(&pDevice->lock);
368 return;
369 }
370
371 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
372
373 if (pMgmt->uScanChannel == 0 ) {
374 pMgmt->uScanChannel = pDevice->byMinChannel;
375 }
376 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
377 pMgmt->eScanState = WMAC_NO_SCANNING;
378
379 if (pDevice->byBBType != pDevice->byScanBBType) {
380 pDevice->byBBType = pDevice->byScanBBType;
381 CARDvSetBSSMode(pDevice);
382 }
383
384 if (pDevice->bUpdateBBVGA) {
385 BBvSetShortSlotTime(pDevice);
386 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
387 BBvUpdatePreEDThreshold(pDevice, FALSE);
388 }
389 // Set channel back
390 vAdHocBeaconRestart(pDevice);
391 // Set channel back
392 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
393 // Set Filter
394 if (pMgmt->bCurrBSSIDFilterOn) {
395 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
396 pDevice->byRxMode |= RCR_BSSID;
397 }
398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
399 pDevice->bStopDataPkt = FALSE;
400 s_bCommandComplete(pDevice);
401 spin_unlock_irq(&pDevice->lock);
402 return;
403
404 } else {
405 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
407 s_bCommandComplete(pDevice);
408 spin_unlock_irq(&pDevice->lock);
409 return;
410 }
411 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
412 // pMgmt->eScanType = WMAC_SCAN_ACTIVE; //mike mark
413 pMgmt->abyScanBSSID[0] = 0xFF;
414 pMgmt->abyScanBSSID[1] = 0xFF;
415 pMgmt->abyScanBSSID[2] = 0xFF;
416 pMgmt->abyScanBSSID[3] = 0xFF;
417 pMgmt->abyScanBSSID[4] = 0xFF;
418 pMgmt->abyScanBSSID[5] = 0xFF;
419 pItemSSID->byElementID = WLAN_EID_SSID;
420 // clear bssid list
421 /* BSSvClearBSSList((void *) pDevice,
422 pDevice->bLinkPass); */
423 pMgmt->eScanState = WMAC_IS_SCANNING;
424 pDevice->byScanBBType = pDevice->byBBType; //lucas
425 pDevice->bStopDataPkt = TRUE;
426 // Turn off RCR_BSSID filter every time
427 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
428 pDevice->byRxMode &= ~RCR_BSSID;
429
430 }
431 //lucas
432 vAdHocBeaconStop(pDevice);
433 if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
434 pDevice->byBBType = BB_TYPE_11A;
435 CARDvSetBSSMode(pDevice);
436 }
437 else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
438 pDevice->byBBType = BB_TYPE_11G;
439 CARDvSetBSSMode(pDevice);
440 }
441 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning.... channel: [%d]\n", pMgmt->uScanChannel);
442 // Set channel
443 CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
444 // Set Baseband to be more sensitive.
445
446 if (pDevice->bUpdateBBVGA) {
447 BBvSetShortSlotTime(pDevice);
448 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
449 BBvUpdatePreEDThreshold(pDevice, TRUE);
450 }
451 pMgmt->uScanChannel++;
452
453 while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
454 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
455 pMgmt->uScanChannel++;
456 }
457
458 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
459 // Set Baseband to be not sensitive and rescan
460 pDevice->eCommandState = WLAN_CMD_SCAN_END;
461
462 }
463 if ((pMgmt->b11hEnable == FALSE) ||
464 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
465 s_vProbeChannel(pDevice);
466 spin_unlock_irq(&pDevice->lock);
467 vCommandTimerWait((void *) pDevice, 100);
468 return;
469 } else {
470 spin_unlock_irq(&pDevice->lock);
471 vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
472 return;
473 }
474
475 }
476
477 break;
478
479 case WLAN_CMD_SCAN_END:
480
481 // Set Baseband's sensitivity back.
482 if (pDevice->byBBType != pDevice->byScanBBType) {
483 pDevice->byBBType = pDevice->byScanBBType;
484 CARDvSetBSSMode(pDevice);
485 }
486
487 if (pDevice->bUpdateBBVGA) {
488 BBvSetShortSlotTime(pDevice);
489 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
490 BBvUpdatePreEDThreshold(pDevice, FALSE);
491 }
492
493 // Set channel back
494 vAdHocBeaconRestart(pDevice);
495 // Set channel back
496 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
497 // Set Filter
498 if (pMgmt->bCurrBSSIDFilterOn) {
499 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
500 pDevice->byRxMode |= RCR_BSSID;
501 }
502 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
503 pMgmt->eScanState = WMAC_NO_SCANNING;
504 pDevice->bStopDataPkt = FALSE;
505
506 if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
507 {
508 //send scan event to wpa_Supplicant
509 union iwreq_data wrqu;
510 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
511 memset(&wrqu, 0, sizeof(wrqu));
512 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
513 }
514 s_bCommandComplete(pDevice);
515 break;
516
517 case WLAN_CMD_DISASSOCIATE_START :
518 pDevice->byReAssocCount = 0;
519 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
520 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
521 s_bCommandComplete(pDevice);
522 spin_unlock_irq(&pDevice->lock);
523 return;
524 } else {
525
526 pDevice->bwextstep0 = FALSE;
527 pDevice->bwextstep1 = FALSE;
528 pDevice->bwextstep2 = FALSE;
529 pDevice->bwextstep3 = FALSE;
530 pDevice->bWPASuppWextEnabled = FALSE;
531 pDevice->fWPA_Authened = FALSE;
532
533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
534 // reason = 8 : disassoc because sta has left
535 vMgrDisassocBeginSta((void *) pDevice,
536 pMgmt,
537 pMgmt->abyCurrBSSID,
538 (8),
539 &Status);
540 pDevice->bLinkPass = FALSE;
541 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
542 // unlock command busy
543 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
544 pItemSSID->len = 0;
545 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
546 pMgmt->eCurrState = WMAC_STATE_IDLE;
547 pMgmt->sNodeDBTable[0].bActive = FALSE;
548 // pDevice->bBeaconBufReady = FALSE;
549 }
550 netif_stop_queue(pDevice->dev);
551 if (pDevice->bNeedRadioOFF == TRUE)
552 CARDbRadioPowerOff(pDevice);
553 s_bCommandComplete(pDevice);
554 break;
555
556
557 case WLAN_CMD_SSID_START:
558
559 pDevice->byReAssocCount = 0;
560 if (pDevice->bRadioOff == TRUE) {
561 s_bCommandComplete(pDevice);
562 spin_unlock_irq(&pDevice->lock);
563 return;
564 }
565
566 memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
567 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
568
569 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
570 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
572 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
573
574 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
576 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
577 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
578 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
579 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
580 }
581
582 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
583 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
584
585 if (pItemSSID->len == pItemSSIDCurr->len) {
586 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
587 s_bCommandComplete(pDevice);
588 spin_unlock_irq(&pDevice->lock);
589 return;
590 }
591 }
592 netif_stop_queue(pDevice->dev);
593 pDevice->bLinkPass = FALSE;
594 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
595 }
596 // set initial state
597 pMgmt->eCurrState = WMAC_STATE_IDLE;
598 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
599 PSvDisablePowerSaving((void *) pDevice);
600 BSSvClearNodeDBTable(pDevice, 0);
601 vMgrJoinBSSBegin((void *) pDevice, &Status);
602 // if Infra mode
603 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
604 // Call mgr to begin the deauthentication
605 // reason = (3) because sta has left ESS
606 if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
607 vMgrDeAuthenBeginSta((void *)pDevice,
608 pMgmt,
609 pMgmt->abyCurrBSSID,
610 (3),
611 &Status);
612 }
613 // Call mgr to begin the authentication
614 vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
615 if (Status == CMD_STATUS_SUCCESS) {
616 pDevice->byLinkWaitCount = 0;
617 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
618 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
619 spin_unlock_irq(&pDevice->lock);
620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
621 return;
622 }
623 }
624 // if Adhoc mode
625 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
626 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
627 if (netif_queue_stopped(pDevice->dev)){
628 netif_wake_queue(pDevice->dev);
629 }
630 pDevice->bLinkPass = TRUE;
631 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
632 pMgmt->sNodeDBTable[0].bActive = TRUE;
633 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
634 }
635 else {
636 // start own IBSS
637 DBG_PRT(MSG_LEVEL_DEBUG,
638 KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
639 vMgrCreateOwnIBSS((void *) pDevice, &Status);
640 if (Status != CMD_STATUS_SUCCESS){
641 DBG_PRT(MSG_LEVEL_DEBUG,
642 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
643 }
644 BSSvAddMulticastNode(pDevice);
645 }
646 s_bClearBSSID_SCAN(pDevice);
647 }
648 // if SSID not found
649 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
650 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
651 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
652 // start own IBSS
653 DBG_PRT(MSG_LEVEL_DEBUG,
654 KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
655 vMgrCreateOwnIBSS((void *) pDevice, &Status);
656 if (Status != CMD_STATUS_SUCCESS){
657 DBG_PRT(MSG_LEVEL_DEBUG,
658 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
659 }
660 BSSvAddMulticastNode(pDevice);
661 s_bClearBSSID_SCAN(pDevice);
662 /*
663 pDevice->bLinkPass = TRUE;
664 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
665 if (netif_queue_stopped(pDevice->dev)){
666 netif_wake_queue(pDevice->dev);
667 }
668 s_bClearBSSID_SCAN(pDevice);
669 */
670 }
671 else {
672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
673 // if(pDevice->bWPASuppWextEnabled == TRUE)
674 {
675 union iwreq_data wrqu;
676 memset(&wrqu, 0, sizeof (wrqu));
677 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
678 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
679 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
680 }
681 }
682 }
683 s_bCommandComplete(pDevice);
684 break;
685
686 case WLAN_AUTHENTICATE_WAIT :
687 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
688 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
689 pDevice->byLinkWaitCount = 0;
690 // Call mgr to begin the association
691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
692 vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
693 if (Status == CMD_STATUS_SUCCESS) {
694 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
695 pDevice->byLinkWaitCount = 0;
696 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
697 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
698 spin_unlock_irq(&pDevice->lock);
699 return;
700 }
701 }
702 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
703 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
704 }
705 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
706 pDevice->byLinkWaitCount ++;
707 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
708 spin_unlock_irq(&pDevice->lock);
709 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
710 return;
711 }
712 pDevice->byLinkWaitCount = 0;
713
714 s_bCommandComplete(pDevice);
715 break;
716
717 case WLAN_ASSOCIATE_WAIT :
718 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
719 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
720 if (pDevice->ePSMode != WMAC_POWER_CAM) {
721 PSvEnablePowerSaving((void *) pDevice,
722 pMgmt->wListenInterval);
723 }
724 /*
725 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
726 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
727 }
728 */
729 pDevice->byLinkWaitCount = 0;
730 pDevice->byReAssocCount = 0;
731 pDevice->bLinkPass = TRUE;
732 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
733 s_bClearBSSID_SCAN(pDevice);
734
735 if (netif_queue_stopped(pDevice->dev)){
736 netif_wake_queue(pDevice->dev);
737 }
738
739 if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time
740 // printk("Re-initial TxDataTimer****\n");
741 del_timer(&pDevice->sTimerTxData);
742 init_timer(&pDevice->sTimerTxData);
743 pDevice->sTimerTxData.data = (unsigned long) pDevice;
744 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
745 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
746 pDevice->fTxDataInSleep = FALSE;
747 pDevice->nTxDataTimeCout = 0;
748 }
749 else {
750 // printk("mike:-->First time trigger TimerTxData InSleep\n");
751 }
752 pDevice->IsTxDataTrigger = TRUE;
753 add_timer(&pDevice->sTimerTxData);
754
755 }
756 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
757 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
758 }
759 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
760 pDevice->byLinkWaitCount ++;
761 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
762 spin_unlock_irq(&pDevice->lock);
763 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
764 return;
765 }
766 pDevice->byLinkWaitCount = 0;
767
768 s_bCommandComplete(pDevice);
769 break;
770
771 case WLAN_CMD_AP_MODE_START :
772 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
773
774 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
775 del_timer(&pMgmt->sTimerSecondCallback);
776 pMgmt->eCurrState = WMAC_STATE_IDLE;
777 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
778 pDevice->bLinkPass = FALSE;
779 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
780 if (pDevice->bEnableHostWEP == TRUE)
781 BSSvClearNodeDBTable(pDevice, 1);
782 else
783 BSSvClearNodeDBTable(pDevice, 0);
784 pDevice->uAssocCount = 0;
785 pMgmt->eCurrState = WMAC_STATE_IDLE;
786 pDevice->bFixRate = FALSE;
787
788 vMgrCreateOwnIBSS((void *) pDevice, &Status);
789 if (Status != CMD_STATUS_SUCCESS) {
790 DBG_PRT(MSG_LEVEL_DEBUG,
791 KERN_INFO "vMgrCreateOwnIBSS fail!\n");
792 }
793 // always turn off unicast bit
794 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
795 pDevice->byRxMode &= ~RCR_UNICAST;
796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
797 BSSvAddMulticastNode(pDevice);
798 if (netif_queue_stopped(pDevice->dev)){
799 netif_wake_queue(pDevice->dev);
800 }
801 pDevice->bLinkPass = TRUE;
802 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
803 add_timer(&pMgmt->sTimerSecondCallback);
804 }
805 s_bCommandComplete(pDevice);
806 break;
807
808 case WLAN_CMD_TX_PSPACKET_START :
809 // DTIM Multicast tx
810 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
811 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
812 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
813 pMgmt->abyPSTxMap[0] &= ~byMask[0];
814 pDevice->bMoreData = FALSE;
815 }
816 else {
817 pDevice->bMoreData = TRUE;
818 }
819
820 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
821 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
822 }
823
824 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
825 }
826 }
827
828 // PS nodes tx
829 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
830 if (pMgmt->sNodeDBTable[ii].bActive &&
831 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
832 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
833 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
834 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
835 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
836 // clear tx map
837 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
838 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
839 pDevice->bMoreData = FALSE;
840 }
841 else {
842 pDevice->bMoreData = TRUE;
843 }
844
845 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
846 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
847 }
848
849 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
850 // check if sta ps enable, wait next pspoll
851 // if sta ps disable, send all pending buffers.
852 if (pMgmt->sNodeDBTable[ii].bPSEnable)
853 break;
854 }
855 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
856 // clear tx map
857 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
858 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
860 }
861 pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE;
862 }
863 }
864
865 s_bCommandComplete(pDevice);
866 break;
867
868 case WLAN_CMD_RADIO_START:
869
870 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
871 // if (pDevice->bRadioCmd == TRUE)
872 // CARDbRadioPowerOn(pDevice);
873 // else
874 // CARDbRadioPowerOff(pDevice);
875
876 {
877 int ntStatus = STATUS_SUCCESS;
878 BYTE byTmp;
879
880 ntStatus = CONTROLnsRequestIn(pDevice,
881 MESSAGE_TYPE_READ,
882 MAC_REG_GPIOCTL1,
883 MESSAGE_REQUEST_MACREG,
884 1,
885 &byTmp);
886
887 if ( ntStatus != STATUS_SUCCESS ) {
888 s_bCommandComplete(pDevice);
889 spin_unlock_irq(&pDevice->lock);
890 return;
891 }
892 if ( (byTmp & GPIO3_DATA) == 0 ) {
893 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
894 // Old commands are useless.
895 // empty command Q
896 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
897 pDevice->uCmdDequeueIdx = 0;
898 pDevice->uCmdEnqueueIdx = 0;
899 //0415pDevice->bCmdRunning = FALSE;
900 pDevice->bCmdClear = TRUE;
901 pDevice->bStopTx0Pkt = FALSE;
902 pDevice->bStopDataPkt = TRUE;
903
904 pDevice->byKeyIndex = 0;
905 pDevice->bTransmitKey = FALSE;
906 spin_unlock_irq(&pDevice->lock);
907 KeyvInitTable(pDevice,&pDevice->sKey);
908 spin_lock_irq(&pDevice->lock);
909 pMgmt->byCSSPK = KEY_CTL_NONE;
910 pMgmt->byCSSGK = KEY_CTL_NONE;
911
912 if (pDevice->bLinkPass == TRUE) {
913 // reason = 8 : disassoc because sta has left
914 vMgrDisassocBeginSta((void *) pDevice,
915 pMgmt,
916 pMgmt->abyCurrBSSID,
917 (8),
918 &Status);
919 pDevice->bLinkPass = FALSE;
920 // unlock command busy
921 pMgmt->eCurrState = WMAC_STATE_IDLE;
922 pMgmt->sNodeDBTable[0].bActive = FALSE;
923 // if(pDevice->bWPASuppWextEnabled == TRUE)
924 {
925 union iwreq_data wrqu;
926 memset(&wrqu, 0, sizeof (wrqu));
927 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
928 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
929 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
930 }
931 }
932 pDevice->bwextstep0 = FALSE;
933 pDevice->bwextstep1 = FALSE;
934 pDevice->bwextstep2 = FALSE;
935 pDevice->bwextstep3 = FALSE;
936 pDevice->bWPASuppWextEnabled = FALSE;
937 //clear current SSID
938 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
939 pItemSSID->len = 0;
940 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
941 //clear desired SSID
942 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
943 pItemSSID->len = 0;
944 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
945
946 netif_stop_queue(pDevice->dev);
947 CARDbRadioPowerOff(pDevice);
948 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
949 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
950 pDevice->bHWRadioOff = TRUE;
951 } else {
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
953 pDevice->bHWRadioOff = FALSE;
954 CARDbRadioPowerOn(pDevice);
955 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
956 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
957 }
958 }
959
960 s_bCommandComplete(pDevice);
961 break;
962
963
964 case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
965
966 pDevice->bStopDataPkt = TRUE;
967 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
968 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
969 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
970 pDevice->bStopDataPkt = FALSE;
971 s_bCommandComplete(pDevice);
972 break;
973
974 case WLAN_CMD_TBTT_WAKEUP_START:
975 PSbIsNextTBTTWakeUp(pDevice);
976 s_bCommandComplete(pDevice);
977 break;
978
979 case WLAN_CMD_BECON_SEND_START:
980 bMgrPrepareBeaconToSend(pDevice, pMgmt);
981 s_bCommandComplete(pDevice);
982 break;
983
984 case WLAN_CMD_SETPOWER_START:
985
986 RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
987
988 s_bCommandComplete(pDevice);
989 break;
990
991 case WLAN_CMD_CHANGE_ANTENNA_START:
992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
993 if ( pDevice->dwRxAntennaSel == 0) {
994 pDevice->dwRxAntennaSel=1;
995 if (pDevice->bTxRxAntInv == TRUE)
996 BBvSetAntennaMode(pDevice, ANT_RXA);
997 else
998 BBvSetAntennaMode(pDevice, ANT_RXB);
999 } else {
1000 pDevice->dwRxAntennaSel=0;
1001 if (pDevice->bTxRxAntInv == TRUE)
1002 BBvSetAntennaMode(pDevice, ANT_RXB);
1003 else
1004 BBvSetAntennaMode(pDevice, ANT_RXA);
1005 }
1006 s_bCommandComplete(pDevice);
1007 break;
1008
1009 case WLAN_CMD_REMOVE_ALLKEY_START:
1010 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
1011 s_bCommandComplete(pDevice);
1012 break;
1013
1014
1015 case WLAN_CMD_MAC_DISPOWERSAVING_START:
1016 ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
1017 if ( (byData & PSCTL_PS) != 0 ) {
1018 // disable power saving hw function
1019 CONTROLnsRequestOut(pDevice,
1020 MESSAGE_TYPE_DISABLE_PS,
1021 0,
1022 0,
1023 0,
1024 NULL
1025 );
1026 }
1027 s_bCommandComplete(pDevice);
1028 break;
1029
1030 case WLAN_CMD_11H_CHSW_START:
1031 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
1032 pDevice->bChannelSwitch = FALSE;
1033 pMgmt->uCurrChannel = pDevice->byNewChannel;
1034 pDevice->bStopDataPkt = FALSE;
1035 s_bCommandComplete(pDevice);
1036 break;
1037
1038 default:
1039 s_bCommandComplete(pDevice);
1040 break;
1041 } //switch
1042
1043 spin_unlock_irq(&pDevice->lock);
1044 return;
1045 }
1046
1047
1048 static
1049 BOOL
1050 s_bCommandComplete (
1051 PSDevice pDevice
1052 )
1053 {
1054 PWLAN_IE_SSID pSSID;
1055 BOOL bRadioCmd = FALSE;
1056 //WORD wDeAuthenReason = 0;
1057 BOOL bForceSCAN = TRUE;
1058 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1059
1060
1061 pDevice->eCommandState = WLAN_CMD_IDLE;
1062 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
1063 //Command Queue Empty
1064 pDevice->bCmdRunning = FALSE;
1065 return TRUE;
1066 }
1067 else {
1068 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
1069 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
1070 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
1071 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
1072 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
1073 pDevice->cbFreeCmdQueue++;
1074 pDevice->bCmdRunning = TRUE;
1075 switch ( pDevice->eCommand ) {
1076 case WLAN_CMD_BSSID_SCAN:
1077 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
1078 pDevice->eCommandState = WLAN_CMD_SCAN_START;
1079 pMgmt->uScanChannel = 0;
1080 if (pSSID->len != 0) {
1081 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1082 } else {
1083 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1084 }
1085 /*
1086 if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) {
1087 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
1088 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
1089 pDevice->eCommandState = WLAN_CMD_IDLE;
1090 }
1091 }
1092 */
1093 break;
1094 case WLAN_CMD_SSID:
1095 pDevice->eCommandState = WLAN_CMD_SSID_START;
1096 if (pSSID->len > WLAN_SSID_MAXLEN)
1097 pSSID->len = WLAN_SSID_MAXLEN;
1098 if (pSSID->len != 0)
1099 memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
1101 break;
1102 case WLAN_CMD_DISASSOCIATE:
1103 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
1104 break;
1105 case WLAN_CMD_RX_PSPOLL:
1106 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
1107 break;
1108 case WLAN_CMD_RUN_AP:
1109 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
1110 break;
1111 case WLAN_CMD_RADIO:
1112 pDevice->eCommandState = WLAN_CMD_RADIO_START;
1113 pDevice->bRadioCmd = bRadioCmd;
1114 break;
1115 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1116 pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
1117 break;
1118
1119 case WLAN_CMD_TBTT_WAKEUP:
1120 pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
1121 break;
1122
1123 case WLAN_CMD_BECON_SEND:
1124 pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
1125 break;
1126
1127 case WLAN_CMD_SETPOWER:
1128 pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
1129 break;
1130
1131 case WLAN_CMD_CHANGE_ANTENNA:
1132 pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
1133 break;
1134
1135 case WLAN_CMD_REMOVE_ALLKEY:
1136 pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
1137 break;
1138
1139 case WLAN_CMD_MAC_DISPOWERSAVING:
1140 pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
1141 break;
1142
1143 case WLAN_CMD_11H_CHSW:
1144 pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
1145 break;
1146
1147 default:
1148 break;
1149
1150 }
1151 vCommandTimerWait((void *) pDevice, 0);
1152 }
1153
1154 return TRUE;
1155 }
1156
1157 BOOL bScheduleCommand(void *hDeviceContext,
1158 CMD_CODE eCommand,
1159 PBYTE pbyItem0)
1160 {
1161 PSDevice pDevice = (PSDevice)hDeviceContext;
1162
1163
1164 if (pDevice->cbFreeCmdQueue == 0) {
1165 return (FALSE);
1166 }
1167 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1168 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE;
1169 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1170 if (pbyItem0 != NULL) {
1171 switch (eCommand) {
1172 case WLAN_CMD_BSSID_SCAN:
1173 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE;
1174 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1175 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1176 break;
1177
1178 case WLAN_CMD_SSID:
1179 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1180 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1181 break;
1182
1183 case WLAN_CMD_DISASSOCIATE:
1184 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1185 break;
1186 /*
1187 case WLAN_CMD_DEAUTH:
1188 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
1189 break;
1190 */
1191
1192 case WLAN_CMD_RADIO:
1193 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1194 break;
1195
1196 default:
1197 break;
1198 }
1199 }
1200
1201 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1202 pDevice->cbFreeCmdQueue--;
1203
1204 if (pDevice->bCmdRunning == FALSE) {
1205 s_bCommandComplete(pDevice);
1206 }
1207 else {
1208 }
1209 return (TRUE);
1210
1211 }
1212
1213 /*
1214 * Description:
1215 * Clear BSSID_SCAN cmd in CMD Queue
1216 *
1217 * Parameters:
1218 * In:
1219 * hDeviceContext - Pointer to the adapter
1220 * eCommand - Command
1221 * Out:
1222 * none
1223 *
1224 * Return Value: TRUE if success; otherwise FALSE
1225 *
1226 */
1227 static BOOL s_bClearBSSID_SCAN(void *hDeviceContext)
1228 {
1229 PSDevice pDevice = (PSDevice)hDeviceContext;
1230 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1231 unsigned int ii;
1232
1233 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1234 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1235 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1236 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1237 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1238 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1239 break;
1240 }
1241 }
1242 return TRUE;
1243 }
1244
1245
1246 //mike add:reset command timer
1247 void vResetCommandTimer(void *hDeviceContext)
1248 {
1249 PSDevice pDevice = (PSDevice)hDeviceContext;
1250
1251 //delete timer
1252 del_timer(&pDevice->sTimerCommand);
1253 //init timer
1254 init_timer(&pDevice->sTimerCommand);
1255 pDevice->sTimerCommand.data = (unsigned long)pDevice;
1256 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
1257 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1258 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1259 pDevice->uCmdDequeueIdx = 0;
1260 pDevice->uCmdEnqueueIdx = 0;
1261 pDevice->eCommandState = WLAN_CMD_IDLE;
1262 pDevice->bCmdRunning = FALSE;
1263 pDevice->bCmdClear = FALSE;
1264 }
1265
1266 void BSSvSecondTxData(void *hDeviceContext)
1267 {
1268 PSDevice pDevice = (PSDevice)hDeviceContext;
1269 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1270
1271 pDevice->nTxDataTimeCout++;
1272
1273 if (pDevice->nTxDataTimeCout < 4) { //don't tx data if timer less than 40s
1274 // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1275 // (int)pDevice->nTxDataTimeCout);
1276 pDevice->sTimerTxData.expires = RUN_AT(10 * HZ); //10s callback
1277 add_timer(&pDevice->sTimerTxData);
1278 return;
1279 }
1280
1281 spin_lock_irq(&pDevice->lock);
1282 //is wap_supplicant running successful OR only open && sharekey mode!
1283 if (((pDevice->bLinkPass == TRUE) &&
1284 (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1285 (pDevice->fWPA_Authened == TRUE)) { //wpa linking
1286 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1287 pDevice->fTxDataInSleep = TRUE;
1288 PSbSendNullPacket(pDevice); //send null packet
1289 pDevice->fTxDataInSleep = FALSE;
1290 }
1291 spin_unlock_irq(&pDevice->lock);
1292
1293 pDevice->sTimerTxData.expires = RUN_AT(10 * HZ); //10s callback
1294 add_timer(&pDevice->sTimerTxData);
1295 }