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
;
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
;
33 #if ZDCONF_LP_SUPPORT == 1
40 //FPRINT("zd_SendPkt");
42 if (zd_CheckTotalQueCnt() > TXQ_THRESHOLD
){
43 //FPRINT("Drop Tx packet");
47 signal
= allocSignal();
49 FPRINT("zd_SendPkt out of signal");
50 FPRINT_V("freeSignalCount", freeSignalCount
);
53 #if ZDCONF_LP_SUPPORT == 1
54 memcpy(signal
->EthHdr
,pEthHdr
,14);
56 pfrmDesc
= allocFdesc();
59 FPRINT("zd_SendPkt out of description");
60 FPRINT_V("freeFdescCount", freeFdescCount
);
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
;
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 */
85 frame
->bodyLen
= bodyLen
;
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
);
95 pfrmDesc
->ConfigSet
|= EAPOL_FRAME_SET
;
97 pfrmDesc
->ConfigSet
&= ~EAPOL_FRAME_SET
;
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
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
);
115 if (SendPkt(signal
, pfrmDesc
, TRUE
)) //4727
120 SendPkt(signal
, pfrmDesc
, TRUE
);
127 #define BSS_FORWARD 2
128 void zd_WirelessForward(U8
*pHdr
, U8
*pBody
, U32 len
, void *buf
, U8 mode
, void *pHash
, U8
*pEthHdr
)
134 //FPRINT("zd_WirelessForward");
137 if (zd_CheckTotalQueCnt() > TXQ_THRESHOLD
){
138 //FPRINT("Drop Intra-BSS packet");
139 pdot11Obj
->ReleaseBuffer(buf
);
144 signal
= allocSignal();
146 FPRINT("zd_WirelessForward out of signal");
147 FPRINT_V("freeSignalCount", freeSignalCount
);
148 pdot11Obj
->ReleaseBuffer(buf
);
152 pfrmDesc
= allocFdesc();
155 FPRINT("zd_WirelessForward out of description");
156 FPRINT_V("freeFdescCount", freeFdescCount
);
157 pdot11Obj
->ReleaseBuffer(buf
);
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);
170 frame
->bodyLen
= len
;
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
);
196 void zd_SendDeauthFrame(U8
*sta
, U8 ReasonCode
)
200 printk(KERN_ERR
"SendDeauthFrame with ReasonCode=%u\n",ReasonCode
);
201 if ((mBssType
== INDEPENDENT_BSS
) || (mBssType
== PSEUDO_IBSS
))
204 if ((signal
= allocSignal()) == NULL
)
206 signal
->id
= SIG_DEAUTH_REQ
;
207 signal
->block
= BLOCK_AUTH_REQ
;
209 memcpy(&signal
->frmInfo
.Sta
, sta
, 6);
210 signal
->frmInfo
.rCode
= ReasonCode
;
211 sigEnque(pMgtQ
, (signal
));
216 void zd_SendClass2ErrorFrame(MacAddr_t
*sta
, U8 vapId
)
220 //FPRINT("zd_sendClass2ErrorFrame");
222 if ((mBssType
== INDEPENDENT_BSS
) || (mBssType
== PSEUDO_IBSS
))
225 if ((signal
= allocSignal()) == NULL
)
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
));
237 void zd_SendClass3ErrorFrame(MacAddr_t
*sta
, U8 vapId
)
241 //FPRINT("zd_SendClass3ErrorFrame");
242 if ((mBssType
== INDEPENDENT_BSS
) || (mBssType
== PSEUDO_IBSS
))
245 if ((signal
= allocSignal()) == NULL
)
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
));
258 #define MIC_HEADER_LEN 16
259 BOOLEAN
zd_CheckMic(U8
*pHdr
, U8
*pBody
, U32 bodyLen
, Hash_t
*pHash
, U8
*pEthHdr
)
268 /* Always return TRUE, 4D06 */
273 if (pIV
[3] & EIV_BIT
)
275 if (pHdr
[4] & 1) // Use group key
278 pRxMicKey
= &mBcMicKey
;
282 else // Use Unicast key
286 if ((PkInstalled
=pHash
->pkInstalled
))
287 pRxMicKey
= &pHash
->RxMicKey
;
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;
300 U32 Len
= bodyLen
- MIC_LNG
;
302 void *reg
= pdot11Obj
->reg
;
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
);
327 //FPRINT("Rx MIC can't start !!!");
328 //FPRINT_V("MicStatus", MicStatus);
329 zdCnt
.RxMicNoStart
++;
335 pdot11Obj
->SetReg(reg
, ZD_MIC_KEY_LOW
, pRxMicKey
->K0
);
336 pdot11Obj
->SetReg(reg
, ZD_MIC_KEY_HIGH
, pRxMicKey
->K1
);
339 pdot11Obj
->SetReg(reg
, ZD_MIC_START_ADDR0
, (U32
)pEthHdr
);
340 pdot11Obj
->SetReg(reg
, ZD_MIC_BLOCK0_LEN
, MIC_HEADER_LEN
);
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
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
));
362 //FPRINT("Rx MIC not finish !!!");
363 //FPRINT_V("HwMicStatus", HwMicStatus);
364 zdCnt
.RxMicNoFinish
++;
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);
382 //Software MIC Calculation, HW MIC failed
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
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
401 MICappendByte(*pByte
++, pRxMicKey
);
403 MICappendByte(0,pRxMicKey
);//priority
404 MICappendByte(0,pRxMicKey
);//3 zeros
405 MICappendByte(0,pRxMicKey
);
406 MICappendByte(0,pRxMicKey
);
409 for (i
=0; i
<Len
; i
++){
410 MICappendByte(*pByte
++, pRxMicKey
);
413 MICgetMIC(CalMic
, pRxMicKey
); // Append MIC (8 byte)
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]);
432 //FPRINT("***** MIC success *****");
433 //printk(KERN_ERR "SW MIC check OK\n");
442 void zd_ReceivePkt(U8
*pHdr
, U32 hdrLen
, U8
*pBody
, U32 bodyLen
, void *buf
, U8
*pEthHdr
, rxInfo_t
*pRxInfo
, const BOOLEAN LP
)
448 MacAddr_t
*pDa
, *pSa
;
450 PsMode psm
= PSMODE_STA_ACTIVE
;
451 U32 dataLen
= 0xFFFFFFFF;
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
;
465 #if ZDCONF_LP_SUPPORT == 1
466 // ####### FOR A-MSDU ########
468 struct sk_buff
*skb
= NULL
;
473 U16 idx
, pktLen
,idx2
;
475 Hash_t
*sHash
= NULL
;
479 // ###########################
489 ZDEBUG("zd_ReceivePkt");
492 if (mBssType
== AP_BSS
){
493 pDa
= (MacAddr_t
*)&pHdr
[16]; //A3
494 pSa
= (MacAddr_t
*)&pHdr
[10]; //A2
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
);
500 pHash
= RxInfoIndicate(pSa
, psm
, rate
); //12us update ps and rate information
502 pHash
= sstByAid
[SaIndex
];
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
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
;
528 zd_SendClass2ErrorFrame(pSa
, vapId
);
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]);
541 if (sas
== STATION_STATE_ASOC
){ //association station
542 if (mBssType
== AP_BSS
){
544 if (pHash
->keyLength
== 32){
545 //if (mDynKeyMode == DYN_KEY_TKIP){
546 if (!pHash
->pkInstalled
)
548 else if (!mGkInstalled
)
550 else if ((pHdr
[1] & WEP_BIT
) && (hdrLen
== 32)){
552 if (!zd_CheckMic(pHdr
, pBody
, bodyLen
, pHash
, pEthHdr
)){
556 bodyLen
-= MIC_LNG
; //remove MIC
561 if (mCurrConnUser
> 1){
563 bcBuf
= pdot11Obj
->AllocBuffer(bodyLen
, &pBcData
);
565 memcpy(pBcData
, pBody
, bodyLen
);
566 zd_WirelessForward(pHdr
, pBcData
, bodyLen
, bcBuf
, mode
, NULL
, pEthHdr
);
572 void *pTxHash
= NULL
;
574 if (mBlockBSS
){ //discard IntraBSS packet
578 zd_QueryStaTable((U8
*)pDa
, &pTxHash
); //Automatic wireless forwarding
583 if ((pHash
->keyLength
==32) && (pHdr
[1] & WEP_BIT
) && (hdrLen
== 32)){
585 if (!zd_CheckMic(pHdr
, pBody
, bodyLen
, pHash
, pEthHdr
)){
589 bodyLen
-= MIC_LNG
; //remove MIC
594 zd_WirelessForward(pHdr
, pBody
, bodyLen
, buf
, mode
, pTxHash
, pEthHdr
);
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.
608 else{// sw-mic check ok, remove MIC
616 #if ZDCONF_LP_SUPPORT == 1
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) {
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)){
635 dataLen
= bodyLen
+ 6; /* Plus DA, SA*/
638 *---------------*------*-----*------------------------*
639 | WLAN HDR | SNAP | LEN | DATA |
640 *---------------*------*-----*------------------------*
645 dataLen
= bodyLen
+ 14; /* Plus DA, SA and TypeLen */
646 pData
[12] = (bodyLen
>>8) & 0xFF;
647 pData
[13] = bodyLen
& 0xFF;
650 *---------------*------------------------*
652 *---------------*------------------------*
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
);
667 pRxSignal
= allocSignal();
669 FPRINT("zd_ReceivePkt out of signal");
670 FPRINT_V("freeSignalCount", freeSignalCount
);
674 pRxFdesc
= allocFdesc();
676 FPRINT("zd_ReceivePkt out of description");
677 FPRINT_V("freeFdescCount", freeFdescCount
);
678 freeSignal(pRxSignal
);
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
);
696 pdot11Obj
->ReleaseBuffer(buf
);
703 pdot11Obj
->ReleaseBuffer(buf
);
706 void zd_InitWepData(void)
718 void zd_Release_80211_Buffer(void)
725 BOOLEAN
zd_Reset80211(zd_80211Obj_t
* pObj
)
739 BOOLEAN
zd_HandlePsPoll(U8
*pHdr
)
743 //PSDEBUG("zd_HandlePsPoll");
744 psPollFrame
.HdrLen
= 16;
745 psPollFrame
.bodyLen
= 0;
746 memcpy(&psPollFrame
.header
[0], pHdr
, 16);
747 RxPsPoll(&psPollFrame
);
751 BOOLEAN
zd_StartAP(void)
753 void *reg
= pdot11Obj
->reg
;
755 HW_SetRfChannel(pdot11Obj
, mRfChannel
, 1, mMacMode
);
758 pdot11Obj
->SetReg(reg
, ZD_BasicRateTbl
, 0);
760 HW_SetSupportedRate(pdot11Obj
, (U8
*)&mBrates
);
763 if(PURE_A_MODE
!= mMacMode
)
764 HW_SetSupportedRate(pdot11Obj
, (U8
*)&mExtRates
);
768 /* Set CAM_MODE to AP Mode */
769 pdot11Obj
->SetReg(reg
, ZD_CAM_MODE
, CAM_AP
);
772 HW_EnableBeacon(pdot11Obj
, mBeaconPeriod
, mDtimPeriod
, AP_BSS
);
773 HW_RadioOnOff(pdot11Obj
, mRadioOn
);
777 BOOLEAN
zd_ProbeReq(void)
780 //FPRINT("zd_ProbeReq");
782 if ((signal
= allocSignal()) == NULL
){
786 signal
->id
= SIG_PROBE_REQ
;
787 signal
->block
= BLOCK_SYNCH
;
788 sigEnque(pMgtQ
, (signal
));
793 BOOLEAN
zd_ScanReq(void)
796 if ((signal
= allocSignal()) == NULL
){
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
));
810 void *reg
=pdot11Obj
->reg
;
811 if (mBssType
== AP_BSS
)
812 pdot11Obj
->SetReg(reg
, ZD_Rx_Filter
, AP_RX_FILTER
);
814 pdot11Obj
->SetReg(reg
, ZD_Rx_Filter
, STA_RX_FILTER
);
816 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
817 HW_SetRfChannel(pdot11Obj
, mRfChannel
, 1,mMacMode
);
821 pdot11Obj
->ConfigFlag
&= ((~ACTIVE_CHANNEL_SCAN_SET
) & (~JUST_CHANNEL_SCAN
));
825 void *reg
=pdot11Obj
->reg
;
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
);
837 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
838 HW_SetRfChannel(pdot11Obj
,dot11A_Channel
[channel
-1],1 ,mMacMode
);
847 BOOLEAN
zd_CmdProbeReq(U8 bWithSSID
)
849 void *reg
= pdot11Obj
->reg
;
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
;
860 pdot11Obj
->bChScanning
=1;
861 if(pdot11Obj
->bDeviceInSleep
)
863 printk("In SLEEEEEEEEEEEEEEEEEEEEEP @ %s\n", __FUNCTION__
);
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
;
875 if(mMacMode
!= PURE_A_MODE
) {
876 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
877 HW_SetRfChannel(pdot11Obj
, CurrScanCH
, 1,mMacMode
);
880 // printk("HW_SetRfChannel:%s(%d)\n",__FILE__,__LINE__);
881 HW_SetRfChannel(pdot11Obj
, dot11A_Channel
[CurrScanCH
-1], 1,mMacMode
);
886 if (mRequestFlag
& CHANNEL_SCAN_SET
)
887 mRequestFlag
&= ~CHANNEL_SCAN_SET
;
889 //pdot11Obj->bChScanning = 1;
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
);
904 pdot11Obj
->SetReg(reg
, ZD_CAM_MODE
, CAM_IBSS
);
905 if (mBssType
== PSEUDO_IBSS
){
906 zd_PseudoIbssConnect();
911 pdot11Obj
->ConfigFlag
|= SCAN_AND_CONNECT_SET
;
912 mRequestFlag
|= CHANNEL_SCAN_SET
;
919 BOOLEAN
zd_CmdDisasoc(MacAddr_t
*sta
, U8 rCode
)
922 //FPRINT("zd_CmdDisasoc");
927 if ((signal
= allocSignal()) == NULL
)
930 signal
->id
= SIG_DIASSOC_REQ
;
931 signal
->block
= BLOCK_ASOC
;
932 if (mBssType
== INFRASTRUCTURE_BSS
){
933 memcpy(&signal
->frmInfo
.Sta
, (U8
*)&mBssId
, 6);
936 memcpy(&signal
->frmInfo
.Sta
, sta
, 6);
938 signal
->frmInfo
.rCode
= (ReasonCode
)rCode
;
939 sigEnque(pMgtQ
, (signal
));
944 BOOLEAN
zd_CmdDeauth(MacAddr_t
*sta
, U8 rCode
)
948 if ((signal
= allocSignal()) == NULL
)
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
));
960 BOOLEAN
zd_PassiveScan(void)
962 void *reg
= pdot11Obj
->reg
;
964 //FPRINT("zd_PassiveScan");
966 if (pdot11Obj
->ConfigFlag
& PASSIVE_CHANNEL_SCAN_SET
)
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
);
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
);
985 BOOLEAN
zd_DisasocAll(U8 rCode
)
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
);
999 else if (mBssType
== INFRASTRUCTURE_BSS
){
1001 zd_CmdDisasoc(&mBssId
, rCode
);
1007 BOOLEAN
zd_ChooseAP(BOOLEAN bUseBssid
)
1011 U16 quality
= 10000;
1012 BOOLEAN found
= FALSE
;
1015 for (i
=0; i
<mBssCnt
; i
++)
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);
1027 cap
= mBssInfo
[i
].cap
;
1028 if ((memcmp(&dot11DesiredSsid
, &mBssInfo
[i
].ssid
, dot11DesiredSsid
.buf
[1]+2) == 0)
1029 || (!mProbeWithSsid
) ) {
1033 else if ((mMacMode
== PURE_B_MODE
) && (mBssInfo
[i
].apMode
== PURE_G_AP
))
1035 else if ((mMacMode
== PURE_B_MODE
) && (mBssInfo
[i
].apMode
== PURE_A_AP
))
1037 else if ((mMacMode
== PURE_G_MODE
) && (mBssInfo
[i
].apMode
== PURE_B_AP
))
1039 else if ((mMacMode
== PURE_G_MODE
) && (mBssInfo
[i
].apMode
== PURE_A_AP
))
1042 else if ((mMacMode
== PURE_A_MODE
) && (mBssInfo
[i
].apMode
!= PURE_A_AP
))
1045 else if ((mMacMode
== MIXED_MODE
) && (mBssInfo
[i
].apMode
== PURE_A_AP
))
1050 //check capability ...
1051 if (cap
& CAP_PRIVACY
)
1053 if (!mPrivacyInvoked
)
1058 if (mPrivacyInvoked
)
1064 if (!pdot11Obj
->IsUSB2_0
)
1066 if (mBssInfo
[i
].apMode
== PURE_G_AP
)
1074 if (mBssInfo
[i
].signalQuality
< quality
)
1076 quality
= mBssInfo
[i
].signalQuality
;
1078 //FPRINT_V("cap", cap);
1089 if (mBssIndex
< mBssCnt
){
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
;
1100 //printk(KERN_ERR "****** Can't find desiredSSID:");
1101 //for (i=0; i<dot11DesiredSsid.buf[1]; i++) {
1102 // printk("%c", dot11DesiredSsid.buf[2+i]);
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]);
1116 BOOLEAN
zd_InfraConnect(U8 index
)
1119 struct zd1205_private
*macp
= (struct zd1205_private
*)g_dev
->priv
;
1122 Element
*pSsid
= NULL
;
1124 BOOLEAN bChooseAPResult
;
1125 void *reg
= pdot11Obj
->reg
;
1126 //FPRINT("zd_InfraConnect");
1130 if ((signal
= allocSignal()) == NULL
)
1132 if(mCounterMeasureState
) {
1133 mRequestFlag
&= ~BSS_CONNECT_SET
;
1137 // look up global scan result table according to desired ssid,
1138 // because mBssInfo order may be different from macp->BSSInfo[].
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)
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.
1166 return FALSE
; // The index exceed mBssInfo[].
1171 //printk(KERN_ERR "Desired SSID found in location %d\n",mBssIndex);
1176 if(pdot11Obj
->bDeviceInSleep
)
1178 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
1183 tmpvalue
= pdot11Obj
->GetReg(reg
, ZD_BCNInterval
);
1184 tmpvalue
&= ~BIT_25
;
1185 pdot11Obj
->SetReg(reg
, ZD_BCNInterval
, tmpvalue
);
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);
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
);
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
;
1245 BOOLEAN
zd_IbssConnect(void)
1247 struct zd1205_private
*macp
=g_dev
->priv
;
1250 BOOLEAN bBSSFound
= FALSE
;
1252 BssInfo_t
*pBssInfo
;
1253 void *reg
= pdot11Obj
->reg
;
1256 //FPRINT("zd_IbssConnect");
1258 pdot11Obj
->SetReg(reg
, ZD_CWmin_CWmax
, CW_NORMAL_SLOT
);
1259 // not to use short slot time
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
;
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;
1284 if(pdot11Obj
->bDeviceInSleep
)
1286 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
1290 tmpvalue
= pdot11Obj
->GetReg(reg
, ZD_BCNInterval
);
1292 pdot11Obj
->SetReg(reg
, ZD_BCNInterval
, tmpvalue
);
1295 //macp->PwrState = CAM;
1297 if(pdot11Obj
->bDeviceInSleep
)
1299 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
1303 tmpvalue
= pdot11Obj
->GetReg(reg
, ZD_BCNInterval
);
1304 tmpvalue
&= ~BIT_26
;
1305 pdot11Obj
->SetReg(reg
, ZD_BCNInterval
, tmpvalue
);
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){
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);
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]);
1345 ChangeMacMode(MIXED_MODE, pBssInfo->Phpm.buf[2]);
1348 ChangeMacMode(macp
->cardSetting
.MacMode
, pBssInfo
->Phpm
.buf
[2]);
1352 zd1205_SetRatesInfo(macp
);
1353 mMacMode
= macp
->cardSetting
.MacMode
;
1354 mRfChannel
= macp
->cardSetting
.Channel
;
1355 mPhpm
.buf
[0] = EID_DSPARMS
;
1357 mPhpm
.buf
[2] = mRfChannel
;
1359 // printk("Ibss Join, MAC_MODE:%d, CHANNEL:%d\n", mMacMode,mRfChannel);
1361 HW_SetRfChannel(pdot11Obj
, mRfChannel
, 1, mMacMode
);
1362 //FPRINT_V("mRfChannel", mRfChannel);
1364 //update beacon interval
1366 mBeaconPeriod = pBssInfo->bcnInterval; //MZCai
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);
1379 printk("Ibss Join, MAC_MODE:%d, CHANNEL:%d\n", mMacMode
,mRfChannel
);
1380 mBeaconPeriod
= pBssInfo
->bcnInterval
; //MZCai
1381 HW_UpdateBcnInterval(pdot11Obj
, mBeaconPeriod
);
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);
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);
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);
1413 HW_EnableBeacon(pdot11Obj
, mBeaconPeriod
, 0, INDEPENDENT_BSS
);
1414 HW_RadioOnOff(pdot11Obj
, mRadioOn
);
1415 mRequestFlag
&= ~IBSS_CONNECT_SET
;
1417 memcpy(&pdot11Obj
->CurrSsid
[0], (U8
*)&mSsid
, mSsid
.buf
[1]+2);
1418 pdot11Obj
->StatusNotify(STA_ASSOCIATED
, (U8
*)&mBssId
);
1423 if (!(pdot11Obj
->ConfigFlag
& IBSS_CHANNEL_SCAN_SET
)){
1424 pdot11Obj
->ConfigFlag
|= IBSS_CHANNEL_SCAN_SET
;
1427 /*=====prince delete
1434 if(pdot11Obj
->bDeviceInSleep
)
1436 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
1440 //FPRINT("IBSS not found, create it !!!");
1441 /****************************************************/
1442 /* We generate an IBSS */
1443 /****************************************************/
1444 seed
= pdot11Obj
->GetReg(reg
, ZD_TSF_LowPart
);
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);
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
;
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);
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);
1486 //update ATIM Window
1487 HW_UpdateATIMWindow(pdot11Obj
, mATIMWindow
);
1488 //FPRINT_V("mATIMWindow", mATIMWindow);
1491 HW_EnableBeacon(pdot11Obj
, mBeaconPeriod
, 0, INDEPENDENT_BSS
);
1492 HW_RadioOnOff(pdot11Obj
, mRadioOn
);
1493 mRequestFlag
&= ~IBSS_CONNECT_SET
;
1495 memcpy(&pdot11Obj
->CurrSsid
[0], (U8
*)&mSsid
, mSsid
.buf
[1]+2);
1496 pdot11Obj
->StatusNotify(STA_ASSOCIATED
, (U8
*)&mBssId
);
1502 void zd_ResetDevice(void)
1504 U16 BeaconInterval
= 0x2;
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.
1512 i_state
= pdot11Obj
->EnterCS();
1515 if(pdot11Obj
->bDeviceInSleep
)
1517 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
1521 tmpvalue
= pdot11Obj
->GetReg(reg
, ZD_PS_Ctrl
);
1522 pdot11Obj
->SetReg(reg
, ZD_PS_Ctrl
, (tmpvalue
| BIT_0
));
1523 pdot11Obj
->bDeviceInSleep
= 1;
1526 pdot11Obj
->ExitCS(i_state
);
1527 // Delay 1ms to ensure device had been reset
1528 pdot11Obj
->DelayUs(1000);
1533 BOOLEAN
zd_PseudoIbssConnect(void)
1535 void *reg
= pdot11Obj
->reg
;
1537 memset(IBSS_BSSID
, 0, 6);
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);
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
);
1553 pdot11Obj
->StatusNotify(STA_ASSOCIATED
, (U8
*)IBSS_BSSID
);
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();
1579 BOOLEAN
zd_CmdDisConnect(void)
1582 mRequestFlag
|= DIS_CONNECT_SET
;
1588 BOOLEAN
zd_CmdRoaming(void)
1590 if ((mRequestFlag
& (ROAMING_SET
| CHANNEL_SCAN_SET
)) || pdot11Obj
->bChScanning
|| (pdot11Obj
->ConfigFlag
& SCAN_AND_CONNECT_SET
))
1596 if (mBssType
== INDEPENDENT_BSS
)
1597 mRequestFlag
|= CHANNEL_SCAN_SET
;
1599 mRequestFlag
|= ROAMING_SET
;
1606 BOOLEAN
zd_CmdFlushQ(void)
1608 if (pdot11Obj
->QueueFlag
& TX_QUEUE_SET
){
1611 else if (pdot11Obj
->QueueFlag
& MGT_QUEUE_SET
){
1614 else if (pdot11Obj
->QueueFlag
& AWAKE_QUEUE_SET
){
1621 BOOLEAN
zd_CmdProcess(U16 CmdId
, void *parm1
, U32 parm2
)
1623 BOOLEAN status
= TRUE
;
1626 case CMD_RESET_80211
:
1627 status
= zd_Reset80211((zd_80211Obj_t
*)parm1
);
1631 if (mBssType
== AP_BSS
)
1632 status
= zd_StartAP();
1635 if ((pdot11Obj
->ConfigFlag
& SCAN_AND_CONNECT_SET
)||(mRequestFlag
& CHANNEL_SCAN_SET
))
1637 // printk("Scan and connect is underGoing\n");
1640 else if (!mIfaceOpened
)
1642 status
= zd_StartSTA(1);
1643 mIfaceOpened
= TRUE
;
1647 pdot11Obj
->ConfigFlag
|= SCAN_AND_CONNECT_SET
;
1654 case CMD_DISASOC
: //IAPP cth
1655 status
= zd_CmdDisasoc((MacAddr_t
*)parm1
, (U8
)parm2
);
1658 case CMD_DEAUTH
://MAC filter cth
1659 status
= zd_CmdDeauth((MacAddr_t
*)parm1
, (U8
)parm2
);
1663 //PSDEBUG("CMD_PS_POLL");
1664 status
= zd_HandlePsPoll((U8
*)parm1
);
1667 case CMD_PASSIVE_SCAN
:
1668 status
= zd_PassiveScan();
1671 case CMD_DISASOC_ALL
:
1672 status
= zd_DisasocAll((U8
)parm2
);
1677 U8
*pBsstype
=(U8
*)parm1
;
1678 status
= zd_CmdConnect((U8
)parm2
,*pBsstype
);
1683 //FPRINT("CMD_PROBE_REQ");
1684 status
= zd_CmdProbeReq((U8
)parm2
);
1685 pdot11Obj
->ConfigFlag
|= JUST_CHANNEL_SCAN
;
1688 case CMD_DIS_CONNECT
:
1689 status
= zd_CmdDisConnect();
1692 case CMD_FLUSH_QUEUE
:
1693 status
= zd_CmdFlushQ();
1697 status
= zd_CmdRoaming();
1708 //Event Nofify Functions
1709 void zd_NextBcn(void)
1712 struct zd1205_private
*macp
= g_dev
->priv
;
1713 card_Setting_t
*pSetting
= &macp
->cardSetting
;
1716 if (mBssType
== AP_BSS
){
1717 if (mDtimCount
== 0)
1718 mDtimCount
= mDtimPeriod
;
1725 pdot11Obj
->QueueFlag
|= TX_QUEUE_SET
;
1727 /*==prince add begin
1728 if( mBssType == INDEPENDENT_BSS )
1730 if ( mMacMode == PURE_A_MODE )
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====*/
1749 void zd_DtimNotify(void)
1755 extern BOOLEAN
Tchal_WaitChalRsp(Signal_t
*signal
);
1756 void zd_SendTChalMsg(void)
1758 Tchal_WaitChalRsp(NULL
);
1762 extern BOOLEAN
AuthTimeOut(Signal_t
*signal
);
1763 void zd_SendTAuthMsg(void)
1769 extern BOOLEAN
AsocTimeOut(Signal_t
*signal
);
1770 void zd_SendTAsocMsg(void)
1777 void zd_SwitchNextCH(void)
1779 void *reg
= pdot11Obj
->reg
;
1781 struct zd1205_private
*macp
= g_dev
->priv
;
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.
1801 if (mBssType
== AP_BSS
)
1802 pdot11Obj
->SetReg(reg
, ZD_Rx_Filter
, AP_RX_FILTER
);
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;
1819 pdot11Obj
->bChScanning
= 0;
1822 if (pdot11Obj
->ConfigFlag
& ACTIVE_CHANNEL_SCAN_SET
)
1825 printk("\nSSID BSSID CH Signal Mode Basic-Rates Ext-Rates b/g AP");
1826 printk("\n------------------------------------------------------------------------------------");
1827 for (i
=0; i
<mBssNum
; i
++)
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
++) {
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
);
1856 printk(" Infra, W");
1859 printk(" Ad_Hoc,W");
1867 for (j
=0; j
<mBssInfo
[i
].supRates
.buf
[1]; j
++) {
1868 printk(" %x", mBssInfo
[i
].supRates
.buf
[2+j
]);
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
)
1878 else if (mBssInfo
[i
].apMode
== PURE_G_AP
)
1880 else if (mBssInfo
[i
].apMode
== MIXED_AP
)
1883 else if (mBssInfo
[i
].apMode
== PURE_A_AP
)
1891 FPRINT("****** Scan Finished ******");
1893 pdot11Obj
->ConfigFlag
&= ~ACTIVE_CHANNEL_SCAN_SET
;
1895 }//End of ACTIVE_CHANNEL_SCAN_SET
1897 if (pdot11Obj
->ConfigFlag
& JUST_CHANNEL_SCAN
){
1898 pdot11Obj
->ConfigFlag
&= ~JUST_CHANNEL_SCAN
;
1902 mMacMode
= initMAC_Mode
;
1903 HW_SetRfChannel(pdot11Obj
, mRfChannel
, 1, initMAC_Mode
);
1908 if (mBssType
== INFRASTRUCTURE_BSS
)
1910 zd_InfraConnect(mBssNum
);
1915 else if (mBssType
== INDEPENDENT_BSS
)
1919 if (pdot11Obj
->ConfigFlag
& SCAN_AND_CONNECT_SET
)
1921 pdot11Obj
->ConfigFlag
&= ~SCAN_AND_CONNECT_SET
;
1924 initMAC_Mode
= 0xff;
1927 macp
->CurrScanCH
= CurrScanCH
;
1931 }//End of (CurrentScannedChannel > MAX_CHANNEL_ALLOW)
1936 macp
->CurrScanCH
= CurrScanCH
;
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
) {
1953 mMacMode = PURE_A_MODE;
1955 ChangeMacMode(PURE_A_MODE,dot11A_Channel[CurrScanCH-1]);
1956 pdot11Obj->DelayUs(1000);
1957 HW_SetRfChannel(pdot11Obj, dot11A_Channel[CurrScanCH-1],0,mMacMode);
1960 //===prince add begin
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
);
1985 else if(ScanAround
< 1 &&PURE_A_MODE
== LastScanMacMode
&& CurrScanCH
> dot11A_Channel_Amount
- 1){
1989 mMacMode = MIXED_MODE;
1990 ChangeMacMode(MIXED_MODE, CurrScanCH);
1991 pdot11Obj->DelayUs(1000);
1992 HW_SetRfChannel(pdot11Obj, CurrScanCH, 0,mMacMode);
1994 //===prince add begin
1996 if ( macp
->cardSetting
.BssType
== INFRASTRUCTURE_BSS
)
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
)
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
);
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
)
2031 void zd_UpdateCurrTxRate(U8 rate
, U16 aid
)
2034 if (mBssType
== INFRASTRUCTURE_BSS
){
2035 pHash
= sstByAid
[0];
2036 pHash
->CurrTxRate
= rate
;
2040 pHash
= sstByAid
[aid
];
2042 pHash
->CurrTxRate
= rate
;
2044 if (rate
< pHash
->CurrTxRate
){ //Retry Failed happened
2045 pHash
->FailedFrames
++;
2046 //FPRINT_V("FailedFrames", pHash->FailedFrames);
2053 void zd_EnableProtection(U8 protect
)
2056 void *reg
= pdot11Obj
->reg
;
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__
);
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
);
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
;
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);
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);
2103 pdot11Obj
->SetReg(reg
, ZD_RTS_CTS_Rate
, 0x30000);
2107 void zd_EnableShortSlot(U8 slot
)
2109 void *reg
= pdot11Obj
->reg
;
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
);
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
;
2133 void zd_EventNotify(U16 EventId
, U32 parm1
, U32 parm2
, U32 parm3
)
2135 //struct zd1205_private *macp = g_dev->priv;
2143 case EVENT_DTIM_NOTIFY
:
2147 case EVENT_TX_COMPLETE
:
2148 TxCompleted(parm1
, (U8
)parm2
, (U16
)parm3
);
2151 case EVENT_TCHAL_TIMEOUT
:
2155 case EVENT_SCAN_TIMEOUT
:
2159 case EVENT_UPDATE_TX_RATE
:
2160 zd_UpdateCurrTxRate((U8
)parm1
, (U16
)parm2
);
2163 case EVENT_SW_RESET
:
2167 case EVENT_BUF_RELEASE
:
2168 zd_Release_80211_Buffer();
2171 case EVENT_AUTH_TIMEOUT
:
2175 case EVENT_ASOC_TIMEOUT
:
2179 case EVENT_PS_CHANGE
:
2180 zd_PsChange((U8
)parm1
);
2183 case EVENT_MORE_DATA
:
2184 mRequestFlag
|= PS_POLL_SET
;
2187 case EVENT_ENABLE_PROTECTION
:
2188 zd_EnableProtection((U8
)parm1
);
2191 case EVENT_ENABLE_BARKER
:
2192 zd_EnableBarker((U8
)parm1
);
2195 case EVENT_SHORT_SLOT
:
2196 zd_EnableShortSlot((U8
)parm1
);
2206 BOOLEAN
zd_CleanupTxQ(void)
2208 //FPRINT("*****zd_CleanupTxQ*****");
2210 int CleanResult
= 1;
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__
);
2220 CleanResult
= CleanupTxQ();
2224 pdot11Obj
->QueueFlag
&= ~TX_QUEUE_SET
;
2231 BOOLEAN
zd_CleanupAwakeQ(void)
2233 //PSDEBUG("*****zd_CleanupAwakeQ*****");
2237 // To prevent unknown reason that can't clean Awake Queue
2238 if(loopCheck
++ > 100)
2240 printk("infinite loop occurs in %s\n", __FUNCTION__
);
2248 pdot11Obj
->QueueFlag
&= ~AWAKE_QUEUE_SET
;
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
);
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
){
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);
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);
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};
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
){
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
;
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
;
2403 HW_RadioOnOff(pdot11Obj
, mRadioOn
);
2406 if (mRfChannel
!= pSetting
->Channel
){
2407 mRfChannel
= pSetting
->Channel
;
2408 mPhpm
.buf
[0] = EID_DSPARMS
;
2410 mPhpm
.buf
[2] = mRfChannel
;
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
;
2429 mCap
|= CAP_SHORT_PREAMBLE
;
2431 mCap
&= ~CAP_SHORT_PREAMBLE
;
2433 mPrivacyInvoked
= pSetting
->EncryOnOff
;
2434 if (pSetting
->DynKeyMode
> 0)
2435 mPrivacyInvoked
= TRUE
;
2437 if (mPrivacyInvoked
)
2438 mCap
|= CAP_PRIVACY
;
2440 mCap
&= ~CAP_PRIVACY
;
2443 if ( memcmp( &dot11DesiredSsid
, pSetting
->Info_SSID
,36) !=0 )
2447 memcpy(&dot11DesiredSsid
, pSetting
->Info_SSID
, pSetting
->Info_SSID
[1]+2);
2449 if (dot11DesiredSsid
.buf
[1] == 0)
2450 mProbeWithSsid
= FALSE
;
2452 mProbeWithSsid
= TRUE
;
2453 //mProbeWithSsid = FALSE; //debug for ANY connection
2455 if ((pSetting
->BssType
== INFRASTRUCTURE_BSS
) || (pSetting
->BssType
== INDEPENDENT_BSS
)) {
2457 // if (memcmp(&mSsid, &dot11DesiredSsid, dot11DesiredSsid.buf[1]+2) != 0 ){
2462 if (pSetting
->BssType
== INDEPENDENT_BSS
){
2463 memcpy(&mSsid
, &dot11DesiredSsid
, dot11DesiredSsid
.buf
[1]+2);
2464 mATIMWindow
= pSetting
->ATIMWindow
;
2469 mHiddenSSID
= pSetting
->HiddenSSID
;
2471 mSsid
.buf
[0] = EID_SSID
;
2476 memcpy(&mBrates
, pSetting
->Info_SupportedRates
, pSetting
->Info_SupportedRates
[1]+2);
2480 pdot11Obj
->SetReg(reg
, ZD_BasicRateTbl
, 0);
2482 HW_SetSupportedRate(pdot11Obj
, (U8
*)&mBrates
);
2486 if (pSetting
->MacMode
!= PURE_B_MODE
){
2487 if (pSetting
->ShortSlotTime
){
2488 pdot11Obj
->ConfigFlag
|= SHORT_SLOT_TIME_SET
;
2489 mCap
|= CAP_SHORT_SLOT_TIME
;
2492 pdot11Obj
->ConfigFlag
&= ~SHORT_SLOT_TIME_SET
;
2493 mCap
&= ~CAP_SHORT_SLOT_TIME
;
2497 if(PURE_A_MODE
!= pSetting
->MacMode
) {
2498 memcpy(&mExtRates
, pSetting
->Ext_SupportedRates
, pSetting
->Ext_SupportedRates
[1]+2);
2500 HW_SetSupportedRate(pdot11Obj
, (U8
*)&mExtRates
);
2508 if (mMacMode
!= pSetting
->MacMode
) { //MacMode changed
2513 mMacMode
= pSetting
->MacMode
;
2516 memcpy((U8
*)&dot11MacAddress
, pSetting
->MacAddr
, 6);
2519 if ( memcmp( &mKeyVector
[0][0], &pSetting
->keyVector
[0][0],sizeof(mKeyVector
) ) != 0 )
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
);
2539 memset(&mWPAIe
.buf
[0], 0, sizeof(mWPAIe
));
2544 mOperationMode
= pSetting
->OperationMode
;
2547 //HW_CAM_ResetRollTbl(pdot11Obj);
2548 if ((mOperationMode
== CAM_AP_VAP
) || (mOperationMode
== CAM_AP_CLIENT
)){
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);
2565 {// Only clear all keys in the first time.
2566 HW_CAM_ResetRollTbl(pdot11Obj
);
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
2583 zd_CmdProcess(CMD_DISASOC_ALL
, 0, ZD_UNSPEC_REASON
);
2589 mErp
.buf
[2] = 0; //reset erp info
2591 if ((mCap
& CAP_SHORT_PREAMBLE
) == 0){
2592 mErp
.buf
[2] |= BARKER_PREAMBLE
;
2594 if(pdot11Obj
->bDeviceInSleep
)
2596 printk("In SLLLLLLLLLLLLLLLLLLP @ %s\n", __FUNCTION__
);
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
);
2608 pdot11Obj
->ConfigFlag
&= ~ENABLE_PROTECTION_SET
;
2610 if (pSetting
->BssType
== INDEPENDENT_BSS
){
2611 if (mMacMode
== PURE_G_MODE
)
2614 mErp
.buf
[2] = (NON_ERP_PRESENT
| USE_PROTECTION
| BARKER_PREAMBLE
);
2619 //if (mBssType != pSetting->BssType){
2620 if (mBssType
!= pSetting
->BssType
)
2621 //if (pSetting->BssType != INFRASTRUCTURE_BSS)
2625 mBssType
= pSetting
->BssType
;
2626 if (pSetting
->BssType
== AP_BSS
){
2635 //for (i=0; i<(MAX_AID+1); i++)
2636 //CleanupHash(sstByAid[i]);
2643 mBssType
= pSetting
->BssType
;
2644 pdot11Obj
->BssType
= mBssType
;
2648 if (pSetting
->BssType
== INFRASTRUCTURE_BSS
)
2651 pdot11Obj
->ConfigFlag
|= SCAN_AND_CONNECT_SET
;
2652 if (pSetting
->ap_scan
== 1)
2654 ret
= zd_ChooseAP(1); // Choose AP by dot11DesiredBssid.
2657 ret
= zd_ChooseAP(0);
2661 zd_StartSTA(0);//ReScan all channels to find the selected BSS.
2668 printk("Call StartSTA(IBSS or AP)\n");
2672 else if (pSetting
->BssType
== INDEPENDENT_BSS
)
2675 printk("Call StartSTA(IBSS or AP)\n");
2677 else if (pSetting
->BssType
== AP_BSS
)
2681 printk("Call StartAP\n");
2694 void zd_PsPoll(void)
2697 FrmDesc_t
*pfrmDesc
;
2699 //FPRINT("zd_PsPoll");
2701 if ((signal
= allocSignal()) == NULL
){
2705 pfrmDesc
= allocFdesc();
2711 sendPsPollFrame(signal
, pfrmDesc
, &mBssId
, mAid
);
2712 mRequestFlag
&= ~PS_POLL_SET
;
2716 void zd_NullData(void)
2719 FrmDesc_t
*pfrmDesc
;
2721 //FPRINT("zd_NullData");
2723 if ((signal
= allocSignal()) == NULL
){
2727 pfrmDesc
= allocFdesc();
2733 sendNullDataFrame(signal
, pfrmDesc
, &mBssId
);
2734 mRequestFlag
&= ~PS_CHANGE_SET
;
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;
2749 zd_CmdProbeReq((U8)mProbeWithSsid);
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
){
2769 FPRINT("DIS_CONNECT_SET");
2774 if (mRequestFlag
& ROAMING_SET
){
2776 FPRINT("ROAMING_SET");
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
);
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
);
2797 if (mRequestFlag
& CONNECT_TOUT_SET
){
2798 //FPRINT("CONNECT_TOUT_SET");
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
;
2809 mSsid
.buf
[1] = 0; //reset mSsid
2813 FPRINT("Connect Timeout, Re-Connect...");
2814 zd_InfraConnect(mBssIndex
);
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
){
2829 if (mRequestFlag
& PS_CHANGE_SET
){
2834 if (mRequestFlag
& IBSS_CONNECT_SET
){
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
;
2853 while((signal
= sigDeque(&mgtQ
)) != NULL
){
2857 printk("We are trapped in %s\n", __FUNCTION__
);
2858 sigEnque(&mgtQ
, signal
);
2861 switch(signal
->block
){
2863 ret
= SynchEntry(signal
);
2866 case BLOCK_AUTH_REQ
:
2867 ret
= AuthReqEntry(signal
);
2870 case BLOCK_AUTH_RSP
:
2871 ret
= AuthRspEntry(signal
);
2875 ret
= AsocEntry(signal
);
2884 pdot11Obj
->ReleaseBuffer(signal
->buf
);
2889 pdot11Obj
->QueueFlag
&= ~MGT_QUEUE_SET
;
2892 U8
zd_CheckTotalQueCnt(void)
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
);
2911 void zd_RateAdaption(void)
2922 //For STA, it do RateAdaption with AP only
2923 //For Others, with Associated STAs
2924 if(INFRASTRUCTURE_BSS
== mBssType
)
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
];
2939 SucessFrmCnt
= pHash
->SuccessFrames
;
2940 FailFmrCnt
= pHash
->FailedFrames
;
2942 //FPRINT_V("Aid", i);
2944 if (SucessFrmCnt
+ FailFmrCnt
< 20)
2946 //FPRINT(" FmrCnt < 20");
2950 if ((SucessFrmCnt
) && (FailFmrCnt
== 0))
2952 pHash
->RiseConditionCount
++;
2953 pHash
->DownConditionCount
= 0;
2954 //FPRINT(" FailFmrCnt == 0");
2959 Ratio
= SucessFrmCnt
/ FailFmrCnt
;
2960 if (Ratio
>= 9 && pHash
->CurrTxRate
>= RATE_36M
)
2962 pHash
->RiseConditionCount
++;
2963 pHash
->DownConditionCount
= 0;
2966 else if (Ratio
> LINE1
) //100
2968 //FPRINT(" > LINE1");
2969 if (pHash
->CurrTxRate
> RATE_36M
)
2971 pHash
->RiseConditionCount
= 0;
2972 pHash
->DownConditionCount
++;
2975 else if (pHash
->CurrTxRate
== RATE_36M
)
2977 pHash
->RiseConditionCount
= 0;
2978 pHash
->DownConditionCount
= 0;
2983 pHash
->RiseConditionCount
++;
2984 pHash
->DownConditionCount
= 0;
2990 if (Ratio
>= LINE2
) //10
2992 //FPRINT(" > LINE2");
2993 if (pHash
->CurrTxRate
> RATE_24M
)
2995 pHash
->RiseConditionCount
= 0;
2996 pHash
->DownConditionCount
++;
2999 else if (pHash
->CurrTxRate
== RATE_24M
)
3001 pHash
->RiseConditionCount
= 0;
3002 pHash
->DownConditionCount
= 0;
3007 pHash
->RiseConditionCount
++;
3008 pHash
->DownConditionCount
= 0;
3016 //FPRINT(" > LINE3");
3017 if (pHash
->CurrTxRate
> RATE_18M
)
3019 pHash
->RiseConditionCount
= 0;
3020 pHash
->DownConditionCount
++;
3023 else if (pHash
->CurrTxRate
== RATE_18M
)
3025 pHash
->RiseConditionCount
= 0;
3026 pHash
->DownConditionCount
= 0;
3031 pHash
->RiseConditionCount
++;
3032 pHash
->DownConditionCount
= 0;
3038 //FPRINT(" < LINE3");
3039 pHash
->RiseConditionCount
= 0;
3040 pHash
->DownConditionCount
++;
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
;
3069 pHash
->bJustRiseRate
= FALSE
;
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
3119 void zd_PerSecTimer(void)
3124 if (mBssType
== AP_BSS
){
3125 if (sec
> AGE_HASH_PERIOD
){
3127 void *reg
= pdot11Obj
->reg
;
3129 mZyDasModeClient
= FALSE
;
3130 pdot11Obj
->ConfigFlag
&= ~NON_ERP_PRESENT_SET
;
3131 pdot11Obj
->ConfigFlag
&= ~BARKER_PREAMBLE_SET
;
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__
);
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__
);
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");
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
);
3192 BOOLEAN
zd_QueryStaTable(U8
*sta
, void **ppHash
)
3194 Hash_t
*pHash
= NULL
;
3195 MacAddr_t
*addr
= (MacAddr_t
*) sta
;
3197 pHash
= HashSearch(addr
);
3204 if (pHash
->asoc
== STATION_STATE_ASOC
)
3210 U8
zd_GetBssList(bss_info_t
*pBssList
)
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
;
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
));
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
));
3240 //printk(" [zd_GetBssList] wpa ie len = %d\r\n", mBssInfo[i].WPAIe[1]+2);
3246 U16
zd_AidLookUp(U8
*addr
)
3248 MacAddr_t
*sta
= (MacAddr_t
*)addr
;
3249 return AIdLookup(sta
);
3252 void zd_UpdateIbssInfo(U8
*addr
, U8 tmpMaxRate
, U8 preamble
, U8 erpSta
)
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);
3265 void zd_UpdateIbssInfo(U8
*addr
, U8 tmpMaxRate
, U8 preamble
, U8 erpSta
)
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
);
3280 if (!pHash
->AlreadyIn
)
3284 if (erpSta
== FALSE
)
3290 AssocInfoUpdate((MacAddr_t
*)addr
, MaxRate
, 0, 0, preamble
, erpSta
,0,0,1,0);
3291 //FPRINT_V("MaxRate", MaxRate);
3292 //FPRINT_V("erpSta", erpSta);