support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6628 / 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                 prP2pFsmInfo->fgIsWPSMode = 0;
912
913         cnmTimerInitTimer(prAdapter,
914                             &(prP2pFsmInfo->rP2pFsmTimeoutTimer),
915                             (PFN_MGMT_TIMEOUT_FUNC)p2pFsmRunEventFsmTimeout,
916                             (UINT_32)prP2pFsmInfo);
917
918         //4 <2> Initiate BSS_INFO_T - common part
919         BSS_INFO_INIT(prAdapter, NETWORK_TYPE_P2P_INDEX);
920
921
922         //4 <2.1> Initiate BSS_INFO_T - Setup HW ID
923         prP2pBssInfo->ucConfigAdHocAPMode = AP_MODE_11G_P2P;
924         prP2pBssInfo->ucHwDefaultFixedRateCode = RATE_OFDM_6M;
925
926
927         prP2pBssInfo->ucNonHTBasicPhyType = (UINT_8)
928             rNonHTApModeAttributes[prP2pBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
929         prP2pBssInfo->u2BSSBasicRateSet =
930             rNonHTApModeAttributes[prP2pBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
931
932         prP2pBssInfo->u2OperationalRateSet =
933             rNonHTPhyAttributes[prP2pBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
934
935         rateGetDataRatesFromRateSet(prP2pBssInfo->u2OperationalRateSet,
936                                 prP2pBssInfo->u2BSSBasicRateSet,
937                                 prP2pBssInfo->aucAllSupportedRates,
938                                 &prP2pBssInfo->ucAllSupportedRatesLen);
939
940         prP2pBssInfo->prBeacon = cnmMgtPktAlloc(prAdapter,
941                                                             OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem[0]) + MAX_IE_LENGTH);
942
943         if (prP2pBssInfo->prBeacon) {
944             prP2pBssInfo->prBeacon->eSrc = TX_PACKET_MGMT;
945             prP2pBssInfo->prBeacon->ucStaRecIndex = 0xFF; /* NULL STA_REC */
946             prP2pBssInfo->prBeacon->ucNetworkType = NETWORK_TYPE_P2P_INDEX;
947         }
948         else {
949             /* Out of memory. */
950             ASSERT(FALSE);
951         }
952
953         prP2pBssInfo->eCurrentOPMode = OP_MODE_NUM;
954
955         prP2pBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = PM_UAPSD_ALL;
956         prP2pBssInfo->rPmProfSetupInfo.ucBmpTriggerAC = PM_UAPSD_ALL;
957         prP2pBssInfo->rPmProfSetupInfo.ucUapsdSp = WMM_MAX_SP_LENGTH_2;
958         prP2pBssInfo->ucPrimaryChannel = P2P_DEFAULT_LISTEN_CHANNEL;
959         prP2pBssInfo->eBand = BAND_2G4;
960         prP2pBssInfo->eBssSCO =  CHNL_EXT_SCN;
961
962         if (prAdapter->rWifiVar.fgSupportQoS) {
963             prP2pBssInfo->fgIsQBSS = TRUE;
964         }
965         else {
966             prP2pBssInfo->fgIsQBSS = FALSE;
967         }
968
969         SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
970
971         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
972
973     } while (FALSE);
974
975     return;
976 } /* p2pFsmInit */
977
978
979
980
981
982 /*----------------------------------------------------------------------------*/
983 /*!
984 * @brief The function is used to uninitialize the value in P2P_FSM_INFO_T for
985 *        P2P FSM operation
986 *
987 * @param (none)
988 *
989 * @return (none)
990 */
991 /*----------------------------------------------------------------------------*/
992 VOID
993 p2pFsmUninit (
994     IN P_ADAPTER_T prAdapter
995     )
996 {
997     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
998     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
999
1000     do {
1001         ASSERT_BREAK(prAdapter != NULL);
1002
1003         DEBUGFUNC("p2pFsmUninit()");
1004         DBGLOG(P2P, INFO, ("->p2pFsmUninit()\n"));
1005
1006         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1007         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1008
1009         p2pFuncSwitchOPMode(prAdapter, prP2pBssInfo, OP_MODE_P2P_DEVICE, TRUE);
1010
1011         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1012         
1013         p2pStateAbort_IDLE(prAdapter, prP2pFsmInfo, P2P_STATE_NUM);
1014
1015         UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1016
1017         wlanAcquirePowerControl(prAdapter);
1018
1019         /* Release all pending CMD queue. */
1020         DBGLOG(P2P, TRACE, ("p2pFsmUninit: wlanProcessCommandQueue, num of element:%d\n", prAdapter->prGlueInfo->rCmdQueue.u4NumElem));
1021         wlanProcessCommandQueue(prAdapter, &prAdapter->prGlueInfo->rCmdQueue);
1022
1023         wlanReleasePowerControl(prAdapter);
1024
1025         /* Release pending mgmt frame,
1026           * mgmt frame may be pending by CMD without resource.
1027           */
1028         kalClearMgmtFramesByNetType(prAdapter->prGlueInfo, NETWORK_TYPE_P2P_INDEX);
1029
1030         /* Clear PendingCmdQue*/
1031         wlanReleasePendingCMDbyNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1032
1033         if (prP2pBssInfo->prBeacon) {
1034             cnmMgtPktFree(prAdapter, prP2pBssInfo->prBeacon);
1035             prP2pBssInfo->prBeacon = NULL;
1036         }
1037
1038     } while (FALSE);
1039
1040     return;
1041
1042 } /* end of p2pFsmUninit() */
1043
1044 VOID
1045 p2pFsmStateTransition (
1046     IN P_ADAPTER_T prAdapter,
1047     IN P_P2P_FSM_INFO_T prP2pFsmInfo,
1048     IN ENUM_P2P_STATE_T eNextState
1049     )
1050 {
1051     BOOLEAN fgIsTransOut = (BOOLEAN)FALSE;
1052     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1053     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
1054
1055     do {
1056         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1057
1058         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1059         prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1060
1061         if (!IS_BSS_ACTIVE(prP2pBssInfo)) {
1062             if (!cnmP2PIsPermitted(prAdapter)) {
1063                 return;
1064             }
1065
1066             SET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1067             nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1068         }
1069
1070         fgIsTransOut = fgIsTransOut?FALSE:TRUE;
1071
1072         if (!fgIsTransOut) {
1073             DBGLOG(P2P, STATE, ("TRANSITION: [%s] -> [%s]\n",
1074                                 apucDebugP2pState[prP2pFsmInfo->eCurrentState],
1075                                 apucDebugP2pState[eNextState]));
1076
1077             /* Transition into current state. */
1078             prP2pFsmInfo->ePreviousState = prP2pFsmInfo->eCurrentState;
1079             prP2pFsmInfo->eCurrentState = eNextState;
1080         }
1081
1082
1083         switch (prP2pFsmInfo->eCurrentState) {
1084         case P2P_STATE_IDLE:
1085             if (fgIsTransOut) {
1086
1087                 p2pStateAbort_IDLE(prAdapter,
1088                                     prP2pFsmInfo,
1089                                     eNextState);
1090             }
1091             else {
1092                 fgIsTransOut = p2pStateInit_IDLE(prAdapter,
1093                                                     prP2pFsmInfo,
1094                                                     prP2pBssInfo,
1095                                                     &eNextState);
1096             }
1097
1098             break;
1099         case P2P_STATE_SCAN:
1100             if (fgIsTransOut) {
1101
1102                 // Scan done / scan canceled.
1103                 p2pStateAbort_SCAN(prAdapter, prP2pFsmInfo, eNextState);
1104             }
1105             else {
1106                 // Initial scan request.
1107                 p2pStateInit_SCAN(prAdapter, prP2pFsmInfo);
1108             }
1109
1110             break;
1111         case P2P_STATE_AP_CHANNEL_DETECT:
1112             if (fgIsTransOut) {
1113                 // Scan done
1114                     // Get sparse channel result.
1115                 p2pStateAbort_AP_CHANNEL_DETECT(prAdapter,
1116                                                 prP2pFsmInfo,
1117                                                 prP2pSpecificBssInfo,
1118                                                 eNextState);
1119             }
1120
1121             else {
1122                 // Initial passive scan request.
1123                 p2pStateInit_AP_CHANNEL_DETECT(prAdapter, prP2pFsmInfo);
1124             }
1125
1126             break;
1127         case P2P_STATE_REQING_CHANNEL:
1128             if (fgIsTransOut) {
1129
1130                 // Channel on hand / Channel canceled.
1131                 p2pStateAbort_REQING_CHANNEL(prAdapter, prP2pFsmInfo, eNextState);
1132             }
1133             else {
1134                 // Initial channel request.
1135                 p2pFuncAcquireCh(prAdapter, &(prP2pFsmInfo->rChnlReqInfo));
1136             }
1137
1138             break;
1139         case P2P_STATE_CHNL_ON_HAND:
1140             if (fgIsTransOut) {
1141                 p2pStateAbort_CHNL_ON_HAND(prAdapter, prP2pFsmInfo, prP2pBssInfo, eNextState);
1142             }
1143             else {
1144                 // Initial channel ready.
1145                     // Send channel ready event.
1146                     // Start a FSM timer.
1147                 p2pStateInit_CHNL_ON_HAND(prAdapter, prP2pBssInfo, prP2pFsmInfo);
1148             }
1149
1150             break;
1151         case P2P_STATE_GC_JOIN:
1152             if (fgIsTransOut) {
1153
1154                 // Join complete / join canceled.
1155                 p2pStateAbort_GC_JOIN(prAdapter,
1156                                         prP2pFsmInfo,
1157                                         &(prP2pFsmInfo->rJoinInfo),
1158                                         eNextState);
1159             }
1160             else {
1161                 ASSERT(prP2pFsmInfo->prTargetBss != NULL);
1162
1163                 // Send request to SAA module.
1164                 p2pStateInit_GC_JOIN(prAdapter,
1165                                         prP2pFsmInfo,
1166                                         prP2pBssInfo,
1167                                         &(prP2pFsmInfo->rJoinInfo),
1168                                         prP2pFsmInfo->prTargetBss);
1169             }
1170
1171             break;
1172         default:
1173             break;
1174         }
1175
1176     } while (fgIsTransOut);
1177
1178 } /* p2pFsmStateTransition */
1179
1180
1181 VOID
1182 p2pFsmRunEventSwitchOPMode (
1183     IN P_ADAPTER_T prAdapter,
1184     IN P_MSG_HDR_T prMsgHdr
1185     )
1186 {
1187     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1188     P_MSG_P2P_SWITCH_OP_MODE_T prSwitchOpMode = (P_MSG_P2P_SWITCH_OP_MODE_T)prMsgHdr;
1189     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
1190
1191     do {
1192         ASSERT_BREAK((prAdapter != NULL) && (prSwitchOpMode != NULL));
1193
1194         DBGLOG(P2P, TRACE, ("p2pFsmRunEventSwitchOPMode\n"));
1195
1196         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1197         prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
1198
1199         if (prSwitchOpMode->eOpMode >= OP_MODE_NUM) {
1200             ASSERT(FALSE);
1201             break;
1202         }
1203
1204         /* P2P Device / GC. */
1205         p2pFuncSwitchOPMode(prAdapter,
1206                                     prP2pBssInfo,
1207                                     prSwitchOpMode->eOpMode,
1208                                     TRUE);
1209
1210     } while (FALSE);
1211
1212     if (prMsgHdr) {
1213         cnmMemFree(prAdapter, prMsgHdr);
1214     }
1215
1216
1217 } /* p2pFsmRunEventSwitchOPMode */
1218
1219
1220 /*----------------------------------------------------------------------------*/
1221 /*!
1222 * \brief    This function is used to handle scan done event during Device Discovery.
1223 *
1224 * \param[in] prAdapter  Pointer of ADAPTER_T
1225 *
1226 * \return none
1227 */
1228 /*----------------------------------------------------------------------------*/
1229 VOID
1230 p2pFsmRunEventScanDone (
1231     IN P_ADAPTER_T prAdapter,
1232     IN P_MSG_HDR_T prMsgHdr
1233     )
1234 {
1235     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1236     P_P2P_SCAN_REQ_INFO_T prScanReqInfo = (P_P2P_SCAN_REQ_INFO_T)NULL;
1237     P_MSG_SCN_SCAN_DONE prScanDoneMsg = (P_MSG_SCN_SCAN_DONE)NULL;
1238     ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1239
1240     do {
1241         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1242
1243
1244         /* This scan done event is either for "SCAN" phase or "SEARCH" state or "LISTEN" state.
1245           * The scan done for SCAN phase & SEARCH state doesn't imply Device
1246           * Discovery over.
1247           */
1248         DBGLOG(P2P, TRACE, ("P2P Scan Done Event\n"));
1249
1250         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1251
1252         if (prP2pFsmInfo == NULL) {
1253             break;
1254         }
1255
1256
1257         prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1258         prScanDoneMsg = (P_MSG_SCN_SCAN_DONE)prMsgHdr;
1259
1260         if (prScanDoneMsg->ucSeqNum != prScanReqInfo->ucSeqNumOfScnMsg) {
1261             /* Scan Done message sequence number mismatch.
1262               * Ignore this event. (P2P FSM issue two scan events.)
1263               */
1264             /* The scan request has been cancelled.
1265               * Ignore this message. It is possible.
1266               */
1267             DBGLOG(P2P, TRACE, ("P2P Scan Don SeqNum:%d <-> P2P Fsm SCAN Msg:%d\n",
1268                             prScanDoneMsg->ucSeqNum,
1269                             prScanReqInfo->ucSeqNumOfScnMsg));
1270
1271             break;
1272         }
1273
1274
1275         switch (prP2pFsmInfo->eCurrentState) {
1276         case P2P_STATE_SCAN:
1277             {
1278                 P_P2P_CONNECTION_REQ_INFO_T prConnReqInfo = &(prP2pFsmInfo->rConnReqInfo);
1279
1280                 prScanReqInfo->fgIsAbort = FALSE;
1281
1282                 if (prConnReqInfo->fgIsConnRequest) {
1283
1284                     if ((prP2pFsmInfo->prTargetBss = p2pFuncKeepOnConnection(prAdapter,
1285                                                                                                     &prP2pFsmInfo->rConnReqInfo,
1286                                                                                                     &prP2pFsmInfo->rChnlReqInfo,
1287                                                                                                     &prP2pFsmInfo->rScanReqInfo)) == NULL) {
1288                         eNextState = P2P_STATE_SCAN;
1289                     }
1290                     else {
1291                         eNextState = P2P_STATE_REQING_CHANNEL;
1292                     }
1293
1294                 }
1295                 else {
1296                     eNextState = P2P_STATE_IDLE;
1297                 }
1298
1299             }
1300             break;
1301         case P2P_STATE_AP_CHANNEL_DETECT:
1302             eNextState = P2P_STATE_REQING_CHANNEL;
1303             break;
1304         default:
1305             /* Unexpected channel scan done event without being chanceled. */
1306             ASSERT(FALSE);
1307             break;
1308         }
1309
1310         prScanReqInfo->fgIsScanRequest = FALSE;
1311
1312         p2pFsmStateTransition(prAdapter,
1313                         prP2pFsmInfo,
1314                         eNextState);
1315
1316     } while (FALSE);
1317
1318     if (prMsgHdr) {
1319         cnmMemFree(prAdapter, prMsgHdr);
1320     }
1321
1322     return;
1323 } /* p2pFsmRunEventScanDone */
1324
1325
1326
1327 /*----------------------------------------------------------------------------*/
1328 /*!
1329 * \brief    This function is call when channel is granted by CNM module from FW.
1330 *
1331 * \param[in] prAdapter  Pointer of ADAPTER_T
1332 *
1333 * \return none
1334 */
1335 /*----------------------------------------------------------------------------*/
1336 VOID
1337 p2pFsmRunEventChGrant (
1338     IN P_ADAPTER_T prAdapter,
1339     IN P_MSG_HDR_T prMsgHdr
1340     )
1341 {
1342     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1343     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1344     P_MSG_CH_GRANT_T prMsgChGrant = (P_MSG_CH_GRANT_T)NULL;
1345     UINT_8 ucTokenID = 0;
1346
1347     do {
1348         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1349
1350         DBGLOG(P2P, TRACE, ("P2P Run Event Channel Grant\n"));
1351
1352         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1353
1354         if (prP2pFsmInfo == NULL) {
1355             break;
1356         }
1357         
1358         prMsgChGrant = (P_MSG_CH_GRANT_T)prMsgHdr;
1359         ucTokenID = prMsgChGrant->ucTokenID;
1360         prP2pFsmInfo->u4GrantInterval = prMsgChGrant->u4GrantInterval;
1361
1362         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1363
1364         if (ucTokenID == prChnlReqInfo->ucSeqNumOfChReq) {
1365             ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1366
1367             switch (prP2pFsmInfo->eCurrentState) {
1368             case P2P_STATE_REQING_CHANNEL:
1369                 switch (prChnlReqInfo->eChannelReqType) {
1370                 case CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL:
1371                     eNextState = P2P_STATE_CHNL_ON_HAND;
1372                     break;
1373                 case CHANNEL_REQ_TYPE_GC_JOIN_REQ:
1374                     eNextState = P2P_STATE_GC_JOIN;
1375                     break;
1376                 case CHANNEL_REQ_TYPE_GO_START_BSS:
1377                     eNextState = P2P_STATE_IDLE;
1378                     break;
1379                 default:
1380                     break;
1381                 }
1382
1383                 p2pFsmStateTransition(prAdapter,
1384                                 prP2pFsmInfo,
1385                                 eNextState);
1386                 break;
1387             default:
1388                 /* Channel is granted under unexpected state.
1389                   * Driver should cancel channel privileagea before leaving the states.
1390                   */
1391                 ASSERT(FALSE);
1392                 break;
1393             }
1394
1395         }
1396         else {
1397             /* Channel requsted, but released. */
1398             //ASSERT(!prChnlReqInfo->fgIsChannelRequested);
1399             DBGLOG(P2P, TRACE, ("Channel requsted, but released\n"));
1400         }
1401     } while (FALSE);
1402
1403     if (prMsgHdr) {
1404         cnmMemFree(prAdapter, prMsgHdr);
1405     }
1406
1407     return;
1408
1409 } /* p2pFsmRunEventChGrant */
1410
1411
1412 VOID
1413 p2pFsmRunEventChannelRequest (
1414     IN P_ADAPTER_T prAdapter,
1415     IN P_MSG_HDR_T prMsgHdr
1416     )
1417 {
1418     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1419     P_MSG_P2P_CHNL_REQUEST_T prP2pChnlReqMsg = (P_MSG_P2P_CHNL_REQUEST_T)NULL;
1420     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1421     ENUM_P2P_STATE_T eNextState = P2P_STATE_NUM;
1422
1423     do {
1424         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1425
1426         prP2pChnlReqMsg = (P_MSG_P2P_CHNL_REQUEST_T)prMsgHdr;
1427         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1428
1429         if (prP2pFsmInfo == NULL) {
1430             break;
1431         }
1432         
1433         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1434
1435         DBGLOG(P2P, TRACE, ("p2pFsmRunEventChannelRequest\n"));
1436
1437         /* Special case of time renewing for same frequency. */
1438         if ((prP2pFsmInfo->eCurrentState == P2P_STATE_CHNL_ON_HAND) &&
1439                 (prChnlReqInfo->ucReqChnlNum == prP2pChnlReqMsg->rChannelInfo.ucChannelNum) &&
1440                 (prChnlReqInfo->eBand == prP2pChnlReqMsg->rChannelInfo.eBand) &&
1441                 (prChnlReqInfo->eChnlSco == prP2pChnlReqMsg->eChnlSco)) {
1442
1443             ASSERT(prChnlReqInfo->fgIsChannelRequested == TRUE);
1444             ASSERT(prChnlReqInfo->eChannelReqType == CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL);
1445
1446             prChnlReqInfo->u8Cookie = prP2pChnlReqMsg->u8Cookie;
1447             prChnlReqInfo->u4MaxInterval = prP2pChnlReqMsg->u4Duration;
1448
1449             /* Re-enter the state. */
1450             eNextState = P2P_STATE_CHNL_ON_HAND;
1451         }
1452         else {
1453
1454             // Make sure the state is in IDLE state.
1455             p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1456
1457             prChnlReqInfo->u8Cookie = prP2pChnlReqMsg->u8Cookie;  /* Cookie can only be assign after abort.(for indication) */
1458             prChnlReqInfo->ucReqChnlNum = prP2pChnlReqMsg->rChannelInfo.ucChannelNum;
1459             prChnlReqInfo->eBand = prP2pChnlReqMsg->rChannelInfo.eBand;
1460             prChnlReqInfo->eChnlSco = prP2pChnlReqMsg->eChnlSco;
1461             prChnlReqInfo->u4MaxInterval = prP2pChnlReqMsg->u4Duration;
1462             prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_REMAIN_ON_CHANNEL;
1463
1464             eNextState = P2P_STATE_REQING_CHANNEL;
1465         }
1466
1467         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, eNextState);
1468
1469     } while (FALSE);
1470
1471
1472     if (prMsgHdr) {
1473         cnmMemFree(prAdapter, prMsgHdr);
1474     }
1475
1476     return;
1477 } /* p2pFsmRunEventChannelRequest */
1478
1479
1480 VOID
1481 p2pFsmRunEventChannelAbort (
1482     IN P_ADAPTER_T prAdapter,
1483     IN P_MSG_HDR_T prMsgHdr
1484     )
1485 {
1486     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1487     P_MSG_P2P_CHNL_ABORT_T prChnlAbortMsg = (P_MSG_P2P_CHNL_ABORT_T)NULL;
1488     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
1489
1490     do {
1491         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1492
1493         prChnlAbortMsg = (P_MSG_P2P_CHNL_ABORT_T)prMsgHdr;
1494         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1495         
1496         if (prP2pFsmInfo == NULL) {
1497             break;
1498         }
1499
1500         prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1501
1502         DBGLOG(P2P, TRACE, ("p2pFsmRunEventChannelAbort\n"));
1503
1504         if ((prChnlAbortMsg->u8Cookie == prChnlReqInfo->u8Cookie) &&
1505                 (prChnlReqInfo->fgIsChannelRequested)) {
1506
1507             ASSERT((prP2pFsmInfo->eCurrentState == P2P_STATE_REQING_CHANNEL ||
1508                             (prP2pFsmInfo->eCurrentState == P2P_STATE_CHNL_ON_HAND)));
1509
1510             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1511         }
1512
1513     } while (FALSE);
1514
1515     if (prMsgHdr) {
1516         cnmMemFree(prAdapter, prMsgHdr);
1517     }
1518
1519     return;
1520 } /* p2pFsmRunEventChannelAbort */
1521
1522
1523
1524 VOID
1525 p2pFsmRunEventScanRequest (
1526     IN P_ADAPTER_T prAdapter,
1527     IN P_MSG_HDR_T prMsgHdr
1528     )
1529 {
1530
1531     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1532     P_MSG_P2P_SCAN_REQUEST_T prP2pScanReqMsg = (P_MSG_P2P_SCAN_REQUEST_T)NULL;
1533     P_P2P_SCAN_REQ_INFO_T prScanReqInfo = (P_P2P_SCAN_REQ_INFO_T)NULL;
1534     UINT_32 u4ChnlListSize = 0;
1535
1536     do {
1537         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1538
1539         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1540
1541         if (prP2pFsmInfo == NULL) {
1542             break;
1543         }
1544         
1545         prP2pScanReqMsg = (P_MSG_P2P_SCAN_REQUEST_T)prMsgHdr;
1546         prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1547
1548         DBGLOG(P2P, TRACE, ("p2pFsmRunEventScanRequest\n"));
1549
1550         // Make sure the state is in IDLE state.
1551         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1552
1553         ASSERT(prScanReqInfo->fgIsScanRequest == FALSE);
1554
1555         prScanReqInfo->fgIsAbort = TRUE;
1556         prScanReqInfo->eScanType = SCAN_TYPE_ACTIVE_SCAN;
1557         prScanReqInfo->eChannelSet = SCAN_CHANNEL_SPECIFIED;
1558
1559         // Channel List
1560         prScanReqInfo->ucNumChannelList = prP2pScanReqMsg->u4NumChannel;
1561         DBGLOG(P2P, TRACE, ("Scan Request Channel List Number: %d\n", prScanReqInfo->ucNumChannelList));
1562         if (prScanReqInfo->ucNumChannelList > MAXIMUM_OPERATION_CHANNEL_LIST) {
1563             DBGLOG(P2P, TRACE, ("Channel List Number Overloaded: %d, change to: %d\n",
1564                                                                                     prScanReqInfo->ucNumChannelList,
1565                                                                                     MAXIMUM_OPERATION_CHANNEL_LIST));
1566             prScanReqInfo->ucNumChannelList = MAXIMUM_OPERATION_CHANNEL_LIST;
1567         }
1568
1569         u4ChnlListSize = sizeof(RF_CHANNEL_INFO_T) * prScanReqInfo->ucNumChannelList;
1570         kalMemCopy(prScanReqInfo->arScanChannelList, prP2pScanReqMsg->arChannelListInfo, u4ChnlListSize);
1571
1572         // TODO: I only take the first SSID. Multiple SSID may be needed in the future.
1573         // SSID
1574         if (prP2pScanReqMsg->i4SsidNum >= 1) {
1575
1576             kalMemCopy(&(prScanReqInfo->rSsidStruct),
1577                                 prP2pScanReqMsg->prSSID,
1578                                 sizeof(P2P_SSID_STRUCT_T));
1579         }
1580         else {
1581             prScanReqInfo->rSsidStruct.ucSsidLen = 0;
1582         }
1583
1584         // IE Buffer
1585         kalMemCopy(prScanReqInfo->aucIEBuf,
1586                             prP2pScanReqMsg->pucIEBuf,
1587                             prP2pScanReqMsg->u4IELen);
1588
1589         prScanReqInfo->u4BufLength = prP2pScanReqMsg->u4IELen;
1590
1591         p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN);
1592
1593
1594
1595     } while (FALSE);
1596
1597     if (prMsgHdr) {
1598         cnmMemFree(prAdapter, prMsgHdr);
1599     }
1600
1601
1602 } /* p2pFsmRunEventScanRequest */
1603
1604
1605 VOID
1606 p2pFsmRunEventScanAbort (
1607     IN P_ADAPTER_T prAdapter,
1608     IN P_MSG_HDR_T prMsgHdr
1609     )
1610 {
1611
1612     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1613
1614     do {
1615         ASSERT_BREAK(prAdapter != NULL);
1616
1617         DBGLOG(P2P, TRACE, ("p2pFsmRunEventScanAbort\n"));
1618
1619         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1620
1621         if (prP2pFsmInfo->eCurrentState == P2P_STATE_SCAN) {
1622             P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1623
1624             prScanReqInfo->fgIsAbort = TRUE;
1625
1626             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1627         }
1628
1629     } while (FALSE);
1630
1631     if (prMsgHdr) {
1632         cnmMemFree(prAdapter, prMsgHdr);
1633     }
1634
1635     return;
1636 } /* p2pFsmRunEventScanAbort */
1637
1638
1639
1640
1641
1642 VOID
1643 p2pFsmRunEventAbort (
1644     IN P_ADAPTER_T prAdapter,
1645     IN P_P2P_FSM_INFO_T prP2pFsmInfo
1646     )
1647 {
1648     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1649     do {
1650         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1651
1652         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1653
1654         DBGLOG(P2P, TRACE, ("p2pFsmRunEventAbort\n"));
1655
1656         if (prP2pFsmInfo->eCurrentState != P2P_STATE_IDLE) {
1657
1658             if (prP2pFsmInfo->eCurrentState == P2P_STATE_SCAN) {
1659
1660                 P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
1661
1662                 prScanReqInfo->fgIsAbort = TRUE;
1663             }
1664             else if (prP2pFsmInfo->eCurrentState == P2P_STATE_REQING_CHANNEL) {
1665                 /* 2012/08/06: frog 
1666                               * Prevent Start GO.
1667                               */
1668                 prP2pBssInfo->eIntendOPMode = OP_MODE_NUM;
1669             }
1670
1671             // For other state, is there any special action that should be take before leaving?
1672
1673             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1674         }
1675         else {
1676             /* P2P State IDLE. */
1677             P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1678
1679             if (prChnlReqInfo->fgIsChannelRequested) {
1680                 p2pFuncReleaseCh(prAdapter, prChnlReqInfo);
1681             }
1682
1683             cnmTimerStopTimer(prAdapter, &(prP2pFsmInfo->rP2pFsmTimeoutTimer));
1684         }
1685
1686
1687     } while (FALSE);
1688
1689     return;
1690 } /* p2pFsmRunEventAbort */
1691
1692
1693
1694 /*----------------------------------------------------------------------------*/
1695 /*!
1696 * \brief    This function is used to handle FSM Timeout.
1697 *
1698 * \param[in] prAdapter  Pointer of ADAPTER_T
1699 *
1700 * \return none
1701 */
1702 /*----------------------------------------------------------------------------*/
1703 VOID
1704 p2pFsmRunEventFsmTimeout (
1705     IN P_ADAPTER_T prAdapter,
1706     IN UINT_32 u4Param
1707     )
1708 {
1709     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)u4Param;
1710
1711     do {
1712         ASSERT_BREAK((prAdapter != NULL) && (prP2pFsmInfo != NULL));
1713
1714         DBGLOG(P2P, TRACE, ("P2P FSM Timeout Event\n"));
1715
1716         switch (prP2pFsmInfo->eCurrentState) {
1717         case P2P_STATE_IDLE:
1718             {
1719                 P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1720                 if (prChnlReqInfo->fgIsChannelRequested) {
1721                     p2pFuncReleaseCh(prAdapter, prChnlReqInfo);
1722                 }
1723                 else if (IS_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX)) {
1724                     UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1725                     nicDeactivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1726                 }
1727
1728             }
1729             break;
1730
1731 //        case P2P_STATE_SCAN:
1732 //            break;
1733 //        case P2P_STATE_AP_CHANNEL_DETECT:
1734 //            break;
1735 //        case P2P_STATE_REQING_CHANNEL:
1736 //            break;
1737         case P2P_STATE_CHNL_ON_HAND:
1738             {
1739                 p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
1740             }
1741             break;
1742 //        case P2P_STATE_GC_JOIN:
1743 //            break;
1744         default:
1745             break;
1746         }
1747
1748     } while (FALSE);
1749
1750     return;
1751 } /* p2pFsmRunEventFsmTimeout */
1752
1753 VOID
1754 p2pFsmRunEventMgmtFrameTx (
1755     IN P_ADAPTER_T prAdapter,
1756     IN P_MSG_HDR_T prMsgHdr
1757     )
1758 {
1759     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1760     P_MSG_P2P_MGMT_TX_REQUEST_T prMgmtTxMsg = (P_MSG_P2P_MGMT_TX_REQUEST_T)NULL;
1761
1762     do {
1763         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1764
1765         DBGLOG(P2P, TRACE, ("p2pFsmRunEventMgmtFrameTx\n"));
1766
1767         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1768
1769         if (prP2pFsmInfo == NULL) {
1770             break;
1771         }
1772         
1773         prMgmtTxMsg = (P_MSG_P2P_MGMT_TX_REQUEST_T)prMsgHdr;
1774
1775         p2pFuncTxMgmtFrame(prAdapter,
1776                         &prP2pFsmInfo->rMgmtTxInfo,
1777                         prMgmtTxMsg->prMgmtMsduInfo,
1778                         prMgmtTxMsg->u8Cookie);
1779
1780
1781
1782     } while (FALSE);
1783
1784     if (prMsgHdr) {
1785         cnmMemFree(prAdapter, prMsgHdr);
1786     }
1787
1788     return;
1789
1790 } /* p2pFsmRunEventMgmtTx */
1791
1792
1793 VOID
1794 p2pFsmRunEventStartAP (
1795     IN P_ADAPTER_T prAdapter,
1796     IN P_MSG_HDR_T prMsgHdr
1797     )
1798 {
1799     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1800     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
1801     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
1802     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
1803
1804     do {
1805         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1806
1807         DBGLOG(P2P, TRACE, ("p2pFsmRunEventStartAP\n"));
1808
1809         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1810
1811         if (prP2pFsmInfo == NULL) {
1812             break;
1813         }
1814         
1815         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
1816         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)prMsgHdr;
1817         prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1818
1819
1820         if (prP2pStartAPMsg->u4BcnInterval) {
1821             DBGLOG(P2P, TRACE, ("Beacon interval updated to :%ld \n", prP2pStartAPMsg->u4BcnInterval));
1822             prP2pBssInfo->u2BeaconInterval = (UINT_16)prP2pStartAPMsg->u4BcnInterval;
1823         }
1824         else if (prP2pBssInfo->u2BeaconInterval == 0)  {
1825             prP2pBssInfo->u2BeaconInterval = DOT11_BEACON_PERIOD_DEFAULT;
1826         }
1827         
1828         if (prP2pStartAPMsg->u4DtimPeriod) {
1829             DBGLOG(P2P, TRACE, ("DTIM interval updated to :%ld \n", prP2pStartAPMsg->u4DtimPeriod));
1830             prP2pBssInfo->ucDTIMPeriod = (UINT_8)prP2pStartAPMsg->u4DtimPeriod;
1831         }
1832         else if (prP2pBssInfo->ucDTIMPeriod == 0) {
1833             prP2pBssInfo->ucDTIMPeriod = DOT11_DTIM_PERIOD_DEFAULT;
1834         }
1835
1836         if (prP2pStartAPMsg->u2SsidLen != 0) {
1837             kalMemCopy(prP2pBssInfo->aucSSID, prP2pStartAPMsg->aucSsid, prP2pStartAPMsg->u2SsidLen);
1838             kalMemCopy(prP2pSpecificBssInfo->aucGroupSsid, prP2pStartAPMsg->aucSsid, prP2pStartAPMsg->u2SsidLen);
1839             prP2pBssInfo->ucSSIDLen = prP2pSpecificBssInfo->u2GroupSsidLen = prP2pStartAPMsg->u2SsidLen;
1840         }
1841
1842
1843         prP2pBssInfo->eHiddenSsidType = prP2pStartAPMsg->ucHiddenSsidType;
1844         
1845
1846         // TODO: JB
1847         /* Privacy & inactive timeout. */
1848
1849         if ((prP2pBssInfo->eCurrentOPMode != OP_MODE_ACCESS_POINT) ||
1850                 (prP2pBssInfo->eIntendOPMode != OP_MODE_NUM)) {
1851             UINT_8 ucPreferedChnl = 0;
1852             ENUM_BAND_T eBand = BAND_NULL;
1853             ENUM_CHNL_EXT_T eSco = CHNL_EXT_SCN;
1854             ENUM_P2P_STATE_T eNextState = P2P_STATE_SCAN;
1855             P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
1856
1857
1858             if(prP2pFsmInfo->eCurrentState != P2P_STATE_SCAN &&
1859                prP2pFsmInfo->eCurrentState != P2P_STATE_IDLE) {
1860                 // Make sure the state is in IDLE state.
1861                 p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
1862             }
1863
1864             // 20120118: Moved to p2pFuncSwitchOPMode().
1865             //SET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1866
1867             /* Leave IDLE state. */
1868             SET_NET_PWR_STATE_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
1869
1870             // sync with firmware
1871             //DBGLOG(P2P, INFO, ("Activate P2P Network. \n"));
1872             //nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
1873
1874
1875             /* Key to trigger P2P FSM to allocate channel for AP mode. */
1876             prP2pBssInfo->eIntendOPMode = OP_MODE_ACCESS_POINT;
1877
1878             /* Sparse Channel to decide which channel to use. */
1879             if ((cnmPreferredChannel(prAdapter,
1880                                             &eBand,
1881                                             &ucPreferedChnl,
1882                                             &eSco) == FALSE) && (prP2pConnSettings->ucOperatingChnl == 0)) {
1883                 // Sparse Channel Detection using passive mode.
1884                 eNextState = P2P_STATE_AP_CHANNEL_DETECT;
1885             }
1886             else {
1887                 P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
1888                 P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &prP2pFsmInfo->rChnlReqInfo;
1889
1890
1891 #if 1
1892                 /* 2012-01-27: frog - Channel set from upper layer is the first priority. */
1893                 /* Becuase the channel & beacon is decided by p2p_supplicant. */
1894                 if (prP2pConnSettings->ucOperatingChnl != 0) {
1895                     prP2pSpecificBssInfo->ucPreferredChannel = prP2pConnSettings->ucOperatingChnl;
1896                     prP2pSpecificBssInfo->eRfBand = prP2pConnSettings->eBand;
1897                 }
1898                 
1899                 else {
1900                     ASSERT(ucPreferedChnl != 0);
1901                     prP2pSpecificBssInfo->ucPreferredChannel = ucPreferedChnl;
1902                     prP2pSpecificBssInfo->eRfBand = eBand;
1903                 }
1904 #else
1905                 if (ucPreferedChnl) {
1906                     prP2pSpecificBssInfo->ucPreferredChannel = ucPreferedChnl;
1907                     prP2pSpecificBssInfo->eRfBand = eBand;
1908                 }
1909                 else {
1910                     ASSERT(prP2pConnSettings->ucOperatingChnl != 0);
1911                     prP2pSpecificBssInfo->ucPreferredChannel = prP2pConnSettings->ucOperatingChnl;
1912                     prP2pSpecificBssInfo->eRfBand = prP2pConnSettings->eBand;
1913                 }
1914
1915 #endif
1916                 prChnlReqInfo->ucReqChnlNum = prP2pSpecificBssInfo->ucPreferredChannel;
1917                 prChnlReqInfo->eBand = prP2pSpecificBssInfo->eRfBand;
1918                 prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_GO_START_BSS;
1919             }
1920             
1921             /* If channel is specified, use active scan to shorten the scan time. */
1922             p2pFsmStateTransition(prAdapter,
1923                                         prAdapter->rWifiVar.prP2pFsmInfo,
1924                                         eNextState);
1925         }
1926
1927
1928         
1929     } while (FALSE);
1930
1931
1932
1933     if (prMsgHdr) {
1934         cnmMemFree(prAdapter, prMsgHdr);
1935     }
1936     
1937     return;
1938 } /* p2pFsmRunEventStartAP */
1939
1940 VOID
1941 p2pFsmRunEventNetDeviceRegister (
1942     IN P_ADAPTER_T prAdapter,
1943     IN P_MSG_HDR_T prMsgHdr
1944     )
1945 {
1946     P_MSG_P2P_NETDEV_REGISTER_T prNetDevRegisterMsg = (P_MSG_P2P_NETDEV_REGISTER_T)NULL;
1947
1948
1949     do {
1950
1951         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1952
1953         DBGLOG(P2P, TRACE, ("p2pFsmRunEventNetDeviceRegister\n"));
1954
1955         prNetDevRegisterMsg = (P_MSG_P2P_NETDEV_REGISTER_T)prMsgHdr;
1956         
1957          if (prNetDevRegisterMsg->fgIsEnable) {
1958             p2pSetMode((prNetDevRegisterMsg->ucMode == 1)?TRUE:FALSE);
1959
1960             if (p2pLaunch(prAdapter->prGlueInfo)) {
1961                 ASSERT(prAdapter->fgIsP2PRegistered);
1962             }
1963
1964         }
1965         else {
1966             if (prAdapter->fgIsP2PRegistered) {
1967                 p2pRemove(prAdapter->prGlueInfo);
1968             }
1969
1970         }
1971     } while (FALSE);
1972     
1973     if (prMsgHdr) {
1974         cnmMemFree(prAdapter, prMsgHdr);
1975     }
1976
1977     return;
1978 } /* p2pFsmRunEventNetDeviceRegister */
1979
1980
1981 VOID
1982 p2pFsmRunEventUpdateMgmtFrame (
1983     IN P_ADAPTER_T prAdapter,
1984     IN P_MSG_HDR_T prMsgHdr
1985     )
1986 {
1987     P_MSG_P2P_MGMT_FRAME_UPDATE_T prP2pMgmtFrameUpdateMsg = (P_MSG_P2P_MGMT_FRAME_UPDATE_T)NULL;
1988     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1989
1990     do {
1991         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
1992
1993         DBGLOG(P2P, TRACE, ("p2pFsmRunEventUpdateMgmtFrame\n"));
1994
1995         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
1996
1997         if (prP2pFsmInfo == NULL) {
1998             break;
1999         }
2000         
2001         prP2pMgmtFrameUpdateMsg = (P_MSG_P2P_MGMT_FRAME_UPDATE_T)prMsgHdr;
2002
2003         switch (prP2pMgmtFrameUpdateMsg->eBufferType) {
2004         case ENUM_FRAME_TYPE_EXTRA_IE_BEACON:
2005             break;
2006         case ENUM_FRAME_TYPE_EXTRA_IE_ASSOC_RSP:
2007             break;
2008         case ENUM_FRAME_TYPE_EXTRA_IE_PROBE_RSP:
2009             break;
2010         case ENUM_FRAME_TYPE_PROBE_RSP_TEMPLATE:
2011             break;
2012         case ENUM_FRAME_TYPE_BEACON_TEMPLATE:
2013             break;
2014         default:
2015             break;
2016         }
2017         
2018     } while (FALSE);
2019
2020     if (prMsgHdr) {
2021         cnmMemFree(prAdapter, prMsgHdr);
2022     }
2023
2024     return;
2025 } /* p2pFsmRunEventUpdateMgmtFrame */
2026
2027
2028 VOID
2029 p2pFsmRunEventBeaconUpdate (
2030     IN P_ADAPTER_T prAdapter,
2031     IN P_MSG_HDR_T prMsgHdr
2032     )
2033 {
2034     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2035     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2036     P_MSG_P2P_BEACON_UPDATE_T prBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
2037
2038     do {
2039         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2040
2041         DBGLOG(P2P, TRACE, ("p2pFsmRunEventBeaconUpdate\n"));
2042
2043                 printk("p2pFsmRunEventBeaconUpdate\n");
2044
2045         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2046
2047         if (prP2pFsmInfo == NULL) {
2048             break;
2049         }
2050         
2051         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2052         prBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)prMsgHdr;
2053
2054         
2055         p2pFuncBeaconUpdate(prAdapter,
2056                         prP2pBssInfo,
2057                         &prP2pFsmInfo->rBcnContentInfo,
2058                         prBcnUpdateMsg->pucBcnHdr,
2059                         prBcnUpdateMsg->u4BcnHdrLen,
2060                         prBcnUpdateMsg->pucBcnBody,
2061                         prBcnUpdateMsg->u4BcnBodyLen);
2062
2063         if ((prP2pBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) &&
2064                 (prP2pBssInfo->eIntendOPMode == OP_MODE_NUM)) {
2065             /* AP is created, Beacon Update. */
2066             //nicPmIndicateBssAbort(prAdapter, NETWORK_TYPE_P2P_INDEX);
2067
2068             bssUpdateBeaconContent(prAdapter, NETWORK_TYPE_P2P_INDEX);
2069
2070             //nicPmIndicateBssCreated(prAdapter, NETWORK_TYPE_P2P_INDEX);
2071         }
2072         
2073
2074
2075     } while (FALSE);
2076
2077
2078     if (prMsgHdr) {
2079         cnmMemFree(prAdapter, prMsgHdr);
2080     }
2081
2082 } /* p2pFsmRunEventBeaconUpdate */
2083
2084
2085 VOID
2086 p2pFsmRunEventStopAP (
2087     IN P_ADAPTER_T prAdapter,
2088     IN P_MSG_HDR_T prMsgHdr
2089     )
2090 {
2091     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2092
2093     do {
2094         ASSERT_BREAK((prAdapter != NULL));
2095
2096         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2097
2098         DBGLOG(P2P, TRACE, ("p2pFsmRunEventStopAP\n"));
2099
2100         if ((prP2pBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)
2101                 && (prP2pBssInfo->eIntendOPMode == OP_MODE_NUM)) {
2102             /* AP is created, Beacon Update. */
2103
2104             p2pFuncDissolve(prAdapter, prP2pBssInfo, TRUE, REASON_CODE_DEAUTH_LEAVING_BSS);
2105             
2106             DBGLOG(P2P, TRACE, ("Stop Beaconing\n"));
2107             nicPmIndicateBssAbort(prAdapter, NETWORK_TYPE_P2P_INDEX);
2108
2109             /* Reset RLM related field of BSSINFO. */
2110             rlmBssAborted(prAdapter, prP2pBssInfo);
2111         }
2112
2113         
2114
2115         // 20120118: Moved to p2pFuncSwitchOPMode().
2116         //UNSET_NET_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2117
2118         /* Enter IDLE state. */
2119         SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2120
2121         DBGLOG(P2P, INFO, ("Re activate P2P Network. \n"));
2122         nicDeactivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
2123
2124         nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX);
2125
2126 #if CFG_SUPPORT_WFD
2127         p2pFsmRunEventWfdSettingUpdate(prAdapter, NULL);
2128 #endif
2129
2130         p2pFsmRunEventAbort(prAdapter, prAdapter->rWifiVar.prP2pFsmInfo);
2131 //        p2pFsmStateTransition(prAdapter, prAdapter->rWifiVar.prP2pFsmInfo, P2P_STATE_IDLE);
2132
2133     } while (FALSE);
2134
2135     if (prMsgHdr) {
2136         cnmMemFree(prAdapter, prMsgHdr);
2137     }
2138
2139 } /* p2pFsmRunEventStopAP */
2140
2141 VOID
2142 p2pFsmRunEventConnectionRequest (
2143     IN P_ADAPTER_T prAdapter,
2144     IN P_MSG_HDR_T prMsgHdr
2145     )
2146 {
2147     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2148     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2149     P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = (P_P2P_CHNL_REQ_INFO_T)NULL;
2150     P_MSG_P2P_CONNECTION_REQUEST_T prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
2151     P_P2P_CONNECTION_REQ_INFO_T prConnReqInfo = (P_P2P_CONNECTION_REQ_INFO_T)NULL;
2152
2153     do {
2154         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2155
2156         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2157         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2158
2159         if (prP2pFsmInfo == NULL) {
2160             break;
2161         }
2162         
2163         prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)prMsgHdr;
2164
2165         prConnReqInfo = &(prP2pFsmInfo->rConnReqInfo);
2166         prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
2167
2168         DBGLOG(P2P, TRACE, ("p2pFsmRunEventConnectionRequest\n"));
2169
2170         if (prP2pBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE) {
2171             break;
2172         }
2173
2174         SET_NET_PWR_STATE_ACTIVE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2175
2176         
2177         // Make sure the state is in IDLE state.
2178         p2pFsmRunEventAbort(prAdapter, prP2pFsmInfo);
2179
2180         // Update connection request information.
2181         prConnReqInfo->fgIsConnRequest = TRUE;
2182         COPY_MAC_ADDR(prConnReqInfo->aucBssid, prConnReqMsg->aucBssid);
2183         kalMemCopy(&(prConnReqInfo->rSsidStruct), &(prConnReqMsg->rSsid), sizeof(P2P_SSID_STRUCT_T));
2184         kalMemCopy(prConnReqInfo->aucIEBuf, prConnReqMsg->aucIEBuf, prConnReqMsg->u4IELen);
2185         prConnReqInfo->u4BufLength = prConnReqMsg->u4IELen;
2186
2187         /* Find BSS Descriptor first. */
2188         prP2pFsmInfo->prTargetBss =  scanP2pSearchDesc(prAdapter,
2189                                                                         prP2pBssInfo,
2190                                                                         prConnReqInfo);
2191
2192         if (prP2pFsmInfo->prTargetBss == NULL) {
2193             /* Update scan parameter... to scan target device. */
2194             P_P2P_SCAN_REQ_INFO_T prScanReqInfo = &(prP2pFsmInfo->rScanReqInfo);
2195
2196             prScanReqInfo->ucNumChannelList = 1;
2197             prScanReqInfo->eScanType = SCAN_TYPE_ACTIVE_SCAN;
2198             prScanReqInfo->eChannelSet = SCAN_CHANNEL_SPECIFIED;
2199             prScanReqInfo->arScanChannelList[0].ucChannelNum = prConnReqMsg->rChannelInfo.ucChannelNum;
2200             kalMemCopy(&(prScanReqInfo->rSsidStruct), &(prConnReqMsg->rSsid), sizeof(P2P_SSID_STRUCT_T));
2201             prScanReqInfo->u4BufLength = 0;  /* Prevent other P2P ID in IE. */
2202             prScanReqInfo->fgIsAbort = TRUE;
2203
2204             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN);
2205         }
2206         else {
2207             prChnlReqInfo->u8Cookie = 0;
2208             prChnlReqInfo->ucReqChnlNum = prConnReqMsg->rChannelInfo.ucChannelNum;
2209             prChnlReqInfo->eBand = prConnReqMsg->rChannelInfo.eBand;
2210             prChnlReqInfo->eChnlSco = prConnReqMsg->eChnlSco;
2211             prChnlReqInfo->u4MaxInterval = AIS_JOIN_CH_REQUEST_INTERVAL;
2212             prChnlReqInfo->eChannelReqType = CHANNEL_REQ_TYPE_GC_JOIN_REQ;
2213
2214             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_REQING_CHANNEL);
2215         }
2216
2217
2218     } while (FALSE);
2219
2220     if (prMsgHdr) {
2221         cnmMemFree(prAdapter, prMsgHdr);
2222     }
2223
2224     return;
2225
2226 } /* p2pFsmRunEventConnectionRequest */
2227
2228 /*----------------------------------------------------------------------------*/
2229 /*!
2230 * \brief    This function is used to handle Connection Request from Supplicant.
2231 *
2232 * \param[in] prAdapter  Pointer of ADAPTER_T
2233 *
2234 * \return none
2235 */
2236 /*----------------------------------------------------------------------------*/
2237 VOID
2238 p2pFsmRunEventConnectionAbort (
2239     IN P_ADAPTER_T prAdapter,
2240     IN P_MSG_HDR_T prMsgHdr
2241     )
2242 {
2243     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2244     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2245     P_MSG_P2P_CONNECTION_ABORT_T prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
2246     //P_STA_RECORD_T prTargetStaRec = (P_STA_RECORD_T)NULL;
2247
2248     do {
2249
2250         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2251
2252         DBGLOG(P2P, TRACE, ("p2pFsmRunEventConnectionAbort: Connection Abort.\n"));
2253
2254         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2255
2256         if (prP2pFsmInfo == NULL) {
2257             break;
2258         }
2259         
2260         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2261
2262         prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)prMsgHdr;
2263
2264         switch (prP2pBssInfo->eCurrentOPMode) {
2265         case OP_MODE_INFRASTRUCTURE:
2266             {
2267                 UINT_8 aucBCBSSID[] = BC_BSSID;
2268                 
2269                 if (!prP2pBssInfo->prStaRecOfAP) {
2270                     DBGLOG(P2P, TRACE, ("GO's StaRec is NULL\n"));
2271                     break;
2272                 }
2273                 if (UNEQUAL_MAC_ADDR(prP2pBssInfo->prStaRecOfAP->aucMacAddr, prDisconnMsg->aucTargetID) &&
2274                     UNEQUAL_MAC_ADDR(prDisconnMsg->aucTargetID, aucBCBSSID)) {
2275                     DBGLOG(P2P, TRACE, ("Unequal MAC ADDR ["MACSTR":"MACSTR"]\n",
2276                         MAC2STR(prP2pBssInfo->prStaRecOfAP->aucMacAddr),
2277                         MAC2STR(prDisconnMsg->aucTargetID)));
2278                     break;
2279                 }
2280
2281                 
2282                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo, NULL, NULL, 0, 0);
2283
2284                 /* Stop rejoin timer if it is started. */
2285                 // TODO: If it has.
2286
2287                 p2pFuncDisconnect(prAdapter, prP2pBssInfo->prStaRecOfAP, prDisconnMsg->fgSendDeauth, prDisconnMsg->u2ReasonCode);
2288
2289                 //prTargetStaRec = prP2pBssInfo->prStaRecOfAP;
2290
2291                 /* Fix possible KE when RX Beacon & call nicPmIndicateBssConnected(). hit prStaRecOfAP == NULL. */
2292                 p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_DISCONNECTED);
2293
2294                 prP2pBssInfo->prStaRecOfAP = NULL;
2295
2296                 SET_NET_PWR_STATE_IDLE(prAdapter, NETWORK_TYPE_P2P_INDEX);
2297
2298                 p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2299
2300             }
2301             break;
2302         case OP_MODE_ACCESS_POINT:
2303             {
2304                 P_LINK_T prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2305                 /* Search specific client device, and disconnect. */
2306                 /* 1. Send deauthentication frame. */
2307                 /* 2. Indication: Device disconnect. */
2308                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2309                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2310
2311                 DBGLOG(P2P, TRACE, ("Disconnecting with Target ID: "MACSTR"\n", MAC2STR(prDisconnMsg->aucTargetID)));
2312
2313                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2314                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2315
2316                     ASSERT(prCurrStaRec);
2317
2318                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prDisconnMsg->aucTargetID)) {
2319
2320                         DBGLOG(P2P, TRACE, ("Disconnecting: "MACSTR"\n", MAC2STR(prCurrStaRec->aucMacAddr)));
2321
2322                         /* Remove STA from client list. */
2323                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2324
2325                         /* Glue layer indication. */
2326                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prCurrStaRec, FALSE);
2327
2328                         /* Send deauth & do indication. */
2329                         p2pFuncDisconnect(prAdapter, prCurrStaRec, prDisconnMsg->fgSendDeauth, prDisconnMsg->u2ReasonCode);
2330
2331                         //prTargetStaRec = prCurrStaRec;
2332
2333                         break;
2334                     }
2335                 }
2336
2337             }
2338             break;
2339         case OP_MODE_P2P_DEVICE:
2340         default:
2341             ASSERT(FALSE);
2342             break;
2343         }
2344
2345     } while (FALSE);
2346
2347     //20120830 moved into p2pFuncDisconnect()
2348     //if ((!prDisconnMsg->fgSendDeauth) && (prTargetStaRec)) {
2349     //    cnmStaRecFree(prAdapter, prTargetStaRec, TRUE);
2350     //}
2351
2352
2353     if (prMsgHdr) {
2354         cnmMemFree(prAdapter, prMsgHdr);
2355     }
2356
2357     return;
2358 } /* p2pFsmRunEventConnectionAbort */
2359
2360
2361 VOID
2362 p2pFsmRunEventDissolve (
2363     IN P_ADAPTER_T prAdapter,
2364     IN P_MSG_HDR_T prMsgHdr
2365     )
2366 {
2367
2368     // TODO:
2369
2370     DBGLOG(P2P, TRACE, ("p2pFsmRunEventDissolve\n"));
2371
2372     if (prMsgHdr) {
2373         cnmMemFree(prAdapter, prMsgHdr);
2374     }
2375
2376     return;
2377 }
2378 WLAN_STATUS
2379 p2pFsmRunEventDeauthTxDone (
2380     IN P_ADAPTER_T prAdapter,
2381     IN P_MSDU_INFO_T prMsduInfo,
2382     IN ENUM_TX_RESULT_CODE_T rTxDoneStatus
2383     )
2384 {
2385
2386     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
2387     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2388     ENUM_PARAM_MEDIA_STATE_T eOriMediaStatus;
2389
2390     do {
2391
2392         ASSERT_BREAK((prAdapter != NULL) &&
2393                                     (prMsduInfo != NULL));
2394
2395         DBGLOG(P2P, TRACE, ("Deauth TX Done\n"));
2396
2397         prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
2398
2399         if (prStaRec == NULL) {
2400             DBGLOG(P2P, TRACE, ("Station Record NULL, Index:%d\n", prMsduInfo->ucStaRecIndex));
2401             break;
2402         }
2403
2404         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2405         eOriMediaStatus = prP2pBssInfo->eConnectionState;
2406
2407
2408                 bssRemoveStaRecFromClientList(prAdapter, prP2pBssInfo, prStaRec);
2409
2410         /**/
2411         cnmStaRecFree(prAdapter, prStaRec, TRUE);
2412
2413         if ((prP2pBssInfo->eCurrentOPMode != OP_MODE_ACCESS_POINT) ||
2414                 (prP2pBssInfo->rStaRecOfClientList.u4NumElem == 0)) {
2415             DBGLOG(P2P, TRACE, ("No More Client, Media Status DISCONNECTED\n"));
2416             p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_DISCONNECTED);
2417         }
2418
2419         /* Because the eConnectionState is changed before Deauth TxDone. Dont Check eConnectionState */
2420         //if (eOriMediaStatus != prP2pBssInfo->eConnectionState) {
2421             /* Update Disconnected state to FW. */
2422             nicUpdateBss(prAdapter, NETWORK_TYPE_P2P_INDEX);
2423         //}
2424
2425
2426     } while (FALSE);
2427
2428     return WLAN_STATUS_SUCCESS;
2429 } /* p2pFsmRunEventDeauthTxDone */
2430
2431
2432 WLAN_STATUS
2433 p2pFsmRunEventMgmtFrameTxDone (
2434     IN P_ADAPTER_T prAdapter,
2435     IN P_MSDU_INFO_T prMsduInfo,
2436     IN ENUM_TX_RESULT_CODE_T rTxDoneStatus
2437     )
2438 {
2439     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2440     P_P2P_MGMT_TX_REQ_INFO_T prMgmtTxReqInfo = (P_P2P_MGMT_TX_REQ_INFO_T)NULL;
2441     BOOLEAN fgIsSuccess = FALSE;
2442
2443     do {
2444         ASSERT_BREAK((prAdapter != NULL) && (prMsduInfo != NULL));
2445
2446         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2447         prMgmtTxReqInfo = &(prP2pFsmInfo->rMgmtTxInfo);
2448
2449         if (rTxDoneStatus != TX_RESULT_SUCCESS) {
2450             DBGLOG(P2P, TRACE, ("Mgmt Frame TX Fail, Status:%d.\n", rTxDoneStatus));
2451         }
2452         else {
2453             fgIsSuccess = TRUE;
2454             DBGLOG(P2P, TRACE, ("Mgmt Frame TX Done.\n"));
2455         }
2456
2457
2458         if (prMgmtTxReqInfo->prMgmtTxMsdu == prMsduInfo) {
2459             kalP2PIndicateMgmtTxStatus(prAdapter->prGlueInfo,
2460                             prMgmtTxReqInfo->u8Cookie,
2461                             fgIsSuccess,
2462                             prMsduInfo->prPacket,
2463                             (UINT_32)prMsduInfo->u2FrameLength);
2464
2465             prMgmtTxReqInfo->prMgmtTxMsdu = NULL;
2466         }
2467
2468     } while (FALSE);
2469
2470     return WLAN_STATUS_SUCCESS;
2471
2472 } /* p2pFsmRunEventMgmtFrameTxDone */
2473
2474
2475 /*----------------------------------------------------------------------------*/
2476 /*!
2477 * \brief    This function is called when JOIN complete message event is received from SAA.
2478 *
2479 * \param[in] prAdapter  Pointer of ADAPTER_T
2480 *
2481 * \return none
2482 */
2483 /*----------------------------------------------------------------------------*/
2484 VOID
2485 p2pFsmRunEventJoinComplete (
2486     IN P_ADAPTER_T prAdapter,
2487     IN P_MSG_HDR_T prMsgHdr
2488     )
2489 {
2490     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2491     P_P2P_JOIN_INFO_T prJoinInfo = (P_P2P_JOIN_INFO_T)NULL;
2492     P_MSG_JOIN_COMP_T prJoinCompMsg = (P_MSG_JOIN_COMP_T)NULL;
2493     P_SW_RFB_T prAssocRspSwRfb = (P_SW_RFB_T)NULL;
2494     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2495
2496     do {
2497         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2498
2499         DBGLOG(P2P, TRACE, ("P2P Join Complete\n"));
2500
2501         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2502
2503         if (prP2pFsmInfo == NULL) {
2504             break;
2505         }
2506         
2507
2508         prJoinInfo = &(prP2pFsmInfo->rJoinInfo);
2509         prJoinCompMsg = (P_MSG_JOIN_COMP_T)prMsgHdr;
2510         prAssocRspSwRfb = prJoinCompMsg->prSwRfb;
2511         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2512
2513         if (prP2pBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) {
2514             P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
2515
2516             prStaRec = prJoinCompMsg->prStaRec;
2517
2518             /* Check SEQ NUM */
2519             if (prJoinCompMsg->ucSeqNum == prJoinInfo->ucSeqNumOfReqMsg) {
2520                 ASSERT(prStaRec == prJoinInfo->prTargetStaRec);
2521                 prJoinInfo->fgIsJoinComplete = TRUE;
2522
2523                 if (prJoinCompMsg->rJoinStatus == WLAN_STATUS_SUCCESS) {
2524
2525                     //4 <1.1> Change FW's Media State immediately.
2526                     p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_CONNECTED);
2527
2528                     //4 <1.2> Deactivate previous AP's STA_RECORD_T in Driver if have.
2529                     if ((prP2pBssInfo->prStaRecOfAP) &&
2530                             (prP2pBssInfo->prStaRecOfAP != prStaRec)) {
2531                         cnmStaRecChangeState(prAdapter, prP2pBssInfo->prStaRecOfAP, STA_STATE_1);
2532
2533                         cnmStaRecFree(prAdapter, prP2pBssInfo->prStaRecOfAP, TRUE);
2534
2535                         prP2pBssInfo->prStaRecOfAP = NULL;
2536                     }
2537
2538                     //4 <1.3> Update BSS_INFO_T
2539                     p2pFuncUpdateBssInfoForJOIN(prAdapter, prP2pFsmInfo->prTargetBss, prStaRec, prAssocRspSwRfb);
2540
2541                     //4 <1.4> Activate current AP's STA_RECORD_T in Driver.
2542                     cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
2543
2544 #if CFG_SUPPORT_P2P_RSSI_QUERY
2545                     //<1.5> Update RSSI if necessary
2546                     nicUpdateRSSI(prAdapter, NETWORK_TYPE_P2P_INDEX, (INT_8)(RCPI_TO_dBm(prStaRec->ucRCPI)), 0);
2547 #endif
2548
2549                     //4 <1.6> Indicate Connected Event to Host immediately.
2550                     /* Require BSSID, Association ID, Beacon Interval.. from AIS_BSS_INFO_T */
2551                     //p2pIndicationOfMediaStateToHost(prAdapter, PARAM_MEDIA_STATE_CONNECTED, prStaRec->aucMacAddr);
2552                     kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2553                                                                     &prP2pFsmInfo->rConnReqInfo,
2554                                                                     prJoinInfo->aucIEBuf,
2555                                                                     prJoinInfo->u4BufLength,
2556                                                                     prStaRec->u2StatusCode);
2557
2558                 }
2559                 else {
2560                     /* Join Fail*/
2561                     //4 <2.1> Redo JOIN process with other Auth Type if possible
2562                     if (p2pFuncRetryJOIN(prAdapter, prStaRec, prJoinInfo) == FALSE) {
2563                         P_BSS_DESC_T prBssDesc;
2564
2565                         /* Increase Failure Count */
2566                         prStaRec->ucJoinFailureCount++;
2567
2568                         prBssDesc = prP2pFsmInfo->prTargetBss;
2569
2570                         ASSERT(prBssDesc);
2571                         ASSERT(prBssDesc->fgIsConnecting);
2572
2573                         prBssDesc->fgIsConnecting = FALSE;
2574
2575                         if( prStaRec->ucJoinFailureCount >=3) {
2576
2577                         kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2578                                                                     &prP2pFsmInfo->rConnReqInfo,
2579                                                                     prJoinInfo->aucIEBuf,
2580                                                                     prJoinInfo->u4BufLength,
2581                                                                     prStaRec->u2StatusCode);
2582                         }
2583                         else {
2584                             /* Sometime the GO is not ready to response auth. Connect it again*/
2585                             prP2pFsmInfo->prTargetBss = NULL;
2586                         }
2587
2588
2589                     }
2590
2591                 }
2592             }
2593         }
2594
2595         if (prAssocRspSwRfb) {
2596             nicRxReturnRFB(prAdapter, prAssocRspSwRfb);
2597         }
2598
2599         if (prP2pFsmInfo->eCurrentState == P2P_STATE_GC_JOIN) {
2600             
2601             if(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX].eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
2602             /* Return to IDLE state. */
2603             p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2604              }
2605             else {
2606             //p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_IDLE);
2607                  /* one more scan */
2608                  p2pFsmStateTransition(prAdapter, prP2pFsmInfo, P2P_STATE_SCAN); 
2609             }
2610         }
2611
2612     } while (FALSE);
2613
2614     if (prMsgHdr) {
2615         cnmMemFree(prAdapter, prMsgHdr);
2616     }
2617
2618     return;
2619
2620 } /* p2pFsmRunEventJoinComplete */
2621
2622
2623
2624 VOID
2625 p2pFsmRunEventMgmtFrameRegister (
2626     IN P_ADAPTER_T prAdapter,
2627     IN P_MSG_HDR_T prMsgHdr
2628     )
2629 {
2630     P_MSG_P2P_MGMT_FRAME_REGISTER_T prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)NULL;
2631     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2632
2633     do {
2634         ASSERT_BREAK((prAdapter != NULL) && (prMsgHdr != NULL));
2635
2636         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2637
2638         if (prP2pFsmInfo == NULL) {
2639             break;
2640         }
2641
2642         prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)prMsgHdr;
2643
2644         p2pFuncMgmtFrameRegister(prAdapter,
2645                             prMgmtFrameRegister->u2FrameType,
2646                             prMgmtFrameRegister->fgIsRegister,
2647                             &prP2pFsmInfo->u4P2pPacketFilter);
2648
2649
2650     } while (FALSE);
2651
2652     if (prMsgHdr) {
2653         cnmMemFree(prAdapter, prMsgHdr);
2654     }
2655
2656     return;
2657
2658 } /* p2pFsmRunEventMgmtFrameRegister */
2659
2660
2661
2662
2663 #if 0
2664 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2665 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2666 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2667 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2668 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2669 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2670 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2671 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2672 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2673 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2674 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2675 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2676 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2677 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2678 #endif
2679
2680
2681
2682
2683
2684
2685
2686 /*----------------------------------------------------------------------------*/
2687 /*!
2688 * \brief    This function is call when RX deauthentication frame from the AIR.
2689 *             If we are under STA mode, we would go back to P2P Device.
2690 *             If we are under AP mode, we would stay in AP mode until disconnect event from HOST.
2691 *
2692 * \param[in] prAdapter  Pointer of ADAPTER_T
2693 *
2694 * \return none
2695 */
2696 /*----------------------------------------------------------------------------*/
2697 VOID
2698 p2pFsmRunEventRxDeauthentication (
2699     IN P_ADAPTER_T prAdapter,
2700     IN P_STA_RECORD_T prStaRec,
2701     IN P_SW_RFB_T prSwRfb
2702     )
2703 {
2704     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2705     UINT_16 u2ReasonCode = 0;
2706
2707     do {
2708         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
2709
2710         if (prStaRec == NULL) {
2711             prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
2712         }
2713
2714         if (!prStaRec) {
2715             break;
2716         }
2717
2718
2719         prP2pBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
2720
2721         if (prStaRec->ucStaState == STA_STATE_1) {
2722             break;
2723         }
2724
2725         DBGLOG(P2P, TRACE, ("RX Deauth\n"));
2726
2727         switch (prP2pBssInfo->eCurrentOPMode) {
2728         case OP_MODE_INFRASTRUCTURE:
2729             if (authProcessRxDeauthFrame(prSwRfb,
2730                     prStaRec->aucMacAddr,
2731                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2732                 P_WLAN_DEAUTH_FRAME_T prDeauthFrame = (P_WLAN_DEAUTH_FRAME_T)prSwRfb->pvHeader;
2733                 UINT_16 u2IELength = 0;
2734
2735                 if (prP2pBssInfo->prStaRecOfAP != prStaRec) {
2736                     break;
2737                 }
2738
2739
2740                 prStaRec->u2ReasonCode = u2ReasonCode;
2741                 u2IELength = prSwRfb->u2PacketLen - (WLAN_MAC_HEADER_LEN + REASON_CODE_FIELD_LEN);
2742
2743                 ASSERT(prP2pBssInfo->prStaRecOfAP == prStaRec);
2744
2745                 /* Indicate disconnect to Host. */
2746                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2747                                         NULL,
2748                                         prDeauthFrame->aucInfoElem,
2749                                         u2IELength,
2750                                         u2ReasonCode);
2751
2752                 prP2pBssInfo->prStaRecOfAP = NULL;
2753
2754                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2755             }
2756             break;
2757         case OP_MODE_ACCESS_POINT:
2758             /* Delete client from client list. */
2759             if (authProcessRxDeauthFrame(prSwRfb,
2760                     prP2pBssInfo->aucBSSID,
2761                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2762                 P_LINK_T prStaRecOfClientList = (P_LINK_T)NULL;
2763                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2764                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2765
2766                 prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2767
2768                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2769                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2770
2771                     ASSERT(prCurrStaRec);
2772
2773                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prStaRec->aucMacAddr)) {
2774
2775                         /* Remove STA from client list. */
2776                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2777
2778                         /* Indicate to Host. */
2779                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, FALSE);
2780
2781                         /* Indicate disconnect to Host. */
2782                         p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2783
2784                         break;
2785                     }
2786                 }
2787             }
2788             break;
2789         case OP_MODE_P2P_DEVICE:
2790         default:
2791             /* Findout why someone sent deauthentication frame to us. */
2792             ASSERT(FALSE);
2793             break;
2794         }
2795
2796         DBGLOG(P2P, TRACE, ("Deauth Reason:%d\n", u2ReasonCode));
2797
2798     } while (FALSE);
2799
2800     return;
2801 } /* p2pFsmRunEventRxDeauthentication */
2802
2803 /*----------------------------------------------------------------------------*/
2804 /*!
2805 * \brief    This function is call when RX deauthentication frame from the AIR.
2806 *             If we are under STA mode, we would go back to P2P Device.
2807 *             If we are under AP mode, we would stay in AP mode until disconnect event from HOST.
2808 *
2809 * \param[in] prAdapter  Pointer of ADAPTER_T
2810 *
2811 * \return none
2812 */
2813 /*----------------------------------------------------------------------------*/
2814 VOID
2815 p2pFsmRunEventRxDisassociation (
2816     IN P_ADAPTER_T prAdapter,
2817     IN P_STA_RECORD_T prStaRec,
2818     IN P_SW_RFB_T prSwRfb
2819     )
2820 {
2821     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2822     UINT_16 u2ReasonCode = 0;
2823
2824     do {
2825         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
2826
2827         if (prStaRec == NULL) {
2828             prStaRec = cnmGetStaRecByIndex(prAdapter, prSwRfb->ucStaRecIdx);
2829         }
2830
2831
2832         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2833
2834         if (prStaRec->ucStaState == STA_STATE_1) {
2835
2836             break;
2837         }
2838
2839         DBGLOG(P2P, TRACE, ("RX Disassoc\n"));
2840
2841         switch (prP2pBssInfo->eCurrentOPMode) {
2842         case OP_MODE_INFRASTRUCTURE:
2843             if (assocProcessRxDisassocFrame(prAdapter,
2844                     prSwRfb,
2845                     prStaRec->aucMacAddr,
2846                     &prStaRec->u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2847                 P_WLAN_DISASSOC_FRAME_T prDisassocFrame = (P_WLAN_DISASSOC_FRAME_T)prSwRfb->pvHeader;
2848                 UINT_16 u2IELength = 0;
2849
2850                 ASSERT(prP2pBssInfo->prStaRecOfAP == prStaRec);
2851
2852                 if (prP2pBssInfo->prStaRecOfAP != prStaRec) {
2853                     break;
2854                 }
2855
2856
2857                 u2IELength = prSwRfb->u2PacketLen - (WLAN_MAC_HEADER_LEN + REASON_CODE_FIELD_LEN);
2858
2859                 /* Indicate disconnect to Host. */
2860                 kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2861                                         NULL,
2862                                         prDisassocFrame->aucInfoElem,
2863                                         u2IELength,
2864                                         prStaRec->u2ReasonCode);
2865                 
2866                 prP2pBssInfo->prStaRecOfAP = NULL;
2867
2868                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, prStaRec->u2ReasonCode);
2869                 
2870             }
2871             break;
2872         case OP_MODE_ACCESS_POINT:
2873             /* Delete client from client list. */
2874             if (assocProcessRxDisassocFrame(prAdapter,
2875                     prSwRfb,
2876                     prP2pBssInfo->aucBSSID,
2877                     &u2ReasonCode) == WLAN_STATUS_SUCCESS) {
2878                 P_LINK_T prStaRecOfClientList = (P_LINK_T)NULL;
2879                 P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T)NULL;
2880                 P_STA_RECORD_T prCurrStaRec = (P_STA_RECORD_T)NULL;
2881
2882                 prStaRecOfClientList = &prP2pBssInfo->rStaRecOfClientList;
2883
2884                 LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
2885                     prCurrStaRec = LINK_ENTRY(prLinkEntry, STA_RECORD_T, rLinkEntry);
2886
2887                     ASSERT(prCurrStaRec);
2888
2889                     if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, prStaRec->aucMacAddr)) {
2890
2891                         /* Remove STA from client list. */
2892                         LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prCurrStaRec->rLinkEntry);
2893
2894                         /* Indicate to Host. */
2895                         //kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, FALSE);
2896
2897                         /* Indicate disconnect to Host. */
2898                         p2pFuncDisconnect(prAdapter, prStaRec, FALSE, u2ReasonCode);
2899
2900                         break;
2901                     }
2902                 }
2903             }
2904             break;
2905         case OP_MODE_P2P_DEVICE:
2906         default:
2907             ASSERT(FALSE);
2908             break;
2909         }
2910
2911
2912     } while (FALSE);
2913
2914     return;
2915 } /* p2pFsmRunEventRxDisassociation */
2916
2917
2918
2919
2920
2921 /*----------------------------------------------------------------------------*/
2922 /*!
2923 * \brief    This function is called when a probe request frame is received.
2924 *
2925 * \param[in] prAdapter  Pointer of ADAPTER_T
2926 *
2927 * \return boolean value if probe response frame is accepted & need cancel scan request.
2928 */
2929 /*----------------------------------------------------------------------------*/
2930 VOID
2931 p2pFsmRunEventRxProbeResponseFrame (
2932     IN P_ADAPTER_T prAdapter,
2933     IN P_SW_RFB_T prSwRfb,
2934     IN P_BSS_DESC_T prBssDesc
2935     )
2936 {
2937     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2938     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
2939     P_WLAN_MAC_MGMT_HEADER_T prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)NULL;
2940     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2941
2942     do {
2943         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL) && (prBssDesc != NULL));
2944
2945         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2946         prP2pConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
2947         prP2pBssInfo = &prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
2948
2949         /* There is a connection request. */
2950         prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T)prSwRfb->pvHeader;
2951
2952     } while (FALSE);
2953
2954     return;
2955 } /* p2pFsmRunEventRxProbeResponseFrame */
2956
2957
2958
2959
2960
2961
2962 VOID
2963 p2pFsmRunEventBeaconTimeout (
2964     IN P_ADAPTER_T prAdapter
2965     )
2966 {
2967     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
2968     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
2969
2970     do {
2971         ASSERT_BREAK(prAdapter != NULL);
2972
2973         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
2974         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
2975
2976         DBGLOG(P2P, TRACE, ("p2pFsmRunEventBeaconTimeout: Beacon Timeout\n"));
2977
2978         /* Only client mode would have beacon lost event. */
2979         ASSERT(prP2pBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE);
2980
2981         if (prP2pBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
2982             /* Indicate disconnect to Host. */
2983             kalP2PGCIndicateConnectionStatus(prAdapter->prGlueInfo,
2984                                     NULL,
2985                                     NULL,
2986                                     0,
2987                                     REASON_CODE_DISASSOC_INACTIVITY);
2988
2989             if (prP2pBssInfo->prStaRecOfAP != NULL) {
2990                 P_STA_RECORD_T prStaRec = prP2pBssInfo->prStaRecOfAP;
2991                 
2992                 prP2pBssInfo->prStaRecOfAP = NULL;
2993
2994                 p2pFuncDisconnect(prAdapter, prStaRec, FALSE, REASON_CODE_DISASSOC_LEAVING_BSS);
2995
2996                 //20120830 moved into p2pFuncDisconnect()
2997                 //cnmStaRecFree(prAdapter, prP2pBssInfo->prStaRecOfAP, TRUE);
2998
2999                 
3000             }
3001         }
3002     } while (FALSE);
3003
3004     return;
3005 } /* p2pFsmRunEventBeaconTimeout */
3006
3007
3008
3009
3010 #if CFG_SUPPORT_WFD
3011 VOID
3012 p2pFsmRunEventWfdSettingUpdate (
3013     IN P_ADAPTER_T prAdapter,
3014     IN P_MSG_HDR_T prMsgHdr
3015     )
3016 {
3017     P_WFD_CFG_SETTINGS_T prWfdCfgSettings = (P_WFD_CFG_SETTINGS_T)NULL;
3018     P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T prMsgWfdCfgSettings = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)NULL;
3019     WLAN_STATUS rStatus;
3020
3021
3022     DBGLOG(P2P, INFO,("p2pFsmRunEventWfdSettingUpdate\n"));
3023
3024     do {
3025         ASSERT_BREAK((prAdapter != NULL));
3026
3027         if (prMsgHdr != NULL) {
3028             prMsgWfdCfgSettings = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)prMsgHdr;
3029             prWfdCfgSettings = prMsgWfdCfgSettings->prWfdCfgSettings;
3030         }
3031         else {
3032             prWfdCfgSettings = &prAdapter->rWifiVar.prP2pFsmInfo->rWfdConfigureSettings;
3033         }
3034         
3035         DBGLOG(P2P, INFO,("WFD Enalbe %x info %x state %x flag %x adv %x\n", 
3036                     prWfdCfgSettings->ucWfdEnable,
3037                     prWfdCfgSettings->u2WfdDevInfo, 
3038                     prWfdCfgSettings->u4WfdState, 
3039                     prWfdCfgSettings->u4WfdFlag, 
3040                     prWfdCfgSettings->u4WfdAdvancedFlag));
3041
3042         rStatus = wlanSendSetQueryCmd (
3043                         prAdapter,                  /* prAdapter */
3044                         CMD_ID_SET_WFD_CTRL,   /* ucCID */
3045                         TRUE,                       /* fgSetQuery */
3046                         FALSE,                /* fgNeedResp */
3047                         FALSE,                      /* fgIsOid */
3048                         NULL,
3049                         NULL,                       /* pfCmdTimeoutHandler */
3050                         sizeof(WFD_CFG_SETTINGS_T),    /* u4SetQueryInfoLen */
3051                         (PUINT_8)prWfdCfgSettings,     /* pucInfoBuffer */
3052                         NULL,                       /* pvSetQueryBuffer */
3053                         0                           /* u4SetQueryBufferLen */
3054                         );
3055
3056     } while (FALSE);
3057
3058     return;
3059
3060 }
3061 /* p2pFsmRunEventWfdSettingUpdate */
3062
3063 #endif
3064
3065
3066
3067
3068
3069
3070
3071
3072 /*----------------------------------------------------------------------------*/
3073 /*!
3074 * @brief This function is used to generate P2P IE for Beacon frame.
3075 *
3076 * @param[in] prMsduInfo             Pointer to the composed MSDU_INFO_T.
3077 *
3078 * @return none
3079 */
3080 /*----------------------------------------------------------------------------*/
3081 VOID
3082 p2pGenerateP2P_IEForAssocReq (
3083     IN P_ADAPTER_T prAdapter,
3084     IN P_MSDU_INFO_T prMsduInfo
3085     )
3086 {
3087     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
3088     P_STA_RECORD_T prStaRec = (P_STA_RECORD_T)NULL;
3089
3090     do {
3091         ASSERT_BREAK((prAdapter != NULL) && (prMsduInfo != NULL));
3092
3093         prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
3094
3095         prStaRec = cnmGetStaRecByIndex(prAdapter, prMsduInfo->ucStaRecIndex);
3096
3097         if (IS_STA_P2P_TYPE(prStaRec)) {
3098             // TODO:
3099         }
3100
3101     } while (FALSE);
3102
3103     return;
3104
3105 } /* end of p2pGenerateP2P_IEForAssocReq() */
3106
3107
3108
3109
3110 /*----------------------------------------------------------------------------*/
3111 /*!
3112 * @brief This function is used to generate P2P IE for Probe Request frame.
3113 *
3114 * @param[in] prMsduInfo             Pointer to the composed MSDU_INFO_T.
3115 *
3116 * @return none
3117 */
3118 /*----------------------------------------------------------------------------*/
3119 VOID
3120 p2pGenerateP2P_IEForProbeReq (
3121     IN P_ADAPTER_T prAdapter,
3122     IN PUINT_16 pu2Offset,
3123     IN PUINT_8 pucBuf,
3124     IN UINT_16 u2BufSize
3125     )
3126 {
3127     ASSERT(prAdapter);
3128     ASSERT(pucBuf);
3129
3130     // TODO:
3131
3132     return;
3133
3134 } /* end of p2pGenerateP2P_IEForProbReq() */
3135
3136
3137
3138
3139 /*----------------------------------------------------------------------------*/
3140 /*!
3141 * @brief This function is used to calculate P2P IE length for Beacon frame.
3142 *
3143 * @param[in] eNetTypeIndex      Specify which network
3144 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3145 *
3146 * @return The length of P2P IE added
3147 */
3148 /*----------------------------------------------------------------------------*/
3149 UINT_32
3150 p2pCalculateP2P_IELenForProbeReq (
3151     IN P_ADAPTER_T prAdapter,
3152     IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
3153     IN P_STA_RECORD_T prStaRec
3154     )
3155 {
3156
3157     if (eNetTypeIndex != NETWORK_TYPE_P2P_INDEX) {
3158         return 0;
3159     }
3160
3161     // TODO:
3162
3163     return 0;
3164
3165 } /* end of p2pCalculateP2P_IELenForProbeReq() */
3166
3167
3168
3169
3170
3171 /*----------------------------------------------------------------------------*/
3172 /*!
3173 * @brief This function will indiate the Event of Tx Fail of AAA Module.
3174 *
3175 * @param[in] prAdapter          Pointer to the Adapter structure.
3176 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3177 *
3178 * @return (none)
3179 */
3180 /*----------------------------------------------------------------------------*/
3181 VOID
3182 p2pRunEventAAATxFail (
3183     IN P_ADAPTER_T prAdapter,
3184     IN P_STA_RECORD_T prStaRec
3185     )
3186 {
3187     P_BSS_INFO_T prBssInfo;
3188
3189
3190     ASSERT(prAdapter);
3191     ASSERT(prStaRec);
3192
3193     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
3194
3195     bssRemoveStaRecFromClientList(prAdapter, prBssInfo, prStaRec);
3196
3197     p2pFuncDisconnect(prAdapter, prStaRec, FALSE, REASON_CODE_UNSPECIFIED);
3198
3199     
3200     //20120830 moved into p2puUncDisconnect.
3201     //cnmStaRecFree(prAdapter, prStaRec, TRUE);
3202
3203     return;
3204 } /* p2pRunEventAAATxFail */
3205
3206
3207 /*----------------------------------------------------------------------------*/
3208 /*!
3209 * @brief This function will indiate the Event of Successful Completion of AAA Module.
3210 *
3211 * @param[in] prAdapter          Pointer to the Adapter structure.
3212 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3213 *
3214 * @return (none)
3215 */
3216 /*----------------------------------------------------------------------------*/
3217 WLAN_STATUS
3218 p2pRunEventAAAComplete (
3219     IN P_ADAPTER_T prAdapter,
3220     IN P_STA_RECORD_T prStaRec
3221     )
3222 {
3223     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
3224     P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T)NULL;
3225     ENUM_PARAM_MEDIA_STATE_T eOriMediaState;
3226
3227     do {
3228         ASSERT_BREAK((prAdapter != NULL) && (prStaRec != NULL));
3229
3230         prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
3231
3232         eOriMediaState = prP2pBssInfo->eConnectionState;
3233
3234         if(prStaRec != NULL){
3235
3236                             bssRemoveStaRecFromClientList(prAdapter, prP2pBssInfo, prStaRec);
3237
3238                     }
3239                     else{
3240
3241                             break;
3242
3243                     }
3244
3245         if (prP2pBssInfo->rStaRecOfClientList.u4NumElem > P2P_MAXIMUM_CLIENT_COUNT ||
3246             kalP2PMaxClients(prAdapter->prGlueInfo, prP2pBssInfo->rStaRecOfClientList.u4NumElem)) {
3247             rStatus = WLAN_STATUS_RESOURCES;
3248             break;
3249         }
3250
3251         bssAddStaRecToClientList(prAdapter, prP2pBssInfo, prStaRec);
3252
3253         prStaRec->u2AssocId = bssAssignAssocID(prStaRec);
3254         
3255         if (prP2pBssInfo->rStaRecOfClientList.u4NumElem > P2P_MAXIMUM_CLIENT_COUNT ||
3256             kalP2PMaxClients(prAdapter->prGlueInfo, prP2pBssInfo->rStaRecOfClientList.u4NumElem)) {
3257             rStatus = WLAN_STATUS_RESOURCES;
3258             break;
3259         }
3260
3261         cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
3262
3263         p2pChangeMediaState(prAdapter, PARAM_MEDIA_STATE_CONNECTED);
3264
3265         /* Update Connected state to FW. */
3266         if (eOriMediaState != prP2pBssInfo->eConnectionState) {
3267             nicUpdateBss(prAdapter, NETWORK_TYPE_P2P_INDEX);
3268         }
3269
3270     } while (FALSE);
3271
3272     return rStatus;
3273 } /* p2pRunEventAAAComplete */
3274
3275
3276 /*----------------------------------------------------------------------------*/
3277 /*!
3278 * @brief This function will indiate the Event of Successful Completion of AAA Module.
3279 *
3280 * @param[in] prAdapter          Pointer to the Adapter structure.
3281 * @param[in] prStaRec           Pointer to the STA_RECORD_T
3282 *
3283 * @return (none)
3284 */
3285 /*----------------------------------------------------------------------------*/
3286 WLAN_STATUS
3287 p2pRunEventAAASuccess (
3288     IN P_ADAPTER_T prAdapter,
3289     IN P_STA_RECORD_T prStaRec
3290     )
3291 {
3292     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
3293
3294     do {
3295         ASSERT_BREAK((prAdapter != NULL) && (prStaRec != NULL));
3296
3297         /* Glue layer indication. */
3298         kalP2PGOStationUpdate(prAdapter->prGlueInfo, prStaRec, TRUE);
3299
3300     } while (FALSE);
3301
3302     return rStatus;
3303 } /* p2pRunEventAAASuccess */
3304
3305
3306
3307 /*----------------------------------------------------------------------------*/
3308 /*!
3309 * \brief
3310 *
3311 * \param[in]
3312 *
3313 * \return none
3314 */
3315 /*----------------------------------------------------------------------------*/
3316 WLAN_STATUS
3317 p2pRxPublicActionFrame (
3318     IN P_ADAPTER_T prAdapter,
3319     IN P_SW_RFB_T prSwRfb
3320     )
3321 {
3322     WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS;
3323     P_P2P_PUBLIC_ACTION_FRAME_T prPublicActionFrame = (P_P2P_PUBLIC_ACTION_FRAME_T)NULL;
3324     P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
3325
3326     ASSERT(prSwRfb);
3327     ASSERT(prAdapter);
3328
3329
3330
3331     prPublicActionFrame = (P_P2P_PUBLIC_ACTION_FRAME_T)prSwRfb->pvHeader;
3332     prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
3333
3334     DBGLOG(P2P, TRACE, ("RX Public Action Frame Token:%d.\n", prPublicActionFrame->ucDialogToken));
3335
3336     if (prPublicActionFrame->ucCategory != CATEGORY_PUBLIC_ACTION) {
3337         return rWlanStatus;
3338     }
3339
3340     switch (prPublicActionFrame->ucAction) {
3341     case ACTION_PUBLIC_WIFI_DIRECT:
3342         break;
3343     case ACTION_GAS_INITIAL_REQUEST:
3344     case ACTION_GAS_INITIAL_RESPONSE:
3345     case ACTION_GAS_COMEBACK_REQUEST:
3346     case ACTION_GAS_COMEBACK_RESPONSE:
3347         break;
3348     default:
3349         break;
3350     }
3351
3352     return rWlanStatus;
3353 } /* p2pRxPublicActionFrame */
3354
3355
3356
3357 WLAN_STATUS
3358 p2pRxActionFrame (
3359     IN P_ADAPTER_T prAdapter,
3360     IN P_SW_RFB_T prSwRfb
3361     )
3362 {
3363     WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS;
3364     P_P2P_ACTION_FRAME_T prP2pActionFrame = (P_P2P_ACTION_FRAME_T)NULL;
3365     UINT_8 aucOui[3] = VENDOR_OUI_WFA_SPECIFIC;
3366
3367     do {
3368         ASSERT_BREAK((prAdapter != NULL) && (prSwRfb != NULL));
3369
3370         prP2pActionFrame = (P_P2P_ACTION_FRAME_T)prSwRfb->pvHeader;
3371
3372         if (prP2pActionFrame->ucCategory != CATEGORY_VENDOR_SPECIFIC_ACTION) {
3373             DBGLOG(P2P, TRACE, ("RX Action Frame but not vendor specific.\n"));
3374             break;
3375         }
3376
3377
3378         if ((prP2pActionFrame->ucOuiType != VENDOR_OUI_TYPE_P2P) ||
3379                 (prP2pActionFrame->aucOui[0] != aucOui[0]) ||
3380                 (prP2pActionFrame->aucOui[1] != aucOui[1]) ||
3381                 (prP2pActionFrame->aucOui[2] != aucOui[2])) {
3382             DBGLOG(P2P, TRACE, ("RX Vendor Specific Action Frame but not P2P Type or not WFA OUI.\n"));
3383             break;
3384         }
3385
3386     } while (FALSE);
3387
3388     return rWlanStatus;
3389 } /* p2pRxActionFrame */
3390
3391
3392 VOID
3393 p2pProcessEvent_UpdateNOAParam (
3394     IN P_ADAPTER_T    prAdapter,
3395     UINT_8  ucNetTypeIndex,
3396     P_EVENT_UPDATE_NOA_PARAMS_T prEventUpdateNoaParam
3397     )
3398 {
3399     P_BSS_INFO_T prBssInfo = (P_BSS_INFO_T)NULL;
3400     P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
3401     UINT_32 i;
3402     BOOLEAN fgNoaAttrExisted = FALSE;
3403
3404     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[ucNetTypeIndex]);
3405     prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
3406
3407     prP2pSpecificBssInfo->fgEnableOppPS = prEventUpdateNoaParam->fgEnableOppPS;
3408     prP2pSpecificBssInfo->u2CTWindow = prEventUpdateNoaParam->u2CTWindow;
3409     prP2pSpecificBssInfo->ucNoAIndex = prEventUpdateNoaParam->ucNoAIndex;
3410     prP2pSpecificBssInfo->ucNoATimingCount = prEventUpdateNoaParam->ucNoATimingCount;
3411
3412     fgNoaAttrExisted |= prP2pSpecificBssInfo->fgEnableOppPS;
3413
3414
3415     ASSERT(prP2pSpecificBssInfo->ucNoATimingCount <= P2P_MAXIMUM_NOA_COUNT);
3416
3417     for (i = 0; i < prP2pSpecificBssInfo->ucNoATimingCount; i++) {
3418         // in used
3419         prP2pSpecificBssInfo->arNoATiming[i].fgIsInUse =
3420             prEventUpdateNoaParam->arEventNoaTiming[i].fgIsInUse;
3421         // count
3422         prP2pSpecificBssInfo->arNoATiming[i].ucCount =
3423             prEventUpdateNoaParam->arEventNoaTiming[i].ucCount;
3424         // duration
3425         prP2pSpecificBssInfo->arNoATiming[i].u4Duration =
3426             prEventUpdateNoaParam->arEventNoaTiming[i].u4Duration;
3427         // interval
3428         prP2pSpecificBssInfo->arNoATiming[i].u4Interval =
3429             prEventUpdateNoaParam->arEventNoaTiming[i].u4Interval;
3430         // start time
3431         prP2pSpecificBssInfo->arNoATiming[i].u4StartTime =
3432             prEventUpdateNoaParam->arEventNoaTiming[i].u4StartTime;
3433
3434         fgNoaAttrExisted |= prP2pSpecificBssInfo->arNoATiming[i].fgIsInUse;
3435     }
3436
3437     prP2pSpecificBssInfo->fgIsNoaAttrExisted = fgNoaAttrExisted;
3438
3439     // update beacon content by the change
3440     bssUpdateBeaconContent(prAdapter, ucNetTypeIndex);
3441 }
3442
3443 #endif /* CFG_ENABLE_WIFI_DIRECT */
3444