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