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