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 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
91 /* Plus wlan header */
96 if ((eid
== ZM_WLAN_EID_HT_CAPABILITY
) ||
97 (eid
== ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
))
100 eid
= ZM_WLAN_EID_WPA_IE
;
105 bufLen
= zfwBufGetSize(dev
, buf
);
107 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
109 /* Search target element */
110 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == eid
)
113 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
115 /* Element length error */
119 if ( elen
== 0 && eid
!= ZM_WLAN_EID_SSID
)
121 /* Element length error */
125 if ( eid
== ZM_WLAN_EID_WPA_IE
)
127 /* avoid sta to be thought use 11n when find a WPA_IE */
128 if ( (HTType
== 0) && zfRxBufferEqualToStr(dev
, buf
, oui
, offset
+2, 4) )
136 if ((HTType
== 1) && ( zfRxBufferEqualToStr(dev
, buf
, oui11n
, offset
+2, 3) ))
138 if ( zmw_rx_buf_readb(dev
, buf
, offset
+5) == HTEid
)
150 /* Advance to next element */
152 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
154 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
166 /************************************************************************/
168 /* FUNCTION DESCRIPTION zfFindWifiElement */
169 /* Find a specific Wifi element in management frame */
172 /* dev : device pointer */
173 /* buf : management frame buffer */
174 /* type : OUI type */
175 /* subType : OUI subtype */
178 /* byte offset of target element */
179 /* or 0xffff if not found */
182 /* Stephen Chen ZyDAS Technology Corporation 2006.1 */
184 /************************************************************************/
185 u16_t
zfFindWifiElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
, u8_t subtype
)
194 /* Get offset of first element */
195 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
197 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
202 /* Plus wlan header */
205 bufLen
= zfwBufGetSize(dev
, buf
);
207 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
209 /* Search target element */
210 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_WIFI_IE
)
213 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
215 /* Element length error */
224 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
225 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
226 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0xF2)
227 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+5)) == type
))
230 if ( subtype
!= 0xff )
232 if ( (tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+6)) == subtype
)
243 /* Advance to next element */
244 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
253 u16_t
zfRemoveElement(zdev_t
* dev
, u8_t
* buf
, u16_t size
, u8_t eid
)
258 u8_t oui
[4] = {0x00, 0x50, 0xf2, 0x01};
259 u8_t oui11n
[3] = {0x00,0x90,0x4C};
262 if ((eid
== ZM_WLAN_EID_HT_CAPABILITY
) ||
263 (eid
== ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
))
266 eid
= ZM_WLAN_EID_WPA_IE
;
270 while (offset
< size
)
272 elen
= *(buf
+offset
+1);
274 if (*(buf
+offset
) == eid
)
276 if ( eid
== ZM_WLAN_EID_WPA_IE
)
279 && (*(buf
+offset
+2) == oui
[0])
280 && (*(buf
+offset
+3) == oui
[1])
281 && (*(buf
+offset
+4) == oui
[2])
282 && (*(buf
+offset
+5) == oui
[3]) )
284 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
285 return (size
-elen
-2);
289 && (*(buf
+offset
+2) == oui11n
[0])
290 && (*(buf
+offset
+3) == oui11n
[1])
291 && (*(buf
+offset
+4) == oui11n
[2])
292 && (*(buf
+offset
+5) == HTEid
) )
294 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
295 return (size
-elen
-2);
300 zfMemoryMove(buf
+offset
, buf
+offset
+elen
+2, size
-offset
-elen
-2);
301 return (size
-elen
-2);
311 u16_t
zfUpdateElement(zdev_t
* dev
, u8_t
* buf
, u16_t size
, u8_t
* updateeid
)
316 while (offset
< size
) {
317 elen
= *(buf
+offset
+1);
319 if (*(buf
+offset
) == updateeid
[0]) {
320 if (updateeid
[1] <= elen
) {
321 zfMemoryMove(buf
+offset
, updateeid
, updateeid
[1]+2);
322 zfMemoryMove(buf
+offset
+updateeid
[1]+2, buf
+offset
+elen
+2, size
-offset
-elen
-2);
324 return size
-(elen
-updateeid
[1]);
326 zfMemoryMove(buf
+offset
+updateeid
[1]+2, buf
+offset
+elen
+2, size
-offset
-elen
-2);
327 zfMemoryMove(buf
+offset
, updateeid
, updateeid
[1]+2);
329 return size
+(updateeid
[1]-elen
);
339 u16_t
zfFindSuperGElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
)
347 u8_t ouiSuperG
[6] = {0x00,0x03,0x7f,0x01, 0x01, 0x00};
349 zmw_get_wlan_dev(dev
);
351 /* Get offset of first element */
352 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
353 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
358 /* Plus wlan header */
361 bufLen
= zfwBufGetSize(dev
, buf
);
363 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
365 /* Search target element */
366 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_VENDOR_PRIVATE
)
369 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
371 /* Element length error */
380 if (zfRxBufferEqualToStr(dev
, buf
, ouiSuperG
, offset
+2, 6) && ( zmw_rx_buf_readb(dev
, buf
, offset
+1) >= 6))
382 /* super_feature 0:useFastFrame, 1:useCompression, 2:useTurboPrime */
383 super_feature
= zmw_rx_buf_readb(dev
, buf
, offset
+8);
384 if ((super_feature
& 0x01) || (super_feature
& 0x02) || (super_feature
& 0x04))
390 /* Advance to next element */
392 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
394 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
405 u16_t
zfFindXRElement(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
)
412 u8_t ouixr
[6] = {0x00,0x03,0x7f,0x03, 0x01, 0x00};
414 zmw_get_wlan_dev(dev
);
416 /* Get offset of first element */
417 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
418 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
423 /* Plus wlan header */
426 bufLen
= zfwBufGetSize(dev
, buf
);
428 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
430 /* Search target element */
431 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_VENDOR_PRIVATE
)
434 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
436 /* Element length error */
445 if (zfRxBufferEqualToStr(dev
, buf
, ouixr
, offset
+2, 6) && ( zmw_rx_buf_readb(dev
, buf
, offset
+1) >= 6))
450 /* Advance to next element */
452 elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
454 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
465 /************************************************************************/
467 /* FUNCTION DESCRIPTION zfMmAddIeSupportRate */
468 /* Add information element Support Rate to buffer. */
471 /* dev : device pointer */
472 /* buf : buffer to add information element */
473 /* offset : add information element from this offset */
474 /* eid : element ID */
475 /* rateSet : CCK or OFDM */
478 /* buffer offset after adding information element */
481 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
483 /************************************************************************/
484 u16_t
zfMmAddIeSupportRate(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t eid
, u8_t rateSet
)
489 zmw_get_wlan_dev(dev
);
491 //if ( (rateSet == ZM_RATE_SET_OFDM)&&((wd->gRate & 0xff) == 0) )
496 /* Information : Support Rate */
497 if ( rateSet
== ZM_RATE_SET_CCK
)
501 if ((wd
->bRate
& (0x1<<i
)) == (0x1<<i
))
502 //if ((0xf & (0x1<<i)) == (0x1<<i))
504 zmw_tx_buf_writeb(dev
, buf
, offset
+len
+2,
505 zg11bRateTbl
[i
]+((wd
->bRateBasic
& (0x1<<i
))<<(7-i
)));
510 else if ( rateSet
== ZM_RATE_SET_OFDM
)
514 if ((wd
->gRate
& (0x1<<i
)) == (0x1<<i
))
515 //if ((0xff & (0x1<<i)) == (0x1<<i))
517 zmw_tx_buf_writeb(dev
, buf
, offset
+len
+2,
518 zg11gRateTbl
[i
]+((wd
->gRateBasic
& (0x1<<i
))<<(7-i
)));
527 zmw_tx_buf_writeb(dev
, buf
, offset
, eid
);
530 zmw_tx_buf_writeb(dev
, buf
, offset
+1, len
);
539 /************************************************************************/
541 /* FUNCTION DESCRIPTION zfMmAddIeDs */
542 /* Add information element DS to buffer. */
545 /* dev : device pointer */
546 /* buf : buffer to add information element */
547 /* offset : add information element from this offset */
550 /* buffer offset after adding information element */
553 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
555 /************************************************************************/
556 u16_t
zfMmAddIeDs(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
558 zmw_get_wlan_dev(dev
);
561 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_DS
);
564 zmw_tx_buf_writeb(dev
, buf
, offset
++, 1);
566 /* Information : DS */
567 zmw_tx_buf_writeb(dev
, buf
, offset
++,
568 zfChFreqToNum(wd
->frequency
, NULL
));
574 /************************************************************************/
576 /* FUNCTION DESCRIPTION zfMmAddIeErp */
577 /* Add information element ERP to buffer. */
580 /* dev : device pointer */
581 /* buf : buffer to add information element */
582 /* offset : add information element from this offset */
585 /* buffer offset after adding information element */
588 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
590 /************************************************************************/
591 u16_t
zfMmAddIeErp(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
593 zmw_get_wlan_dev(dev
);
596 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_ERP
);
599 zmw_tx_buf_writeb(dev
, buf
, offset
++, 1);
601 /* Information : ERP */
602 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->erpElement
);
608 /************************************************************************/
610 /* FUNCTION DESCRIPTION zfMmAddIeWpa */
611 /* Add information element WPA to buffer. */
614 /* dev : device pointer */
615 /* buf : buffer to add information element */
616 /* offset : add information element from this offset */
619 /* buffer offset after adding information element */
622 /* Yuan-Gu Wei ZyDAS Technology Corporation 2006.2 */
624 /************************************************************************/
625 u16_t
zfMmAddIeWpa(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u16_t apId
)
627 //struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev);
630 zmw_get_wlan_dev(dev
);
633 //zmw_inttx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_WPA_IE);
636 //zmw_inttx_buf_writeb(dev, buf, offset++, wd->ap.wpaLen);
637 for(i
= 0; i
< wd
->ap
.wpaLen
[apId
]; i
++)
639 /* Information : WPA */
640 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->ap
.wpaIe
[apId
][i
]);
646 /************************************************************************/
648 /* FUNCTION DESCRIPTION zfMmAddHTCapability */
649 /* Add HT Capability Infomation to buffer. */
652 /* dev : device pointer */
653 /* buf : buffer to add information element */
654 /* offset : add information element from this offset */
657 /* buffer offset after adding information element */
660 /* Chao-Wen Yang ZyDAS Technology Corporation 2006.06 */
662 /************************************************************************/
663 u16_t
zfMmAddHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
665 u8_t OUI
[3] = {0x0,0x90,0x4C};
668 zmw_get_wlan_dev(dev
);
671 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_WPA_IE
);
673 if ( wd
->wlanMode
== ZM_MODE_AP
)
676 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.Length
+ 4);
679 for (i
= 0; i
< 3; i
++)
681 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
684 /* Element Type ID */
685 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.ElementID
);
687 /* HT Capability Data */
688 for (i
= 0; i
< 26; i
++)
690 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Byte
[i
+2]);
696 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.Length
+ 4);
699 for (i
= 0; i
< 3; i
++)
701 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
704 /* Element Type ID */
705 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.ElementID
);
707 /* HT Capability Data */
708 for (i
= 0; i
< 26; i
++)
710 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Byte
[i
+2]);
718 u16_t
zfMmAddPreNHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
720 //u8_t OUI[3] = {0x0,0x90,0x4C};
723 zmw_get_wlan_dev(dev
);
726 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_PREN2_EID_HTCAPABILITY
);
728 if ( wd
->wlanMode
== ZM_MODE_AP
)
731 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Data
.Length
);
733 /* HT Capability Data */
734 for (i
= 0; i
< 26; i
++)
736 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.HTCap
.Byte
[i
+2]);
742 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Data
.Length
);
744 /* HT Capability Data */
745 for (i
= 0; i
< 26; i
++)
747 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.HTCap
.Byte
[i
+2]);
754 /************************************************************************/
756 /* FUNCTION DESCRIPTION zfMmAddExtendedHTCapability */
757 /* Add Extended HT Capability Infomation to buffer. */
760 /* dev : device pointer */
761 /* buf : buffer to add information element */
762 /* offset : add information element from this offset */
765 /* buffer offset after adding information element */
768 /* Chao-Wen Yang ZyDAS Technology Corporation 2006.06 */
770 /************************************************************************/
771 u16_t
zfMmAddExtendedHTCapability(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
773 u8_t OUI
[3] = {0x0,0x90,0x4C};
776 zmw_get_wlan_dev(dev
);
779 zmw_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_WPA_IE
);
781 if ( wd
->wlanMode
== ZM_MODE_AP
)
784 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Data
.Length
+ 4);
787 for (i
= 0; i
< 3; i
++)
789 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
792 /* Element Type ID */
793 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Data
.ElementID
);
795 /* HT Capability Data */
796 for (i
= 0; i
< 22; i
++)
798 zmw_buf_writeb(dev
, buf
, offset
++, wd
->ap
.ExtHTCap
.Byte
[i
+2]);
804 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Data
.Length
+ 4);
807 for (i
= 0; i
< 3; i
++)
809 zmw_buf_writeb(dev
, buf
, offset
++, OUI
[i
]);
812 /* Element Type ID */
813 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Data
.ElementID
);
815 /* HT Capability Data */
816 for (i
= 0; i
< 22; i
++)
818 zmw_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ExtHTCap
.Byte
[i
+2]);
827 /************************************************************************/
829 /* FUNCTION DESCRIPTION zfSendMmFrame */
830 /* Send management frame. */
833 /* dev : device pointer */
834 /* frameType : management frame type */
835 /* dst : destination MAC address */
836 /* p1 : parameter 1 */
837 /* p2 : parameter 2 */
838 /* p3 : parameter 3 */
844 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
846 /************************************************************************/
847 /* probe req : p1=> bWithSSID, p2=>R, p3=>R */
848 /* probe rsp : p1=>R, p2=>R, p3=>VAP ID(AP) */
849 /* deauth : p1=>Reason Code, p2=>R, p3=>VAP ID(AP) */
850 /* Disasoc : p1=>Reason Code, p2=>R, p3=>VAP ID(AP) */
851 /* ATIM : p1=>R, p2=>R, p3=>R */
852 /* (re)asoc rsp : p1=>Status Code, p2=>AID, p3=>VAP ID(AP) */
853 /* asoc req : p1=>R, p2=>R, p3=>R */
854 /* reasoc req : p1=>AP MAC[0], p2=>AP MAC[1], p3=>AP MAC[2] */
855 /* auth : p1=>low=Algorithm, high=Transaction, p2=>Status, p3=>VAP ID */
856 void zfSendMmFrame(zdev_t
* dev
, u8_t frameType
, u16_t
* dst
,
857 u32_t p1
, u32_t p2
, u32_t p3
)
861 //struct zsAddrTbl addrTbl;
864 u16_t header
[(24+25+1)/2];
870 zmw_get_wlan_dev(dev
);
871 zmw_declare_for_critical_section();
873 zm_msg2_mm(ZM_LV_2
, "Send mm frame, type=", frameType
);
874 /* TBD : Maximum size of managment frame */
875 if ((buf
= zfwBufAllocate(dev
, 1024)) == NULL
)
877 zm_msg0_mm(ZM_LV_0
, "Alloc mm buf Fail!");
881 //Reserve room for wlan header
886 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
887 offset
= zfSendProbeReq(dev
, buf
, offset
, (u8_t
) p1
);
890 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
891 zm_msg0_mm(ZM_LV_3
, "probe rsp");
892 /* 24-31 Time Stamp : hardware WON'T fill this field */
893 zmw_tx_buf_writeh(dev
, buf
, offset
, 0);
894 zmw_tx_buf_writeh(dev
, buf
, offset
+2, 0);
895 zmw_tx_buf_writeh(dev
, buf
, offset
+4, 0);
896 zmw_tx_buf_writeh(dev
, buf
, offset
+6, 0);
899 /* Beacon Interval */
900 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->beaconInterval
);
903 if (wd
->wlanMode
== ZM_MODE_AP
)
907 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->ap
.capab
[vap
]);
910 offset
= zfApAddIeSsid(dev
, buf
, offset
, vap
);
915 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[0]);
916 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[1]);
918 offset
= zfStaAddIeSsid(dev
, buf
, offset
);
922 if ( wd
->frequency
< 3000 )
924 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
925 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
929 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
930 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
933 /* DS parameter set */
934 offset
= zfMmAddIeDs(dev
, buf
, offset
);
937 if ( wd
->wlanMode
== ZM_MODE_IBSS
)
939 offset
= zfStaAddIeIbss(dev
, buf
, offset
);
941 if (wd
->frequency
< 3000)
943 if( wd
->wfc
.bIbssGMode
944 && (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) ) // Only accompany with enabling a mode .
946 /* ERP Information */
948 offset
= zfMmAddIeErp(dev
, buf
, offset
);
951 /* Extended Supported Rates */
952 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
953 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
959 if ((wd
->wlanMode
== ZM_MODE_AP
)
960 && (wd
->ap
.wlanType
[vap
] != ZM_WLAN_TYPE_PURE_B
))
962 /* ERP Information */
963 offset
= zfMmAddIeErp(dev
, buf
, offset
);
965 /* Extended Supported Rates */
966 if ( wd
->frequency
< 3000 )
968 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
969 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
973 /* ERP Information */
974 //offset = zfMmAddIeErp(dev, buf, offset);
976 /* Extended Supported Rates */
977 //offset = zfMmAddIeSupportRate(dev, buf, offset,
978 // ZM_WLAN_EID_EXTENDED_RATE, ZM_RATE_SET_OFDM);
981 if (wd
->wlanMode
== ZM_MODE_AP
&& wd
->ap
.wpaSupport
[vap
] == 1)
983 offset
= zfMmAddIeWpa(dev
, buf
, offset
, vap
);
985 else if ( wd
->wlanMode
== ZM_MODE_IBSS
&& wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
987 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, ZM_WLAN_FRAME_TYPE_AUTH
);
991 if (wd
->wlanMode
== ZM_MODE_AP
)
993 if (wd
->ap
.qosMode
== 1)
995 offset
= zfApAddIeWmePara(dev
, buf
, offset
, vap
);
999 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
1003 /* TODO : Need to check if it is ok */
1004 /* HT Capabilities Info */
1005 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1007 /* Extended HT Capabilities Info */
1008 offset
= zfMmAddExtendedHTCapability(dev
, buf
, offset
);
1011 if ( wd
->sta
.ibssAdditionalIESize
)
1012 offset
= zfStaAddIbssAdditionalIE(dev
, buf
, offset
);
1015 case ZM_WLAN_FRAME_TYPE_AUTH
:
1019 offset
+= 4; // for reserving wep header
1023 /* Algotrithm Number */
1024 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p1
&0xffff));
1027 /* Transaction Number */
1028 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p1
>>16));
1032 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p2
);
1035 if (wd
->wlanMode
== ZM_MODE_AP
)
1040 /* Challenge Text => share-2 or share-3 */
1043 if (p2
== 0) //Status == success
1045 zmw_buf_writeh(dev
, buf
, offset
, 0x8010);
1047 /* share-2 : AP generate challenge text */
1048 for (i
=0; i
<128; i
++)
1050 wd
->ap
.challengeText
[i
] = (u8_t
)zfGetRandomNumber(dev
, 0);
1052 zfCopyToIntTxBuffer(dev
, buf
, wd
->ap
.challengeText
, offset
, 128);
1056 else if (p1
== 0x30001)
1058 /* share-3 : STA return challenge Text */
1059 zfCopyToIntTxBuffer(dev
, buf
, wd
->sta
.challengeText
, offset
, wd
->sta
.challengeText
[1]+2);
1060 offset
+= (wd
->sta
.challengeText
[1]+2);
1065 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1066 case ZM_WLAN_FRAME_TYPE_REASOCREQ
:
1068 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[0]);
1069 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[1]);
1071 /* Listen Interval */
1072 zmw_tx_buf_writeh(dev
, buf
, offset
, 0x0005);
1075 /* Reassocaited Request : Current AP address */
1076 if (frameType
== ZM_WLAN_FRAME_TYPE_REASOCREQ
)
1078 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[0]);
1080 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[1]);
1082 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[2]);
1087 offset
= zfStaAddIeSsid(dev
, buf
, offset
);
1090 if ( wd
->sta
.currentFrequency
< 3000 )
1093 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1098 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1101 if ((wd
->sta
.capability
[1] & ZM_BIT_0
) == 1)
1102 { //spectrum managment flag enable
1103 offset
= zfStaAddIePowerCap(dev
, buf
, offset
);
1104 offset
= zfStaAddIeSupportCh(dev
, buf
, offset
);
1107 if (wd
->sta
.currentFrequency
< 3000)
1109 /* Extended Supported Rates */
1110 if (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
))
1112 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1117 //offset = zfStaAddIeWpaRsn(dev, buf, offset, frameType);
1118 //Move to wrapper function, for OS difference--CWYang(m)
1119 //for windows wrapper, zfwStaAddIeWpaRsn() should be below:
1120 //u16_t zfwStaAddIeWpaRsn(zdev_t* dev, zbuf_t* buf, u16_t offset, u8_t frameType)
1122 // return zfStaAddIeWpaRsn(dev, buf, offset, frameType);
1124 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, frameType
);
1126 #ifdef ZM_ENABLE_CENC
1128 //if (wd->sta.encryMode == ZM_CENC)
1129 offset
= zfStaAddIeCenc(dev
, buf
, offset
);
1130 #endif //ZM_ENABLE_CENC
1131 if (((wd
->sta
.wmeEnabled
& ZM_STA_WME_ENABLE_BIT
) != 0) //WME enabled
1132 && ((wd
->sta
.apWmeCapability
& 0x1) != 0)) //WME AP
1134 if (((wd
->sta
.apWmeCapability
& 0x80) != 0) //UAPSD AP
1135 && ((wd
->sta
.wmeEnabled
& ZM_STA_UAPSD_ENABLE_BIT
) != 0)) //UAPSD enabled
1137 offset
= zfStaAddIeWmeInfo(dev
, buf
, offset
, wd
->sta
.wmeQosInfo
);
1141 offset
= zfStaAddIeWmeInfo(dev
, buf
, offset
, 0);
1146 if (wd
->sta
.EnableHT
!= 0)
1148 #ifndef ZM_DISABLE_AMSDU8K_SUPPORT
1150 if (wd
->sta
.wepStatus
== ZM_ENCRYPTION_WEP_DISABLED
)
1152 wd
->sta
.HTCap
.Data
.HtCapInfo
|= HTCAP_MaxAMSDULength
;
1156 wd
->sta
.HTCap
.Data
.HtCapInfo
&= (~HTCAP_MaxAMSDULength
);
1160 wd
->sta
.HTCap
.Data
.HtCapInfo
&= (~HTCAP_MaxAMSDULength
);
1163 /* HT Capabilities Info */
1164 if (wd
->BandWidth40
== 1) {
1165 wd
->sta
.HTCap
.Data
.HtCapInfo
|= HTCAP_SupChannelWidthSet
;
1168 wd
->sta
.HTCap
.Data
.HtCapInfo
&= ~HTCAP_SupChannelWidthSet
;
1169 //wd->sta.HTCap.Data.HtCapInfo |= HTCAP_SupChannelWidthSet;
1172 wd
->sta
.HTCap
.Data
.AMPDUParam
&= ~HTCAP_MaxRxAMPDU3
;
1173 wd
->sta
.HTCap
.Data
.AMPDUParam
|= HTCAP_MaxRxAMPDU3
;
1174 wd
->sta
.HTCap
.Data
.MCSSet
[1] = 0xFF; // MCS 8 ~ 15
1175 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1176 offset
= zfMmAddPreNHTCapability(dev
, buf
, offset
);
1178 /* Extended HT Capabilities Info */
1179 //offset = zfMmAddExtendedHTCapability(dev, buf, offset);
1183 //Store asoc request frame body, for VISTA only
1184 wd
->sta
.asocReqFrameBodySize
= ((offset
- hlen
) >
1185 ZM_CACHED_FRAMEBODY_SIZE
)?
1186 ZM_CACHED_FRAMEBODY_SIZE
:(offset
- hlen
);
1187 for (i
=0; i
<wd
->sta
.asocReqFrameBodySize
; i
++)
1189 wd
->sta
.asocReqFrameBody
[i
] = zmw_tx_buf_readb(dev
, buf
, i
+ hlen
);
1193 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1194 case ZM_WLAN_FRAME_TYPE_REASOCRSP
:
1198 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->ap
.capab
[vap
]);
1202 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p1
);
1206 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)(p2
|0xc000));
1210 if ( wd
->frequency
< 3000 )
1213 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1215 /* Extended Supported Rates */
1216 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1221 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
, ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1226 /* WME Parameters */
1227 if (wd
->wlanMode
== ZM_MODE_AP
)
1229 /* TODO : if WME STA then send WME parameter element */
1230 if (wd
->ap
.qosMode
== 1)
1232 offset
= zfApAddIeWmePara(dev
, buf
, offset
, vap
);
1237 /* HT Capabilities Info */
1238 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1240 /* Extended HT Capabilities Info */
1241 offset
= zfMmAddExtendedHTCapability(dev
, buf
, offset
);
1244 case ZM_WLAN_FRAME_TYPE_ATIM
:
1246 /* TODO : add two dumb bytes temporarily */
1250 case ZM_WLAN_FRAME_TYPE_QOS_NULL
:
1251 zmw_buf_writeh(dev
, buf
, offset
, 0x0010);
1255 case ZM_WLAN_DATA_FRAME
:
1258 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1259 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1260 if (wd
->wlanMode
== ZM_MODE_AP
)
1264 if ((aid
= zfApFindSta(dev
, dst
)) != 0xffff)
1266 zmw_enter_critical_section(dev
);
1267 /* Clear STA table */
1268 wd
->ap
.staTable
[aid
].valid
= 0;
1270 zmw_leave_critical_section(dev
);
1272 if (wd
->zfcbDisAsocNotify
!= NULL
)
1274 wd
->zfcbDisAsocNotify(dev
, (u8_t
*)dst
, vap
);
1279 zmw_tx_buf_writeh(dev
, buf
, offset
, (u16_t
)p1
);
1284 zfwBufSetSize(dev
, buf
, offset
);
1286 zm_msg2_mm(ZM_LV_2
, "management frame body size=", offset
-hlen
);
1289 zfTxGenMmHeader(dev
, frameType
, dst
, header
, offset
-hlen
, buf
, vap
, encrypt
);
1290 for (i
=0; i
<(hlen
>>1); i
++)
1292 zmw_tx_buf_writeh(dev
, buf
, i
*2, header
[i
]);
1295 /* Get buffer DMA address */
1296 //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0)
1297 //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0)
1302 zm_msg2_mm(ZM_LV_2
, "offset=", offset
);
1303 zm_msg2_mm(ZM_LV_2
, "hlen=", hlen
);
1304 //zm_msg2_mm(ZM_LV_2, "addrTblSize=", addrTblSize);
1305 //zm_msg2_mm(ZM_LV_2, "addrTbl.len[0]=", addrTbl.len[0]);
1306 //zm_msg2_mm(ZM_LV_2, "addrTbl.physAddrl[0]=", addrTbl.physAddrl[0]);
1307 //zm_msg2_mm(ZM_LV_2, "buf->data=", buf->data);
1310 if ((err
= zfHpSend(dev
, NULL
, 0, NULL
, 0, NULL
, 0, buf
, 0,
1311 ZM_INTERNAL_ALLOC_BUF
, 0, 0xff)) != ZM_SUCCESS
)
1316 zfPutVmmq(dev
, buf
);
1324 zfwBufFree(dev
, buf
, 0);
1330 /************************************************************************/
1332 /* FUNCTION DESCRIPTION zfProcessManagement */
1333 /* Process received management frame. */
1336 /* dev : device pointer */
1337 /* buf : received management frame buffer */
1343 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1345 /************************************************************************/
1346 void zfProcessManagement(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
) //CWYang(m)
1351 u16_t vap
= 0, index
= 0;
1354 zmw_get_wlan_dev(dev
);
1356 ra
[0] = zmw_rx_buf_readh(dev
, buf
, 4);
1357 ra
[1] = zmw_rx_buf_readh(dev
, buf
, 6);
1358 ra
[2] = zmw_rx_buf_readh(dev
, buf
, 8);
1360 ta
[0] = zmw_rx_buf_readh(dev
, buf
, 10);
1361 ta
[1] = zmw_rx_buf_readh(dev
, buf
, 12);
1362 ta
[2] = zmw_rx_buf_readh(dev
, buf
, 14);
1364 frameType
= zmw_rx_buf_readb(dev
, buf
, 0);
1366 if (wd
->wlanMode
== ZM_MODE_AP
)
1370 if ((ra
[0] & 0x1) != 1)
1372 /* AP : Find virtual AP */
1373 if ((index
= zfApFindSta(dev
, ta
)) != 0xffff)
1375 vap
= wd
->ap
.staTable
[index
].vap
;
1378 zm_msg2_mm(ZM_LV_2
, "vap=", vap
);
1381 /* Dispatch by frame type */
1385 case ZM_WLAN_FRAME_TYPE_BEACON
:
1386 zfApProcessBeacon(dev
, buf
);
1388 /* Authentication */
1389 case ZM_WLAN_FRAME_TYPE_AUTH
:
1390 zfApProcessAuth(dev
, buf
, ta
, vap
);
1392 /* Association request */
1393 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1394 /* Reassociation request */
1395 case ZM_WLAN_FRAME_TYPE_REASOCREQ
:
1396 zfApProcessAsocReq(dev
, buf
, ta
, vap
);
1398 /* Association response */
1399 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1400 //zfApProcessAsocRsp(dev, buf);
1402 /* Deauthentication */
1403 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1404 zfApProcessDeauth(dev
, buf
, ta
, vap
);
1406 /* Disassociation */
1407 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1408 zfApProcessDisasoc(dev
, buf
, ta
, vap
);
1411 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
1412 zfProcessProbeReq(dev
, buf
, ta
);
1414 /* Probe response */
1415 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
1416 zfApProcessProbeRsp(dev
, buf
, AddInfo
);
1419 case ZM_WLAN_FRAME_TYPE_ACTION
:
1420 zfApProcessAction(dev
, buf
);
1424 else //if ((wd->wlanMode == ZM_MODE_INFRASTRUCTURE) || (wd->wlanMode == ZM_MODE_IBSS))
1426 /* Dispatch by frame type */
1430 case ZM_WLAN_FRAME_TYPE_BEACON
:
1431 /* if enable 802.11h and current chanel is silent but receive beacon from other AP */
1432 if (((wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1433 & ZM_REG_FLAG_CHANNEL_CSA
) != 0) && wd
->sta
.DFSEnable
)
1435 wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1436 &= ~(ZM_REG_FLAG_CHANNEL_CSA
& ZM_REG_FLAG_CHANNEL_PASSIVE
);
1438 zfStaProcessBeacon(dev
, buf
, AddInfo
); //CWYang(m)
1440 /* Authentication */
1441 case ZM_WLAN_FRAME_TYPE_AUTH
:
1442 /* TODO : vap parameter is useless in STA mode, get rid of it */
1443 zfStaProcessAuth(dev
, buf
, ta
, 0);
1445 /* Association request */
1446 case ZM_WLAN_FRAME_TYPE_ASOCREQ
:
1447 /* TODO : vap parameter is useless in STA mode, get rid of it */
1448 zfStaProcessAsocReq(dev
, buf
, ta
, 0);
1450 /* Association response */
1451 case ZM_WLAN_FRAME_TYPE_ASOCRSP
:
1452 /* Reassociation request */
1453 case ZM_WLAN_FRAME_TYPE_REASOCRSP
:
1454 zfStaProcessAsocRsp(dev
, buf
);
1456 /* Deauthentication */
1457 case ZM_WLAN_FRAME_TYPE_DEAUTH
:
1458 zm_debug_msg0("Deauthentication received");
1459 zfStaProcessDeauth(dev
, buf
);
1461 /* Disassociation */
1462 case ZM_WLAN_FRAME_TYPE_DISASOC
:
1463 zm_debug_msg0("Disassociation received");
1464 zfStaProcessDisasoc(dev
, buf
);
1467 case ZM_WLAN_FRAME_TYPE_PROBEREQ
:
1468 zfProcessProbeReq(dev
, buf
, ta
);
1470 /* Probe response */
1471 case ZM_WLAN_FRAME_TYPE_PROBERSP
:
1472 /* if enable 802.11h and current chanel is silent but receive probe response from other AP */
1473 if (((wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1474 & ZM_REG_FLAG_CHANNEL_CSA
) != 0) && wd
->sta
.DFSEnable
)
1476 wd
->regulationTable
.allowChannel
[wd
->regulationTable
.CurChIndex
].channelFlags
1477 &= ~(ZM_REG_FLAG_CHANNEL_CSA
& ZM_REG_FLAG_CHANNEL_PASSIVE
);
1479 zfStaProcessProbeRsp(dev
, buf
, AddInfo
);
1482 case ZM_WLAN_FRAME_TYPE_ATIM
:
1483 zfStaProcessAtim(dev
, buf
);
1486 case ZM_WLAN_FRAME_TYPE_ACTION
:
1487 zm_msg0_mm(ZM_LV_2
, "ProcessActionMgtFrame");
1488 zfStaProcessAction(dev
, buf
);
1494 /************************************************************************/
1496 /* FUNCTION DESCRIPTION zfProcessProbeReq */
1497 /* Process probe request management frame. */
1500 /* dev : device pointer */
1501 /* buf : auth frame buffer */
1507 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
1509 /************************************************************************/
1510 void zfProcessProbeReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t
* src
)
1518 zmw_get_wlan_dev(dev
);
1520 /* check mode : AP/IBSS */
1521 if ((wd
->wlanMode
!= ZM_MODE_AP
) && (wd
->wlanMode
!= ZM_MODE_IBSS
))
1523 zm_msg0_mm(ZM_LV_3
, "Ignore probe req");
1527 if ((wd
->wlanMode
!= ZM_MODE_AP
) && (wd
->sta
.adapterState
== ZM_STA_STATE_DISCONNECT
))
1529 zm_msg0_mm(ZM_LV_3
, "Packets dropped due to disconnect state");
1533 if ( wd
->wlanMode
== ZM_MODE_IBSS
)
1535 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBERSP
, src
, 0, 0, 0);
1541 if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SSID
)) == 0xffff)
1543 zm_msg0_mm(ZM_LV_3
, "probe req SSID not found");
1547 len
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1549 for (i
=0; i
<ZM_MAX_AP_SUPPORT
; i
++)
1551 if ((wd
->ap
.apBitmap
& (1<<i
)) != 0)
1553 zm_msg1_mm(ZM_LV_3
, "len=", len
);
1555 /* boardcast SSID */
1558 if (wd
->ap
.hideSsid
[i
] == 0)
1563 /* Not broadcast SSID */
1564 else if (wd
->ap
.ssidLen
[i
] == len
)
1566 for (j
=0; j
<len
; j
++)
1568 if ((ch
= zmw_rx_buf_readb(dev
, buf
, offset
+2+j
))
1569 != wd
->ap
.ssid
[i
][j
])
1581 /* Send probe response */
1582 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBERSP
, src
, i
, 0, i
);
1588 /************************************************************************/
1590 /* FUNCTION DESCRIPTION zfProcessProbeRsp */
1591 /* Process probe response management frame. */
1594 /* dev : device pointer */
1595 /* buf : auth frame buffer */
1596 /* AddInfo : Rx Header and Rx Mac Status */
1602 /* Aress Yang ZyDAS Technology Corporation 2006.11 */
1604 /************************************************************************/
1605 void zfProcessProbeRsp(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
)
1607 /* Gather scan result */
1608 /* Parse TIM and send PS-POLL in power saving mode */
1609 struct zsWlanProbeRspFrameHeader
* pProbeRspHeader
;
1610 struct zsBssInfo
* pBssInfo
;
1611 u8_t pBuf
[sizeof(struct zsWlanProbeRspFrameHeader
)];
1614 zmw_get_wlan_dev(dev
);
1616 zmw_declare_for_critical_section();
1618 zfCopyFromRxBuffer(dev
, buf
, pBuf
, 0,
1619 sizeof(struct zsWlanProbeRspFrameHeader
));
1620 pProbeRspHeader
= (struct zsWlanProbeRspFrameHeader
*) pBuf
;
1622 zmw_enter_critical_section(dev
);
1624 //zm_debug_msg1("bss count = ", wd->sta.bssList.bssCount);
1626 pBssInfo
= zfStaFindBssInfo(dev
, buf
, pProbeRspHeader
);
1628 //if ( i == wd->sta.bssList.bssCount )
1629 if ( pBssInfo
== NULL
)
1631 /* Allocate a new entry if BSS not in the scan list */
1632 pBssInfo
= zfBssInfoAllocate(dev
);
1633 if (pBssInfo
!= NULL
)
1635 res
= zfStaInitBssInfo(dev
, buf
, pProbeRspHeader
, pBssInfo
, AddInfo
, 0);
1636 //zfDumpSSID(pBssInfo->ssid[1], &(pBssInfo->ssid[2]));
1639 zfBssInfoFree(dev
, pBssInfo
);
1643 zfBssInfoInsertToList(dev
, pBssInfo
);
1649 res
= zfStaInitBssInfo(dev
, buf
, pProbeRspHeader
, pBssInfo
, AddInfo
, 1);
1652 zfBssInfoRemoveFromList(dev
, pBssInfo
);
1653 zfBssInfoFree(dev
, pBssInfo
);
1655 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
1659 // It would reset the alive counter if the peer station is found!
1660 zfStaFindFreeOpposite(dev
, (u16_t
*)pBssInfo
->macaddr
, &idx
);
1664 zmw_leave_critical_section(dev
);
1669 /************************************************************************/
1671 /* FUNCTION DESCRIPTION zfSendProbeReq */
1672 /* Send probe request management frame. */
1675 /* dev : device pointer */
1682 /* Ji-Huang Lee ZyDAS Technology Corporation 2005.11 */
1684 /************************************************************************/
1686 u16_t
zfSendProbeReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t bWithSSID
)
1688 zmw_get_wlan_dev(dev
);
1689 zmw_declare_for_critical_section();
1693 if (bWithSSID
== 0) /* broadcast ssid */
1695 //zmw_leave_critical_section(dev);
1696 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1697 zmw_tx_buf_writeb(dev
, buf
, offset
++, 0); /* length = 0 */
1701 zmw_enter_critical_section(dev
);
1702 if (wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
== 0)
1704 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1705 zmw_tx_buf_writeb(dev
, buf
, offset
++, 0); /* length = 0 */
1709 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
1710 zmw_tx_buf_writeb(dev
, buf
, offset
++,
1711 wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
);
1712 zfCopyToIntTxBuffer(dev
, buf
,
1713 wd
->ws
.probingSsidList
[bWithSSID
-1].ssid
,
1715 wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
); /* ssid */
1716 offset
+= wd
->ws
.probingSsidList
[bWithSSID
-1].ssidLen
;
1718 zmw_leave_critical_section(dev
);
1721 /* Supported rates */
1722 if ( wd
->sta
.currentFrequency
< 3000 )
1724 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1725 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1727 if (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) {
1728 if (wd
->wlanMode
== ZM_MODE_IBSS
) {
1729 if (wd
->wfc
.bIbssGMode
) {
1730 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1731 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1734 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1735 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1741 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1742 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1749 /************************************************************************/
1751 /* FUNCTION DESCRIPTION zfUpdateDefaultQosParameter */
1752 /* Update TxQs CWMIN, CWMAX, AIFS and TXO to WME default value. */
1755 /* dev : device pointer */
1756 /* mode : 0=>STA, 1=>AP */
1762 /* Stephen ZyDAS Technology Corporation 2006.6 */
1764 /************************************************************************/
1765 void zfUpdateDefaultQosParameter(zdev_t
* dev
, u8_t mode
)
1772 /* WMM parameter for STA */
1776 aifs
[0] = 3 * 9 + 10;
1781 aifs
[1] = 7 * 9 + 10;
1786 aifs
[2] = 2 * 9 + 10;
1791 aifs
[3] = 2 * 9 + 10;
1796 aifs
[4] = 2 * 9 + 10;
1799 /* WMM parameter for AP */
1803 aifs
[3] = 1 * 9 + 10;
1804 aifs
[4] = 1 * 9 + 10;
1806 zfHpUpdateQosParameter(dev
, cwmin
, cwmax
, aifs
, txop
);
1809 u16_t
zfFindATHExtCap(zdev_t
* dev
, zbuf_t
* buf
, u8_t type
, u8_t subtype
)
1818 /* Get offset of first element */
1819 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
1821 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
1826 /* Plus wlan header */
1829 bufLen
= zfwBufGetSize(dev
, buf
);
1832 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
1834 /* Search target element */
1835 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_WIFI_IE
)
1838 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
1840 /* Element length error */
1849 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1850 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x03)
1851 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x7f)
1852 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+5)) == type
))
1855 if ( subtype
!= 0xff )
1857 if ( (tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+6)) == subtype
)
1869 /* Advance to next element */
1870 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
1879 u16_t
zfFindBrdcmMrvlRlnkExtCap(zdev_t
* dev
, zbuf_t
* buf
)
1888 /* Get offset of first element */
1889 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
1891 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
1896 /* Plus wlan header */
1899 bufLen
= zfwBufGetSize(dev
, buf
);
1902 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
1904 /* Search target element */
1905 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_WIFI_IE
)
1908 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
1910 /* Element length error */
1919 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1920 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x10)
1921 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x18))
1926 else if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
1927 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
1928 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x43))
1934 else if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == 0x7F)
1937 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
1939 /* Element length error */
1948 if ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x01)
1955 /* Advance to next element */
1956 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
1965 u16_t
zfFindMarvelExtCap(zdev_t
* dev
, zbuf_t
* buf
)
1974 /* Get offset of first element */
1975 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
1977 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
1982 /* Plus wlan header */
1985 bufLen
= zfwBufGetSize(dev
, buf
);
1988 while ((offset
+2)<bufLen
) // including element ID and length (2bytes)
1990 /* Search target element */
1991 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_WIFI_IE
)
1994 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1))>(bufLen
- offset
))
1996 /* Element length error */
2005 if (((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
2006 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x50)
2007 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x43))
2014 /* Advance to next element */
2015 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
2024 u16_t
zfFindBroadcomExtCap(zdev_t
* dev
, zbuf_t
* buf
)
2033 /* Get offset of first element */
2034 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
2036 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
2041 /* Plus wlan header */
2044 bufLen
= zfwBufGetSize(dev
, buf
);
2047 while((offset
+2) < bufLen
) // including element ID and length (2bytes)
2049 /* Search target element */
2050 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == ZM_WLAN_EID_WIFI_IE
)
2053 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) > (bufLen
- offset
))
2055 /* Element length error */
2064 if ( ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x00)
2065 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+3)) == 0x10)
2066 && ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+4)) == 0x18) )
2072 /* Advance to next element */
2073 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)
2084 u16_t
zfFindRlnkExtCap(zdev_t
* dev
, zbuf_t
* buf
)
2093 /* Get offset of first element */
2094 subType
= (zmw_rx_buf_readb(dev
, buf
, 0) >> 4);
2096 if ((offset
= zgElementOffsetTable
[subType
]) == 0xff)
2101 /* Plus wlan header */
2104 bufLen
= zfwBufGetSize(dev
, buf
);
2107 while((offset
+2) < bufLen
) // including element ID and length (2bytes)
2109 /* Search target element */
2110 if ((id
= zmw_rx_buf_readb(dev
, buf
, offset
)) == 0x7F)
2113 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) > (bufLen
- offset
))
2115 /* Element length error */
2124 if ((tmp
= zmw_rx_buf_readb(dev
, buf
, offset
+2)) == 0x01)
2131 /* Advance to next element */
2132 if ((elen
= zmw_rx_buf_readb(dev
, buf
, offset
+1)) == 0)