MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdpmfilter.c
blob240821f5bafd00407e7a0b1f95dfe462e36e6a08
1 #ifndef __ZDPMFILTER_C__
2 #define __ZDPMFILTER_C__
4 #include "zd80211.h"
5 #include "zd1205.h"
6 #include "zddebug.h"
7 extern struct net_device *g_dev;
9 #define DBG_USE_SERIAL_WRITE 0
10 void AgePsQ(U16 aid);
11 BOOLEAN TxSend(Signal_t *signal, FrmDesc_t *pfrmDesc);
12 #define write_str(a,b)
13 U8 usedID = 0;
14 U8 TimBitMap[(MAX_AID/8)+2];
15 Signal_t *txRequest[BURST_NUM] = { NULL };
16 static BOOLEAN mcBuffered = FALSE;
18 //make tim for beacon frame
19 void mkTim(Element *tim, TrafficMap_t *trf, U8 dtc, U8 dtp, U16 aidLo, U16 aidHi, BOOLEAN bc)
21 int i;
22 U8 *map = (U8*)trf->t;
23 U16 N1 = 0;
24 U16 N2 = 0;
25 U8 index = 0;
27 tim->buf[0] = EID_TIM;
28 tim->buf[2] = dtc;
29 tim->buf[3] = dtp;
31 // Calculate N1
32 for (i=0; i<=(aidHi/8); i++){
33 if (map[i] != 0){
34 break;
38 if (i>0){
39 // N1 is the largest even number
40 N1 = (U16)(i & ~0x01);
43 // Calculate N2
44 for (i=(aidHi/8); i>=0; i--){
45 if (map[i] != 0){
46 break;
50 if (i>0){
51 N2 = (U16)i;
54 // Fill the content
55 if (N2==0){
56 tim->buf[4] = 0;
57 tim->buf[5] = map[0];
58 tim->buf[1] = 4;
60 else{
61 tim->buf[4] = (U8)N1;
62 for (i=N1; i<=N2; i++){
63 tim->buf[5+index++] = map[i];
65 tim->buf[1] = N2-N1+4;
68 if (bc){
69 tim->buf[4] |= 0x01;
74 void TxCompleted(U32 result, U8 retID, U16 aid) //in isr routine
76 Signal_t *signal;
77 FrmInfo_t *pfrmInfo;
78 FrmDesc_t *pfrmDesc;
79 void *buf;
80 Hash_t *pHash = NULL;
81 U8 bIntraBss = 0;
83 #ifdef HOST_IF_USB
84 if ((result != ZD_TX_CONFIRM) && (retID == 0xff)){
85 pHash = sstByAid[aid];
86 if (!pHash)
87 return;
88 else
89 pHash->FailedFrames++;
91 return;
93 #endif
95 signal = txRequest[retID];
96 if (signal == NULL)
98 printk(KERN_ERR "TxCompleted: input signal is NULL\n");
99 return;
101 pfrmInfo = &signal->frmInfo;
102 pfrmDesc = pfrmInfo->frmDesc;
104 buf = signal->buf;
105 if (pfrmDesc)
106 bIntraBss = (pfrmDesc->ConfigSet & INTRA_BSS_SET);
108 //if (aid)
110 pHash = sstByAid[aid];
111 if (!pHash)
112 goto no_rate_info;
114 if (result == ZD_TX_CONFIRM){
115 //for rate adaption
116 pHash->SuccessFrames++;
118 else //retry failed
119 pHash->FailedFrames++;
124 no_rate_info:
125 if (pfrmDesc)
126 freeFdesc(pfrmDesc);
127 pdot11Obj->ReleaseBuffer(buf);
128 freeSignal(signal);
129 txRequest[retID] = NULL;
131 if ((buf) && (!bIntraBss)){ //upper layer data
132 pdot11Obj->TxCompleted();
137 char DbgStr1[]="Tx ProbReq";
138 char DbgStr2[]="Tx Auth";
139 char DbgStr3[]="Tx Data";
140 char DbgStr4[]="msg4";
141 char DbgStr5[]="msg5";
142 char DbgStr6[]="msg6";
143 char DbgStr7[]="msg7";
144 char DbgStr8[]="msg8";
145 char DbgStr9[]="msg9";
146 char DbgStr10[]="msg10";
147 char DbgStr11[]="msg11";
149 char DbgStr12[]="msg12";
150 BOOLEAN TxSend(Signal_t *signal, FrmDesc_t *pfrmDesc)
152 FrmInfo_t *pfrmInfo;
153 U32 XCount = 0;
154 U32 nextBodyLen;
155 fragInfo_t fragInfo;
156 int i;
157 U8 bIntraBss = 0;
158 Frame_t *pf;
159 Frame_t *nextPf;
160 U32 flags;
161 Hash_t *pHash = NULL;
162 U32 *tmpiv = NULL;
163 //U8 WepKeyLen = 0;
164 //U8 *pWepKey = NULL;
165 U8 tmp4pIv[8];
166 U8 *pIv = tmp4pIv;
167 U8 KeyId = 5;
168 U32 iv32 = 0;
169 BOOLEAN bExtIV = FALSE;
170 U8 EncryType;
171 BOOLEAN bGroupAddr = FALSE;
172 U8 bWep = 0;
173 U8 vapId = 0;
174 U8 Num;
175 U8 bDataFrm = signal->bDataFrm;
176 //U8 KeyInstalled = 0;
178 ZDEBUG("TxSend");
181 //txRequest[usedID] = signal;
182 memcpy(fragInfo.CalSwMic, pfrmDesc->CalMIC, MIC_LNG+1);
183 pfrmInfo = &signal->frmInfo;
184 bIntraBss = (pfrmDesc->ConfigSet & INTRA_BSS_SET);
186 pf = pfrmDesc->mpdu;
188 //for PS-POLL handling
189 if (pfrmDesc->ConfigSet & PS_POLL_SET){
190 if(mMacMode != PURE_A_MODE) {
191 fragInfo.rate = RATE_1M;
192 fragInfo.preamble = mPreambleType;
194 else if(mMacMode == PURE_A_MODE) {
195 fragInfo.rate = RATE_6M;
196 fragInfo.preamble = SHORT_PREAMBLE; //802.11A frame must
199 fragInfo.aid = 0;
200 fragInfo.macHdr[0] = &pf->header[0];
201 fragInfo.macBody[0] = pf->body;
202 fragInfo.bodyLen[0] = 0;
203 fragInfo.nextBodyLen[0] = 0;
204 //fragInfo.msgID = usedID;
205 fragInfo.totalFrag = 1;
206 fragInfo.hdrLen = pf->HdrLen;
207 fragInfo.encryType = WEP_NOT_USED;
208 fragInfo.vapId = vapId;
209 fragInfo.bIntraBss = bIntraBss;
210 fragInfo.buf = signal->buf;
211 goto just_send;
214 pHash = pfrmDesc->pHash;
215 bWep = wepBit(pf);
216 EncryType = mKeyFormat;
218 /* if ((pf->header[0] & 0xFC) == 0x40)
219 { //Probe Req, for debugging purpose.
220 if (pf->body[0]==0)
222 if (pf->body[1] == 0)
223 printk(KERN_ERR "Probe Request with Broadcase ssid\n");
224 else
225 printk(KERN_ERR "Probe Request with ssid=%s",&pf->body[2]);
228 else if ((pf->header[0] & 0xFC) == 0xB0)
230 //printk(KERN_ERR "Tx Auth\n");
231 //serial_printf(" Tx Auth\n");
233 else if ((pf->header[0] & 0xFC) == 0x08)
235 //printk(KERN_ERR "Tx Data,keyMode=%d\n",mDynKeyMode);
236 //serial_printf("Tx Data,keyMode=%d\n",mDynKeyMode);
237 } */
238 if (isGroup(addr1(pf))){
239 bGroupAddr = TRUE;
240 fragInfo.rate = pdot11Obj->BasicRate;
241 fragInfo.aid = 0;
242 if(PURE_A_MODE != mMacMode)
243 fragInfo.preamble = 0;
244 else
245 fragInfo.preamble = 1;
247 /*if ((mSwCipher) && (bWep)){
248 if ((mDynKeyMode == DYN_KEY_WEP64) || (mDynKeyMode == DYN_KEY_WEP128)){
249 WepKeyLen = mBcKeyLen;
250 pWepKey = &mBcKeyVector[0];
251 pIv = &mBcIv[1];
252 KeyId = mBcKeyId;
253 tmpiv = (U32 *)mBcIv;
255 }*/ /* The software encryption is always disabled.*/
257 if (bWep){// For 802.1x dynamic key mode
258 if ((mDynKeyMode == DYN_KEY_WEP64) || (mDynKeyMode == DYN_KEY_WEP128)){
259 if (mDynKeyMode == DYN_KEY_WEP64)
260 EncryType = WEP64_USED;
261 else
262 EncryType = WEP128_USED;
263 pIv = &mBcIv[1];
264 KeyId = mBcKeyId;
265 tmpiv = (U32 *)mBcIv;
270 else{ // unicast frame
271 if (!pHash){
272 // Should be Probe Response frame
273 fragInfo.rate = pdot11Obj->BasicRate;
274 //FPRINT_V("pHash = 0; fragInfo.rate", fragInfo.rate);
275 fragInfo.aid = 0;
276 if(mMacMode != PURE_A_MODE)
277 fragInfo.preamble = 0;
278 else
279 fragInfo.preamble = 1;
282 else{
283 fragInfo.rate = pHash->CurrTxRate;
285 //FPRINT_V("pHash != 0 fragInfo.rate", fragInfo.rate);
286 fragInfo.aid = (U16)pHash->aid;
287 fragInfo.preamble = pHash->Preamble;
289 //if (mBssType == AP_BSS)
291 EncryType = pHash->encryMode;
294 //get pairwise key
295 if (bWep)
297 if ((mDynKeyMode == DYN_KEY_WEP64) || (mDynKeyMode == DYN_KEY_WEP128)){
298 pIv = &pHash->wepIv[1];
299 KeyId = pHash->KeyId;
300 tmpiv = (U32 *)pHash->wepIv;
306 if (bWep){
307 if (mDynKeyMode == 0){ // static 4 keys, wep64, 128 or 256
308 pIv = &mWepIv[1];
309 KeyId = mKeyId;
310 tmpiv = (U32 *)mWepIv;
311 EncryType = mKeyFormat;
315 Num = pfrmInfo->fTot;
316 //FPRINT_V("Tx fTot", pfrmInfo->fTot);
317 for (i=0; i<Num; i++){
318 pf = &pfrmDesc->mpdu[i];
319 if (Num == 1)
321 nextBodyLen = 0;
322 if (!bDataFrm)
323 { //Management frame
324 bIntraBss = 0;
325 if (frmType(pf) == ST_PROBE_RSP)
328 U32 loTm, hiTm;
329 HW_GetTsf(pdot11Obj, &loTm, &hiTm);
330 setTs(pf, loTm, hiTm);
334 else
336 if (Num != (i+1))
338 nextPf = &pfrmDesc->mpdu[i+1];
339 nextBodyLen = nextPf->bodyLen;
341 else
343 nextBodyLen = 0;
347 //prepare frag information
348 fragInfo.macHdr[i] = &pf->header[0];
349 fragInfo.macBody[i] = pf->body;
350 fragInfo.bodyLen[i] = pf->bodyLen;
351 fragInfo.nextBodyLen[i] = nextBodyLen;
353 if (bWep)
354 {// Encryption is needed.
355 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
356 {// WPA encryption mode.
357 if (bGroupAddr)
359 if (mGkInstalled)
361 switch(mWpaBcKeyLen)
363 case 32:// Group TKIP
364 mIv16++;
365 if (mIv16 == 0)
366 mIv32++;
367 pIv[0] = Hi8(mIv16);
368 pIv[1] = (Hi8(mIv16) | 0x20) & 0x7f;
369 pIv[2] = Lo8(mIv16);
370 KeyId = mWpaBcKeyId;
371 iv32 = mIv32;
372 bExtIV = TRUE;
373 EncryType = TKIP_USED;
374 break;
375 case 5: // Group WEP64
376 pIv = &mBcIv[1];
377 KeyId = mWpaBcKeyId;
378 tmpiv = (U32 *)mBcIv;
379 EncryType = WEP64_USED;
380 break;
381 case 13: // Group WEP128
382 pIv = &mBcIv[1];
383 KeyId = mWpaBcKeyId;
384 tmpiv = (U32 *)mBcIv;
385 EncryType = WEP128_USED;
386 break;
387 case 16:// Group AES
388 mIv16++;
389 if (mIv16 == 0)
390 mIv32++;
391 pIv[0] = Lo8(mIv16);
392 pIv[1] = Hi8(mIv16);
393 pIv[2] = 0;
394 KeyId = mWpaBcKeyId;
395 iv32 = mIv32;
396 bExtIV = TRUE;
397 EncryType = AES_USED;
398 break;
399 default: // Group key Len error
400 bWep=FALSE;
401 fragInfo.macHdr[i][1] &= ~WEP_BIT;
402 break;
405 else
406 {// Group key was not installed yet.
407 bWep=FALSE;
408 fragInfo.macHdr[i][1] &= ~WEP_BIT;
410 }//endof group frame.
411 else
412 { //unicast
413 //printk(KERN_ERR "send unicast packet,pkeyinstalled:%d\n",pHash->pkInstalled);
414 //KeyInstalled = pHash->pkInstalled;
415 if ((pHash) && (pHash->pkInstalled))
417 pHash->iv16++;
418 if (pHash->iv16 == 0)
419 pHash->iv32++;
420 if (EncryType == TKIP_USED)
422 pIv[0] = Hi8(pHash->iv16);
423 pIv[1] = (Hi8(pHash->iv16) | 0x20) & 0x7f;
424 pIv[2] = Lo8(pHash->iv16);
426 else if (EncryType == AES_USED)
428 pIv[0] = Lo8(pHash->iv16);
429 pIv[1] = Hi8(pHash->iv16);
430 pIv[2] = 0;
432 KeyId = pHash->KeyId;
433 iv32 = pHash->iv32;
434 bExtIV = TRUE;
436 else
437 {// No key has been installed before.
438 bWep=FALSE;
439 fragInfo.macHdr[i][1] &= ~WEP_BIT;
442 } // end of ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
443 fragInfo.macHdr[i][MAC_HDR_LNG] = pIv[0];
444 fragInfo.macHdr[i][MAC_HDR_LNG+1] = pIv[1];
445 fragInfo.macHdr[i][MAC_HDR_LNG+2] = pIv[2];
446 fragInfo.macHdr[i][MAC_HDR_LNG+3] = KeyId << 6;
447 //if (mDynKeyMode != DYN_KEY_TKIP && mDynKeyMode != DYN_KEY_AES)
448 if (EncryType == WEP64_USED || EncryType == WEP128_USED)
449 *tmpiv = (((*tmpiv) & 0x00FFFFFF) + 1) | ((*tmpiv) & 0xFF000000);
451 if (bExtIV){
452 fragInfo.macHdr[i][MAC_HDR_LNG+3] |= 0x20;
453 fragInfo.macHdr[i][MAC_HDR_LNG+4] = (U8)(iv32);
454 fragInfo.macHdr[i][MAC_HDR_LNG+5] = (U8)(iv32 >> 8);
455 fragInfo.macHdr[i][MAC_HDR_LNG+6] = (U8)(iv32 >> 16);
456 fragInfo.macHdr[i][MAC_HDR_LNG+7] = (U8)(iv32 >> 24);
462 //fragInfo.msgID = usedID;
463 fragInfo.bIntraBss = bIntraBss;
464 fragInfo.buf = signal->buf;
465 fragInfo.totalFrag = Num;
466 fragInfo.hdrLen = MAC_HDR_LNG;
468 if (bWep)
470 fragInfo.hdrLen += IV_LNG;
471 if (bExtIV){
472 fragInfo.hdrLen += EIV_LNG;
474 fragInfo.encryType = EncryType;
476 else
477 fragInfo.encryType=WEP_NOT_USED;
479 //if (mAssoc)
480 //FPRINT_V("EncryType", fragInfo.encryType);
481 //fragInfo.vapId = vapId;
483 //if (fragInfo.encryType == TKIP)
485 //fragInfo.bWaitingMIC = pfrmDesc->bWaitingMIC;
486 //fragInfo.bSwCalcMIC = pfrmDesc->bSwCalcMIC;
487 //fragInfo.HwMicPhys = (U32)pfrmDesc->HwMicPhys;
490 just_send:
491 flags = pdot11Obj->EnterCS();
492 // The following 5 lines must be protected by a critical section.
493 fragInfo.msgID = usedID;
494 txRequest[usedID] = signal;
495 #if ZDCONF_LP_SUPPORT == 1
496 memcpy(fragInfo.EthHdr, signal->EthHdr,14);
497 #endif
498 pdot11Obj->SetupNextSend(&fragInfo);
502 XCount++;
503 usedID++;
504 if (usedID > (BURST_NUM -1))
505 usedID = 0;
506 if(XCount > 1000) break;
507 }while(txRequest[usedID] != NULL);
509 if(XCount > 1000 && freeSignalCount != 0 )
511 for(;XCount > 0;XCount--)
512 printk("XCount!!!!\n");
515 pdot11Obj->ExitCS(flags);
517 return FALSE;
520 void FlushQ(SignalQ_t *Q)
522 Signal_t *signal;
523 FrmInfo_t *pfrmInfo;
524 FrmDesc_t *pfrmDesc;
525 int loopCheck = 0;
527 while((signal = sigDeque(Q)) != NULL){
528 // General loop check only. for future hidden bug
529 if(loopCheck++ > 100)
531 printk("infinite loop occurs in %s\n", __FUNCTION__);
532 loopCheck = 0;
533 break;
535 pfrmInfo = &signal->frmInfo;
536 pfrmDesc = pfrmInfo->frmDesc;
537 pdot11Obj->ReleaseBuffer(signal->buf);
538 freeFdesc(pfrmDesc);
539 freeSignal(signal);
544 void TimMapSet(U8 *map, U16 aid, BOOLEAN flag)
546 U8 mask, index;
549 if ((aid == 0) || (aid > MAX_AID))
550 return;
552 index = aid / 8;
553 mask = 0x01 << (aid % 8);
555 if (flag)
556 map[index] |= mask;
557 else
558 map[index] &= ~mask;
563 BOOLEAN CleanupTxQ(void)
565 Signal_t *signal;
566 FrmInfo_t *pfrmInfo;
567 FrmDesc_t *pfrmDesc;
569 //PSDEBUG("CleanupTxQ");
570 if (pTxQ->cnt > 0){
571 signal = pTxQ->first;
572 if (!signal)
573 return FALSE;
575 pfrmInfo = &signal->frmInfo;
576 pfrmDesc = pfrmInfo->frmDesc;
578 if (!pdot11Obj->CheckTCBAvail(pfrmInfo->fTot))
579 return FALSE;
581 signal = sigDeque(pTxQ);
582 goto send_PduReq;
585 return FALSE;
588 send_PduReq:
589 TxSend(signal, pfrmDesc);
590 return TRUE;
595 BOOLEAN CleanupAwakeQ(void)
597 Signal_t *signal;
598 FrmInfo_t *pfrmInfo;
599 FrmDesc_t *pfrmDesc;
601 //PSDEBUG("CleanupAwakeQ");
602 if (pAwakeQ->cnt > 0){
603 signal = pAwakeQ->first;
604 if (!signal)
605 return FALSE;
607 pfrmInfo = &signal->frmInfo;
609 pfrmDesc = pfrmInfo->frmDesc;
610 if (!pdot11Obj->CheckTCBAvail(pfrmInfo->fTot))
611 return FALSE;
613 signal = sigDeque(pAwakeQ);
614 //PSDEBUG("===== Queue out awakeQ");
615 //PSDEBUG_V("pAwakeQ->cnt", pAwakeQ->cnt);
616 goto send_PduReq;
619 return FALSE;
622 send_PduReq:
623 TxSend(signal, pfrmDesc);
624 return TRUE;
628 void AgePsQ(U16 aid)
630 Signal_t *psSignal;
631 U16 interval;
632 FrmDesc_t *pfrmDesc;
633 U32 eol;
634 FrmInfo_t *pfrmInfo;
635 U16 loopCheck = 0;
637 if ((aid == 0) || (aid > MAX_AID)) //Invalid AID
638 return;
641 while (pPsQ[aid]->cnt){
642 // General Loop Check only. For future hidden bug
643 if(loopCheck++ > 100)
645 printk("infinite loop occurs in %s\n", __FUNCTION__);
646 loopCheck = 0;
647 break;
650 interval = sstByAid[aid]->lsInterval;
651 if (interval == 0)
652 interval = 1;
654 psSignal = pPsQ[aid]->first;
656 if (!psSignal)
657 break;
659 pfrmInfo = &psSignal->frmInfo;
660 eol = pfrmInfo->eol;
661 #ifndef HOST_IF_USB
662 if ((HW_GetNow(pdot11Obj) - eol) < (2*interval*mBeaconPeriod*1024)) //us
663 break;
665 if ((HW_GetNow(pdot11Obj) - eol) < (1024*1024)) //us
666 break;
667 #else
668 if ((HW_GetNow(pdot11Obj) - eol) < (2*interval*mBeaconPeriod/10)) //10ms
669 break;
671 if ((HW_GetNow(pdot11Obj) - eol) < (100)) //10ms
672 break;
673 #endif
674 //Data life time-out
675 psSignal = sigDeque(pPsQ[aid]);
676 if (!psSignal)
677 break;
679 PSDEBUG_V("*****Data life time-out, AID", aid);
680 pfrmDesc = pfrmInfo->frmDesc;
682 freeFdesc(pfrmDesc);
683 pdot11Obj->ReleaseBuffer(psSignal->buf);
684 freeSignal(psSignal);
688 if (!pPsQ[aid]->cnt)
689 TimMapSet(TimBitMap, aid, FALSE);
691 return;
695 void PsPolled(MacAddr_t *sta, U16 aid)
697 Signal_t *signal;
698 FrmInfo_t *pfrmInfo;
699 FrmDesc_t *pfrmDesc;
700 Frame_t *frame;
701 int i;
702 U8 Num;
704 //PSDEBUG("PsPolled");
706 signal = sigDeque(pPsQ[aid]);
707 if (!signal){
708 PSDEBUG("No Queue data for PS-POLL!!!");
709 TimMapSet(TimBitMap, aid, FALSE);
710 return;
712 else{
714 PSDEBUG_V("Queue out psQ, AID ", aid);
715 PSDEBUG_V("cnt ", pPsQ[aid]->cnt);
716 pfrmInfo = &signal->frmInfo;
717 pfrmDesc = pfrmInfo->frmDesc;
719 Num = pfrmInfo->fTot;
720 for (i=0; i<Num; i++){
721 frame = &pfrmDesc->mpdu[i];
722 //PSDEBUG_V("pfrmInfo ", (U32)pfrmInfo);
723 //PSDEBUG_V("eol ", (U32)pfrmInfo->eol);
724 PSDEBUG_V("pfrmDesc ", (U32)pfrmDesc);
725 //PSDEBUG_V("frame ", (U32)frame);
726 if (!pPsQ[aid]->cnt){
727 frame->header[1] &= ~MORE_DATA_BIT;
728 PSDEBUG("More bit 0");
730 else {
731 frame->header[1] |= MORE_DATA_BIT;
732 PSDEBUG("More bit 1");
735 PSDEBUG_V("bodyLen ", frame->bodyLen);
739 if (!pdot11Obj->CheckTCBAvail(Num)){
740 PSDEBUG("*****Fail to send out!!!");
741 PSDEBUG_V("Queue in psQ, AID", aid);
742 sigEnqueFirst(pPsQ[aid], signal);
743 return;
745 else
746 sigEnque(pTxQ, signal);
747 return;
752 void StaWakeup(MacAddr_t *sta)
754 U16 aid;
755 Signal_t *signal;
756 U16 loopCheck = 0;
758 aid = AIdLookup(sta);
759 if ((aid == 0) || (aid > MAX_AID))
760 return;
762 while((signal = sigDeque(pPsQ[aid])) != NULL){
763 // General Loop Check only. For future hidden bug
764 if(loopCheck++ > 100)
766 printk("infinite loop occurs in %s\n", __FUNCTION__);
767 loopCheck = 0;
768 break;
771 sigEnque(pTxQ, signal);
776 void InitPMFilterQ(void)
778 U8 i;
779 static BOOLEAN bFirstTime = TRUE;
781 if (bFirstTime){
782 bFirstTime = FALSE;
783 for (i=0; i < MAX_RECORD; i++){
784 pPsQ[i] = &psQ[i];
785 initSigQue(pPsQ[i]);
787 pTxQ = &txQ;
788 pAwakeQ = &awakeQ;
789 initSigQue(pTxQ);
790 initSigQue(pAwakeQ);
792 else{
793 for (i=0; i < MAX_RECORD; i++)
794 FlushQ(pPsQ[i]);
795 FlushQ(pTxQ);
796 FlushQ(pAwakeQ);
799 memset(TimBitMap, 0, sizeof(TimBitMap));
803 void ConfigBcnFIFO(void)
805 int i, j;
806 BOOLEAN bcst = FALSE;
807 struct zd1205_private *macp=g_dev->priv;
808 Signal_t *signal;
809 U8 tim[256];
810 U8 Beacon[256];
811 U16 BcnIndex = 0;
812 U16 Len;
813 U16 loopCheck = 0;
814 static int reCheck = 0;
816 //FPRINT("ConfigBcnFIFO");
818 if(test_and_set_bit(0, &reCheck))
820 printk("Reenter\n");
821 return;
823 if (mBssType == AP_BSS){
824 if (mPsStaCnt > 0) {
825 HW_SetSTA_PS(pdot11Obj, 1);
826 for (i=1; i < (MAX_AID+1); i++){
827 AgePsQ(i);
828 if (pPsQ[i]->cnt){
829 TimMapSet(TimBitMap, i, TRUE);
830 PSDEBUG_V("TimMapSet Aid", i);
834 else{
835 HW_SetSTA_PS(pdot11Obj, 0);
836 //send McQ
837 if (pPsQ[0]->cnt){
838 //General loop check only. For future hidden bug
839 while(1){
840 if(loopCheck++ > 100)
842 printk("infinite loop occurs in %s\n", __FUNCTION__);
843 loopCheck = 0;
844 break;
847 signal = sigDeque(pPsQ[0]);
848 if (!signal)
849 break;
851 sigEnque(pTxQ, signal);
857 /* make beacon frame */
858 /* Frame control */
859 Beacon[BcnIndex++] = 0x80;
860 Beacon[BcnIndex++] = 0x00;
862 /* Duration HMAC will fill this field */
863 Beacon[BcnIndex++] = 0x00;
864 Beacon[BcnIndex++] = 0x00;
866 /* Address1 */
867 Beacon[BcnIndex++] = 0xff;
868 Beacon[BcnIndex++] = 0xff;
869 Beacon[BcnIndex++] = 0xff;
870 Beacon[BcnIndex++] = 0xff;
871 Beacon[BcnIndex++] = 0xff;
872 Beacon[BcnIndex++] = 0xff;
874 /* Address2 */
875 for (j=0; j<6; j++)
876 //Beacon[BcnIndex++] = mBssId.mac[j];
877 Beacon[BcnIndex++] = dot11MacAddress.mac[j];
879 /* Address3 */
880 for (j=0; j<6; j++)
882 Beacon[BcnIndex++] = mBssId.mac[j];
884 /* Sequence control HMAC will fill this field */
885 //Beacon[BcnIndex++] = 0x00;
886 //Beacon[BcnIndex++] = 0x00;
887 BcnIndex += 2;
889 /* Timestamp HMAC will fill this field */
890 //for (j=0; j<8; j++)
891 //Beacon[BcnIndex++] = 0x00;
892 BcnIndex += 8;
894 /* BeaconInterval */
895 Beacon[BcnIndex++] = mBeaconPeriod;
896 Beacon[BcnIndex++] = mBeaconPeriod >> 8;
898 /* Display the Capability */
899 if(pdot11Obj->dbg_cmd & DBG_CMD_BEACON)
900 printk(KERN_ERR "mCap: 0x%04x\n", mCap);
902 /* Capability */
903 Beacon[BcnIndex++] = mCap;
904 Beacon[BcnIndex++] = mCap >> 8;
906 /* SSID */
907 Len = eLen(&mSsid)+2;
908 for (j=0; j<Len; j++)
909 Beacon[BcnIndex++] = mSsid.buf[j];
911 /* Supported rates */
912 Len = eLen(&mBrates)+2;
913 for (j=0; j<Len; j++)
914 Beacon[BcnIndex++] = mBrates.buf[j];
916 /* DS parameter */
917 Beacon[BcnIndex++] = mPhpm.buf[0];
918 Beacon[BcnIndex++] = mPhpm.buf[1];
919 Beacon[BcnIndex++] = mPhpm.buf[2];
921 if (mBssType == INDEPENDENT_BSS){
922 Beacon[BcnIndex++] = EID_IBPARMS;
923 Beacon[BcnIndex++] = 0x2;
924 Beacon[BcnIndex++] = mATIMWindow;
925 Beacon[BcnIndex++] = mATIMWindow >> 8;
928 /* Tim */
929 //if ((mDtimCount == 0) && (pPsQ[0]->cnt > 0)){ //dtim and buffer for mc
930 if (mBssType == AP_BSS){
931 if ((mDtimCount == 0) && mcBuffered){
932 bcst = TRUE;
935 mkTim((Element*)tim, (TrafficMap_t *)&TimBitMap, mDtimCount, mDtimPeriod, 1, MAX_AID, bcst);
936 Len = tim[1]+2;
937 for (j=0; j<Len; j++)
938 Beacon[BcnIndex++] = tim[j];
941 #if defined(OFDM)
942 if (mMacMode != PURE_B_MODE && mMacMode != PURE_A_MODE)
945 //ERP element
947 Beacon[BcnIndex++] = mErp.buf[0];
948 Beacon[BcnIndex++] = mErp.buf[1];
949 Beacon[BcnIndex] = mErp.buf[2];
950 /*if (pdot11Obj->bDisProtection==1)
951 {//Disable protection
952 Beacon[BcnIndex] &= ~USE_PROTECTION;
954 BcnIndex++;
956 //Extended supported rates
957 Len = mExtRates.buf[1]+2;;
958 for (j=0; j<Len; j++)
959 Beacon[BcnIndex++] = mExtRates.buf[j];
961 #endif
963 //WPA IE
964 /* if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES)){
965 Len = mWPAIe.buf[1]+2;
966 for (j=0; j<Len; j++)
967 Beacon[BcnIndex++] = mWPAIe.buf[j];
968 } */
969 Len = macp->cardSetting.WPAIeLen;
970 if (Len)
972 memcpy(&Beacon[BcnIndex], &mWPAIe, Len);
973 BcnIndex += Len;
976 /* CRC32 HMAC will calucate this value */
977 //for (j=0; j<4; j++)
978 // Beacon[BcnIndex++] = 0x00;
979 BcnIndex += 4;
982 HW_SetBeaconFIFO(pdot11Obj, &Beacon[0], BcnIndex);
984 memset(TimBitMap, 0, sizeof(TimBitMap));
985 clear_bit(0, &reCheck);
989 void SendMcPkt(void)
991 Signal_t *signal;
992 U16 loopCheck = 0;
994 while(pPsQ[0]->cnt > 0){
995 //General loop check only. For future hidden bug check
996 if(loopCheck++ > 100)
998 printk("infinite loop occurs in %s\n", __FUNCTION__);
999 loopCheck = 0;
1000 break;
1003 signal = pPsQ[0]->first;
1004 if (!signal)
1005 break;
1007 signal = sigDeque(pPsQ[0]);
1008 //PSDEBUG("Queue in awakeQ");
1009 sigEnque(pAwakeQ, signal);
1010 //PSDEBUG_V("pAwakeQ->cnt", pAwakeQ->cnt);
1013 if (pAwakeQ->cnt > 0){
1014 mcBuffered = TRUE;
1016 else
1017 mcBuffered = FALSE;
1021 void ResetPMFilter(void)
1023 int i;
1025 for (i=0; i<BURST_NUM; i++)
1026 txRequest[i] = NULL;
1028 InitPMFilterQ();
1032 BOOLEAN SendPkt(Signal_t* signal, FrmDesc_t *pfrmDesc, BOOLEAN bImmediate)
1034 FrmInfo_t *pfrmInfo;
1035 Frame_t *frame;
1036 int i;
1037 Hash_t *pHash;
1038 U8 Num;
1040 //PSDEBUG("SendPkt");
1041 pfrmInfo = &signal->frmInfo;
1042 frame = pfrmDesc->mpdu;
1043 pHash = pfrmDesc->pHash;
1044 Num = pfrmInfo->fTot;
1046 if (!signal->bDataFrm) {
1047 //if (!pfrmDesc->bDataFrm){
1048 goto direct_send;
1051 if (!isGroup(addr1(frame))) { //unicast
1052 PsMode dpsm;
1053 U16 aid;
1055 if (mBssType != AP_BSS)
1056 goto direct_send;
1058 //PsInquiry(addr1(frame), &dpsm, &aid);
1059 dpsm = pHash->psm;
1060 aid = pHash->aid;
1062 if ((dpsm == PSMODE_POWER_SAVE) && (aid > 0) && (aid <(MAX_AID+1))) {
1063 AgePsQ(aid);
1065 if (zd_CheckTotalQueCnt() > TXQ_THRESHOLD) {
1066 PSDEBUG("*****Drop PS packet*****");
1067 freeFdesc(pfrmDesc);
1068 pdot11Obj->ReleaseBuffer(signal->buf);
1069 freeSignal(signal);
1070 return FALSE;
1072 else {
1073 //for (i=0; i<Num; i++){
1074 // setMoreData((&pfrmDesc->mpdu[i]), 1);
1075 // pfrmDesc->mpdu[i].header[i] |= MORE_DATA_BIT;
1076 //}
1077 pfrmInfo->eol = HW_GetNow(pdot11Obj); //Set timestamp
1079 sigEnque(pPsQ[aid], signal); //Queue in PS Queue
1080 PSDEBUG_V("Queue in PS Queue, AID ", aid);
1081 PSDEBUG_V("cnt ", pPsQ[aid]->cnt);
1082 //PSDEBUG_V("pfrmInfo ", (U32)pfrmInfo);
1083 //PSDEBUG_V("eol ", (U32)pfrmInfo->eol);
1084 PSDEBUG_V("pfrmDesc ", (U32)pfrmDesc);
1085 //PSDEBUG_V("frame ", (U32)frame);
1086 PSDEBUG_V("bodyLen ", frame->bodyLen);
1087 TimMapSet(TimBitMap, aid, TRUE);
1088 return FALSE;
1091 else {
1092 goto direct_send;
1095 else{ //group address
1096 if ((orderBit(frame) == 0) && (mPsStaCnt > 0)){
1097 if ((zd_CheckTotalQueCnt() > TXQ_THRESHOLD) || (pPsQ[0]->cnt > MCQ_THRESHOLD)){
1098 PSDEBUG("*****Drop MC packet*****");
1099 freeFdesc(pfrmDesc);
1100 pdot11Obj->ReleaseBuffer(signal->buf);
1101 freeSignal(signal);
1102 return FALSE;
1104 else{
1105 for (i=0; i<Num; i++){
1106 pfrmDesc->mpdu[i].header[1] |= MORE_DATA_BIT;
1109 sigEnque(pPsQ[0], signal); // psQ[0] is for mcQ
1110 //PSDEBUG("+++++ Queue in mcQ");
1111 //PSDEBUG_V("mcQ->cnt", pPsQ[0]->cnt);
1112 return FALSE;
1115 else{
1116 goto direct_send;
1121 direct_send:
1122 if (!bImmediate){
1123 sigEnque(pTxQ, signal);
1124 return FALSE;
1126 else{
1127 if (!pdot11Obj->CheckTCBAvail(Num)){
1128 #if 1 //727
1129 freeSignal(signal);
1130 freeFdesc(pfrmDesc);
1131 return TRUE;
1132 #else
1133 sigEnque(pTxQ, signal);
1134 return FALSE;
1135 #endif
1136 //PSDEBUG("Queue in TxQ");
1137 //PSDEBUG_V("Cnt of TxQ", pTxQ->cnt);
1139 return TxSend(signal, pfrmDesc); //14 us
1143 #endif