2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Module Name : mm.c */
20 /* This module contains common functions for handle management */
26 /************************************************************************/
28 #include "../hal/hpreg.h"
30 /* TODO : put all constant tables to a file */
31 const u8_t zg11bRateTbl
[4] = {2, 4, 11, 22};
32 const u8_t zg11gRateTbl
[8] = {12, 18, 24, 36, 48, 72, 96, 108};
34 /* 0xff => element does not exist */
35 const u8_t zgElementOffsetTable
[] =
39 10, /* 2 : reasoc req*/
40 6, /* 3 : reasoc rsp */
41 0, /* 4 : probe req */
42 12, /* 5 : probe rsp */
43 0xff, /* 6 : reserved */
44 0xff, /* 7 : reserved */
47 0xff, /* 10 : disasoc */
49 0xff, /* 12 : deauth */
51 0xff, /* 14 : reserved */
52 0xff, /* 15 : reserved */
55 /************************************************************************/
57 /* FUNCTION DESCRIPTION zfFindElement */
58 /* Find a specific element in management frame */
61 /* dev : device pointer */
62 /* buf : management frame buffer */
63 /* eid : target element id */
66 /* byte offset of target element */
67 /* or 0xffff if not found */
70 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
72 /************************************************************************/
73 u16_t
zfFindElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t eid
)
80 u8_t oui
[4] = {0x00, 0x50, 0xf2, 0x01};
81 u8_t oui11n
[3] = {0x00,0x90,0x4C};
84 /* Get offset of first element */
85 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
86 offset
= zgElementOffsetTable
[subType
];
92 /* Plus wlan header */
97 if ((eid
== ZM_WLAN_EID_HT_CAPABILITY
) ||
98 (eid
== ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
))
101 eid
= ZM_WLAN_EID_WPA_IE
;
106 bufLen
= zfwBufGetSize(dev
, buf
);
108 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
110 /* Search target element */
111 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
115 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
116 if (elen
> bufLen
- offset
)
118 /* Element length error */
122 if ( elen
== 0 && eid
!= ZM_WLAN_EID_SSID
)
124 /* Element length error */
128 if ( eid
== ZM_WLAN_EID_WPA_IE
)
130 /* avoid sta to be thought use 11n when find a WPA_IE */
131 if ( (HTType
== 0) && zfRxBufferEqualToStr(dev
, buf
, oui
, offset
+2, 4) )
139 if ((HTType
== 1) && ( zfRxBufferEqualToStr(dev
, buf
, oui11n
, offset
+2, 3) ))
141 if ( zmw_rx_buf_readb(dev
, buf
, offset
+5) == HTEid
)
153 /* Advance to next element */
155 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
157 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
170 /************************************************************************/
172 /* FUNCTION DESCRIPTION zfFindWifiElement */
173 /* Find a specific Wifi element in management frame */
176 /* dev : device pointer */
177 /* buf : management frame buffer */
178 /* type : OUI type */
179 /* subType : OUI subtype */
182 /* byte offset of target element */
183 /* or 0xffff if not found */
186 /* Stephen Chen ZyDAS Technology Corporation 2006.1 */
188 /************************************************************************/
189 u16_t
zfFindWifiElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
, u8_t subtype
)
198 /* Get offset of first element */
199 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
201 offset
= zgElementOffsetTable
[subType
];
207 /* Plus wlan header */
210 bufLen
= zfwBufGetSize(dev
, buf
);
212 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
214 /* Search target element */
215 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
216 if (id
== ZM_WLAN_EID_WIFI_IE
)
219 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
220 if (elen
> bufLen
- offset
)
222 /* Element length error */
231 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
232 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
233 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0xF2)
234 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+5)) == type
))
237 if ( subtype
!= 0xff )
239 tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+6);
251 /* Advance to next element */
252 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
262 u16_t
zfRemoveElement(zdev_t
* dev
, u8_t
* buf
, u16_t size
, u8_t eid
)
267 u8_t oui
[4] = {0x00, 0x50, 0xf2, 0x01};
268 u8_t oui11n
[3] = {0x00,0x90,0x4C};
271 if ((eid
== ZM_WLAN_EID_HT_CAPABILITY
) ||
272 (eid
== ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
))
275 eid
= ZM_WLAN_EID_WPA_IE
;
279 while (offset
< size
)
281 elen
= *(buf
+offset
+1);
283 if (*(buf
+offset
) == eid
)
285 if ( eid
== ZM_WLAN_EID_WPA_IE
)
288 && (*(buf
+offset
+2) == oui
[0])
289 && (*(buf
+offset
+3) == oui
[1])
290 && (*(buf
+offset
+4) == oui
[2])
291 && (*(buf
+offset
+5) == oui
[3]) )
293 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
294 return (size
-elen
-2);
298 && (*(buf
+offset
+2) == oui11n
[0])
299 && (*(buf
+offset
+3) == oui11n
[1])
300 && (*(buf
+offset
+4) == oui11n
[2])
301 && (*(buf
+offset
+5) == HTEid
) )
303 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
304 return (size
-elen
-2);
309 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
310 return (size
-elen
-2);
320 u16_t
zfUpdateElement(zdev_t
* dev
, u8_t
* buf
, u16_t size
, u8_t
* updateeid
)
325 while (offset
< size
) {
326 elen
= *(buf
+offset
+1);
328 if (*(buf
+offset
) == updateeid
[0]) {
329 if (updateeid
[1] <= elen
) {
330 zfMemoryMove(buf
+offset
, updateeid
, updateeid
[1]+2);
331 zfMemoryMove(buf
+offset
+updateeid
[1]+2, buf
+offset
+elen
+2, size
-offset
-elen
-2);
333 return size
-(elen
-updateeid
[1]);
335 zfMemoryMove(buf
+offset
+updateeid
[1]+2, buf
+offset
+elen
+2, size
-offset
-elen
-2);
336 zfMemoryMove(buf
+offset
, updateeid
, updateeid
[1]+2);
338 return size
+(updateeid
[1]-elen
);
348 u16_t
zfFindSuperGElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
)
356 u8_t ouiSuperG
[6] = {0x00,0x03,0x7f,0x01, 0x01, 0x00};
358 /* Get offset of first element */
359 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
360 offset
= zgElementOffsetTable
[subType
];
366 /* Plus wlan header */
369 bufLen
= zfwBufGetSize(dev
, buf
);
371 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
373 /* Search target element */
374 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
375 if (id
== ZM_WLAN_EID_VENDOR_PRIVATE
)
378 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
379 if (elen
> bufLen
- offset
)
381 /* Element length error */
390 if (zfRxBufferEqualToStr(dev
, buf
, ouiSuperG
, offset
+2, 6) && ( zmw_rx_buf_readb(dev
, buf
, offset
+1) >= 6))
392 /* super_feature 0:useFastFrame, 1:useCompression, 2:useTurboPrime */
393 super_feature
= zmw_rx_buf_readb(dev
, buf
, offset
+8);
394 if ((super_feature
& 0x01) || (super_feature
& 0x02) || (super_feature
& 0x04))
400 /* Advance to next element */
402 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
404 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
416 u16_t
zfFindXRElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
)
423 u8_t ouixr
[6] = {0x00,0x03,0x7f,0x03, 0x01, 0x00};
425 /* Get offset of first element */
426 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
427 offset
= zgElementOffsetTable
[subType
];
433 /* Plus wlan header */
436 bufLen
= zfwBufGetSize(dev
, buf
);
438 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
440 /* Search target element */
441 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
442 if (id
== ZM_WLAN_EID_VENDOR_PRIVATE
)
445 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
446 if (elen
> bufLen
- offset
)
448 /* Element length error */
457 if (zfRxBufferEqualToStr(dev
, buf
, ouixr
, offset
+2, 6) && ( zmw_rx_buf_readb(dev
, buf
, offset
+1) >= 6))
462 /* Advance to next element */
464 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
466 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
478 /************************************************************************/
480 /* FUNCTION DESCRIPTION zfMmAddIeSupportRate */
481 /* Add information element Support Rate to buffer. */
484 /* dev : device pointer */
485 /* buf : buffer to add information element */
486 /* offset : add information element from this offset */
487 /* eid : element ID */
488 /* rateSet : CCK or OFDM */
491 /* buffer offset after adding information element */
494 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
496 /************************************************************************/
497 u16_t
zfMmAddIeSupportRate(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t eid
, u8_t rateSet
)
502 zmw_get_wlan_dev(dev
);
504 //if ( (rateSet == ZM_RATE_SET_OFDM)&&((wd->gRate & 0xff) == 0) )
509 /* Information : Support Rate */
510 if ( rateSet
== ZM_RATE_SET_CCK
)
514 if ((wd
->bRate
& (0x1<<i
)) == (0x1<<i
))
515 //if ((0xf & (0x1<<i)) == (0x1<<i))
517 zmw_tx_buf_writeb(dev
, buf
, offset
+len
+2,
518 zg11bRateTbl
[i
]+((wd
->bRateBasic
& (0x1<<i
))<<(7-i
)));
523 else if ( rateSet
== ZM_RATE_SET_OFDM
)
527 if ((wd
->gRate
& (0x1<<i
)) == (0x1<<i
))
528 //if ((0xff & (0x1<<i)) == (0x1<<i))
530 zmw_tx_buf_writeb(dev
, buf
, offset
+len
+2,
531 zg11gRateTbl
[i
]+((wd
->gRateBasic
& (0x1<<i
))<<(7-i
)));
540 zmw_tx_buf_writeb(dev
, buf
, offset
, eid
);
543 zmw_tx_buf_writeb(dev
, buf
, offset
+1, len
);
552 /************************************************************************/
554 /* FUNCTION DESCRIPTION zfMmAddIeDs */
555 /* Add information element DS to buffer. */
558 /* dev : device pointer */
559 /* buf : buffer to add information element */
560 /* offset : add information element from this offset */
563 /* buffer offset after adding information element */
566 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
568 /************************************************************************/
569 u16_t
zfMmAddIeDs(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
571 zmw_get_wlan_dev(dev
);
574 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_DS
);
577 zmw_tx_buf_writeb(dev
, buf
, offset
++, 1);
579 /* Information : DS */
580 zmw_tx_buf_writeb(dev
, buf
, offset
++,
581 zfChFreqToNum(wd
->frequency
, NULL
));
587 /************************************************************************/
589 /* FUNCTION DESCRIPTION zfMmAddIeErp */
590 /* Add information element ERP to buffer. */
593 /* dev : device pointer */
594 /* buf : buffer to add information element */
595 /* offset : add information element from this offset */
598 /* buffer offset after adding information element */
601 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
603 /************************************************************************/
604 u16_t
zfMmAddIeErp(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
606 zmw_get_wlan_dev(dev
);
609 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_ERP
);
612 zmw_tx_buf_writeb(dev
, buf
, offset
++, 1);
614 /* Information : ERP */
615 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->erpElement
);
621 /************************************************************************/
623 /* FUNCTION DESCRIPTION zfMmAddIeWpa */
624 /* Add information element WPA to buffer. */
627 /* dev : device pointer */
628 /* buf : buffer to add information element */
629 /* offset : add information element from this offset */
632 /* buffer offset after adding information element */
635 /* Yuan-Gu Wei ZyDAS Technology Corporation 2006.2 */
637 /************************************************************************/
638 u16_t
zfMmAddIeWpa(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u16_t apId
)
640 //struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev);
643 zmw_get_wlan_dev(dev
);
646 //zmw_inttx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_WPA_IE);
649 //zmw_inttx_buf_writeb(dev, buf, offset++, wd->ap.wpaLen);
650 for(i
= 0; i
< wd
->ap
.wpaLen
[apId
]; i
++)
652 /* Information : WPA */
653 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->ap
.wpaIe
[apId
][i
]);
659 /************************************************************************/
661 /* FUNCTION DESCRIPTION zfMmAddHTCapability */
662 /* Add HT Capability Infomation to buffer. */
665 /* dev : device pointer */
666 /* buf : buffer to add information element */
667 /* offset : add information element from this offset */
670 /* buffer offset after adding information element */
673 /* Chao-Wen Yang ZyDAS Technology Corporation 2006.06 */
675 /************************************************************************/
676 u16_t
zfMmAddHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
678 u8_t OUI
[3] = {0x0,0x90,0x4C};
681 zmw_get_wlan_dev(dev
);
684 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_WPA_IE
);
686 if ( wd
->wlanMode
== ZM_MODE_AP
)
689 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.Length
+ 4);
692 for (i
= 0; i
< 3; i
++)
694 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
697 /* Element Type ID */
698 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.ElementID
);
700 /* HT Capability Data */
701 for (i
= 0; i
< 26; i
++)
703 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Byte
[i
+2]);
709 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.Length
+ 4);
712 for (i
= 0; i
< 3; i
++)
714 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
717 /* Element Type ID */
718 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.ElementID
);
720 /* HT Capability Data */
721 for (i
= 0; i
< 26; i
++)
723 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Byte
[i
+2]);
731 u16_t
zfMmAddPreNHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
733 //u8_t OUI[3] = {0x0,0x90,0x4C};
736 zmw_get_wlan_dev(dev
);
739 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_PREN2_EID_HTCAPABILITY
);
741 if ( wd
->wlanMode
== ZM_MODE_AP
)
744 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.Length
);
746 /* HT Capability Data */
747 for (i
= 0; i
< 26; i
++)
749 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Byte
[i
+2]);
755 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.Length
);
757 /* HT Capability Data */
758 for (i
= 0; i
< 26; i
++)
760 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Byte
[i
+2]);
767 /************************************************************************/
769 /* FUNCTION DESCRIPTION zfMmAddExtendedHTCapability */
770 /* Add Extended HT Capability Infomation to buffer. */
773 /* dev : device pointer */
774 /* buf : buffer to add information element */
775 /* offset : add information element from this offset */
778 /* buffer offset after adding information element */
781 /* Chao-Wen Yang ZyDAS Technology Corporation 2006.06 */
783 /************************************************************************/
784 u16_t
zfMmAddExtendedHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
786 u8_t OUI
[3] = {0x0,0x90,0x4C};
789 zmw_get_wlan_dev(dev
);
792 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_WPA_IE
);
794 if ( wd
->wlanMode
== ZM_MODE_AP
)
797 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Data
.Length
+ 4);
800 for (i
= 0; i
< 3; i
++)
802 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
805 /* Element Type ID */
806 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Data
.ElementID
);
808 /* HT Capability Data */
809 for (i
= 0; i
< 22; i
++)
811 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Byte
[i
+2]);
817 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Data
.Length
+ 4);
820 for (i
= 0; i
< 3; i
++)
822 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
825 /* Element Type ID */
826 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Data
.ElementID
);
828 /* HT Capability Data */
829 for (i
= 0; i
< 22; i
++)
831 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Byte
[i
+2]);
840 /************************************************************************/
842 /* FUNCTION DESCRIPTION zfSendMmFrame */
843 /* Send management frame. */
846 /* dev : device pointer */
847 /* frameType : management frame type */
848 /* dst : destination MAC address */
849 /* p1 : parameter 1 */
850 /* p2 : parameter 2 */
851 /* p3 : parameter 3 */
857 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
859 /************************************************************************/
860 /* probe req : p1=> bWithSSID, p2=>R, p3=>R */
861 /* probe rsp : p1=>R, p2=>R, p3=>VAP ID(AP) */
862 /* deauth : p1=>Reason Code, p2=>R, p3=>VAP ID(AP) */
863 /* Disasoc : p1=>Reason Code, p2=>R, p3=>VAP ID(AP) */
864 /* ATIM : p1=>R, p2=>R, p3=>R */
865 /* (re)asoc rsp : p1=>Status Code, p2=>AID, p3=>VAP ID(AP) */
866 /* asoc req : p1=>R, p2=>R, p3=>R */
867 /* reasoc req : p1=>AP MAC[0], p2=>AP MAC[1], p3=>AP MAC[2] */
868 /* auth : p1=>low=Algorithm, high=Transaction, p2=>Status, p3=>VAP ID */
869 void zfSendMmFrame(zdev_t
* dev
, u8_t frameType
, u16_t
* dst
,
870 u32_t p1
, u32_t p2
, u32_t p3
)
874 //struct zsAddrTbl addrTbl;
877 u16_t header
[(24+25+1)/2];
883 zmw_get_wlan_dev(dev
);
884 zmw_declare_for_critical_section();
886 zm_msg2_mm(ZM_LV_2
, "Send mm frame, type=", frameType
);
887 /* TBD : Maximum size of management frame */
888 buf
= zfwBufAllocate(dev
, 1024);
891 zm_msg0_mm(ZM_LV_0
, "Alloc mm buf Fail!");
895 //Reserve room for wlan header
900 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
901 offset
= zfSendProbeReq(dev
, buf
, offset
, (u8_t
) p1
);
904 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
905 zm_msg0_mm(ZM_LV_3
, "probe rsp");
906 /* 24-31 Time Stamp : hardware WON'T fill this field */
907 zmw_tx_buf_writeh(dev
, buf
, offset
, 0);
908 zmw_tx_buf_writeh(dev
, buf
, offset
+2, 0);
909 zmw_tx_buf_writeh(dev
, buf
, offset
+4, 0);
910 zmw_tx_buf_writeh(dev
, buf
, offset
+6, 0);
913 /* Beacon Interval */
914 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->beaconInterval
);
917 if (wd
->wlanMode
== ZM_MODE_AP
)
921 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->ap
.capab
[vap
]);
924 offset
= zfApAddIeSsid(dev
, buf
, offset
, vap
);
929 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[0]);
930 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[1]);
932 offset
= zfStaAddIeSsid(dev
, buf
, offset
);
936 if ( wd
->frequency
< 3000 )
938 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
939 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
943 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
944 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
947 /* DS parameter set */
948 offset
= zfMmAddIeDs(dev
, buf
, offset
);
951 if ( wd
->wlanMode
== ZM_MODE_IBSS
)
953 offset
= zfStaAddIeIbss(dev
, buf
, offset
);
955 if (wd
->frequency
< 3000)
957 if( wd
->wfc
.bIbssGMode
958 && (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) ) // Only accompany with enabling a mode .
960 /* ERP Information */
962 offset
= zfMmAddIeErp(dev
, buf
, offset
);
965 /* Extended Supported Rates */
966 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
967 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
973 if ((wd
->wlanMode
== ZM_MODE_AP
)
974 && (wd
->ap
.wlanType
[vap
] != ZM_WLAN_TYPE_PURE_B
))
976 /* ERP Information */
977 offset
= zfMmAddIeErp(dev
, buf
, offset
);
979 /* Extended Supported Rates */
980 if ( wd
->frequency
< 3000 )
982 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
983 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
987 /* ERP Information */
988 //offset = zfMmAddIeErp(dev, buf, offset);
990 /* Extended Supported Rates */
991 //offset = zfMmAddIeSupportRate(dev, buf, offset,
992 // ZM_WLAN_EID_EXTENDED_RATE, ZM_RATE_SET_OFDM);
995 if (wd
->wlanMode
== ZM_MODE_AP
&& wd
->ap
.wpaSupport
[vap
] == 1)
997 offset
= zfMmAddIeWpa(dev
, buf
, offset
, vap
);
999 else if ( wd
->wlanMode
== ZM_MODE_IBSS
&& wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
1001 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, ZM_WLAN_FRAME_TYPE_AUTH
);
1004 /* WME Parameters */
1005 if (wd
->wlanMode
== ZM_MODE_AP
)
1007 if (wd
->ap
.qosMode
== 1)
1009 offset
= zfApAddIeWmePara(dev
, buf
, offset
, vap
);
1013 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
1017 /* TODO : Need to check if it is ok */
1018 /* HT Capabilities Info */
1019 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1021 /* Extended HT Capabilities Info */
1022 offset
= zfMmAddExtendedHTCapability(dev
, buf
, offset
);
1025 if ( wd
->sta
.ibssAdditionalIESize
)
1026 offset
= zfStaAddIbssAdditionalIE(dev
, buf
, offset
);
1029 case ZM_WLAN_FRAME_TYPE_AUTH
:
1033 offset
+= 4; // for reserving wep header
1037 /* Algotrithm Number */
1038 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p1
&0xffff));
1041 /* Transaction Number */
1042 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p1
>>16));
1046 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p2
);
1049 if (wd
->wlanMode
== ZM_MODE_AP
)
1054 /* Challenge Text => share-2 or share-3 */
1057 if (p2
== 0) //Status == success
1059 zmw_buf_writeh(dev
, buf
, offset
, 0x8010);
1061 /* share-2 : AP generate challenge text */
1062 for (i
=0; i
<128; i
++)
1064 wd
->ap
.challengeText
[i
] = (u8_t
)zfGetRandomNumber(dev
, 0);
1066 zfCopyToIntTxBuffer(dev
, buf
, wd
->ap
.challengeText
, offset
, 128);
1070 else if (p1
== 0x30001)
1072 /* share-3 : STA return challenge Text */
1073 zfCopyToIntTxBuffer(dev
, buf
, wd
->sta
.challengeText
, offset
, wd
->sta
.challengeText
[1]+2);
1074 offset
+= (wd
->sta
.challengeText
[1]+2);
1079 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1080 case ZM_WLAN_FRAME_TYPE_REASOCREQ
:
1082 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[0]);
1083 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[1]);
1085 /* Listen Interval */
1086 zmw_tx_buf_writeh(dev
, buf
, offset
, 0x0005);
1089 /* Reassocaited Request : Current AP address */
1090 if (frameType
== ZM_WLAN_FRAME_TYPE_REASOCREQ
)
1092 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[0]);
1094 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[1]);
1096 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[2]);
1101 offset
= zfStaAddIeSsid(dev
, buf
, offset
);
1104 if ( wd
->sta
.currentFrequency
< 3000 )
1107 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1112 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1115 if ((wd
->sta
.capability
[1] & ZM_BIT_0
) == 1)
1116 { //spectrum management flag enable
1117 offset
= zfStaAddIePowerCap(dev
, buf
, offset
);
1118 offset
= zfStaAddIeSupportCh(dev
, buf
, offset
);
1121 if (wd
->sta
.currentFrequency
< 3000)
1123 /* Extended Supported Rates */
1124 if (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
))
1126 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1131 //offset = zfStaAddIeWpaRsn(dev, buf, offset, frameType);
1132 //Move to wrapper function, for OS difference--CWYang(m)
1133 //for windows wrapper, zfwStaAddIeWpaRsn() should be below:
1134 //u16_t zfwStaAddIeWpaRsn(zdev_t* dev, zbuf_t* buf, u16_t offset, u8_t frameType)
1136 // return zfStaAddIeWpaRsn(dev, buf, offset, frameType);
1138 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, frameType
);
1140 #ifdef ZM_ENABLE_CENC
1142 //if (wd->sta.encryMode == ZM_CENC)
1143 offset
= zfStaAddIeCenc(dev
, buf
, offset
);
1144 #endif //ZM_ENABLE_CENC
1145 if (((wd
->sta
.wmeEnabled
& ZM_STA_WME_ENABLE_BIT
) != 0) //WME enabled
1146 && ((wd
->sta
.apWmeCapability
& 0x1) != 0)) //WME AP
1148 if (((wd
->sta
.apWmeCapability
& 0x80) != 0) //UAPSD AP
1149 && ((wd
->sta
.wmeEnabled
& ZM_STA_UAPSD_ENABLE_BIT
) != 0)) //UAPSD enabled
1151 offset
= zfStaAddIeWmeInfo(dev
, buf
, offset
, wd
->sta
.wmeQosInfo
);
1155 offset
= zfStaAddIeWmeInfo(dev
, buf
, offset
, 0);
1160 if (wd
->sta
.EnableHT
!= 0)
1162 #ifndef ZM_DISABLE_AMSDU8K_SUPPORT
1164 if (wd
->sta
.wepStatus
== ZM_ENCRYPTION_WEP_DISABLED
)
1166 wd
->sta
.HTCap
.Data
.HtCapInfo
|= HTCAP_MaxAMSDULength
;
1170 wd
->sta
.HTCap
.Data
.HtCapInfo
&= (~HTCAP_MaxAMSDULength
);
1174 wd
->sta
.HTCap
.Data
.HtCapInfo
&= (~HTCAP_MaxAMSDULength
);
1177 /* HT Capabilities Info */
1178 if (wd
->BandWidth40
== 1) {
1179 wd
->sta
.HTCap
.Data
.HtCapInfo
|= HTCAP_SupChannelWidthSet
;
1182 wd
->sta
.HTCap
.Data
.HtCapInfo
&= ~HTCAP_SupChannelWidthSet
;
1183 //wd->sta.HTCap.Data.HtCapInfo |= HTCAP_SupChannelWidthSet;
1186 wd
->sta
.HTCap
.Data
.AMPDUParam
&= ~HTCAP_MaxRxAMPDU3
;
1187 wd
->sta
.HTCap
.Data
.AMPDUParam
|= HTCAP_MaxRxAMPDU3
;
1188 wd
->sta
.HTCap
.Data
.MCSSet
[1] = 0xFF; // MCS 8 ~ 15
1189 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1190 offset
= zfMmAddPreNHTCapability(dev
, buf
, offset
);
1192 /* Extended HT Capabilities Info */
1193 //offset = zfMmAddExtendedHTCapability(dev, buf, offset);
1197 //Store asoc request frame body, for VISTA only
1198 wd
->sta
.asocReqFrameBodySize
= ((offset
- hlen
) >
1199 ZM_CACHED_FRAMEBODY_SIZE
)?
1200 ZM_CACHED_FRAMEBODY_SIZE
:(offset
- hlen
);
1201 for (i
=0; i
<wd
->sta
.asocReqFrameBodySize
; i
++)
1203 wd
->sta
.asocReqFrameBody
[i
] = zmw_tx_buf_readb(dev
, buf
, i
+ hlen
);
1207 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1208 case ZM_WLAN_FRAME_TYPE_REASOCRSP
:
1212 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->ap
.capab
[vap
]);
1216 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p1
);
1220 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p2
|0xc000));
1224 if ( wd
->frequency
< 3000 )
1227 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1229 /* Extended Supported Rates */
1230 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1235 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1240 /* WME Parameters */
1241 if (wd
->wlanMode
== ZM_MODE_AP
)
1243 /* TODO : if WME STA then send WME parameter element */
1244 if (wd
->ap
.qosMode
== 1)
1246 offset
= zfApAddIeWmePara(dev
, buf
, offset
, vap
);
1251 /* HT Capabilities Info */
1252 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1254 /* Extended HT Capabilities Info */
1255 offset
= zfMmAddExtendedHTCapability(dev
, buf
, offset
);
1258 case ZM_WLAN_FRAME_TYPE_ATIM
:
1260 /* TODO : add two dumb bytes temporarily */
1264 case ZM_WLAN_FRAME_TYPE_QOS_NULL
:
1265 zmw_buf_writeh(dev
, buf
, offset
, 0x0010);
1269 case ZM_WLAN_DATA_FRAME
:
1272 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1273 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1274 if (wd
->wlanMode
== ZM_MODE_AP
)
1278 aid
= zfApFindSta(dev
, dst
);
1281 zmw_enter_critical_section(dev
);
1282 /* Clear STA table */
1283 wd
->ap
.staTable
[aid
].valid
= 0;
1285 zmw_leave_critical_section(dev
);
1287 if (wd
->zfcbDisAsocNotify
!= NULL
)
1289 wd
->zfcbDisAsocNotify(dev
, (u8_t
*)dst
, vap
);
1294 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p1
);
1299 zfwBufSetSize(dev
, buf
, offset
);
1301 zm_msg2_mm(ZM_LV_2
, "management frame body size=", offset
-hlen
);
1304 zfTxGenMmHeader(dev
, frameType
, dst
, header
, offset
-hlen
, buf
, vap
, encrypt
);
1305 for (i
=0; i
<(hlen
>>1); i
++)
1307 zmw_tx_buf_writeh(dev
, buf
, i
*2, header
[i
]);
1310 /* Get buffer DMA address */
1311 //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0)
1312 //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0)
1317 zm_msg2_mm(ZM_LV_2
, "offset=", offset
);
1318 zm_msg2_mm(ZM_LV_2
, "hlen=", hlen
);
1319 //zm_msg2_mm(ZM_LV_2, "addrTblSize=", addrTblSize);
1320 //zm_msg2_mm(ZM_LV_2, "addrTbl.len[0]=", addrTbl.len[0]);
1321 //zm_msg2_mm(ZM_LV_2, "addrTbl.physAddrl[0]=", addrTbl.physAddrl[0]);
1322 //zm_msg2_mm(ZM_LV_2, "buf->data=", buf->data);
1325 err
= zfHpSend(dev
, NULL
, 0, NULL
, 0, NULL
, 0, buf
, 0,
1326 ZM_INTERNAL_ALLOC_BUF
, 0, 0xff);
1327 if (err
!= ZM_SUCCESS
)
1332 zfPutVmmq(dev
, buf
);
1340 zfwBufFree(dev
, buf
, 0);
1346 /************************************************************************/
1348 /* FUNCTION DESCRIPTION zfProcessManagement */
1349 /* Process received management frame. */
1352 /* dev : device pointer */
1353 /* buf : received management frame buffer */
1359 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1361 /************************************************************************/
1362 void zfProcessManagement(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
) //CWYang(m)
1367 u16_t vap
= 0, index
= 0;
1370 zmw_get_wlan_dev(dev
);
1372 ra
[0] = zmw_rx_buf_readh(dev
, buf
, 4);
1373 ra
[1] = zmw_rx_buf_readh(dev
, buf
, 6);
1374 ra
[2] = zmw_rx_buf_readh(dev
, buf
, 8);
1376 ta
[0] = zmw_rx_buf_readh(dev
, buf
, 10);
1377 ta
[1] = zmw_rx_buf_readh(dev
, buf
, 12);
1378 ta
[2] = zmw_rx_buf_readh(dev
, buf
, 14);
1380 frameType
= zmw_rx_buf_readb(dev
, buf
, 0);
1382 if (wd
->wlanMode
== ZM_MODE_AP
)
1386 if ((ra
[0] & 0x1) != 1)
1388 /* AP : Find virtual AP */
1389 index
= zfApFindSta(dev
, ta
);
1390 if (index
!= 0xffff)
1392 vap
= wd
->ap
.staTable
[index
].vap
;
1395 zm_msg2_mm(ZM_LV_2
, "vap=", vap
);
1398 /* Dispatch by frame type */
1402 case ZM_WLAN_FRAME_TYPE_BEACON
:
1403 zfApProcessBeacon(dev
, buf
);
1405 /* Authentication */
1406 case ZM_WLAN_FRAME_TYPE_AUTH
:
1407 zfApProcessAuth(dev
, buf
, ta
, vap
);
1409 /* Association request */
1410 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1411 /* Reassociation request */
1412 case ZM_WLAN_FRAME_TYPE_REASOCREQ
:
1413 zfApProcessAsocReq(dev
, buf
, ta
, vap
);
1415 /* Association response */
1416 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1417 //zfApProcessAsocRsp(dev, buf);
1419 /* Deauthentication */
1420 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1421 zfApProcessDeauth(dev
, buf
, ta
, vap
);
1423 /* Disassociation */
1424 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1425 zfApProcessDisasoc(dev
, buf
, ta
, vap
);
1428 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
1429 zfProcessProbeReq(dev
, buf
, ta
);
1431 /* Probe response */
1432 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
1433 zfApProcessProbeRsp(dev
, buf
, AddInfo
);
1436 case ZM_WLAN_FRAME_TYPE_ACTION
:
1437 zfApProcessAction(dev
, buf
);
1441 else //if ((wd->wlanMode == ZM_MODE_INFRASTRUCTURE) || (wd->wlanMode == ZM_MODE_IBSS))
1443 /* Dispatch by frame type */
1447 case ZM_WLAN_FRAME_TYPE_BEACON
:
1448 /* if enable 802.11h and current channel is silent but receive beacon from other AP */
1449 if (((wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1450 & ZM_REG_FLAG_CHANNEL_CSA
) != 0) && wd
->sta
.DFSEnable
)
1452 wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1453 &= ~(ZM_REG_FLAG_CHANNEL_CSA
& ZM_REG_FLAG_CHANNEL_PASSIVE
);
1455 zfStaProcessBeacon(dev
, buf
, AddInfo
); //CWYang(m)
1457 /* Authentication */
1458 case ZM_WLAN_FRAME_TYPE_AUTH
:
1459 /* TODO : vap parameter is useless in STA mode, get rid of it */
1460 zfStaProcessAuth(dev
, buf
, ta
, 0);
1462 /* Association request */
1463 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1464 /* TODO : vap parameter is useless in STA mode, get rid of it */
1465 zfStaProcessAsocReq(dev
, buf
, ta
, 0);
1467 /* Association response */
1468 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1469 /* Reassociation request */
1470 case ZM_WLAN_FRAME_TYPE_REASOCRSP
:
1471 zfStaProcessAsocRsp(dev
, buf
);
1473 /* Deauthentication */
1474 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1475 zm_debug_msg0("Deauthentication received");
1476 zfStaProcessDeauth(dev
, buf
);
1478 /* Disassociation */
1479 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1480 zm_debug_msg0("Disassociation received");
1481 zfStaProcessDisasoc(dev
, buf
);
1484 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
1485 zfProcessProbeReq(dev
, buf
, ta
);
1487 /* Probe response */
1488 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
1489 /* if enable 802.11h and current channel is silent but receive probe response from other AP */
1490 if (((wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1491 & ZM_REG_FLAG_CHANNEL_CSA
) != 0) && wd
->sta
.DFSEnable
)
1493 wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1494 &= ~(ZM_REG_FLAG_CHANNEL_CSA
& ZM_REG_FLAG_CHANNEL_PASSIVE
);
1496 zfStaProcessProbeRsp(dev
, buf
, AddInfo
);
1499 case ZM_WLAN_FRAME_TYPE_ATIM
:
1500 zfStaProcessAtim(dev
, buf
);
1503 case ZM_WLAN_FRAME_TYPE_ACTION
:
1504 zm_msg0_mm(ZM_LV_2
, "ProcessActionMgtFrame");
1505 zfStaProcessAction(dev
, buf
);
1511 /************************************************************************/
1513 /* FUNCTION DESCRIPTION zfProcessProbeReq */
1514 /* Process probe request management frame. */
1517 /* dev : device pointer */
1518 /* buf : auth frame buffer */
1524 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1526 /************************************************************************/
1527 void zfProcessProbeReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t
* src
)
1535 zmw_get_wlan_dev(dev
);
1537 /* check mode : AP/IBSS */
1538 if ((wd
->wlanMode
!= ZM_MODE_AP
) && (wd
->wlanMode
!= ZM_MODE_IBSS
))
1540 zm_msg0_mm(ZM_LV_3
, "Ignore probe req");
1544 if ((wd
->wlanMode
!= ZM_MODE_AP
) && (wd
->sta
.adapterState
== ZM_STA_STATE_DISCONNECT
))
1546 zm_msg0_mm(ZM_LV_3
, "Packets dropped due to disconnect state");
1550 if ( wd
->wlanMode
== ZM_MODE_IBSS
)
1552 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBERSP
, src
, 0, 0, 0);
1558 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SSID
);
1559 if (offset
== 0xffff)
1561 zm_msg0_mm(ZM_LV_3
, "probe req SSID not found");
1565 len
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1567 for (i
=0; i
<ZM_MAX_AP_SUPPORT
; i
++)
1569 if ((wd
->ap
.apBitmap
& (1<<i
)) != 0)
1571 zm_msg1_mm(ZM_LV_3
, "len=", len
);
1573 /* boardcast SSID */
1576 if (wd
->ap
.hideSsid
[i
] == 0)
1581 /* Not broadcast SSID */
1582 else if (wd
->ap
.ssidLen
[i
] == len
)
1584 for (j
=0; j
<len
; j
++)
1586 ch
= zmw_rx_buf_readb(dev
, buf
, offset
+2+j
);
1587 if (ch
!= wd
->ap
.ssid
[i
][j
])
1599 /* Send probe response */
1600 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBERSP
, src
, i
, 0, i
);
1606 /************************************************************************/
1608 /* FUNCTION DESCRIPTION zfProcessProbeRsp */
1609 /* Process probe response management frame. */
1612 /* dev : device pointer */
1613 /* buf : auth frame buffer */
1614 /* AddInfo : Rx Header and Rx Mac Status */
1620 /* Aress Yang ZyDAS Technology Corporation 2006.11 */
1622 /************************************************************************/
1623 void zfProcessProbeRsp(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
)
1625 /* Gather scan result */
1626 /* Parse TIM and send PS-POLL in power saving mode */
1627 struct zsWlanProbeRspFrameHeader
* pProbeRspHeader
;
1628 struct zsBssInfo
* pBssInfo
;
1629 u8_t pBuf
[sizeof(struct zsWlanProbeRspFrameHeader
)];
1632 zmw_get_wlan_dev(dev
);
1634 zmw_declare_for_critical_section();
1636 zfCopyFromRxBuffer(dev
, buf
, pBuf
, 0,
1637 sizeof(struct zsWlanProbeRspFrameHeader
));
1638 pProbeRspHeader
= (struct zsWlanProbeRspFrameHeader
*) pBuf
;
1640 zmw_enter_critical_section(dev
);
1642 //zm_debug_msg1("bss count = ", wd->sta.bssList.bssCount);
1644 pBssInfo
= zfStaFindBssInfo(dev
, buf
, pProbeRspHeader
);
1646 //if ( i == wd->sta.bssList.bssCount )
1647 if ( pBssInfo
== NULL
)
1649 /* Allocate a new entry if BSS not in the scan list */
1650 pBssInfo
= zfBssInfoAllocate(dev
);
1651 if (pBssInfo
!= NULL
)
1653 res
= zfStaInitBssInfo(dev
, buf
, pProbeRspHeader
, pBssInfo
, AddInfo
, 0);
1654 //zfDumpSSID(pBssInfo->ssid[1], &(pBssInfo->ssid[2]));
1657 zfBssInfoFree(dev
, pBssInfo
);
1661 zfBssInfoInsertToList(dev
, pBssInfo
);
1667 res
= zfStaInitBssInfo(dev
, buf
, pProbeRspHeader
, pBssInfo
, AddInfo
, 1);
1670 zfBssInfoRemoveFromList(dev
, pBssInfo
);
1671 zfBssInfoFree(dev
, pBssInfo
);
1673 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
1677 // It would reset the alive counter if the peer station is found!
1678 zfStaFindFreeOpposite(dev
, (u16_t
*)pBssInfo
->macaddr
, &idx
);
1682 zmw_leave_critical_section(dev
);
1687 /************************************************************************/
1689 /* FUNCTION DESCRIPTION zfSendProbeReq */
1690 /* Send probe request management frame. */
1693 /* dev : device pointer */
1700 /* Ji-Huang Lee ZyDAS Technology Corporation 2005.11 */
1702 /************************************************************************/
1704 u16_t
zfSendProbeReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t bWithSSID
)
1706 zmw_get_wlan_dev(dev
);
1707 zmw_declare_for_critical_section();
1711 if (bWithSSID
== 0) /* broadcast ssid */
1713 //zmw_leave_critical_section(dev);
1714 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1715 zmw_tx_buf_writeb(dev
, buf
, offset
++, 0); /* length = 0 */
1719 zmw_enter_critical_section(dev
);
1720 if (wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
== 0)
1722 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1723 zmw_tx_buf_writeb(dev
, buf
, offset
++, 0); /* length = 0 */
1727 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1728 zmw_tx_buf_writeb(dev
, buf
, offset
++,
1729 wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
);
1730 zfCopyToIntTxBuffer(dev
, buf
,
1731 wd
->ws
.probingSsidList
[bWithSSID
-1].ssid
,
1733 wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
); /* ssid */
1734 offset
+= wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
;
1736 zmw_leave_critical_section(dev
);
1739 /* Supported rates */
1740 if ( wd
->sta
.currentFrequency
< 3000 )
1742 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1743 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1745 if (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) {
1746 if (wd
->wlanMode
== ZM_MODE_IBSS
) {
1747 if (wd
->wfc
.bIbssGMode
) {
1748 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1749 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1752 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1753 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1759 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1760 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1767 /************************************************************************/
1769 /* FUNCTION DESCRIPTION zfUpdateDefaultQosParameter */
1770 /* Update TxQs CWMIN, CWMAX, AIFS and TXO to WME default value. */
1773 /* dev : device pointer */
1774 /* mode : 0=>STA, 1=>AP */
1780 /* Stephen ZyDAS Technology Corporation 2006.6 */
1782 /************************************************************************/
1783 void zfUpdateDefaultQosParameter(zdev_t
* dev
, u8_t mode
)
1790 /* WMM parameter for STA */
1794 aifs
[0] = 3 * 9 + 10;
1799 aifs
[1] = 7 * 9 + 10;
1804 aifs
[2] = 2 * 9 + 10;
1809 aifs
[3] = 2 * 9 + 10;
1814 aifs
[4] = 2 * 9 + 10;
1817 /* WMM parameter for AP */
1821 aifs
[3] = 1 * 9 + 10;
1822 aifs
[4] = 1 * 9 + 10;
1824 zfHpUpdateQosParameter(dev
, cwmin
, cwmax
, aifs
, txop
);
1827 u16_t
zfFindATHExtCap(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
, u8_t subtype
)
1836 /* Get offset of first element */
1837 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
1839 offset
= zgElementOffsetTable
[subType
];
1845 /* Plus wlan header */
1848 bufLen
= zfwBufGetSize(dev
, buf
);
1851 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
1853 /* Search target element */
1854 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
1855 if (id
== ZM_WLAN_EID_WIFI_IE
)
1858 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1859 if (elen
> bufLen
- offset
)
1861 /* Element length error */
1870 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1871 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x03)
1872 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x7f)
1873 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+5)) == type
))
1876 if ( subtype
!= 0xff )
1878 tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+6);
1879 if (tmp
== subtype
)
1891 /* Advance to next element */
1892 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1902 u16_t
zfFindBrdcmMrvlRlnkExtCap(zdev_t
* dev
, zbuf_t
* buf
)
1911 /* Get offset of first element */
1912 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
1914 offset
= zgElementOffsetTable
[subType
];
1920 /* Plus wlan header */
1923 bufLen
= zfwBufGetSize(dev
, buf
);
1926 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
1928 /* Search target element */
1929 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
1930 if (id
== ZM_WLAN_EID_WIFI_IE
)
1933 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1934 if (elen
> bufLen
- offset
)
1936 /* Element length error */
1945 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1946 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x10)
1947 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x18))
1952 else if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1953 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
1954 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x43))
1960 else if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == 0x7F)
1963 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1964 if (elen
> bufLen
- offset
)
1966 /* Element length error */
1975 tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
1983 /* Advance to next element */
1984 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1994 u16_t
zfFindMarvelExtCap(zdev_t
* dev
, zbuf_t
* buf
)
2003 /* Get offset of first element */
2004 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
2006 offset
= zgElementOffsetTable
[subType
];
2012 /* Plus wlan header */
2015 bufLen
= zfwBufGetSize(dev
, buf
);
2018 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
2020 /* Search target element */
2021 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
2022 if (id
== ZM_WLAN_EID_WIFI_IE
)
2025 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2026 if (elen
>(bufLen
- offset
))
2028 /* Element length error */
2037 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
2038 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
2039 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x43))
2046 /* Advance to next element */
2047 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2057 u16_t
zfFindBroadcomExtCap(zdev_t
* dev
, zbuf_t
* buf
)
2066 /* Get offset of first element */
2067 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
2069 offset
= zgElementOffsetTable
[subType
];
2075 /* Plus wlan header */
2078 bufLen
= zfwBufGetSize(dev
, buf
);
2081 while((offset
+2) < bufLen
) // including element ID and length (2bytes)
2083 /* Search target element */
2084 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
2085 if (id
== ZM_WLAN_EID_WIFI_IE
)
2088 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2089 if (elen
> (bufLen
- offset
))
2091 /* Element length error */
2100 if ( ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
2101 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x10)
2102 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x18) )
2108 /* Advance to next element */
2109 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2121 u16_t
zfFindRlnkExtCap(zdev_t
* dev
, zbuf_t
* buf
)
2130 /* Get offset of first element */
2131 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
2133 offset
= zgElementOffsetTable
[subType
];
2139 /* Plus wlan header */
2142 bufLen
= zfwBufGetSize(dev
, buf
);
2145 while((offset
+2) < bufLen
) // including element ID and length (2bytes)
2147 /* Search target element */
2148 id
= zmw_rx_buf_readb(dev
, buf
, offset
);
2152 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2153 if (elen
> bufLen
- offset
)
2155 /* Element length error */
2164 tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
2172 /* Advance to next element */
2173 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);