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