support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6620 / wlan / mgmt / p2p_fsm.c
1 /*
2 ** $Id: //Department/DaVinci/TRUNK/WiFi_P2P_Driver/mgmt/p2p_fsm.c#61 $
3 */
4
5 /*! \file   "p2p_fsm.c"
6     \brief  This file defines the FSM for P2P Module.
7
8     This file defines the FSM for P2P Module.
9 */
10
11
12
13 /*
14 ** $Log: p2p_fsm.c $
15 **
16 ** 07 29 2013 yuche.tsai
17 ** [ALPS00818788] [PreRC1][Mobile HotSpot]DUT should support hidden SSID broadcast for Mobile HotSpot
18 ** Support hidden SSID for MT6630.
19 ** FW Label: 20130729_ALPS_WIFI_FW_MT6620_V1_12
20 **
21 ** 12 20 2012 yuche.tsai
22 ** [ALPS00410124] [Rose][Free Test][KE][rlmUpdateParamsForAP]The device reboot automaticly and then "Fatal/Kernel" pops up during use data service.(Once)
23 ** Fix possible NULL station record cause KE under AP mode.
24 ** May due to variable uninitial.
25 ** Review: http://mtksap20:8080/go?page=NewReview&reviewid=49970
26 ** 
27 ** 09 12 2012 wcpadmin
28 ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
29 ** .
30 ** 
31 ** 08 31 2012 yuche.tsai
32 ** [ALPS00349585] [6577JB][WiFi direct][KE]Establish p2p connection while both device have connected to AP previously,one device reboots automatically with KE
33 ** Fix possible KE when concurrent & disconnect.
34 ** 
35 ** 08 21 2012 yuche.tsai
36 ** NULL
37 ** fix disconnect indication.
38 ** 
39 ** 08 16 2012 yuche.tsai
40 ** NULL
41 ** Fix compile warning.
42 ** 
43 ** 08 14 2012 yuche.tsai
44 ** NULL
45 ** Fix p2p bug find on ALPS.JB trunk.
46 ** 
47 ** 07 27 2012 yuche.tsai
48 ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
49 ** Update for driver unload KE issue.
50 ** 
51 ** 07 26 2012 yuche.tsai
52 ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
53 ** Update driver code of ALPS.JB for hot-spot.
54 ** 
55 ** 07 19 2012 yuche.tsai
56 ** NULL
57 ** Code update for JB.
58  *
59  * 07 17 2012 yuche.tsai
60  * NULL
61  * Compile no error before trial run.
62  *
63  * 07 05 2011 yuche.tsai
64  * [WCXRP00000821] [Volunteer Patch][WiFi Direct][Driver] WiFi Direct Connection Speed Issue
65  * Fix the compile flag of enhancement.
66  *
67  * 07 05 2011 yuche.tsai
68  * [WCXRP00000808] [Volunteer Patch][MT6620][Driver/FW] Device discoverability issue fix
69  * Change device discoverability methodology. From driver SCAN to FW lock channel.
70  *
71  * 07 05 2011 yuche.tsai
72  * [WCXRP00000821] [Volunteer Patch][WiFi Direct][Driver] WiFi Direct Connection Speed Issue
73  * Add wifi direct connection enhancement method I, II & VI.
74  *
75  * 07 05 2011 yuche.tsai
76  * [WCXRP00000833] [Volunteer Patch][WiFi Direct][Driver] Service Discovery Frame RX Indicate Issue
77  * Fix Service Discovery Race Condition Issue.
78  *
79  * 06 23 2011 cp.wu
80  * [WCXRP00000798] [MT6620 Wi-Fi][Firmware] Follow-ups for WAPI frequency offset workaround in firmware SCN module
81  * change parameter name from PeerAddr to BSSID
82  *
83  * 06 21 2011 yuche.tsai
84  * [WCXRP00000799] [Volunteer Patch][MT6620][Driver] Connection Indication Twice Issue.
85  * Fix an issue of accepting connection of GO.
86  *
87  * 06 21 2011 yuche.tsai
88  * [WCXRP00000775] [Volunteer Patch][MT6620][Driver] Dynamic enable SD capability
89  * Drop GAS frame when SD is not enabled.
90  *
91  * 06 20 2011 yuche.tsai
92  * NULL
93  * Fix compile error.
94  *
95  * 06 20 2011 yuche.tsai
96  * [WCXRP00000799] [Volunteer Patch][MT6620][Driver] Connection Indication Twice Issue.
97  * Fix connection indication twice issue.
98  *
99  * 06 20 2011 cp.wu
100  * [WCXRP00000798] [MT6620 Wi-Fi][Firmware] Follow-ups for WAPI frequency offset workaround in firmware SCN module
101  * 1. specify target's BSSID when requesting channel privilege.
102  * 2. pass BSSID information to firmware domain
103  *
104  * 06 20 2011 yuche.tsai
105  * [WCXRP00000795] [Volunteer Patch][MT6620][Driver] GO can not connect second device issue
106  * Solve P2P GO can not formation with second device issue.
107  *
108  * 06 14 2011 yuche.tsai
109  * NULL
110  * Change disconnect feature.
111  *
112  * 06 10 2011 yuche.tsai
113  * [WCXRP00000775] [Volunteer Patch][MT6620][Driver] Dynamic enable SD capability[WCXRP00000776] [Need Patch][MT6620][Driver] MT6620 response probe request of P2P device with P2P IE under Hot Spot mode.
114  * 1. Dynamic enable SD capability after P2P supplicant ready.
115  * 2. Avoid response probe respone with p2p IE when under hot spot mode.
116  *
117  * 06 07 2011 yuche.tsai
118  * [WCXRP00000763] [Volunteer Patch][MT6620][Driver] RX Service Discovery Frame under AP mode Issue
119  * Fix RX SD request under AP mode issue.
120  *
121  * 06 02 2011 cp.wu
122  * [WCXRP00000681] [MT5931][Firmware] HIF code size reduction
123  * eliminate unused parameters for SAA-FSM
124  *
125  * 05 26 2011 yuche.tsai
126  * [WCXRP00000745] Support accepting connection after one Group Connection Lost.
127
128 After Group Formation & lost connection, if MT6620 behave as:
129
130 1. GO: It would keep under GO state until been dissolved by supplicant.
131
132           At this time, other P2P device can use join method to join this group.
133
134
135 2. GC: It would keep on searching target GO or target device until been dissolved by supplicant.
136
137 At this time, it would ignore other P2P device formation request.
138
139
140 --
141
142 Modification: Make driver to accept GO NEGO REQ at this time, to let user decide to accept new connection or not.
143
144  * [Volunteer Patch][MT6620][Driver]
145  * Driver would indicate connection request, if password ID is not ready but connection request is issued.
146  *
147  * 05 18 2011 yuche.tsai
148  * [WCXRP00000728] [Volunteer Patch][MT6620][Driver] Service Discovery Request TX issue.
149  * A solution for both connection request & IO control.
150  *
151  * 05 16 2011 yuche.tsai
152  * [WCXRP00000728] [Volunteer Patch][MT6620][Driver] Service Discovery Request TX issue.
153  * Fix SD request can not send out issue.
154  *
155  * 05 09 2011 terry.wu
156  * [WCXRP00000711] [MT6620 Wi-Fi][Driver] Set Initial value of StaType in StaRec for Hotspot Client
157  * Set initial value of StaType in StaRec for hotspot client.
158  *
159  * 05 04 2011 yuche.tsai
160  * [WCXRP00000697] [Volunteer Patch][MT6620][Driver]
161  * Bug fix for p2p descriptor is NULL if BSS descriptor is found first.
162  *
163  * 05 04 2011 yuche.tsai
164  * NULL
165  * Support partial persistent group function.
166  *
167  * 05 02 2011 yuche.tsai
168  * [WCXRP00000693] [Volunteer Patch][MT6620][Driver] Clear Formation Flag after TX lifetime timeout.
169  * Clear formation flag after formation timeout.
170  *
171  * 04 20 2011 yuche.tsai
172  * [WCXRP00000668] [Volunteer Patch][MT6620][Driver] Possible race condition when add scan & query scan result at the same time.
173  * Fix side effect while starting ATGO.
174  *
175  * 04 20 2011 yuche.tsai
176  * NULL
177  * Fix ASSERT issue in FW, side effect of last change.
178  *
179  * 04 19 2011 yuche.tsai
180  * [WCXRP00000668] [Volunteer Patch][MT6620][Driver] Possible race condition when add scan & query scan result at the same time.
181  * Workaround for multiple device connection, before invitation ready.
182  *
183  * 04 19 2011 yuche.tsai
184  * [WCXRP00000665] [Wifi Direct][MT6620 E4] When use Ralink's dongle to establish wifi direct connection with PBC. But 6573 always not pop accept option to establish connection.
185  * Support connection indication when GO NEGO REQ doesn't have configure method, instead it has PasswordID.
186  *
187  * 04 18 2011 yuche.tsai
188  * NULL
189  * Fix error.
190  *
191  * 04 14 2011 yuche.tsai
192  * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
193  * Fix a connection issue.
194  *
195  * 04 14 2011 yuche.tsai
196  * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
197  * Fix the channel issue of AP mode.
198  *
199  * 04 14 2011 yuche.tsai
200  * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
201  * Connection flow refine for Sigma test.
202  *
203  * 04 09 2011 yuche.tsai
204  * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
205  * Fix Device discoverability related issue.
206  *
207  * 04 09 2011 yuche.tsai
208  * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
209  * Fix bug for Device Discoverability.
210  *
211  * 04 08 2011 yuche.tsai
212  * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
213  * Fix compile error.
214  *
215  * 04 08 2011 yuche.tsai
216  * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
217  * Add device discoverability support.
218  *
219  * 03 28 2011 yuche.tsai
220  * NULL
221  * Fix a possible issue for retry join when media status connected.
222  *
223  * 03 25 2011 yuche.tsai
224  * NULL
225  * Improve some error handleing.
226  *
227  * 03 24 2011 yuche.tsai
228  * NULL
229  * Assign AID before change STA_REC state to state 3.
230  *
231  * 03 23 2011 yuche.tsai
232  * NULL
233  * Fix Response Rate Issue when TX Auth Rsp Frame under P2P Mode.
234  *
235  * 03 23 2011 yuche.tsai
236  * NULL
237  * Fix issue of connection to one GC.
238  *
239  * 03 23 2011 yuche.tsai
240  * NULL
241  * Fix ASSERT issue when starting Hot-spot.
242  *
243  * 03 22 2011 yuche.tsai
244  * NULL
245  * When Target Information is not available, change to passive mode.
246  *
247  * 03 22 2011 yuche.tsai
248  * NULL
249  * Fix one connection issue while using Keypad to connect a GO.
250  *
251  * 03 22 2011 yuche.tsai
252  * NULL
253  * 1. Fix two issues that may cause kernel panic.
254  *
255  * 03 22 2011 yuche.tsai
256  * NULL
257  * Fix GC connect to other device issue.
258  *
259  * 03 22 2011 yuche.tsai
260  * NULL
261  * 1.Shorten the LISTEN interval.
262  * 2. Fix IF address issue when we are GO
263  * 3. Fix LISTEN channel issue.
264  *
265  * 03 22 2011 yuche.tsai
266  * NULL
267  * Modify formation policy setting.
268  *
269  * 03 21 2011 yuche.tsai
270  * NULL
271  * Solve Listen State doesn't response probe response issue.
272  *
273  * 03 21 2011 yuche.tsai
274  * NULL
275  * Change P2P Connection Request Flow.
276  *
277  * 03 19 2011 yuche.tsai
278  * [WCXRP00000584] [Volunteer Patch][MT6620][Driver] Add beacon timeout support for WiFi Direct.
279  * Add beacon timeout support.
280  *
281  * 03 19 2011 yuche.tsai
282  * [WCXRP00000583] [Volunteer Patch][MT6620][Driver] P2P connection of the third peer issue
283  * Indicate the correct Group SSID when join on Group.
284  *
285  * 03 19 2011 yuche.tsai
286  * [WCXRP00000583] [Volunteer Patch][MT6620][Driver] P2P connection of the third peer issue
287  * Support the third P2P device to join GO/GC group.
288  *
289  * 03 19 2011 yuche.tsai
290  * [WCXRP00000581] [Volunteer Patch][MT6620][Driver] P2P IE in Assoc Req Issue
291  * Append P2P IE in Assoc Req, so that GC can be discovered in probe response of GO.
292  *
293  * 03 18 2011 yuche.tsai
294  * [WCXRP00000578] [Volunteer Patch][MT6620][Driver] Separate Connection Request from general IOCTL
295  * Separate connection request from general IOCTL.
296  *
297  * 03 18 2011 yuche.tsai
298  * [WCXRP00000574] [Volunteer Patch][MT6620][Driver] Modify P2P FSM Connection Flow
299  * Modify connection flow after Group Formation Complete, or device connect to a GO.
300  * Instead of request channel & connect directly, we use scan to allocate channel bandwidth & connect after RX BCN.
301  *
302  * 03 17 2011 yuche.tsai
303  * NULL
304  * When AIS is connect to an AP, Hot Spot would be enabled under fixed same channel.
305  *
306  * 03 17 2011 yuche.tsai
307  * NULL
308  * Solve the Group Info IE in Probe Response incorrect issue.
309  *
310  * 03 17 2011 yuche.tsai
311  * NULL
312  * Release Channel after Join Complete.
313  *
314  * 03 16 2011 wh.su
315  * [WCXRP00000530] [MT6620 Wi-Fi] [Driver] skip doing p2pRunEventAAAComplete after send assoc response Tx Done
316  * enable the protected while at P2P start GO, and skip some security check .
317  *
318  * 03 15 2011 yuche.tsai
319  * [WCXRP00000560] [Volunteer Patch][MT6620][Driver] P2P Connection from UI using KEY/DISPLAY issue
320  * Fix local configure method issue.
321  *
322  * 03 15 2011 yuche.tsai
323  * [WCXRP00000560] [Volunteer Patch][MT6620][Driver] P2P Connection from UI using KEY/DISPLAY issue
324  * Fix some configure method issue.
325  *
326  * 03 14 2011 yuche.tsai
327  * NULL
328  * .
329  *
330  * 03 14 2011 yuche.tsai
331  * NULL
332  * Fix password ID issue.
333  *
334  * 03 10 2011 yuche.tsai
335  * NULL
336  * Add P2P API.
337  *
338  * 03 08 2011 yuche.tsai
339  * [WCXRP00000480] [Volunteer Patch][MT6620][Driver] WCS IE format issue[WCXRP00000509] [Volunteer Patch][MT6620][Driver] Kernal panic when remove p2p module.
340  * .
341  *
342  * 03 07 2011 yuche.tsai
343  * [WCXRP00000502] [Volunteer Patch][MT6620][Driver] Fix group ID issue when doing Group Formation.
344  * .
345  *
346  * 03 07 2011 wh.su
347  * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
348  * rename the define to anti_pviracy.
349  *
350  * 03 05 2011 wh.su
351  * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
352  * add the code to get the check rsponse and indicate to app.
353  *
354  * 03 04 2011 wh.su
355  * [WCXRP00000510] [MT6620 Wi-Fi] [Driver] Fixed the CTIA enter test mode issue
356  * fixed the p2p action frame type check for device request indication.
357  *
358  * 03 02 2011 yuche.tsai
359  * [WCXRP00000245] 1. Invitation Request/Response.
360 2. Provision Discovery Request/Response
361
362  * Fix Service Discovery RX packet buffer pointer.
363  *
364  * 03 01 2011 yuche.tsai
365  * [WCXRP00000501] [Volunteer Patch][MT6620][Driver] No common channel issue when doing GO formation
366  * Update channel issue when doing GO formation..
367  *
368  * 03 01 2011 yuche.tsai
369  * [WCXRP00000245] 1. Invitation Request/Response.
370 2. Provision Discovery Request/Response
371
372  * Update Service Discovery Related wlanoid function.
373  *
374  * 02 21 2011 yuche.tsai
375  * [WCXRP00000481] [Volunteer Patch][MT6620][FW] Scan hang under concurrent case.
376  * Fix all BE issue of WSC or P2P IE.
377  *
378  * 02 18 2011 wh.su
379  * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
380  * fixed the wsc config method mapping to driver used config method issue.
381  *
382  * 02 18 2011 yuche.tsai
383  * [WCXRP00000479] [Volunteer Patch][MT6620][Driver] Probe Response of P2P using 11b rate.
384  * Update basic rate to FW, after P2P is initialed.
385  *
386  * 02 18 2011 yuche.tsai
387  * [WCXRP00000478] [Volunteer Patch][MT6620][Driver] Probe request frame during search phase do not contain P2P wildcard SSID.
388  * Use P2P Wildcard SSID when scan type of P2P_WILDCARD_SSID is set.
389  *
390  * 02 18 2011 yuche.tsai
391  * [WCXRP00000480] [Volunteer Patch][MT6620][Driver] WCS IE format issue
392  * Fix WSC IE BE format issue.
393  *
394  * 02 17 2011 wh.su
395  * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
396  * append the WSC IE config method attribute at provision discovery request.
397  *
398  * 02 16 2011 wh.su
399  * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
400  * fixed the probe request send out without WSC IE issue (at P2P).
401  *
402  * 02 16 2011 yuche.tsai
403  * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
404  * If two station connected to the Hot-Spot and one disconnect, FW would get into an infinite loop
405  *
406  * 02 15 2011 yuche.tsai
407  * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
408  * Fix re-connection issue after RX deauthentication.
409  *
410  * 02 15 2011 yuche.tsai
411  * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
412  * Fix conneciton issue after disconnect with AP.
413  *
414  * 02 12 2011 yuche.tsai
415  * [WCXRP00000441] [Volunteer Patch][MT6620][Driver] BoW can not create desired station type when Hot Spot is enabled.
416  * P2P Create Station Type according to Target BSS capability.
417  *
418  * 02 10 2011 yuche.tsai
419  * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
420  * Support Disassoc & Deauthentication for Hot-Spot.
421  *
422  * 02 09 2011 yuche.tsai
423  * [WCXRP00000245] 1. Invitation Request/Response.
424 2. Provision Discovery Request/Response
425
426  * Add Service Discovery Indication Related code.
427  *
428  * 02 09 2011 yuche.tsai
429  * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
430  * Add Support for MLME deauthentication for Hot-Spot.
431  *
432  * 02 09 2011 yuche.tsai
433  * [WCXRP00000429] [Volunteer Patch][MT6620][Driver] Hot Spot Client Limit Issue
434  * Fix Client Limit Issue.
435  *
436  * 02 08 2011 yuche.tsai
437  * [WCXRP00000419] [Volunteer Patch][MT6620/MT5931][Driver] Provide function of disconnect to target station for AAA module.
438  * Disconnect every station client when disolve on P2P group.
439  *
440  * 02 08 2011 yuche.tsai
441  * [WCXRP00000245] 1. Invitation Request/Response.
442 2. Provision Discovery Request/Response
443
444  * 1. Fix Service Disocvery Logical issue.
445  * 2. Fix a NULL pointer access violation issue when sending deauthentication packet to a class error station.
446  *
447  * 02 08 2011 yuche.tsai
448  * [WCXRP00000419] [Volunteer Patch][MT6620/MT5931][Driver] Provide function of disconnect to target station for AAA module.
449  * Workaround of disable P2P network.
450  *
451  * 02 08 2011 yuche.tsai
452  * [WCXRP00000421] [Volunteer Patch][MT6620][Driver] Fix incorrect SSID length Issue
453  * 1. Fixed SSID wrong length issue.
454  * 2. Under Hot Spot configuration, there won't be any P2P IE.
455  * 3. Under Hot Spot configuration, P2P FSM won't get into LISTEN state first.
456  *
457  * 01 27 2011 yuche.tsai
458  * [WCXRP00000399] [Volunteer Patch][MT6620/MT5931][Driver] Fix scan side effect after P2P module separate.
459  * Modify Start GO flow.
460  *
461  * 01 27 2011 yuche.tsai
462  * [WCXRP00000399] [Volunteer Patch][MT6620/MT5931][Driver] Fix scan side effect after P2P module separate.
463  * Fix desire phy type set issue.
464  *
465  * 01 27 2011 yuche.tsai
466  * [WCXRP00000399] [Volunteer Patch][MT6620/MT5931][Driver] Fix scan side effect after P2P module separate.
467  * Add desire phy type set phase I.
468  *
469  * 01 26 2011 yuche.tsai
470  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
471  * Fix P2P Disconnect Issue.
472  *
473  * 01 26 2011 yuche.tsai
474  * [WCXRP00000245] 1. Invitation Request/Response.
475 2. Provision Discovery Request/Response
476
477  * Add Service Discovery Function.
478  *
479  * 01 26 2011 cm.chang
480  * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
481  * .
482  *
483  * 01 25 2011 yuche.tsai
484  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
485  * Fix compile error when DBG is disabled.
486  *
487  * 01 25 2011 yuche.tsai
488  * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
489  * Change Station Type Definition.
490  *
491  * 01 19 2011 yuche.tsai
492  * [WCXRP00000353] [Volunteer Patch][MT6620][Driver] Desired Non-HT Rate Set update when STA record is created under AP Mode.
493  * Add P2P QoS Support.
494  *
495  * 01 19 2011 george.huang
496  * [WCXRP00000355] [MT6620 Wi-Fi] Set WMM-PS related setting with qualifying AP capability
497  * Null NOA attribute setting when no related parameters.
498  *
499  * 01 14 2011 yuche.tsai
500  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
501  * Modify AAA flow according to CM's comment.
502  *
503  * 01 13 2011 yuche.tsai
504  * [WCXRP00000353] [Volunteer Patch][MT6620][Driver] Desired Non-HT Rate Set update when STA record is created under AP Mode.
505  * Resolve Channel ZERO issue. (Uninitialized default channel)
506  *
507  * 01 13 2011 yuche.tsai
508  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
509  * Update P2P State Debug Message.
510  *
511  * 01 12 2011 yuche.tsai
512  * [WCXRP00000353] [Volunteer Patch][MT6620][Driver] Desired Non-HT Rate Set update when STA record is created under AP Mode.
513  * Fix bug when allocating message buffer.
514  *
515  * 01 12 2011 yuche.tsai
516  * [WCXRP00000353] [Volunteer Patch][MT6620][Driver] Desired Non-HT Rate Set update when STA record is created under AP Mode.
517  * Update Phy Type Set. When legacy client is connected, it can use 11b rate,
518  * but if the P2P device is connected, 11b rate is not allowed.
519  *
520  * 01 12 2011 yuche.tsai
521  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
522  * 1. Modify Channel Acquire Time of AP mode from 5s to 1s.
523  * 2. Call cnmP2pIsPermit() before active P2P network.
524  * 3. Add channel selection support for AP mode.
525  *
526  * 01 12 2011 yuche.tsai
527  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
528  * Fix Bug of reference to NULL pointer.
529  *
530  * 01 12 2011 yuche.tsai
531  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
532  * Modify some behavior of AP mode.
533  *
534  * 01 12 2011 yuche.tsai
535  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
536  * Fix bug of wrong pointer check.
537  *
538  * 01 12 2011 yuche.tsai
539  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
540  * Fix Compile Error.
541  *
542  * 01 11 2011 yuche.tsai
543  * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
544  * Add station record into client list before change it state from STATE_2 to STATE_3.
545  *
546  * 01 05 2011 yuche.tsai
547  * [WCXRP00000345] [MT6620][Volunteer Patch] P2P may issue a SSID specified scan request, but the SSID length is still invalid.
548  * Specify SSID Type when issue a scan request.
549  *
550  * 01 05 2011 cp.wu
551  * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease physically continous memory demands
552  * correct typo
553  *
554  * 01 05 2011 george.huang
555  * [WCXRP00000343] [MT6620 Wi-Fi] Add TSF reset path for concurrent operation
556  * modify NOA update path for preventing assertion false alarm.
557  *
558  * 01 04 2011 cp.wu
559  * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease physically continous memory demands
560  * separate kalMemAlloc() into virtually-continous and physically-continous type to ease slab system pressure
561  *
562  * 01 03 2011 wh.su
563  * [WCXRP00000326] [MT6620][Wi-Fi][Driver] check in the binary format gl_sec.o.new instead of use change type!!!
564  * let the p2p ap mode acept a legacy device join.
565  *
566  * 12 22 2010 yuche.tsai
567  * [WCXRP00000245] 1. Invitation Request/Response.
568 2. Provision Discovery Request/Response
569
570  * Fix Compile Error.
571  *
572  * 12 15 2010 yuche.tsai
573  * [WCXRP00000245] 1. Invitation Request/Response.
574 2. Provision Discovery Request/Response
575
576  * Refine Connection Flow.
577  *
578  * 12 08 2010 yuche.tsai
579  * [WCXRP00000245] [MT6620][Driver] Invitation & Provision Discovery Feature Check-in
580  * [WCXRP000000245][MT6620][Driver] Invitation Request Feature Add
581  *
582  * 12 08 2010 yuche.tsai
583  * [WCXRP00000244] [MT6620][Driver] Add station record type for each client when in AP mode.
584  * Change STA Type under AP mode. We would tell if client is a P2P device or a legacy client by checking the P2P IE in assoc req frame.
585  *
586  * 12 07 2010 cm.chang
587  * [WCXRP00000239] MT6620 Wi-Fi][Driver][FW] Merge concurrent branch back to maintrunk
588  * The order of invoking nicUpdateBss() and rlm functions
589  *
590  * 12 02 2010 yuche.tsai
591  * NULL
592  * Update P2P Connection Policy for Invitation.
593  *
594  * 12 02 2010 yuche.tsai
595  * NULL
596  * Update P2P Connection Policy for Invitation & Provision Discovery.
597  *
598  * 11 30 2010 yuche.tsai
599  * NULL
600  * Invitation & Provision Discovery Indication.
601  *
602  * 11 30 2010 yuche.tsai
603  * NULL
604  * Update Configure Method indication & selection for Provision Discovery & GO_NEGO_REQ
605  *
606  * 11 30 2010 yuche.tsai
607  * NULL
608  * Update RCIP value when RX assoc request frame.
609  *
610  * 11 29 2010 yuche.tsai
611  * NULL
612  * Update P2P related function for INVITATION & PROVISION DISCOVERY.
613  *
614  * 11 26 2010 george.huang
615  * [WCXRP00000152] [MT6620 Wi-Fi] AP mode power saving function
616  * Update P2P PS for NOA function.
617  *
618  * 11 25 2010 yuche.tsai
619  * NULL
620  * Update Code for Invitation Related Function.
621  *
622  * 11 17 2010 wh.su
623  * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID[WCXRP00000179] [MT6620 Wi-Fi][FW] Set the Tx lowest rate at wlan table for normal operation
624  * fixed some ASSERT check.
625  *
626  * 11 05 2010 wh.su
627  * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
628  * fixed the p2p role code error.
629  *
630  * 11 04 2010 wh.su
631  * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
632  * adding the p2p random ssid support.
633  *
634  * 10 20 2010 wh.su
635  * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
636  * fixed the ASSERT check error
637  *
638  * 10 20 2010 wh.su
639  * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
640  * Add the code to support disconnect p2p group
641  *
642  * 10 19 2010 wh.su
643  * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine[WCXRP00000102] [MT6620 Wi-Fi] [FW] Add a compiling flag and code for support Direct GO at Android
644  * fixed the compiling error.
645  *
646  * 10 14 2010 wh.su
647  * [WCXRP00000102] [MT6620 Wi-Fi] [FW] Add a compiling flag and code for support Direct GO at Android
648  * adding a code to support Direct GO with a compiling flag .
649  *
650  * 10 08 2010 cp.wu
651  * [WCXRP00000087] [MT6620 Wi-Fi][Driver] Cannot connect to 5GHz AP, driver will cause FW assert.
652  * correct erroneous logic: specifying eBand with incompatible eSco
653  *
654  * 10 08 2010 wh.su
655  * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
656  * fixed the compiling error.
657  *
658  * 10 08 2010 wh.su
659  * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
660  * update the frog's new p2p state machine.
661  *
662  * 09 10 2010 wh.su
663  * NULL
664  * fixed the compiling error at WinXP.
665  *
666  * 09 07 2010 yuche.tsai
667  * NULL
668  * Reset Common IE Buffer of P2P INFO when scan request is issued.
669  * If an action frame other than public action frame is received, return direcly.
670  *
671  * 09 07 2010 wh.su
672  * NULL
673  * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
674  *
675  * 09 06 2010 wh.su
676  * NULL
677  * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
678  *
679  * 09 03 2010 kevin.huang
680  * NULL
681  * Refine #include sequence and solve recursive/nested #include issue
682  *
683  * 08 26 2010 yuche.tsai
684  * NULL
685  * Add P2P Connection Abort Event Message handler.
686  *
687  * 08 24 2010 cm.chang
688  * NULL
689  * Support RLM initail channel of Ad-hoc, P2P and BOW
690  *
691  * 08 23 2010 yuche.tsai
692  * NULL
693  * 1. Fix Interface Address from GO Nego Req/Rsp is not correct.
694  * 2. Fix GO mode does not change media state after station connected.
695  * 3. Fix STA don't response probe request when there is a connection request.
696  *
697  * 08 20 2010 cm.chang
698  * NULL
699  * Migrate RLM code to host from FW
700  *
701  * 08 20 2010 kevin.huang
702  * NULL
703  * Modify AAA Module for changing STA STATE 3 at p2p/bowRunEventAAAComplete()
704  *
705  * 08 20 2010 yuche.tsai
706  * NULL
707  * Add Glue Layer indication.
708  *
709  * 08 17 2010 yuche.tsai
710  * NULL
711  * Fix compile warning under Linux.
712  *
713  * 08 17 2010 yuche.tsai
714  * NULL
715  * Fix some P2P FSM bug.
716  *
717  * 08 16 2010 yuche.tsai
718  * NULL
719  * Add random Interface Address Generation support.
720  *
721  * 08 16 2010 yuche.tsai
722  * NULL
723  * Fix some P2P FSM bug.
724  *
725  * 08 16 2010 yuche.tsai
726  * NULL
727  * Update P2P FSM code for GO Nego.
728  *
729  * 08 16 2010 kevin.huang
730  * NULL
731  * Refine AAA functions
732  *
733  * 08 12 2010 kevin.huang
734  * NULL
735  * Refine bssProcessProbeRequest() and bssSendBeaconProbeResponse()
736  *
737  * 08 12 2010 yuche.tsai
738  * NULL
739  * Join complete indication.
740  *
741  * 08 11 2010 yuche.tsai
742  * NULL
743  * Add two boolean in connection request.
744  * Based on these two boolean value, P2P FSM should
745  * decide to do invitation or group formation or start a GO directly.
746  *
747  * 08 11 2010 yuche.tsai
748  * NULL
749  * Update P2P FSM, currently P2P Device Discovery is verified.
750  *
751  * 08 05 2010 yuche.tsai
752  * NULL
753  * Update P2P FSM for group formation.
754  *
755  * 08 03 2010 george.huang
756  * NULL
757  * handle event for updating NOA parameters indicated from FW
758  *
759  * 08 03 2010 cp.wu
760  * NULL
761  * limit build always needs spin-lock declaration.
762  *
763  * 08 02 2010 yuche.tsai
764  * NULL
765  * P2P Group Negotiation Code Check in.
766  *
767  * 07 26 2010 yuche.tsai
768  *
769  * Add P2P FSM code check in.
770  *
771  * 07 21 2010 yuche.tsai
772  *
773  * Add P2P Scan & Scan Result Parsing & Saving.
774  *
775  * 07 19 2010 yuche.tsai
776  *
777  * Update P2P FSM.
778  *
779  * 07 09 2010 george.huang
780  *
781  * [WPD00001556] Migrate PM variables from FW to driver: for composing QoS Info
782  *
783  * 07 08 2010 cp.wu
784  *
785  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
786  *
787  * 06 21 2010 yuche.tsai
788  * [WPD00003839][MT6620 5931][P2P] Feature migration
789  * Fix compile error while enable WIFI_DIRECT support.
790  *
791  * 06 21 2010 yuche.tsai
792  * [WPD00003839][MT6620 5931][P2P] Feature migration
793  * Update P2P Function call.
794  *
795  * 06 17 2010 yuche.tsai
796  * [WPD00003839][MT6620 5931][P2P] Feature migration
797  * First draft for migration P2P FSM from FW to Driver.
798  *
799  * 04 19 2010 kevin.huang
800  * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
801  * Add Beacon Timeout Support and will send Null frame to diagnose connection
802  *
803  * 03 18 2010 kevin.huang
804  * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
805  * Rename CFG flag for P2P
806  *
807  * 02 26 2010 kevin.huang
808  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
809  * Add code to test P2P GO
810  *
811  * 02 23 2010 kevin.huang
812  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
813  * Add Wi-Fi Direct SSID and P2P GO Test Mode
814  *
815  * 02 05 2010 kevin.huang
816  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
817  * Modify code due to BAND_24G define was changed
818  *
819  * 02 05 2010 kevin.huang
820  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
821  * Revise data structure to share the same BSS_INFO_T for avoiding coding error
822  *
823  * 02 04 2010 kevin.huang
824  * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
825  * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
826 */
827
828 /*******************************************************************************
829 *                         C O M P I L E R   F L A G S
830 ********************************************************************************
831 */
832
833 /*******************************************************************************
834 *                    E X T E R N A L   R E F E R E N C E S
835 ********************************************************************************
836 */
837 #include "precomp.h"
838
839 #if CFG_ENABLE_WIFI_DIRECT
840
841 /*******************************************************************************
842 *                              C O N S T A N T S
843 ********************************************************************************
844 */
845
846 /*******************************************************************************
847 *                             D A T A   T Y P E S
848 ********************************************************************************
849 */
850
851 /*******************************************************************************
852 *                            P U B L I C   D A T A
853 ********************************************************************************
854 */
855
856 /*******************************************************************************
857 *                           P R I V A T E   D A T A
858 ********************************************************************************
859 */
860 #if DBG
861 /*lint -save -e64 Type mismatch */
862 static PUINT_8 apucDebugP2pState[P2P_STATE_NUM] = {
863     (PUINT_8)DISP_STRING("P2P_STATE_IDLE"),
864     (PUINT_8)DISP_STRING("P2P_STATE_SCAN"),
865     (PUINT_8)DISP_STRING("P2P_STATE_AP_CHANNEL_DETECT"),
866     (PUINT_8)DISP_STRING("P2P_STATE_REQING_CHANNEL"),
867     (PUINT_8)DISP_STRING("P2P_STATE_CHNL_ON_HAND"),
868     (PUINT_8)DISP_STRING("P2P_STATE_GC_JOIN")
869 };
870 /*lint -restore */
871 #endif /* DBG */
872
873
874 /*******************************************************************************
875 *                                 M A C R O S
876 ********************************************************************************
877 */
878
879 /*******************************************************************************
880 *                   F U N C T I O N   D E C L A R A T I O N S
881 ********************************************************************************
882 */
883
884 /*******************************************************************************
885 *                              F U N C T I O N S
886 ********************************************************************************
887 */
888
889 /*   p2pStateXXX : Processing P2P FSM related action.
890   *   p2pFSMXXX : Control P2P FSM flow.
891   *   p2pFuncXXX : Function for doing one thing.
892   */
893 VOID
894 p2pFsmInit (
895         IN P_ADAPTER_T prAdapter
896         )
897 {
898
899     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
900     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
901
902     do {
903         ASSERT_BREAK(prAdapter != NULL);
904
905         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
906         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
907
908         ASSERT_BREAK(prP2pFsmInfo != NULL);
909
910         LINK_INITIALIZE(&(prP2pFsmInfo->rMsgEventQueue));
911         LINK_INITIALIZE(&(prP2pBssInfo->rStaRecOfClientList));
912
913
914         prP2pFsmInfo->eCurrentState = prP2pFsmInfo->ePreviousState = P2P_STATE_IDLE;
915         prP2pFsmInfo->prTargetBss = NULL;
916                 prP2pFsmInfo->fgIsWPSMode = 0;
917
918         cnmTimerInitTimer(prAdapter,
919                             &(prP2pFsmInfo->rP2pFsmTimeoutTimer),
920                             (PFN_MGMT_TIMEOUT_FUNC)p2pFsmRunEventFsmTimeout,
921                             (UINT_32)prP2pFsmInfo);
922
923         //4 <2> Initiate BSS_INFO_T - common part
924         BSS_INFO_INIT(prAdapter, NETWORK_TYPE_P2P_INDEX);
925
926
927         //4 <2.1> Initiate BSS_INFO_T - Setup HW ID
928         prP2pBssInfo->ucConfigAdHocAPMode = AP_MODE_11G_P2P;
929         prP2pBssInfo->ucHwDefaultFixedRateCode = RATE_OFDM_6M;
930
931
932         prP2pBssInfo->ucNonHTBasicPhyType = (UINT_8)
933             rNonHTApModeAttributes[prP2pBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
934         prP2pBssInfo->u2BSSBasicRateSet =
935             rNonHTApModeAttributes[prP2pBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
936
937         prP2pBssInfo->u2OperationalRateSet =
938             rNonHTPhyAttributes[prP2pBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
939
940         rateGetDataRatesFromRateSet(prP2pBssInfo->u2OperationalRateSet,
941                                 prP2pBssInfo->u2BSSBasicRateSet,
942                                 prP2pBssInfo->aucAllSupportedRates,
943                                 &prP2pBssInfo->ucAllSupportedRatesLen);
944
945         prP2pBssInfo->prBeacon = cnmMgtPktAlloc(prAdapter,
946                                                             OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem[0]) + MAX_IE_LENGTH);
947
948         if (prP2pBssInfo->prBeacon) {
949             prP2pBssInfo->prBeacon->eSrc = TX_PACKET_MGMT;
950             prP2pBssInfo->prBeacon->ucStaRecIndex = 0xFF; /* NULL STA_REC */
951             prP2pBssInfo->prBeacon->ucNetworkType = NETWORK_TYPE_P2P_INDEX;
952         }
953         else {
954             /* Out of memory. */
955             ASSERT(FALSE);
956         }
957
958         prP2pBssInfo->eCurrentOPMode = OP_MODE_NUM;
959
960         prP2pBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = PM_UAPSD_ALL;
961         prP2pBssInfo->rPmProfSetupInfo.ucBmpTriggerAC = PM_UAPSD_ALL;
962         prP2pBssInfo->rPmProfSetupInfo.ucUapsdSp = WMM_MAX_SP_LENGTH_2;
963         prP2pBssInfo->ucPrimaryChannel = P2P_DEFAULT_LISTEN_CHANNEL;
964         prP2pBssInfo->eBand = BAND_2G4;
965         prP2pBssInfo->eBssSCO =  CHNL_EXT_SCN;
966
967         if (prAdapter->rWifiVar.fgSupportQoS) {
968             prP2pBssInfo->fgIsQBSS = TRUE;
969         }
970         else {
971             prP2pBssInfo->fgIsQBSS = FALSE;
972         }
973
974         SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
975
976         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
977
978     } while (FALSE);
979
980     return;
981 } /* p2pFsmInit */
982
983
984
985
986
987 /*----------------------------------------------------------------------------*/
988 /*!
989 * @brief The function is used to uninitialize the value in P2P_FSM_INFO_T for
990 *        P2P FSM operation
991 *
992 * @param (none)
993 *
994 * @return (none)
995 */
996 /*----------------------------------------------------------------------------*/
997 VOID
998 p2pFsmUninit (
999     IN P_ADAPTER_T prAdapter
1000     )
1001 {
1002     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1003     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1004
1005     do {
1006         ASSERT_BREAK(prAdapter != NULL);
1007
1008         DEBUGFUNC("p2pFsmUninit()");
1009         DBGLOG(P2P, INFO, ("->p2pFsmUninit()\n"));
1010
1011         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1012         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1013
1014         p2pFuncSwitchOPMode(prAdapter, prP2pBssInfo, OP_MODE_P2P_DEVICE, TRUE);
1015
1016         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1017         
1018         p2pStateAbort_IDLE(prAdapter, prP2pFsmInfo, P2P_STATE_NUM);
1019
1020         UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1021
1022         wlanAcquirePowerControl(prAdapter);
1023
1024         /* Release all pending CMD queue. */
1025         DBGLOG(P2P, TRACE, ("p2pFsmUninit: wlanProcessCommandQueue, num of element:%d\n", prAdapter->prGlueInfo->rCmdQueue.u4NumElem));
1026         wlanProcessCommandQueue(prAdapter, &prAdapter->prGlueInfo->rCmdQueue);
1027
1028         wlanReleasePowerControl(prAdapter);
1029
1030         /* Release pending mgmt frame,
1031           * mgmt frame may be pending by CMD without resource.
1032           */
1033         kalClearMgmtFramesByNetType(prAdapter->prGlueInfo, NETWORK_TYPE_P2P_INDEX);
1034
1035         /* Clear PendingCmdQue*/
1036         wlanReleasePendingCMDbyNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1037
1038         if (prP2pBssInfo->prBeacon) {
1039             cnmMgtPktFree(prAdapter, prP2pBssInfo->prBeacon);
1040             prP2pBssInfo->prBeacon = NULL;
1041         }
1042
1043     } while (FALSE);
1044
1045     return;
1046
1047 } /* end of p2pFsmUninit() */
1048
1049 VOID
1050 p2pFsmStateTransition (
1051     IN P_ADAPTER_T prAdapter,
1052     IN P_P2P_FSM_INFO_T prP2pFsmInfo,
1053     IN ENUM_P2P_STATE_T eNextState
1054     )
1055 {
1056     BOOLEAN fgIsTransOut = (BOOLEAN)FALSE;
1057     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1058     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
1059
1060     do {
1061         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1062
1063         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1064         prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1065
1066         if (!IS_BSS_ACTIVE(prP2pBssInfo)) {
1067             if (!cnmP2PIsPermitted(prAdapter)) {
1068                 return;
1069             }
1070
1071             SET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1072             nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1073         }
1074
1075         fgIsTransOut = fgIsTransOut?FALSE:TRUE;
1076
1077         if (!fgIsTransOut) {
1078             DBGLOG(P2P, STATE, ("TRANSITION: [%s] -> [%s]\n",
1079                                 apucDebugP2pState[prP2pFsmInfo->eCurrentState],
1080                                 apucDebugP2pState[eNextState]));
1081
1082             /* Transition into current state. */
1083             prP2pFsmInfo->ePreviousState = prP2pFsmInfo->eCurrentState;
1084             prP2pFsmInfo->eCurrentState = eNextState;
1085         }
1086
1087
1088         switch (prP2pFsmInfo->eCurrentState) {
1089         case P2P_STATE_IDLE:
1090             if (fgIsTransOut) {
1091
1092                 p2pStateAbort_IDLE(prAdapter,
1093                                     prP2pFsmInfo,
1094                                     eNextState);
1095             }
1096             else {
1097                 fgIsTransOut = p2pStateInit_IDLE(prAdapter,
1098                                                     prP2pFsmInfo,
1099                                                     prP2pBssInfo,
1100                                                     &eNextState);
1101             }
1102
1103             break;
1104         case P2P_STATE_SCAN:
1105             if (fgIsTransOut) {
1106
1107                 // Scan done / scan canceled.
1108                 p2pStateAbort_SCAN(prAdapter, prP2pFsmInfo, eNextState);
1109             }
1110             else {
1111                 // Initial scan request.
1112                 p2pStateInit_SCAN(prAdapter, prP2pFsmInfo);
1113             }
1114
1115             break;
1116         case P2P_STATE_AP_CHANNEL_DETECT:
1117             if (fgIsTransOut) {
1118                 // Scan done
1119                     // Get sparse channel result.
1120                 p2pStateAbort_AP_CHANNEL_DETECT(prAdapter,
1121                                                 prP2pFsmInfo,
1122                                                 prP2pSpecificBssInfo,
1123                                                 eNextState);
1124             }
1125
1126             else {
1127                 // Initial passive scan request.
1128                 p2pStateInit_AP_CHANNEL_DETECT(prAdapter, prP2pFsmInfo);
1129             }
1130
1131             break;
1132         case P2P_STATE_REQING_CHANNEL:
1133             if (fgIsTransOut) {
1134
1135                 // Channel on hand / Channel canceled.
1136                 p2pStateAbort_REQING_CHANNEL(prAdapter, prP2pFsmInfo, eNextState);
1137             }
1138             else {
1139                 // Initial channel request.
1140                 p2pFuncAcquireCh(prAdapter, &(prP2pFsmInfo->rChnlReqInfo));
1141             }
1142
1143             break;
1144         case P2P_STATE_CHNL_ON_HAND:
1145             if (fgIsTransOut) {
1146                 p2pStateAbort_CHNL_ON_HAND(prAdapter, prP2pFsmInfo, prP2pBssInfo, eNextState);
1147             }
1148             else {
1149                 // Initial channel ready.
1150                     // Send channel ready event.
1151                     // Start a FSM timer.
1152                 p2pStateInit_CHNL_ON_HAND(prAdapter, prP2pBssInfo, prP2pFsmInfo);
1153             }
1154
1155             break;
1156         case P2P_STATE_GC_JOIN:
1157             if (fgIsTransOut) {
1158
1159                 // Join complete / join canceled.
1160                 p2pStateAbort_GC_JOIN(prAdapter,
1161                                         prP2pFsmInfo,
1162                                         &(prP2pFsmInfo->rJoinInfo),
1163                                         eNextState);
1164             }
1165             else {
1166                 ASSERT(prP2pFsmInfo->prTargetBss != NULL);
1167
1168                 // Send request to SAA module.
1169                 p2pStateInit_GC_JOIN(prAdapter,
1170                                         prP2pFsmInfo,
1171                                         prP2pBssInfo,
1172                                         &(prP2pFsmInfo->rJoinInfo),
1173                                         prP2pFsmInfo->prTargetBss);
1174             }
1175
1176             break;
1177         default:
1178             break;
1179         }
1180
1181     } while (fgIsTransOut);
1182
1183 } /* p2pFsmStateTransition */
1184
1185
1186 VOID
1187 p2pFsmRunEventSwitchOPMode (
1188     IN P_ADAPTER_T prAdapter,
1189     IN P_MSG_HDR_T prMsgHdr
1190     )
1191 {
1192     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1193     P_MSG_P2P_SWITCH_OP_MODE_T prSwitchOpMode = (P_MSG_P2P_SWITCH_OP_MODE_T)prMsgHdr;
1194     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
1195
1196     do {
1197         ASSERT_BREAK((prAdapter != NULL) && (prSwitchOpMode != NULL));
1198
1199         DBGLOG(P2P, TRACE, ("p2pFsmRunEventSwitchOPMode\n"));
1200
1201         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1202         prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
1203
1204         if (prSwitchOpMode->eOpMode >= OP_MODE_NUM) {
1205             ASSERT(FALSE);
1206             break;
1207         }
1208
1209         /* P2P Device / GC. */
1210         p2pFuncSwitchOPMode(prAdapter,
1211                                     prP2pBssInfo,
1212                                     prSwitchOpMode->eOpMode,
1213                                     TRUE);
1214
1215     } while (FALSE);
1216
1217     if (prMsgHdr) {
1218         cnmMemFree(prAdapter, prMsgHdr);
1219     }
1220
1221
1222 } /* p2pFsmRunEventSwitchOPMode */
1223
1224
1225 /*----------------------------------------------------------------------------*/
1226 /*!
1227 * \brief    This function is used to handle scan done event during Device Discovery.
1228 *
1229 * \param[in] prAdapter  Pointer of ADAPTER_T
1230 *
1231 * \return none
1232 */
1233 /*----------------------------------------------------------------------------*/
1234 VOID
1235 p2pFsmRunEventScanDone (
1236     IN P_ADAPTER_T prAdapter,
1237     IN P_MSG_HDR_T prMsgHdr
1238     )
1239 {
1240     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1241     P_P2P_SCAN_REQ_INFO_T prScanReqInfo = (P_P2P_SCAN_REQ_INFO_T)NULL;
1242     P_MSG_SCN_SCAN_DONE prScanDoneMsg = (P_MSG_SCN_SCAN_DONE)NULL;
1243     ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1244
1245     do {
1246         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1247
1248
1249         /* This scan done event is either for "SCAN" phase or "SEARCH" state or "LISTEN" state.
1250           * The scan done for SCAN phase & SEARCH state doesn't imply Device
1251           * Discovery over.
1252           */
1253         DBGLOG(P2P, TRACE, ("P2P Scan Done Event\n"));
1254
1255         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1256
1257         if (prP2pFsmInfo == NULL) {
1258             break;
1259         }
1260
1261
1262         prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1263         prScanDoneMsg = (P_MSG_SCN_SCAN_DONE)prMsgHdr;
1264
1265         if (prScanDoneMsg->ucSeqNum != prScanReqInfo->ucSeqNumOfScnMsg) {
1266             /* Scan Done message sequence number mismatch.
1267               * Ignore this event. (P2P FSM issue two scan events.)
1268               */
1269             /* The scan request has been cancelled.
1270               * Ignore this message. It is possible.
1271               */
1272             DBGLOG(P2P, TRACE, ("P2P Scan Don SeqNum:%d <-> P2P Fsm SCAN Msg:%d\n",
1273                             prScanDoneMsg->ucSeqNum,
1274                             prScanReqInfo->ucSeqNumOfScnMsg));
1275
1276             break;
1277         }
1278
1279
1280         switch (prP2pFsmInfo->eCurrentState) {
1281         case P2P_STATE_SCAN:
1282             {
1283                 P_P2P_CONNECTION_REQ_INFO_T prConnReqInfo = &(prP2pFsmInfo->rConnReqInfo);
1284
1285                 prScanReqInfo->fgIsAbort = FALSE;
1286
1287                 if (prConnReqInfo->fgIsConnRequest) {
1288
1289                     if ((prP2pFsmInfo->prTargetBss = p2pFuncKeepOnConnection(prAdapter,
1290                                                                                                     &prP2pFsmInfo->rConnReqInfo,
1291                                                                                                     &prP2pFsmInfo->rChnlReqInfo,
1292                                                                                                     &prP2pFsmInfo->rScanReqInfo)) == NULL) {
1293                         eNextState = P2P_STATE_SCAN;
1294                     }
1295                     else {
1296                         eNextState = P2P_STATE_REQING_CHANNEL;
1297                     }
1298
1299                 }
1300                 else {
1301                     eNextState = P2P_STATE_IDLE;
1302                 }
1303
1304             }
1305             break;
1306         case P2P_STATE_AP_CHANNEL_DETECT:
1307             eNextState = P2P_STATE_REQING_CHANNEL;
1308             break;
1309         default:
1310             /* Unexpected channel scan done event without being chanceled. */
1311             ASSERT(FALSE);
1312             break;
1313         }
1314
1315         prScanReqInfo->fgIsScanRequest = FALSE;
1316
1317         p2pFsmStateTransition(prAdapter,
1318                         prP2pFsmInfo,
1319                         eNextState);
1320
1321     } while (FALSE);
1322
1323     if (prMsgHdr) {
1324         cnmMemFree(prAdapter, prMsgHdr);
1325     }
1326
1327     return;
1328 } /* p2pFsmRunEventScanDone */
1329
1330
1331
1332 /*----------------------------------------------------------------------------*/
1333 /*!
1334 * \brief    This function is call when channel is granted by CNM module from FW.
1335 *
1336 * \param[in] prAdapter  Pointer of ADAPTER_T
1337 *
1338 * \return none
1339 */
1340 /*----------------------------------------------------------------------------*/
1341 VOID
1342 p2pFsmRunEventChGrant (
1343     IN P_ADAPTER_T prAdapter,
1344     IN P_MSG_HDR_T prMsgHdr
1345     )
1346 {
1347     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1348     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1349     P_MSG_CH_GRANT_T prMsgChGrant = (P_MSG_CH_GRANT_T)NULL;
1350     UINT_8 ucTokenID = 0;
1351
1352     do {
1353         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1354
1355         DBGLOG(P2P, TRACE, ("P2P Run Event Channel Grant\n"));
1356
1357         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1358
1359         if (prP2pFsmInfo == NULL) {
1360             break;
1361         }
1362         
1363         prMsgChGrant = (P_MSG_CH_GRANT_T)prMsgHdr;
1364         ucTokenID = prMsgChGrant->ucTokenID;
1365         prP2pFsmInfo->u4GrantInterval = prMsgChGrant->u4GrantInterval;
1366
1367         
1368         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1369
1370         if (ucTokenID == prChnlReqInfo->ucSeqNumOfChReq) {
1371             ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1372
1373             switch (prP2pFsmInfo->eCurrentState) {
1374             case P2P_STATE_REQING_CHANNEL:
1375                 switch (prChnlReqInfo->eChannelReqType) {
1376                 case CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL:
1377                     eNextState = P2P_STATE_CHNL_ON_HAND;
1378                     break;
1379                 case CHANNEL_REQ_TYPE_GC_JOIN_REQ:
1380                     eNextState = P2P_STATE_GC_JOIN;
1381                     break;
1382                 case CHANNEL_REQ_TYPE_GO_START_BSS:
1383                     eNextState = P2P_STATE_IDLE;
1384                     break;
1385                 default:
1386                     break;
1387                 }
1388
1389                 p2pFsmStateTransition(prAdapter,
1390                                 prP2pFsmInfo,
1391                                 eNextState);
1392                 break;
1393             default:
1394                 /* Channel is granted under unexpected state.
1395                   * Driver should cancel channel privileagea before leaving the states.
1396                   */
1397                 ASSERT(FALSE);
1398                 break;
1399             }
1400
1401         }
1402         else {
1403             /* Channel requsted, but released. */
1404             //ASSERT(!prChnlReqInfo->fgIsChannelRequested);
1405             DBGLOG(P2P, TRACE, ("Channel requsted, but released\n"));
1406         }
1407     } while (FALSE);
1408
1409     if (prMsgHdr) {
1410         cnmMemFree(prAdapter, prMsgHdr);
1411     }
1412
1413     return;
1414
1415 } /* p2pFsmRunEventChGrant */
1416
1417
1418 VOID
1419 p2pFsmRunEventChannelRequest (
1420     IN P_ADAPTER_T prAdapter,
1421     IN P_MSG_HDR_T prMsgHdr
1422     )
1423 {
1424     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1425     P_MSG_P2P_CHNL_REQUEST_T prP2pChnlReqMsg = (P_MSG_P2P_CHNL_REQUEST_T)NULL;
1426     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1427     ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1428
1429     do {
1430         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1431
1432         prP2pChnlReqMsg = (P_MSG_P2P_CHNL_REQUEST_T)prMsgHdr;
1433         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1434
1435         if (prP2pFsmInfo == NULL) {
1436             break;
1437         }
1438         
1439         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1440
1441         DBGLOG(P2P, TRACE, ("p2pFsmRunEventChannelRequest\n"));
1442
1443         /* Special case of time renewing for same frequency. */
1444         if ((prP2pFsmInfo->eCurrentState == P2P_STATE_CHNL_ON_HAND) &&
1445                 (prChnlReqInfo->ucReqChnlNum == prP2pChnlReqMsg->rChannelInfo.ucChannelNum) &&
1446                 (prChnlReqInfo->eBand == prP2pChnlReqMsg->rChannelInfo.eBand) &&
1447                 (prChnlReqInfo->eChnlSco == prP2pChnlReqMsg->eChnlSco)) {
1448
1449             ASSERT(prChnlReqInfo->fgIsChannelRequested == TRUE);
1450             ASSERT(prChnlReqInfo->eChannelReqType == CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL);
1451
1452             prChnlReqInfo->u8Cookie = prP2pChnlReqMsg->u8Cookie;
1453             prChnlReqInfo->u4MaxInterval = prP2pChnlReqMsg->u4Duration;
1454 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
1455             prChnlReqInfo->fgNeedIndSupp = prP2pChnlReqMsg->fgNeedIndSupp;
1456 #endif
1457
1458             /* Re-enter the state. */
1459             eNextState = P2P_STATE_CHNL_ON_HAND;
1460         }
1461         else {
1462
1463             // Make sure the state is in IDLE state.
1464             p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1465
1466             prChnlReqInfo->u8Cookie = prP2pChnlReqMsg->u8Cookie;  /* Cookie can only be assign after abort.(for indication) */
1467             prChnlReqInfo->ucReqChnlNum = prP2pChnlReqMsg->rChannelInfo.ucChannelNum;
1468             prChnlReqInfo->eBand = prP2pChnlReqMsg->rChannelInfo.eBand;
1469             prChnlReqInfo->eChnlSco = prP2pChnlReqMsg->eChnlSco;
1470             prChnlReqInfo->u4MaxInterval = prP2pChnlReqMsg->u4Duration;
1471             prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL;
1472 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
1473             prChnlReqInfo->fgNeedIndSupp = prP2pChnlReqMsg->fgNeedIndSupp;
1474 #endif
1475             eNextState = P2P_STATE_REQING_CHANNEL;
1476         }
1477
1478         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, eNextState);
1479
1480     } while (FALSE);
1481
1482
1483     if (prMsgHdr) {
1484         cnmMemFree(prAdapter, prMsgHdr);
1485     }
1486
1487     return;
1488 } /* p2pFsmRunEventChannelRequest */
1489
1490
1491 VOID
1492 p2pFsmRunEventChannelAbort (
1493     IN P_ADAPTER_T prAdapter,
1494     IN P_MSG_HDR_T prMsgHdr
1495     )
1496 {
1497     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1498     P_MSG_P2P_CHNL_ABORT_T prChnlAbortMsg = (P_MSG_P2P_CHNL_ABORT_T)NULL;
1499     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1500
1501     do {
1502         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1503
1504         prChnlAbortMsg = (P_MSG_P2P_CHNL_ABORT_T)prMsgHdr;
1505         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1506         
1507         if (prP2pFsmInfo == NULL) {
1508             break;
1509         }
1510
1511         prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1512
1513         DBGLOG(P2P, TRACE, ("p2pFsmRunEventChannelAbort\n"));
1514
1515         if ((prChnlAbortMsg->u8Cookie == prChnlReqInfo->u8Cookie) &&
1516                 (prChnlReqInfo->fgIsChannelRequested)) {
1517
1518             ASSERT((prP2pFsmInfo->eCurrentState == P2P_STATE_REQING_CHANNEL ||
1519                             (prP2pFsmInfo->eCurrentState == P2P_STATE_CHNL_ON_HAND)));
1520
1521             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1522         }
1523
1524     } while (FALSE);
1525
1526     if (prMsgHdr) {
1527         cnmMemFree(prAdapter, prMsgHdr);
1528     }
1529
1530     return;
1531 } /* p2pFsmRunEventChannelAbort */
1532
1533
1534
1535 VOID
1536 p2pFsmRunEventScanRequest (
1537     IN P_ADAPTER_T prAdapter,
1538     IN P_MSG_HDR_T prMsgHdr
1539     )
1540 {
1541
1542     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1543     P_MSG_P2P_SCAN_REQUEST_T prP2pScanReqMsg = (P_MSG_P2P_SCAN_REQUEST_T)NULL;
1544     P_P2P_SCAN_REQ_INFO_T prScanReqInfo = (P_P2P_SCAN_REQ_INFO_T)NULL;
1545     UINT_32 u4ChnlListSize = 0;
1546
1547     do {
1548         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1549
1550         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1551
1552         if (prP2pFsmInfo == NULL) {
1553             break;
1554         }
1555         
1556         prP2pScanReqMsg = (P_MSG_P2P_SCAN_REQUEST_T)prMsgHdr;
1557         prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1558
1559         DBGLOG(P2P, TRACE, ("p2pFsmRunEventScanRequest\n"));
1560
1561         // Make sure the state is in IDLE state.
1562         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1563
1564         ASSERT(prScanReqInfo->fgIsScanRequest == FALSE);
1565
1566         prScanReqInfo->fgIsAbort = TRUE;
1567         prScanReqInfo->eScanType = SCAN_TYPE_ACTIVE_SCAN;
1568         prScanReqInfo->eChannelSet = SCAN_CHANNEL_SPECIFIED;
1569
1570         // Channel List
1571         prScanReqInfo->ucNumChannelList = prP2pScanReqMsg->u4NumChannel;
1572         DBGLOG(P2P, TRACE, ("Scan Request Channel List Number: %d\n", prScanReqInfo->ucNumChannelList));
1573         if (prScanReqInfo->ucNumChannelList > MAXIMUM_OPERATION_CHANNEL_LIST) {
1574             DBGLOG(P2P, TRACE, ("Channel List Number Overloaded: %d, change to: %d\n",
1575                                                                                     prScanReqInfo->ucNumChannelList,
1576                                                                                     MAXIMUM_OPERATION_CHANNEL_LIST));
1577             prScanReqInfo->ucNumChannelList = MAXIMUM_OPERATION_CHANNEL_LIST;
1578         }
1579
1580         u4ChnlListSize = sizeof(RF_CHANNEL_INFO_T) * prScanReqInfo->ucNumChannelList;
1581         kalMemCopy(prScanReqInfo->arScanChannelList, prP2pScanReqMsg->arChannelListInfo, u4ChnlListSize);
1582
1583         // TODO: I only take the first SSID. Multiple SSID may be needed in the future.
1584         // SSID
1585         if (prP2pScanReqMsg->i4SsidNum >= 1) {
1586
1587             kalMemCopy(&(prScanReqInfo->rSsidStruct),
1588                                 prP2pScanReqMsg->prSSID,
1589                                 sizeof(P2P_SSID_STRUCT_T));
1590         }
1591         else {
1592             prScanReqInfo->rSsidStruct.ucSsidLen = 0;
1593         }
1594
1595         // IE Buffer
1596         kalMemCopy(prScanReqInfo->aucIEBuf,
1597                             prP2pScanReqMsg->pucIEBuf,
1598                             prP2pScanReqMsg->u4IELen);
1599
1600         prScanReqInfo->u4BufLength = prP2pScanReqMsg->u4IELen;
1601
1602         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN);
1603
1604
1605
1606     } while (FALSE);
1607
1608     if (prMsgHdr) {
1609         cnmMemFree(prAdapter, prMsgHdr);
1610     }
1611
1612
1613 } /* p2pFsmRunEventScanRequest */
1614
1615
1616 VOID
1617 p2pFsmRunEventScanAbort (
1618     IN P_ADAPTER_T prAdapter,
1619     IN P_MSG_HDR_T prMsgHdr
1620     )
1621 {
1622
1623     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1624
1625     do {
1626         ASSERT_BREAK(prAdapter != NULL);
1627
1628         DBGLOG(P2P, TRACE, ("p2pFsmRunEventScanAbort\n"));
1629
1630         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1631
1632         if (prP2pFsmInfo->eCurrentState == P2P_STATE_SCAN) {
1633             P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1634
1635             prScanReqInfo->fgIsAbort = TRUE;
1636
1637             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1638         }
1639
1640     } while (FALSE);
1641
1642     if (prMsgHdr) {
1643         cnmMemFree(prAdapter, prMsgHdr);
1644     }
1645
1646     return;
1647 } /* p2pFsmRunEventScanAbort */
1648
1649
1650
1651
1652
1653 VOID
1654 p2pFsmRunEventAbort (
1655     IN P_ADAPTER_T prAdapter,
1656     IN P_P2P_FSM_INFO_T prP2pFsmInfo
1657     )
1658 {
1659     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1660     do {
1661         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1662
1663         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1664
1665         DBGLOG(P2P, TRACE, ("p2pFsmRunEventAbort\n"));
1666
1667         if (prP2pFsmInfo->eCurrentState != P2P_STATE_IDLE) {
1668
1669             if (prP2pFsmInfo->eCurrentState == P2P_STATE_SCAN) {
1670
1671                 P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1672
1673                 prScanReqInfo->fgIsAbort = TRUE;
1674             }
1675             else if (prP2pFsmInfo->eCurrentState == P2P_STATE_REQING_CHANNEL) {
1676                 /* 2012/08/06: frog 
1677                               * Prevent Start GO.
1678                               */
1679                 prP2pBssInfo->eIntendOPMode = OP_MODE_NUM;
1680             }
1681
1682             // For other state, is there any special action that should be take before leaving?
1683
1684             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1685         }
1686         else {
1687             /* P2P State IDLE. */
1688             P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1689
1690             if (prChnlReqInfo->fgIsChannelRequested) {
1691                 p2pFuncReleaseCh(prAdapter, prChnlReqInfo);
1692             }
1693
1694             cnmTimerStopTimer(prAdapter, &(prP2pFsmInfo->rP2pFsmTimeoutTimer));
1695         }
1696
1697
1698     } while (FALSE);
1699
1700     return;
1701 } /* p2pFsmRunEventAbort */
1702
1703
1704
1705 /*----------------------------------------------------------------------------*/
1706 /*!
1707 * \brief    This function is used to handle FSM Timeout.
1708 *
1709 * \param[in] prAdapter  Pointer of ADAPTER_T
1710 *
1711 * \return none
1712 */
1713 /*----------------------------------------------------------------------------*/
1714 VOID
1715 p2pFsmRunEventFsmTimeout (
1716     IN P_ADAPTER_T prAdapter,
1717     IN UINT_32 u4Param
1718     )
1719 {
1720     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)u4Param;
1721
1722     do {
1723         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1724
1725         DBGLOG(P2P, TRACE, ("P2P FSM Timeout Event\n"));
1726
1727         switch (prP2pFsmInfo->eCurrentState) {
1728         case P2P_STATE_IDLE:
1729             {
1730                 P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1731                 if (prChnlReqInfo->fgIsChannelRequested) {
1732                     p2pFuncReleaseCh(prAdapter, prChnlReqInfo);
1733                 }
1734                 else if (IS_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX)) {
1735                     UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1736                     nicDeactivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1737                 }
1738
1739             }
1740             break;
1741
1742 //        case P2P_STATE_SCAN:
1743 //            break;
1744 //        case P2P_STATE_AP_CHANNEL_DETECT:
1745 //            break;
1746 //        case P2P_STATE_REQING_CHANNEL:
1747 //            break;
1748         case P2P_STATE_CHNL_ON_HAND:
1749             {
1750                 p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1751             }
1752             break;
1753 //        case P2P_STATE_GC_JOIN:
1754 //            break;
1755         default:
1756             break;
1757         }
1758
1759     } while (FALSE);
1760
1761     return;
1762 } /* p2pFsmRunEventFsmTimeout */
1763
1764 VOID
1765 p2pFsmRunEventMgmtFrameTx (
1766     IN P_ADAPTER_T prAdapter,
1767     IN P_MSG_HDR_T prMsgHdr
1768     )
1769 {
1770     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1771     P_MSG_P2P_MGMT_TX_REQUEST_T prMgmtTxMsg = (P_MSG_P2P_MGMT_TX_REQUEST_T)NULL;
1772
1773     do {
1774         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1775
1776         DBGLOG(P2P, TRACE, ("p2pFsmRunEventMgmtFrameTx\n"));
1777
1778         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1779
1780         if (prP2pFsmInfo == NULL) {
1781             break;
1782         }
1783         
1784         prMgmtTxMsg = (P_MSG_P2P_MGMT_TX_REQUEST_T)prMsgHdr;
1785
1786         p2pFuncTxMgmtFrame(prAdapter,
1787                         &prP2pFsmInfo->rMgmtTxInfo,
1788                         prMgmtTxMsg->prMgmtMsduInfo,
1789                         prMgmtTxMsg->u8Cookie);
1790
1791
1792
1793     } while (FALSE);
1794
1795     if (prMsgHdr) {
1796         cnmMemFree(prAdapter, prMsgHdr);
1797     }
1798
1799     return;
1800
1801 } /* p2pFsmRunEventMgmtTx */
1802
1803
1804 VOID
1805 p2pFsmRunEventStartAP (
1806     IN P_ADAPTER_T prAdapter,
1807     IN P_MSG_HDR_T prMsgHdr
1808     )
1809 {
1810     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1811     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1812     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
1813     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
1814
1815     do {
1816         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1817
1818         DBGLOG(P2P, TRACE, ("p2pFsmRunEventStartAP\n"));
1819
1820         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1821
1822         if (prP2pFsmInfo == NULL) {
1823             break;
1824         }
1825         
1826         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1827         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)prMsgHdr;
1828         prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1829
1830
1831         if (prP2pStartAPMsg->u4BcnInterval) {
1832             DBGLOG(P2P, TRACE, ("Beacon interval updated to :%ld \n", prP2pStartAPMsg->u4BcnInterval));
1833             prP2pBssInfo->u2BeaconInterval = (UINT_16)prP2pStartAPMsg->u4BcnInterval;
1834         }
1835         else if (prP2pBssInfo->u2BeaconInterval == 0)  {
1836             prP2pBssInfo->u2BeaconInterval = DOT11_BEACON_PERIOD_DEFAULT;
1837         }
1838         
1839         if (prP2pStartAPMsg->u4DtimPeriod) {
1840             DBGLOG(P2P, TRACE, ("DTIM interval updated to :%ld \n", prP2pStartAPMsg->u4DtimPeriod));
1841             prP2pBssInfo->ucDTIMPeriod = (UINT_8)prP2pStartAPMsg->u4DtimPeriod;
1842         }
1843         else if (prP2pBssInfo->ucDTIMPeriod == 0) {
1844             prP2pBssInfo->ucDTIMPeriod = DOT11_DTIM_PERIOD_DEFAULT;
1845         }
1846
1847         if (prP2pStartAPMsg->u2SsidLen != 0) {
1848             kalMemCopy(prP2pBssInfo->aucSSID, prP2pStartAPMsg->aucSsid, prP2pStartAPMsg->u2SsidLen);
1849             kalMemCopy(prP2pSpecificBssInfo->aucGroupSsid, prP2pStartAPMsg->aucSsid, prP2pStartAPMsg->u2SsidLen);
1850             prP2pBssInfo->ucSSIDLen = prP2pSpecificBssInfo->u2GroupSsidLen = prP2pStartAPMsg->u2SsidLen;
1851         }
1852
1853
1854         prP2pBssInfo->eHiddenSsidType = prP2pStartAPMsg->ucHiddenSsidType;
1855         
1856
1857         // TODO: JB
1858         /* Privacy & inactive timeout. */
1859
1860         if ((prP2pBssInfo->eCurrentOPMode != OP_MODE_ACCESS_POINT) ||
1861                 (prP2pBssInfo->eIntendOPMode != OP_MODE_NUM)) {
1862             UINT_8 ucPreferedChnl = 0;
1863             ENUM_BAND_T eBand = BAND_NULL;
1864             ENUM_CHNL_EXT_T eSco = CHNL_EXT_SCN;
1865             ENUM_P2P_STATE_T eNextState = P2P_STATE_SCAN;
1866             P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
1867
1868
1869             if(prP2pFsmInfo->eCurrentState != P2P_STATE_SCAN &&
1870                prP2pFsmInfo->eCurrentState != P2P_STATE_IDLE) {
1871                 // Make sure the state is in IDLE state.
1872                 p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1873             }
1874
1875             // 20120118: Moved to p2pFuncSwitchOPMode().
1876             //SET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1877
1878             /* Leave IDLE state. */
1879             SET_NET_PWR_STATE_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1880
1881             // sync with firmware
1882             //DBGLOG(P2P, INFO, ("Activate P2P Network. \n"));
1883             //nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1884
1885
1886             /* Key to trigger P2P FSM to allocate channel for AP mode. */
1887             prP2pBssInfo->eIntendOPMode = OP_MODE_ACCESS_POINT;
1888
1889             /* Sparse Channel to decide which channel to use. */
1890             if ((cnmPreferredChannel(prAdapter,
1891                                             &eBand,
1892                                             &ucPreferedChnl,
1893                                             &eSco) == FALSE) && (prP2pConnSettings->ucOperatingChnl == 0)) {
1894                 // Sparse Channel Detection using passive mode.
1895                 eNextState = P2P_STATE_AP_CHANNEL_DETECT;
1896             }
1897             else {
1898                 P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1899                 P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1900
1901
1902 #if 1
1903                 /* 2012-01-27: frog - Channel set from upper layer is the first priority. */
1904                 /* Becuase the channel & beacon is decided by p2p_supplicant. */
1905                 if (prP2pConnSettings->ucOperatingChnl != 0) {
1906                     prP2pSpecificBssInfo->ucPreferredChannel = prP2pConnSettings->ucOperatingChnl;
1907                     prP2pSpecificBssInfo->eRfBand = prP2pConnSettings->eBand;
1908                 }
1909                 
1910                 else {
1911                     ASSERT(ucPreferedChnl != 0);
1912                     prP2pSpecificBssInfo->ucPreferredChannel = ucPreferedChnl;
1913                     prP2pSpecificBssInfo->eRfBand = eBand;
1914                 }
1915 #else
1916                 if (ucPreferedChnl) {
1917                     prP2pSpecificBssInfo->ucPreferredChannel = ucPreferedChnl;
1918                     prP2pSpecificBssInfo->eRfBand = eBand;
1919                 }
1920                 else {
1921                     ASSERT(prP2pConnSettings->ucOperatingChnl != 0);
1922                     prP2pSpecificBssInfo->ucPreferredChannel = prP2pConnSettings->ucOperatingChnl;
1923                     prP2pSpecificBssInfo->eRfBand = prP2pConnSettings->eBand;
1924                 }
1925
1926 #endif
1927                 prChnlReqInfo->ucReqChnlNum = prP2pSpecificBssInfo->ucPreferredChannel;
1928                 prChnlReqInfo->eBand = prP2pSpecificBssInfo->eRfBand;
1929                 prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_GO_START_BSS;
1930             }
1931             
1932             /* If channel is specified, use active scan to shorten the scan time. */
1933             p2pFsmStateTransition(prAdapter,
1934                                         prAdapter->rWifiVar.prP2pFsmInfo,
1935                                         eNextState);
1936         }
1937
1938
1939         
1940     } while (FALSE);
1941
1942
1943
1944     if (prMsgHdr) {
1945         cnmMemFree(prAdapter, prMsgHdr);
1946     }
1947     
1948     return;
1949 } /* p2pFsmRunEventStartAP */
1950
1951 VOID
1952 p2pFsmRunEventNetDeviceRegister (
1953     IN P_ADAPTER_T prAdapter,
1954     IN P_MSG_HDR_T prMsgHdr
1955     )
1956 {
1957     P_MSG_P2P_NETDEV_REGISTER_T prNetDevRegisterMsg = (P_MSG_P2P_NETDEV_REGISTER_T)NULL;
1958
1959
1960     do {
1961
1962         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1963
1964         DBGLOG(P2P, TRACE, ("p2pFsmRunEventNetDeviceRegister\n"));
1965
1966         prNetDevRegisterMsg = (P_MSG_P2P_NETDEV_REGISTER_T)prMsgHdr;
1967         
1968          if (prNetDevRegisterMsg->fgIsEnable) {
1969             p2pSetMode((prNetDevRegisterMsg->ucMode == 1)?TRUE:FALSE);
1970
1971             if (p2pLaunch(prAdapter->prGlueInfo)) {
1972                 ASSERT(prAdapter->fgIsP2PRegistered);
1973             }
1974
1975         }
1976         else {
1977             if (prAdapter->fgIsP2PRegistered) {
1978                 p2pRemove(prAdapter->prGlueInfo);
1979             }
1980
1981         }
1982     } while (FALSE);
1983     
1984     if (prMsgHdr) {
1985         cnmMemFree(prAdapter, prMsgHdr);
1986     }
1987
1988     return;
1989 } /* p2pFsmRunEventNetDeviceRegister */
1990
1991
1992 VOID
1993 p2pFsmRunEventUpdateMgmtFrame (
1994     IN P_ADAPTER_T prAdapter,
1995     IN P_MSG_HDR_T prMsgHdr
1996     )
1997 {
1998     P_MSG_P2P_MGMT_FRAME_UPDATE_T prP2pMgmtFrameUpdateMsg = (P_MSG_P2P_MGMT_FRAME_UPDATE_T)NULL;
1999     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2000
2001     do {
2002         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2003
2004         DBGLOG(P2P, TRACE, ("p2pFsmRunEventUpdateMgmtFrame\n"));
2005
2006         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2007
2008         if (prP2pFsmInfo == NULL) {
2009             break;
2010         }
2011         
2012         prP2pMgmtFrameUpdateMsg = (P_MSG_P2P_MGMT_FRAME_UPDATE_T)prMsgHdr;
2013
2014         switch (prP2pMgmtFrameUpdateMsg->eBufferType) {
2015         case ENUM_FRAME_TYPE_EXTRA_IE_BEACON:
2016             break;
2017         case ENUM_FRAME_TYPE_EXTRA_IE_ASSOC_RSP:
2018             break;
2019         case ENUM_FRAME_TYPE_EXTRA_IE_PROBE_RSP:
2020             break;
2021         case ENUM_FRAME_TYPE_PROBE_RSP_TEMPLATE:
2022             break;
2023         case ENUM_FRAME_TYPE_BEACON_TEMPLATE:
2024             break;
2025         default:
2026             break;
2027         }
2028         
2029     } while (FALSE);
2030
2031     if (prMsgHdr) {
2032         cnmMemFree(prAdapter, prMsgHdr);
2033     }
2034
2035     return;
2036 } /* p2pFsmRunEventUpdateMgmtFrame */
2037
2038
2039 VOID
2040 p2pFsmRunEventBeaconUpdate (
2041     IN P_ADAPTER_T prAdapter,
2042     IN P_MSG_HDR_T prMsgHdr
2043     )
2044 {
2045     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2046     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2047     P_MSG_P2P_BEACON_UPDATE_T prBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
2048
2049     do {
2050         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2051
2052         DBGLOG(P2P, TRACE, ("p2pFsmRunEventBeaconUpdate\n"));
2053
2054
2055         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2056
2057         if (prP2pFsmInfo == NULL) {
2058             break;
2059         }
2060         
2061         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2062         prBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)prMsgHdr;
2063
2064         
2065         p2pFuncBeaconUpdate(prAdapter,
2066                         prP2pBssInfo,
2067                         &prP2pFsmInfo->rBcnContentInfo,
2068                         prBcnUpdateMsg->pucBcnHdr,
2069                         prBcnUpdateMsg->u4BcnHdrLen,
2070                         prBcnUpdateMsg->pucBcnBody,
2071                         prBcnUpdateMsg->u4BcnBodyLen);
2072
2073         if ((prP2pBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) &&
2074                 (prP2pBssInfo->eIntendOPMode == OP_MODE_NUM)) {
2075             /* AP is created, Beacon Update. */
2076             //nicPmIndicateBssAbort(prAdapter, NETWORK_TYPE_P2P_INDEX);
2077
2078             bssUpdateBeaconContent(prAdapter, NETWORK_TYPE_P2P_INDEX);
2079
2080             //nicPmIndicateBssCreated(prAdapter, NETWORK_TYPE_P2P_INDEX);
2081         }
2082         
2083
2084
2085     } while (FALSE);
2086
2087
2088     if (prMsgHdr) {
2089         cnmMemFree(prAdapter, prMsgHdr);
2090     }
2091
2092 } /* p2pFsmRunEventBeaconUpdate */
2093
2094
2095 VOID
2096 p2pFsmRunEventStopAP (
2097     IN P_ADAPTER_T prAdapter,
2098     IN P_MSG_HDR_T prMsgHdr
2099     )
2100 {
2101     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2102
2103     do {
2104         ASSERT_BREAK((prAdapter != NULL));
2105
2106         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2107
2108         DBGLOG(P2P, TRACE, ("p2pFsmRunEventStopAP\n"));
2109
2110         if ((prP2pBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)
2111                 && (prP2pBssInfo->eIntendOPMode == OP_MODE_NUM)) {
2112             /* AP is created, Beacon Update. */
2113
2114             p2pFuncDissolve(prAdapter, prP2pBssInfo, TRUE, REASON_CODE_DEAUTH_LEAVING_BSS);
2115             
2116             DBGLOG(P2P, TRACE, ("Stop Beaconing\n"));
2117             nicPmIndicateBssAbort(prAdapter, NETWORK_TYPE_P2P_INDEX);
2118
2119             /* Reset RLM related field of BSSINFO. */
2120             rlmBssAborted(prAdapter, prP2pBssInfo);
2121         }
2122
2123         
2124
2125         // 20120118: Moved to p2pFuncSwitchOPMode().
2126         //UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2127
2128         /* Enter IDLE state. */
2129         SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2130
2131         DBGLOG(P2P, INFO, ("Re activate P2P Network. \n"));
2132         nicDeactivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
2133
2134         nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
2135
2136 #if CFG_SUPPORT_WFD
2137         p2pFsmRunEventWfdSettingUpdate(prAdapter, NULL);
2138 #endif
2139
2140         p2pFsmRunEventAbort(prAdapter, prAdapter->rWifiVar.prP2pFsmInfo);
2141 //        p2pFsmStateTransition(prAdapter, prAdapter->rWifiVar.prP2pFsmInfo, P2P_STATE_IDLE);
2142
2143     } while (FALSE);
2144
2145     if (prMsgHdr) {
2146         cnmMemFree(prAdapter, prMsgHdr);
2147     }
2148
2149 } /* p2pFsmRunEventStopAP */
2150
2151 VOID
2152 p2pFsmRunEventConnectionRequest (
2153     IN P_ADAPTER_T prAdapter,
2154     IN P_MSG_HDR_T prMsgHdr
2155     )
2156 {
2157     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2158     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2159     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
2160     P_MSG_P2P_CONNECTION_REQUEST_T prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
2161     P_P2P_CONNECTION_REQ_INFO_T prConnReqInfo = (P_P2P_CONNECTION_REQ_INFO_T)NULL;
2162
2163     do {
2164         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2165
2166         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2167         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2168
2169         if (prP2pFsmInfo == NULL) {
2170             break;
2171         }
2172         
2173         prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)prMsgHdr;
2174
2175         prConnReqInfo = &(prP2pFsmInfo->rConnReqInfo);
2176         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
2177
2178         DBGLOG(P2P, TRACE, ("p2pFsmRunEventConnectionRequest\n"));
2179
2180         if (prP2pBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE) {
2181             break;
2182         }
2183
2184         SET_NET_PWR_STATE_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2185
2186         
2187         // Make sure the state is in IDLE state.
2188         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
2189
2190         // Update connection request information.
2191         prConnReqInfo->fgIsConnRequest = TRUE;
2192         COPY_MAC_ADDR(prConnReqInfo->aucBssid, prConnReqMsg->aucBssid);
2193         kalMemCopy(&(prConnReqInfo->rSsidStruct), &(prConnReqMsg->rSsid), sizeof(P2P_SSID_STRUCT_T));
2194         kalMemCopy(prConnReqInfo->aucIEBuf, prConnReqMsg->aucIEBuf, prConnReqMsg->u4IELen);
2195         prConnReqInfo->u4BufLength = prConnReqMsg->u4IELen;
2196
2197         /* Find BSS Descriptor first. */
2198         prP2pFsmInfo->prTargetBss =  scanP2pSearchDesc(prAdapter,
2199                                                                         prP2pBssInfo,
2200                                                                         prConnReqInfo);
2201
2202         if (prP2pFsmInfo->prTargetBss == NULL) {
2203             /* Update scan parameter... to scan target device. */
2204             P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
2205
2206             prScanReqInfo->ucNumChannelList = 1;
2207             prScanReqInfo->eScanType = SCAN_TYPE_ACTIVE_SCAN;
2208             prScanReqInfo->eChannelSet = SCAN_CHANNEL_SPECIFIED;
2209             prScanReqInfo->arScanChannelList[0].ucChannelNum = prConnReqMsg->rChannelInfo.ucChannelNum;
2210             kalMemCopy(&(prScanReqInfo->rSsidStruct), &(prConnReqMsg->rSsid), sizeof(P2P_SSID_STRUCT_T));
2211             prScanReqInfo->u4BufLength = 0;  /* Prevent other P2P ID in IE. */
2212             prScanReqInfo->fgIsAbort = TRUE;
2213
2214             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN);
2215         }
2216         else {
2217             prChnlReqInfo->u8Cookie = 0;
2218             prChnlReqInfo->ucReqChnlNum = prConnReqMsg->rChannelInfo.ucChannelNum;
2219             prChnlReqInfo->eBand = prConnReqMsg->rChannelInfo.eBand;
2220             prChnlReqInfo->eChnlSco = prConnReqMsg->eChnlSco;
2221             prChnlReqInfo->u4MaxInterval = AIS_JOIN_CH_REQUEST_INTERVAL;
2222             prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_GC_JOIN_REQ;
2223
2224             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_REQING_CHANNEL);
2225         }
2226
2227
2228     } while (FALSE);
2229
2230     if (prMsgHdr) {
2231         cnmMemFree(prAdapter, prMsgHdr);
2232     }
2233
2234     return;
2235
2236 } /* p2pFsmRunEventConnectionRequest */
2237
2238 /*----------------------------------------------------------------------------*/
2239 /*!
2240 * \brief    This function is used to handle Connection Request from Supplicant.
2241 *
2242 * \param[in] prAdapter  Pointer of ADAPTER_T
2243 *
2244 * \return none
2245 */
2246 /*----------------------------------------------------------------------------*/
2247 VOID
2248 p2pFsmRunEventConnectionAbort (
2249     IN P_ADAPTER_T prAdapter,
2250     IN P_MSG_HDR_T prMsgHdr
2251     )
2252 {
2253     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2254     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2255     P_MSG_P2P_CONNECTION_ABORT_T prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
2256     //P_STA_RECORD_T prTargetStaRec = (P_STA_RECORD_T)NULL;
2257
2258     do {
2259
2260         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2261
2262         DBGLOG(P2P, STATE, ("p2pFsmRunEventConnectionAbort: Connection Abort.\n"));
2263
2264         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2265
2266         if (prP2pFsmInfo == NULL) {
2267             break;
2268         }
2269         
2270         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2271
2272         prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)prMsgHdr;
2273
2274         switch (prP2pBssInfo->eCurrentOPMode) {
2275         case OP_MODE_INFRASTRUCTURE:
2276             {
2277                 UINT_8 aucBCBSSID[] = BC_BSSID;
2278                 
2279                 if (!prP2pBssInfo->prStaRecOfAP) {
2280                     DBGLOG(P2P, TRACE, ("GO's StaRec is NULL\n"));
2281                     break;
2282                 }
2283                 if (UNEQUAL_MAC_ADDR(prP2pBssInfo->prStaRecOfAP->aucMacAddr, prDisconnMsg->aucTargetID) &&
2284                     UNEQUAL_MAC_ADDR(prDisconnMsg->aucTargetID, aucBCBSSID)) {
2285                     DBGLOG(P2P, TRACE, ("Unequal MAC ADDR ["MACSTR":"MACSTR"]\n",
2286                         MAC2STR(prP2pBssInfo->prStaRecOfAP->aucMacAddr),
2287                         MAC2STR(prDisconnMsg->aucTargetID)));
2288                     break;
2289                 }
2290
2291                 
2292                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo, NULL, NULL, 0, 0);
2293
2294                 /* Stop rejoin timer if it is started. */
2295                 // TODO: If it has.
2296
2297                 p2pFuncDisconnect(prAdapter, prP2pBssInfo->prStaRecOfAP, prDisconnMsg->fgSendDeauth, prDisconnMsg->u2ReasonCode);
2298
2299                 //prTargetStaRec = prP2pBssInfo->prStaRecOfAP;
2300
2301                 /* Fix possible KE when RX Beacon & call nicPmIndicateBssConnected(). hit prStaRecOfAP == NULL. */
2302                 p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_DISCONNECTED);
2303
2304                 prP2pBssInfo->prStaRecOfAP = NULL;
2305
2306                 SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2307
2308                 p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2309
2310             }
2311             break;
2312         case OP_MODE_ACCESS_POINT:
2313             {
2314                 P_LINK_T prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2315                 /* Search specific client device, and disconnect. */
2316                 /* 1. Send deauthentication frame. */
2317                 /* 2. Indication: Device disconnect. */
2318                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2319                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2320
2321                 DBGLOG(P2P, TRACE, ("Disconnecting with Target ID: "MACSTR"\n", MAC2STR(prDisconnMsg->aucTargetID)));
2322
2323                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2324                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2325
2326                     ASSERT(prCurrStaRec);
2327
2328                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prDisconnMsg->aucTargetID)) {
2329
2330                         DBGLOG(P2P, TRACE, ("Disconnecting: "MACSTR"\n", MAC2STR(prCurrStaRec->aucMacAddr)));
2331
2332                         /* Remove STA from client list. */
2333                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2334
2335                         /* Glue layer indication. */
2336                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prCurrStaRec, FALSE);
2337
2338                         /* Send deauth & do indication. */
2339                         p2pFuncDisconnect(prAdapter, prCurrStaRec, prDisconnMsg->fgSendDeauth, prDisconnMsg->u2ReasonCode);
2340
2341                         //prTargetStaRec = prCurrStaRec;
2342
2343                         break;
2344                     }
2345                 }
2346
2347             }
2348             break;
2349         case OP_MODE_P2P_DEVICE:
2350         default:
2351             //ASSERT(FALSE);
2352             break;
2353         }
2354
2355     } while (FALSE);
2356
2357     //20120830 moved into p2pFuncDisconnect()
2358     //if ((!prDisconnMsg->fgSendDeauth) && (prTargetStaRec)) {
2359     //    cnmStaRecFree(prAdapter, prTargetStaRec, TRUE);
2360     //}
2361
2362
2363     if (prMsgHdr) {
2364         cnmMemFree(prAdapter, prMsgHdr);
2365     }
2366
2367     return;
2368 } /* p2pFsmRunEventConnectionAbort */
2369
2370
2371 VOID
2372 p2pFsmRunEventDissolve (
2373     IN P_ADAPTER_T prAdapter,
2374     IN P_MSG_HDR_T prMsgHdr
2375     )
2376 {
2377
2378     // TODO:
2379
2380     DBGLOG(P2P, TRACE, ("p2pFsmRunEventDissolve\n"));
2381
2382     if (prMsgHdr) {
2383         cnmMemFree(prAdapter, prMsgHdr);
2384     }
2385
2386     return;
2387 }
2388 WLAN_STATUS
2389 p2pFsmRunEventDeauthTxDone (
2390     IN P_ADAPTER_T prAdapter,
2391     IN P_MSDU_INFO_T prMsduInfo,
2392     IN ENUM_TX_RESULT_CODE_T rTxDoneStatus
2393     )
2394 {
2395
2396     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
2397     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2398     ENUM_PARAM_MEDIA_STATE_T eOriMediaStatus;
2399
2400     do {
2401
2402         ASSERT_BREAK((prAdapter != NULL) &&
2403                                     (prMsduInfo != NULL));
2404
2405         DBGLOG(P2P, TRACE, ("Deauth TX Done\n"));
2406
2407         prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
2408
2409         if (prStaRec == NULL) {
2410             DBGLOG(P2P, TRACE, ("Station Record NULL, Index:%d\n", prMsduInfo->ucStaRecIndex));
2411             break;
2412         }
2413
2414         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2415         eOriMediaStatus = prP2pBssInfo->eConnectionState;
2416
2417
2418                 bssRemoveStaRecFromClientList(prAdapter, prP2pBssInfo, prStaRec);
2419
2420         /**/
2421         cnmStaRecFree(prAdapter, prStaRec, TRUE);
2422
2423         if ((prP2pBssInfo->eCurrentOPMode != OP_MODE_ACCESS_POINT) ||
2424                 (prP2pBssInfo->rStaRecOfClientList.u4NumElem == 0)) {
2425             DBGLOG(P2P, TRACE, ("No More Client, Media Status DISCONNECTED\n"));
2426             p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_DISCONNECTED);
2427         }
2428
2429         /* Because the eConnectionState is changed before Deauth TxDone. Dont Check eConnectionState */
2430         //if (eOriMediaStatus != prP2pBssInfo->eConnectionState) {
2431             /* Update Disconnected state to FW. */
2432             nicUpdateBss(prAdapter, NETWORK_TYPE_P2P_INDEX);
2433         //}
2434
2435
2436     } while (FALSE);
2437
2438     return WLAN_STATUS_SUCCESS;
2439 } /* p2pFsmRunEventDeauthTxDone */
2440
2441
2442 WLAN_STATUS
2443 p2pFsmRunEventMgmtFrameTxDone (
2444     IN P_ADAPTER_T prAdapter,
2445     IN P_MSDU_INFO_T prMsduInfo,
2446     IN ENUM_TX_RESULT_CODE_T rTxDoneStatus
2447     )
2448 {
2449     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2450     P_P2P_MGMT_TX_REQ_INFO_T prMgmtTxReqInfo = (P_P2P_MGMT_TX_REQ_INFO_T)NULL;
2451     BOOLEAN fgIsSuccess = FALSE;
2452
2453     do {
2454         ASSERT_BREAK((prAdapter != NULL) && (prMsduInfo != NULL));
2455
2456         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2457         prMgmtTxReqInfo = &(prP2pFsmInfo->rMgmtTxInfo);
2458
2459         if (rTxDoneStatus != TX_RESULT_SUCCESS) {
2460                         DBGLOG(P2P, TRACE, ("Mgmt Frame TX Fail, Status:%d.\n", rTxDoneStatus));
2461
2462         }
2463         else {
2464             fgIsSuccess = TRUE;
2465             DBGLOG(P2P, TRACE, ("Mgmt Frame TX Done.\n"));
2466         }
2467
2468
2469         if (prMgmtTxReqInfo->prMgmtTxMsdu == prMsduInfo) {
2470
2471             kalP2PIndicateMgmtTxStatus(prAdapter->prGlueInfo,
2472                             prMgmtTxReqInfo->u8Cookie,
2473                             fgIsSuccess,
2474                             prMsduInfo->prPacket,
2475                             (UINT_32)prMsduInfo->u2FrameLength);
2476
2477             prMgmtTxReqInfo->prMgmtTxMsdu = NULL;
2478         }
2479
2480     } while (FALSE);
2481
2482     return WLAN_STATUS_SUCCESS;
2483
2484 } /* p2pFsmRunEventMgmtFrameTxDone */
2485
2486
2487 /*----------------------------------------------------------------------------*/
2488 /*!
2489 * \brief    This function is called when JOIN complete message event is received from SAA.
2490 *
2491 * \param[in] prAdapter  Pointer of ADAPTER_T
2492 *
2493 * \return none
2494 */
2495 /*----------------------------------------------------------------------------*/
2496 VOID
2497 p2pFsmRunEventJoinComplete (
2498     IN P_ADAPTER_T prAdapter,
2499     IN P_MSG_HDR_T prMsgHdr
2500     )
2501 {
2502     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2503     P_P2P_JOIN_INFO_T prJoinInfo = (P_P2P_JOIN_INFO_T)NULL;
2504     P_MSG_JOIN_COMP_T prJoinCompMsg = (P_MSG_JOIN_COMP_T)NULL;
2505     P_SW_RFB_T prAssocRspSwRfb = (P_SW_RFB_T)NULL;
2506     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2507
2508     do {
2509         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2510
2511         DBGLOG(P2P, TRACE, ("P2P Join Complete\n"));
2512
2513         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2514
2515         if (prP2pFsmInfo == NULL) {
2516             break;
2517         }
2518         
2519
2520         prJoinInfo = &(prP2pFsmInfo->rJoinInfo);
2521         prJoinCompMsg = (P_MSG_JOIN_COMP_T)prMsgHdr;
2522         prAssocRspSwRfb = prJoinCompMsg->prSwRfb;
2523         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2524
2525         if (prP2pBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) {
2526             P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
2527
2528             prStaRec = prJoinCompMsg->prStaRec;
2529
2530             /* Check SEQ NUM */
2531             if (prJoinCompMsg->ucSeqNum == prJoinInfo->ucSeqNumOfReqMsg) {
2532                 ASSERT(prStaRec == prJoinInfo->prTargetStaRec);
2533                 prJoinInfo->fgIsJoinComplete = TRUE;
2534
2535                 if (prJoinCompMsg->rJoinStatus == WLAN_STATUS_SUCCESS) {
2536
2537                     //4 <1.1> Change FW's Media State immediately.
2538                     p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_CONNECTED);
2539
2540                     //4 <1.2> Deactivate previous AP's STA_RECORD_T in Driver if have.
2541                     if ((prP2pBssInfo->prStaRecOfAP) &&
2542                             (prP2pBssInfo->prStaRecOfAP != prStaRec)) {
2543                         cnmStaRecChangeState(prAdapter, prP2pBssInfo->prStaRecOfAP, STA_STATE_1);
2544
2545                         cnmStaRecFree(prAdapter, prP2pBssInfo->prStaRecOfAP, TRUE);
2546
2547                         prP2pBssInfo->prStaRecOfAP = NULL;
2548                     }
2549
2550                     //4 <1.3> Update BSS_INFO_T
2551                     p2pFuncUpdateBssInfoForJOIN(prAdapter, prP2pFsmInfo->prTargetBss, prStaRec, prAssocRspSwRfb);
2552
2553                     //4 <1.4> Activate current AP's STA_RECORD_T in Driver.
2554                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
2555
2556 #if CFG_SUPPORT_P2P_RSSI_QUERY
2557                     //<1.5> Update RSSI if necessary
2558                     nicUpdateRSSI(prAdapter, NETWORK_TYPE_P2P_INDEX, (INT_8)(RCPI_TO_dBm(prStaRec->ucRCPI)), 0);
2559 #endif
2560
2561                     //4 <1.6> Indicate Connected Event to Host immediately.
2562                     /* Require BSSID, Association ID, Beacon Interval.. from AIS_BSS_INFO_T */
2563                     //p2pIndicationOfMediaStateToHost(prAdapter, PARAM_MEDIA_STATE_CONNECTED, prStaRec->aucMacAddr);
2564                     kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2565                                                                     &prP2pFsmInfo->rConnReqInfo,
2566                                                                     prJoinInfo->aucIEBuf,
2567                                                                     prJoinInfo->u4BufLength,
2568                                                                     prStaRec->u2StatusCode);
2569
2570                 }
2571                 else {
2572                     /* Join Fail*/
2573                     //4 <2.1> Redo JOIN process with other Auth Type if possible
2574                     if (p2pFuncRetryJOIN(prAdapter, prStaRec, prJoinInfo) == FALSE) {
2575                         P_BSS_DESC_T prBssDesc;
2576
2577                         /* Increase Failure Count */
2578                         prStaRec->ucJoinFailureCount++;
2579
2580                         prBssDesc = prP2pFsmInfo->prTargetBss;
2581
2582                         ASSERT(prBssDesc);
2583                         ASSERT(prBssDesc->fgIsConnecting);
2584
2585                         prBssDesc->fgIsConnecting = FALSE;
2586
2587                         if( prStaRec->ucJoinFailureCount >=3) {
2588
2589                         kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2590                                                                     &prP2pFsmInfo->rConnReqInfo,
2591                                                                     prJoinInfo->aucIEBuf,
2592                                                                     prJoinInfo->u4BufLength,
2593                                                                     prStaRec->u2StatusCode);
2594                         }
2595                         else {
2596                             /* Sometime the GO is not ready to response auth. Connect it again*/
2597                             prP2pFsmInfo->prTargetBss = NULL;
2598                         }
2599
2600
2601                     }
2602
2603                 }
2604             }
2605         }
2606
2607         if (prAssocRspSwRfb) {
2608             nicRxReturnRFB(prAdapter, prAssocRspSwRfb);
2609         }
2610
2611         if (prP2pFsmInfo->eCurrentState == P2P_STATE_GC_JOIN) {
2612             
2613             if(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX].eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
2614             /* Return to IDLE state. */
2615             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2616         }
2617             else {
2618             //p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2619                  /* one more scan */
2620                  p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN); 
2621             }
2622         }
2623
2624     } while (FALSE);
2625
2626     if (prMsgHdr) {
2627         cnmMemFree(prAdapter, prMsgHdr);
2628     }
2629
2630     return;
2631
2632 } /* p2pFsmRunEventJoinComplete */
2633
2634
2635
2636 VOID
2637 p2pFsmRunEventMgmtFrameRegister (
2638     IN P_ADAPTER_T prAdapter,
2639     IN P_MSG_HDR_T prMsgHdr
2640     )
2641 {
2642     P_MSG_P2P_MGMT_FRAME_REGISTER_T prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)NULL;
2643     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2644
2645     do {
2646         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2647
2648         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2649
2650         if (prP2pFsmInfo == NULL) {
2651             break;
2652         }
2653
2654         prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)prMsgHdr;
2655
2656         p2pFuncMgmtFrameRegister(prAdapter,
2657                             prMgmtFrameRegister->u2FrameType,
2658                             prMgmtFrameRegister->fgIsRegister,
2659                             &prP2pFsmInfo->u4P2pPacketFilter);
2660
2661
2662     } while (FALSE);
2663
2664     if (prMsgHdr) {
2665         cnmMemFree(prAdapter, prMsgHdr);
2666     }
2667
2668     return;
2669
2670 } /* p2pFsmRunEventMgmtFrameRegister */
2671
2672
2673
2674
2675 #if 0
2676 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2677 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2678 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2679 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2680 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2681 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2682 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2683 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2684 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2685 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2686 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2687 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2688 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2689 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2690 #endif
2691
2692
2693
2694
2695
2696
2697
2698 /*----------------------------------------------------------------------------*/
2699 /*!
2700 * \brief    This function is call when RX deauthentication frame from the AIR.
2701 *             If we are under STA mode, we would go back to P2P Device.
2702 *             If we are under AP mode, we would stay in AP mode until disconnect event from HOST.
2703 *
2704 * \param[in] prAdapter  Pointer of ADAPTER_T
2705 *
2706 * \return none
2707 */
2708 /*----------------------------------------------------------------------------*/
2709 VOID
2710 p2pFsmRunEventRxDeauthentication (
2711     IN P_ADAPTER_T prAdapter,
2712     IN P_STA_RECORD_T prStaRec,
2713     IN P_SW_RFB_T prSwRfb
2714     )
2715 {
2716     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2717     UINT_16 u2ReasonCode = 0;
2718
2719     do {
2720         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
2721
2722         if (prStaRec == NULL) {
2723             prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
2724         }
2725
2726         if (!prStaRec) {
2727             break;
2728         }
2729
2730
2731         prP2pBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
2732
2733         if (prStaRec->ucStaState == STA_STATE_1) {
2734             break;
2735         }
2736
2737         DBGLOG(P2P, TRACE, ("RX Deauth\n"));
2738
2739         switch (prP2pBssInfo->eCurrentOPMode) {
2740         case OP_MODE_INFRASTRUCTURE:
2741             if (authProcessRxDeauthFrame(prSwRfb,
2742                     prStaRec->aucMacAddr,
2743                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2744                 P_WLAN_DEAUTH_FRAME_T prDeauthFrame = (P_WLAN_DEAUTH_FRAME_T)prSwRfb->pvHeader;
2745                 UINT_16 u2IELength = 0;
2746
2747                 if (prP2pBssInfo->prStaRecOfAP != prStaRec) {
2748                     break;
2749                 }
2750
2751
2752                 prStaRec->u2ReasonCode = u2ReasonCode;
2753                 u2IELength = prSwRfb->u2PacketLen - (WLAN_MAC_HEADER_LEN + REASON_CODE_FIELD_LEN);
2754
2755                 ASSERT(prP2pBssInfo->prStaRecOfAP == prStaRec);
2756
2757                 /* Indicate disconnect to Host. */
2758                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2759                                         NULL,
2760                                         prDeauthFrame->aucInfoElem,
2761                                         u2IELength,
2762                                         u2ReasonCode);
2763
2764                 prP2pBssInfo->prStaRecOfAP = NULL;
2765
2766                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2767             }
2768             break;
2769         case OP_MODE_ACCESS_POINT:
2770             /* Delete client from client list. */
2771             if (authProcessRxDeauthFrame(prSwRfb,
2772                     prP2pBssInfo->aucBSSID,
2773                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2774                 P_LINK_T prStaRecOfClientList = (P_LINK_T)NULL;
2775                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2776                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2777
2778                 prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2779
2780                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2781                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2782
2783                     ASSERT(prCurrStaRec);
2784
2785                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prStaRec->aucMacAddr)) {
2786
2787                         /* Remove STA from client list. */
2788                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2789
2790                         /* Indicate to Host. */
2791                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, FALSE);
2792
2793                         /* Indicate disconnect to Host. */
2794                         p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2795
2796                         break;
2797                     }
2798                 }
2799             }
2800             break;
2801         case OP_MODE_P2P_DEVICE:
2802         default:
2803             /* Findout why someone sent deauthentication frame to us. */
2804             ASSERT(FALSE);
2805             break;
2806         }
2807
2808         DBGLOG(P2P, TRACE, ("Deauth Reason:%d\n", u2ReasonCode));
2809
2810     } while (FALSE);
2811
2812     return;
2813 } /* p2pFsmRunEventRxDeauthentication */
2814
2815 /*----------------------------------------------------------------------------*/
2816 /*!
2817 * \brief    This function is call when RX deauthentication frame from the AIR.
2818 *             If we are under STA mode, we would go back to P2P Device.
2819 *             If we are under AP mode, we would stay in AP mode until disconnect event from HOST.
2820 *
2821 * \param[in] prAdapter  Pointer of ADAPTER_T
2822 *
2823 * \return none
2824 */
2825 /*----------------------------------------------------------------------------*/
2826 VOID
2827 p2pFsmRunEventRxDisassociation (
2828     IN P_ADAPTER_T prAdapter,
2829     IN P_STA_RECORD_T prStaRec,
2830     IN P_SW_RFB_T prSwRfb
2831     )
2832 {
2833     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2834     UINT_16 u2ReasonCode = 0;
2835
2836     do {
2837         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
2838
2839         if (prStaRec == NULL) {
2840             prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
2841         }
2842
2843
2844         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2845
2846         if (prStaRec->ucStaState == STA_STATE_1) {
2847
2848             break;
2849         }
2850
2851         DBGLOG(P2P, TRACE, ("RX Disassoc\n"));
2852
2853         switch (prP2pBssInfo->eCurrentOPMode) {
2854         case OP_MODE_INFRASTRUCTURE:
2855             if (assocProcessRxDisassocFrame(prAdapter,
2856                     prSwRfb,
2857                     prStaRec->aucMacAddr,
2858                     &prStaRec->u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2859                 P_WLAN_DISASSOC_FRAME_T prDisassocFrame = (P_WLAN_DISASSOC_FRAME_T)prSwRfb->pvHeader;
2860                 UINT_16 u2IELength = 0;
2861
2862                 ASSERT(prP2pBssInfo->prStaRecOfAP == prStaRec);
2863
2864                 if (prP2pBssInfo->prStaRecOfAP != prStaRec) {
2865                     break;
2866                 }
2867
2868
2869                 u2IELength = prSwRfb->u2PacketLen - (WLAN_MAC_HEADER_LEN + REASON_CODE_FIELD_LEN);
2870
2871                 /* Indicate disconnect to Host. */
2872                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2873                                         NULL,
2874                                         prDisassocFrame->aucInfoElem,
2875                                         u2IELength,
2876                                         prStaRec->u2ReasonCode);
2877                 
2878                 prP2pBssInfo->prStaRecOfAP = NULL;
2879
2880                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, prStaRec->u2ReasonCode);
2881                 
2882             }
2883             break;
2884         case OP_MODE_ACCESS_POINT:
2885             /* Delete client from client list. */
2886             if (assocProcessRxDisassocFrame(prAdapter,
2887                     prSwRfb,
2888                     prP2pBssInfo->aucBSSID,
2889                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2890                 P_LINK_T prStaRecOfClientList = (P_LINK_T)NULL;
2891                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2892                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2893
2894                 prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2895
2896                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2897                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2898
2899                     ASSERT(prCurrStaRec);
2900
2901                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prStaRec->aucMacAddr)) {
2902
2903                         /* Remove STA from client list. */
2904                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2905
2906                         /* Indicate to Host. */
2907                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, FALSE);
2908
2909                         /* Indicate disconnect to Host. */
2910                         p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2911
2912                         break;
2913                     }
2914                 }
2915             }
2916             break;
2917         case OP_MODE_P2P_DEVICE:
2918         default:
2919             ASSERT(FALSE);
2920             break;
2921         }
2922
2923
2924     } while (FALSE);
2925
2926     return;
2927 } /* p2pFsmRunEventRxDisassociation */
2928
2929
2930
2931
2932
2933 /*----------------------------------------------------------------------------*/
2934 /*!
2935 * \brief    This function is called when a probe request frame is received.
2936 *
2937 * \param[in] prAdapter  Pointer of ADAPTER_T
2938 *
2939 * \return boolean value if probe response frame is accepted & need cancel scan request.
2940 */
2941 /*----------------------------------------------------------------------------*/
2942 VOID
2943 p2pFsmRunEventRxProbeResponseFrame (
2944     IN P_ADAPTER_T prAdapter,
2945     IN P_SW_RFB_T prSwRfb,
2946     IN P_BSS_DESC_T prBssDesc
2947     )
2948 {
2949     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2950     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
2951     P_WLAN_MAC_MGMT_HEADER_T prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)NULL;
2952     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2953
2954     do {
2955         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL) && (prBssDesc != NULL));
2956
2957         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2958         prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
2959         prP2pBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
2960
2961         /* There is a connection request. */
2962         prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)prSwRfb->pvHeader;
2963
2964     } while (FALSE);
2965
2966     return;
2967 } /* p2pFsmRunEventRxProbeResponseFrame */
2968
2969
2970
2971
2972
2973
2974 VOID
2975 p2pFsmRunEventBeaconTimeout (
2976     IN P_ADAPTER_T prAdapter
2977     )
2978 {
2979     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2980     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2981
2982     do {
2983         ASSERT_BREAK(prAdapter != NULL);
2984
2985         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2986         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2987
2988         DBGLOG(P2P, TRACE, ("p2pFsmRunEventBeaconTimeout: Beacon Timeout\n"));
2989
2990         /* Only client mode would have beacon lost event. */
2991         ASSERT(prP2pBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE);
2992
2993         if (prP2pBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
2994             /* Indicate disconnect to Host. */
2995             kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2996                                     NULL,
2997                                     NULL,
2998                                     0,
2999                                     REASON_CODE_DISASSOC_INACTIVITY);
3000
3001             if (prP2pBssInfo->prStaRecOfAP != NULL) {
3002                 P_STA_RECORD_T prStaRec = prP2pBssInfo->prStaRecOfAP;
3003                 
3004                 prP2pBssInfo->prStaRecOfAP = NULL;
3005
3006                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, REASON_CODE_DISASSOC_LEAVING_BSS);
3007
3008                 //20120830 moved into p2pFuncDisconnect()
3009                 //cnmStaRecFree(prAdapter, prP2pBssInfo->prStaRecOfAP, TRUE);
3010
3011                 
3012             }
3013         }
3014     } while (FALSE);
3015
3016     return;
3017 } /* p2pFsmRunEventBeaconTimeout */
3018
3019
3020
3021
3022 #if CFG_SUPPORT_WFD
3023 VOID
3024 p2pFsmRunEventWfdSettingUpdate (
3025     IN P_ADAPTER_T prAdapter,
3026     IN P_MSG_HDR_T prMsgHdr
3027     )
3028 {
3029     P_WFD_CFG_SETTINGS_T prWfdCfgSettings = (P_WFD_CFG_SETTINGS_T)NULL;
3030     P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T prMsgWfdCfgSettings = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)NULL;
3031     WLAN_STATUS rStatus;
3032
3033
3034     DBGLOG(P2P, INFO,("p2pFsmRunEventWfdSettingUpdate\n"));
3035
3036     do {
3037         ASSERT_BREAK((prAdapter != NULL));
3038
3039         if (prMsgHdr != NULL) {
3040             prMsgWfdCfgSettings = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)prMsgHdr;
3041             prWfdCfgSettings = prMsgWfdCfgSettings->prWfdCfgSettings;
3042         }
3043         else {
3044             prWfdCfgSettings = &prAdapter->rWifiVar.prP2pFsmInfo->rWfdConfigureSettings;
3045         }
3046         
3047         DBGLOG(P2P, INFO,("WFD Enalbe %x info %x state %x flag %x adv %x\n", 
3048                     prWfdCfgSettings->ucWfdEnable,
3049                     prWfdCfgSettings->u2WfdDevInfo, 
3050                     prWfdCfgSettings->u4WfdState, 
3051                     prWfdCfgSettings->u4WfdFlag, 
3052                     prWfdCfgSettings->u4WfdAdvancedFlag));
3053
3054         rStatus = wlanSendSetQueryCmd (
3055                         prAdapter,                  /* prAdapter */
3056                         CMD_ID_SET_WFD_CTRL,   /* ucCID */
3057                         TRUE,                       /* fgSetQuery */
3058                         FALSE,                /* fgNeedResp */
3059                         FALSE,                      /* fgIsOid */
3060                         NULL,
3061                         NULL,                       /* pfCmdTimeoutHandler */
3062                         sizeof(WFD_CFG_SETTINGS_T),    /* u4SetQueryInfoLen */
3063                         (PUINT_8)prWfdCfgSettings,     /* pucInfoBuffer */
3064                         NULL,                       /* pvSetQueryBuffer */
3065                         0                           /* u4SetQueryBufferLen */
3066                         );
3067
3068     } while (FALSE);
3069
3070     return;
3071
3072 }
3073 /* p2pFsmRunEventWfdSettingUpdate */
3074
3075 #endif
3076
3077
3078
3079
3080
3081
3082
3083
3084 /*----------------------------------------------------------------------------*/
3085 /*!
3086 * @brief This function is used to generate P2P IE for Beacon frame.
3087 *
3088 * @param[in] prMsduInfo             Pointer to the composed MSDU_INFO_T.
3089 *
3090 * @return none
3091 */
3092 /*----------------------------------------------------------------------------*/
3093 VOID
3094 p2pGenerateP2P_IEForAssocReq (
3095     IN P_ADAPTER_T prAdapter,
3096     IN P_MSDU_INFO_T prMsduInfo
3097     )
3098 {
3099     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
3100     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
3101
3102     do {
3103         ASSERT_BREAK((prAdapter != NULL) && (prMsduInfo != NULL));
3104
3105         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
3106
3107         prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
3108
3109         if (IS_STA_P2P_TYPE(prStaRec)) {
3110             // TODO:
3111         }
3112
3113     } while (FALSE);
3114
3115     return;
3116
3117 } /* end of p2pGenerateP2P_IEForAssocReq() */
3118
3119
3120
3121
3122 /*----------------------------------------------------------------------------*/
3123 /*!
3124 * @brief This function is used to generate P2P IE for Probe Request frame.
3125 *
3126 * @param[in] prMsduInfo             Pointer to the composed MSDU_INFO_T.
3127 *
3128 * @return none
3129 */
3130 /*----------------------------------------------------------------------------*/
3131 VOID
3132 p2pGenerateP2P_IEForProbeReq (
3133     IN P_ADAPTER_T prAdapter,
3134     IN PUINT_16 pu2Offset,
3135     IN PUINT_8 pucBuf,
3136     IN UINT_16 u2BufSize
3137     )
3138 {
3139     ASSERT(prAdapter);
3140     ASSERT(pucBuf);
3141
3142     // TODO:
3143
3144     return;
3145
3146 } /* end of p2pGenerateP2P_IEForProbReq() */
3147
3148
3149
3150
3151 /*----------------------------------------------------------------------------*/
3152 /*!
3153 * @brief This function is used to calculate P2P IE length for Beacon frame.
3154 *
3155 * @param[in] eNetTypeIndex      Specify which network
3156 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3157 *
3158 * @return The length of P2P IE added
3159 */
3160 /*----------------------------------------------------------------------------*/
3161 UINT_32
3162 p2pCalculateP2P_IELenForProbeReq (
3163     IN P_ADAPTER_T prAdapter,
3164     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
3165     IN P_STA_RECORD_T prStaRec
3166     )
3167 {
3168
3169     if (eNetTypeIndex != NETWORK_TYPE_P2P_INDEX) {
3170         return 0;
3171     }
3172
3173     // TODO:
3174
3175     return 0;
3176
3177 } /* end of p2pCalculateP2P_IELenForProbeReq() */
3178
3179
3180
3181
3182
3183 /*----------------------------------------------------------------------------*/
3184 /*!
3185 * @brief This function will indiate the Event of Tx Fail of AAA Module.
3186 *
3187 * @param[in] prAdapter          Pointer to the Adapter structure.
3188 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3189 *
3190 * @return (none)
3191 */
3192 /*----------------------------------------------------------------------------*/
3193 VOID
3194 p2pRunEventAAATxFail (
3195     IN P_ADAPTER_T prAdapter,
3196     IN P_STA_RECORD_T prStaRec
3197     )
3198 {
3199     P_BSS_INFO_T prBssInfo;
3200
3201
3202     ASSERT(prAdapter);
3203     ASSERT(prStaRec);
3204
3205     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
3206
3207     bssRemoveStaRecFromClientList(prAdapter, prBssInfo, prStaRec);
3208
3209     p2pFuncDisconnect(prAdapter, prStaRec, FALSE, REASON_CODE_UNSPECIFIED);
3210
3211     
3212     //20120830 moved into p2puUncDisconnect.
3213     //cnmStaRecFree(prAdapter, prStaRec, TRUE);
3214
3215     return;
3216 } /* p2pRunEventAAATxFail */
3217
3218
3219 /*----------------------------------------------------------------------------*/
3220 /*!
3221 * @brief This function will indiate the Event of Successful Completion of AAA Module.
3222 *
3223 * @param[in] prAdapter          Pointer to the Adapter structure.
3224 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3225 *
3226 * @return (none)
3227 */
3228 /*----------------------------------------------------------------------------*/
3229 WLAN_STATUS
3230 p2pRunEventAAAComplete (
3231     IN P_ADAPTER_T prAdapter,
3232     IN P_STA_RECORD_T prStaRec
3233     )
3234 {
3235     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
3236     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
3237     ENUM_PARAM_MEDIA_STATE_T eOriMediaState;
3238
3239     do {
3240         ASSERT_BREAK((prAdapter != NULL) && (prStaRec != NULL));
3241
3242         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
3243
3244         eOriMediaState = prP2pBssInfo->eConnectionState;
3245
3246         if (prStaRec != NULL) {
3247                         bssRemoveStaRecFromClientList(prAdapter, prP2pBssInfo, prStaRec);
3248                 }
3249                 else{
3250                         break;
3251                 }
3252
3253         if (prP2pBssInfo->rStaRecOfClientList.u4NumElem >= P2P_MAXIMUM_CLIENT_COUNT ||
3254             kalP2PMaxClients(prAdapter->prGlueInfo, prP2pBssInfo->rStaRecOfClientList.u4NumElem)) {
3255             rStatus = WLAN_STATUS_RESOURCES;
3256             break;
3257         }
3258
3259         bssAddStaRecToClientList(prAdapter, prP2pBssInfo, prStaRec);
3260
3261         prStaRec->u2AssocId = bssAssignAssocID(prStaRec);
3262         
3263         cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
3264
3265         p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_CONNECTED);
3266
3267         /* Update Connected state to FW. */
3268         if (eOriMediaState != prP2pBssInfo->eConnectionState) {
3269             nicUpdateBss(prAdapter, NETWORK_TYPE_P2P_INDEX);
3270         }
3271
3272     } while (FALSE);
3273
3274     return rStatus;
3275 } /* p2pRunEventAAAComplete */
3276
3277
3278 /*----------------------------------------------------------------------------*/
3279 /*!
3280 * @brief This function will indiate the Event of Successful Completion of AAA Module.
3281 *
3282 * @param[in] prAdapter          Pointer to the Adapter structure.
3283 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3284 *
3285 * @return (none)
3286 */
3287 /*----------------------------------------------------------------------------*/
3288 WLAN_STATUS
3289 p2pRunEventAAASuccess (
3290     IN P_ADAPTER_T prAdapter,
3291     IN P_STA_RECORD_T prStaRec
3292     )
3293 {
3294     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
3295
3296     do {
3297         ASSERT_BREAK((prAdapter != NULL) && (prStaRec != NULL));
3298
3299         /* Glue layer indication. */
3300         kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, TRUE);
3301
3302     } while (FALSE);
3303
3304     return rStatus;
3305 } /* p2pRunEventAAASuccess */
3306
3307
3308
3309 /*----------------------------------------------------------------------------*/
3310 /*!
3311 * \brief
3312 *
3313 * \param[in]
3314 *
3315 * \return none
3316 */
3317 /*----------------------------------------------------------------------------*/
3318 WLAN_STATUS
3319 p2pRxPublicActionFrame (
3320     IN P_ADAPTER_T prAdapter,
3321     IN P_SW_RFB_T prSwRfb
3322     )
3323 {
3324     WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS;
3325     P_P2P_PUBLIC_ACTION_FRAME_T prPublicActionFrame = (P_P2P_PUBLIC_ACTION_FRAME_T)NULL;
3326     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
3327
3328     ASSERT(prSwRfb);
3329     ASSERT(prAdapter);
3330
3331
3332
3333     prPublicActionFrame = (P_P2P_PUBLIC_ACTION_FRAME_T)prSwRfb->pvHeader;
3334     prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
3335
3336     DBGLOG(P2P, TRACE, ("RX Public Action Frame Token:%d.\n", prPublicActionFrame->ucDialogToken));
3337
3338     if (prPublicActionFrame->ucCategory != CATEGORY_PUBLIC_ACTION) {
3339         return rWlanStatus;
3340     }
3341
3342     switch (prPublicActionFrame->ucAction) {
3343     case ACTION_PUBLIC_WIFI_DIRECT:
3344         break;
3345     case ACTION_GAS_INITIAL_REQUEST:
3346     case ACTION_GAS_INITIAL_RESPONSE:
3347     case ACTION_GAS_COMEBACK_REQUEST:
3348     case ACTION_GAS_COMEBACK_RESPONSE:
3349         break;
3350     default:
3351         break;
3352     }
3353
3354     return rWlanStatus;
3355 } /* p2pRxPublicActionFrame */
3356
3357
3358
3359 WLAN_STATUS
3360 p2pRxActionFrame (
3361     IN P_ADAPTER_T prAdapter,
3362     IN P_SW_RFB_T prSwRfb
3363     )
3364 {
3365     WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS;
3366     P_P2P_ACTION_FRAME_T prP2pActionFrame = (P_P2P_ACTION_FRAME_T)NULL;
3367     UINT_8 aucOui[3] = VENDOR_OUI_WFA_SPECIFIC;
3368
3369     do {
3370         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
3371
3372         prP2pActionFrame = (P_P2P_ACTION_FRAME_T)prSwRfb->pvHeader;
3373
3374         if (prP2pActionFrame->ucCategory != CATEGORY_VENDOR_SPECIFIC_ACTION) {
3375             DBGLOG(P2P, TRACE, ("RX Action Frame but not vendor specific.\n"));
3376             break;
3377         }
3378
3379
3380         if ((prP2pActionFrame->ucOuiType != VENDOR_OUI_TYPE_P2P) ||
3381                 (prP2pActionFrame->aucOui[0] != aucOui[0]) ||
3382                 (prP2pActionFrame->aucOui[1] != aucOui[1]) ||
3383                 (prP2pActionFrame->aucOui[2] != aucOui[2])) {
3384             DBGLOG(P2P, TRACE, ("RX Vendor Specific Action Frame but not P2P Type or not WFA OUI.\n"));
3385             break;
3386         }
3387
3388     } while (FALSE);
3389
3390     return rWlanStatus;
3391 } /* p2pRxActionFrame */
3392
3393
3394 VOID
3395 p2pProcessEvent_UpdateNOAParam (
3396     IN P_ADAPTER_T    prAdapter,
3397     UINT_8  ucNetTypeIndex,
3398     P_EVENT_UPDATE_NOA_PARAMS_T prEventUpdateNoaParam
3399     )
3400 {
3401     P_BSS_INFO_T prBssInfo = (P_BSS_INFO_T)NULL;
3402     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
3403     UINT_32 i;
3404     BOOLEAN fgNoaAttrExisted = FALSE;
3405
3406     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[ucNetTypeIndex]);
3407     prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
3408
3409     prP2pSpecificBssInfo->fgEnableOppPS = prEventUpdateNoaParam->fgEnableOppPS;
3410     prP2pSpecificBssInfo->u2CTWindow = prEventUpdateNoaParam->u2CTWindow;
3411     prP2pSpecificBssInfo->ucNoAIndex = prEventUpdateNoaParam->ucNoAIndex;
3412     prP2pSpecificBssInfo->ucNoATimingCount = prEventUpdateNoaParam->ucNoATimingCount;
3413
3414     fgNoaAttrExisted |= prP2pSpecificBssInfo->fgEnableOppPS;
3415
3416
3417     ASSERT(prP2pSpecificBssInfo->ucNoATimingCount <= P2P_MAXIMUM_NOA_COUNT);
3418
3419     for (i = 0; i < prP2pSpecificBssInfo->ucNoATimingCount; i++) {
3420         // in used
3421         prP2pSpecificBssInfo->arNoATiming[i].fgIsInUse =
3422             prEventUpdateNoaParam->arEventNoaTiming[i].fgIsInUse;
3423         // count
3424         prP2pSpecificBssInfo->arNoATiming[i].ucCount =
3425             prEventUpdateNoaParam->arEventNoaTiming[i].ucCount;
3426         // duration
3427         prP2pSpecificBssInfo->arNoATiming[i].u4Duration =
3428             prEventUpdateNoaParam->arEventNoaTiming[i].u4Duration;
3429         // interval
3430         prP2pSpecificBssInfo->arNoATiming[i].u4Interval =
3431             prEventUpdateNoaParam->arEventNoaTiming[i].u4Interval;
3432         // start time
3433         prP2pSpecificBssInfo->arNoATiming[i].u4StartTime =
3434             prEventUpdateNoaParam->arEventNoaTiming[i].u4StartTime;
3435
3436         fgNoaAttrExisted |= prP2pSpecificBssInfo->arNoATiming[i].fgIsInUse;
3437     }
3438
3439     prP2pSpecificBssInfo->fgIsNoaAttrExisted = fgNoaAttrExisted;
3440
3441     // update beacon content by the change
3442     bssUpdateBeaconContent(prAdapter, ucNetTypeIndex);
3443 }
3444
3445 #endif /* CFG_ENABLE_WIFI_DIRECT */
3446