support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931 / mgmt / bss.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/bss.c#3 $
3 */
4
5 /*! \file   "bss.c"
6     \brief  This file contains the functions for creating BSS(AP)/IBSS(AdHoc).
7
8     This file contains the functions for BSS(AP)/IBSS(AdHoc). We may create a BSS/IBSS
9     network, or merge with exist IBSS network and sending Beacon Frame or reply
10     the Probe Response Frame for received Probe Request Frame.
11 */
12
13
14
15 /*
16 ** $Log: bss.c $
17 ** 
18 ** 08 29 2012 chinglan.wang
19 ** [ALPS00349664] [6577JB][WIFI] Phone can not connect to AP secured with AES via WPS in 802.11n Only
20 ** .
21 ** 
22 ** 07 26 2012 yuche.tsai
23 ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
24 ** Update driver code of ALPS.JB for hot-spot.
25  *
26  * 07 17 2012 yuche.tsai
27  * NULL
28  * Let netdev bring up.
29  *
30  * 07 17 2012 yuche.tsai
31  * NULL
32  * Compile no error before trial run.
33  *
34  * 06 14 2012 chinglan.wang
35  * NULL
36  * Fix the losing of the HT IE in assoc request..
37  *
38  * 06 13 2012 yuche.tsai
39  * NULL
40  * Update maintrunk driver.
41  * Add support for driver compose assoc request frame.
42  *
43  * 03 08 2012 yuche.tsai
44  * NULL
45  * Fix FW assert when start Hot-Spot.
46  *
47  * 03 02 2012 terry.wu
48  * NULL
49  * Snc CFG80211 modification for ICS migration from branch 2.2.
50  *
51  * 01 20 2012 chinglan.wang
52  * 03 02 2012 terry.wu
53  * NULL
54  * Fix the WPA-PSK TKIP and WPA2-PSK AES security mode bug.
55  *
56  * NULL
57  * Sync CFG80211 modification from branch 2,2.
58  *
59  * 01 15 2012 yuche.tsai
60  * NULL
61  * Fix wrong basic rate issue.
62  *
63  * 01 13 2012 yuche.tsai
64  * NULL
65  * WiFi Hot Spot Tethering for ICS ALPHA testing version.
66  *
67  * 11 03 2011 cm.chang
68  * [WCXRP00000997] [MT6620 Wi-Fi][Driver][FW] Handle change of BSS preamble type and slot time
69  * Always set short slot time to TRUE initially in AP mode
70  *
71  * 11 03 2011 wh.su
72  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
73  * change the DBGLOG for "\n" and "\r\n". LABEL to LOUD for XLOG
74  *
75  * 09 14 2011 yuche.tsai
76  * NULL
77  * Add P2P IE in assoc response.
78  *
79  * 04 18 2011 terry.wu
80  * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
81  * Remove flag CFG_WIFI_DIRECT_MOVED.
82  *
83  * 04 12 2011 eddie.chen
84  * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
85  * Fix the sta index in processing security frame
86  * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
87  * Add debug message.
88  *
89  * 04 08 2011 eddie.chen
90  * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
91  * Fix for sigma
92  *
93  * 03 29 2011 eddie.chen
94  * [WCXRP00000608] [MT6620 Wi-Fi][DRV] Change wmm parameters in beacon
95  * Change wmm parameters in beacon.
96  *
97  * 03 29 2011 yuche.tsai
98  * [WCXRP00000607] [Volunteer Patch][MT6620][Driver] Coding Style Fix for klocwork scan.
99  * Fix klocwork issue.
100  *
101  * 03 19 2011 yuche.tsai
102  * [WCXRP00000581] [Volunteer Patch][MT6620][Driver] P2P IE in Assoc Req Issue
103  * Make assoc req to append P2P IE if wifi direct is enabled.
104  *
105  * 03 11 2011 chinglan.wang
106  * [WCXRP00000537] [MT6620 Wi-Fi][Driver] Can not connect to 802.11b/g/n mixed AP with WEP security.
107  * .
108  *
109  * 03 03 2011 george.huang
110  * [WCXRP00000508] [MT6620 Wi-Fi][Driver] aware of beacon MSDU will be free, after BSS deactivated
111  * .
112  *
113  * 03 03 2011 george.huang
114  * [WCXRP00000508] [MT6620 Wi-Fi][Driver] aware of beacon MSDU will be free, after BSS deactivated
115  * modify to handle if beacon MSDU been released when BSS deactivated
116  *
117  * 03 02 2011 wh.su
118  * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
119  * add code to let the beacon and probe response for Auto GO WSC .
120  *
121  * 03 02 2011 wh.su
122  * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
123  * Add code to send beacon and probe response WSC IE at Auto GO.
124  *
125  * 02 17 2011 eddie.chen
126  * [WCXRP00000458] [MT6620 Wi-Fi][Driver] BOW Concurrent - ProbeResp was exist in other channel
127  * 1) Chnage GetFrameAction decision when BSS is absent.
128  * 2) Check channel and resource in processing ProbeRequest
129  *
130  * 02 12 2011 yuche.tsai
131  * [WCXRP00000441] [Volunteer Patch][MT6620][Driver] BoW can not create desired station type when Hot Spot is enabled.
132  * bss should create station record type according to callers input.
133  *
134  * 02 11 2011 terry.wu
135  * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
136  * In p2p link function, check networktype before calling p2p function.
137  *
138  * 02 11 2011 terry.wu
139  * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
140  * Modify p2p link function to avoid assert.
141  *
142  * 01 26 2011 cm.chang
143  * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
144  * .
145  *
146  * 01 25 2011 yuche.tsai
147  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
148  * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
149  *
150  * 01 25 2011 eddie.chen
151  * [WCXRP00000385] [MT6620 Wi-Fi][DRV] Add destination decision for forwarding packets
152  * Fix the compile error in windows.
153  *
154  * 01 24 2011 eddie.chen
155  * [WCXRP00000385] [MT6620 Wi-Fi][DRV] Add destination decision for forwarding packets
156  * Add destination decision in AP mode.
157  *
158  * 01 24 2011 terry.wu
159  * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
160  * .Fix typo and missing entry
161  *
162  * 12 30 2010 eddie.chen
163  * [WCXRP00000322] Add WMM IE in beacon,
164
165 Add per station flow control when STA is in PS
166
167
168  * Fix  prBssInfo->aucCWminLog to  prBssInfo->aucCWminLogForBcast
169  *
170  * 12 29 2010 eddie.chen
171  * [WCXRP00000322] Add WMM IE in beacon,
172
173 Add per station flow control when STA is in PS
174
175
176  * Add WMM parameter for broadcast.
177  *
178  * 12 29 2010 eddie.chen
179  * [WCXRP00000322] Add WMM IE in beacon,
180 Add per station flow control when STA is in PS
181
182  * 1) PS flow control event
183  *
184  * 2) WMM IE in beacon, assoc resp, probe resp
185  *
186  * 11 29 2010 cp.wu
187  * [WCXRP00000210] [MT6620 Wi-Fi][Driver][FW] Set RCPI value in STA_REC for initial TX rate selection of auto-rate algorithm
188  * update ucRcpi of STA_RECORD_T for AIS when
189  * 1) Beacons for IBSS merge is received
190  * 2) Associate Response for a connecting peer is received
191  *
192  * 10 18 2010 cp.wu
193  * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
194  * use definition macro to replace hard-coded constant
195  *
196  * 10 08 2010 wh.su
197  * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
198  * update the frog's new p2p state machine.
199  *
200  * 09 28 2010 wh.su
201  * NULL
202  * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
203  *
204  * 09 27 2010 chinghwa.yu
205  * [WCXRP00000063] Update BCM CoEx design and settings[WCXRP00000065] Update BoW design and settings
206  * Update BCM/BoW design and settings.
207  *
208  * 09 16 2010 cm.chang
209  * NULL
210  * Change conditional compiling options for BOW
211  *
212  * 09 10 2010 cm.chang
213  * NULL
214  * Always update Beacon content if FW sync OBSS info
215  *
216  * 09 07 2010 wh.su
217  * NULL
218  * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
219  *
220  * 09 03 2010 kevin.huang
221  * NULL
222  * Refine #include sequence and solve recursive/nested #include issue
223  *
224  * 08 31 2010 kevin.huang
225  * NULL
226  * Use LINK LIST operation to process SCAN result
227  *
228  * 08 30 2010 cp.wu
229  * NULL
230  * eliminate klockwork errors
231  *
232  * 08 29 2010 yuche.tsai
233  * NULL
234  * Finish SLT TX/RX & Rate Changing Support.
235  *
236  * 08 24 2010 cm.chang
237  * NULL
238  * Support RLM initail channel of Ad-hoc, P2P and BOW
239  *
240  * 08 16 2010 yuche.tsai
241  * NULL
242  * Before composing Beacon IE, assign network type index for msdu info,
243  * this information is needed by RLM module while composing some RLM related IE field.
244  *
245  * 08 16 2010 cp.wu
246  * NULL
247  * Replace CFG_SUPPORT_BOW by CFG_ENABLE_BT_OVER_WIFI.
248  * There is no CFG_SUPPORT_BOW in driver domain source.
249  *
250  * 08 16 2010 kevin.huang
251  * NULL
252  * Refine AAA functions
253  *
254  * 08 12 2010 kevin.huang
255  * NULL
256  * Fix undefined pucDestAddr in bssUpdateBeaconContent()
257  *
258  * 08 12 2010 kevin.huang
259  * NULL
260  * Refine bssProcessProbeRequest() and bssSendBeaconProbeResponse()
261  *
262  * 08 11 2010 cp.wu
263  * NULL
264  * 1) do not use in-stack variable for beacon updating. (for MAUI porting)
265  * 2) extending scanning result to 64 instead of 48
266  *
267  * 08 02 2010 yuche.tsai
268  * NULL
269  * P2P Group Negotiation Code Check in.
270  *
271  * 08 02 2010 george.huang
272  * NULL
273  * add WMM-PS test related OID/ CMD handlers
274  *
275  * 07 26 2010 yuche.tsai
276  *
277  * Add support to RX probe response for P2P.
278  *
279  * 07 20 2010 cp.wu
280  *
281  * 1) bugfix: do not stop timer for join after switched into normal_tr state, for providing chance for DHCP handshasking
282  * 2) modify rsnPerformPolicySelection() invoking
283  *
284  * 07 19 2010 wh.su
285  *
286  * update for security supporting.
287  *
288  * 07 19 2010 cp.wu
289  *
290  * [WPD00003833] [MT6620 and MT5931] Driver migration.
291  * when IBSS is being merged-in, send command packet to PM for connected indication
292  *
293  * 07 19 2010 cp.wu
294  *
295  * [WPD00003833] [MT6620 and MT5931] Driver migration.
296  * Add Ad-Hoc support to AIS-FSM
297  *
298  * 07 14 2010 yarco.yang
299  *
300  * 1. Remove CFG_MQM_MIGRATION
301  * 2. Add CMD_UPDATE_WMM_PARMS command
302  *
303  * 07 08 2010 cp.wu
304  *
305  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
306  *
307  * 07 06 2010 george.huang
308  * [WPD00001556]Basic power managemenet function
309  * Update arguments for nicUpdateBeaconIETemplate()
310  *
311  * 06 29 2010 cp.wu
312  * [WPD00003833][MT6620 and MT5931] Driver migration
313  * 1) sync to. CMD/EVENT document v0.03
314  * 2) simplify DTIM period parsing in scan.c only, bss.c no longer parses it again.
315  * 3) send command packet to indicate FW-PM after
316  *     a) 1st beacon is received after AIS has connected to an AP
317  *     b) IBSS-ALONE has been created
318  *     c) IBSS-MERGE has occured
319  *
320  * 06 28 2010 cp.wu
321  * [WPD00003833][MT6620 and MT5931] Driver migration
322  * send MMPDU in basic rate.
323  *
324  * 06 25 2010 george.huang
325  * [WPD00001556]Basic power managemenet function
326  * Create beacon update path, with expose bssUpdateBeaconContent()
327  *
328  * 06 21 2010 yuche.tsai
329  * [WPD00003839][MT6620 5931][P2P] Feature migration
330  * Fix compile error while enable WIFI_DIRECT support.
331  *
332  * 06 21 2010 yarco.yang
333  * [WPD00003837][MT6620]Data Path Refine
334  * Support CFG_MQM_MIGRATION flag
335  *
336  * 06 21 2010 cp.wu
337  * [WPD00003833][MT6620 and MT5931] Driver migration
338  * enable RX management frame handling.
339  *
340  * 06 21 2010 cp.wu
341  * [WPD00003833][MT6620 and MT5931] Driver migration
342  * specify correct value for management frames.
343  *
344  * 06 18 2010 cm.chang
345  * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
346  * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
347  *
348  * 06 15 2010 cp.wu
349  * [WPD00003833][MT6620 and MT5931] Driver migration
350  * correct when ADHOC support is turned on.
351  *
352  * 06 15 2010 cp.wu
353  * [WPD00003833][MT6620 and MT5931] Driver migration
354  * add scan.c.
355  *
356  * 06 14 2010 cp.wu
357  * [WPD00003833][MT6620 and MT5931] Driver migration
358  * add management dispatching function table.
359  *
360  * 06 11 2010 cp.wu
361  * [WPD00003833][MT6620 and MT5931] Driver migration
362  * auth.c is migrated.
363  *
364  * 06 11 2010 cp.wu
365  * [WPD00003833][MT6620 and MT5931] Driver migration
366  * fix compilation error when WIFI_DIRECT is turned on
367  *
368  * 06 11 2010 cp.wu
369  * [WPD00003833][MT6620 and MT5931] Driver migration
370  * add bss.c.
371  *
372  * 06 04 2010 george.huang
373  * [BORA00000678][MT6620]WiFi LP integration
374  * [PM] Support U-APSD for STA mode
375  *
376  * 05 28 2010 kevin.huang
377  * [BORA00000794][WIFISYS][New Feature]Power Management Support
378  * Add ClientList handling API - bssClearClientList, bssAddStaRecToClientList
379  *
380  * 05 24 2010 kevin.huang
381  * [BORA00000794][WIFISYS][New Feature]Power Management Support
382  * Update bssProcessProbeRequest() to avoid redundant SSID IE {0,0} for IOT.
383  *
384  * 05 21 2010 kevin.huang
385  * [BORA00000794][WIFISYS][New Feature]Power Management Support
386  * Refine txmInitWtblTxRateTable() - set TX initial rate according to AP's operation rate set
387  *
388  * 05 18 2010 cm.chang
389  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
390  * Ad-hoc Beacon should not carry HT OP and OBSS IEs
391  *
392  * 05 14 2010 kevin.huang
393  * [BORA00000794][WIFISYS][New Feature]Power Management Support
394  * Use TX MGMT Frame API for sending PS NULL frame to avoid the TX Burst Mechanism in TX FW Frame API
395  *
396  * 05 14 2010 kevin.huang
397  * [BORA00000794][WIFISYS][New Feature]Power Management Support
398  * Seperate Beacon and ProbeResp IE array
399  *
400  * 05 12 2010 kevin.huang
401  * [BORA00000794][WIFISYS][New Feature]Power Management Support
402  * Add Power Management - Legacy PS-POLL support.
403  *
404  * 04 28 2010 tehuang.liu
405  * [BORA00000605][WIFISYS] Phase3 Integration
406  * Removed the use of compiling flag MQM_WMM_PARSING
407  *
408  * 04 27 2010 kevin.huang
409  * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
410  * Add Set Slot Time and Beacon Timeout Support for AdHoc Mode
411  *
412  * 04 24 2010 cm.chang
413  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
414  * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
415  *
416  * 04 22 2010 cm.chang
417  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
418  * First draft code to support protection in AP mode
419  *
420  * 04 20 2010 kevin.huang
421  * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
422  * Fix restart Beacon Timeout Func after connection diagnosis
423  *
424  * 04 19 2010 kevin.huang
425  * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
426  * Add Beacon Timeout Support and will send Null frame to diagnose connection
427  *
428  * 04 16 2010 wh.su
429  * [BORA00000680][MT6620] Support the statistic for Microsoft os query
430  * adding the wpa-none for ibss beacon.
431  *
432  * 04 15 2010 wh.su
433  * [BORA00000680][MT6620] Support the statistic for Microsoft os query
434  * fixed the protected bit at cap info for ad-hoc.
435  *
436  * 03 18 2010 kevin.huang
437  * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
438  * Rename the CFG flags
439  *
440  * 03 16 2010 kevin.huang
441  * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
442  * Add AdHoc Mode
443  *
444  * 02 26 2010 kevin.huang
445  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
446  * Update outgoing beacon's TX data rate
447  *
448  * 02 23 2010 kevin.huang
449  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
450  * Add DTIM count update while TX Beacon
451  *
452  * 02 05 2010 kevin.huang
453  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
454  * Modify code due to define - BAND_24G and specific BSS_INFO_T was changed
455  *
456  * 02 05 2010 kevin.huang
457  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
458  * Revise data structure to share the same BSS_INFO_T for avoiding coding error
459  *
460  * 02 04 2010 kevin.huang
461  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
462  * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
463 */
464
465 /*******************************************************************************
466 *                         C O M P I L E R   F L A G S
467 ********************************************************************************
468 */
469
470 /*******************************************************************************
471 *                    E X T E R N A L   R E F E R E N C E S
472 ********************************************************************************
473 */
474 #include "precomp.h"
475
476 /*******************************************************************************
477 *                              C O N S T A N T S
478 ********************************************************************************
479 */
480
481 /*******************************************************************************
482 *                             D A T A   T Y P E S
483 ********************************************************************************
484 */
485 /*******************************************************************************
486 *                            P U B L I C   D A T A
487 ********************************************************************************
488 */
489 #if (CFG_SUPPORT_ADHOC) || (CFG_SUPPORT_AAA)
490 APPEND_VAR_IE_ENTRY_T txBcnIETable[] = {
491     { (ELEM_HDR_LEN + (RATE_NUM - ELEM_MAX_LEN_SUP_RATES)), NULL,                           bssGenerateExtSuppRate_IE   }   /* 50 */
492    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_ERP),                    NULL,                           rlmRspGenerateErpIE         }   /* 42 */
493    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_HT_CAP),                 NULL,                           rlmRspGenerateHtCapIE       }   /* 45 */
494    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_HT_OP),                  NULL,                           rlmRspGenerateHtOpIE        }   /* 61 */
495 #if CFG_ENABLE_WIFI_DIRECT
496    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_OBSS_SCAN),              NULL,                           rlmRspGenerateObssScanIE    }   /* 74 */
497 #endif
498    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_EXT_CAP),                NULL,                           rlmRspGenerateExtCapIE      }   /* 127 */
499    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_WPA),                    NULL,                           rsnGenerateWpaNoneIE        }   /* 221 */
500    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_WMM_PARAM),              NULL,                           mqmGenerateWmmParamIE       }   /* 221 */
501 #if CFG_ENABLE_WIFI_DIRECT
502    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_WPA),                    NULL,                           rsnGenerateWPAIE            }   /* 221 */
503    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_RSN),                    NULL,                           rsnGenerateRSNIE            }   /* 48 */
504 #if 0 //LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
505    ,{ 0,                                                    p2pFuncCalculateExtra_IELenForBeacon, p2pFuncGenerateExtra_IEForBeacon  }   /* 221 */
506 #else
507    ,{ 0,                                                    p2pFuncCalculateP2p_IELenForBeacon, p2pFuncGenerateP2p_IEForBeacon  }   /* 221 */
508    ,{ 0,                                                    p2pFuncCalculateWSC_IELenForBeacon, p2pFuncGenerateWSC_IEForBeacon      }   /* 221 */
509 #endif
510 #endif /* CFG_ENABLE_WIFI_DIRECT */
511 };
512
513
514 APPEND_VAR_IE_ENTRY_T txProbRspIETable[] = {
515     { (ELEM_HDR_LEN + (RATE_NUM - ELEM_MAX_LEN_SUP_RATES)), NULL,                           bssGenerateExtSuppRate_IE   }   /* 50 */
516    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_ERP),                    NULL,                           rlmRspGenerateErpIE         }   /* 42 */
517    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_HT_CAP),                 NULL,                           rlmRspGenerateHtCapIE       }   /* 45 */
518    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_HT_OP),                  NULL,                           rlmRspGenerateHtOpIE        }   /* 61 */
519 #if CFG_ENABLE_WIFI_DIRECT
520    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_RSN),                    NULL,                           rsnGenerateRSNIE            }   /* 48 */
521    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_OBSS_SCAN),              NULL,                           rlmRspGenerateObssScanIE    }   /* 74 */
522 #endif
523    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_EXT_CAP),                NULL,                           rlmRspGenerateExtCapIE      }   /* 127 */
524    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_WPA),                    NULL,                           rsnGenerateWpaNoneIE        }   /* 221 */
525    ,{ (ELEM_HDR_LEN + ELEM_MAX_LEN_WMM_PARAM),              NULL,                           mqmGenerateWmmParamIE       }   /* 221 */
526 };
527
528 #endif /* CFG_SUPPORT_ADHOC || CFG_SUPPORT_AAA */
529
530
531 /*******************************************************************************
532 *                           P R I V A T E   D A T A
533 ********************************************************************************
534 */
535
536 /*******************************************************************************
537 *                                 M A C R O S
538 ********************************************************************************
539 */
540
541
542 /*******************************************************************************
543 *                   F U N C T I O N   D E C L A R A T I O N S
544 ********************************************************************************
545 */
546
547 /*******************************************************************************
548 *                              F U N C T I O N S
549 ********************************************************************************
550 */
551 /*----------------------------------------------------------------------------*/
552 /* Routines for all Operation Modes                                           */
553 /*----------------------------------------------------------------------------*/
554 /*----------------------------------------------------------------------------*/
555 /*!
556 * @brief This function will create or reset a STA_RECORD_T by given BSS_DESC_T for
557 *        Infrastructure or AdHoc Mode.
558 *
559 * @param[in] prAdapter              Pointer to the Adapter structure.
560 * @param[in] eStaType               Assign STA Type for this STA_RECORD_T
561 * @param[in] eNetTypeIndex          Assign Net Type Index for this STA_RECORD_T
562 * @param[in] prBssDesc              Received Beacon/ProbeResp from this STA
563 *
564 * @retval   Pointer to STA_RECORD_T
565 */
566 /*----------------------------------------------------------------------------*/
567 P_STA_RECORD_T
568 bssCreateStaRecFromBssDesc (
569     IN P_ADAPTER_T                  prAdapter,
570     IN ENUM_STA_TYPE_T              eStaType,
571     IN ENUM_NETWORK_TYPE_INDEX_T    eNetTypeIndex,
572     IN P_BSS_DESC_T                 prBssDesc
573     )
574 {
575     P_STA_RECORD_T prStaRec;
576     UINT_8 ucNonHTPhyTypeSet;
577
578
579     ASSERT(prBssDesc);
580
581     //4 <1> Get a valid STA_RECORD_T
582     prStaRec = cnmGetStaRecByAddress(prAdapter, (UINT_8) eNetTypeIndex,
583                                         prBssDesc->aucSrcAddr);
584     if (!prStaRec) {
585
586         prStaRec = cnmStaRecAlloc(prAdapter, (UINT_8) eNetTypeIndex);
587
588         /* TODO(Kevin): Error handling of allocation of STA_RECORD_T for
589          * exhausted case and do removal of unused STA_RECORD_T.
590          */
591
592         if(!prStaRec) {
593             ASSERT(FALSE);
594             return NULL;
595         }
596
597         ASSERT(prStaRec);
598
599         prStaRec->ucJoinFailureCount = 0;
600         /* TODO(Kevin): If this is an old entry, we may also reset the ucJoinFailureCount to 0.
601          */
602
603         COPY_MAC_ADDR(prStaRec->aucMacAddr, prBssDesc->aucSrcAddr);
604     }
605
606
607     //4 <2> Setup STA TYPE and NETWORK
608     prStaRec->eStaType = eStaType;
609
610     prStaRec->ucNetTypeIndex = eNetTypeIndex;
611
612
613     //4 <3> Update information from BSS_DESC_T to current P_STA_RECORD_T
614     prStaRec->u2CapInfo = prBssDesc->u2CapInfo;
615
616     prStaRec->u2OperationalRateSet = prBssDesc->u2OperationalRateSet;
617     prStaRec->u2BSSBasicRateSet = prBssDesc->u2BSSBasicRateSet;
618
619     prStaRec->ucPhyTypeSet = prBssDesc->ucPhyTypeSet;
620
621         if (!((prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_ENABLED) ||
622                 (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_KEY_ABSENT) ||
623                 (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION_DISABLED) ||
624                 (prAdapter->prGlueInfo->u2WSCAssocInfoIELen) ||
625                 (prAdapter->prGlueInfo->u2WapiAssocInfoIESz))) {
626                 DBGLOG(BSS, INFO, ("Ignore the HT Bit for TKIP as pairwise cipher configed!\n"));
627                 prStaRec->ucPhyTypeSet &= ~PHY_TYPE_BIT_HT;
628         }
629
630     prStaRec->ucDesiredPhyTypeSet = prStaRec->ucPhyTypeSet & prAdapter->rWifiVar.ucAvailablePhyTypeSet;
631
632     ucNonHTPhyTypeSet = prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11ABG;
633
634     /* Check for Target BSS's non HT Phy Types */
635     if (ucNonHTPhyTypeSet) {
636
637         if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_ERP) {
638             prStaRec->ucNonHTBasicPhyType = PHY_TYPE_ERP_INDEX;
639         }
640         else if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_OFDM) {
641             prStaRec->ucNonHTBasicPhyType = PHY_TYPE_OFDM_INDEX;
642         }
643         else /* if (ucNonHTPhyTypeSet & PHY_TYPE_HR_DSSS_INDEX) */ {
644             prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
645         }
646
647         prStaRec->fgHasBasicPhyType = TRUE;
648     }
649     else {
650         /* Use mandatory for 11N only BSS */
651         ASSERT(prStaRec->ucPhyTypeSet & PHY_TYPE_SET_802_11N);
652
653         {
654             /* TODO(Kevin): which value should we set for 11n ? ERP ? */
655             prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
656         }
657
658         prStaRec->fgHasBasicPhyType = FALSE;
659     }
660
661     /* Update non HT Desired Rate Set */
662     {
663         P_CONNECTION_SETTINGS_T prConnSettings;
664
665
666         prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
667
668         prStaRec->u2DesiredNonHTRateSet =
669             (prStaRec->u2OperationalRateSet & prConnSettings->u2DesiredNonHTRateSet);
670     }
671
672     //4 <4> Update information from BSS_DESC_T to current P_STA_RECORD_T
673     if (IS_AP_STA(prStaRec)) {
674         /* do not need to parse IE for DTIM,
675          * which have been parsed before inserting into BSS_DESC_T
676          */
677         if (prBssDesc->ucDTIMPeriod) {
678             prStaRec->ucDTIMPeriod = prBssDesc->ucDTIMPeriod;
679         }
680         else {
681             prStaRec->ucDTIMPeriod = 0; // Means that TIM was not parsed.
682         }
683     }
684
685
686     //4 <5> Update default value
687     prStaRec->fgDiagnoseConnection = FALSE;
688
689
690     //4 <6> Update default value for other Modules
691     /* Determine fgIsWmmSupported and fgIsUapsdSupported in STA_REC */
692     mqmProcessScanResult(prAdapter, prBssDesc, prStaRec);
693
694     return prStaRec;
695
696 } /* end of bssCreateStaRecFromBssDesc() */
697
698
699 /*----------------------------------------------------------------------------*/
700 /*!
701 * @brief This function will compose the Null Data frame.
702 *
703 * @param[in] prAdapter              Pointer to the Adapter structure.
704 * @param[in] pucBuffer              Pointer to the frame buffer.
705 * @param[in] prStaRec               Pointer to the STA_RECORD_T.
706 *
707 * @return (none)
708 */
709 /*----------------------------------------------------------------------------*/
710 VOID
711 bssComposeNullFrame (
712     IN P_ADAPTER_T      prAdapter,
713     IN PUINT_8          pucBuffer,
714     IN P_STA_RECORD_T   prStaRec
715     )
716 {
717     P_WLAN_MAC_HEADER_T prNullFrame;
718     P_BSS_INFO_T prBssInfo;
719     UINT_16 u2FrameCtrl;
720
721
722     ASSERT(pucBuffer);
723     ASSERT(prStaRec);
724     ASSERT(prStaRec->ucNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
725
726     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
727
728     ASSERT(prBssInfo);
729
730     prNullFrame = (P_WLAN_MAC_HEADER_T)pucBuffer;
731
732     //4 <1> Decide the Frame Control Field
733     u2FrameCtrl = MAC_FRAME_NULL;
734
735     if (IS_AP_STA(prStaRec)) {
736         u2FrameCtrl |= MASK_FC_TO_DS;
737
738         if (prStaRec->fgSetPwrMgtBit) {
739             u2FrameCtrl |= MASK_FC_PWR_MGT;
740         }
741     }
742     else if (IS_CLIENT_STA(prStaRec)) {
743         u2FrameCtrl |= MASK_FC_FROM_DS;
744     }
745     else if (IS_DLS_STA(prStaRec)) {
746         /* TODO(Kevin) */
747     }
748     else {
749         /* NOTE(Kevin): We won't send Null frame for IBSS */
750         ASSERT(0);
751         return;
752     }
753
754     //4 <2> Compose the Null frame
755     /* Fill the Frame Control field. */
756     //WLAN_SET_FIELD_16(&prNullFrame->u2FrameCtrl, u2FrameCtrl);
757     prNullFrame->u2FrameCtrl = u2FrameCtrl; // NOTE(Kevin): Optimized for ARM
758
759     /* Fill the Address 1 field with Target Peer Address. */
760     COPY_MAC_ADDR(prNullFrame->aucAddr1, prStaRec->aucMacAddr);
761
762     /* Fill the Address 2 field with our MAC Address. */
763     COPY_MAC_ADDR(prNullFrame->aucAddr2, prBssInfo->aucOwnMacAddr);
764
765     /* Fill the Address 3 field with Target BSSID. */
766     COPY_MAC_ADDR(prNullFrame->aucAddr3, prBssInfo->aucBSSID);
767
768     /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
769     prNullFrame->u2SeqCtrl = 0;
770
771     return;
772
773 } /* end of bssComposeNullFrameHeader() */
774
775
776 /*----------------------------------------------------------------------------*/
777 /*!
778 * @brief This function will compose the QoS Null Data frame.
779 *
780 * @param[in] prAdapter              Pointer to the Adapter structure.
781 * @param[in] pucBuffer              Pointer to the frame buffer.
782 * @param[in] prStaRec               Pointer to the STA_RECORD_T.
783 * @param[in] ucUP                   User Priority.
784 * @param[in] fgSetEOSP              Set the EOSP bit.
785 *
786 * @return (none)
787 */
788 /*----------------------------------------------------------------------------*/
789 VOID
790 bssComposeQoSNullFrame (
791     IN P_ADAPTER_T      prAdapter,
792     IN PUINT_8          pucBuffer,
793     IN P_STA_RECORD_T   prStaRec,
794     IN UINT_8           ucUP,
795     IN BOOLEAN          fgSetEOSP
796     )
797 {
798     P_WLAN_MAC_HEADER_QOS_T prQoSNullFrame;
799     P_BSS_INFO_T prBssInfo;
800     UINT_16 u2FrameCtrl;
801     UINT_16 u2QosControl;
802
803
804     ASSERT(pucBuffer);
805     ASSERT(prStaRec);
806     ASSERT(prStaRec->ucNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
807
808     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
809
810     ASSERT(prBssInfo);
811
812     prQoSNullFrame = (P_WLAN_MAC_HEADER_QOS_T)pucBuffer;
813
814     //4 <1> Decide the Frame Control Field
815     u2FrameCtrl = MAC_FRAME_QOS_NULL;
816
817     if (IS_AP_STA(prStaRec)) {
818         u2FrameCtrl |= MASK_FC_TO_DS;
819
820         if (prStaRec->fgSetPwrMgtBit) {
821             u2FrameCtrl |= MASK_FC_PWR_MGT;
822         }
823     }
824     else if (IS_CLIENT_STA(prStaRec)) {
825         u2FrameCtrl |= MASK_FC_FROM_DS;
826     }
827     else if (IS_DLS_STA(prStaRec)) {
828         /* TODO(Kevin) */
829     }
830     else {
831         /* NOTE(Kevin): We won't send QoS Null frame for IBSS */
832         ASSERT(0);
833         return;
834     }
835
836     //4 <2> Compose the QoS Null frame
837     /* Fill the Frame Control field. */
838     //WLAN_SET_FIELD_16(&prQoSNullFrame->u2FrameCtrl, u2FrameCtrl);
839     prQoSNullFrame->u2FrameCtrl = u2FrameCtrl; // NOTE(Kevin): Optimized for ARM
840
841     /* Fill the Address 1 field with Target Peer Address. */
842     COPY_MAC_ADDR(prQoSNullFrame->aucAddr1, prStaRec->aucMacAddr);
843
844     /* Fill the Address 2 field with our MAC Address. */
845     COPY_MAC_ADDR(prQoSNullFrame->aucAddr2, prBssInfo->aucOwnMacAddr);
846
847     /* Fill the Address 3 field with Target BSSID. */
848     COPY_MAC_ADDR(prQoSNullFrame->aucAddr3, prBssInfo->aucBSSID);
849
850     /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
851     prQoSNullFrame->u2SeqCtrl = 0;
852
853     u2QosControl = (UINT_16)(ucUP & WMM_QC_UP_MASK);
854
855     if (fgSetEOSP) {
856         u2QosControl |= WMM_QC_EOSP;
857     }
858
859     //WLAN_SET_FIELD_16(&prQoSNullFrame->u2QosCtrl, u2QosControl);
860     prQoSNullFrame->u2QosCtrl = u2QosControl; // NOTE(Kevin): Optimized for ARM
861
862     return;
863
864 } /* end of bssComposeQoSNullFrameHeader() */
865
866
867 /*----------------------------------------------------------------------------*/
868 /*!
869 * @brief Send the Null Frame
870 *
871 * @param[in] prAdapter          Pointer to the Adapter structure.
872 * @param[in] prStaRec           Pointer to the STA_RECORD_T
873 * @param[in] pfTxDoneHandler    TX Done call back function
874 *
875 * @retval WLAN_STATUS_RESOURCE  No available resources to send frame.
876 * @retval WLAN_STATUS_SUCCESS   Succe]ss.
877 */
878 /*----------------------------------------------------------------------------*/
879 WLAN_STATUS
880 bssSendNullFrame (
881     IN P_ADAPTER_T          prAdapter,
882     IN P_STA_RECORD_T       prStaRec,
883     IN PFN_TX_DONE_HANDLER  pfTxDoneHandler
884     )
885 {
886     P_MSDU_INFO_T prMsduInfo;
887     UINT_16 u2EstimatedFrameLen;
888
889
890     //4 <1> Allocate a PKT_INFO_T for Null Frame
891     /* Init with MGMT Header Length */
892     u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + \
893                           WLAN_MAC_HEADER_LEN;
894
895     /* Allocate a MSDU_INFO_T */
896     if ( (prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen)) == NULL) {
897         DBGLOG(BSS, WARN, ("No PKT_INFO_T for sending Null Frame.\n"));
898         return WLAN_STATUS_RESOURCES;
899     }
900
901     //4 <2> Compose Null frame in MSDU_INfO_T.
902     bssComposeNullFrame(prAdapter,
903             (PUINT_8)((UINT_32)prMsduInfo->prPacket + MAC_TX_RESERVED_FIELD),
904             prStaRec);
905 #if 0
906     //4 <3> Update information of MSDU_INFO_T
907     TXM_SET_DATA_PACKET( \
908     /* STA_REC ptr */       prStaRec, \
909     /* MSDU_INFO ptr */     prMsduInfo, \
910     /* MAC HDR ptr */       (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD), \
911     /* MAC HDR length */    WLAN_MAC_HEADER_LEN, \
912     /* PAYLOAD ptr */       (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_LEN), \
913     /* PAYLOAD length */    0, \
914     /* Network Type Index */(UINT_8)prStaRec->ucNetTypeIndex, \
915     /* TID */               0 /* BE: AC1 */, \
916     /* Flag 802.11 */       TRUE,\
917     /* Pkt arrival time */  0 /* TODO: Obtain the system time */, \
918     /* Resource TC */       0 /* Irrelevant */, \
919     /* Flag 802.1x */       FALSE,\
920     /* TX-done callback */  pfTxDoneHandler, \
921     /* PS forwarding type*/ PS_FORWARDING_TYPE_NON_PS, \
922     /* PS Session ID */     0           /* Irrelevant */, \
923     /* Flag fixed rate */   TRUE, \
924     /* Fixed tx rate */     g_aprBssInfo[prStaRec->ucNetTypeIndex]->ucHwDefaultFixedRateCode, \
925     /* Fixed-rate retry */  BSS_DEFAULT_CONN_TEST_NULL_FRAME_RETRY_LIMIT, \
926     /* PAL LLH */           0 /* Irrelevant */,\
927     /* ACL SN */            0 /* Irrelevant */,\
928     /* Flag No Ack */       FALSE \
929     );
930
931     /* Terminate with a NULL pointer */
932     NIC_HIF_TX_SET_NEXT_MSDU_INFO(prMsduInfo,NULL);
933
934     /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
935
936     /* Indicate the packet to TXM */
937     //4 <4> Inform TXM to send this Null frame.
938     txmSendFwDataPackets(prMsduInfo);
939 #endif
940
941     prMsduInfo->eSrc = TX_PACKET_MGMT;
942     prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_DATA;
943     prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
944     prMsduInfo->ucNetworkType = prStaRec->ucNetTypeIndex;
945     prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_LEN;
946     prMsduInfo->fgIs802_1x = FALSE;
947     prMsduInfo->fgIs802_11 = TRUE;
948     prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_LEN;
949     prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
950     prMsduInfo->pfTxDoneHandler = pfTxDoneHandler;
951     prMsduInfo->fgIsBasicRate = FALSE;
952
953     //4 <4> Inform TXM  to send this Null frame.
954     nicTxEnqueueMsdu(prAdapter, prMsduInfo);
955
956     return WLAN_STATUS_SUCCESS;
957
958 } /* end of bssSendNullFrame() */
959
960
961 /*----------------------------------------------------------------------------*/
962 /*!
963 * @brief Send the QoS Null Frame
964 *
965 * @param[in] prAdapter          Pointer to the Adapter structure.
966 * @param[in] prStaRec           Pointer to the STA_RECORD_T
967 * @param[in] pfTxDoneHandler    TX Done call back function
968 *
969 * @retval WLAN_STATUS_RESOURCE  No available resources to send frame.
970 * @retval WLAN_STATUS_SUCCESS   Success.
971 */
972 /*----------------------------------------------------------------------------*/
973 WLAN_STATUS
974 bssSendQoSNullFrame (
975     IN P_ADAPTER_T          prAdapter,
976     IN P_STA_RECORD_T       prStaRec,
977     IN UINT_8               ucUP,
978     IN PFN_TX_DONE_HANDLER  pfTxDoneHandler
979     )
980 {
981     P_MSDU_INFO_T prMsduInfo;
982     UINT_16 u2EstimatedFrameLen;
983
984
985     //4 <1> Allocate a PKT_INFO_T for Null Frame
986     /* Init with MGMT Header Length */
987     u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + \
988                           WLAN_MAC_HEADER_QOS_LEN;
989
990     /* Allocate a MSDU_INFO_T */
991     if ( (prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen)) == NULL) {
992         DBGLOG(BSS, WARN, ("No PKT_INFO_T for sending Null Frame.\n"));
993         return WLAN_STATUS_RESOURCES;
994     }
995
996     //4 <2> Compose Null frame in MSDU_INfO_T.
997     bssComposeQoSNullFrame(prAdapter,
998             (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
999             prStaRec,
1000             ucUP,
1001             FALSE);
1002 #if 0
1003     //4 <3> Update information of MSDU_INFO_T
1004     TXM_SET_DATA_PACKET( \
1005     /* STA_REC ptr */       prStaRec, \
1006     /* MSDU_INFO ptr */     prMsduInfo, \
1007     /* MAC HDR ptr */       (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD), \
1008     /* MAC HDR length */    WLAN_MAC_HEADER_QOS_LEN, \
1009     /* PAYLOAD ptr */       (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_QOS_LEN), \
1010     /* PAYLOAD length */    0, \
1011     /* Network Type Index */(UINT_8)prStaRec->ucNetTypeIndex, \
1012     /* TID */               0 /* BE: AC1 */, \
1013     /* Flag 802.11 */       TRUE,\
1014     /* Pkt arrival time */  0 /* TODO: Obtain the system time */, \
1015     /* Resource TC */       0 /* Irrelevant */, \
1016     /* Flag 802.1x */       FALSE,\
1017     /* TX-done callback */  pfTxDoneHandler, \
1018     /* PS forwarding type*/ PS_FORWARDING_TYPE_NON_PS, \
1019     /* PS Session ID */     0           /* Irrelevant */, \
1020     /* Flag fixed rate */   TRUE, \
1021     /* Fixed tx rate */     g_aprBssInfo[prStaRec->ucNetTypeIndex]->ucHwDefaultFixedRateCode, \
1022     /* Fixed-rate retry */  TXM_DEFAULT_DATA_FRAME_RETRY_LIMIT, \
1023     /* PAL LLH */           0 /* Irrelevant */,\
1024     /* ACL SN */            0 /* Irrelevant */,\
1025     /* Flag No Ack */       FALSE \
1026     );
1027
1028     /* Terminate with a NULL pointer */
1029     NIC_HIF_TX_SET_NEXT_MSDU_INFO(prMsduInfo,NULL);
1030
1031     /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
1032
1033     /* Indicate the packet to TXM */
1034     //4 <4> Inform TXM to send this Null frame.
1035     txmSendFwDataPackets(prMsduInfo);
1036 #endif
1037
1038     prMsduInfo->eSrc = TX_PACKET_MGMT;
1039     prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT;
1040     prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
1041     prMsduInfo->ucNetworkType = prStaRec->ucNetTypeIndex;
1042     prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_QOS_LEN;
1043     prMsduInfo->fgIs802_1x = FALSE;
1044     prMsduInfo->fgIs802_11 = TRUE;
1045     prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_QOS_LEN;
1046     prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
1047     prMsduInfo->pfTxDoneHandler = pfTxDoneHandler;
1048     prMsduInfo->fgIsBasicRate = TRUE;
1049
1050     //4 <4> Inform TXM  to send this Null frame.
1051     nicTxEnqueueMsdu(prAdapter, prMsduInfo);
1052
1053     return WLAN_STATUS_SUCCESS;
1054
1055 } /* end of bssSendQoSNullFrame() */
1056
1057
1058 #if (CFG_SUPPORT_ADHOC) || (CFG_SUPPORT_AAA)
1059 /*----------------------------------------------------------------------------*/
1060 /* Routines for both IBSS(AdHoc) and BSS(AP)                                  */
1061 /*----------------------------------------------------------------------------*/
1062 /*----------------------------------------------------------------------------*/
1063 /*!
1064 * @brief This function is used to generate Information Elements of Extended
1065 *        Support Rate
1066 *
1067 * @param[in] prAdapter      Pointer to the Adapter structure.
1068 * @param[in] prMsduInfo     Pointer to the composed MSDU_INFO_T.
1069 *
1070 * @return (none)
1071 */
1072 /*----------------------------------------------------------------------------*/
1073 VOID
1074 bssGenerateExtSuppRate_IE (
1075     IN P_ADAPTER_T      prAdapter,
1076     IN P_MSDU_INFO_T    prMsduInfo
1077     )
1078 {
1079     P_BSS_INFO_T prBssInfo;
1080     PUINT_8 pucBuffer;
1081     UINT_8 ucExtSupRatesLen;
1082
1083
1084     ASSERT(prMsduInfo);
1085
1086     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prMsduInfo->ucNetworkType]);
1087     ASSERT(prBssInfo);
1088
1089     pucBuffer = (PUINT_8)((UINT_32)prMsduInfo->prPacket +
1090                           (UINT_32)prMsduInfo->u2FrameLength);
1091     ASSERT(pucBuffer);
1092
1093     if (prBssInfo->ucAllSupportedRatesLen > ELEM_MAX_LEN_SUP_RATES) {
1094
1095         ucExtSupRatesLen = prBssInfo->ucAllSupportedRatesLen - ELEM_MAX_LEN_SUP_RATES;
1096     }
1097     else {
1098         ucExtSupRatesLen = 0;
1099     }
1100
1101     /* Fill the Extended Supported Rates element. */
1102     if (ucExtSupRatesLen) {
1103
1104         EXT_SUP_RATES_IE(pucBuffer)->ucId = ELEM_ID_EXTENDED_SUP_RATES;
1105         EXT_SUP_RATES_IE(pucBuffer)->ucLength = ucExtSupRatesLen;
1106
1107         kalMemCopy(EXT_SUP_RATES_IE(pucBuffer)->aucExtSupportedRates,
1108                    &prBssInfo->aucAllSupportedRates[ELEM_MAX_LEN_SUP_RATES],
1109                    ucExtSupRatesLen);
1110
1111         prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1112     }
1113
1114     return;
1115 } /* end of bssGenerateExtSuppRate_IE() */
1116
1117
1118 /*----------------------------------------------------------------------------*/
1119 /*!
1120 * @brief This function is used to compose Common Information Elements for Beacon
1121 *        or Probe Response Frame.
1122 *
1123 * @param[in] prMsduInfo     Pointer to the composed MSDU_INFO_T.
1124 * @param[in] prBssInfo      Pointer to the BSS_INFO_T.
1125 * @param[in] pucDestAddr    Pointer to the Destination Address, if NULL, means Beacon.
1126 *
1127 * @return (none)
1128 */
1129 /*----------------------------------------------------------------------------*/
1130 VOID
1131 bssBuildBeaconProbeRespFrameCommonIEs (
1132     IN P_MSDU_INFO_T    prMsduInfo,
1133     IN P_BSS_INFO_T     prBssInfo,
1134     IN PUINT_8          pucDestAddr
1135     )
1136 {
1137     PUINT_8 pucBuffer;
1138     UINT_8 ucSupRatesLen;
1139
1140
1141     ASSERT(prMsduInfo);
1142     ASSERT(prBssInfo);
1143
1144     pucBuffer = (PUINT_8)((UINT_32)prMsduInfo->prPacket +
1145                           (UINT_32)prMsduInfo->u2FrameLength);
1146     ASSERT(pucBuffer);
1147
1148     /* Compose the frame body of the Probe Response frame. */
1149     //4 <1> Fill the SSID element.
1150     SSID_IE(pucBuffer)->ucId = ELEM_ID_SSID;
1151     SSID_IE(pucBuffer)->ucLength = prBssInfo->ucSSIDLen;
1152     if (prBssInfo->ucSSIDLen) {
1153         kalMemCopy(SSID_IE(pucBuffer)->aucSSID, prBssInfo->aucSSID, prBssInfo->ucSSIDLen);
1154     }
1155
1156     prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1157     pucBuffer += IE_SIZE(pucBuffer);
1158
1159
1160     //4 <2> Fill the Supported Rates element.
1161     if (prBssInfo->ucAllSupportedRatesLen > ELEM_MAX_LEN_SUP_RATES) {
1162
1163         ucSupRatesLen = ELEM_MAX_LEN_SUP_RATES;
1164     }
1165     else {
1166         ucSupRatesLen = prBssInfo->ucAllSupportedRatesLen;
1167     }
1168
1169     if (ucSupRatesLen) {
1170         SUP_RATES_IE(pucBuffer)->ucId = ELEM_ID_SUP_RATES;
1171         SUP_RATES_IE(pucBuffer)->ucLength = ucSupRatesLen;
1172         kalMemCopy(SUP_RATES_IE(pucBuffer)->aucSupportedRates,
1173                    prBssInfo->aucAllSupportedRates,
1174                    ucSupRatesLen);
1175
1176         prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1177         pucBuffer += IE_SIZE(pucBuffer);
1178     }
1179
1180
1181     //4 <3> Fill the DS Parameter Set element.
1182     if (prBssInfo->eBand == BAND_2G4) {
1183         DS_PARAM_IE(pucBuffer)->ucId = ELEM_ID_DS_PARAM_SET;
1184         DS_PARAM_IE(pucBuffer)->ucLength = ELEM_MAX_LEN_DS_PARAMETER_SET;
1185         DS_PARAM_IE(pucBuffer)->ucCurrChnl = prBssInfo->ucPrimaryChannel;
1186
1187         prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1188         pucBuffer += IE_SIZE(pucBuffer);
1189     }
1190
1191
1192     //4 <4> IBSS Parameter Set element, ID: 6
1193     if (prBssInfo->eCurrentOPMode == OP_MODE_IBSS) {
1194         IBSS_PARAM_IE(pucBuffer)->ucId = ELEM_ID_IBSS_PARAM_SET;
1195         IBSS_PARAM_IE(pucBuffer)->ucLength = ELEM_MAX_LEN_IBSS_PARAMETER_SET;
1196         WLAN_SET_FIELD_16(&(IBSS_PARAM_IE(pucBuffer)->u2ATIMWindow), prBssInfo->u2ATIMWindow);
1197
1198         prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1199         pucBuffer += IE_SIZE(pucBuffer);
1200     }
1201
1202
1203     //4 <5> TIM element, ID: 5
1204     if ((!pucDestAddr) && // For Beacon only.
1205         (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
1206
1207 #if CFG_ENABLE_WIFI_DIRECT
1208         /*no fgIsP2PRegistered protect*/
1209         if (prBssInfo->ucNetTypeIndex == NETWORK_TYPE_P2P_INDEX) {
1210 #if 0
1211             P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
1212             UINT_8 ucBitmapControl = 0;
1213             UINT_32 u4N1, u4N2;
1214
1215
1216             prP2pSpecificBssInfo = &(prAdapter->rWifiVar.rP2pSpecificBssInfo);
1217
1218             // Clear existing value.
1219             prP2pSpecificBssInfo->ucBitmapCtrl = 0;
1220             kalMemZero(prP2pSpecificBssInfo->aucPartialVirtualBitmap,
1221                        sizeof(prP2pSpecificBssInfo->aucPartialVirtualBitmap));
1222
1223
1224             // IEEE 802.11 2007 - 7.3.2.6
1225             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
1226             TIM_IE(pucBuffer)->ucDTIMCount = prBssInfo->ucDTIMCount;
1227             TIM_IE(pucBuffer)->ucDTIMPeriod = prBssInfo->ucDTIMPeriod;
1228
1229             // Setup DTIM Count for next TBTT.
1230             if (prBssInfo->ucDTIMCount == 0) {
1231                 //3 *** pmQueryBufferedBCAST();
1232             }
1233
1234             //3 *** pmQueryBufferedPSNode();
1235             /* TODO(Kevin): Call PM Module here to loop all STA_RECORD_Ts and it
1236              * will call bssSetTIMBitmap to toggle the Bitmap.
1237              */
1238
1239             // Set Virtual Bitmap for UCAST
1240             u4N1 = (prP2pSpecificBssInfo->u2SmallestAID >> 4) << 1; // Find the largest even number.
1241             u4N2 = prP2pSpecificBssInfo->u2LargestAID >> 3; // Find the smallest number.
1242
1243             ASSERT(u4N2 >= u4N1);
1244
1245             kalMemCopy(TIM_IE(pucBuffer)->aucPartialVirtualMap,
1246                        &prP2pSpecificBssInfo->aucPartialVirtualBitmap[u4N1],
1247                        ((u4N2 - u4N1) + 1));
1248
1249             // Set Virtual Bitmap for BMCAST
1250             // BMC bit only indicated when DTIM count == 0.
1251             if (prBssInfo->ucDTIMCount == 0) {
1252                 ucBitmapControl = prP2pSpecificBssInfo->ucBitmapCtrl;
1253             }
1254             TIM_IE(pucBuffer)->ucBitmapControl = ucBitmapControl | (UINT_8)u4N1;
1255
1256             TIM_IE(pucBuffer)->ucLength = ((u4N2 - u4N1) + 4);
1257
1258             prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1259 #else
1260
1261             // IEEE 802.11 2007 - 7.3.2.6
1262             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
1263             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
1264             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
1265             TIM_IE(pucBuffer)->ucDTIMPeriod = prBssInfo->ucDTIMPeriod;
1266             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
1267
1268             prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
1269
1270 #endif
1271
1272         }
1273         else
1274 #endif /* CFG_ENABLE_WIFI_DIRECT */
1275         {
1276             /* NOTE(Kevin): 1. AIS - Didn't Support AP Mode.
1277              *              2. BOW - Didn't Support BCAST and PS.
1278              */
1279         }
1280
1281
1282
1283     }
1284
1285     return;
1286 } /* end of bssBuildBeaconProbeRespFrameCommonIEs() */
1287
1288
1289 /*----------------------------------------------------------------------------*/
1290 /*!
1291 * @brief This function will compose the Beacon/Probe Response frame header and
1292 *        its fixed fields.
1293 *
1294 * @param[in] pucBuffer              Pointer to the frame buffer.
1295 * @param[in] pucDestAddr            Pointer to the Destination Address, if NULL, means Beacon.
1296 * @param[in] pucOwnMACAddress       Given Our MAC Address.
1297 * @param[in] pucBSSID               Given BSSID of the BSS.
1298 * @param[in] u2BeaconInterval       Given Beacon Interval.
1299 * @param[in] u2CapInfo              Given Capability Info.
1300 *
1301 * @return (none)
1302 */
1303 /*----------------------------------------------------------------------------*/
1304 VOID
1305 bssComposeBeaconProbeRespFrameHeaderAndFF (
1306     IN PUINT_8      pucBuffer,
1307     IN PUINT_8      pucDestAddr,
1308     IN PUINT_8      pucOwnMACAddress,
1309     IN PUINT_8      pucBSSID,
1310     IN UINT_16      u2BeaconInterval,
1311     IN UINT_16      u2CapInfo
1312     )
1313 {
1314     P_WLAN_BEACON_FRAME_T prBcnProbRspFrame;
1315     UINT_8 aucBCAddr[] = BC_MAC_ADDR;
1316     UINT_16 u2FrameCtrl;
1317
1318     DEBUGFUNC("bssComposeBeaconProbeRespFrameHeaderAndFF");
1319     //DBGLOG(INIT, LOUD, ("\n"));
1320
1321
1322     ASSERT(pucBuffer);
1323     ASSERT(pucOwnMACAddress);
1324     ASSERT(pucBSSID);
1325
1326     prBcnProbRspFrame = (P_WLAN_BEACON_FRAME_T)pucBuffer;
1327
1328     //4 <1> Compose the frame header of the Beacon /ProbeResp frame.
1329     /* Fill the Frame Control field. */
1330     if (pucDestAddr) {
1331         u2FrameCtrl = MAC_FRAME_PROBE_RSP;
1332     }
1333     else {
1334         u2FrameCtrl = MAC_FRAME_BEACON;
1335         pucDestAddr = aucBCAddr;
1336     }
1337     //WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2FrameCtrl, u2FrameCtrl);
1338     prBcnProbRspFrame->u2FrameCtrl = u2FrameCtrl; // NOTE(Kevin): Optimized for ARM
1339
1340     /* Fill the DA field with BCAST MAC ADDR or TA of ProbeReq. */
1341     COPY_MAC_ADDR(prBcnProbRspFrame->aucDestAddr, pucDestAddr);
1342
1343     /* Fill the SA field with our MAC Address. */
1344     COPY_MAC_ADDR(prBcnProbRspFrame->aucSrcAddr, pucOwnMACAddress);
1345
1346     /* Fill the BSSID field with current BSSID. */
1347     COPY_MAC_ADDR(prBcnProbRspFrame->aucBSSID, pucBSSID);
1348
1349     /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
1350     prBcnProbRspFrame->u2SeqCtrl = 0;
1351
1352
1353     //4 <2> Compose the frame body's common fixed field part of the Beacon /ProbeResp frame.
1354     /* MAC will update TimeStamp field */
1355
1356     /* Fill the Beacon Interval field. */
1357     //WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2BeaconInterval, u2BeaconInterval);
1358     prBcnProbRspFrame->u2BeaconInterval = u2BeaconInterval; // NOTE(Kevin): Optimized for ARM
1359
1360     /* Fill the Capability Information field. */
1361     //WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2CapInfo, u2CapInfo);
1362     prBcnProbRspFrame->u2CapInfo = u2CapInfo; // NOTE(Kevin): Optimized for ARM
1363
1364     return;
1365 } /* end of bssComposeBeaconProbeRespFrameHeaderAndFF() */
1366
1367
1368 /*----------------------------------------------------------------------------*/
1369 /*!
1370 * @brief Update the Beacon Frame Template to FW for AIS AdHoc and P2P GO.
1371 *
1372 * @param[in] prAdapter          Pointer to the Adapter structure.
1373 * @param[in] eNetTypeIndex      Specify which network reply the Probe Response.
1374 *
1375 * @retval WLAN_STATUS_SUCCESS   Success.
1376 */
1377 /*----------------------------------------------------------------------------*/
1378 WLAN_STATUS
1379 bssUpdateBeaconContent (
1380     IN P_ADAPTER_T prAdapter,
1381     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
1382     )
1383 {
1384     P_BSS_INFO_T prBssInfo;
1385     P_MSDU_INFO_T prMsduInfo;
1386     P_WLAN_BEACON_FRAME_T prBcnFrame;
1387     UINT_32 i;
1388
1389     DEBUGFUNC("bssUpdateBeaconContent");
1390     DBGLOG(INIT, LOUD, ("\n"));
1391
1392     ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
1393
1394     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
1395
1396     //4 <1> Allocate a PKT_INFO_T for Beacon Frame
1397     /* Allocate a MSDU_INFO_T */
1398     // For Beacon
1399     prMsduInfo = prBssInfo->prBeacon;
1400
1401     // beacon prMsduInfo will be NULLify once BSS deactivated, so skip if it is
1402     if (prMsduInfo == NULL) {
1403         return WLAN_STATUS_SUCCESS;
1404     }
1405
1406     //4 <2> Compose header
1407     bssComposeBeaconProbeRespFrameHeaderAndFF(
1408             (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
1409             NULL,
1410             prBssInfo->aucOwnMacAddr,
1411             prBssInfo->aucBSSID,
1412             prBssInfo->u2BeaconInterval,
1413             prBssInfo->u2CapInfo);
1414
1415
1416     prMsduInfo->u2FrameLength = (WLAN_MAC_MGMT_HEADER_LEN +
1417         (TIMESTAMP_FIELD_LEN + BEACON_INTERVAL_FIELD_LEN + CAP_INFO_FIELD_LEN));
1418
1419     prMsduInfo->ucNetworkType = eNetTypeIndex;
1420
1421     //4 <3> Compose the frame body's Common IEs of the Beacon frame.
1422     bssBuildBeaconProbeRespFrameCommonIEs(prMsduInfo, prBssInfo, NULL);
1423
1424
1425     //4 <4> Compose IEs in MSDU_INFO_T
1426
1427     /* Append IE for Beacon */
1428     for (i = 0; i < sizeof(txBcnIETable)/sizeof(APPEND_VAR_IE_ENTRY_T); i++) {
1429         if (txBcnIETable[i].pfnAppendIE) {
1430             txBcnIETable[i].pfnAppendIE(prAdapter, prMsduInfo);
1431         }
1432     }
1433
1434     prBcnFrame = (P_WLAN_BEACON_FRAME_T)prMsduInfo->prPacket;
1435
1436     return nicUpdateBeaconIETemplate(prAdapter,
1437             IE_UPD_METHOD_UPDATE_ALL,
1438             eNetTypeIndex,
1439             prBssInfo->u2CapInfo,
1440             (PUINT_8)prBcnFrame->aucInfoElem,
1441             prMsduInfo->u2FrameLength - OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem));
1442
1443
1444 } /* end of bssUpdateBeaconContent() */
1445
1446
1447 /*----------------------------------------------------------------------------*/
1448 /*!
1449 * @brief Send the Beacon Frame(for BOW) or Probe Response Frame according to the given
1450 *        Destination Address.
1451 *
1452 * @param[in] prAdapter          Pointer to the Adapter structure.
1453 * @param[in] eNetTypeIndex      Specify which network reply the Probe Response.
1454 * @param[in] pucDestAddr        Pointer to the Destination Address to reply
1455 * @param[in] u4ControlFlags     Control flags for information on Probe Response.
1456 *
1457 * @retval WLAN_STATUS_RESOURCE  No available resources to send frame.
1458 * @retval WLAN_STATUS_SUCCESS   Success.
1459 */
1460 /*----------------------------------------------------------------------------*/
1461 WLAN_STATUS
1462 bssSendBeaconProbeResponse (
1463     IN P_ADAPTER_T prAdapter,
1464     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
1465     IN PUINT_8 pucDestAddr,
1466     IN UINT_32 u4ControlFlags
1467     )
1468 {
1469     P_BSS_INFO_T prBssInfo;
1470     P_MSDU_INFO_T prMsduInfo;
1471     UINT_16 u2EstimatedFrameLen;
1472     UINT_16 u2EstimatedFixedIELen;
1473     UINT_16 u2EstimatedExtraIELen;
1474     P_APPEND_VAR_IE_ENTRY_T prIeArray = NULL;
1475     UINT_32 u4IeArraySize = 0;
1476     UINT_32 i;
1477
1478
1479     ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
1480
1481     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
1482
1483
1484     if (!pucDestAddr) { // For Beacon
1485         prIeArray = &txBcnIETable[0];
1486         u4IeArraySize = sizeof(txBcnIETable)/sizeof(APPEND_VAR_IE_ENTRY_T);
1487     }
1488     else {
1489         prIeArray = &txProbRspIETable[0];
1490         u4IeArraySize = sizeof(txProbRspIETable)/sizeof(APPEND_VAR_IE_ENTRY_T);
1491     }
1492
1493
1494     //4 <1> Allocate a PKT_INFO_T for Beacon /Probe Response Frame
1495     /* Allocate a MSDU_INFO_T */
1496
1497     /* Init with MGMT Header Length + Length of Fixed Fields + Common IE Fields */
1498     u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + \
1499                           WLAN_MAC_MGMT_HEADER_LEN + \
1500                           TIMESTAMP_FIELD_LEN + \
1501                           BEACON_INTERVAL_FIELD_LEN + \
1502                           CAP_INFO_FIELD_LEN + \
1503                           (ELEM_HDR_LEN + ELEM_MAX_LEN_SSID) + \
1504                           (ELEM_HDR_LEN + ELEM_MAX_LEN_SUP_RATES) + \
1505                           (ELEM_HDR_LEN + ELEM_MAX_LEN_DS_PARAMETER_SET) + \
1506                           (ELEM_HDR_LEN + ELEM_MAX_LEN_IBSS_PARAMETER_SET) + \
1507                           (ELEM_HDR_LEN + (3 + MAX_LEN_TIM_PARTIAL_BMP));
1508
1509     /* + Extra IE Length */
1510     u2EstimatedExtraIELen = 0;
1511
1512     for (i = 0; i < u4IeArraySize; i++) {
1513         u2EstimatedFixedIELen = prIeArray[i].u2EstimatedFixedIELen;
1514
1515         if (u2EstimatedFixedIELen) {
1516             u2EstimatedExtraIELen += u2EstimatedFixedIELen;
1517         }
1518         else {
1519             ASSERT(prIeArray[i].pfnCalculateVariableIELen);
1520
1521             u2EstimatedExtraIELen += (UINT_16)
1522                 prIeArray[i].pfnCalculateVariableIELen(prAdapter, eNetTypeIndex, NULL);
1523         }
1524     }
1525
1526     u2EstimatedFrameLen += u2EstimatedExtraIELen;
1527
1528     if ( (prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen)) == NULL) {
1529         DBGLOG(BSS, WARN, ("No PKT_INFO_T for sending %s.\n",
1530             ((!pucDestAddr)?"Beacon":"Probe Response")));
1531         return WLAN_STATUS_RESOURCES;
1532     }
1533
1534
1535     //4 <2> Compose Beacon/Probe Response frame header and fixed fields in MSDU_INfO_T.
1536     /* Compose Header and Fixed Field */
1537 #if CFG_ENABLE_WIFI_DIRECT
1538     if (u4ControlFlags & BSS_PROBE_RESP_USE_P2P_DEV_ADDR) {
1539         if(prAdapter->fgIsP2PRegistered) {
1540             bssComposeBeaconProbeRespFrameHeaderAndFF(
1541                     (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
1542                     pucDestAddr,
1543                     prAdapter->rWifiVar.aucDeviceAddress,
1544                     prAdapter->rWifiVar.aucDeviceAddress,
1545                     DOT11_BEACON_PERIOD_DEFAULT,
1546                     (prBssInfo->u2CapInfo & ~(CAP_INFO_ESS | CAP_INFO_IBSS)));
1547         }
1548     }
1549     else
1550 #endif /* CFG_ENABLE_WIFI_DIRECT */
1551     {
1552         bssComposeBeaconProbeRespFrameHeaderAndFF(
1553                 (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
1554                 pucDestAddr,
1555                 prBssInfo->aucOwnMacAddr,
1556                 prBssInfo->aucBSSID,
1557                 prBssInfo->u2BeaconInterval,
1558                 prBssInfo->u2CapInfo);
1559     }
1560
1561
1562     //4 <3> Update information of MSDU_INFO_T
1563     prMsduInfo->eSrc = TX_PACKET_MGMT;
1564     prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT;
1565     prMsduInfo->ucStaRecIndex = 0xFF;
1566     prMsduInfo->ucNetworkType = (UINT_8)eNetTypeIndex;
1567     prMsduInfo->ucMacHeaderLength = WLAN_MAC_MGMT_HEADER_LEN;
1568     prMsduInfo->fgIs802_1x = FALSE;
1569     prMsduInfo->fgIs802_11 = TRUE;
1570     prMsduInfo->u2FrameLength = (WLAN_MAC_MGMT_HEADER_LEN +
1571         TIMESTAMP_FIELD_LEN + BEACON_INTERVAL_FIELD_LEN + CAP_INFO_FIELD_LEN);
1572     prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
1573     prMsduInfo->pfTxDoneHandler = NULL;
1574     prMsduInfo->fgIsBasicRate = TRUE;
1575
1576
1577     //4 <4> Compose the frame body's Common IEs of the Beacon/ProbeResp  frame.
1578     bssBuildBeaconProbeRespFrameCommonIEs(prMsduInfo, prBssInfo, pucDestAddr);
1579
1580
1581     //4 <5> Compose IEs in MSDU_INFO_T
1582
1583     /* Append IE */
1584     for (i = 0; i < u4IeArraySize; i++) {
1585         if (prIeArray[i].pfnAppendIE) {
1586             prIeArray[i].pfnAppendIE(prAdapter, prMsduInfo);
1587         }
1588     }
1589
1590     /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
1591
1592     //4 <6> Inform TXM  to send this Beacon /Probe Response frame.
1593     nicTxEnqueueMsdu(prAdapter, prMsduInfo);
1594
1595     return WLAN_STATUS_SUCCESS;
1596
1597 } /* end of bssSendBeaconProbeResponse() */
1598
1599
1600 /*----------------------------------------------------------------------------*/
1601 /*!
1602 * @brief This function will process the Rx Probe Request Frame and then send
1603 *        back the corresponding Probe Response Frame if the specified conditions
1604 *        were matched.
1605 *
1606 * @param[in] prAdapter          Pointer to the Adapter structure.
1607 * @param[in] prSwRfb            Pointer to SW RFB data structure.
1608 *
1609 * @retval WLAN_STATUS_SUCCESS   Always return success
1610 */
1611 /*----------------------------------------------------------------------------*/
1612 WLAN_STATUS
1613 bssProcessProbeRequest (
1614     IN P_ADAPTER_T prAdapter,
1615     IN P_SW_RFB_T prSwRfb
1616     )
1617 {
1618     P_WLAN_MAC_MGMT_HEADER_T prMgtHdr;
1619     P_BSS_INFO_T prBssInfo;
1620     ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
1621     UINT_8 aucBCBSSID[] = BC_BSSID;
1622     BOOLEAN fgIsBcBssid;
1623     BOOLEAN fgReplyProbeResp;
1624     UINT_32 u4CtrlFlagsForProbeResp = 0;
1625     ENUM_BAND_T             eBand;
1626     UINT_8                  ucHwChannelNum;
1627
1628
1629     ASSERT(prSwRfb);
1630
1631     //4 <1> Parse Probe Req and Get BSSID
1632     prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)prSwRfb->pvHeader;
1633
1634     if (EQUAL_MAC_ADDR(aucBCBSSID, prMgtHdr->aucBSSID)) {
1635         fgIsBcBssid = TRUE;
1636     }
1637     else {
1638         fgIsBcBssid = FALSE;
1639     }
1640
1641
1642     //4 <2> Check network conditions before reply Probe Response Frame (Consider Concurrent)
1643     for (eNetTypeIndex = NETWORK_TYPE_AIS_INDEX; eNetTypeIndex < NETWORK_TYPE_INDEX_NUM; eNetTypeIndex++) {
1644
1645         if (!IS_NET_ACTIVE(prAdapter, eNetTypeIndex)) {
1646             continue;
1647         }
1648
1649         prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
1650
1651         if ((!fgIsBcBssid) &&
1652             UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prMgtHdr->aucBSSID)) {
1653             continue;
1654         }
1655
1656         eBand = HIF_RX_HDR_GET_RF_BAND(prSwRfb->prHifRxHdr);
1657         ucHwChannelNum = HIF_RX_HDR_GET_CHNL_NUM(prSwRfb->prHifRxHdr);
1658
1659         if(prBssInfo->eBand != eBand) {
1660             continue;
1661         }
1662
1663         if(prBssInfo->ucPrimaryChannel != ucHwChannelNum) {
1664             continue;
1665         }
1666
1667         fgReplyProbeResp = FALSE;
1668
1669         if (NETWORK_TYPE_AIS_INDEX == eNetTypeIndex) {
1670
1671 #if CFG_SUPPORT_ADHOC
1672             fgReplyProbeResp = aisValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
1673 #endif
1674         }
1675 #if CFG_ENABLE_WIFI_DIRECT
1676         else if ((prAdapter->fgIsP2PRegistered) &&
1677                  (NETWORK_TYPE_P2P_INDEX == eNetTypeIndex)) {
1678
1679             fgReplyProbeResp = p2pFuncValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
1680         }
1681 #endif
1682 #if CFG_ENABLE_BT_OVER_WIFI
1683         else if (NETWORK_TYPE_BOW_INDEX == eNetTypeIndex) {
1684
1685             fgReplyProbeResp = bowValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
1686         }
1687 #endif
1688
1689        if (fgReplyProbeResp) {
1690             if(nicTxGetFreeCmdCount(prAdapter) > (CFG_TX_MAX_CMD_PKT_NUM/2) ){
1691                 /* Resource margin is enough */
1692                 bssSendBeaconProbeResponse(prAdapter, eNetTypeIndex, prMgtHdr->aucSrcAddr, u4CtrlFlagsForProbeResp);
1693             }
1694         }
1695     }
1696
1697     return WLAN_STATUS_SUCCESS;
1698
1699 } /* end of bssProcessProbeRequest() */
1700
1701
1702 #if 0 // NOTE(Kevin): condition check should move to P2P_FSM.c
1703 /*----------------------------------------------------------------------------*/
1704 /*!
1705 * @brief This function will process the Rx Probe Request Frame and then send
1706 *        back the corresponding Probe Response Frame if the specified conditions
1707 *        were matched.
1708 *
1709 * @param[in] prSwRfb            Pointer to SW RFB data structure.
1710 *
1711 * @retval WLAN_STATUS_SUCCESS   Always return success
1712 */
1713 /*----------------------------------------------------------------------------*/
1714 WLAN_STATUS
1715 bssProcessProbeRequest (
1716     IN P_ADAPTER_T  prAdapter,
1717     IN P_SW_RFB_T   prSwRfb
1718     )
1719 {
1720     P_WLAN_MAC_MGMT_HEADER_T prMgtHdr;
1721     P_BSS_INFO_T prBssInfo;
1722     P_IE_SSID_T prIeSsid = (P_IE_SSID_T)NULL;
1723     P_IE_SUPPORTED_RATE_T prIeSupportedRate = (P_IE_SUPPORTED_RATE_T)NULL;
1724     P_IE_EXT_SUPPORTED_RATE_T prIeExtSupportedRate = (P_IE_EXT_SUPPORTED_RATE_T)NULL;
1725     PUINT_8 pucIE;
1726     UINT_16 u2IELength;
1727     UINT_16 u2Offset = 0;
1728     UINT_8 aucBCBSSID[] = BC_BSSID;
1729     ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
1730     BOOLEAN fgReplyProbeResp;
1731 #if CFG_ENABLE_WIFI_DIRECT
1732     BOOLEAN fgP2PTargetDeviceFound;
1733     UINT_8 aucP2PWildcardSSID[] = P2P_WILDCARD_SSID;
1734 #endif
1735
1736     ASSERT(prSwRfb);
1737
1738     //4 <1> Parse Probe Req and Get SSID IE ptr
1739     prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)prSwRfb->pvHeader;
1740
1741     u2IELength = prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen;
1742     pucIE = (PUINT_8)((UINT_32)prSwRfb->pvHeader + prSwRfb->u2HeaderLen);
1743
1744     prIeSsid = (P_IE_SSID_T)NULL;
1745
1746     IE_FOR_EACH(pucIE, u2IELength, u2Offset) {
1747         switch (IE_ID(pucIE)) {
1748         case ELEM_ID_SSID:
1749             if ((!prIeSsid) &&
1750                 (IE_LEN(pucIE) <= ELEM_MAX_LEN_SSID)) {
1751                 prIeSsid = (P_IE_SSID_T)pucIE;
1752             }
1753             break;
1754
1755         case ELEM_ID_SUP_RATES:
1756             /* NOTE(Kevin): Buffalo WHR-G54S's supported rate set IE exceed 8.
1757              * IE_LEN(pucIE) == 12, "1(B), 2(B), 5.5(B), 6(B), 9(B), 11(B),
1758              * 12(B), 18(B), 24(B), 36(B), 48(B), 54(B)"
1759              */
1760             // if (IE_LEN(pucIE) <= ELEM_MAX_LEN_SUP_RATES) {
1761             if (IE_LEN(pucIE) <= RATE_NUM) {
1762                 prIeSupportedRate = SUP_RATES_IE(pucIE);
1763             }
1764             break;
1765
1766         case ELEM_ID_EXTENDED_SUP_RATES:
1767             prIeExtSupportedRate = EXT_SUP_RATES_IE(pucIE);
1768             break;
1769
1770 #if CFG_ENABLE_WIFI_DIRECT
1771         // TODO: P2P IE & WCS IE parsing for P2P.
1772         case ELEM_ID_P2P:
1773
1774             break;
1775 #endif
1776
1777         /* no default */
1778         }
1779     } /* end of IE_FOR_EACH */
1780
1781     //4 <2> Check network conditions before reply Probe Response Frame (Consider Concurrent)
1782     for (eNetTypeIndex = NETWORK_TYPE_AIS_INDEX; eNetTypeIndex < NETWORK_TYPE_INDEX_NUM; eNetTypeIndex++) {
1783
1784         if (!IS_NET_ACTIVE(prAdapter, eNetTypeIndex)) {
1785             continue;
1786         }
1787
1788         prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
1789
1790         if (UNEQUAL_MAC_ADDR(aucBCBSSID, prMgtHdr->aucBSSID) &&
1791             UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prMgtHdr->aucBSSID)) {
1792             /* BSSID not Wildcard BSSID. */
1793             continue;
1794         }
1795
1796         fgReplyProbeResp = FALSE;
1797
1798         if (NETWORK_TYPE_AIS_INDEX == eNetTypeIndex) {
1799
1800             if (prBssInfo->eCurrentOPMode == OP_MODE_IBSS) {
1801
1802                 /* TODO(Kevin): Check if we are IBSS Master. */
1803                 if (TRUE) {
1804
1805                     if (prIeSsid) {
1806                         if ((prIeSsid->ucLength == BC_SSID_LEN) || /* WILDCARD SSID */
1807                             EQUAL_SSID(prBssInfo->aucSSID, prBssInfo->ucSSIDLen,
1808                                        prIeSsid->aucSSID, prIeSsid->ucLength)) {
1809                             fgReplyProbeResp = TRUE;
1810                         }
1811                     }
1812                 }
1813             }
1814         }
1815 #if CFG_ENABLE_WIFI_DIRECT
1816         else if (NETWORK_TYPE_P2P_INDEX == eNetTypeIndex) {
1817
1818             // TODO(Kevin): Move following lines to p2p_fsm.c
1819
1820             if ((prIeSsid) &&
1821                     ((prIeSsid->ucLength == BC_SSID_LEN) ||
1822                     (EQUAL_SSID(aucP2PWildcardSSID,
1823                         P2P_WILDCARD_SSID_LEN,
1824                         prIeSsid->aucSSID,
1825                         prIeSsid->ucLength)))) {
1826 //                if (p2pFsmRunEventRxProbeRequestFrame(prAdapter, prMgtHdr->aucSrcAddr, pucIE, u2IELength)) {
1827                 if (p2pFsmRunEventRxProbeRequestFrame(prAdapter, prSwRfb)) {
1828                     /* Extand channel request time & cancel scan request. */
1829                     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1830
1831                     // TODO: RX probe request may not caused by LISTEN state.
1832                     // TODO: It can be GO.
1833                     /* Generally speaking, cancel a non-exist scan request is fine.
1834                       * We can check P2P FSM here for only LISTEN state.
1835                       */
1836
1837                     P_MSG_SCN_SCAN_CANCEL prScanCancelMsg;
1838
1839                     prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1840
1841                     /* Abort JOIN process. */
1842                     prScanCancelMsg = (P_MSG_SCN_SCAN_CANCEL)cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_SCN_SCAN_CANCEL));
1843                     if (!prScanCancelMsg) {
1844                         ASSERT(0); // Can't abort SCN FSM
1845                         continue;
1846                     }
1847
1848                     prScanCancelMsg->rMsgHdr.eMsgId = MID_P2P_SCN_SCAN_CANCEL;
1849                     prScanCancelMsg->ucSeqNum = prP2pFsmInfo->ucSeqNumOfScnMsg;
1850                     prScanCancelMsg->ucNetTypeIndex = (UINT_8)NETWORK_TYPE_P2P_INDEX;
1851                     prScanCancelMsg->fgIsChannelExt = TRUE;
1852
1853                     mboxSendMsg(prAdapter,
1854                             MBOX_ID_0,
1855                             (P_MSG_HDR_T) prScanCancelMsg,
1856                             MSG_SEND_METHOD_BUF);
1857               }
1858             }
1859             else {
1860                 /* 1. Probe Request without SSID.
1861                   * 2. Probe Request with SSID not Wildcard SSID & not P2P Wildcard SSID.
1862                   */
1863                 continue;
1864             }
1865
1866 #if 0 // Frog
1867             if (prAdapter->rWifiVar.prP2pFsmInfo->eCurrentState == P2P_STATE_LISTEN) {
1868                 // P2P 2.4.1 - P2P Devices shall not respond to Probe Request frames which only contain 11b rates only.
1869                 if (prIeSupportedRate || prIeExtSupportedRate) {
1870                     UINT_16 u2OperationalRateSet, u2BSSBasicRateSet;
1871                     BOOLEAN fgIsUnknownBssBasicRate;
1872
1873                     rateGetRateSetFromIEs(prIeSupportedRate,
1874                                           prIeExtSupportedRate,
1875                                           &u2OperationalRateSet,
1876                                           &u2BSSBasicRateSet, /* Ignore any Basic Bit */
1877                                           &fgIsUnknownBssBasicRate);
1878
1879                     if (u2OperationalRateSet & ~RATE_SET_HR_DSSS) {
1880                         continue;
1881                     }
1882                 }
1883             }
1884
1885             // TODO: Check channel time before first check point to:
1886             /* If Target device is selected:
1887               *     1. Send XXXX request frame.
1888               * else
1889               *     1. Send Probe Response frame.
1890               */
1891
1892             if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
1893                 /* TODO(Kevin): During PROVISION state, can we reply Probe Response ? */
1894
1895                 /* TODO(Kevin):
1896                            * If we are GO, accept legacy client --> accept Wildcard SSID
1897                            * If we are in Listen State, accept only P2P Device --> check P2P IE and WPS IE
1898                            */
1899                 if (TRUE /* We are GO */) {
1900                     if (prIeSsid) {
1901                         UINT_8 aucSSID[]=P2P_WILDCARD_SSID;
1902
1903                         if ((prIeSsid->ucLength == BC_SSID_LEN) || /* WILDCARD SSID */
1904                             EQUAL_SSID(prBssInfo->aucSSID, prBssInfo->ucSSIDLen,
1905                                        prIeSsid->aucSSID, prIeSsid->ucLength) ||
1906                             EQUAL_SSID(aucSSID, P2P_WILDCARD_SSID_LEN,
1907                                        prIeSsid->aucSSID, prIeSsid->ucLength)) {
1908                             fgReplyProbeResp = TRUE;
1909                         }
1910                     }
1911                 }
1912 //                else if (FALSE /* We are in Listen State */) {
1913 //                }
1914
1915                 /* TODO(Kevin): Check P2P IE and WPS IE */
1916             }
1917 #endif
1918         }
1919 #endif
1920 #if CFG_ENABLE_BT_OVER_WIFI
1921         else if (NETWORK_TYPE_BOW_INDEX == eNetTypeIndex) {
1922
1923             if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
1924                 /* TODO(Kevin): TBD */
1925             }
1926         }
1927 #endif
1928         else {
1929             ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
1930         }
1931
1932         if (fgReplyProbeResp) {
1933             bssSendBeaconProbeResponse(prAdapter, eNetTypeIndex, prMgtHdr->aucSrcAddr);
1934         }
1935
1936     }
1937
1938     return WLAN_STATUS_SUCCESS;
1939
1940 } /* end of bssProcessProbeRequest() */
1941 #endif
1942
1943
1944 /*----------------------------------------------------------------------------*/
1945 /*!
1946 * @brief This function is used to clear the client list for AdHoc or AP Mode
1947 *
1948 * @param[in] prAdapter              Pointer to the Adapter structure.
1949 * @param[in] prBssInfo              Given related BSS_INFO_T.
1950 *
1951 * @return (none)
1952 */
1953 /*----------------------------------------------------------------------------*/
1954 VOID
1955 bssClearClientList (
1956     IN P_ADAPTER_T  prAdapter,
1957     IN P_BSS_INFO_T prBssInfo
1958     )
1959 {
1960     P_LINK_T prStaRecOfClientList;
1961
1962
1963     ASSERT(prBssInfo);
1964
1965     prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
1966
1967     if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
1968         P_STA_RECORD_T prPeerStaRec;
1969
1970         LINK_FOR_EACH_ENTRY(prPeerStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
1971             cnmStaRecChangeState(prAdapter, prPeerStaRec, STA_STATE_1);
1972         }
1973
1974         LINK_INITIALIZE(prStaRecOfClientList);
1975     }
1976
1977     return;
1978 } /* end of bssClearClientList() */
1979
1980
1981
1982 /*----------------------------------------------------------------------------*/
1983 /*!
1984 * @brief This function is used to Add a STA_RECORD_T to the client list for AdHoc or AP Mode
1985 *
1986 * @param[in] prAdapter              Pointer to the Adapter structure.
1987 * @param[in] prBssInfo              Given related BSS_INFO_T.
1988 * @param[in] prStaRec               Pointer to the STA_RECORD_T
1989 *
1990 * @return (none)
1991 */
1992 /*----------------------------------------------------------------------------*/
1993 VOID
1994 bssAddStaRecToClientList (
1995     IN P_ADAPTER_T  prAdapter,
1996     IN P_BSS_INFO_T prBssInfo,
1997     IN P_STA_RECORD_T prStaRec
1998     )
1999 {
2000     P_LINK_T prStaRecOfClientList;
2001
2002
2003     ASSERT(prBssInfo);
2004
2005     prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
2006
2007     if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
2008         P_STA_RECORD_T prCurrStaRec;
2009
2010         LINK_FOR_EACH_ENTRY(prCurrStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
2011
2012             if (prCurrStaRec == prStaRec) {
2013                 DBGLOG(BSS, WARN, ("Current Client List already contains that STA_RECORD_T["MACSTR"]\n",
2014                     MAC2STR(prStaRec->aucMacAddr)));
2015                 return;
2016             }
2017         }
2018     }
2019
2020     LINK_INSERT_TAIL(prStaRecOfClientList, &prStaRec->rLinkEntry);
2021
2022     return;
2023 } /* end of bssAddStaRecToClientList() */
2024
2025
2026 /*----------------------------------------------------------------------------*/
2027 /*!
2028 * @brief This function is used to Remove a STA_RECORD_T from the client list for AdHoc or AP Mode
2029 *
2030 * @param[in] prAdapter              Pointer to the Adapter structure.
2031 * @param[in] prStaRec               Pointer to the STA_RECORD_T
2032 *
2033 * @return (none)
2034 */
2035 /*----------------------------------------------------------------------------*/
2036 VOID
2037 bssRemoveStaRecFromClientList (
2038     IN P_ADAPTER_T  prAdapter,
2039     IN P_BSS_INFO_T prBssInfo,
2040     IN P_STA_RECORD_T prStaRec
2041     )
2042 {
2043     P_LINK_T prStaRecOfClientList;
2044
2045
2046     ASSERT(prBssInfo);
2047
2048     prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
2049
2050     if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
2051         P_STA_RECORD_T prCurrStaRec;
2052
2053         LINK_FOR_EACH_ENTRY(prCurrStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
2054
2055             if (prCurrStaRec == prStaRec) {
2056
2057                 LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prStaRec->rLinkEntry);
2058
2059                 return;
2060             }
2061         }
2062     }
2063
2064     DBGLOG(BSS, INFO, ("Current Client List didn't contain that STA_RECORD_T["MACSTR"] before removing.\n",
2065         MAC2STR(prStaRec->aucMacAddr)));
2066
2067     return;
2068 } /* end of bssRemoveStaRecFromClientList() */
2069 #endif /* CFG_SUPPORT_ADHOC || CFG_SUPPORT_AAA */
2070
2071
2072 #if CFG_SUPPORT_ADHOC
2073 /*----------------------------------------------------------------------------*/
2074 /* Routines for IBSS(AdHoc) only                                              */
2075 /*----------------------------------------------------------------------------*/
2076 /*----------------------------------------------------------------------------*/
2077 /*!
2078 * @brief This function is used to process Beacons from current Ad-Hoc network peers.
2079 *        We also process Beacons from other Ad-Hoc network during SCAN. If it has
2080 *        the same SSID and we'll decide to merge into it if it has a larger TSF.
2081 *
2082 * @param[in] prAdapter  Pointer to the Adapter structure.
2083 * @param[in] prBssInfo  Pointer to the BSS_INFO_T.
2084 * @param[in] prBSSDesc  Pointer to the BSS Descriptor.
2085 *
2086 * @return (none)
2087 */
2088 /*----------------------------------------------------------------------------*/
2089 VOID
2090 ibssProcessMatchedBeacon (
2091     IN P_ADAPTER_T  prAdapter,
2092     IN P_BSS_INFO_T prBssInfo,
2093     IN P_BSS_DESC_T prBssDesc,
2094     IN UINT_8       ucRCPI
2095     )
2096 {
2097     P_STA_RECORD_T prStaRec = NULL;
2098
2099     BOOLEAN fgIsCheckCapability = FALSE;
2100     BOOLEAN fgIsCheckTSF = FALSE;
2101     BOOLEAN fgIsGoingMerging = FALSE;
2102     BOOLEAN fgIsSameBSSID;
2103
2104
2105     ASSERT(prBssInfo);
2106     ASSERT(prBssDesc);
2107
2108     //4 <1> Process IBSS Beacon only after we create or merge with other IBSS.
2109     if (!prBssInfo->fgIsBeaconActivated) {
2110         return;
2111     }
2112
2113     //4 <2> Get the STA_RECORD_T of TA.
2114     prStaRec = cnmGetStaRecByAddress(prAdapter,
2115                             (UINT_8) NETWORK_TYPE_AIS_INDEX,
2116                             prBssDesc->aucSrcAddr);
2117
2118     fgIsSameBSSID = UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prBssDesc->aucBSSID) ? FALSE : TRUE;
2119
2120
2121     //4 <3> IBSS Merge Decision Flow for Processing Beacon.
2122     if (fgIsSameBSSID) {
2123
2124         /* Same BSSID:
2125          * Case I.  This is a new TA and it has decide to merged with us.
2126          *      a)  If fgIsMerging == FALSE - we will send msg to notify AIS.
2127          *      b)  If fgIsMerging == TRUE - already notify AIS.
2128          * Case II. This is an old TA and we've already merged together.
2129          */
2130         if (!prStaRec) {
2131
2132             /* For Case I - Check this IBSS's capability first before adding this Sta Record. */
2133             fgIsCheckCapability = TRUE;
2134
2135             /* If check is passed, then we perform merging with this new IBSS */
2136             fgIsGoingMerging = TRUE;
2137
2138         }
2139         else {
2140
2141             ASSERT((prStaRec->ucNetTypeIndex == NETWORK_TYPE_AIS_INDEX) &&
2142                 IS_ADHOC_STA(prStaRec));
2143
2144             if (prStaRec->ucStaState != STA_STATE_3) {
2145
2146                 if (!prStaRec->fgIsMerging) {
2147
2148                     /* For Case I - Check this IBSS's capability first before adding this Sta Record. */
2149                     fgIsCheckCapability = TRUE;
2150
2151                     /* If check is passed, then we perform merging with this new IBSS */
2152                     fgIsGoingMerging = TRUE;
2153                 }
2154                 else {
2155                     /* For Case II - Update rExpirationTime of Sta Record */
2156                     GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
2157                 }
2158             }
2159             else {
2160                 /* For Case II - Update rExpirationTime of Sta Record */
2161                 GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
2162             }
2163
2164         }
2165     }
2166     else {
2167
2168         /* Unequal BSSID:
2169          * Case III. This is a new TA and we need to compare the TSF and get the winner.
2170          * Case IV.  This is an old TA and it merge into a new IBSS before we do the same thing.
2171          *           We need to compare the TSF to get the winner.
2172          * Case V.   This is an old TA and it restart a new IBSS. We also need to
2173          *           compare the TSF to get the winner.
2174          */
2175
2176         /* For Case III, IV & V - We'll always check this new IBSS's capability first
2177          * before merging into new IBSS.
2178          */
2179         fgIsCheckCapability = TRUE;
2180
2181         /* If check is passed, we need to perform TSF check to decide the major BSSID */
2182         fgIsCheckTSF = TRUE;
2183
2184         /* For Case IV & V - We won't update rExpirationTime of Sta Record */
2185     }
2186
2187
2188     //4 <7> Check this BSS_DESC_T's capability.
2189     if (fgIsCheckCapability) {
2190         BOOLEAN fgIsCapabilityMatched = FALSE;
2191
2192         do {
2193             if (!(prBssDesc->ucPhyTypeSet & (prAdapter->rWifiVar.ucAvailablePhyTypeSet))) {
2194                 DBGLOG(BSS, LOUD,
2195                     ("IBSS MERGE: Ignore Peer MAC: "MACSTR" - Unsupported Phy.\n",
2196                      MAC2STR(prBssDesc->aucSrcAddr)));
2197
2198                 break;
2199             }
2200
2201             if (prBssDesc->fgIsUnknownBssBasicRate) {
2202                 DBGLOG(BSS, LOUD,
2203                     ("IBSS MERGE: Ignore Peer MAC: "MACSTR" - Unknown Basic Rate.\n",
2204                      MAC2STR(prBssDesc->aucSrcAddr)));
2205
2206                 break;
2207             }
2208
2209             if (ibssCheckCapabilityForAdHocMode(prAdapter, prBssDesc) == WLAN_STATUS_FAILURE) {
2210                 DBGLOG(BSS, LOUD,
2211                     ("IBSS MERGE: Ignore Peer MAC: "MACSTR" - Capability is not matched.\n",
2212                      MAC2STR(prBssDesc->aucSrcAddr)));
2213
2214                 break;
2215             }
2216
2217             fgIsCapabilityMatched = TRUE;
2218         }
2219         while (FALSE);
2220
2221         if (!fgIsCapabilityMatched) {
2222
2223             if (prStaRec) {
2224                 /* For Case II - We merge this STA_RECORD in RX Path.
2225                  *     Case IV & V - They change their BSSID after we merge with them.
2226                  */
2227
2228                 DBGLOG(BSS, LOUD,
2229                     ("IBSS MERGE: Ignore Peer MAC: "MACSTR" - Capability is not matched.\n",
2230                      MAC2STR(prBssDesc->aucSrcAddr)));
2231             }
2232
2233             return;
2234         }
2235
2236         DBGLOG(BSS, LOUD,
2237             ("IBSS MERGE: Peer MAC: "MACSTR" - Check capability was passed.\n",
2238              MAC2STR(prBssDesc->aucSrcAddr)));
2239     }
2240
2241
2242     if (fgIsCheckTSF) {
2243 #if CFG_SLT_SUPPORT
2244         fgIsGoingMerging = TRUE;
2245 #else
2246         if (prBssDesc->fgIsLargerTSF) {
2247             fgIsGoingMerging = TRUE;
2248         }
2249         else {
2250             return;
2251         }
2252 #endif
2253     }
2254
2255
2256     if (fgIsGoingMerging) {
2257         P_MSG_AIS_IBSS_PEER_FOUND_T prAisIbssPeerFoundMsg;
2258
2259
2260         //4 <1> We will merge with to this BSS immediately.
2261         prBssDesc->fgIsConnecting = TRUE;
2262         prBssDesc->fgIsConnected = FALSE;
2263
2264         //4 <2> Setup corresponding STA_RECORD_T
2265         prStaRec = bssCreateStaRecFromBssDesc(prAdapter,
2266                                               STA_TYPE_ADHOC_PEER,
2267                                               NETWORK_TYPE_AIS_INDEX,
2268                                               prBssDesc);
2269
2270         if(!prStaRec) {
2271             // no memory ?
2272             return;
2273         }
2274
2275         prStaRec->fgIsMerging = TRUE;
2276
2277         /* update RCPI */
2278         prStaRec->ucRCPI = ucRCPI;
2279
2280         //4 <3> Send Merge Msg to CNM to obtain the channel privilege.
2281         prAisIbssPeerFoundMsg = (P_MSG_AIS_IBSS_PEER_FOUND_T)
2282             cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_AIS_IBSS_PEER_FOUND_T));
2283
2284         if (!prAisIbssPeerFoundMsg) {
2285
2286             ASSERT(0); // Can't send Merge Msg
2287             return;
2288         }
2289
2290         prAisIbssPeerFoundMsg->rMsgHdr.eMsgId = MID_SCN_AIS_FOUND_IBSS;
2291         prAisIbssPeerFoundMsg->ucNetTypeIndex = (UINT_8)NETWORK_TYPE_AIS_INDEX;
2292         prAisIbssPeerFoundMsg->prStaRec = prStaRec;
2293
2294         /* Inform AIS to do STATE TRANSITION
2295          * For Case I - If AIS in IBSS_ALONE, let it jump to NORMAL_TR after we know the new member.
2296          * For Case III, IV - Now this new BSSID wins the TSF, follow it.
2297          */
2298         if (fgIsSameBSSID) {
2299             prAisIbssPeerFoundMsg->fgIsMergeIn = TRUE;
2300         }
2301         else {
2302 #if CFG_SLT_SUPPORT
2303             prAisIbssPeerFoundMsg->fgIsMergeIn = TRUE;
2304 #else
2305             prAisIbssPeerFoundMsg->fgIsMergeIn = (prBssDesc->fgIsLargerTSF) ? FALSE: TRUE;
2306 #endif
2307         }
2308
2309         mboxSendMsg(prAdapter,
2310                 MBOX_ID_0,
2311                 (P_MSG_HDR_T) prAisIbssPeerFoundMsg,
2312                 MSG_SEND_METHOD_BUF);
2313
2314     }
2315
2316     return;
2317 } /* end of ibssProcessMatchedBeacon() */
2318
2319
2320 /*----------------------------------------------------------------------------*/
2321 /*!
2322 * @brief This function will check the Capability for Ad-Hoc to decide if we are
2323 *        able to merge with(same capability).
2324 *
2325 * @param[in] prBSSDesc  Pointer to the BSS Descriptor.
2326 *
2327 * @retval WLAN_STATUS_FAILURE   Can't pass the check of Capability.
2328 * @retval WLAN_STATUS_SUCCESS   Pass the check of Capability.
2329 */
2330 /*----------------------------------------------------------------------------*/
2331 WLAN_STATUS
2332 ibssCheckCapabilityForAdHocMode (
2333     IN P_ADAPTER_T  prAdapter,
2334     IN P_BSS_DESC_T prBssDesc
2335     )
2336 {
2337     P_CONNECTION_SETTINGS_T prConnSettings;
2338     WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
2339
2340
2341     ASSERT(prBssDesc);
2342     prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
2343
2344     do {
2345         //4 <1> Check the BSS Basic Rate Set for current AdHoc Mode
2346         if ((prConnSettings->eAdHocMode == AD_HOC_MODE_11B) &&
2347             (prBssDesc->u2BSSBasicRateSet & ~RATE_SET_HR_DSSS)) {
2348             break;
2349         }
2350         else if ((prConnSettings->eAdHocMode == AD_HOC_MODE_11A) &&
2351             (prBssDesc->u2BSSBasicRateSet & ~RATE_SET_OFDM)) {
2352             break;
2353         }
2354
2355         //4 <2> Check the Short Slot Time.
2356 #if 0 // Do not check ShortSlotTime until Wi-Fi define such policy
2357         if (prConnSettings->eAdHocMode == AD_HOC_MODE_11G) {
2358             if (((prConnSettings->fgIsShortSlotTimeOptionEnable) &&
2359                  !(prBssDesc->u2CapInfo & CAP_INFO_SHORT_SLOT_TIME)) ||
2360                 (!(prConnSettings->fgIsShortSlotTimeOptionEnable) &&
2361                  (prBssDesc->u2CapInfo & CAP_INFO_SHORT_SLOT_TIME))) {
2362                 break;
2363             }
2364         }
2365 #endif
2366
2367         //4 <3> Check the ATIM window setting.
2368         if (prBssDesc->u2ATIMWindow) {
2369             DBGLOG(BSS, INFO, ("AdHoc PS was not supported(ATIM Window: %d)\n",
2370                 prBssDesc->u2ATIMWindow));
2371             break;
2372         }
2373
2374 #if CFG_RSN_MIGRATION
2375         //4 <4> Check the Security setting.
2376         if (!rsnPerformPolicySelection(prAdapter, prBssDesc)) {
2377             break;
2378         }
2379 #endif
2380
2381         rStatus = WLAN_STATUS_SUCCESS;
2382     }
2383     while (FALSE);
2384
2385     return rStatus;
2386
2387 } /* end of ibssCheckCapabilityForAdHocMode() */
2388
2389
2390 /*----------------------------------------------------------------------------*/
2391 /*!
2392 * @brief This function will initial the BSS_INFO_T for IBSS Mode.
2393 *
2394 * @param[in] prBssInfo      Pointer to the BSS_INFO_T.
2395 *
2396 * @return (none)
2397 */
2398 /*----------------------------------------------------------------------------*/
2399 VOID
2400 ibssInitForAdHoc (
2401     IN P_ADAPTER_T  prAdapter,
2402     IN P_BSS_INFO_T prBssInfo
2403     )
2404 {
2405     UINT_8 ucLowestBasicRateIndex;
2406     UINT_8 aucBSSID[MAC_ADDR_LEN];
2407     PUINT_16 pu2BSSID = (PUINT_16)&aucBSSID[0];
2408     UINT_32 i;
2409
2410
2411     ASSERT(prBssInfo);
2412     ASSERT(prBssInfo->eCurrentOPMode == OP_MODE_IBSS);
2413
2414
2415     //4 <1> Setup PHY Attributes and Basic Rate Set/Operational Rate Set
2416     prBssInfo->ucNonHTBasicPhyType = (UINT_8)
2417         rNonHTAdHocModeAttributes[prBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
2418     prBssInfo->u2BSSBasicRateSet =
2419         rNonHTAdHocModeAttributes[prBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
2420
2421
2422     prBssInfo->u2OperationalRateSet =
2423         rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
2424
2425     rateGetDataRatesFromRateSet(prBssInfo->u2OperationalRateSet,
2426                                 prBssInfo->u2BSSBasicRateSet,
2427                                 prBssInfo->aucAllSupportedRates,
2428                                 &prBssInfo->ucAllSupportedRatesLen);
2429
2430     //4 <2> Setup BSSID
2431     if (!prBssInfo->fgHoldSameBssidForIBSS) {
2432
2433         for (i = 0; i < sizeof(aucBSSID)/sizeof(UINT_16); i++) {
2434             pu2BSSID[i] = (UINT_16)(kalRandomNumber() & 0xFFFF);
2435         }
2436
2437         aucBSSID[0] &= ~0x01; // 7.1.3.3.3 - The individual/group bit of the address is set to 0.
2438         aucBSSID[0] |= 0x02; // 7.1.3.3.3 - The universal/local bit of the address is set to 1.
2439
2440         COPY_MAC_ADDR(prBssInfo->aucBSSID, aucBSSID);
2441     }
2442
2443
2444     //4 <3> Setup Capability - Short Preamble
2445     if (rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].fgIsShortPreambleOptionImplemented &&
2446         ((prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_SHORT) || /* Short Preamble Option Enable is TRUE */
2447          (prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_AUTO)) ) {
2448
2449         prBssInfo->fgIsShortPreambleAllowed = TRUE;
2450         prBssInfo->fgUseShortPreamble = TRUE;
2451     }
2452     else {
2453         prBssInfo->fgIsShortPreambleAllowed = FALSE;
2454         prBssInfo->fgUseShortPreamble = FALSE;
2455     }
2456
2457
2458     //4 <4> Setup Capability - Short Slot Time
2459     // 7.3.1.4 For IBSS, the Short Slot Time subfield shall be set to 0.
2460     prBssInfo->fgUseShortSlotTime = FALSE; /* Set to FALSE for AdHoc */
2461
2462
2463     //4 <5> Compoase Capability
2464     prBssInfo->u2CapInfo = CAP_INFO_IBSS;
2465
2466     if (prBssInfo->fgIsProtection) {
2467         prBssInfo->u2CapInfo |= CAP_INFO_PRIVACY;
2468     }
2469
2470     if (prBssInfo->fgIsShortPreambleAllowed) {
2471         prBssInfo->u2CapInfo |= CAP_INFO_SHORT_PREAMBLE;
2472     }
2473
2474     if (prBssInfo->fgUseShortSlotTime) {
2475         prBssInfo->u2CapInfo |= CAP_INFO_SHORT_SLOT_TIME;
2476     }
2477
2478
2479     //4 <6> Find Lowest Basic Rate Index for default TX Rate of MMPDU
2480     rateGetLowestRateIndexFromRateSet(prBssInfo->u2BSSBasicRateSet, &ucLowestBasicRateIndex);
2481
2482     prBssInfo->ucHwDefaultFixedRateCode =
2483         aucRateIndex2RateCode[PREAMBLE_DEFAULT_LONG_NONE][ucLowestBasicRateIndex];
2484
2485     return;
2486 } /* end of ibssInitForAdHoc() */
2487
2488 #endif /* CFG_SUPPORT_ADHOC */
2489
2490
2491 #if CFG_SUPPORT_AAA
2492
2493 /*----------------------------------------------------------------------------*/
2494 /* Routines for BSS(AP) only                                                  */
2495 /*----------------------------------------------------------------------------*/
2496 /*----------------------------------------------------------------------------*/
2497 /*!
2498 * @brief This function will initial the BSS_INFO_T for AP Mode.
2499 *
2500 * @param[in] prBssInfo              Given related BSS_INFO_T.
2501 *
2502 * @return (none)
2503 */
2504 /*----------------------------------------------------------------------------*/
2505 VOID
2506 bssInitForAP (
2507     IN P_ADAPTER_T  prAdapter,
2508     IN P_BSS_INFO_T prBssInfo,
2509     IN BOOLEAN fgIsRateUpdate
2510     )
2511 {
2512     UINT_8 ucLowestBasicRateIndex;
2513
2514     P_AC_QUE_PARMS_T          prACQueParms;
2515
2516     ENUM_WMM_ACI_T eAci;
2517
2518     UINT_8 auCWminLog2ForBcast[WMM_AC_INDEX_NUM] = {  4/*BE*/, 4 /*BK*/, 3/*VO*/, 2/*VI*/};
2519     UINT_8 auCWmaxLog2ForBcast[WMM_AC_INDEX_NUM] = { 10, 10, 4, 3};
2520     UINT_8 auAifsForBcast[WMM_AC_INDEX_NUM] = { 3, 7, 2, 2 };
2521     UINT_8 auTxopForBcast[WMM_AC_INDEX_NUM] = { 0, 0, 94, 47 }; /* If the AP is OFDM */
2522
2523     UINT_8 auCWminLog2[WMM_AC_INDEX_NUM] = {  4 /*BE*/, 4 /*BK*/, 3 /*VO*/, 2 /*VI*/};
2524     UINT_8 auCWmaxLog2[WMM_AC_INDEX_NUM] = { 7, 10, 4, 3};
2525     UINT_8 auAifs[WMM_AC_INDEX_NUM] = { 3, 7, 1, 1 };
2526     UINT_8 auTxop[WMM_AC_INDEX_NUM] = { 0, 0, 94, 47 }; /* If the AP is OFDM */
2527
2528     DEBUGFUNC("bssInitForAP");
2529     DBGLOG(BSS, LOUD,("\n"));
2530
2531     ASSERT(prBssInfo);
2532     ASSERT((prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) || (prBssInfo->eCurrentOPMode == OP_MODE_BOW));
2533
2534 #if 0
2535     prAdapter->rWifiVar.rConnSettings.fgRxShortGIDisabled = TRUE;
2536     prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode = CONFIG_BW_20M;
2537     prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode = CONFIG_BW_20M;
2538 #endif
2539
2540
2541     //4 <1> Setup PHY Attributes and Basic Rate Set/Operational Rate Set
2542     prBssInfo->ucNonHTBasicPhyType = (UINT_8)
2543             rNonHTApModeAttributes[prBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
2544     prBssInfo->u2BSSBasicRateSet =
2545             rNonHTApModeAttributes[prBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
2546
2547
2548     prBssInfo->u2OperationalRateSet =
2549             rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
2550
2551     if (fgIsRateUpdate) {
2552             rateGetDataRatesFromRateSet(prBssInfo->u2OperationalRateSet,
2553                                         prBssInfo->u2BSSBasicRateSet,
2554                                         prBssInfo->aucAllSupportedRates,
2555                                         &prBssInfo->ucAllSupportedRatesLen);
2556     }
2557
2558     //4 <2> Setup BSSID
2559     COPY_MAC_ADDR(prBssInfo->aucBSSID, prBssInfo->aucOwnMacAddr);
2560
2561
2562     //4 <3> Setup Capability - Short Preamble
2563     if (rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].fgIsShortPreambleOptionImplemented &&
2564         ((prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_SHORT) || /* Short Preamble Option Enable is TRUE */
2565          (prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_AUTO)) ) {
2566
2567         prBssInfo->fgIsShortPreambleAllowed = TRUE;
2568         prBssInfo->fgUseShortPreamble = TRUE;
2569     }
2570     else {
2571         prBssInfo->fgIsShortPreambleAllowed = FALSE;
2572         prBssInfo->fgUseShortPreamble = FALSE;
2573     }
2574
2575
2576     //4 <4> Setup Capability - Short Slot Time
2577     prBssInfo->fgUseShortSlotTime = TRUE;
2578
2579     //4 <5> Compoase Capability
2580     prBssInfo->u2CapInfo = CAP_INFO_ESS;
2581
2582     if (prBssInfo->fgIsProtection) {
2583         prBssInfo->u2CapInfo |= CAP_INFO_PRIVACY;
2584     }
2585
2586     if (prBssInfo->fgIsShortPreambleAllowed) {
2587         prBssInfo->u2CapInfo |= CAP_INFO_SHORT_PREAMBLE;
2588     }
2589
2590     if (prBssInfo->fgUseShortSlotTime) {
2591         prBssInfo->u2CapInfo |= CAP_INFO_SHORT_SLOT_TIME;
2592     }
2593
2594
2595     //4 <6> Find Lowest Basic Rate Index for default TX Rate of MMPDU
2596     rateGetLowestRateIndexFromRateSet(prBssInfo->u2BSSBasicRateSet, &ucLowestBasicRateIndex);
2597
2598     prBssInfo->ucHwDefaultFixedRateCode =
2599         aucRateIndex2RateCode[PREAMBLE_DEFAULT_LONG_NONE][ucLowestBasicRateIndex];
2600
2601
2602     //4 <7> Fill the EDCA
2603
2604     prACQueParms = prBssInfo->arACQueParmsForBcast;
2605
2606     for(eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++){
2607
2608         prACQueParms[eAci].fgIsACMSet = FALSE;
2609         prACQueParms[eAci].u2Aifsn = auAifsForBcast[eAci];
2610         prACQueParms[eAci].u2CWmin = BIT(auCWminLog2ForBcast[eAci])-1;
2611         prACQueParms[eAci].u2CWmax = BIT(auCWmaxLog2ForBcast[eAci])-1;
2612         prACQueParms[eAci].u2TxopLimit = auTxopForBcast[eAci];
2613
2614         prBssInfo->aucCWminLog2ForBcast[eAci] = auCWminLog2ForBcast[eAci] ; /* used to send WMM IE */
2615         prBssInfo->aucCWmaxLog2ForBcast[eAci] = auCWmaxLog2ForBcast[eAci] ;
2616
2617         DBGLOG(BSS, INFO, ("Bcast: eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
2618                    eAci,prACQueParms[eAci].fgIsACMSet ,
2619                    prACQueParms[eAci].u2Aifsn,
2620                    prACQueParms[eAci].u2CWmin,
2621                    prACQueParms[eAci].u2CWmax,
2622                    prACQueParms[eAci].u2TxopLimit));
2623
2624     }
2625
2626     prACQueParms = prBssInfo->arACQueParms;
2627
2628     for(eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++){
2629
2630         prACQueParms[eAci].fgIsACMSet = FALSE;
2631         prACQueParms[eAci].u2Aifsn = auAifs[eAci];
2632         prACQueParms[eAci].u2CWmin = BIT(auCWminLog2[eAci])-1;
2633         prACQueParms[eAci].u2CWmax = BIT(auCWmaxLog2[eAci])-1;
2634         prACQueParms[eAci].u2TxopLimit = auTxop[eAci];
2635
2636         DBGLOG(BSS, INFO, ("eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
2637                    eAci,prACQueParms[eAci].fgIsACMSet ,
2638                    prACQueParms[eAci].u2Aifsn,
2639                    prACQueParms[eAci].u2CWmin,
2640                    prACQueParms[eAci].u2CWmax,
2641                    prACQueParms[eAci].u2TxopLimit));
2642     }
2643
2644     /* Note: Caller should update the EDCA setting to HW by nicQmUpdateWmmParms() it there is no AIS network */
2645     /* Note: In E2, only 4 HW queues. The the Edca parameters should be folow by AIS network */
2646     /* Note: In E3, 8 HW queues.  the Wmm parameters should be updated to right queues  according to BSS */
2647
2648
2649     return;
2650 } /* end of bssInitForAP() */
2651
2652 #if 0
2653 /*----------------------------------------------------------------------------*/
2654 /*!
2655 * @brief Update DTIM Count
2656 *
2657 * @param[in] eNetTypeIndex      Specify which network to update
2658 *
2659 * @return (none)
2660 */
2661 /*----------------------------------------------------------------------------*/
2662 VOID
2663 bssUpdateDTIMCount (
2664     IN P_ADAPTER_T  prAdapter,
2665     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex
2666     )
2667 {
2668     P_BSS_INFO_T prBssInfo;
2669
2670
2671     ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
2672
2673     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
2674
2675     if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
2676
2677         // Setup DTIM Count for next TBTT.
2678         if (prBssInfo->ucDTIMCount > 0) {
2679             prBssInfo->ucDTIMCount--;
2680         }
2681         else {
2682
2683             ASSERT(prBssInfo->ucDTIMPeriod > 0);
2684
2685             prBssInfo->ucDTIMCount = prBssInfo->ucDTIMPeriod - 1;
2686         }
2687     }
2688
2689     return;
2690 } /* end of bssUpdateDTIMIE() */
2691
2692
2693 /*----------------------------------------------------------------------------*/
2694 /*!
2695 * @brief This function is used to set the Virtual Bitmap in TIM Information Elements
2696 *
2697 * @param[in] prBssInfo      Pointer to the BSS_INFO_T.
2698 * @param[in] u2AssocId      The association id to set in Virtual Bitmap.
2699 *
2700 * @return (none)
2701 */
2702 /*----------------------------------------------------------------------------*/
2703 VOID
2704 bssSetTIMBitmap (
2705     IN P_ADAPTER_T  prAdapter,
2706     IN P_BSS_INFO_T prBssInfo,
2707     IN UINT_16 u2AssocId
2708     )
2709 {
2710
2711     ASSERT(prBssInfo);
2712
2713     if (prBssInfo->ucNetTypeIndex == NETWORK_TYPE_P2P_INDEX) {
2714         P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
2715
2716
2717         prP2pSpecificBssInfo = &(prAdapter->rWifiVar.rP2pSpecificBssInfo);
2718
2719         /* Use Association ID == 0 for BMCAST indication */
2720         if (u2AssocId == 0) {
2721
2722             prP2pSpecificBssInfo->ucBitmapCtrl |= (UINT_8)BIT(0);
2723         }
2724         else {
2725             PUINT_8 pucPartialVirtualBitmap;
2726             UINT_8 ucBitmapToSet;
2727
2728
2729             pucPartialVirtualBitmap = &prP2pSpecificBssInfo->aucPartialVirtualBitmap[(u2AssocId >> 3)]; // (u2AssocId / 8)
2730             ucBitmapToSet = (UINT_8) BIT((u2AssocId % 8));
2731
2732             if (*pucPartialVirtualBitmap & ucBitmapToSet) {
2733                 /* The virtual bitmap has been set */
2734                 return;
2735             }
2736
2737             *pucPartialVirtualBitmap |= ucBitmapToSet;
2738
2739             // Update u2SmallestAID and u2LargestAID
2740             if ((u2AssocId < prP2pSpecificBssInfo->u2SmallestAID) ||
2741                 (prP2pSpecificBssInfo->u2SmallestAID == 0)) {
2742                 prP2pSpecificBssInfo->u2SmallestAID = u2AssocId;
2743             }
2744
2745             if ((u2AssocId > prP2pSpecificBssInfo->u2LargestAID) ||
2746                 (prP2pSpecificBssInfo->u2LargestAID == 0)) {
2747                 prP2pSpecificBssInfo->u2LargestAID = u2AssocId;
2748             }
2749         }
2750     }
2751
2752     return;
2753 } /* end of bssSetTIMBitmap() */
2754 #endif
2755
2756 #endif /* CFG_SUPPORT_AAA */
2757
2758
2759 VOID
2760 bssCreateStaRecFromAuth (
2761     IN P_ADAPTER_T  prAdapter
2762     )
2763 {
2764
2765 }
2766
2767
2768 VOID
2769 bssUpdateStaRecFromAssocReq (
2770     IN P_ADAPTER_T  prAdapter
2771     )
2772 {
2773
2774 }
2775
2776