MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdhci.c
blobbda42c426b1e8ab41b8db1bac74d1a711a8d07ad
1 #ifndef _ZDHCI_C_
2 #define _ZDHCI_C_
3 #include "zd80211.h"
4 #include "zdhci.h"
5 #include "zdequates.h"
6 #include "zd1205.h"
7 #include "zddebug.h"
9 #define MAX_CHANNEL_ALLOW 13
11 BOOLEAN zd_PseudoIbssConnect(void);
13 static U8 zd_Snap_Header[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
14 static U8 zd_SnapBridgeTunnel[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
15 static U8 zd_Snap_Apple_Type[] = {0xAA,0xAA,0x03,0x08,0x00,0x07,0x80,0x9b};
16 static U8 zd_Snap_Apple_AARP[] = {0xAA,0xAA,0x03,0x00,0x00,0x00,0x80,0xf3};
18 extern struct net_device *g_dev;
19 zd_80211Obj_t *pdot11Obj = 0;
21 extern const U16 dot11A_Channel[];
22 extern const U16 dot11A_Channel_Amount;
23 extern void ChangeMacMode(u8 MAC_Mode,u8 Channel);
24 extern U32 mTimeBeforeAdhocRoaming;
27 U16 CurrScanCH = 1;
29 BOOLEAN zd_SendPkt(U8 *pEthHdr, U8 *pBody, U32 bodyLen, void *buf, U8 bEapol, void *pHash)
31 struct zd1205_private *macp = (struct zd1205_private *)g_dev->priv;
32 Signal_t *signal;
33 #if ZDCONF_LP_SUPPORT == 1
34 U8 EthHdr[14];
35 #endif
36 FrmDesc_t *pfrmDesc;
37 Frame_t *frame;
38 U8 vapId = 0;
40 //FPRINT("zd_SendPkt");
41 if (mPsStaCnt){
42 if (zd_CheckTotalQueCnt() > TXQ_THRESHOLD){
43 //FPRINT("Drop Tx packet");
44 return FALSE;
47 signal = allocSignal();
48 if (!signal){
49 FPRINT("zd_SendPkt out of signal");
50 FPRINT_V("freeSignalCount", freeSignalCount);
51 return FALSE;
53 #if ZDCONF_LP_SUPPORT == 1
54 memcpy(signal->EthHdr,pEthHdr,14);
55 #endif
56 pfrmDesc = allocFdesc();
57 if (!pfrmDesc){
58 freeSignal(signal);
59 FPRINT("zd_SendPkt out of description");
60 FPRINT_V("freeFdescCount", freeFdescCount);
61 return FALSE;
64 frame = pfrmDesc->mpdu;
65 /* FrameControl(2) Duration/ID(2) A1(6) A2(6) A3(6) Seq(2) A4/LLCHdr(6) LLCHdr(6) */
66 if (mBssType == AP_BSS){
67 memcpy((char *)&(frame->header[4]), (char *)&(pEthHdr[0]), 6); /* Set DA to A1 */
68 memcpy((char *)&(frame->header[16]), (char *)&(pEthHdr[6]), 6); /* Set SA to A3 */
69 frame->header[1] = FROM_DS_BIT;
70 } else if (mBssType == INFRASTRUCTURE_BSS){
71 memcpy((char *)&(frame->header[4]), (char *)&mBssId, 6); /* Set BSSID to A1 */
72 memcpy((char *)&(frame->header[16]), (char *)&(pEthHdr[0]), 6); /* Set DA to A3 */
73 frame->header[1] = TO_DS_BIT;
74 if (mPwrState && macp->bAssoc)
75 frame->header[1] |= PW_SAVE_BIT;
76 else
77 frame->header[1] &= ~PW_SAVE_BIT;
79 else if ((mBssType == INDEPENDENT_BSS) || (mBssType == PSEUDO_IBSS)){
80 memcpy((char *)&(frame->header[4]), (char *)&(pEthHdr[0]), 6); /* Set DA to A1 */
81 memcpy((char *)&(frame->header[16]), (char *)&mBssId, 6); /* Set Bssid to A3 */
82 frame->header[1] = 0;
85 frame->bodyLen = bodyLen;
86 frame->body = pBody;
87 signal->buf = buf;
88 signal->vapId = vapId;
89 pfrmDesc->ConfigSet &= ~INTRA_BSS_SET;
90 frame->HdrLen = MAC_HDR_LNG;
91 frame->header[0] = ST_DATA;
92 setAddr2(frame, &dot11MacAddress);
94 if (bEapol)
95 pfrmDesc->ConfigSet |= EAPOL_FRAME_SET;
96 else
97 pfrmDesc->ConfigSet &= ~EAPOL_FRAME_SET;
99 signal->bDataFrm = 1;
100 //pfrmDesc->bDataFrm = 1;
101 pfrmDesc->pHash = (Hash_t *)pHash;
102 if (pHash == NULL && !(pEthHdr[0]&BIT_0) )
103 printk(KERN_ERR "===== ==== ===pHash is NULL in zd_SendPkt\n");
104 mkFragment(signal, pfrmDesc, pEthHdr); //10 us
105 #if 0
106 //force free for debug only
107 zd1205_dump_data("header", (u8 *)&frame->header[0], frame->HdrLen);
108 zd1205_dump_data("body", (u8 *)frame->body, frame->bodyLen);
109 freeSignal(signal);
110 freeFdesc(pfrmDesc);
111 return TRUE;
112 #endif
114 #if 1
115 if (SendPkt(signal, pfrmDesc, TRUE)) //4727
116 return FALSE;
117 else
118 return TRUE;
119 #else
120 SendPkt(signal, pfrmDesc, TRUE);
121 return TRUE;
122 #endif
125 #define LP_FORWARD 0
126 #define BC_FORWARD 1
127 #define BSS_FORWARD 2
128 void zd_WirelessForward(U8 *pHdr, U8 *pBody, U32 len, void *buf, U8 mode, void *pHash, U8 *pEthHdr)
130 Signal_t *signal;
131 FrmDesc_t *pfrmDesc;
132 Frame_t *frame;
133 U8 vapId = 0;
134 //FPRINT("zd_WirelessForward");
136 if (mPsStaCnt){
137 if (zd_CheckTotalQueCnt() > TXQ_THRESHOLD){
138 //FPRINT("Drop Intra-BSS packet");
139 pdot11Obj->ReleaseBuffer(buf);
140 return;
144 signal = allocSignal();
145 if (!signal){
146 FPRINT("zd_WirelessForward out of signal");
147 FPRINT_V("freeSignalCount", freeSignalCount);
148 pdot11Obj->ReleaseBuffer(buf);
149 return;
152 pfrmDesc = allocFdesc();
153 if (!pfrmDesc){
154 freeSignal(signal);
155 FPRINT("zd_WirelessForward out of description");
156 FPRINT_V("freeFdescCount", freeFdescCount);
157 pdot11Obj->ReleaseBuffer(buf);
158 return;
161 frame = pfrmDesc->mpdu;
162 /* FrameControl(2) Duration/ID(2) A1(6) A2(6) A3(6) Seq(2) A4/LLCHdr(6) LLCHdr(6) */
163 memcpy((char *)&(frame->header[4]), (char *)&(pHdr[16]), 6); /* Set DA to A1 */
164 memcpy((char *)&(frame->header[16]), (char *)&(pHdr[10]), 6); /* Set SA to A3 */
165 #if ZDCONF_LP_SUPPORT == 1
166 memcpy(signal->EthHdr, (char *)&(frame->header[4]),6);
167 memcpy(signal->EthHdr+ETH_ALEN, (char *)&(frame->header[16]),6);
168 #endif
170 frame->bodyLen = len;
171 frame->body = pBody;
172 signal->buf = buf;
173 signal->vapId = vapId;
175 if (mode == LP_FORWARD){
176 memcpy((char *)&(frame->header[4]), (char *)&(pHdr[10]), 6); /* Set DA to A1 */
177 memcpy((char *)&(frame->header[16]), (char *)&dot11MacAddress, 6); /* Set SA to A3 */
178 frame->body[6] = 0x38;
179 frame->body[7] = 0x39;
182 pfrmDesc->ConfigSet |= INTRA_BSS_SET;
183 pfrmDesc->ConfigSet &= ~EAPOL_FRAME_SET;
184 signal->bDataFrm = 1;
185 //pfrmDesc->bDataFrm = 1;
186 frame->HdrLen = MAC_HDR_LNG;
187 frame->header[0] = ST_DATA;
188 frame->header[1] = FROM_DS_BIT;
189 setAddr2(frame, &dot11MacAddress);
190 pfrmDesc->pHash = (Hash_t *)pHash;
191 mkFragment(signal, pfrmDesc, pEthHdr);
192 SendPkt(signal, pfrmDesc, FALSE);
193 return;
196 void zd_SendDeauthFrame(U8 *sta, U8 ReasonCode)
198 Signal_t *signal;
200 printk(KERN_ERR "SendDeauthFrame with ReasonCode=%u\n",ReasonCode);
201 if ((mBssType == INDEPENDENT_BSS) || (mBssType == PSEUDO_IBSS))
202 return;
204 if ((signal = allocSignal()) == NULL)
205 return;
206 signal->id = SIG_DEAUTH_REQ;
207 signal->block = BLOCK_AUTH_REQ;
208 signal->vapId = 0;
209 memcpy(&signal->frmInfo.Sta, sta, 6);
210 signal->frmInfo.rCode = ReasonCode;
211 sigEnque(pMgtQ, (signal));
213 return;
216 void zd_SendClass2ErrorFrame(MacAddr_t *sta, U8 vapId)
218 Signal_t *signal;
220 //FPRINT("zd_sendClass2ErrorFrame");
222 if ((mBssType == INDEPENDENT_BSS) || (mBssType == PSEUDO_IBSS))
223 return;
225 if ((signal = allocSignal()) == NULL)
226 return;
227 signal->id = SIG_DEAUTH_REQ;
228 signal->block = BLOCK_AUTH_REQ;
229 signal->vapId = vapId;
230 memcpy(&signal->frmInfo.Sta, sta, 6);
231 signal->frmInfo.rCode = RC_CLASS2_ERROR;
232 sigEnque(pMgtQ, (signal));
234 return;
237 void zd_SendClass3ErrorFrame(MacAddr_t *sta, U8 vapId)
239 Signal_t *signal;
241 //FPRINT("zd_SendClass3ErrorFrame");
242 if ((mBssType == INDEPENDENT_BSS) || (mBssType == PSEUDO_IBSS))
243 return;
245 if ((signal = allocSignal()) == NULL)
246 return;
248 signal->id = SIG_DIASSOC_REQ;
249 signal->block = BLOCK_ASOC;
250 signal->vapId = vapId;
251 memcpy(&signal->frmInfo.Sta, sta, 6);
252 signal->frmInfo.rCode = RC_CLASS3_ERROR;
253 sigEnque(pMgtQ, (signal));
255 return;
258 #define MIC_HEADER_LEN 16
259 BOOLEAN zd_CheckMic(U8 *pHdr, U8 *pBody, U32 bodyLen, Hash_t *pHash, U8 *pEthHdr)
261 MICvar *pRxMicKey;
262 U8 PkInstalled = 0;
263 U8 *pByte;
264 U8 CalMic[8];
265 int i = 0;
266 U8 *pIV = pHdr + 24;
268 /* Always return TRUE, 4D06 */
269 //return TRUE;
270 //if (!pHash)
271 // return FALSE;
273 if (pIV[3] & EIV_BIT)
275 if (pHdr[4] & 1) // Use group key
277 if (mGkInstalled)
278 pRxMicKey = &mBcMicKey;
279 else
280 return FALSE;
282 else // Use Unicast key
284 if (!pHash)
285 return FALSE;
286 if ((PkInstalled=pHash->pkInstalled))
287 pRxMicKey = &pHash->RxMicKey;
288 else
289 return FALSE;
292 //zd1205_dump_data("IV = ", pIV, 8);
293 //zd1205_dump_data("MIC K0= ", (U8 *)&pRxMicKey->K0, 4);
294 //zd1205_dump_data("MIC K1= ", (U8 *)&pRxMicKey->K1, 4);
295 //pRxMicKey = &pHash->RxMicKey;
297 //PkInstalled = pHash->pkInstalled;
299 if (1){
300 U32 Len = bodyLen - MIC_LNG;
301 #if 0
302 void *reg = pdot11Obj->reg;
303 U32 BolckLen = 0;
304 U32 tmpValue = 0;
305 U32 BlockNum = 2;
306 U32 MicLow, MicHigh;
307 U32 MicStatus = 0;
308 U32 HwMicStatus = 0;
309 register int j = 0;
310 U32 RxMicWrBackAddr = (U32)pEthHdr + MIC_HEADER_LEN;
311 U32 HwMicHighPhys = RxMicWrBackAddr + 4;
312 U32 HwMicStatusPhys = HwMicHighPhys + 4;
314 //FPRINT("************* RX MIC ****************");
316 //reser HW MIC status
317 memset(RxMicWrBackAddr, 0x11, 12);
319 //wait last MIC finish, then start this one
320 MicStatus = pdot11Obj->GetReg(reg, ZD_MIC_STATUS);
321 while (MicStatus & MIC_BUSY){
322 pdot11Obj->DelayUs(1);
323 MicStatus = pdot11Obj->GetReg(reg, ZD_MIC_STATUS);
324 j++;
325 if (j>1000){
326 bMicFinish = FALSE;
327 //FPRINT("Rx MIC can't start !!!");
328 //FPRINT_V("MicStatus", MicStatus);
329 zdCnt.RxMicNoStart++;
330 break;
334 //set mic key
335 pdot11Obj->SetReg(reg, ZD_MIC_KEY_LOW, pRxMicKey->K0);
336 pdot11Obj->SetReg(reg, ZD_MIC_KEY_HIGH, pRxMicKey->K1);
338 //set 802.3 header
339 pdot11Obj->SetReg(reg, ZD_MIC_START_ADDR0, (U32)pEthHdr);
340 pdot11Obj->SetReg(reg, ZD_MIC_BLOCK0_LEN, MIC_HEADER_LEN);
342 //set mac body
343 pdot11Obj->SetReg(reg, ZD_MIC_START_ADDR1, (U32)pBody);
344 pdot11Obj->SetReg(reg, ZD_MIC_BLOCK1_LEN, Len);
346 //set write back address
347 pdot11Obj->SetReg(reg, ZD_MIC_WRITE_BACK_ADDRS, (U32)RxMicWrBackAddr);
349 BolckLen = MIC_HEADER_LEN + Len;
350 tmpValue = (BlockNum | (BolckLen << 16));
351 pdot11Obj->SetReg(reg, ZD_MIC_TOTAL_BLOCK_NUM, tmpValue);
353 // busy waiting MIC finish
354 j= 0;
355 HwMicStatus = zd_le32_to_cpu(*(U32 *)(HwMicStatusPhys));
356 while (HwMicStatus != HW_MIC_FINISH){
357 pdot11Obj->DelayUs(1);
358 HwMicStatus = zd_le32_to_cpu(*(U32 *)(HwMicStatusPhys));
359 j++;
360 if (j>1000){
361 bMicFinish = FALSE;
362 //FPRINT("Rx MIC not finish !!!");
363 //FPRINT_V("HwMicStatus", HwMicStatus);
364 zdCnt.RxMicNoFinish++;
365 break;
369 MicLow = zd_le32_to_cpu (*(U32 *)RxMicWrBackAddr);
370 MicHigh = zd_le32_to_cpu (*(U32 *)(HwMicHighPhys));
372 pByte = pBody + Len; //point to MIC start
373 CalMic[0] = (U8) MicLow;
374 CalMic[1] = (U8) (MicLow >> 8);
375 CalMic[2] = (U8) (MicLow >> 16);
376 CalMic[3] = (U8) (MicLow >> 24);
377 CalMic[4] = (U8) MicHigh;
378 CalMic[5] = (U8) (MicHigh >> 8);
379 CalMic[6] = (U8) (MicHigh >> 16);
380 CalMic[7] = (U8) (MicHigh >> 24);
381 #else
382 //Software MIC Calculation, HW MIC failed
383 MICclear(pRxMicKey);
385 //pByte = pEthHdr;
386 if (mBssType == INFRASTRUCTURE_BSS ||
387 mBssType == INDEPENDENT_BSS)
388 pByte = &pHdr[4]; // DA = Addr1
389 else //if (mBssType == AP_BSS)
390 pByte = &pHdr[16]; //DA = Addr3
392 for (i=0; i<6; i++){
393 MICappendByte(*pByte++, pRxMicKey);
395 if (mBssType == AP_BSS ||
396 mBssType == INDEPENDENT_BSS)
397 pByte = &pHdr[10]; // SA=Addr2
398 else // if (mBssType == INFRASTRUCTURE_BSS)
399 pByte = &pHdr[16]; // SA=Addr3
400 for (i=0; i<6; i++){
401 MICappendByte(*pByte++, pRxMicKey);
403 MICappendByte(0,pRxMicKey);//priority
404 MICappendByte(0,pRxMicKey);//3 zeros
405 MICappendByte(0,pRxMicKey);
406 MICappendByte(0,pRxMicKey);
408 pByte = pBody;
409 for (i=0; i<Len; i++){
410 MICappendByte(*pByte++, pRxMicKey);
413 MICgetMIC(CalMic, pRxMicKey); // Append MIC (8 byte)
415 #endif
416 //FPRINT_V("Calcu HW MIC", RxCompLogBuf[RxComplogPktCnt][10]-RxCompLogBuf[RxComplogPktCnt][9]);
418 // now pBye point to MIC area
419 if (pdot11Obj->MIC_CNT && memcmp(CalMic, pByte, MIC_LNG) != 0){
420 zd1205_dump_data("pHdr = ", pHdr, 32);
421 //FPRINT_V("Body Addr", (U32)pBody);
422 zd1205_dump_data("pBody = ", pBody, bodyLen+16);
423 zd1205_dump_data("CalMic = ", CalMic, 8);
424 zd1205_dump_data("ReceMic = ", pByte, 8);
426 printk(KERN_ERR "SW MIC Check fail\n");
427 hostap_michael_mic_failure((struct zd1205_private *)g_dev->priv, (struct hostap_ieee80211_hdr *)pHdr, pIV[3] & KEYID_MASK);
428 //pdot11Obj->MicFailure(&pEthHdr[6]);
429 return FALSE;
431 else{
432 //FPRINT("***** MIC success *****");
433 //printk(KERN_ERR "SW MIC check OK\n");
434 return TRUE;
439 return FALSE;
442 void zd_ReceivePkt(U8 *pHdr, U32 hdrLen, U8 *pBody, U32 bodyLen, void *buf, U8 *pEthHdr, rxInfo_t *pRxInfo, const BOOLEAN LP)
444 U8 *x;
445 Signal_t *pRxSignal;
446 FrmDesc_t *pRxFdesc;
447 Frame_t *pRxFrame;
448 MacAddr_t *pDa, *pSa;
449 StationState sas;
450 PsMode psm = PSMODE_STA_ACTIVE;
451 U32 dataLen = 0xFFFFFFFF;
452 U8 *pData = NULL;
453 U8 mode;
454 void *bcBuf;
455 U8 *pBcData;
456 Hash_t *pHash;
457 U8 vapId = 0;
458 U8 rate = pRxInfo->rate;
459 U8 bDataFrm = pRxInfo->bDataFrm;
460 U8 SaIndex = pRxInfo->SaIndex;
461 U8 signalStrength = pRxInfo->signalStrength;
462 U8 signalQuality = pRxInfo->signalQuality;
463 U8 bSwCheckMIC = pRxInfo->bSwCheckMIC;
464 U32 LP_MAP = 0;
465 #if ZDCONF_LP_SUPPORT == 1
466 // ####### FOR A-MSDU ########
467 U16 wCnt;
468 struct sk_buff *skb = NULL;
469 Signal_t *signal;
470 FrmDesc_t *pfrmDesc;
471 Frame_t *frame;
472 U16 dataOff = 0;
473 U16 idx, pktLen,idx2;
474 int j=0;
475 Hash_t *sHash = NULL;
476 U8 HDR[24];
477 U8 *pBody2;
478 U32 len2;
479 // ###########################
482 if(LP)
484 LP_MAP = 0xFFFFFFFF;
486 #endif
489 ZDEBUG("zd_ReceivePkt");
492 if (mBssType == AP_BSS){
493 pDa = (MacAddr_t *)&pHdr[16]; //A3
494 pSa = (MacAddr_t *)&pHdr[10]; //A2
495 if (bDataFrm){
496 //don't care PS Bit in authenticate, (Re)assoicate and Probe Reguest frame
497 psm = (PsMode)((pHdr[1] & PW_SAVE_BIT) ? PSMODE_POWER_SAVE : PSMODE_STA_ACTIVE);
499 if (SaIndex == 0)
500 pHash = RxInfoIndicate(pSa, psm, rate); //12us update ps and rate information
501 else {
502 pHash = sstByAid[SaIndex];
503 if (pHash)
504 RxInfoUpdate(pHash, psm, rate);
507 else if (mBssType == INFRASTRUCTURE_BSS){
508 pDa = (MacAddr_t *)&pHdr[4]; //A1 will be my MAC
509 //pSa = (MacAddr_t *)&pHdr[16]; //A3
510 pSa = (MacAddr_t *)&pHdr[10]; //A2 for Asoc status check
511 pHash = sstByAid[0];
513 else{ // INDEPENDENT_BSS or PSEUDO_IBSS
514 pDa = (MacAddr_t *)&pHdr[4]; //A1
515 pSa = (MacAddr_t *)&pHdr[10]; //A2
516 pHash = RxInfoIndicate(pSa, 0, rate);
518 #if ZDCONF_LP_SUPPORT == 1
519 if(pHash) pHash->LP_CAP = LP;
520 #endif
523 if (bDataFrm){
524 if (!bodyLen)
525 goto rx_release;
527 if (!pHash){
528 zd_SendClass2ErrorFrame(pSa, vapId);
529 goto rx_release;
531 else {
532 sas = pHash->asoc;
533 if ((sas != STATION_STATE_ASOC) && (mBssType == AP_BSS)){
534 //if (sas != STATION_STATE_ASOC){
535 zd_SendClass3ErrorFrame(pSa, vapId);
536 printk(KERN_ERR "Class3ErrFrm:%02X %02X %02X %02X %02X %02X\n",pSa->mac[0],pSa->mac[1],pSa->mac[2],pSa->mac[3],pSa->mac[4],pSa->mac[5]);
537 goto rx_release;
541 if (sas == STATION_STATE_ASOC){ //association station
542 if (mBssType == AP_BSS){
543 if (isGroup(pDa)){
544 if (pHash->keyLength == 32){
545 //if (mDynKeyMode == DYN_KEY_TKIP){
546 if (!pHash->pkInstalled)
547 goto rx_release;
548 else if (!mGkInstalled)
549 goto rx_release;
550 else if ((pHdr[1] & WEP_BIT) && (hdrLen == 32)){
551 if (bSwCheckMIC){
552 if (!zd_CheckMic(pHdr, pBody, bodyLen, pHash, pEthHdr)){
553 goto rx_release;
555 else {
556 bodyLen -= MIC_LNG; //remove MIC
561 if (mCurrConnUser > 1){
562 mode = BC_FORWARD;
563 bcBuf = pdot11Obj->AllocBuffer(bodyLen, &pBcData);
564 if (bcBuf){
565 memcpy(pBcData, pBody, bodyLen);
566 zd_WirelessForward(pHdr, pBcData, bodyLen, bcBuf, mode, NULL, pEthHdr);
569 goto rx_ind;
571 else {
572 void *pTxHash = NULL;
574 if (mBlockBSS){ //discard IntraBSS packet
575 goto rx_release;
578 zd_QueryStaTable((U8 *)pDa, &pTxHash); //Automatic wireless forwarding
580 if (pTxHash){
581 if (bSwCheckMIC)
583 if ((pHash->keyLength==32) && (pHdr[1] & WEP_BIT) && (hdrLen == 32)){
585 if (!zd_CheckMic(pHdr, pBody, bodyLen, pHash, pEthHdr)){
586 goto rx_release;
588 else
589 bodyLen -= MIC_LNG; //remove MIC
593 mode = BSS_FORWARD;
594 zd_WirelessForward(pHdr, pBody, bodyLen, buf, mode, pTxHash, pEthHdr);
595 return;
599 // mic check
600 if (bSwCheckMIC) // For TKIP, always use sw-mic check.
602 //if ((pHash->keyLength==32) && (pHdr[1] & WEP_BIT) && (hdrLen == 32))
604 if (!zd_CheckMic(pHdr, pBody, bodyLen, pHash, pEthHdr))
605 {// sw-mic check failed, discard this packet.
606 goto rx_release;
608 else{// sw-mic check ok, remove MIC
609 bodyLen -= MIC_LNG;
613 rx_ind:
614 if(LP)
616 #if ZDCONF_LP_SUPPORT == 1
617 pData = pBody;
618 dataLen = bodyLen;
619 #endif
621 //If Typelen field is not used for len
622 else if(memcmp(pBody,zd_Snap_Apple_AARP,8)==0 || memcmp(pBody,zd_Snap_Apple_Type,8)==0) {
624 pData = pBody - 14;
625 dataLen = bodyLen + 14; /* Plus DA, SA and TypeLen */
626 pData[12] = (bodyLen>>8) & 0xFF;
627 pData[13] = bodyLen & 0xFF;
631 else if ((bodyLen > 5 ) && (memcmp(pBody, zd_Snap_Header, 6) == 0
632 || memcmp(pBody, zd_SnapBridgeTunnel, 6) == 0)){
634 pData = pBody - 6;
635 dataLen = bodyLen + 6; /* Plus DA, SA*/
637 /* 24 6 2 n
638 *---------------*------*-----*------------------------*
639 | WLAN HDR | SNAP | LEN | DATA |
640 *---------------*------*-----*------------------------*
643 else{
644 pData = pBody - 14;
645 dataLen = bodyLen + 14; /* Plus DA, SA and TypeLen */
646 pData[12] = (bodyLen>>8) & 0xFF;
647 pData[13] = bodyLen & 0xFF;
649 /* 24 6
650 *---------------*------------------------*
651 | WLAN HDR | DATA |
652 *---------------*------------------------*
655 if(!LP)
657 memcpy(pData, pEthHdr, 6); /* Set DA */
658 memcpy(pData+6, pEthHdr+6, 6); /* Set SA */
660 //if (Type == 0x888e)
661 //zd1205_dump_data("pData = ", pData, dataLen);
662 pdot11Obj->RxInd(pData, dataLen, buf, LP_MAP);
663 return;
666 else { //Mgt Frame
667 pRxSignal = allocSignal();
668 if (!pRxSignal){
669 FPRINT("zd_ReceivePkt out of signal");
670 FPRINT_V("freeSignalCount", freeSignalCount);
671 goto rx_release;
674 pRxFdesc = allocFdesc();
675 if (!pRxFdesc){
676 FPRINT("zd_ReceivePkt out of description");
677 FPRINT_V("freeFdescCount", freeFdescCount);
678 freeSignal(pRxSignal);
679 goto rx_release;
681 else{
682 //pRxFdesc->bDataFrm = bDataFrm;
683 pRxFdesc->signalStrength = signalStrength;
684 pRxFdesc->signalQuality = signalQuality;
685 pRxFrame = pRxFdesc->mpdu;
686 pRxFrame->HdrLen = hdrLen;
687 pRxFrame->bodyLen = bodyLen;
688 memcpy(pRxFrame->header, pHdr, hdrLen);
689 pRxFrame->body = pBody;
690 pRxSignal->buf = buf;
691 pRxSignal->vapId = vapId;
692 pRxSignal->frmInfo.frmDesc = pRxFdesc;
693 if (!RxMgtMpdu(pRxSignal)){
694 freeSignal(pRxSignal);
695 freeFdesc(pRxFdesc);
696 pdot11Obj->ReleaseBuffer(buf);
698 return;
702 rx_release:
703 pdot11Obj->ReleaseBuffer(buf);
704 return;
706 void zd_InitWepData(void)
708 mWepIv[0] = 0;
709 mWepIv[1] = 0;
710 mWepIv[2] = 0;
711 mWepIv[3] = 0;
712 mBcIv[0] = 0;
713 mBcIv[1] = 0;
714 mBcIv[2] = 0;
715 mBcIv[3] = 0;
718 void zd_Release_80211_Buffer(void)
720 releaseSignalBuf();
721 releaseFdescBuf();
724 //Cmd Functions
725 BOOLEAN zd_Reset80211(zd_80211Obj_t * pObj)
728 pdot11Obj = pObj;
730 initSignalBuf();
731 initFdescBuf();
732 ResetPSMonitor();
733 ResetPMFilter();
734 zd_InitWepData();
735 mBssCnt=0;
736 return TRUE;
739 BOOLEAN zd_HandlePsPoll(U8 *pHdr)
741 Frame_t psPollFrame;
743 //PSDEBUG("zd_HandlePsPoll");
744 psPollFrame.HdrLen = 16;
745 psPollFrame.bodyLen = 0;
746 memcpy(&psPollFrame.header[0], pHdr, 16);
747 RxPsPoll(&psPollFrame);
748 return TRUE;
751 BOOLEAN zd_StartAP(void)
753 void *reg = pdot11Obj->reg;
755 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, mMacMode);
757 #if defined(AMAC)
758 pdot11Obj->SetReg(reg, ZD_BasicRateTbl, 0);
759 #endif
760 HW_SetSupportedRate(pdot11Obj, (U8 *)&mBrates);
762 #if defined(OFDM)
763 if(PURE_A_MODE != mMacMode)
764 HW_SetSupportedRate(pdot11Obj, (U8 *)&mExtRates);
766 #endif
768 /* Set CAM_MODE to AP Mode */
769 pdot11Obj->SetReg(reg, ZD_CAM_MODE, CAM_AP);
771 ConfigBcnFIFO();
772 HW_EnableBeacon(pdot11Obj, mBeaconPeriod, mDtimPeriod, AP_BSS);
773 HW_RadioOnOff(pdot11Obj, mRadioOn);
774 return TRUE;
777 BOOLEAN zd_ProbeReq(void)
779 Signal_t *signal;
780 //FPRINT("zd_ProbeReq");
782 if ((signal = allocSignal()) == NULL){
783 return FALSE;
785 signal->vapId=0;
786 signal->id = SIG_PROBE_REQ;
787 signal->block = BLOCK_SYNCH;
788 sigEnque(pMgtQ, (signal));
789 zd_SigProcess();
791 return TRUE;
793 BOOLEAN zd_ScanReq(void)
795 Signal_t *signal;
796 if ((signal = allocSignal()) == NULL){
797 return FALSE;
799 signal->vapId=0x12; //This member is not used in zd1211, we can use it to carry additional information, 0x1234 indicates we don't want to start a scantimer after sending a Probe Request frame.
801 signal->id = SIG_PROBE_REQ;
802 signal->block = BLOCK_SYNCH;
803 sigEnque(pMgtQ, (signal));
804 zd_SigProcess();
805 return TRUE;
807 #if 0
808 void zd_ScanEnd()
810 void *reg=pdot11Obj->reg;
811 if (mBssType == AP_BSS)
812 pdot11Obj->SetReg(reg, ZD_Rx_Filter, AP_RX_FILTER);
813 else
814 pdot11Obj->SetReg(reg, ZD_Rx_Filter, STA_RX_FILTER);
815 if (mAssoc) {
816 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
817 HW_SetRfChannel(pdot11Obj, mRfChannel, 1,mMacMode);
820 mBssCnt=mBssNum;
821 pdot11Obj->ConfigFlag &= ((~ACTIVE_CHANNEL_SCAN_SET) & (~JUST_CHANNEL_SCAN));
823 void zd_ScanBegin()
825 void *reg=pdot11Obj->reg;
826 mBssNum=0;
827 pdot11Obj->ConfigFlag |= (ACTIVE_CHANNEL_SCAN_SET | JUST_CHANNEL_SCAN);
828 pdot11Obj->SetReg(reg, ZD_Rx_Filter, (BIT_5|BIT_8));
830 void zd_CmdScanReq(u16 channel)
832 if(mMacMode != PURE_A_MODE) {
833 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
834 HW_SetRfChannel(pdot11Obj, channel, 1,mMacMode);
836 else {
837 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
838 HW_SetRfChannel(pdot11Obj,dot11A_Channel[channel-1],1 ,mMacMode);
842 zd_ScanReq();
843 return;
846 #endif
847 BOOLEAN zd_CmdProbeReq(U8 bWithSSID)
849 void *reg = pdot11Obj->reg;
850 U32 tempValue;
852 //FPRINT("zd_CmdProbeReq");
853 if (pdot11Obj->bChScanning){
854 FPRINT("Channel is under scanning....");
856 if (mRequestFlag & CHANNEL_SCAN_SET)
857 mRequestFlag &= ~CHANNEL_SCAN_SET;
858 return FALSE;
860 pdot11Obj->bChScanning=1;
861 if(pdot11Obj->bDeviceInSleep)
863 printk("In SLEEEEEEEEEEEEEEEEEEEEEP @ %s\n", __FUNCTION__);
864 return 0;
866 tempValue = pdot11Obj->GetReg(reg, ZD_BCNInterval);
867 tempValue &= ~BIT_25; // disable IBSS Beacon transmission temporarily.
868 pdot11Obj->SetReg(reg, ZD_BCNInterval, tempValue);
871 pdot11Obj->SetReg(reg, ZD_Rx_Filter, (BIT_5|BIT_8)); //only accept beacon and ProbeRsp frame
872 pdot11Obj->ConfigFlag |= ACTIVE_CHANNEL_SCAN_SET;
874 mBssNum = 0;
875 if(mMacMode != PURE_A_MODE) {
876 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
877 HW_SetRfChannel(pdot11Obj, CurrScanCH, 1,mMacMode);
879 else {
880 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
881 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH-1], 1,mMacMode);
884 zd_ProbeReq();
886 if (mRequestFlag & CHANNEL_SCAN_SET)
887 mRequestFlag &= ~CHANNEL_SCAN_SET;
889 //pdot11Obj->bChScanning = 1;
890 return TRUE;
893 BOOLEAN zd_StartSTA(BOOLEAN bEnable)
895 void *reg = pdot11Obj->reg;
896 //FPRINT("zd_StartSTA");
897 HW_SetSupportedRate(pdot11Obj, (U8 *)&mBrates);
898 HW_RadioOnOff(pdot11Obj, mRadioOn);
901 if (mBssType == INFRASTRUCTURE_BSS)
902 pdot11Obj->SetReg(reg, ZD_CAM_MODE, CAM_STA);
903 else
904 pdot11Obj->SetReg(reg, ZD_CAM_MODE, CAM_IBSS);
905 if (mBssType == PSEUDO_IBSS){
906 zd_PseudoIbssConnect();
908 else {
909 //if (!bEnable)
911 pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
912 mRequestFlag |= CHANNEL_SCAN_SET;
916 return TRUE;
919 BOOLEAN zd_CmdDisasoc(MacAddr_t *sta, U8 rCode)
921 Signal_t *signal;
922 //FPRINT("zd_CmdDisasoc");
924 //if (isGroup(sta))
925 // return FALSE;
927 if ((signal = allocSignal()) == NULL)
928 return FALSE;
930 signal->id = SIG_DIASSOC_REQ;
931 signal->block = BLOCK_ASOC;
932 if (mBssType == INFRASTRUCTURE_BSS){
933 memcpy(&signal->frmInfo.Sta, (U8 *)&mBssId, 6);
935 else {
936 memcpy(&signal->frmInfo.Sta, sta, 6);
938 signal->frmInfo.rCode = (ReasonCode)rCode;
939 sigEnque(pMgtQ, (signal));
941 return TRUE;
944 BOOLEAN zd_CmdDeauth(MacAddr_t *sta, U8 rCode)
946 Signal_t *signal;
948 if ((signal = allocSignal()) == NULL)
949 return FALSE;
951 signal->id = SIG_DEAUTH_REQ;
952 signal->block = BLOCK_AUTH_REQ;
953 memcpy(&signal->frmInfo.Sta, sta, 6);
954 signal->frmInfo.rCode = (ReasonCode)rCode;
955 sigEnque(pMgtQ, (signal));
957 return TRUE;
960 BOOLEAN zd_PassiveScan(void)
962 void *reg = pdot11Obj->reg;
964 //FPRINT("zd_PassiveScan");
966 if (pdot11Obj->ConfigFlag & PASSIVE_CHANNEL_SCAN_SET)
967 return FALSE;
969 pdot11Obj->ConfigFlag |= PASSIVE_CHANNEL_SCAN_SET;
970 pdot11Obj->SetReg(reg, ZD_Rx_Filter, 0x100); //only accept beacon frame
971 if(mMacMode != PURE_A_MODE) {
972 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
973 HW_SetRfChannel(pdot11Obj, CurrScanCH, 1,mMacMode);
975 else {
976 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
977 HW_SetRfChannel(pdot11Obj,dot11A_Channel[CurrScanCH-1],1 ,mMacMode);
980 pdot11Obj->StartTimer(SCAN_TIMEOUT, DO_SCAN);
982 return TRUE;
985 BOOLEAN zd_DisasocAll(U8 rCode)
987 int i;
988 MacAddr_t *sta;
989 if (mBssType == AP_BSS){
990 for (i=1; i<(MAX_AID+1); i++){
991 if (sstByAid[i]->asoc == STATION_STATE_ASOC){
992 sta = (MacAddr_t *)&sstByAid[i]->mac[0];
993 zd_CmdDisasoc(sta, rCode);
997 FlushQ(pTxQ);
999 else if (mBssType == INFRASTRUCTURE_BSS){
1000 if (mAssoc)
1001 zd_CmdDisasoc(&mBssId, rCode);
1003 return TRUE;
1007 BOOLEAN zd_ChooseAP(BOOLEAN bUseBssid)
1009 U8 i;
1010 U16 cap;
1011 U16 quality = 10000;
1012 BOOLEAN found = FALSE;
1014 mBssIndex = 0xff;
1015 for (i=0; i<mBssCnt; i++)
1017 if (bUseBssid)
1019 if (memcmp(&dot11DesiredBssid, &mBssInfo[i].bssid.mac[0], ETH_ALEN) == 0 && memcmp(&dot11DesiredBssid, zeroMacAddress, ETH_ALEN)!=0)
1021 //ZD1211DEBUG(0, "zd_ChooseAP: Bssid" MACSTR "matched to index:%d\n",MAC2STR(dot11DesiredBssid), i);
1022 mBssIndex = i;
1023 break;
1027 cap = mBssInfo[i].cap;
1028 if ((memcmp(&dot11DesiredSsid, &mBssInfo[i].ssid, dot11DesiredSsid.buf[1]+2) == 0)
1029 || (!mProbeWithSsid) ) {
1031 if(1)
1033 else if ((mMacMode == PURE_B_MODE) && (mBssInfo[i].apMode == PURE_G_AP))
1034 continue;
1035 else if ((mMacMode == PURE_B_MODE) && (mBssInfo[i].apMode == PURE_A_AP))
1036 continue;
1037 else if ((mMacMode == PURE_G_MODE) && (mBssInfo[i].apMode == PURE_B_AP))
1038 continue;
1039 else if ((mMacMode == PURE_G_MODE) && (mBssInfo[i].apMode == PURE_A_AP))
1040 continue;
1042 else if ((mMacMode == PURE_A_MODE) && (mBssInfo[i].apMode != PURE_A_AP))
1043 continue;
1045 else if ((mMacMode == MIXED_MODE) && (mBssInfo[i].apMode == PURE_A_AP))
1046 continue;
1050 //check capability ...
1051 if (cap & CAP_PRIVACY)
1053 if (!mPrivacyInvoked)
1054 continue;
1056 else
1058 if (mPrivacyInvoked)
1059 continue;
1064 if (!pdot11Obj->IsUSB2_0)
1065 { //host is usb 1.1
1066 if (mBssInfo[i].apMode == PURE_G_AP)
1067 continue;
1072 if (cap & CAP_ESS)
1074 if (mBssInfo[i].signalQuality < quality )
1076 quality = mBssInfo[i].signalQuality;
1077 mBssIndex = i;
1078 //FPRINT_V("cap", cap);
1084 //break;
1089 if (mBssIndex< mBssCnt){
1090 found = TRUE;
1091 //FPRINT_V("Desired AP Found, Bss Index", mBssIndex);
1092 if (pdot11Obj->ConfigFlag & SCAN_AND_CONNECT_SET){
1093 //printk("zd_ChooseAP: set mRequestFlag.BSS_CONNECT_SET\n");
1094 mRequestFlag |= BSS_CONNECT_SET;
1095 pdot11Obj->ConfigFlag &= ~SCAN_AND_CONNECT_SET;
1098 else{
1099 //printk(" \n");
1100 //printk(KERN_ERR "****** Can't find desiredSSID:");
1101 //for (i=0; i<dot11DesiredSsid.buf[1]; i++) {
1102 // printk("%c", dot11DesiredSsid.buf[2+i]);
1104 //printk(" \n");
1106 // int j;
1107 // if(0xff != mBssIndex) {
1108 // for(j=0;j<mBssInfo[mBssIndex].ssid.buf[1];j++)
1109 // printk("%c",mBssInfo[mBssIndex].ssid.buf[2+j]);
1110 // printk(" ChooseAP(Mac=%d,Ch:%d)\n",mBssInfo[mBssIndex].apMode,mBssInfo[mBssIndex].Phpm.buf[2]);
1111 // }
1114 return found;
1116 BOOLEAN zd_InfraConnect(U8 index)
1118 Signal_t *signal;
1119 struct zd1205_private *macp = (struct zd1205_private *)g_dev->priv;
1121 MacAddr_t *pBssid;
1122 Element *pSsid = NULL;
1123 U32 tmpvalue;
1124 BOOLEAN bChooseAPResult;
1125 void *reg = pdot11Obj->reg;
1126 //FPRINT("zd_InfraConnect");
1127 if (mBssNum == 0)
1128 return FALSE;
1130 if ((signal = allocSignal()) == NULL)
1131 return FALSE;
1132 if(mCounterMeasureState) {
1133 mRequestFlag &= ~BSS_CONNECT_SET;
1134 freeSignal(signal);
1135 return FALSE;
1137 // look up global scan result table according to desired ssid,
1138 // because mBssInfo order may be different from macp->BSSInfo[].
1139 /*if (mBssCnt)
1141 U8 ssidLength;
1142 for(i=0; i<mBssCnt; i++)
1144 ssidLength=dot11DesiredSsid.buf[1]+2;
1145 if (mBssInfo[i].cap & CAP_ESS)
1147 if (memcmp((U8*)&dot11DesiredSsid,(U8*)&mBssInfo[i].ssid,ssidLength)==0)
1149 break;
1153 } */
1154 // Use zd_ChooseAP instead of above code
1155 bChooseAPResult=zd_ChooseAP(0);
1156 if (!bChooseAPResult || 1)
1157 {// dot11DesiredSsid can't be found in table mBssInfo[]
1158 if ((index+1) <= mBssCnt)
1160 //printk(KERN_ERR "Desired SSID can't be found in current table\n");
1161 mBssIndex=index; // Can't found in the latest scan result table, use the old index.
1163 else
1165 freeSignal(signal);
1166 return FALSE; // The index exceed mBssInfo[].
1169 else
1171 //printk(KERN_ERR "Desired SSID found in location %d\n",mBssIndex);
1175 //Disable IBSS mode
1176 if(pdot11Obj->bDeviceInSleep)
1178 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
1179 return FALSE;
1183 tmpvalue = pdot11Obj->GetReg(reg, ZD_BCNInterval);
1184 tmpvalue &= ~BIT_25;
1185 pdot11Obj->SetReg(reg, ZD_BCNInterval, tmpvalue);
1186 mCap |= BIT_0;
1187 mCap &= ~BIT_1;
1191 // For IBSS Connect
1192 if (mBssInfo[index].cap & CAP_IBSS)
1196 //mBssIndex = index;
1197 //update beacon interval
1198 HW_UpdateBcnInterval(pdot11Obj, mBssInfo[mBssIndex].bcnInterval);
1200 pSsid = &mBssInfo[mBssIndex].ssid;
1201 memcpy((U8 *)&mSsid, (U8 *)pSsid, pSsid->buf[1]+2);
1202 pBssid = &mBssInfo[mBssIndex].bssid;
1203 memcpy((U8 *)&mBssId, (U8 *)pBssid, 6);
1205 //update Bssid
1206 pdot11Obj->SetReg(reg, ZD_BSSID_P1, zd_cpu_to_le32(*(U32 *)&mBssId.mac[0]));
1207 pdot11Obj->SetReg(reg, ZD_BSSID_P2, zd_cpu_to_le32(*(U32 *)&mBssId.mac[4]));
1208 // Update channel number contained in the DS Parameter Set element of the received probe response or beacon frame.
1209 mRfChannel = mBssInfo[mBssIndex].Phpm.buf[2];
1213 if(PURE_A_AP == mBssInfo[mBssIndex].apMode) {
1214 ChangeMacMode(PURE_A_MODE,mRfChannel);
1215 zd_UpdateCardSetting(&(macp->cardSetting));
1216 pdot11Obj->DelayUs(1000);
1217 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, PURE_A_MODE);
1220 else {
1221 if(PURE_A_MODE == mMacMode)
1222 mMacMode = MIXED_MODE;
1224 ChangeMacMode(mMacMode,mRfChannel);
1225 zd_UpdateCardSetting(&(macp->cardSetting));
1226 pdot11Obj->DelayUs(1000);
1227 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, MIXED_MODE);
1232 signal->id = SIG_AUTH_REQ;
1233 signal->block = BLOCK_AUTH_REQ;
1234 memcpy(&signal->frmInfo.Sta, (U8 *)&mBssId, 6);
1235 sigEnque(pMgtQ, (signal));
1237 if (mRequestFlag & CONNECT_TOUT_SET)
1238 mRequestFlag &= ~CONNECT_TOUT_SET;
1239 if (mRequestFlag & BSS_CONNECT_SET)
1240 mRequestFlag &= ~BSS_CONNECT_SET;
1242 return TRUE;
1245 BOOLEAN zd_IbssConnect(void)
1247 struct zd1205_private *macp=g_dev->priv;
1248 int i,j;
1249 U8 Length;
1250 BOOLEAN bBSSFound = FALSE;
1251 MacAddr_t *pBssid;
1252 BssInfo_t *pBssInfo;
1253 void *reg = pdot11Obj->reg;
1254 U32 tmpvalue;
1255 U32 seed ;
1256 //FPRINT("zd_IbssConnect");
1257 #if defined(OFDM)
1258 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_NORMAL_SLOT);
1259 // not to use short slot time
1260 mCap &= ~BIT_10;
1261 pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
1263 if (mMacMode == PURE_G_MODE){
1264 // not use protection mechanism
1265 pdot11Obj->ConfigFlag &= ~ENABLE_PROTECTION_SET;
1267 else if(mMacMode != PURE_A_MODE) {
1268 // force use protection mechanism
1269 pdot11Obj->ConfigFlag |= ENABLE_PROTECTION_SET;
1272 #endif
1275 // Recover the EIFS to 0x200.
1276 // We need not use SleepResetDevice. In IBSS mode, we can easily
1277 // get others traffic. (not less of Rx-Frame)
1278 pdot11Obj->SetReg(reg, ZD_IFS_Value, 0x5200032);
1279 if (mATIMWindow != 0){
1280 // Do not set macp->PwrState = PSM, otherwise
1281 // throughput with Cirrus card (in PS mode) will down.
1282 //macp->PwrState = PSM;
1283 // PwrMgt = 1
1284 if(pdot11Obj->bDeviceInSleep)
1286 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
1287 return FALSE;
1290 tmpvalue = pdot11Obj->GetReg(reg, ZD_BCNInterval);
1291 tmpvalue |= BIT_26;
1292 pdot11Obj->SetReg(reg, ZD_BCNInterval, tmpvalue);
1294 else{
1295 //macp->PwrState = CAM;
1296 // PwrMgt = 0;
1297 if(pdot11Obj->bDeviceInSleep)
1299 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
1300 return FALSE;
1303 tmpvalue = pdot11Obj->GetReg(reg, ZD_BCNInterval);
1304 tmpvalue &= ~BIT_26;
1305 pdot11Obj->SetReg(reg, ZD_BCNInterval, tmpvalue);
1309 mCap &= ~BIT_0;
1310 mCap |= BIT_1;
1312 mTimeBeforeAdhocRoaming = (jiffies + dot11MacAddress.mac[0] + 3) & 0x1F;
1313 if (mBssCnt ){ // IBSS found
1314 for (i=0; i<mBssCnt; i++){
1315 Length = dot11DesiredSsid.buf[1]+2;
1316 if (mBssInfo[i].cap & CAP_IBSS){
1317 if (memcmp((U8 *)&dot11DesiredSsid, (U8 *)&mBssInfo[i].ssid, Length) == 0){
1318 break;
1322 if (i < mBssCnt){
1323 bBSSFound = TRUE;
1324 mBssIndex = i;
1326 pBssInfo = &mBssInfo[mBssIndex];
1327 mBssId.mac[0] = pBssInfo->bssid.mac[0];
1328 mBssId.mac[1] = pBssInfo->bssid.mac[1];
1329 mBssId.mac[2] = pBssInfo->bssid.mac[2];
1330 mBssId.mac[3] = pBssInfo->bssid.mac[3];
1331 mBssId.mac[4] = pBssInfo->bssid.mac[4];
1332 mBssId.mac[5] = pBssInfo->bssid.mac[5];
1333 //zd1205_dump_data("mBssId = ", (U8 *)&mBssId, 6);
1334 //update Bssid
1335 pdot11Obj->SetReg(reg, ZD_BSSID_P1, zd_cpu_to_le32(*(U32 *)&mBssId.mac[0]));
1336 pdot11Obj->SetReg(reg, ZD_BSSID_P2, zd_cpu_to_le32(*(U32 *)&mBssId.mac[4]));
1338 if(pBssInfo->apMode == PURE_A_AP)
1340 ChangeMacMode(PURE_A_MODE, pBssInfo->Phpm.buf[2]);
1342 else
1344 /*===prince delete
1345 ChangeMacMode(MIXED_MODE, pBssInfo->Phpm.buf[2]);
1346 ====*/
1347 //prince add begin
1348 ChangeMacMode(macp->cardSetting.MacMode, pBssInfo->Phpm.buf[2]);
1349 //prince add end
1352 zd1205_SetRatesInfo(macp);
1353 mMacMode = macp->cardSetting.MacMode;
1354 mRfChannel = macp->cardSetting.Channel;
1355 mPhpm.buf[0] = EID_DSPARMS;
1356 mPhpm.buf[1] = 1;
1357 mPhpm.buf[2] = mRfChannel;
1358 /*==prince dlete
1359 // printk("Ibss Join, MAC_MODE:%d, CHANNEL:%d\n", mMacMode,mRfChannel);
1360 ============*/
1361 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, mMacMode);
1362 //FPRINT_V("mRfChannel", mRfChannel);
1364 //update beacon interval
1365 /*===prince delete
1366 mBeaconPeriod = pBssInfo->bcnInterval; //MZCai
1367 =======*/
1368 //prince add begin
1369 if ( mMacMode == PURE_A_MODE )
1371 U32 curr_tsf=pdot11Obj->GetReg(reg, 0x514);
1372 printk(KERN_DEBUG "IBSS Join, MAC_MODE:%d, CHANNEL:%d, OrgBcnIntval:%d\n", mMacMode, mRfChannel, pBssInfo->bcnInterval);
1373 mBeaconPeriod = pBssInfo->bcnInterval+1+(curr_tsf&0x1f); //MZCai
1374 HW_UpdateBcnInterval(pdot11Obj, mBeaconPeriod);
1375 //FPRINT_V("mBeaconPeriod", mBeaconPeriod);
1377 else
1379 printk("Ibss Join, MAC_MODE:%d, CHANNEL:%d\n", mMacMode,mRfChannel);
1380 mBeaconPeriod = pBssInfo->bcnInterval; //MZCai
1381 HW_UpdateBcnInterval(pdot11Obj, mBeaconPeriod);
1386 //prince add end
1389 //update supported rated
1390 memcpy((U8 *)&mBrates, (U8 *)&pBssInfo->supRates, pBssInfo->supRates.buf[1]+2); //MZCAI
1391 HW_SetSupportedRate(pdot11Obj, (U8 *)&mBrates);
1392 //zd1205_dump_data("mBrates = ", (U8 *)&mBrates, mBrates.buf[1]+2);
1393 #if defined(OFDM)
1394 if(mMacMode != PURE_A_MODE && mMacMode != PURE_B_MODE) //MZCai
1396 if(pBssInfo->extRates.buf[0] == EID_EXT_RATES)
1398 //if(pdot11Obj->IsUSB2_0) //MZCAI
1399 memcpy((U8 *)&mExtRates, (U8 *)&pBssInfo->extRates, pBssInfo->extRates.buf[1]+2); //MZCai
1400 HW_SetSupportedRate(pdot11Obj, (U8 *)&mExtRates);
1404 //zd1205_dump_data("mExtRates = ", (U8 *)&mExtRates, mExtRates.buf[1]+2);
1405 #endif
1406 //update ATIM Window
1407 mATIMWindow = pBssInfo->IbssParms.buf[2]+(((U16)pBssInfo->IbssParms.buf[3]) << 8); //MZCai
1408 memcpy((U8 *)&mIbssParms, (U8 *)&pBssInfo->IbssParms, pBssInfo->IbssParms.buf[1]+2); //MZCai
1409 HW_UpdateATIMWindow(pdot11Obj, mATIMWindow);
1410 //FPRINT_V("mATIMWindow", mATIMWindow);
1412 ConfigBcnFIFO();
1413 HW_EnableBeacon(pdot11Obj, mBeaconPeriod, 0, INDEPENDENT_BSS);
1414 HW_RadioOnOff(pdot11Obj, mRadioOn);
1415 mRequestFlag &= ~IBSS_CONNECT_SET;
1416 mAssoc = TRUE;
1417 memcpy(&pdot11Obj->CurrSsid[0], (U8 *)&mSsid, mSsid.buf[1]+2);
1418 pdot11Obj->StatusNotify(STA_ASSOCIATED, (U8 *)&mBssId);
1419 return TRUE;
1422 else {
1423 if (!(pdot11Obj->ConfigFlag & IBSS_CHANNEL_SCAN_SET)){
1424 pdot11Obj->ConfigFlag |= IBSS_CHANNEL_SCAN_SET;
1425 zd_CmdProbeReq(1);
1427 /*=====prince delete
1428 return FALSE;
1429 =================*/
1432 if (!bBSSFound){
1434 if(pdot11Obj->bDeviceInSleep)
1436 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
1437 return FALSE;
1440 //FPRINT("IBSS not found, create it !!!");
1441 /****************************************************/
1442 /* We generate an IBSS */
1443 /****************************************************/
1444 seed = pdot11Obj->GetReg(reg, ZD_TSF_LowPart);
1445 mBssIndex = 0xff;
1446 //generate random BSSID
1447 mBssId.mac[0] = (U8)((pdot11Obj->Rand(seed) & ~0x3) | 0x2); // I/G = 0, U/L = 1
1448 mBssId.mac[1] = (U8)pdot11Obj->Rand(seed);
1449 mBssId.mac[2] = (U8)pdot11Obj->Rand(seed);
1450 mBssId.mac[3] = (U8)pdot11Obj->Rand(seed);
1451 mBssId.mac[4] = (U8)pdot11Obj->Rand(seed);
1452 mBssId.mac[5] = (U8)pdot11Obj->Rand(seed);
1453 //zd1205_dump_data("mBssId = ", (U8 *)&mBssId, 6);
1454 //update Bssid
1455 pdot11Obj->SetReg(reg, ZD_BSSID_P1, zd_cpu_to_le32(*(U32 *)&mBssId.mac[0]));
1456 pdot11Obj->SetReg(reg, ZD_BSSID_P2, zd_cpu_to_le32(*(U32 *)&mBssId.mac[4]));
1458 ChangeMacMode(macp->IBSS_DesiredMacMode, macp->IBSS_DesiredChannel);
1461 mMacMode = macp->cardSetting.MacMode;
1462 mRfChannel = macp->cardSetting.Channel;
1463 mPhpm.buf[0] = EID_DSPARMS;
1464 mPhpm.buf[1] = 1;
1465 mPhpm.buf[2] = mRfChannel;
1467 printk("Ibss Create, MAC_MODE:%d, CHANNEL:%d\n", mMacMode,mRfChannel);
1469 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, mMacMode);
1470 //FPRINT_V("mRfChannel", mRfChannel);
1472 //update beacon interval
1473 HW_UpdateBcnInterval(pdot11Obj, mBeaconPeriod);
1474 //FPRINT_V("mBeaconPeriod", mBeaconPeriod);
1476 //update supported rated
1477 HW_SetSupportedRate(pdot11Obj, (U8 *)&mBrates);
1478 //zd1205_dump_data("mBrates = ", (U8 *)&mBrates, mBrates.buf[1]+2);
1479 #if defined(OFDM)
1480 if(mMacMode != PURE_A_MODE && mMacMode != PURE_B_MODE)
1481 if (pdot11Obj->IsUSB2_0)
1482 HW_SetSupportedRate(pdot11Obj, (U8 *)&mExtRates);
1484 //zd1205_dump_data("mExtRates = ", (U8 *)&mExtRates, mExtRates.buf[1]+2);
1485 #endif
1486 //update ATIM Window
1487 HW_UpdateATIMWindow(pdot11Obj, mATIMWindow);
1488 //FPRINT_V("mATIMWindow", mATIMWindow);
1490 ConfigBcnFIFO();
1491 HW_EnableBeacon(pdot11Obj, mBeaconPeriod, 0, INDEPENDENT_BSS);
1492 HW_RadioOnOff(pdot11Obj, mRadioOn);
1493 mRequestFlag &= ~IBSS_CONNECT_SET;
1494 mAssoc = TRUE;
1495 memcpy(&pdot11Obj->CurrSsid[0], (U8 *)&mSsid, mSsid.buf[1]+2);
1496 pdot11Obj->StatusNotify(STA_ASSOCIATED, (U8 *)&mBssId);
1497 return TRUE;
1499 return FALSE;
1502 void zd_ResetDevice(void)
1504 U16 BeaconInterval = 0x2;
1505 U32 tmpvalue;
1506 void *reg = pdot11Obj->reg;
1507 // Device will reset after 1ms
1508 HW_UpdateBcnInterval(pdot11Obj, BeaconInterval);
1509 pdot11Obj->SetReg(reg, ZD_Pre_TBTT, 0x1);
1510 //++ Ensure the following is an atomic operation.
1511 #ifndef HOST_IF_USB
1512 i_state = pdot11Obj->EnterCS();
1513 #endif
1515 if(pdot11Obj->bDeviceInSleep)
1517 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
1518 return;
1521 tmpvalue = pdot11Obj->GetReg(reg, ZD_PS_Ctrl);
1522 pdot11Obj->SetReg(reg, ZD_PS_Ctrl, (tmpvalue | BIT_0));
1523 pdot11Obj->bDeviceInSleep = 1;
1525 #ifndef HOST_IF_USB
1526 pdot11Obj->ExitCS(i_state);
1527 // Delay 1ms to ensure device had been reset
1528 pdot11Obj->DelayUs(1000);
1529 #endif
1533 BOOLEAN zd_PseudoIbssConnect(void)
1535 void *reg = pdot11Obj->reg;
1536 U8 IBSS_BSSID[6];
1537 memset(IBSS_BSSID, 0, 6);
1538 //++
1539 // Set EIFS=0x32 to prevent chamber low Tx-throughput (sometimes)
1540 // problem. In chamber environment, almost no Rx-frame, once
1541 // we detect a CRC16/CRC32 error frame, we adopt EIFS, because of
1542 // less of RX-frame, it's less posibility to change EIFS to DIFS
1543 // by FA (Frame Analyzer), and therefore damage the Tx-Throughput.
1544 // We must use SleepResetDevice to trigger FA to adpot 0x32.
1545 pdot11Obj->SetReg(reg, ZD_IFS_Value, 0x5032032);
1546 zd_ResetDevice();
1548 //update Bssid
1549 pdot11Obj->SetReg(reg, ZD_BSSID_P1, zd_cpu_to_le32(*(U32 *)&IBSS_BSSID[0]));
1550 pdot11Obj->SetReg(reg, ZD_BSSID_P2, zd_cpu_to_le32(*(U32 *)&IBSS_BSSID[4]));
1551 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, mMacMode);
1552 mAssoc = TRUE;
1553 pdot11Obj->StatusNotify(STA_ASSOCIATED, (U8 *)IBSS_BSSID);
1555 return TRUE;
1560 BOOLEAN zd_CmdConnect(U8 index, U8 bssType)
1562 if (bssType == INFRASTRUCTURE_BSS)
1564 //printk(KERN_ERR "Build Infra-Type BSS\n");
1565 return zd_InfraConnect(index-1);
1567 else if (bssType==INDEPENDENT_BSS)
1569 //printk(KERN_ERR "Build IBSS\n");
1570 return zd_IbssConnect();
1572 else if (bssType == PSEUDO_IBSS)
1573 return zd_PseudoIbssConnect();
1576 return TRUE;
1579 BOOLEAN zd_CmdDisConnect(void)
1581 mAssoc = FALSE;
1582 mRequestFlag |= DIS_CONNECT_SET;
1584 return TRUE;
1588 BOOLEAN zd_CmdRoaming(void)
1590 if ((mRequestFlag & (ROAMING_SET | CHANNEL_SCAN_SET)) || pdot11Obj->bChScanning || (pdot11Obj->ConfigFlag & SCAN_AND_CONNECT_SET))
1591 return FALSE;
1594 mAssoc = FALSE;
1596 if (mBssType == INDEPENDENT_BSS)
1597 mRequestFlag |= CHANNEL_SCAN_SET;
1598 else
1599 mRequestFlag |= ROAMING_SET;
1601 return TRUE;
1606 BOOLEAN zd_CmdFlushQ(void)
1608 if (pdot11Obj->QueueFlag & TX_QUEUE_SET){
1609 FlushQ(pTxQ);
1611 else if (pdot11Obj->QueueFlag & MGT_QUEUE_SET){
1612 FlushQ(pMgtQ);
1614 else if (pdot11Obj->QueueFlag & AWAKE_QUEUE_SET){
1615 FlushQ(pAwakeQ);
1618 return TRUE;
1621 BOOLEAN zd_CmdProcess(U16 CmdId, void *parm1, U32 parm2)
1623 BOOLEAN status = TRUE;
1625 switch(CmdId){
1626 case CMD_RESET_80211:
1627 status = zd_Reset80211((zd_80211Obj_t *)parm1);
1628 break;
1630 case CMD_ENABLE:
1631 if (mBssType == AP_BSS)
1632 status = zd_StartAP();
1633 else
1635 if ((pdot11Obj->ConfigFlag & SCAN_AND_CONNECT_SET)||(mRequestFlag & CHANNEL_SCAN_SET))
1637 // printk("Scan and connect is underGoing\n");
1638 break;
1640 else if (!mIfaceOpened)
1642 status = zd_StartSTA(1);
1643 mIfaceOpened = TRUE;
1645 else
1647 pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
1648 zd_ChooseAP(0);
1652 break;
1654 case CMD_DISASOC: //IAPP cth
1655 status = zd_CmdDisasoc((MacAddr_t*)parm1, (U8)parm2);
1656 break;
1658 case CMD_DEAUTH://MAC filter cth
1659 status = zd_CmdDeauth((MacAddr_t*)parm1, (U8)parm2);
1660 break;
1662 case CMD_PS_POLL:
1663 //PSDEBUG("CMD_PS_POLL");
1664 status = zd_HandlePsPoll((U8 *)parm1);
1665 break;
1667 case CMD_PASSIVE_SCAN:
1668 status = zd_PassiveScan();
1669 break;
1671 case CMD_DISASOC_ALL:
1672 status = zd_DisasocAll((U8)parm2);
1673 break;
1675 case CMD_CONNECT:
1677 U8 *pBsstype=(U8*)parm1;
1678 status = zd_CmdConnect((U8)parm2,*pBsstype);
1680 break;
1682 case CMD_PROBE_REQ:
1683 //FPRINT("CMD_PROBE_REQ");
1684 status = zd_CmdProbeReq((U8)parm2);
1685 pdot11Obj->ConfigFlag |= JUST_CHANNEL_SCAN;
1686 break;
1688 case CMD_DIS_CONNECT:
1689 status = zd_CmdDisConnect();
1690 break;
1692 case CMD_FLUSH_QUEUE:
1693 status = zd_CmdFlushQ();
1694 break;
1696 case CMD_ROAMING:
1697 status = zd_CmdRoaming();
1698 break;
1700 default:
1701 status = FALSE;
1702 break;
1705 return status;
1708 //Event Nofify Functions
1709 void zd_NextBcn(void)
1711 //prince add begin
1712 struct zd1205_private *macp = g_dev->priv;
1713 card_Setting_t *pSetting = &macp->cardSetting;
1714 //prince add end
1716 if (mBssType == AP_BSS){
1717 if (mDtimCount == 0)
1718 mDtimCount = mDtimPeriod;
1719 mDtimCount--;
1722 ConfigBcnFIFO();
1724 if (pTxQ->cnt)
1725 pdot11Obj->QueueFlag |= TX_QUEUE_SET;
1727 /*==prince add begin
1728 if( mBssType == INDEPENDENT_BSS )
1730 if ( mMacMode == PURE_A_MODE )
1732 U32 myrand ;
1733 //update beacon interval
1734 get_random_bytes(&myrand,sizeof(U32)) ;
1735 //pSetting->bcnInterval = jiffies % 21 + 90;
1736 pSetting->BeaconInterval = myrand % 21 + 90;
1737 mBeaconPeriod = pSetting->BeaconInterval; //MZCai
1738 HW_EnableBeacon( pdot11Obj, pSetting->BeaconInterval, 0 ,INDEPENDENT_BSS );
1743 prince add end====*/
1746 return;
1749 void zd_DtimNotify(void)
1751 SendMcPkt();
1752 return;
1755 extern BOOLEAN Tchal_WaitChalRsp(Signal_t *signal);
1756 void zd_SendTChalMsg(void)
1758 Tchal_WaitChalRsp(NULL);
1759 return;
1762 extern BOOLEAN AuthTimeOut(Signal_t *signal);
1763 void zd_SendTAuthMsg(void)
1765 AuthTimeOut(NULL);
1766 return;
1769 extern BOOLEAN AsocTimeOut(Signal_t *signal);
1770 void zd_SendTAsocMsg(void)
1772 AsocTimeOut(NULL);
1773 return;
1777 void zd_SwitchNextCH(void)
1779 void *reg = pdot11Obj->reg;
1780 //prince add begin
1781 struct zd1205_private *macp = g_dev->priv;
1782 //prince add end
1783 static u8 LastScanMacMode;
1784 static u8 ScanAround = 0;
1785 //static u8 ScanWait = 0;
1786 static u8 initMAC_Mode = 0xff;
1788 if(initMAC_Mode == 0xff)
1789 initMAC_Mode = mMacMode;
1790 //FPRINT("zd_SwitchNextCH");
1792 if ((PURE_A_MODE != mMacMode && CurrScanCH > MAX_CHANNEL_ALLOW) ||
1793 (PURE_A_MODE == mMacMode && CurrScanCH > dot11A_Channel_Amount - 1)
1794 //In 11a, channel array index 0 is also meaningful.
1795 ){ //Scan Finish...
1797 #ifdef HMAC_DEBUG
1798 U8 i, j;
1799 U16 cap;
1800 #endif
1801 if (mBssType == AP_BSS)
1802 pdot11Obj->SetReg(reg, ZD_Rx_Filter, AP_RX_FILTER);
1803 else
1804 pdot11Obj->SetReg(reg, ZD_Rx_Filter, STA_RX_FILTER);
1806 if (pdot11Obj->ConfigFlag & PASSIVE_CHANNEL_SCAN_SET)
1807 pdot11Obj->ConfigFlag &= ~PASSIVE_CHANNEL_SCAN_SET;
1809 if (pdot11Obj->ConfigFlag & IBSS_CHANNEL_SCAN_SET)
1811 pdot11Obj->ConfigFlag &= ~IBSS_CHANNEL_SCAN_SET;
1812 //mRequestFlag |= IBSS_CONNECT_SET;
1815 //prince delete
1816 CurrScanCH = 1;
1819 pdot11Obj->bChScanning = 0;
1820 ScanAround=0;
1822 if (pdot11Obj->ConfigFlag & ACTIVE_CHANNEL_SCAN_SET)
1824 #ifdef HMAC_DEBUG
1825 printk("\nSSID BSSID CH Signal Mode Basic-Rates Ext-Rates b/g AP");
1826 printk("\n------------------------------------------------------------------------------------");
1827 for (i=0; i<mBssNum; i++)
1829 printk("\n");
1830 for (j=0; j<mBssInfo[i].ssid.buf[1]; j++) {
1831 printk("%c", mBssInfo[i].ssid.buf[2+j]);
1834 for (j=mBssInfo[i].ssid.buf[1]; j<12; j++) {
1835 printk(" ");
1838 printk("%02x:%02x:%02x:%02x:%02x:%02x",
1839 mBssInfo[i].bssid.mac[0], mBssInfo[i].bssid.mac[1], mBssInfo[i].bssid.mac[2],
1840 mBssInfo[i].bssid.mac[3], mBssInfo[i].bssid.mac[4], mBssInfo[i].bssid.mac[5]);
1842 printk(" %2d", mBssInfo[i].Phpm.buf[2]);
1843 printk(" %2d", mBssInfo[i].signalStrength);
1845 cap = mBssInfo[i].cap;
1846 cap &= (CAP_PRIVACY | CAP_IBSS | CAP_ESS);
1848 switch(cap) {
1849 case 0x01:
1850 printk(" Infra ");
1851 break;
1852 case 0x02:
1853 printk(" Ad_Hoc ");
1854 break;
1855 case 0x11:
1856 printk(" Infra, W");
1857 break;
1858 case 0x12:
1859 printk(" Ad_Hoc,W");
1860 break;
1861 default :
1862 break;
1865 printk(" ");
1867 for (j=0; j<mBssInfo[i].supRates.buf[1]; j++) {
1868 printk(" %x", mBssInfo[i].supRates.buf[2+j]);
1871 printk(" ");
1872 for (j=0; j<mBssInfo[i].extRates.buf[1]; j++) {
1873 printk(" %x", mBssInfo[i].extRates.buf[2+j]);
1876 if (mBssInfo[i].apMode == PURE_B_AP)
1877 printk(" B-AP");
1878 else if (mBssInfo[i].apMode == PURE_G_AP)
1879 printk(" G-AP");
1880 else if (mBssInfo[i].apMode == MIXED_AP)
1881 printk(" M-AP");
1883 else if (mBssInfo[i].apMode == PURE_A_AP)
1884 printk(" A_AP");
1885 else
1886 VerAssert();
1889 printk("\n");
1891 FPRINT("****** Scan Finished ******");
1892 #endif
1893 pdot11Obj->ConfigFlag &= ~ACTIVE_CHANNEL_SCAN_SET;
1894 mBssCnt = mBssNum;
1895 }//End of ACTIVE_CHANNEL_SCAN_SET
1897 if (pdot11Obj->ConfigFlag & JUST_CHANNEL_SCAN){
1898 pdot11Obj->ConfigFlag &= ~JUST_CHANNEL_SCAN;
1900 if (mAssoc)
1902 mMacMode = initMAC_Mode;
1903 HW_SetRfChannel(pdot11Obj, mRfChannel, 1, initMAC_Mode);
1906 else
1908 if (mBssType == INFRASTRUCTURE_BSS)
1909 //prince add begin
1910 zd_InfraConnect(mBssNum);
1911 //prince add end
1912 /*==prince delete
1913 zd_ChooseAP(0);
1914 ===============*/
1915 else if (mBssType == INDEPENDENT_BSS)
1916 zd_IbssConnect();
1919 if (pdot11Obj->ConfigFlag & SCAN_AND_CONNECT_SET)
1921 pdot11Obj->ConfigFlag &= ~SCAN_AND_CONNECT_SET;
1924 initMAC_Mode = 0xff;
1926 //prince add begin
1927 macp->CurrScanCH = CurrScanCH;
1928 //prince add end
1930 return;
1931 }//End of (CurrentScannedChannel > MAX_CHANNEL_ALLOW)
1933 CurrScanCH++;
1935 //prince add begin
1936 macp->CurrScanCH = CurrScanCH;
1937 //prince add end
1939 if(mMacMode != PURE_A_MODE && CurrScanCH <= MAX_CHANNEL_ALLOW + 1) {
1940 //printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
1941 HW_SetRfChannel(pdot11Obj, CurrScanCH, 1,mMacMode);
1942 LastScanMacMode = mMacMode;
1945 else if(mMacMode == PURE_A_MODE && CurrScanCH<=dot11A_Channel_Amount){
1946 //printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
1947 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH-1],1, mMacMode);
1948 LastScanMacMode = mMacMode;
1950 if(PURE_A_MODE != LastScanMacMode && CurrScanCH > MAX_CHANNEL_ALLOW && ScanAround <1) {
1951 if(pdot11Obj->rfMode == AL7230B_RF) {
1952 /*==prince delete
1953 mMacMode = PURE_A_MODE;
1954 CurrScanCH = 1;
1955 ChangeMacMode(PURE_A_MODE,dot11A_Channel[CurrScanCH-1]);
1956 pdot11Obj->DelayUs(1000);
1957 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH-1],0,mMacMode);
1958 ===========*/
1960 //===prince add begin
1961 CurrScanCH = 1;
1962 if ( macp->cardSetting.BssType == INFRASTRUCTURE_BSS )
1964 mMacMode = PURE_A_MODE;
1965 ChangeMacMode(PURE_A_MODE,dot11A_Channel[CurrScanCH-1]);
1966 pdot11Obj->DelayUs(1000);
1967 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH-1],0,mMacMode);
1969 else if ( macp->cardSetting.BssType == INDEPENDENT_BSS )
1972 mMacMode = macp->cardSetting.MacMode;
1973 ChangeMacMode(mMacMode,CurrScanCH);
1974 pdot11Obj->DelayUs(1000);
1975 HW_SetRfChannel(pdot11Obj, CurrScanCH ,0,mMacMode);
1978 //====
1979 ScanAround ++;
1985 else if(ScanAround < 1 &&PURE_A_MODE == LastScanMacMode && CurrScanCH > dot11A_Channel_Amount - 1){
1986 /*==prince delete
1987 ScanAround ++;
1988 CurrScanCH = 1;
1989 mMacMode = MIXED_MODE;
1990 ChangeMacMode(MIXED_MODE, CurrScanCH);
1991 pdot11Obj->DelayUs(1000);
1992 HW_SetRfChannel(pdot11Obj, CurrScanCH, 0,mMacMode);
1993 ===============*/
1994 //===prince add begin
1995 CurrScanCH = 1;
1996 if ( macp->cardSetting.BssType == INFRASTRUCTURE_BSS )
1998 ScanAround ++;
1999 mMacMode = MIXED_MODE;
2000 ChangeMacMode(MIXED_MODE,CurrScanCH);
2001 pdot11Obj->DelayUs(1000);
2002 HW_SetRfChannel(pdot11Obj, CurrScanCH, 0,mMacMode);
2004 else if ( macp->cardSetting.BssType == INDEPENDENT_BSS )
2006 ScanAround ++;
2007 mMacMode = macp->cardSetting.MacMode;
2008 ChangeMacMode(mMacMode, dot11A_Channel[CurrScanCH - 1]);
2009 pdot11Obj->DelayUs(1000);
2010 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH -1] , 0,mMacMode);
2013 //======
2019 //for debug
2020 //pdot11Obj->SetReg(reg, ZD_USB_DEBUG_PORT, 0x22222222);
2022 if (pdot11Obj->ConfigFlag & PASSIVE_CHANNEL_SCAN_SET)
2023 pdot11Obj->StartTimer(SCAN_TIMEOUT, DO_SCAN);
2025 if (pdot11Obj->ConfigFlag & ACTIVE_CHANNEL_SCAN_SET)
2026 zd_ProbeReq();
2028 return;
2031 void zd_UpdateCurrTxRate(U8 rate, U16 aid)
2033 Hash_t *pHash;
2034 if (mBssType == INFRASTRUCTURE_BSS){
2035 pHash = sstByAid[0];
2036 pHash->CurrTxRate = rate;
2038 else {
2039 if (aid){
2040 pHash = sstByAid[aid];
2041 #if !defined(OFDM)
2042 pHash->CurrTxRate = rate;
2043 #else
2044 if (rate < pHash->CurrTxRate){ //Retry Failed happened
2045 pHash->FailedFrames++;
2046 //FPRINT_V("FailedFrames", pHash->FailedFrames);
2048 #endif
2053 void zd_EnableProtection(U8 protect)
2055 U32 tmpValue;
2056 void *reg = pdot11Obj->reg;
2058 if (protect){
2059 //FPRINT("zd_EnableProtection");
2060 pdot11Obj->ConfigFlag |= ENABLE_PROTECTION_SET;
2061 mErp.buf[2] |= USE_PROTECTION;
2062 if(pdot11Obj->bDeviceInSleep)
2064 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
2065 return ;
2068 tmpValue = pdot11Obj->GetReg(reg, ZD_RTS_CTS_Rate);
2069 tmpValue &= ~CTS_MOD_TYPE_OFDM;
2070 tmpValue |= CTS_RATE_11M;
2071 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, tmpValue);
2073 else {
2074 //FPRINT("zd_DisableProtection");
2075 pdot11Obj->ConfigFlag &= ~ENABLE_PROTECTION_SET;
2076 mErp.buf[2] &= ~USE_PROTECTION;
2078 //pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
2079 mCap |= CAP_SHORT_SLOT_TIME;
2080 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_SHORT_SLOT);
2084 void zd_EnableBarker(U8 barker)
2086 void *reg = pdot11Obj->reg;
2087 if (barker){
2088 //FPRINT("zd_EnableBarker");
2089 pdot11Obj->ConfigFlag |= BARKER_PREAMBLE_SET;
2090 mErp.buf[2] |= BARKER_PREAMBLE;
2091 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, 0x30000);
2093 else {
2094 //FPRINT("zd_DisableBarker");
2095 pdot11Obj->ConfigFlag &= ~BARKER_PREAMBLE_SET;
2096 mErp.buf[2] &= ~BARKER_PREAMBLE;
2097 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, 0x30000);
2100 if(PURE_A_MODE == mMacMode) //Use Slowest rate when CTS/RTS,MZCai
2101 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate,0x01090109);
2102 else
2103 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, 0x30000);
2107 void zd_EnableShortSlot(U8 slot)
2109 void *reg = pdot11Obj->reg;
2110 if (slot){
2111 //FPRINT("zd_EnableShortSlot");
2112 pdot11Obj->ConfigFlag |= SHORT_SLOT_TIME_SET;
2113 pdot11Obj->SetReg(reg, ZD_IFS_Value, 0x547c00a);
2114 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_NORMAL_SLOT);
2116 else {
2117 //FPRINT("zd_DisableShortSlot");
2118 pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
2119 pdot11Obj->SetReg(reg, ZD_IFS_Value, 0x547c032);
2120 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_LONG_SLOT);
2124 void zd_PsChange(U8 PwrState)
2126 //FPRINT("zd_PsChange");
2128 mPwrState = PwrState;
2129 mRequestFlag |= PS_CHANGE_SET;
2130 return;
2133 void zd_EventNotify(U16 EventId, U32 parm1, U32 parm2, U32 parm3)
2135 //struct zd1205_private *macp = g_dev->priv;
2138 switch(EventId){
2139 case EVENT_TBCN:
2140 zd_NextBcn();
2141 break;
2143 case EVENT_DTIM_NOTIFY:
2144 zd_DtimNotify();
2145 break;
2147 case EVENT_TX_COMPLETE:
2148 TxCompleted(parm1, (U8)parm2, (U16)parm3);
2149 break;
2151 case EVENT_TCHAL_TIMEOUT:
2152 zd_SendTChalMsg();
2153 break;
2155 case EVENT_SCAN_TIMEOUT:
2156 zd_SwitchNextCH();
2157 break;
2159 case EVENT_UPDATE_TX_RATE:
2160 zd_UpdateCurrTxRate((U8)parm1, (U16)parm2);
2161 break;
2163 case EVENT_SW_RESET:
2164 //zd_SwReset();
2165 break;
2167 case EVENT_BUF_RELEASE:
2168 zd_Release_80211_Buffer();
2169 break;
2171 case EVENT_AUTH_TIMEOUT:
2172 zd_SendTAuthMsg();
2173 break;
2175 case EVENT_ASOC_TIMEOUT:
2176 zd_SendTAsocMsg();
2177 break;
2179 case EVENT_PS_CHANGE:
2180 zd_PsChange((U8)parm1);
2181 break;
2183 case EVENT_MORE_DATA:
2184 mRequestFlag |= PS_POLL_SET;
2185 break;
2187 case EVENT_ENABLE_PROTECTION:
2188 zd_EnableProtection((U8)parm1);
2189 break;
2191 case EVENT_ENABLE_BARKER:
2192 zd_EnableBarker((U8)parm1);
2193 break;
2195 case EVENT_SHORT_SLOT:
2196 zd_EnableShortSlot((U8)parm1);
2197 break;
2199 default:
2200 break;
2203 return;
2206 BOOLEAN zd_CleanupTxQ(void)
2208 //FPRINT("*****zd_CleanupTxQ*****");
2209 int loopCheck = 0;
2210 int CleanResult = 1;
2211 while(CleanResult)
2213 // To prevent unknown reason that can't clean up the txq(ex. re-queue in CleanupTxQ())
2214 if(loopCheck++ > 100)
2216 printk("infinite loop occurs in %s\n", __FUNCTION__);
2217 loopCheck = 0;
2218 break;
2220 CleanResult = CleanupTxQ();
2223 if (!pTxQ->cnt){
2224 pdot11Obj->QueueFlag &= ~TX_QUEUE_SET;
2225 return TRUE;
2227 else
2228 return FALSE;
2231 BOOLEAN zd_CleanupAwakeQ(void)
2233 //PSDEBUG("*****zd_CleanupAwakeQ*****");
2234 int loopCheck = 0;
2235 while(1)
2237 // To prevent unknown reason that can't clean Awake Queue
2238 if(loopCheck++ > 100)
2240 printk("infinite loop occurs in %s\n", __FUNCTION__);
2241 loopCheck = 0;
2242 break;
2244 CleanupAwakeQ();
2247 if (!pAwakeQ->cnt){
2248 pdot11Obj->QueueFlag &= ~AWAKE_QUEUE_SET;
2249 return TRUE;
2251 else{
2252 #if 0
2253 Signal_t *signal;
2254 FrmInfo_t *pfrmInfo;
2255 FrmDesc_t *pfrmDesc;
2257 while(pAwakeQ->cnt){
2258 signal = sigDeque(pAwakeQ);
2259 pfrmInfo = &signal->frmInfo;
2260 pfrmDesc = pfrmInfo->frmDesc;
2261 freeFdesc(pfrmDesc);
2262 pdot11Obj->ReleaseBuffer(signal->buf);
2263 freeSignal(signal);
2265 #endif
2266 return FALSE;
2270 void zd_ShowQInfo(void)
2272 printk(KERN_DEBUG "AwakeQ = %x, MgtQ = %x, TxQ = %x, mcQ = %x\n",
2273 pAwakeQ->cnt, pMgtQ->cnt, pTxQ->cnt, pPsQ[0]->cnt);
2274 printk(KERN_DEBUG "PsQ1 = %x, PsQ2 = %x, PsQ3 = %x, PsQ4 = %x\n",
2275 pPsQ[1]->cnt, pPsQ[2]->cnt, pPsQ[3]->cnt, pPsQ[4]->cnt);
2278 extern U8 AuthReqState;
2279 extern U8 AsocState;
2280 void zd_ShowState(void)
2282 printk(KERN_DEBUG "AuthReqState = %04x, AsocState = %04x\n", AuthReqState, AsocState);
2283 printk(KERN_DEBUG "mPwrState = %04x, mAssoc = %04x\n", mPwrState, mAssoc);
2284 printk(KERN_DEBUG "mAuthAlg = %04x, mBssIndex = %04x\n", mAuthAlg, mBssIndex);
2285 printk(KERN_DEBUG "mBssType = %04x, ConfigFlag = %04x\n", mBssType, pdot11Obj->ConfigFlag);
2288 void zd_ShowHashInfo(U8 aid)
2290 Hash_t *pHash = NULL;
2291 if (mBssType == INFRASTRUCTURE_BSS){
2292 aid = 0;
2294 pHash = sstByAid[aid];
2295 zd1205_dump_data("Mac Addr = ", pHash->mac, 6);
2296 FPRINT_V("Auth", pHash->auth);
2297 FPRINT_V("Asoc", pHash->asoc);
2298 FPRINT_V("psm", pHash->psm);
2299 FPRINT_V("Aid", pHash->aid);
2300 FPRINT_V("vapId", pHash->vapId);
2301 FPRINT_V("bErpSta", pHash->bErpSta);
2302 FPRINT_V("lsInterval", pHash->lsInterval);
2303 FPRINT_V("encryMode", pHash->encryMode);
2304 FPRINT_V("pkInstalled", pHash->pkInstalled);
2305 FPRINT_V("ZydasMode", pHash->ZydasMode);
2306 FPRINT_V("AlreadyIn", pHash->AlreadyIn);
2307 FPRINT_V("CurrTxRate", pHash->CurrTxRate);
2308 FPRINT_V("MaxRate", pHash->MaxRate);
2309 FPRINT_V("Preamble", pHash->Preamble);
2310 FPRINT_V("KeyId", pHash->KeyId);
2311 FPRINT_V("Rx IV16", pHash->RxSeed.IV16);
2312 FPRINT_V("Rx IV32", pHash->RxSeed.IV32);
2313 zd1205_dump_data("TK = ", pHash->TxSeed.TK, 16);
2314 zd1205_dump_data("Tx MIC K0 = ", (U8 *)&pHash->TxMicKey.K0, 4);
2315 zd1205_dump_data("Tx MIC K1 = ", (U8 *)&pHash->TxMicKey.K1, 4);
2316 zd1205_dump_data("Rx MIC K0 = ", (U8 *)&pHash->RxMicKey.K0, 4);
2317 zd1205_dump_data("Rx MIC K1 = ", (U8 *)&pHash->RxMicKey.K1, 4);
2318 #if 0
2319 FPRINT_V("KeyId", mWpaBcKeyId);
2320 FPRINT_V("GkInstalled", mGkInstalled);
2321 FPRINT_V("IV16", mIv16);
2322 FPRINT_V("IV32", mIv32);
2323 zd1205_dump_data("keyContent = ", pHash->keyContent, 16);
2324 zd1205_dump_data("TK = ", mBcSeed.TK, 16);
2325 zd1205_dump_data("Tx MIC K0 = ", (U8 *)&mBcMicKey.K0, 4);
2326 zd1205_dump_data("Tx MIC K1 = ", (U8 *)&mBcMicKey.K1, 4);
2327 #endif
2330 void zd_UpdateCardSetting(card_Setting_t *pSetting)
2332 void *reg = pdot11Obj->reg;
2333 static BOOLEAN InitConfig = TRUE;
2334 U8 bcAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2335 U32 tmpValue;
2336 BOOLEAN bReConnect = FALSE;
2338 //FPRINT("zd_UpdateCardSetting");
2339 /* Jimmy_chen@moxa.com.tw : Allow TxPower Setting. */
2340 if ( mTxPowerLevel != pSetting->TxPowerLevel )
2342 mTxPowerLevel = pSetting->TxPowerLevel;
2343 if(pSetting->TxPowerLevel>=0 && pSetting->TxPowerLevel<=2)
2345 printk("TxPowerLevel Set=%x\n",pSetting->TxPowerLevel) ;
2346 pdot11Obj->SetReg(reg,ZD_CR31,(U8)pSetting->TxPowerLevel);
2351 if (pSetting->AuthMode == 0){ //open system only
2352 mAuthAlogrithms[0] = OPEN_SYSTEM;
2353 mAuthAlogrithms[1] = NULL_AUTH;
2354 mAuthAlg = OPEN_SYSTEM;
2356 else if (pSetting->AuthMode == 1){ //shared key only
2357 mAuthAlogrithms[0] = SHARE_KEY;
2358 mAuthAlogrithms[1] = NULL_AUTH;
2359 mAuthAlg = SHARE_KEY;
2361 else if (pSetting->AuthMode == 2){ //auto auth mode
2362 mAuthAlogrithms[0] = OPEN_SYSTEM;
2363 mAuthAlogrithms[1] = SHARE_KEY;
2367 if (mAuthMode != pSetting->AuthMode){
2368 if (!InitConfig)
2369 bReConnect = TRUE;
2372 mAuthMode = pSetting->AuthMode;
2374 if (mLimitedUser != pSetting->LimitedUser){
2375 mLimitedUser = pSetting->LimitedUser;
2378 mBlockBSS = pSetting->BlockBSS;
2379 mSwCipher = pSetting->SwCipher;
2380 mKeyFormat = pSetting->EncryMode;
2381 mKeyId = pSetting->EncryKeyId;
2382 mBcKeyId = pSetting->BcKeyId;
2383 mDynKeyMode = pSetting->DynKeyMode;
2384 mFragThreshold = pSetting->FragThreshold;
2385 mRtsThreshold = pSetting->RTSThreshold;
2386 mBeaconPeriod = pSetting->BeaconInterval;
2387 mDtimPeriod = pSetting->DtimPeriod;
2391 if (!InitConfig)
2393 if (pSetting->BssType == INFRASTRUCTURE_BSS) // In IBSS mode, Enable beacon transmission at IBSS creation or Join.
2394 HW_EnableBeacon(pdot11Obj, mBeaconPeriod, mDtimPeriod, pSetting->BssType);
2398 //HW_EnableBeacon(pdot11Obj, mBeaconPeriod, mDtimPeriod, mBssType);
2400 if (mRadioOn != pSetting->RadioOn){
2401 mRadioOn = pSetting->RadioOn;
2402 if (!InitConfig)
2403 HW_RadioOnOff(pdot11Obj, mRadioOn);
2406 if (mRfChannel != pSetting->Channel){
2407 mRfChannel = pSetting->Channel;
2408 mPhpm.buf[0] = EID_DSPARMS;
2409 mPhpm.buf[1] = 1;
2410 mPhpm.buf[2] = mRfChannel;
2412 if (!InitConfig){
2413 if (pSetting->BssType != INFRASTRUCTURE_BSS)
2414 HW_SetRfChannel(pdot11Obj, mRfChannel, 0,pSetting->MacMode);
2417 if (pSetting->BssType == INDEPENDENT_BSS){
2418 mRequestFlag |= CHANNEL_SCAN_SET;
2419 pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
2420 //bReConnect = FALSE;
2426 mPreambleType = pSetting->PreambleType;
2428 if (mPreambleType)
2429 mCap |= CAP_SHORT_PREAMBLE;
2430 else
2431 mCap &= ~CAP_SHORT_PREAMBLE;
2433 mPrivacyInvoked = pSetting->EncryOnOff;
2434 if (pSetting->DynKeyMode > 0)
2435 mPrivacyInvoked = TRUE;
2437 if (mPrivacyInvoked)
2438 mCap |= CAP_PRIVACY;
2439 else
2440 mCap &= ~CAP_PRIVACY;
2442 //prince add begin
2443 if ( memcmp( &dot11DesiredSsid, pSetting->Info_SSID,36) !=0 )
2444 bReConnect = TRUE;
2445 //prince add end
2447 memcpy(&dot11DesiredSsid, pSetting->Info_SSID, pSetting->Info_SSID[1]+2);
2449 if (dot11DesiredSsid.buf[1] == 0)
2450 mProbeWithSsid = FALSE;
2451 else
2452 mProbeWithSsid = TRUE;
2453 //mProbeWithSsid = FALSE; //debug for ANY connection
2455 if ((pSetting->BssType == INFRASTRUCTURE_BSS) || (pSetting->BssType == INDEPENDENT_BSS)) {
2456 if (!InitConfig) {
2457 // if (memcmp(&mSsid, &dot11DesiredSsid, dot11DesiredSsid.buf[1]+2) != 0 ){
2458 bReConnect = TRUE;
2459 // }
2462 if (pSetting->BssType == INDEPENDENT_BSS){
2463 memcpy(&mSsid, &dot11DesiredSsid, dot11DesiredSsid.buf[1]+2);
2464 mATIMWindow = pSetting->ATIMWindow;
2469 mHiddenSSID = pSetting->HiddenSSID;
2470 if (mHiddenSSID){
2471 mSsid.buf[0] = EID_SSID;
2472 mSsid.buf[1] = 1;
2473 mSsid.buf[2] = 0x0;
2476 memcpy(&mBrates, pSetting->Info_SupportedRates, pSetting->Info_SupportedRates[1]+2);
2478 if (!InitConfig){
2479 #if defined(AMAC)
2480 pdot11Obj->SetReg(reg, ZD_BasicRateTbl, 0);
2481 #endif
2482 HW_SetSupportedRate(pdot11Obj, (U8 *)&mBrates);
2485 #if defined(OFDM)
2486 if (pSetting->MacMode != PURE_B_MODE){
2487 if (pSetting->ShortSlotTime){
2488 pdot11Obj->ConfigFlag |= SHORT_SLOT_TIME_SET;
2489 mCap |= CAP_SHORT_SLOT_TIME;
2491 else{
2492 pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
2493 mCap &= ~CAP_SHORT_SLOT_TIME;
2496 mMaxTxRate = 0x0b;
2497 if(PURE_A_MODE != pSetting->MacMode) {
2498 memcpy(&mExtRates, pSetting->Ext_SupportedRates, pSetting->Ext_SupportedRates[1]+2);
2499 if (!InitConfig)
2500 HW_SetSupportedRate(pdot11Obj, (U8 *)&mExtRates);
2504 else
2505 mMaxTxRate = 0x03;
2507 if (!InitConfig) {
2508 if (mMacMode != pSetting->MacMode) { //MacMode changed
2509 bReConnect = TRUE;
2513 mMacMode = pSetting->MacMode;
2514 #endif
2516 memcpy((U8 *)&dot11MacAddress, pSetting->MacAddr, 6);
2518 //prince add begin
2519 if ( memcmp( &mKeyVector[0][0], &pSetting->keyVector[0][0],sizeof(mKeyVector) ) != 0 )
2520 if (!InitConfig)
2521 bReConnect = TRUE;
2522 //prince add end
2523 memcpy(&mKeyVector[0][0], &pSetting->keyVector[0][0], sizeof(mKeyVector));
2524 mWepKeyLen = pSetting->WepKeyLen;
2525 memcpy(&mBcKeyVector[0], &pSetting->BcKeyVector[0], sizeof(mBcKeyVector));
2527 mBcKeyLen = pSetting->BcKeyLen;
2529 /* Check if we need to copy the WPA IE */
2530 //if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES)
2531 // || (pSetting->WPASupport == 1 && pSetting->WPAIe[1] != 0)){
2532 if ((pSetting->WPASupport==1 || pSetting->WPAIeLen))
2534 //printk(KERN_ERR "Copy WPA IE in the zd_UpdateCardSetting\n");
2535 memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2537 else
2539 memset(&mWPAIe.buf[0], 0, sizeof(mWPAIe));
2543 #if defined(AMAC)
2544 mOperationMode = pSetting->OperationMode;
2545 if (!InitConfig)
2547 //HW_CAM_ResetRollTbl(pdot11Obj);
2548 if ((mOperationMode == CAM_AP_VAP) || (mOperationMode == CAM_AP_CLIENT)){
2549 // for Ack response
2550 HW_CAM_ResetRollTbl(pdot11Obj);
2551 HW_CAM_SetMAC(pdot11Obj, CAM_VAP_START_AID, (U8 *)&dot11MacAddress);
2552 HW_CAM_UpdateRollTbl(pdot11Obj, CAM_VAP_START_AID);
2554 // for Address1 matching
2555 HW_CAM_SetMAC(pdot11Obj, 0, (U8 *)&bcAddr);
2556 HW_CAM_UpdateRollTbl(pdot11Obj, 0);
2558 else if (pSetting->BssType == INFRASTRUCTURE_BSS)
2559 {// Don't clear key in AP_BSS and IBSS mode.
2560 HW_CAM_ClearRollTbl(pdot11Obj, CAM_VAP_START_AID);
2561 HW_CAM_ClearRollTbl(pdot11Obj, 0);
2564 else
2565 {// Only clear all keys in the first time.
2566 HW_CAM_ResetRollTbl(pdot11Obj);
2569 #endif
2571 //mPwrState = pSetting->PwrState;
2572 if (pSetting->BssType == AP_BSS){
2573 memcpy(&mSsid, &dot11DesiredSsid, dot11DesiredSsid.buf[1]+2);
2574 memcpy((U8 *)&mBssId, pSetting->MacAddr, 6);
2576 // Update the mCap information
2577 mCap &= ~BIT_1;
2578 mCap |= BIT_0;
2580 //mGkInstalled = 0;
2581 zd_InitWepData();
2582 if (!InitConfig){
2583 zd_CmdProcess(CMD_DISASOC_ALL, 0, ZD_UNSPEC_REASON);
2588 #if defined(OFDM)
2589 mErp.buf[2] = 0; //reset erp info
2591 if ((mCap & CAP_SHORT_PREAMBLE) == 0){
2592 mErp.buf[2] |= BARKER_PREAMBLE;
2593 if (pdot11Obj){
2594 if(pdot11Obj->bDeviceInSleep)
2596 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
2597 return ;
2600 tmpValue = pdot11Obj->GetReg(reg, ZD_RTS_CTS_Rate);
2601 tmpValue &= ~NON_BARKER_PMB_SET;
2602 tmpValue |= CTS_RATE_11M;
2603 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, tmpValue);
2607 if (pdot11Obj)
2608 pdot11Obj->ConfigFlag &= ~ENABLE_PROTECTION_SET;
2610 if (pSetting->BssType == INDEPENDENT_BSS){
2611 if (mMacMode == PURE_G_MODE)
2612 mErp.buf[2] = 0;
2613 else
2614 mErp.buf[2] = (NON_ERP_PRESENT | USE_PROTECTION | BARKER_PREAMBLE);
2616 #endif
2618 if (!InitConfig){
2619 //if (mBssType != pSetting->BssType){
2620 if (mBssType != pSetting->BssType)
2621 //if (pSetting->BssType != INFRASTRUCTURE_BSS)
2623 //int i;
2625 mBssType = pSetting->BssType;
2626 if (pSetting->BssType == AP_BSS){
2627 zd_StartAP();
2628 bReConnect = FALSE;
2630 else{
2631 zd_StartSTA(0);
2632 bReConnect = FALSE;
2635 //for (i=0; i<(MAX_AID+1); i++)
2636 //CleanupHash(sstByAid[i]);
2637 //InitHashTbl();
2638 zd_InitWepData();
2639 //zd_CmdFlushQ();
2643 mBssType = pSetting->BssType;
2644 pdot11Obj->BssType = mBssType;
2646 if (bReConnect)
2648 if (pSetting->BssType == INFRASTRUCTURE_BSS)
2650 BOOLEAN ret;
2651 pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
2652 if (pSetting->ap_scan == 1)
2654 ret = zd_ChooseAP(1); // Choose AP by dot11DesiredBssid.
2656 else
2657 ret = zd_ChooseAP(0);
2659 if (ret == FALSE)
2661 zd_StartSTA(0);//ReScan all channels to find the selected BSS.
2664 /*==prince delete
2665 else
2667 zd_StartSTA(0);
2668 printk("Call StartSTA(IBSS or AP)\n");
2670 ================*/
2671 ///prince add begin
2672 else if (pSetting->BssType == INDEPENDENT_BSS )
2674 zd_StartSTA(0);
2675 printk("Call StartSTA(IBSS or AP)\n");
2677 else if (pSetting->BssType == AP_BSS )
2679 zd_StartAP();
2680 zd_InitWepData();
2681 printk("Call StartAP\n");
2684 //prince add end
2689 InitConfig = FALSE;
2694 void zd_PsPoll(void)
2696 Signal_t *signal;
2697 FrmDesc_t *pfrmDesc;
2699 //FPRINT("zd_PsPoll");
2701 if ((signal = allocSignal()) == NULL){
2702 return;
2705 pfrmDesc = allocFdesc();
2706 if(!pfrmDesc){
2707 freeSignal(signal);
2708 return;
2711 sendPsPollFrame(signal, pfrmDesc, &mBssId, mAid);
2712 mRequestFlag &= ~PS_POLL_SET;
2713 return;
2716 void zd_NullData(void)
2718 Signal_t *signal;
2719 FrmDesc_t *pfrmDesc;
2721 //FPRINT("zd_NullData");
2723 if ((signal = allocSignal()) == NULL){
2724 return;
2727 pfrmDesc = allocFdesc();
2728 if(!pfrmDesc){
2729 freeSignal(signal);
2730 return;
2733 sendNullDataFrame(signal, pfrmDesc, &mBssId);
2734 mRequestFlag &= ~PS_CHANGE_SET;
2735 return;
2738 void zd_DisConnect(void)
2740 //FPRINT("zd_DisConnect");
2742 zd_CmdProcess(CMD_ROAMING,0,0);
2743 mRequestFlag &= ~DIS_CONNECT_SET;
2745 /*pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
2746 pdot11Obj->bChScanning = 0;
2747 mRequestFlag &= ~DIS_CONNECT_SET;
2748 #if 0
2749 zd_CmdProbeReq((U8)mProbeWithSsid);
2750 #else
2751 zd_ChooseAP();
2752 #endif */
2755 void zd_Roaming(void)
2757 //FPRINT("zd_Roaming");
2758 pdot11Obj->ConfigFlag |= SCAN_AND_CONNECT_SET;
2759 //pdot11Obj->bChScanning = 0;
2760 mRequestFlag &= ~ROAMING_SET;
2761 zd_CmdProbeReq((U8)mProbeWithSsid);
2764 void zd_ConnectMon(void)
2766 //FPRINT_V("mRequestFlag", mRequestFlag);
2767 if (mRequestFlag & DIS_CONNECT_SET){
2768 mRequestFlag = 0;
2769 FPRINT("DIS_CONNECT_SET");
2770 zd_DisConnect();
2771 goto end;
2774 if (mRequestFlag & ROAMING_SET){
2775 mRequestFlag = 0;
2776 FPRINT("ROAMING_SET");
2777 zd_Roaming();
2778 goto end;
2781 if (mRequestFlag & CHANNEL_SCAN_SET){
2782 //FPRINT("CHANNEL_SCAN_SET");
2783 mRequestFlag &= ~BSS_CONNECT_SET;
2784 mRequestFlag &= ~CONNECT_TOUT_SET;
2785 zd_CmdProbeReq((U8)mProbeWithSsid);
2786 goto end;
2789 if (mRequestFlag & BSS_CONNECT_SET){
2790 //FPRINT("BSS_CONNECT_SET");
2791 mRequestFlag &= ~CHANNEL_SCAN_SET;
2792 mRequestFlag &= ~CONNECT_TOUT_SET;
2793 zd_InfraConnect(mBssIndex);
2794 goto end;
2797 if (mRequestFlag & CONNECT_TOUT_SET){
2798 //FPRINT("CONNECT_TOUT_SET");
2799 mConnRetryCnt++;
2801 //prince add for ad-hoc and master mode begin
2802 if ( mBssType == INFRASTRUCTURE_BSS )
2804 //prince add for ad-hoc and master mode end
2806 if ((mConnRetryCnt > 6) || (pdot11Obj->bChScanning)){
2807 mRequestFlag &= ~CONNECT_TOUT_SET;
2808 mConnRetryCnt = 0;
2809 mSsid.buf[1] = 0; //reset mSsid
2810 //return;
2812 else {
2813 FPRINT("Connect Timeout, Re-Connect...");
2814 zd_InfraConnect(mBssIndex);
2815 //return;
2817 goto end;
2819 //prince add for ad-hoc and master mode begin
2821 //prince add for ad-hoc and master mode end
2824 if (mRequestFlag & PS_POLL_SET){
2825 zd_PsPoll();
2826 goto end;
2829 if (mRequestFlag & PS_CHANGE_SET){
2830 zd_NullData();
2831 goto end;
2834 if (mRequestFlag & IBSS_CONNECT_SET){
2835 zd_IbssConnect();
2836 goto end;
2838 end:
2839 zd_SigProcess();
2842 extern BOOLEAN SynchEntry(Signal_t* signal);
2843 extern BOOLEAN AuthReqEntry(Signal_t* signal);
2844 extern BOOLEAN AuthRspEntry(Signal_t* signal);
2845 extern BOOLEAN AsocEntry(Signal_t* signal);
2846 //State machine entry point
2847 void zd_SigProcess(void)
2849 Signal_t* signal = NULL;
2850 BOOLEAN ret;
2851 int loopChk = 0;
2853 while((signal = sigDeque(&mgtQ)) != NULL){
2854 if(loopChk++ > 100)
2856 while(loopChk--)
2857 printk("We are trapped in %s\n", __FUNCTION__);
2858 sigEnque(&mgtQ, signal);
2859 break;
2861 switch(signal->block){
2862 case BLOCK_SYNCH:
2863 ret = SynchEntry(signal);
2864 break;
2866 case BLOCK_AUTH_REQ:
2867 ret = AuthReqEntry(signal);
2868 break;
2870 case BLOCK_AUTH_RSP:
2871 ret = AuthRspEntry(signal);
2872 break;
2874 case BLOCK_ASOC:
2875 ret = AsocEntry(signal);
2876 break;
2878 default:
2879 ret = TRUE;
2880 break;
2883 if (ret){
2884 pdot11Obj->ReleaseBuffer(signal->buf);
2885 freeSignal(signal);
2889 pdot11Obj->QueueFlag &= ~MGT_QUEUE_SET;
2892 U8 zd_CheckTotalQueCnt(void)
2894 U8 TotalQueCnt = 0;
2895 U32 flags;
2896 int i;
2898 flags = pdot11Obj->EnterCS();
2900 for (i=0; i<MAX_AID+1; i++)
2901 TotalQueCnt += pPsQ[i]->cnt;
2903 TotalQueCnt += pAwakeQ->cnt;
2904 TotalQueCnt += pTxQ->cnt;
2905 TotalQueCnt += pMgtQ->cnt;
2906 pdot11Obj->ExitCS(flags);
2909 return TotalQueCnt;
2911 void zd_RateAdaption(void)
2913 int i=1;
2914 U32 SucessFrmCnt;
2915 U32 FailFmrCnt;
2916 Hash_t *pHash;
2917 U32 Ratio = 0;
2918 U32 UserLimit=1;
2919 U8 idx,totalUser;
2921 #if defined(OFDM)
2922 //For STA, it do RateAdaption with AP only
2923 //For Others, with Associated STAs
2924 if(INFRASTRUCTURE_BSS == mBssType)
2926 i=0;
2927 UserLimit=0;
2929 //for(idx=0,totalUser=0;idx<=NUM_VAP;idx++)
2930 // totalUser += mCurrConnUser[i];
2931 totalUser = mCurrConnUser;
2932 if (totalUser >= UserLimit)
2934 for (; i<(MAX_AID+1); i++)
2936 pHash = sstByAid[i];
2937 if (pHash->bValid)
2939 SucessFrmCnt = pHash->SuccessFrames;
2940 FailFmrCnt = pHash->FailedFrames;
2942 //FPRINT_V("Aid", i);
2944 if (SucessFrmCnt + FailFmrCnt < 20)
2946 //FPRINT(" FmrCnt < 20");
2947 continue;
2950 if ((SucessFrmCnt) && (FailFmrCnt == 0))
2952 pHash->RiseConditionCount++;
2953 pHash->DownConditionCount = 0;
2954 //FPRINT(" FailFmrCnt == 0");
2955 goto JudgeRate;
2957 else
2959 Ratio = SucessFrmCnt / FailFmrCnt;
2960 if (Ratio >= 9 && pHash->CurrTxRate >= RATE_36M)
2962 pHash->RiseConditionCount++;
2963 pHash->DownConditionCount = 0;
2964 goto JudgeRate;
2966 else if (Ratio > LINE1) //100
2968 //FPRINT(" > LINE1");
2969 if (pHash->CurrTxRate > RATE_36M)
2971 pHash->RiseConditionCount = 0;
2972 pHash->DownConditionCount++;
2973 goto JudgeRate;
2975 else if (pHash->CurrTxRate == RATE_36M)
2977 pHash->RiseConditionCount = 0;
2978 pHash->DownConditionCount = 0;
2979 goto JudgeRate;
2981 else
2983 pHash->RiseConditionCount++;
2984 pHash->DownConditionCount = 0;
2985 goto JudgeRate;
2987 } // LINE1
2988 else
2990 if (Ratio >= LINE2) //10
2992 //FPRINT(" > LINE2");
2993 if (pHash->CurrTxRate > RATE_24M)
2995 pHash->RiseConditionCount = 0;
2996 pHash->DownConditionCount++;
2997 goto JudgeRate;
2999 else if (pHash->CurrTxRate == RATE_24M)
3001 pHash->RiseConditionCount = 0;
3002 pHash->DownConditionCount = 0;
3003 goto JudgeRate;
3005 else
3007 pHash->RiseConditionCount++;
3008 pHash->DownConditionCount = 0;
3009 goto JudgeRate;
3011 } // LINE2
3012 else
3014 if (Ratio >= LINE3)
3016 //FPRINT(" > LINE3");
3017 if (pHash->CurrTxRate > RATE_18M)
3019 pHash->RiseConditionCount = 0;
3020 pHash->DownConditionCount++;
3021 goto JudgeRate;
3023 else if (pHash->CurrTxRate == RATE_18M)
3025 pHash->RiseConditionCount = 0;
3026 pHash->DownConditionCount = 0;
3027 goto JudgeRate;
3029 else
3031 pHash->RiseConditionCount++;
3032 pHash->DownConditionCount = 0;
3033 goto JudgeRate;
3035 } // LINE3
3036 else
3038 //FPRINT(" < LINE3");
3039 pHash->RiseConditionCount = 0;
3040 pHash->DownConditionCount++;
3041 goto JudgeRate;
3047 JudgeRate:
3048 if (pHash->bJustRiseRate)
3050 if (pHash->DownConditionCount)
3052 if (pHash->CurrTxRate > 0 && PURE_A_MODE != mMacMode)
3054 pHash->CurrTxRate--;
3055 if(pdot11Obj->rfMode == UW2453_RF)
3056 if(pHash->CurrTxRate == 1)
3057 pHash->CurrTxRate --;
3058 //FPRINT_V("Case 1: Down Rate, NewRate", pHash->CurrTxRate);
3060 else if(pHash->CurrTxRate > 4)
3062 pHash->CurrTxRate--;
3064 pHash->DownConditionCount = 0;
3065 pHash->bJustRiseRate = FALSE;
3067 else
3069 pHash->bJustRiseRate = FALSE;
3072 else
3074 pHash->bJustRiseRate = 0;
3075 if (pHash->RiseConditionCount >= RISE_CONDITION_THRESHOLD)
3077 if (pHash->MaxRate > pHash->CurrTxRate)
3079 pHash->CurrTxRate++;
3080 if(pdot11Obj->rfMode == UW2453_RF)
3081 if(pHash->CurrTxRate == 1)
3082 pHash->CurrTxRate++ ;
3084 pHash->bJustRiseRate = TRUE;
3085 //FPRINT_V("Case 2: Rise Rate, NewRate", pHash->CurrTxRate);
3087 pHash->DownConditionCount = 0;
3088 pHash->RiseConditionCount = 0;
3090 else if (pHash->DownConditionCount >= DOWN_CONDITION_THRESHOLD)
3092 if (pHash->CurrTxRate > 0 && PURE_A_MODE != mMacMode)
3094 pHash->CurrTxRate--;
3095 if(pdot11Obj->rfMode == UW2453_RF)
3096 if(pHash->CurrTxRate == 1)
3097 pHash->CurrTxRate --;
3099 //FPRINT_V("Case 3: Down Rate, NewRate", pHash->CurrTxRate);
3101 else if(pHash->CurrTxRate > 4)
3103 pHash->CurrTxRate--;
3106 pHash->DownConditionCount = 0;
3107 pHash->RiseConditionCount = 0;
3110 pHash->SuccessFrames = 0;
3111 pHash->FailedFrames = 0;
3113 } // end of pHash->bValid
3114 } // end of for loop
3116 #endif
3119 void zd_PerSecTimer(void)
3121 static U32 sec = 0;
3122 sec++;
3124 if (mBssType == AP_BSS){
3125 if (sec > AGE_HASH_PERIOD){
3126 U32 tmpValue;
3127 void *reg = pdot11Obj->reg;
3129 mZyDasModeClient = FALSE;
3130 pdot11Obj->ConfigFlag &= ~NON_ERP_PRESENT_SET;
3131 pdot11Obj->ConfigFlag &= ~BARKER_PREAMBLE_SET;
3132 AgeHashTbl();
3133 sec = 0;
3135 #if defined(OFDM)
3136 if (mMacMode != PURE_B_MODE && mMacMode != PURE_A_MODE){
3138 if (pdot11Obj->ConfigFlag & NON_ERP_PRESENT_SET){
3139 //FPRINT("Enable Protection Mode");
3140 mErp.buf[2] |= (NON_ERP_PRESENT | USE_PROTECTION);
3141 pdot11Obj->ConfigFlag |= ENABLE_PROTECTION_SET;
3142 if(pdot11Obj->bDeviceInSleep)
3144 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
3145 return ;
3147 tmpValue = pdot11Obj->GetReg(reg, ZD_RTS_CTS_Rate);
3148 tmpValue &= ~CTS_MOD_TYPE_OFDM;
3149 tmpValue |= CTS_RATE_11M;
3150 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, tmpValue);
3151 pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
3152 mCap &= ~CAP_SHORT_SLOT_TIME;
3153 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_NORMAL_SLOT);
3155 if (((mCap & CAP_SHORT_PREAMBLE) == 0) || (pdot11Obj->ConfigFlag & BARKER_PREAMBLE_SET)){
3156 mErp.buf[2] |= BARKER_PREAMBLE;
3157 if(pdot11Obj->bDeviceInSleep)
3159 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__);
3160 return ;
3163 tmpValue = pdot11Obj->GetReg(reg, ZD_RTS_CTS_Rate);
3164 tmpValue &= ~NON_BARKER_PMB_SET;
3165 tmpValue |= CTS_RATE_11M;
3166 pdot11Obj->SetReg(reg, ZD_RTS_CTS_Rate, tmpValue);
3167 //FPRINT("Enable Barker Preamble");
3170 else{
3171 //#if 0 for pure g mode testing
3172 //FPRINT("Disable Protection Mode");
3173 mErp.buf[2] &= ~(NON_ERP_PRESENT);
3174 pdot11Obj->ConfigFlag &= ~ENABLE_PROTECTION_SET;
3176 //FPRINT("Disable Barker Preamble");
3177 mErp.buf[2] &= ~(BARKER_PREAMBLE);
3179 pdot11Obj->ConfigFlag &= ~SHORT_SLOT_TIME_SET;
3180 mCap |= CAP_SHORT_SLOT_TIME;
3181 pdot11Obj->SetReg(reg, ZD_CWmin_CWmax, CW_SHORT_SLOT);
3186 #endif
3192 BOOLEAN zd_QueryStaTable(U8 *sta, void **ppHash)
3194 Hash_t *pHash = NULL;
3195 MacAddr_t *addr = (MacAddr_t*) sta;
3197 pHash = HashSearch(addr);
3199 *ppHash = pHash;
3201 if (!pHash)
3202 return FALSE;
3204 if (pHash->asoc == STATION_STATE_ASOC)
3205 return TRUE;
3206 else
3207 return FALSE;
3210 U8 zd_GetBssList(bss_info_t *pBssList)
3212 U8 i;
3214 for (i=0; i < mBssCnt; i++, pBssList++){
3215 memcpy(pBssList->bssid, (U8 *)&mBssInfo[i].bssid, 6);
3216 pBssList->beaconInterval = mBssInfo[i].bcnInterval;
3217 pBssList->channel = mBssInfo[i].Phpm.buf[2];
3218 pBssList->cap = mBssInfo[i].cap;
3219 memcpy(pBssList->ssid, (U8 *)&mBssInfo[i].ssid, mBssInfo[i].ssid.buf[1]+2);
3220 //printk("ssid: %s\r\n", &mBssInfo[i].ssid.buf[2]);
3221 memcpy(pBssList->supRates, (U8 *)&mBssInfo[i].supRates, mBssInfo[i].supRates.buf[1]+2);
3222 memcpy(pBssList->extRates, (U8 *)&mBssInfo[i].extRates, mBssInfo[i].extRates.buf[1]+2);
3223 pBssList->atimWindow = mBssInfo[i].IbssParms.buf[2] + ((U16)(mBssInfo[i].IbssParms.buf[3]) << 8);
3224 pBssList->signalStrength = mBssInfo[i].signalStrength;
3225 pBssList->signalQuality = mBssInfo[i].signalQuality;
3226 pBssList->apMode = mBssInfo[i].apMode;
3228 /* Copy WPAIe */
3229 memcpy(pBssList->WPAIe, (U8 *)&mBssInfo[i].WPAIe, mBssInfo[i].WPAIe[1]+2);
3230 memcpy(pBssList->RSNIe, (U8 *)&mBssInfo[i].RSNIe, mBssInfo[i].RSNIe[1]+2);
3232 #if ZDCONF_LP_SUPPORT == 1
3233 memcpy(pBssList->zdIE_Info_BURST, (U8 *)&mBssInfo[i].zdIE_BURST, sizeof(pBssList->zdIE_Info_BURST));
3234 memcpy(pBssList->zdIE_Info_AMSDU, (U8 *)&mBssInfo[i].zdIE_AMSDU, sizeof(pBssList->zdIE_Info_AMSDU));
3235 #endif
3236 #if ZDCONF_SES_SUPPORT == 1
3237 pBssList->SES_Element_Valid = mBssInfo[i].SES_Element_Valid;
3238 memcpy(&(pBssList->SES_Element), &(mBssInfo[i].SES_Element), sizeof(Element));
3239 #endif
3240 //printk(" [zd_GetBssList] wpa ie len = %d\r\n", mBssInfo[i].WPAIe[1]+2);
3243 return mBssCnt;
3246 U16 zd_AidLookUp(U8 *addr)
3248 MacAddr_t *sta = (MacAddr_t *)addr;
3249 return AIdLookup(sta);
3251 #if 0
3252 void zd_UpdateIbssInfo(U8 *addr, U8 tmpMaxRate, U8 preamble, U8 erpSta)
3254 U8 MaxRate;
3255 MaxRate = RateConvert((tmpMaxRate & 0x7f));
3256 if (MaxRate > mMaxTxRate)
3257 MaxRate = mMaxTxRate;
3259 UpdateStaStatus((MacAddr_t *)addr, STATION_STATE_ASOC, 0);
3260 AssocInfoUpdate((MacAddr_t *)addr, MaxRate, 0, 0, preamble, erpSta, 0);
3261 //FPRINT_V("MaxRate", MaxRate);
3262 //FPRINT_V("erpSta", erpSta);
3264 #endif
3265 void zd_UpdateIbssInfo(U8 *addr, U8 tmpMaxRate, U8 preamble, U8 erpSta)
3267 U8 MaxRate;
3268 MacAddr_t *Sta;
3269 Hash_t *pHash;
3270 MaxRate = RateConvert((tmpMaxRate & 0x7f));
3272 if (MaxRate > mMaxTxRate)
3273 MaxRate = mMaxTxRate;
3274 Sta = (MacAddr_t *)addr;
3275 UpdateStaStatus(Sta, STATION_STATE_ASOC, 0);
3277 pHash = HashSearch(Sta);
3278 if (pHash != NULL)
3280 if (!pHash->AlreadyIn)
3282 pHash->AlreadyIn=1;
3283 mCurrConnUser++;
3284 if (erpSta == FALSE)
3286 mNumBOnlySta++;
3290 AssocInfoUpdate((MacAddr_t *)addr, MaxRate, 0, 0, preamble, erpSta,0,0,1,0);
3291 //FPRINT_V("MaxRate", MaxRate);
3292 //FPRINT_V("erpSta", erpSta);
3295 #endif