MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdshared.c
blob494aac614e9470e8b753b3361ef1647d712fce84
1 #ifndef __ZDSHARED_C__
2 #define __ZDSHARED_C__
4 #include "zd80211.h"
5 #include "zddebug.h"
6 #include "zd1205.h"
7 extern struct net_device *g_dev;
9 void mkFragment(Signal_t *signal, FrmDesc_t *pfrmDesc, U8 *pEthHdr)
11 struct zd1205_private *macp=g_dev->priv;
12 Frame_t *mpdu, *curMpdu;
13 FrmInfo_t *pfrmInfo;
14 BOOLEAN bWep;
15 U16 pdusize;
16 U8 *pBody;
17 U16 len;
18 U8 fn;
19 U8 *pByte;
20 int i;
21 Hash_t *pHash;
22 MICvar *pTxMicKey = NULL;
23 U8 KeyInstalled = 0;
24 U8 vapId = 0;
25 U8 Num;
26 U8 bDataFrm = signal->bDataFrm;
27 //U8 bDataFrm = pfrmDesc->bDataFrm;
28 U16 HdrLen;
30 ZDEBUG("mkFragment");
31 pfrmDesc->CalMIC[MIC_LNG]=FALSE;
32 pfrmInfo = &signal->frmInfo;
33 pfrmInfo->frmDesc = pfrmDesc; //make connection for signal and frmDesc
34 //PSDEBUG_V("mkFrag pfrmDesc", (U32)pfrmInfo->frmDesc);
35 mpdu = pfrmDesc->mpdu;
36 vapId = signal->vapId;
37 #if 0
38 if (mDynKeyMode == DYN_KEY_TKIP || mDynKeyMode == DYN_KEY_AES){
39 if (bDataFrm){
40 if (isGroup(addr1(mpdu))){
41 KeyInstalled = mGkInstalled;
43 if (mDynKeyMode == DYN_KEY_TKIP){
44 pTxMicKey = &mBcMicKey;
45 if (mWpaBcKeyLen != 32) // Not TKIP, don't make MIC
46 KeyInstalled = 0;
49 else{ //unicast
50 pHash = HashSearch(addr1(mpdu));
51 if (!pHash){
52 FPRINT("HashSearch2 failed !!!");
53 zd1205_dump_data("addr1 = ", (U8 *)addr1(mpdu), 6);
54 KeyInstalled = 0;
56 else {
57 if (mDynKeyMode == DYN_KEY_TKIP)
58 pTxMicKey = &pHash->TxMicKey;
59 KeyInstalled = pHash->pkInstalled;
63 if ((KeyInstalled) && (mDynKeyMode == DYN_KEY_TKIP)){
64 #endif
65 // The following section is used for TKIP-MIC append.
66 //<Slow Pairwise Key Install Fix>
67 if (bDataFrm && ((pfrmDesc->ConfigSet &EAPOL_FRAME_SET) && mGkInstalled == 0 && macp->EncTypeOfLastRxEapolPkt == NO_WEP) == 0)
68 //</Slow Pairwise Key Install Fix>
70 if (macp->cardSetting.WPAIeLen) // WPA is supported for now.
72 if (isGroup(addr1(mpdu)))
73 {// Prepare to send the BC/MC packet.
74 KeyInstalled=mGkInstalled;
75 if (KeyInstalled)
77 if(mWpaBcKeyLen == 32)
78 pTxMicKey = &mBcMicKey;
80 else
81 FPRINT("MkFrag: No Group key installed\n");
83 else
84 {// Prepare to send the UC packet.
85 pHash = HashSearch(addr1(mpdu));
86 KeyInstalled=pHash->pkInstalled;
87 if (!pHash){
88 FPRINT("HashSearch2 failed !!!");
89 zd1205_dump_data("addr1 = ", (U8 *)addr1(mpdu), 6);
91 else if(KeyInstalled)
93 //if (pHash->keyLength==32)
94 if (pHash->encryMode == TKIP)
95 pTxMicKey = &pHash->TxMicKey;
97 else
99 FPRINT("MkFrag: Can't find Pairwise key\n");
103 if (pTxMicKey != NULL)
104 { // This section is used for TKIP-MIC append.
106 U16 len = mpdu->bodyLen;
108 // calculate and append MIC to payload before fragmentation
109 MICclear(pTxMicKey);
112 if(mBssType == AP_BSS || mBssType==INDEPENDENT_BSS)
113 pByte = &mpdu->header[4]; //DA=Addr1
114 else //if (mBssType == INFRASTRUCTURE_BSS)
115 pByte = &mpdu->header[16];//DA=Addr3
116 for(i=0; i<6; i++){ //for DA
117 MICappendByte(*pByte++, pTxMicKey);
120 if(mBssType == INFRASTRUCTURE_BSS || mBssType==INDEPENDENT_BSS)
121 pByte = &mpdu->header[10]; //SA=Addr2
122 else //if (mBssType == AP_BSS)
123 pByte = &mpdu->header[16];
124 for(i=0; i<6; i++){ //for SA
125 MICappendByte(*pByte++, pTxMicKey);
128 MICappendByte(0, pTxMicKey);
129 MICappendByte(0, pTxMicKey);
130 MICappendByte(0, pTxMicKey);
131 MICappendByte(0, pTxMicKey);
133 pByte = mpdu->body;
134 for (i=0; i<len; i++){
135 MICappendByte(*pByte++, pTxMicKey);
137 MICgetMIC(pfrmDesc->CalMIC, pTxMicKey);
138 pfrmDesc->CalMIC[MIC_LNG]=TRUE;
139 //zd1205_dump_data("add sw mic:",(u8*)pfrmDesc->CalMIC, 8);
140 mpdu->bodyLen += MIC_LNG;
145 bWep = mPrivacyInvoked;
146 if ((!bDataFrm) && (!(pfrmDesc->ConfigSet & FORCE_WEP_SET))){
147 bWep = FALSE;
149 else {
150 if (pfrmDesc->ConfigSet & EAPOL_FRAME_SET)
151 bWep = FALSE;
154 if (KeyInstalled) // After pairwise key installed, even Eapol frame need to be encrypted
156 //<Slow Pairwise Key Install Fix>
157 if((INFRASTRUCTURE_BSS == mBssType) && (pfrmDesc->ConfigSet & EAPOL_FRAME_SET) && mGkInstalled == 0 && macp->EncTypeOfLastRxEapolPkt == NO_WEP)
159 printk("TX Forced NO WEP before Group installed even if pairwise key has been installed\n");
160 bWep = FALSE;
162 else
163 //</Slow Pairwise Key Install Fix>
165 bWep = TRUE;
168 else
170 if (bDataFrm && !mKeyFormat && bWep)
172 printk(KERN_DEBUG "chkpnt 001\n");
173 bWep = FALSE;
177 pfrmInfo->eol = 0;
179 pdusize = mFragThreshold;
180 if ((!isGroup(addr1(mpdu))) && (mpdu->HdrLen + mpdu->bodyLen + CRC_LNG > pdusize)){ //Need fragment
181 pdusize -= mpdu->HdrLen + CRC_LNG;
182 pfrmInfo->fTot = (mpdu->bodyLen + (pdusize-1)) / pdusize;
183 if (pfrmInfo->fTot == 0)
184 pfrmInfo->fTot = 1;
186 else{
187 pdusize = mpdu->bodyLen;
188 pfrmInfo->fTot = 1;
191 curMpdu = mpdu;
192 pBody = mpdu->body;
193 len = mpdu->bodyLen;
194 Num = pfrmInfo->fTot;
195 HdrLen = mpdu->HdrLen;
197 for (fn=0; fn<Num; fn++){
198 if (fn){
199 curMpdu = &pfrmDesc->mpdu[fn];
200 memcpy(&curMpdu->header[0], &mpdu->header[0], HdrLen); //make header
201 curMpdu->HdrLen = HdrLen;
202 curMpdu->body = pBody;
204 curMpdu->header[22] = ((curMpdu->header[22] & 0xF0) | fn);
206 if (fn == (Num - 1)){
207 curMpdu->bodyLen = len;
208 curMpdu->header[1] &= ~MORE_FRAG_BIT;
210 else{
211 curMpdu->bodyLen = pdusize;
212 pBody += pdusize;
213 len -= pdusize;
214 curMpdu->header[1] |= MORE_FRAG_BIT;
217 if (bWep)
218 curMpdu->header[1] |= WEP_BIT;
223 BOOLEAN sendMgtFrame(Signal_t *signal, FrmDesc_t *pfrmDesc)
225 // ZDEBUG("sendMgtFrame");
226 pfrmDesc->ConfigSet &= ~INTRA_BSS_SET;
227 pfrmDesc->ConfigSet &= ~EAPOL_FRAME_SET;
228 pfrmDesc->pHash = NULL;
229 pdot11Obj->ReleaseBuffer(signal->buf);
230 signal->buf = NULL;
231 signal->bDataFrm = 0;
232 //pfrmDesc->bDataFrm = 0;
233 mkFragment(signal, pfrmDesc, NULL);
234 return SendPkt(signal, pfrmDesc, TRUE);
236 #if 0
237 BOOLEAN getElem(Frame_t *frame, ElementID eleID, Element *elem)
239 U8 k = 0; //offset bytes to first element
240 U8 n = 0; //num. of element
243 U8 pos; //current position
244 U8 len;
245 U8 max_len=34;
246 switch (frmType(frame)){
247 case ST_PROBE_REQ:
248 k = 0;
249 n = 4;
250 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
251 n++;
252 break;
254 case ST_ASOC_REQ:
256 k = 4;
257 n = 4;
258 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
259 n++;
260 break;
262 case ST_REASOC_REQ:
263 k = 10;
264 n = 4;
265 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
266 n++;
267 break;
269 case ST_AUTH:
270 k = 6;
271 n = 1;
272 max_len=130;
273 break;
275 case ST_BEACON:
276 case ST_PROBE_RSP:
277 k = 12;
278 n = 6;
280 if (mBssType == INDEPENDENT_BSS)
281 n++;
282 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
283 n++;
284 n++; //for country info
285 break;
287 case ST_ASOC_RSP:
288 case ST_REASOC_RSP:
289 k = 6;
290 n = 2;
292 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
293 n++;
294 break;
296 default:
297 elem->buf[1] = 0;
298 return FALSE;
301 //while(n--){
302 while(k < frame->bodyLen)
304 pos = frame->body[k];
305 len = frame->body[k+1] + 2;
307 if ((pos == eleID) && (len <= max_len))
308 { //match
309 if (eleID == EID_WPA) //Valid WPA IE
311 if (len > 20)
313 memcpy((U8 *)elem, &frame->body[k], len);
314 return TRUE;
316 else
317 k += len;
319 else
321 memcpy((U8 *)elem, &frame->body[k], len);
322 return TRUE;
325 else{
326 k += len;
330 elem->buf[1] = 0; //set element length to zero
331 return FALSE;
333 #endif
334 BOOLEAN getElem(Frame_t *frame, ElementID eleID, Element *elem, U8 eleOrder)
336 U16 k = 0; //offset bytes to first element
337 U16 pos; //current position
338 U16 len;
339 U16 max_len = 130;
340 U16 eleCount = 0;
341 U16 loopCheck = 0;
343 switch (frmType(frame)){
344 case ST_PROBE_REQ:
345 k = 0;
346 break;
348 case ST_ASOC_REQ:
349 k = 4;
350 break;
352 case ST_REASOC_REQ:
353 k = 10;
354 break;
356 case ST_AUTH:
357 k = 6;
358 break;
360 case ST_BEACON:
361 case ST_PROBE_RSP:
362 k = 12;
363 break;
365 case ST_ASOC_RSP:
366 case ST_REASOC_RSP:
367 k = 6;
368 break;
370 default:
371 elem->buf[1] = 0;
372 return FALSE;
375 //jxiao
376 while (k < frame->bodyLen)
378 // To prevent incorrect len ( ex. 0)
379 if(loopCheck++ > 100)
381 printk("infinite loop occurs in %s\n", __FUNCTION__);
382 loopCheck = 0;
383 break;
386 pos=frame->body[k];
387 len=frame->body[k+1]+2;
388 if ((pos==eleID) && (len <= max_len))
390 eleCount ++;
391 if(eleCount < eleOrder)
393 k+= len;
394 continue;
396 memcpy((U8 *)elem, &frame->body[k], len);
397 return TRUE;
399 else
401 k += len;
404 elem->buf[1]=0;
405 return FALSE;
408 void mkAuthFrm(FrmDesc_t* pfrmDesc, MacAddr_t *addr1, U16 Alg, U16 Seq,
409 U16 Status, U8 *pChalng, U8 vapId)
411 U8 *body;
412 U16 len;
413 Frame_t *pf = pfrmDesc->mpdu;
415 setFrameType(pf, ST_AUTH);
416 pf->body = pfrmDesc->buffer;
417 body = pf->body;
418 setAddr1(pf, addr1);
419 setAddr2(pf, &dot11MacAddress);
420 setAddr3(pf, &mBssId);
421 pf->HdrLen = MAC_HDR_LNG;
423 body[0] = Alg & 0xff; //AuthAlg
424 body[1] = (Alg & 0xff00) >> 8;
425 body[2] = Seq & 0xff; //AuthSeq
426 body[3] = (Seq & 0xff00) >> 8;
427 body[4] = Status & 0xff; //Status
428 body[5] = (Status & 0xff00) >> 8;
429 len = 6;
431 if ((Alg == SHARE_KEY) && ((Seq == 2)|| (Seq == 3)) && (pChalng)) {
432 body[len] = EID_CTEXT;
433 body[len+1] = CHAL_TEXT_LEN;
434 memcpy(&body[len+2], pChalng, CHAL_TEXT_LEN);
435 len += (2+CHAL_TEXT_LEN);
438 pf->bodyLen = len;
441 void mkRe_AsocRspFrm(FrmDesc_t* pfrmDesc, TypeSubtype subType, MacAddr_t *addr1,
442 U16 Cap, U16 Status, U16 Aid, Element *pSupRates, Element *pExtRates, U8 vapId)
444 U8 *body;
445 U8 elemLen;
446 U16 len;
447 Frame_t *pf = pfrmDesc->mpdu;
449 setFrameType(pf, subType);
450 pf->body = pfrmDesc->buffer;
451 body = pf->body;
452 setAddr1(pf, addr1);
453 setAddr2(pf, &dot11MacAddress);
454 setAddr3(pf, &mBssId);
455 pf->HdrLen = MAC_HDR_LNG;
457 body[0] = Cap & 0xff; //Cap
458 body[1] = (Cap & 0xff00) >> 8;
459 body[2] = Status & 0xff; //Status
460 body[3] = (Status & 0xff00) >> 8;
461 body[4] = Aid & 0xff; //AID
462 body[5] = (Aid & 0xff00) >> 8;
463 len = 6;
465 elemLen = pSupRates->buf[1]+2;
466 memcpy(&body[len], (U8 *)pSupRates, elemLen); //Support Rates
467 len += elemLen;
469 if ((mMacMode != PURE_B_MODE) && (PURE_A_MODE != mMacMode) && (pExtRates)){
470 elemLen = pExtRates->buf[1]+2;
471 memcpy(&body[len], (U8 *)pExtRates, elemLen); //Extended rates
472 len += elemLen;
475 pf->bodyLen = len;
480 void mkProbeRspFrm(FrmDesc_t* pfrmDesc, MacAddr_t *addr1, U16 BcnInterval,
481 U16 Cap, Element *pSsid, Element *pSupRates, Element *pDsParms,
482 Element *pExtRates, Element *pWpa, U8 vapId)
485 struct zd1205_private *macp=g_dev->priv;
487 U8 *body;
488 U8 elemLen;
489 U16 len;
490 Frame_t *pf = pfrmDesc->mpdu;
492 setFrameType(pf, ST_PROBE_RSP);
493 pf->body = pfrmDesc->buffer;
494 body = pf->body;
495 setAddr1(pf, addr1);
496 setAddr2(pf, &dot11MacAddress);
497 setAddr3(pf, &mBssId);
498 pf->HdrLen = MAC_HDR_LNG;
500 body[8] = BcnInterval & 0xff; //BcnPeriod
501 body[9] = (BcnInterval & 0xff00) >> 8;
502 body[10] = Cap & 0xff; //Cap
503 body[11] = (Cap & 0xff00) >> 8;
505 len = 12;
506 elemLen = pSsid->buf[1]+2;
507 memcpy(&body[len], (U8 *)pSsid, elemLen); //SSID
508 len += elemLen;
510 elemLen = pSupRates->buf[1]+2;
512 memcpy(&body[len], (U8 *)pSupRates, elemLen); //Suported rates
513 len += elemLen;
515 elemLen = pDsParms->buf[1]+2;
516 memcpy(&body[len], (U8 *)pDsParms, elemLen); //Extended rates
517 len += elemLen;
519 if ((mMacMode != PURE_B_MODE)&& (mMacMode != PURE_A_MODE) && (pExtRates)){
520 elemLen = pExtRates->buf[1]+2;
521 memcpy(&body[len], (U8 *)pExtRates, elemLen); //Extended rates
522 len += elemLen;
524 #if 0
525 if (((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES)) && (pWpa)){
526 elemLen = pWpa->buf[1]+2;
527 memcpy(&body[len], (U8 *)pWpa, elemLen); //WPA IE
528 len += elemLen;
530 #endif
531 //if (((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES)) && (pWpa)){
532 if (macp->cardSetting.WPAIeLen)
534 //elemLen = pWpa->buf[1]+2;
535 //memcpy(&body[len], (U8 *)pWpa, elemLen); //WPA IE
536 memcpy(&body[len], macp->cardSetting.WPAIe, macp->cardSetting.WPAIeLen);
537 len += macp->cardSetting.WPAIeLen;
540 pf->bodyLen = len;
544 void mkDisAssoc_DeAuthFrm(FrmDesc_t* pfrmDesc, TypeSubtype subType, MacAddr_t *addr1,
545 U16 Reason, U8 vapId)
547 U8 *body;
548 Frame_t *pf = pfrmDesc->mpdu;
550 setFrameType(pf, subType);
551 pf->body = pfrmDesc->buffer;
552 body = pf->body;
553 setAddr1(pf, addr1);
554 setAddr2(pf, &dot11MacAddress);
555 setAddr3(pf, &mBssId);
556 pf->HdrLen = MAC_HDR_LNG;
558 body[0] = Reason & 0xff; //Reason Code
559 body[1] = (Reason & 0xff00) >> 8;
561 pf->bodyLen = 2;
565 void sendProbeRspFrm(MacAddr_t *addr1, U16 BcnInterval, U16 Cap,
566 Element *pSsid, Element *pSupRates, Element *pDsParms,
567 Element *pExtRates, Element *pWpa, U8 vapId)
569 Signal_t *signal;
570 FrmDesc_t *pfrmDesc;
572 if ((signal = allocSignal()) == NULL)
573 return;
575 if ((pfrmDesc = allocFdesc()) == NULL){
576 freeSignal(signal);
577 return;
580 mkProbeRspFrm(pfrmDesc, addr1, BcnInterval, Cap, pSsid, pSupRates, pDsParms,
581 pExtRates, pWpa, vapId);
582 sendMgtFrame(signal, pfrmDesc);
586 void mkProbeReqFrm(FrmDesc_t* pfrmDesc, MacAddr_t *addr1, Element *pSsid, Element *pSupRates,
587 Element *pExtRates, Element *pWpa, U8 vapId)
589 U8 *body;
590 U8 elemLen;
591 U16 len;
592 Frame_t *pf = pfrmDesc->mpdu;
594 setFrameType(pf, ST_PROBE_REQ);
595 pf->body = pfrmDesc->buffer;
596 body = pf->body;
597 setAddr1(pf, addr1);
598 setAddr2(pf, &dot11MacAddress);
599 setAddr3(pf, &dot11BCAddress);
600 pf->HdrLen = MAC_HDR_LNG;
602 len = 0;
603 if (pSsid->buf[1] > 0){
604 elemLen = pSsid->buf[1]+2;
606 memcpy(&body[len], (U8 *)pSsid, elemLen); //Extended rates
607 len += elemLen;
608 } else {
609 body[0] = pSsid->buf[0];
610 body[1] = 0; //broadcast SSID
611 len += 2;
614 elemLen = pSupRates->buf[1]+2;
615 memcpy(&body[len], (U8 *)pSupRates, elemLen); //Extended rates
616 len += elemLen;
618 if ((mMacMode != PURE_A_MODE) && (mMacMode != PURE_B_MODE) && (pExtRates)){
619 elemLen = pExtRates->buf[1]+2;
620 memcpy(&body[len], (U8 *)pExtRates, elemLen); //Extended rates
621 len += elemLen;
624 if ((mDynKeyMode == DYN_KEY_TKIP) && (pWpa)){
625 elemLen = pWpa->buf[1]+2;
626 memcpy(&body[len], (U8 *)pWpa, elemLen); //WPA IE
627 len += elemLen;
630 pf->bodyLen = len;
634 void mkRe_AsocReqFrm(FrmDesc_t* pfrmDesc, TypeSubtype subType, MacAddr_t *addr1,
635 U16 Cap, U16 LisInterval, MacAddr_t *oldAP, Element *pSsid, Element *pSupRates,
636 Element *pExtRates, Element *pWpa, U8 vapId)
639 U8 *body;
640 U8 elemLen;
641 U16 len;
642 Frame_t *pf = pfrmDesc->mpdu;
644 setFrameType(pf, subType);
645 pf->body = pfrmDesc->buffer;
646 body = pf->body;
647 setAddr1(pf, addr1);
648 setAddr2(pf, &dot11MacAddress);
649 setAddr3(pf, &mBssId);
650 pf->HdrLen = MAC_HDR_LNG;
652 body[0] = Cap & 0xff; //Cap
653 body[1] = (Cap & 0xff00) >> 8;
654 body[2] = LisInterval & 0xff; //LisInterval
655 body[3] = (LisInterval & 0xff00) >> 8;
656 len = 4;
658 if (subType == ST_REASOC_REQ){
659 memcpy(&body[4], oldAP, 6);
660 len = 10;
663 elemLen = pSsid->buf[1]+2;
664 memcpy(&body[len], (U8 *)pSsid, elemLen); //SSID
665 len += elemLen;
666 #if ZDCONF_LP_SUPPORT == 1
667 if(pdot11Obj->LP_MODE || pdot11Obj->BURST_MODE)
669 BssInfo_t *bs=NULL;
670 bs=zd1212_bssid_to_BssInfo(mBssId.mac);
671 if(bs != NULL)
673 body[len++] = EID_ZYDAS;
674 body[len++] = 7;
675 body[len++] = (U8)(ZDOUI_TURBO);
676 body[len++] = (U8)(ZDOUI_TURBO >> 8);
677 body[len++] = (U8)(ZDOUI_TURBO >> 16);
678 body[len++] = 0; //OUI Type
679 body[len++] = 0; //OUI SubType
680 body[len++] = 1; //Version
681 body[len] = 0;
682 if(bs->zdIE_BURST.buf[0] == EID_ZYDAS)
684 if(bs->zdIE_BURST.buf[8] & BIT_7)
685 body[len] |= pdot11Obj->BURST_MODE;
688 if(bs->zdIE_AMSDU.buf[0] == EID_ZYDAS)
690 if(bs->zdIE_AMSDU.buf[8] & BIT_0)
691 body[len] |= (pdot11Obj->LP_MODE?BIT_1:0);
693 len++;
698 #endif
701 #ifdef DEBUG_DUMP_ASSOC_REQ
702 zd1205_dump_data("SSID element:", (U8*) &body[len-elemLen], elemLen);
703 #endif
705 elemLen = pSupRates->buf[1]+2;
706 memcpy(&body[len], (U8 *)pSupRates, elemLen); //Support Rates
707 len += elemLen;
708 #ifdef DEBUG_DUMP_ASSOC_REQ
709 zd1205_dump_data("SupportedRate element:", (U8*) &body[len-elemLen], elemLen);
710 #endif
712 if ((mMacMode != PURE_B_MODE) && (mMacMode != PURE_A_MODE)&& (pExtRates)){
713 elemLen = pExtRates->buf[1]+2;
714 memcpy(&body[len], (U8 *)pExtRates, elemLen); //Extended rates
715 len += elemLen;
718 // WPA IE
719 if (pWpa->buf[1] != 0) {
720 elemLen = pWpa->buf[1]+2;
721 memcpy(&body[len], (U8 *)pWpa, elemLen); // WPA IE
722 len += elemLen;
725 pf->bodyLen = len;
728 BOOLEAN sendPsPollFrame(Signal_t *signal, FrmDesc_t *pfrmDesc, MacAddr_t *addr1, U16 aid)
730 FrmInfo_t *pfrmInfo;
731 Frame_t *pf = pfrmDesc->mpdu;
733 setFrameType(pf, ST_PS_POLL);
735 if (mPwrState)
737 pf->header[1] |= PW_SAVE_BIT;
739 else
740 pf->header[1] &= ~PW_SAVE_BIT;
743 setAid(pf, aid);
744 setAddr1(pf, addr1);
745 setAddr2(pf, &dot11MacAddress);
746 pf->HdrLen = 16;
747 pf->bodyLen = 0;
749 pfrmDesc->ConfigSet |= PS_POLL_SET;
750 pfrmDesc->ConfigSet &= ~INTRA_BSS_SET;
751 pfrmDesc->ConfigSet &= ~EAPOL_FRAME_SET;
752 pfrmDesc->pHash = NULL;
753 signal->buf = NULL;
754 signal->bDataFrm = 0;
755 //pfrmDesc->bDataFrm = 0;
757 pfrmInfo = &signal->frmInfo;
758 pfrmInfo->frmDesc = pfrmDesc; //make connection for signal and frmDesc
759 return SendPkt(signal, pfrmDesc, TRUE);
763 BOOLEAN sendNullDataFrame(Signal_t *signal, FrmDesc_t *pfrmDesc, MacAddr_t *addr1)
765 Frame_t *pf = pfrmDesc->mpdu;
767 setFrameType(pf, ST_NULL_FRAME);
768 pf->header[1] = TO_DS_BIT;
770 if (mPwrState){
771 pf->header[1] |= PW_SAVE_BIT;
773 else
774 pf->header[1] &= ~PW_SAVE_BIT;
776 setAddr1(pf, addr1);
777 setAddr2(pf, &dot11MacAddress);
778 setAddr3(pf, &mBssId);
779 pf->HdrLen = MAC_HDR_LNG;
780 pf->bodyLen = 0;
782 pfrmDesc->ConfigSet &= ~INTRA_BSS_SET;
783 pfrmDesc->ConfigSet &= ~EAPOL_FRAME_SET;
784 pfrmDesc->pHash = NULL;
785 signal->buf = NULL;
786 signal->bDataFrm = 1;
788 //pfrmDesc->bDataFrm = 0;
789 mkFragment(signal, pfrmDesc, NULL);
790 return SendPkt(signal, pfrmDesc, TRUE);
794 U8 RateConvert(U8 rate)
796 #if defined(OFDM)
797 switch (rate)
799 case 2 : return 0; // 1M
800 case 4 : return 1; // 2M
801 case 11 : return 2; // 5.5M
802 case 22 : return 3; // 11M
803 case 12 : return 4; // 6M
804 case 18 : return 5; // 9M
805 case 24 : return 6; // 12M
806 case 36 : return 7; // 18M
807 case 48 : return 8; // 24M
808 case 72 : return 9; // 36M
809 case 96 : return 0xa; // 48M
810 case 108: return 0xb; // 54M
812 #else
813 switch (rate)
815 case 2 : return 0; // 1M
816 case 4 : return 1; // 2M
817 case 11 : return 2; // 5.5M
818 case 22 : return 3; // 11M
819 case 33 : return 4; // 16.5M
820 case 44 : return 5; // 22M
821 case 55 : return 6; // 27.5M
822 #if defined(ECCK_60_5)
823 case 66 : return 7; // 33M
824 case 77 : return 8; // 38.5M
825 case 88 : return 9; // 44M
826 case 99 : return 10; // 49.5M
827 case 110: return 11; // 55M
828 case 121: return 12; // 60.5M
829 #endif
831 #endif
833 return 3; // 11M
835 #endif