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