support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931_kk / drv_wlan / os / linux / gl_p2p_cfg80211.c
1 /*
2 ** $Id: @(#) gl_p2p_cfg80211.c@@
3 */
4
5 /*! \file   gl_p2p_cfg80211.c
6     \brief  Main routines of Linux driver interface for Wi-Fi Direct
7             using cfg80211 interface
8
9     This file contains the main routines of Linux driver for MediaTek Inc. 802.11
10     Wireless LAN Adapters.
11 */
12
13 /*******************************************************************************
14 * Copyright (c) 2007 MediaTek Inc.
15 *
16 * All rights reserved. Copying, compilation, modification, distribution
17 * or any other use whatsoever of this material is strictly prohibited
18 * except in accordance with a Software License Agreement with
19 * MediaTek Inc.
20 ********************************************************************************
21 */
22
23 /*******************************************************************************
24 * LEGAL DISCLAIMER
25 *
26 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
27 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
28 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
29 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
30 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
31 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
33 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
34 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
35 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
36 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
37 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
38 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
39 *
40 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
41 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
42 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
43 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
44 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
45 *
46 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
47 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
48 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
49 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
50 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
51 * (ICC).
52 ********************************************************************************
53 */
54
55 /*
56 ** $Log: gl_p2p_cfg80211.c $
57 ** 
58 ** 08 30 2012 yuche.tsai
59 ** NULL
60 ** Fix disconnect issue possible leads KE.
61 ** 
62 ** 08 24 2012 cp.wu
63 ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
64 ** .
65 ** 
66 ** 08 24 2012 cp.wu
67 ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
68 ** cfg80211 support merge back from ALPS.JB to DaVinci - MT6620 Driver v2.3 branch.
69 ** 
70 ** 08 24 2012 yuche.tsai
71 ** NULL
72 ** Fix bug of invitation request.
73 ** 
74 ** 08 20 2012 yuche.tsai
75 ** NULL
76 ** Try to fix frame register KE issue.
77 ** 
78 ** 08 17 2012 yuche.tsai
79 ** NULL
80 ** Fix compile warning.
81 ** 
82 ** 08 16 2012 yuche.tsai
83 ** NULL
84 ** Fix compile warning.
85 ** 
86 ** 08 08 2012 yuche.tsai
87 ** NULL
88 ** Fix bug of hard scan p2p device sometimes
89 ** 
90 ** 08 08 2012 wh.su
91 ** [WCXRP00001246] [MT6620 Wi-Fi][Driver][P2P] Do more filed check for avoid not copy the STA mac address for add key[WCXRP00001262] [MT6620 Wi-Fi][Driver] Fixed the update assoc info pkt length issue
92 ** .
93 **
94 ** 08 06 2012 yuche.tsai
95 ** [WCXRP00001119] [Volunteer Patch][WiFi Direct][Driver] Connection Policy Set for WFD SIGMA test
96 ** Fix P2P reset would not reset QoS BSS info issue.
97 **
98 ** 07 31 2012 yuche.tsai
99 ** NULL
100 ** Update Active/Deactive network policy for P2P network.
101 ** Highly related to power saving.
102 **
103 ** 07 25 2012 yuche.tsai
104 ** NULL
105 ** Add support for null mac address del station.
106 **
107 ** 07 25 2012 yuche.tsai
108 ** NULL
109 ** Bug fix.
110 **
111 ** 07 25 2012 yuche.tsai
112 ** NULL
113 ** Bug fix for TX mgmt frame.
114 **
115 ** 07 24 2012 yuche.tsai
116 ** NULL
117 ** Bug fix for JB.
118 **
119 ** 07 19 2012 yuche.tsai
120 ** NULL
121 ** Code update for JB.
122  *
123  * 07 17 2012 yuche.tsai
124  * NULL
125  * Fix compile error for JB.
126  *
127  * 07 17 2012 yuche.tsai
128  * NULL
129  * Compile no error before trial run.
130  *
131  * 09 21 2010 kevin.huang
132  * [WCXRP00000054] [MT6620 Wi-Fi][Driver] Restructure driver for second Interface
133  * Isolate P2P related function for Hardware Software Bundle
134  *
135  * 07 08 2010 cp.wu
136  *
137  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
138  *
139  * 06 06 2010 kevin.huang
140  * [WPD00003832][MT6620 5931] Create driver base
141  * [MT6620 5931] Create driver base
142  *
143  * 05 31 2010 cp.wu
144  * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
145  * add cfg80211 interface, which is to replace WE, for further extension
146  *
147 **
148 */
149
150 /*******************************************************************************
151 *                         C O M P I L E R   F L A G S
152 ********************************************************************************
153 */
154
155 /*******************************************************************************
156 *                    E X T E R N A L   R E F E R E N C E S
157 ********************************************************************************
158 */
159
160 #include "config.h"
161
162 #if CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_WIFI_DIRECT_CFG_80211
163 #include <linux/kernel.h>
164 #include <linux/netdevice.h>
165 #include <linux/wireless.h>
166 #include <linux/ieee80211.h>
167 #include <net/cfg80211.h>
168
169 #include "precomp.h"
170 #ifdef CFG_DUAL_ANTENNA
171 #include "mtk_porting.h"
172 #include "dual_ant_bwcs.h"
173 #endif
174
175
176
177 /*******************************************************************************
178 *                              C O N S T A N T S
179 ********************************************************************************
180 */
181
182 /*******************************************************************************
183 *                             D A T A   T Y P E S
184 ********************************************************************************
185 */
186
187 /*******************************************************************************
188 *                            P U B L I C   D A T A
189 ********************************************************************************
190 */
191
192 /*******************************************************************************
193 *                           P R I V A T E   D A T A
194 ********************************************************************************
195 */
196
197 /*******************************************************************************
198 *                                 M A C R O S
199 ********************************************************************************
200 */
201
202 /*******************************************************************************
203 *                   F U N C T I O N   D E C L A R A T I O N S
204 ********************************************************************************
205 */
206
207
208 BOOLEAN
209 mtk_p2p_cfg80211func_channel_format_switch(
210     IN struct ieee80211_channel *channel,
211     IN enum nl80211_channel_type channel_type,
212     IN P_RF_CHANNEL_INFO_T prRfChnlInfo,
213     IN P_ENUM_CHNL_EXT_T prChnlSco
214     );
215
216 /*******************************************************************************
217 *                              F U N C T I O N S
218 ********************************************************************************
219 */
220
221 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
222 int mtk_p2p_cfg80211_add_key(
223     struct wiphy *wiphy,
224     struct net_device *ndev,
225     u8 key_index,
226     bool pairwise,
227     const u8 *mac_addr,
228     struct key_params *params
229     )
230 {
231     P_GLUE_INFO_T prGlueInfo = NULL;
232         INT_32 i4Rslt = -EINVAL;
233         WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
234         UINT_32 u4BufLen = 0;
235         P2P_PARAM_KEY_T rKey;
236
237     ASSERT(wiphy);
238
239     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
240
241     kalMemZero(&rKey, sizeof(P2P_PARAM_KEY_T));
242
243         rKey.u4KeyIndex = key_index;
244     if(mac_addr) {
245         memcpy(rKey.arBSSID, mac_addr, ETH_ALEN);
246         if ((rKey.arBSSID[0] == 0x00) && (rKey.arBSSID[1] == 0x00) && (rKey.arBSSID[2] == 0x00) && 
247             (rKey.arBSSID[3] == 0x00) && (rKey.arBSSID[4] == 0x00) && (rKey.arBSSID[5] == 0x00)) {
248             rKey.arBSSID[0] = 0xff;
249             rKey.arBSSID[1] = 0xff;
250             rKey.arBSSID[2] = 0xff;
251             rKey.arBSSID[3] = 0xff;
252             rKey.arBSSID[4] = 0xff;
253             rKey.arBSSID[5] = 0xff;
254         }
255         if (rKey.arBSSID[0] != 0xFF) {
256             rKey.u4KeyIndex |= BIT(31);
257             if ((rKey.arBSSID[0] != 0x00) || (rKey.arBSSID[1] != 0x00) || (rKey.arBSSID[2] != 0x00) ||
258                 (rKey.arBSSID[3] != 0x00) || (rKey.arBSSID[4] != 0x00) || (rKey.arBSSID[5] != 0x00))
259                 rKey.u4KeyIndex |= BIT(30);
260         }
261         else {
262             rKey.u4KeyIndex |= BIT(31);
263         }
264     }
265     else {
266             rKey.arBSSID[0] = 0xff;
267             rKey.arBSSID[1] = 0xff;
268             rKey.arBSSID[2] = 0xff;
269             rKey.arBSSID[3] = 0xff;
270             rKey.arBSSID[4] = 0xff;
271             rKey.arBSSID[5] = 0xff;
272             rKey.u4KeyIndex |= BIT(31); //????
273     }
274         if(params->key)
275         {
276         //rKey.aucKeyMaterial[0] = kalMemAlloc(params->key_len, VIR_MEM_TYPE);
277             kalMemCopy(rKey.aucKeyMaterial, params->key, params->key_len);
278         }
279         rKey.u4KeyLength = params->key_len;
280         rKey.u4Length =  ((UINT_32)&(((P_P2P_PARAM_KEY_T)0)->aucKeyMaterial)) + rKey.u4KeyLength;
281
282         rStatus = kalIoctl(prGlueInfo,
283             wlanoidSetAddP2PKey,
284             &rKey,
285             rKey.u4Length,
286             FALSE,
287             FALSE,
288             TRUE,
289             TRUE,
290             &u4BufLen);
291     if (rStatus == WLAN_STATUS_SUCCESS)
292                 i4Rslt = 0;
293
294     return i4Rslt;
295 }
296
297
298 int mtk_p2p_cfg80211_get_key(
299     struct wiphy *wiphy,
300     struct net_device *ndev,
301     u8 key_index,
302     bool pairwise,
303     const u8 *mac_addr,
304     void *cookie,
305     void (*callback)(void *cookie, struct key_params*)
306     )
307 {
308     P_GLUE_INFO_T prGlueInfo = NULL;
309
310     ASSERT(wiphy);
311
312     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
313
314     // not implemented yet
315
316     return -EINVAL;
317 }
318
319 int mtk_p2p_cfg80211_del_key(
320     struct wiphy *wiphy,
321     struct net_device *ndev,
322     u8 key_index,
323     bool pairwise,
324     const u8 *mac_addr
325     )
326 {
327     P_GLUE_INFO_T prGlueInfo = NULL;
328         PARAM_REMOVE_KEY_T prRemoveKey;
329         INT_32 i4Rslt = -EINVAL;
330         WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
331         UINT_32 u4BufLen = 0;
332
333     ASSERT(wiphy);
334
335     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
336
337     kalMemZero(&prRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
338         if(mac_addr)
339                 memcpy(prRemoveKey.arBSSID, mac_addr, PARAM_MAC_ADDR_LEN);
340         prRemoveKey.u4KeyIndex = key_index;
341         prRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
342
343     rStatus = kalIoctl(prGlueInfo,
344             wlanoidSetRemoveP2PKey,
345             &prRemoveKey,
346             prRemoveKey.u4Length,
347             FALSE,
348             FALSE,
349             TRUE,
350             TRUE,
351             &u4BufLen);
352
353     if (rStatus == WLAN_STATUS_SUCCESS)
354                 i4Rslt = 0;
355
356     return i4Rslt;
357 }
358
359
360 int
361 mtk_p2p_cfg80211_set_default_key (
362     struct wiphy *wiphy,
363     struct net_device *netdev,
364     u8 key_index,
365     bool unicast,
366     bool multicast
367     )
368 {
369     P_GLUE_INFO_T prGlueInfo = NULL;
370
371     ASSERT(wiphy);
372
373     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
374
375     // not implemented yet
376
377     return 0;
378 }
379
380 int mtk_p2p_cfg80211_get_station(
381     struct wiphy *wiphy,
382     struct net_device *ndev,
383     u8 *mac,
384     struct station_info *sinfo
385     )
386 {
387     INT_32 i4RetRslt = -EINVAL;
388     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
389     P_GL_P2P_INFO_T prP2pGlueInfo = (P_GL_P2P_INFO_T)NULL;
390     P2P_STATION_INFO_T rP2pStaInfo;
391
392     ASSERT(wiphy);
393
394     do {
395         if ((wiphy == NULL) ||
396                 (ndev == NULL) ||
397                 (sinfo == NULL) ||
398                 (mac == NULL)) {
399             break;
400         }
401
402         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_get_station\n"));
403
404         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
405         prP2pGlueInfo = prGlueInfo->prP2PInfo;
406
407         sinfo->filled = 0;
408
409         /* Get station information. */
410         /* 1. Inactive time? */
411         p2pFuncGetStationInfo(prGlueInfo->prAdapter,
412                                                 mac,
413                                                 &rP2pStaInfo);
414
415         /* Inactive time. */
416         sinfo->filled |= STATION_INFO_INACTIVE_TIME;
417         sinfo->inactive_time = rP2pStaInfo.u4InactiveTime;
418         sinfo->generation = prP2pGlueInfo->i4Generation;
419
420         i4RetRslt = 0;
421     } while (FALSE);
422
423     return i4RetRslt;
424 }
425
426 int
427 mtk_p2p_cfg80211_scan (
428     struct wiphy *wiphy,
429     struct net_device *ndev,
430     struct cfg80211_scan_request *request
431     )
432 {
433     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
434     P_GL_P2P_INFO_T prP2pGlueInfo = (P_GL_P2P_INFO_T)NULL;
435     P_MSG_P2P_SCAN_REQUEST_T prMsgScanRequest = (P_MSG_P2P_SCAN_REQUEST_T)NULL;
436     UINT_32 u4MsgSize = 0, u4Idx = 0;
437     INT_32 i4RetRslt = -EINVAL;
438     P_RF_CHANNEL_INFO_T prRfChannelInfo = (P_RF_CHANNEL_INFO_T)NULL;
439     P_P2P_SSID_STRUCT_T prSsidStruct = (P_P2P_SSID_STRUCT_T)NULL;
440     struct ieee80211_channel *prChannel = NULL;
441     struct cfg80211_ssid *prSsid = NULL;
442
443     /* [---------Channel---------] [---------SSID---------][---------IE---------] */
444
445
446     do {
447         if ((wiphy == NULL) || (request == NULL)) {
448             break;
449         }
450
451         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
452
453         prP2pGlueInfo = prGlueInfo->prP2PInfo;
454
455         if (prP2pGlueInfo == NULL) {
456             ASSERT(FALSE);
457             break;
458         }
459
460         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_scan.\n"));
461
462
463         if (prP2pGlueInfo->prScanRequest != NULL) {
464             /* There have been a scan request on-going processing. */
465             DBGLOG(P2P, TRACE, ("There have been a scan request on-going processing.\n"));
466             break;
467         }
468
469         prP2pGlueInfo->prScanRequest = request;
470
471         /* Should find out why the n_channels so many? */
472         if (request->n_channels > MAXIMUM_OPERATION_CHANNEL_LIST) {
473             request->n_channels = MAXIMUM_OPERATION_CHANNEL_LIST;
474             DBGLOG(P2P, TRACE, ("Channel list exceed the maximun support.\n"));
475         }
476
477         u4MsgSize = sizeof(MSG_P2P_SCAN_REQUEST_T) +
478                                     (request->n_channels * sizeof(RF_CHANNEL_INFO_T)) +
479                                     (request->n_ssids * sizeof(PARAM_SSID_T)) +
480                                     request->ie_len;
481
482         prMsgScanRequest = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, u4MsgSize);
483
484         if (prMsgScanRequest == NULL) {
485             ASSERT(FALSE);
486             i4RetRslt = -ENOMEM;
487             break;
488         }
489
490         DBGLOG(P2P, TRACE, ("Generating scan request message.\n"));
491
492         prMsgScanRequest->rMsgHdr.eMsgId = MID_MNY_P2P_DEVICE_DISCOVERY;
493
494
495
496         DBGLOG(P2P, TRACE, ("Requesting channel number:%d.\n", request->n_channels));
497
498         for (u4Idx = 0; u4Idx < request->n_channels; u4Idx++) {
499             /* Translate Freq from MHz to channel number. */
500             prRfChannelInfo = &(prMsgScanRequest->arChannelListInfo[u4Idx]);
501             prChannel = request->channels[u4Idx];
502
503             prRfChannelInfo->ucChannelNum = nicFreq2ChannelNum(prChannel->center_freq * 1000);
504             DBGLOG(P2P, TRACE, ("Scanning Channel:%d,  freq: %d\n",
505                                                         prRfChannelInfo->ucChannelNum,
506                                                         prChannel->center_freq));
507             switch (prChannel->band) {
508             case IEEE80211_BAND_2GHZ:
509                 prRfChannelInfo->eBand = BAND_2G4;
510                 break;
511             case IEEE80211_BAND_5GHZ:
512                 prRfChannelInfo->eBand = BAND_5G;
513                 break;
514             default:
515                 DBGLOG(P2P, TRACE, ("UNKNOWN Band info from supplicant\n"));
516                 prRfChannelInfo->eBand = BAND_NULL;
517                 break;
518             }
519
520             /* Iteration. */
521             prRfChannelInfo++;
522         }
523         prMsgScanRequest->u4NumChannel = request->n_channels;
524
525         DBGLOG(P2P, TRACE, ("Finish channel list.\n"));
526
527         /* SSID */
528         prSsid = request->ssids;
529         prSsidStruct = (P_P2P_SSID_STRUCT_T)prRfChannelInfo;
530         if (request->n_ssids) {
531             ASSERT(prSsidStruct == &(prMsgScanRequest->arChannelListInfo[u4Idx]));
532             prMsgScanRequest->prSSID = prSsidStruct;
533         }
534
535         for (u4Idx = 0; u4Idx < request->n_ssids; u4Idx++) {
536             COPY_SSID(prSsidStruct->aucSsid,
537                             prSsidStruct->ucSsidLen,
538                             request->ssids->ssid,
539                             request->ssids->ssid_len);
540
541             prSsidStruct++;
542             prSsid++;
543         }
544
545         prMsgScanRequest->i4SsidNum = request->n_ssids;
546
547         DBGLOG(P2P, TRACE, ("Finish SSID list:%d.\n", request->n_ssids));
548
549         /* IE BUFFERS */
550         prMsgScanRequest->pucIEBuf = (PUINT_8)prSsidStruct;
551         if (request->ie_len) {
552             kalMemCopy(prMsgScanRequest->pucIEBuf, request->ie, request->ie_len);
553             prMsgScanRequest->u4IELen = request->ie_len;
554         }
555
556         DBGLOG(P2P, TRACE, ("Finish IE Buffer.\n"));
557
558
559         mboxSendMsg(prGlueInfo->prAdapter,
560                 MBOX_ID_0,
561                 (P_MSG_HDR_T)prMsgScanRequest,
562                 MSG_SEND_METHOD_BUF);
563
564         i4RetRslt = 0;
565     } while (FALSE);
566
567     return i4RetRslt;
568 } /* mtk_p2p_cfg80211_scan */
569
570 int mtk_p2p_cfg80211_set_wiphy_params(
571     struct wiphy *wiphy,
572     u32 changed
573     )
574 {
575     INT_32 i4Rslt = -EINVAL;
576     P_GLUE_INFO_T prGlueInfo = NULL;
577
578
579     do {
580         if (wiphy == NULL) {
581             break;
582         }
583
584         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_wiphy_params\n"));
585         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
586
587         if (changed & WIPHY_PARAM_RETRY_SHORT) {
588             // TODO:
589             DBGLOG(P2P, TRACE, ("The RETRY short param is changed.\n"));
590         }
591
592         if (changed & WIPHY_PARAM_RETRY_LONG) {
593             // TODO:
594             DBGLOG(P2P, TRACE, ("The RETRY long param is changed.\n"));
595         }
596
597
598         if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
599             // TODO:
600             DBGLOG(P2P, TRACE, ("The RETRY fragmentation threshold is changed.\n"));
601         }
602
603         if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
604             // TODO:
605             DBGLOG(P2P, TRACE, ("The RETRY RTS threshold is changed.\n"));
606         }
607
608         if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
609             // TODO:
610             DBGLOG(P2P, TRACE, ("The coverage class is changed???\n"));
611         }
612
613         i4Rslt = 0;
614     } while (FALSE);
615
616
617
618
619     return i4Rslt;
620 } /* mtk_p2p_cfg80211_set_wiphy_params */
621
622
623
624 int
625 mtk_p2p_cfg80211_join_ibss(
626     struct wiphy *wiphy,
627     struct net_device *dev,
628     struct cfg80211_ibss_params *params
629     )
630 {
631     P_GLUE_INFO_T prGlueInfo = NULL;
632
633     ASSERT(wiphy);
634
635     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
636
637     // not implemented yet
638
639     return -EINVAL;
640 }
641
642 int
643 mtk_p2p_cfg80211_leave_ibss(
644     struct wiphy *wiphy,
645     struct net_device *dev
646     )
647 {
648     P_GLUE_INFO_T prGlueInfo = NULL;
649
650     ASSERT(wiphy);
651
652     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
653
654     // not implemented yet
655
656     return -EINVAL;
657 }
658
659 int
660 mtk_p2p_cfg80211_set_txpower(
661     struct wiphy *wiphy,
662     enum nl80211_tx_power_setting type,
663     int mbm
664     )
665 {
666     P_GLUE_INFO_T prGlueInfo = NULL;
667
668     ASSERT(wiphy);
669
670     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
671
672     // not implemented yet
673
674     return -EINVAL;
675 }
676
677 int
678 mtk_p2p_cfg80211_get_txpower(
679     struct wiphy *wiphy,
680     int *dbm
681     )
682 {
683     P_GLUE_INFO_T prGlueInfo = NULL;
684
685     ASSERT(wiphy);
686
687     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
688
689     // not implemented yet
690
691     return -EINVAL;
692 }
693
694 int
695 mtk_p2p_cfg80211_set_power_mgmt(
696     struct wiphy *wiphy,
697     struct net_device *dev,
698     bool enabled,
699     int timeout
700     )
701 {
702     P_GLUE_INFO_T prGlueInfo = NULL;
703         PARAM_POWER_MODE ePowerMode;
704
705     ASSERT(wiphy);
706
707     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
708
709         INT_32   value = enabled;
710         UINT_32 u4Leng;
711         WLAN_STATUS rStatus;
712     if(enabled) {
713         if(timeout == -1) {
714             ePowerMode = Param_PowerModeFast_PSP;
715         }
716         else {
717             ePowerMode = Param_PowerModeMAX_PSP;
718         }
719     }
720     else {
721         ePowerMode = Param_PowerModeCAM;
722     }
723
724         rStatus = kalIoctl(prGlueInfo,
725                         wlanoidSetP2pPowerSaveProfile,
726                         &ePowerMode,
727                         sizeof(ePowerMode),
728                         FALSE,
729                         FALSE,
730                         TRUE,
731                         TRUE,
732                         &u4Leng);
733         
734     if (rStatus != WLAN_STATUS_SUCCESS) {
735     DBGLOG(REQ, WARN, ("p2p set_power_mgmt error:%lx\n", rStatus));
736     return -EFAULT;
737     }
738
739                  return 0;
740 }
741
742 bool start_beacon;
743
744 //&&&&&&&&&&&&&&&&&&&&&&&&&& Add for ICS Wi-Fi Direct Support. &&&&&&&&&&&&&&&&&&&&&&&
745 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
746 int
747 mtk_p2p_cfg80211_start_ap (
748     struct wiphy *wiphy,
749     struct net_device *dev,
750     struct cfg80211_ap_settings *settings
751     )
752 {
753     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
754     INT_32 i4Rslt = -EINVAL;
755     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
756     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
757     PUINT_8 pucBuffer = (PUINT_8)NULL;
758 //    P_IE_SSID_T prSsidIE = (P_IE_SSID_T)NULL;
759         start_beacon = true;
760
761     do {
762         if ((wiphy == NULL) || (settings == NULL)) {
763             break;
764         }
765
766         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_start_ap.\n"));
767         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
768
769         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
770                                                                 prGlueInfo->prAdapter,
771                                                                 RAM_TYPE_MSG,
772                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + settings->beacon.head_len + settings->beacon.tail_len));
773
774         if (prP2pBcnUpdateMsg == NULL) {
775             ASSERT(FALSE);
776             i4Rslt = -ENOMEM;
777             break;
778         }
779
780
781         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
782         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
783
784         if (settings->beacon.head_len != 0) {
785             kalMemCopy(pucBuffer, settings->beacon.head, settings->beacon.head_len);
786
787             prP2pBcnUpdateMsg->u4BcnHdrLen = settings->beacon.head_len;
788
789             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
790
791             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)settings->beacon.head_len);
792         }
793         else {
794             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
795
796             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
797         }
798
799         if (settings->beacon.tail_len != 0) {
800             UINT_8 ucLen = settings->beacon.tail_len;
801
802             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
803
804             /*Add TIM IE*/
805             // IEEE 802.11 2007 - 7.3.2.6
806             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
807             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
808             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
809             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
810             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
811             ucLen += IE_SIZE(pucBuffer);
812             pucBuffer += IE_SIZE(pucBuffer);
813
814             kalMemCopy(pucBuffer, settings->beacon.tail, settings->beacon.tail_len);
815
816             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
817         }
818         else {
819             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
820
821             prP2pBcnUpdateMsg->pucBcnBody = NULL;
822         }
823
824
825         mboxSendMsg(prGlueInfo->prAdapter,
826                             MBOX_ID_0,
827                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
828                             MSG_SEND_METHOD_BUF);
829
830
831         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
832                                                         prGlueInfo->prAdapter,
833                                                         RAM_TYPE_MSG,
834                                                         sizeof(MSG_P2P_START_AP_T));
835
836         if (prP2pStartAPMsg == NULL) {
837             ASSERT(FALSE);
838             i4Rslt = -ENOMEM;
839             break;
840         }
841
842         prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
843
844         prP2pStartAPMsg->fgIsPrivacy = settings->privacy;
845
846         prP2pStartAPMsg->u4BcnInterval = settings->beacon_interval;
847
848         prP2pStartAPMsg->u4DtimPeriod = settings->dtim_period;
849
850         /* Copy NO SSID. */
851         prP2pStartAPMsg->ucHiddenSsidType = settings->hidden_ssid;
852
853         COPY_SSID(prP2pStartAPMsg->aucSsid,
854                         prP2pStartAPMsg->u2SsidLen,
855                         settings->ssid,
856                         settings->ssid_len);
857
858         mboxSendMsg(prGlueInfo->prAdapter,
859                             MBOX_ID_0,
860                             (P_MSG_HDR_T)prP2pStartAPMsg,
861                             MSG_SEND_METHOD_BUF);
862
863         i4Rslt = 0;
864
865     } while (FALSE);
866
867
868     return i4Rslt;
869
870
871 /////////////////////////
872     /**
873          * struct cfg80211_ap_settings - AP configuration
874          *
875          * Used to configure an AP interface.
876          *
877          * @beacon: beacon data
878          * @beacon_interval: beacon interval
879          * @dtim_period: DTIM period
880          * @ssid: SSID to be used in the BSS (note: may be %NULL if not provided from
881          *      user space)
882          * @ssid_len: length of @ssid
883          * @hidden_ssid: whether to hide the SSID in Beacon/Probe Response frames
884          * @crypto: crypto settings
885          * @privacy: the BSS uses privacy
886          * @auth_type: Authentication type (algorithm)
887          * @inactivity_timeout: time in seconds to determine station's inactivity.
888          */
889 //        struct cfg80211_ap_settings {
890 //                struct cfg80211_beacon_data beacon;
891 //
892 //                int beacon_interval, dtim_period;
893 //                const u8 *ssid;
894 //                size_t ssid_len;
895 //                enum nl80211_hidden_ssid hidden_ssid;
896 //                struct cfg80211_crypto_settings crypto;
897 //                bool privacy;
898 //                enum nl80211_auth_type auth_type;
899 //                int inactivity_timeout;
900 //        };
901 ////////////////////
902
903     return i4Rslt;
904 } /* mtk_p2p_cfg80211_start_ap */
905
906
907 int
908 mtk_p2p_cfg80211_change_beacon (
909     struct wiphy *wiphy,
910     struct net_device *dev,
911     struct cfg80211_beacon_data *info
912     )
913 {
914     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
915     INT_32 i4Rslt = -EINVAL;
916     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
917     PUINT_8 pucBuffer = (PUINT_8)NULL;
918         start_beacon = false;
919         
920     do {
921         if ((wiphy == NULL) || (info == NULL)) {
922             break;
923         }
924
925         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_beacon.\n"));
926         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
927
928         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
929                                                                 prGlueInfo->prAdapter,
930                                                                 RAM_TYPE_MSG,
931                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
932
933
934         if (prP2pBcnUpdateMsg == NULL) {
935             ASSERT(FALSE);
936             i4Rslt = -ENOMEM;
937             break;
938         }
939
940         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
941         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
942
943         if (info->head_len != 0) {
944             kalMemCopy(pucBuffer, info->head, info->head_len);
945
946             prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
947
948             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
949
950             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
951         }
952         else {
953             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
954
955             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
956         }
957
958         if (info->tail_len != 0) {
959             UINT_8 ucLen = info->tail_len;
960
961             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
962
963             /*Add TIM IE*/
964             // IEEE 802.11 2007 - 7.3.2.6
965             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
966             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
967             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
968             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
969             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
970             ucLen += IE_SIZE(pucBuffer);
971             pucBuffer += IE_SIZE(pucBuffer);
972
973             kalMemCopy(pucBuffer, info->tail, info->tail_len);
974
975             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
976         }
977         else {
978             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
979
980             prP2pBcnUpdateMsg->pucBcnBody = NULL;
981         }
982
983
984         mboxSendMsg(prGlueInfo->prAdapter,
985                             MBOX_ID_0,
986                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
987                             MSG_SEND_METHOD_BUF);
988
989 ////////////////////////////
990 /**
991  * struct cfg80211_beacon_data - beacon data
992  * @head: head portion of beacon (before TIM IE)
993  *     or %NULL if not changed
994  * @tail: tail portion of beacon (after TIM IE)
995  *     or %NULL if not changed
996  * @head_len: length of @head
997  * @tail_len: length of @tail
998  * @beacon_ies: extra information element(s) to add into Beacon frames or %NULL
999  * @beacon_ies_len: length of beacon_ies in octets
1000  * @proberesp_ies: extra information element(s) to add into Probe Response
1001  *      frames or %NULL
1002  * @proberesp_ies_len: length of proberesp_ies in octets
1003  * @assocresp_ies: extra information element(s) to add into (Re)Association
1004  *      Response frames or %NULL
1005  * @assocresp_ies_len: length of assocresp_ies in octets
1006  * @probe_resp_len: length of probe response template (@probe_resp)
1007  * @probe_resp: probe response template (AP mode only)
1008  */
1009 //struct cfg80211_beacon_data {
1010 //        const u8 *head, *tail;
1011 //        const u8 *beacon_ies;
1012 //        const u8 *proberesp_ies;
1013 //        const u8 *assocresp_ies;
1014 //        const u8 *probe_resp;
1015
1016 //        size_t head_len, tail_len;
1017 //        size_t beacon_ies_len;
1018 //        size_t proberesp_ies_len;
1019 //        size_t assocresp_ies_len;
1020 //        size_t probe_resp_len;
1021 //};
1022
1023 ////////////////////////////
1024
1025     } while (FALSE);
1026
1027     return i4Rslt;
1028 } /* mtk_p2p_cfg80211_change_beacon */
1029
1030 #else
1031 int
1032 mtk_p2p_cfg80211_add_set_beacon (
1033     struct wiphy *wiphy,
1034     struct net_device *dev,
1035     struct beacon_parameters *info
1036     )
1037 {
1038     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1039     INT_32 i4Rslt = -EINVAL;
1040     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
1041     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
1042     PUINT_8 pucBuffer = (PUINT_8)NULL;
1043     P_IE_SSID_T prSsidIE = (P_IE_SSID_T)NULL;
1044         start_beacon = true;
1045
1046     do {
1047         if ((wiphy == NULL) || (info == NULL)) {
1048             break;
1049         }
1050
1051         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_add_set_beacon.\n"));
1052         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1053
1054         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
1055                                                                 prGlueInfo->prAdapter,
1056                                                                 RAM_TYPE_MSG,
1057                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
1058
1059         if (prP2pBcnUpdateMsg == NULL) {
1060             ASSERT(FALSE);
1061             i4Rslt = -ENOMEM;
1062             break;
1063         }
1064         kalMemZero(prP2pBcnUpdateMsg, (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
1065
1066         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
1067         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
1068
1069         if (info->head_len != 0) {
1070             kalMemCopy(pucBuffer, info->head, info->head_len);
1071
1072             prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
1073
1074             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
1075
1076             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
1077         }
1078         else {
1079             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
1080
1081             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
1082         }
1083
1084         if (info->tail_len != 0) {
1085             UINT_8 ucLen = info->tail_len;
1086
1087             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
1088
1089             /*Add TIM IE*/
1090             // IEEE 802.11 2007 - 7.3.2.6
1091             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
1092             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
1093             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
1094             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
1095             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
1096             ucLen += IE_SIZE(pucBuffer);
1097             pucBuffer += IE_SIZE(pucBuffer);
1098
1099             kalMemCopy(pucBuffer, info->tail, info->tail_len);
1100
1101             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
1102         }
1103         else {
1104             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
1105
1106             prP2pBcnUpdateMsg->pucBcnBody = NULL;
1107         }
1108
1109
1110         mboxSendMsg(prGlueInfo->prAdapter,
1111                             MBOX_ID_0,
1112                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
1113                             MSG_SEND_METHOD_BUF);
1114
1115
1116         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
1117                                                         prGlueInfo->prAdapter,
1118                                                         RAM_TYPE_MSG,
1119                                                         sizeof(MSG_P2P_START_AP_T));
1120
1121         if (prP2pStartAPMsg == NULL) {
1122             ASSERT(FALSE);
1123             i4Rslt = -ENOMEM;
1124             break;
1125         }
1126         kalMemZero(prP2pStartAPMsg, sizeof(MSG_P2P_START_AP_T));
1127
1128         prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
1129                 printk("mtk_p2p_cfg80211_add_set_beacon MID_MNY_P2P_START_AP");
1130
1131         prP2pStartAPMsg->fgIsPrivacy = FALSE;
1132
1133         prP2pStartAPMsg->u4BcnInterval = info->interval;
1134
1135         prP2pStartAPMsg->u4DtimPeriod = info->dtim_period;
1136
1137         /* Copy NO SSID. */
1138         prP2pStartAPMsg->ucHiddenSsidType = ENUM_HIDDEN_SSID_NONE;
1139
1140 #if 0
1141         if (info->head_len > OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)) {
1142             P_WLAN_BEACON_FRAME_T prWlanBcnFrame = info->head;
1143
1144             prSsidIE = (P_IE_HDR_T)p2pFuncGetSpecIE(prGlueInfo->prAdapter,
1145                                     (PUINT_8)prWlanBcnFrame->aucInfoElem,
1146                                     (info->head_len - OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)),
1147                                     ELEM_ID_SSID,
1148                                     NULL);
1149
1150             kalMemCopy(prP2pStartAPMsg->aucSsid, SSID_IE(prSsidIE)->aucSSID, IE_LEN(prSsidIE));
1151
1152         }
1153 #endif
1154
1155         mboxSendMsg(prGlueInfo->prAdapter,
1156                             MBOX_ID_0,
1157                             (P_MSG_HDR_T)prP2pStartAPMsg,
1158                             MSG_SEND_METHOD_BUF);
1159
1160         i4Rslt = 0;
1161
1162     } while (FALSE);
1163
1164     return i4Rslt;
1165 }
1166 /* mtk_p2p_cfg80211_add_set_beacon */
1167 int
1168 mtk_p2p_cfg80211_add_set_beacon_1 (
1169     struct wiphy *wiphy,
1170     struct net_device *dev,
1171     struct beacon_parameters *info
1172     )
1173 {
1174     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1175     INT_32 i4Rslt = -EINVAL;
1176     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
1177     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
1178     PUINT_8 pucBuffer = (PUINT_8)NULL;
1179     P_IE_SSID_T prSsidIE = (P_IE_SSID_T)NULL;
1180         start_beacon = false;
1181
1182     do {
1183         if ((wiphy == NULL) || (info == NULL)) {
1184             break;
1185         }
1186
1187         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_add_set_beacon_1.\n"));
1188         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1189
1190         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
1191                                                                 prGlueInfo->prAdapter,
1192                                                                 RAM_TYPE_MSG,
1193                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
1194
1195         if (prP2pBcnUpdateMsg == NULL) {
1196             ASSERT(FALSE);
1197             i4Rslt = -ENOMEM;
1198             break;
1199         }
1200         kalMemZero(prP2pBcnUpdateMsg, (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
1201
1202         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
1203         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
1204
1205         if (info->head_len != 0) {
1206             kalMemCopy(pucBuffer, info->head, info->head_len);
1207
1208             prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
1209
1210             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
1211
1212             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
1213         }
1214         else {
1215             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
1216
1217             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
1218         }
1219
1220         if (info->tail_len != 0) {
1221             UINT_8 ucLen = info->tail_len;
1222
1223             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
1224
1225             /*Add TIM IE*/
1226             // IEEE 802.11 2007 - 7.3.2.6
1227             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
1228             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
1229             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
1230             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
1231             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
1232             ucLen += IE_SIZE(pucBuffer);
1233             pucBuffer += IE_SIZE(pucBuffer);
1234
1235             kalMemCopy(pucBuffer, info->tail, info->tail_len);
1236
1237             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
1238         }
1239         else {
1240             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
1241
1242             prP2pBcnUpdateMsg->pucBcnBody = NULL;
1243         }
1244
1245
1246         mboxSendMsg(prGlueInfo->prAdapter,
1247                             MBOX_ID_0,
1248                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
1249                             MSG_SEND_METHOD_BUF);
1250
1251
1252         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
1253                                                         prGlueInfo->prAdapter,
1254                                                         RAM_TYPE_MSG,
1255                                                         sizeof(MSG_P2P_START_AP_T));
1256
1257         if (prP2pStartAPMsg == NULL) {
1258             ASSERT(FALSE);
1259             i4Rslt = -ENOMEM;
1260             break;
1261         }
1262         kalMemZero(prP2pStartAPMsg, sizeof(MSG_P2P_START_AP_T));
1263
1264         prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
1265                 printk("mtk_p2p_cfg80211_add_set_beacon_1 MID_MNY_P2P_START_AP");
1266
1267         prP2pStartAPMsg->fgIsPrivacy = FALSE;
1268
1269         prP2pStartAPMsg->u4BcnInterval = info->interval;
1270
1271         prP2pStartAPMsg->u4DtimPeriod = info->dtim_period;
1272
1273         /* Copy NO SSID. */
1274         prP2pStartAPMsg->ucHiddenSsidType = ENUM_HIDDEN_SSID_NONE;
1275
1276 #if 0
1277         if (info->head_len > OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)) {
1278             P_WLAN_BEACON_FRAME_T prWlanBcnFrame = info->head;
1279
1280             prSsidIE = (P_IE_HDR_T)p2pFuncGetSpecIE(prGlueInfo->prAdapter,
1281                                     (PUINT_8)prWlanBcnFrame->aucInfoElem,
1282                                     (info->head_len - OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)),
1283                                     ELEM_ID_SSID,
1284                                     NULL);
1285
1286             kalMemCopy(prP2pStartAPMsg->aucSsid, SSID_IE(prSsidIE)->aucSSID, IE_LEN(prSsidIE));
1287
1288         }
1289 #endif
1290
1291         mboxSendMsg(prGlueInfo->prAdapter,
1292                             MBOX_ID_0,
1293                             (P_MSG_HDR_T)prP2pStartAPMsg,
1294                             MSG_SEND_METHOD_BUF);
1295
1296         i4Rslt = 0;
1297
1298     } while (FALSE);
1299
1300     return i4Rslt;
1301 }
1302 /* mtk_p2p_cfg80211_add_set_beacon */
1303
1304 #endif
1305
1306 int
1307 mtk_p2p_cfg80211_stop_ap (
1308     struct wiphy *wiphy,
1309     struct net_device *dev
1310     )
1311 {
1312     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1313     INT_32 i4Rslt = -EINVAL;
1314     P_MSG_P2P_SWITCH_OP_MODE_T prP2pSwitchMode = (P_MSG_P2P_SWITCH_OP_MODE_T)NULL;
1315
1316     do {
1317         if (wiphy == NULL) {
1318             break;
1319         }
1320
1321
1322         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_stop_ap.\n"));
1323         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1324
1325         // Switch OP MOde.
1326         prP2pSwitchMode = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
1327
1328         if (prP2pSwitchMode == NULL) {
1329             ASSERT(FALSE);
1330             i4Rslt = -ENOMEM;
1331             break;
1332         }
1333
1334         prP2pSwitchMode->rMsgHdr.eMsgId = MID_MNY_P2P_STOP_AP;
1335
1336         mboxSendMsg(prGlueInfo->prAdapter,
1337                             MBOX_ID_0,
1338                             (P_MSG_HDR_T)prP2pSwitchMode,
1339                             MSG_SEND_METHOD_BUF);
1340
1341         i4Rslt = 0;
1342     } while (FALSE);
1343         
1344 #ifdef CFG_DUAL_ANTENNA
1345         if(p2pFuncIsAPMode(prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo))
1346                 wifi2bwcs_connection_event_ind_handler(prGlueInfo->prAdapter->prGlueInfo, WIFI_EVENT_SOFTAP_CONN_DEL);
1347         else
1348                 wifi2bwcs_connection_event_ind_handler(prGlueInfo->prAdapter->prGlueInfo, WIFI_EVENT_P2P_GO_CONN_DEL);
1349 #endif
1350
1351
1352     return i4Rslt;
1353 } /* mtk_p2p_cfg80211_stop_ap */
1354
1355 // TODO:
1356 int
1357 mtk_p2p_cfg80211_deauth (
1358     struct wiphy *wiphy,
1359     struct net_device *dev,
1360     struct cfg80211_deauth_request *req
1361 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
1362     , void *cookie
1363 #endif
1364     )
1365 {
1366     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1367
1368     ASSERT(wiphy);
1369
1370     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1371
1372     // not implemented yet
1373     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_deauth.\n"));
1374
1375     return -EINVAL;
1376 } /* mtk_p2p_cfg80211_deauth */
1377
1378
1379 // TODO:
1380 int
1381 mtk_p2p_cfg80211_disassoc (
1382     struct wiphy *wiphy,
1383     struct net_device *dev,
1384     struct cfg80211_disassoc_request *req
1385 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
1386     , void *cookie
1387 #endif
1388     )
1389 {
1390     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1391
1392     ASSERT(wiphy);
1393
1394     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1395
1396     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disassoc.\n"));
1397
1398     // not implemented yet
1399
1400     return -EINVAL;
1401 } /* mtk_p2p_cfg80211_disassoc */
1402
1403
1404 #if 0//LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
1405 int
1406 mtk_p2p_cfg80211_remain_on_channel2 (
1407     struct wiphy *wiphy,
1408     struct net_device *dev,
1409     struct ieee80211_channel *chan,
1410     enum nl80211_channel_type channel_type,
1411     unsigned int duration,
1412     u64 *cookie,
1413     bool fgNeedIndSupp
1414     )
1415 {
1416     INT_32 i4Rslt = -EINVAL;
1417     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1418     P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1419     P_MSG_P2P_CHNL_REQUEST_T prMsgChnlReq = (P_MSG_P2P_CHNL_REQUEST_T)NULL;
1420
1421
1422     do {
1423         if ((wiphy == NULL) ||
1424                 (dev == NULL) ||
1425                 (chan == NULL) ||
1426                 (cookie == NULL)) {
1427             break;
1428         }
1429         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1430         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1431
1432         //*cookie = prGlueP2pInfo->u8Cookie++;
1433
1434         prMsgChnlReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_REQUEST_T));
1435
1436         if (prMsgChnlReq == NULL) {
1437             ASSERT(FALSE);
1438             i4Rslt = -ENOMEM;
1439             break;
1440         }
1441
1442         //DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_remain_on_channel\n"));
1443
1444         prMsgChnlReq->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_REQ;
1445         prMsgChnlReq->u8Cookie = *cookie;
1446         prMsgChnlReq->u4Duration = duration;
1447         prMsgChnlReq->fgNeedIndSupp = fgNeedIndSupp;
1448
1449
1450         mtk_p2p_cfg80211func_channel_format_switch(chan,
1451                                                     channel_type,
1452                                                     &prMsgChnlReq->rChannelInfo,
1453                                                     &prMsgChnlReq->eChnlSco);
1454
1455         
1456         mboxSendMsg(prGlueInfo->prAdapter,
1457                             MBOX_ID_0,
1458                             (P_MSG_HDR_T)prMsgChnlReq,
1459                             MSG_SEND_METHOD_BUF);
1460
1461         i4Rslt = 0;
1462     } while (FALSE);
1463
1464
1465     return i4Rslt;
1466 }
1467 /* mtk_p2p_cfg80211_remain_on_channel */
1468
1469 int
1470 mtk_p2p_cfg80211_remain_on_channel (
1471     struct wiphy *wiphy,
1472     struct net_device *dev,
1473     struct ieee80211_channel *chan,
1474     enum nl80211_channel_type channel_type,
1475     unsigned int duration,
1476     u64 *cookie
1477     )
1478 {
1479         int ret = -1, atom;
1480         P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1481         P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1482
1483         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1484         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1485         *cookie = prGlueP2pInfo->u8Cookie++;
1486
1487         if(atomic_read(&prGlueInfo->rMgmtTxAto) == 1) {
1488                 ret = wait_for_completion_timeout(&prGlueInfo->rMgmtTxComp, 500*HZ/1000);
1489         } 
1490
1491         ret = mtk_p2p_cfg80211_remain_on_channel2(wiphy, dev, chan, channel_type, duration, cookie, true);
1492
1493         return ret;
1494 }
1495 #else
1496 int
1497 mtk_p2p_cfg80211_remain_on_channel (
1498     struct wiphy *wiphy,
1499     struct net_device *dev,
1500     struct ieee80211_channel *chan,
1501     enum nl80211_channel_type channel_type,
1502     unsigned int duration,
1503     u64 *cookie
1504     )
1505 {
1506     INT_32 i4Rslt = -EINVAL;
1507     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1508     P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1509     P_MSG_P2P_CHNL_REQUEST_T prMsgChnlReq = (P_MSG_P2P_CHNL_REQUEST_T)NULL;
1510
1511
1512     do {
1513         if ((wiphy == NULL) ||
1514                 (dev == NULL) ||
1515                 (chan == NULL) ||
1516                 (cookie == NULL)) {
1517             break;
1518         }
1519         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1520         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1521
1522         *cookie = prGlueP2pInfo->u8Cookie++;
1523
1524         prMsgChnlReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_REQUEST_T));
1525
1526         if (prMsgChnlReq == NULL) {
1527             ASSERT(FALSE);
1528             i4Rslt = -ENOMEM;
1529             break;
1530         }
1531
1532         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_remain_on_channel\n"));
1533
1534         prMsgChnlReq->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_REQ;
1535         prMsgChnlReq->u8Cookie = *cookie;
1536         prMsgChnlReq->u4Duration = duration;
1537
1538
1539         mtk_p2p_cfg80211func_channel_format_switch(chan,
1540                                                     channel_type,
1541                                                     &prMsgChnlReq->rChannelInfo,
1542                                                     &prMsgChnlReq->eChnlSco);
1543
1544                 mboxSendMsg(prGlueInfo->prAdapter,
1545                             MBOX_ID_0,
1546                             (P_MSG_HDR_T)prMsgChnlReq,
1547                             MSG_SEND_METHOD_BUF);
1548
1549         i4Rslt = 0;
1550
1551         i4Rslt = 0;
1552     } while (FALSE);
1553
1554
1555     return i4Rslt;
1556 }
1557 /* mtk_p2p_cfg80211_remain_on_channel */
1558 #endif
1559
1560
1561
1562 int
1563 mtk_p2p_cfg80211_cancel_remain_on_channel (
1564     struct wiphy *wiphy,
1565     struct net_device *dev,
1566     u64 cookie
1567     )
1568 {
1569     INT_32 i4Rslt = -EINVAL;
1570     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1571     P_MSG_P2P_CHNL_ABORT_T prMsgChnlAbort = (P_MSG_P2P_CHNL_ABORT_T)NULL;
1572
1573     do {
1574         if ((wiphy == NULL) || (dev == NULL)) {
1575             break;
1576         }
1577
1578
1579         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1580
1581         prMsgChnlAbort = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_ABORT_T));
1582
1583         if (prMsgChnlAbort == NULL) {
1584             ASSERT(FALSE);
1585             i4Rslt = -ENOMEM;
1586             break;
1587         }
1588
1589         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_cancel_remain_on_channel\n"));
1590
1591         prMsgChnlAbort->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_ABORT;
1592         prMsgChnlAbort->u8Cookie = cookie;
1593
1594
1595         mboxSendMsg(prGlueInfo->prAdapter,
1596                                     MBOX_ID_0,
1597                                     (P_MSG_HDR_T)prMsgChnlAbort,
1598                                     MSG_SEND_METHOD_BUF);
1599
1600         i4Rslt = 0;
1601     } while (FALSE);
1602
1603     return i4Rslt;
1604 } /* mtk_p2p_cfg80211_cancel_remain_on_channel */
1605
1606 #if 0 //LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
1607 int
1608 mtk_p2p_cfg80211_mgmt_tx (
1609     struct wiphy *wiphy, struct net_device *dev,
1610     struct ieee80211_channel *chan, bool offchan,
1611     enum nl80211_channel_type channel_type,
1612     bool channel_type_valid, unsigned int wait,
1613     const u8 *buf,
1614     size_t len,
1615 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
1616         bool no_cck,
1617 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
1618         bool dont_wait_for_ack,
1619 #endif
1620 #endif
1621         u64 *cookie
1622
1623     )
1624 {
1625         P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1626         P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1627         INT_32 i4Rslt = -EINVAL;
1628         INT_32 channel_time= 0;
1629         P_MSG_P2P_MGMT_TX_REQUEST_T prMsgTxReq = (P_MSG_P2P_MGMT_TX_REQUEST_T)NULL;
1630         P_MSDU_INFO_T prMgmtFrame = (P_MSDU_INFO_T)NULL;
1631         PUINT_8 pucFrameBuf = (PUINT_8)NULL;
1632         P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T)NULL;
1633         RF_CHANNEL_INFO_T ChnlInfo;
1634         ENUM_CHNL_EXT_T ChnlSco;
1635         do {
1636                 if ((wiphy == NULL) ||
1637                                 (buf == NULL) ||
1638                                 (len == 0) ||
1639                                 (dev == NULL) ||
1640                                 (cookie == NULL)) {
1641                         break;
1642                 }
1643                 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1644                 prGlueP2pInfo = prGlueInfo->prP2PInfo;
1645                 prP2pFsmInfo = prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo;
1646                 P_P2P_CHNL_REQ_INFO_T prChnlReqInfo = &(prP2pFsmInfo->rChnlReqInfo);
1647
1648                 mtk_p2p_cfg80211func_channel_format_switch(chan,
1649                                 channel_type,
1650                                 &ChnlInfo,
1651                                 &ChnlSco);
1652                 if (prChnlReqInfo->prMsgTxReq!=NULL){
1653                         i4Rslt = -ENOMEM;
1654                         break;
1655                 }
1656                 channel_time=wait;
1657                 //buffer mgmt frame into driver
1658                 *cookie = prGlueP2pInfo->u8Cookie++;
1659
1660                 /* Channel & Channel Type & Wait time are ignored. */
1661                 prMsgTxReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_MGMT_TX_REQUEST_T));
1662
1663                 if (prMsgTxReq == NULL) {
1664                         ASSERT(FALSE);
1665                         i4Rslt = -ENOMEM;
1666                         break;
1667                 }
1668
1669                 prMsgTxReq->fgNoneCckRate = FALSE;
1670                 prMsgTxReq->fgIsWaitRsp = TRUE;
1671
1672                 prMgmtFrame = cnmMgtPktAlloc(prGlueInfo->prAdapter, (UINT_32)(len + MAC_TX_RESERVED_FIELD));
1673
1674                 if ((prMsgTxReq->prMgmtMsduInfo = prMgmtFrame) == NULL) {
1675                         ASSERT(FALSE);
1676                         i4Rslt = -ENOMEM;
1677                         break;
1678                 }
1679
1680                 prMsgTxReq->u8Cookie = *cookie;
1681                 prMsgTxReq->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_TX;
1682
1683                 pucFrameBuf = (PUINT_8)((UINT_32)prMgmtFrame->prPacket + MAC_TX_RESERVED_FIELD);
1684
1685                 kalMemCopy(pucFrameBuf, buf, len);
1686
1687                 prMgmtFrame->u2FrameLength = len;
1688
1689                 if (wait==0&&prChnlReqInfo->ucReqChnlNum==ChnlInfo.ucChannelNum&&
1690                                 prChnlReqInfo->eBand==ChnlInfo.eBand&&
1691                                 prChnlReqInfo->eChnlSco==ChnlSco){
1692                         mboxSendMsg(prGlueInfo->prAdapter,
1693                                         MBOX_ID_0,
1694                                         (P_MSG_HDR_T)prMsgTxReq,
1695                                         MSG_SEND_METHOD_BUF);
1696                         i4Rslt=0;
1697                         break;
1698                 }
1699
1700                 prChnlReqInfo->prMsgTxReq=prMsgTxReq;
1701
1702                 atomic_set(&prGlueInfo->rMgmtTxAto, 1);
1703                 i4Rslt=mtk_p2p_cfg80211_remain_on_channel2(wiphy,dev,chan,channel_type,channel_time, cookie, false);
1704         } while (FALSE);
1705         channel_time=0;
1706         return i4Rslt;
1707 } /* mtk_p2p_cfg80211_mgmt_tx */
1708 #else
1709 int
1710 mtk_p2p_cfg80211_mgmt_tx (
1711     struct wiphy *wiphy, struct net_device *dev,
1712     struct ieee80211_channel *chan, bool offchan,
1713     enum nl80211_channel_type channel_type,
1714     bool channel_type_valid, unsigned int wait,
1715     const u8 *buf,
1716     size_t len,
1717 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
1718         bool no_cck,
1719 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
1720         bool dont_wait_for_ack,
1721 #endif
1722 #endif
1723         u64 *cookie
1724
1725     )
1726 {
1727     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1728     P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1729     INT_32 i4Rslt = -EINVAL;
1730     P_MSG_P2P_MGMT_TX_REQUEST_T prMsgTxReq = (P_MSG_P2P_MGMT_TX_REQUEST_T)NULL;
1731     P_MSDU_INFO_T prMgmtFrame = (P_MSDU_INFO_T)NULL;
1732     PUINT_8 pucFrameBuf = (PUINT_8)NULL;
1733
1734     do {
1735         if ((wiphy == NULL) ||
1736                 (buf == NULL) ||
1737                 (len == 0) ||
1738                 (dev == NULL) ||
1739                 (cookie == NULL)) {
1740             break;
1741         }
1742
1743         //DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_mgmt_tx\n"));
1744
1745         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1746         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1747
1748         *cookie = prGlueP2pInfo->u8Cookie++;
1749
1750         /* Channel & Channel Type & Wait time are ignored. */
1751         prMsgTxReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_MGMT_TX_REQUEST_T));
1752
1753         if (prMsgTxReq == NULL) {
1754             ASSERT(FALSE);
1755             i4Rslt = -ENOMEM;
1756             break;
1757         }
1758
1759         prMsgTxReq->fgNoneCckRate = FALSE;
1760         prMsgTxReq->fgIsWaitRsp = TRUE;
1761
1762         prMgmtFrame = cnmMgtPktAlloc(prGlueInfo->prAdapter, (UINT_32)(len + MAC_TX_RESERVED_FIELD));
1763
1764         if ((prMsgTxReq->prMgmtMsduInfo = prMgmtFrame) == NULL) {
1765             ASSERT(FALSE);
1766             i4Rslt = -ENOMEM;
1767             break;
1768         }
1769
1770         prMsgTxReq->u8Cookie = *cookie;
1771         prMsgTxReq->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_TX;
1772
1773         pucFrameBuf = (PUINT_8)((UINT_32)prMgmtFrame->prPacket + MAC_TX_RESERVED_FIELD);
1774
1775         kalMemCopy(pucFrameBuf, buf, len);
1776
1777         prMgmtFrame->u2FrameLength = len;
1778
1779         mboxSendMsg(prGlueInfo->prAdapter,
1780                             MBOX_ID_0,
1781                             (P_MSG_HDR_T)prMsgTxReq,
1782                             MSG_SEND_METHOD_BUF);
1783
1784         i4Rslt = 0;
1785     } while (FALSE);
1786
1787     if ((i4Rslt != 0) && (prMsgTxReq != NULL)) {
1788         if (prMsgTxReq->prMgmtMsduInfo != NULL) {
1789             cnmMgtPktFree(prGlueInfo->prAdapter, prMsgTxReq->prMgmtMsduInfo);
1790         }
1791
1792         cnmMemFree(prGlueInfo->prAdapter, prMsgTxReq);
1793     }
1794
1795     return i4Rslt;
1796 } /* mtk_p2p_cfg80211_mgmt_tx */
1797 #endif
1798
1799
1800
1801 /*----------------------------------------------------------------------------*/
1802 /*!
1803  * @brief This routine is responsible for requesting to cancel the wait time
1804  *        from transmitting a management frame on another channel
1805  *
1806  * @param 
1807  *
1808  * @retval 0:       successful
1809  *         others:  failure
1810  */
1811 /*----------------------------------------------------------------------------*/
1812 int
1813 mtk_p2p_cfg80211_mgmt_tx_cancel_wait (
1814     struct wiphy *wiphy,
1815     struct net_device *ndev,
1816     u64 cookie
1817     )
1818 {
1819     P_GLUE_INFO_T prGlueInfo = NULL;
1820
1821     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1822     ASSERT(prGlueInfo);
1823
1824 #if 1
1825     printk("--> %s()\n", __func__);
1826 #endif
1827
1828     /* not implemented */
1829         return 0;
1830 //    return -EINVAL;
1831 }
1832
1833
1834 int
1835 mtk_p2p_cfg80211_change_bss (
1836     struct wiphy *wiphy,
1837     struct net_device *dev,
1838     struct bss_parameters *params
1839     )
1840 {
1841     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1842     INT_32 i4Rslt = -EINVAL;
1843
1844     ASSERT(wiphy);
1845
1846     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1847
1848
1849     switch (params->use_cts_prot) {
1850     case -1:
1851         DBGLOG(P2P, TRACE, ("CTS protection no change\n"));
1852         break;
1853     case 0:
1854         DBGLOG(P2P, TRACE, ("CTS protection disable.\n"));
1855         break;
1856     case 1:
1857         DBGLOG(P2P, TRACE, ("CTS protection enable\n"));
1858         break;
1859     default:
1860         DBGLOG(P2P, TRACE, ("CTS protection unknown\n"));
1861         break;
1862     }
1863
1864
1865
1866     switch (params->use_short_preamble) {
1867     case -1:
1868         DBGLOG(P2P, TRACE, ("Short prreamble no change\n"));
1869         break;
1870     case 0:
1871         DBGLOG(P2P, TRACE, ("Short prreamble disable.\n"));
1872         break;
1873     case 1:
1874         DBGLOG(P2P, TRACE, ("Short prreamble enable\n"));
1875         break;
1876     default:
1877         DBGLOG(P2P, TRACE, ("Short prreamble unknown\n"));
1878         break;
1879     }
1880
1881
1882
1883 #if 0
1884     // not implemented yet
1885     p2pFuncChangeBssParam(prGlueInfo->prAdapter,
1886                         prBssInfo->fgIsProtection,
1887                         prBssInfo->fgIsShortPreambleAllowed,
1888                         prBssInfo->fgUseShortSlotTime,
1889                         // Basic rates
1890                         // basic rates len
1891                         // ap isolate
1892                         // ht opmode.
1893                         );
1894 #else
1895     i4Rslt = 0;
1896 #endif
1897
1898     return i4Rslt;
1899 } /* mtk_p2p_cfg80211_change_bss */
1900
1901
1902
1903 int
1904 mtk_p2p_cfg80211_del_station (
1905     struct wiphy *wiphy,
1906     struct net_device *dev,
1907     u8 *mac
1908     )
1909 {
1910     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1911     INT_32 i4Rslt = -EINVAL;
1912     P_MSG_P2P_CONNECTION_ABORT_T prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
1913     UINT_8 aucBcMac[] = BC_MAC_ADDR;
1914
1915
1916     do {
1917         if ((wiphy == NULL) ||
1918                     (dev == NULL)) {
1919             break;
1920         }
1921
1922         if (mac == NULL) {
1923             mac = aucBcMac;
1924         }
1925
1926         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_del_station.\n"));
1927
1928         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1929
1930         //prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)kalMemAlloc(sizeof(MSG_P2P_CONNECTION_ABORT_T), VIR_MEM_TYPE);
1931         prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
1932
1933         if (prDisconnectMsg == NULL) {
1934             ASSERT(FALSE);
1935             i4Rslt = -ENOMEM;
1936             break;
1937         }
1938
1939         prDisconnectMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
1940         COPY_MAC_ADDR(prDisconnectMsg->aucTargetID, mac);
1941         prDisconnectMsg->u2ReasonCode = REASON_CODE_UNSPECIFIED;
1942
1943         mboxSendMsg(prGlueInfo->prAdapter,
1944                         MBOX_ID_0,
1945                         (P_MSG_HDR_T)prDisconnectMsg,
1946                         MSG_SEND_METHOD_BUF);
1947
1948         i4Rslt = 0;
1949     } while (FALSE);
1950
1951     return i4Rslt;
1952
1953 } /* mtk_p2p_cfg80211_del_station */
1954
1955
1956 int 
1957 mtk_p2p_cfg80211_connect (
1958     struct wiphy *wiphy,
1959     struct net_device *dev,
1960     struct cfg80211_connect_params *sme
1961     )
1962 {
1963     INT_32 i4Rslt = -EINVAL;
1964     P_GLUE_INFO_T prGlueInfo = NULL;
1965     P_MSG_P2P_CONNECTION_REQUEST_T prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
1966
1967
1968     do {
1969         if ((wiphy == NULL) ||
1970                 (dev == NULL) ||
1971                 (sme == NULL)) {
1972             break;
1973         }
1974
1975         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_connect.\n"));
1976
1977         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1978
1979         prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, (sizeof(MSG_P2P_CONNECTION_REQUEST_T) + sme->ie_len));
1980
1981         if (prConnReqMsg == NULL) {
1982             ASSERT(FALSE);
1983             i4Rslt = -ENOMEM;
1984             break;
1985         }
1986
1987         prConnReqMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
1988
1989         COPY_SSID(prConnReqMsg->rSsid.aucSsid,
1990                                 prConnReqMsg->rSsid.ucSsidLen,
1991                                 sme->ssid,
1992                                 sme->ssid_len);
1993
1994         COPY_MAC_ADDR(prConnReqMsg->aucBssid, sme->bssid);
1995
1996         DBGLOG(P2P, TRACE, ("Assoc Req IE Buffer Length:%d\n", sme->ie_len));
1997         kalMemCopy(prConnReqMsg->aucIEBuf, sme->ie, sme->ie_len);
1998         prConnReqMsg->u4IELen = sme->ie_len;
1999
2000         mtk_p2p_cfg80211func_channel_format_switch(sme->channel,
2001                                                     NL80211_CHAN_NO_HT,
2002                                                     &prConnReqMsg->rChannelInfo,
2003                                                     &prConnReqMsg->eChnlSco);
2004
2005         mboxSendMsg(prGlueInfo->prAdapter,
2006                         MBOX_ID_0,
2007                         (P_MSG_HDR_T)prConnReqMsg,
2008                         MSG_SEND_METHOD_BUF);
2009
2010
2011         i4Rslt = 0;
2012     } while (FALSE);
2013
2014     return i4Rslt;
2015 } /* mtk_p2p_cfg80211_connect */
2016
2017 int 
2018 mtk_p2p_cfg80211_disconnect (
2019     struct wiphy *wiphy,
2020     struct net_device *dev,
2021     u16 reason_code
2022     )
2023 {
2024     INT_32 i4Rslt = -EINVAL;
2025     P_GLUE_INFO_T prGlueInfo = NULL;
2026     P_MSG_P2P_CONNECTION_ABORT_T prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
2027     UINT_8 aucBCAddr[] = BC_MAC_ADDR;
2028
2029     do {
2030         if ((wiphy == NULL) ||
2031                 (dev == NULL)) {
2032             break;
2033         }
2034
2035         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disconnect.\n"));
2036
2037         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2038
2039 //        prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)kalMemAlloc(sizeof(P_MSG_P2P_CONNECTION_ABORT_T), VIR_MEM_TYPE);
2040         prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
2041
2042         if (prDisconnMsg == NULL) {
2043             ASSERT(FALSE);
2044             i4Rslt = -ENOMEM;
2045             break;
2046         }
2047
2048         prDisconnMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
2049         prDisconnMsg->u2ReasonCode = reason_code;
2050         prDisconnMsg->fgSendDeauth = TRUE;
2051         COPY_MAC_ADDR(prDisconnMsg->aucTargetID, aucBCAddr);
2052
2053         mboxSendMsg(prGlueInfo->prAdapter,
2054                                 MBOX_ID_0,
2055                                 (P_MSG_HDR_T)prDisconnMsg,
2056                                 MSG_SEND_METHOD_UNBUF);
2057
2058         i4Rslt = 0;
2059     } while (FALSE);
2060
2061     return i4Rslt;
2062 } /* mtk_p2p_cfg80211_disconnect */
2063
2064
2065 int
2066 mtk_p2p_cfg80211_change_iface (
2067     IN struct wiphy *wiphy,
2068     IN struct net_device *ndev,
2069     IN enum nl80211_iftype type,
2070     IN u32 *flags,
2071     IN struct vif_params *params
2072     )
2073 {
2074     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
2075     INT_32 i4Rslt = -EINVAL;
2076     P_MSG_P2P_SWITCH_OP_MODE_T prSwitchModeMsg = (P_MSG_P2P_SWITCH_OP_MODE_T)NULL;
2077
2078     do {
2079         if ((wiphy == NULL) ||
2080                 (ndev == NULL)) {
2081             break;
2082         }
2083
2084         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_iface.\n"));
2085
2086         if (ndev->ieee80211_ptr) {
2087             ndev->ieee80211_ptr->iftype = type;
2088         }
2089
2090         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2091
2092
2093         // Switch OP MOde.
2094         prSwitchModeMsg = (P_MSG_P2P_SWITCH_OP_MODE_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
2095
2096         if (prSwitchModeMsg == NULL) {
2097             ASSERT(FALSE);
2098             i4Rslt = -ENOMEM;
2099             break;
2100         }
2101
2102         prSwitchModeMsg->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
2103
2104         switch (type) {
2105         case NL80211_IFTYPE_P2P_CLIENT:
2106             DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_P2P_CLIENT.\n"));
2107         case NL80211_IFTYPE_STATION:
2108             if (type == NL80211_IFTYPE_STATION) {
2109                 DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_STATION.\n"));
2110             }
2111             prSwitchModeMsg->eOpMode = OP_MODE_INFRASTRUCTURE;
2112             break;
2113         case NL80211_IFTYPE_AP:
2114             DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_AP.\n"));
2115         case NL80211_IFTYPE_P2P_GO:
2116             if (type == NL80211_IFTYPE_P2P_GO) {
2117                 DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_P2P_GO not AP.\n"));
2118             }
2119             prSwitchModeMsg->eOpMode = OP_MODE_ACCESS_POINT;
2120             break;
2121         default:
2122             DBGLOG(P2P, TRACE, ("Other type :%d .\n", type));
2123             prSwitchModeMsg->eOpMode = OP_MODE_P2P_DEVICE;
2124             break;
2125         }
2126
2127
2128         mboxSendMsg(prGlueInfo->prAdapter,
2129                             MBOX_ID_0,
2130                             (P_MSG_HDR_T)prSwitchModeMsg,
2131                             MSG_SEND_METHOD_BUF);
2132
2133         i4Rslt = 0;
2134
2135     } while (FALSE);
2136
2137     return i4Rslt;
2138
2139 } /* mtk_p2p_cfg80211_change_iface */
2140
2141
2142 int
2143 mtk_p2p_cfg80211_set_channel (
2144     IN struct wiphy *wiphy,
2145     IN struct net_device *dev,
2146     IN struct ieee80211_channel *chan,
2147     IN enum nl80211_channel_type channel_type)
2148 {
2149     INT_32 i4Rslt = -EINVAL;
2150     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
2151     RF_CHANNEL_INFO_T rRfChnlInfo;
2152
2153     do {
2154         if ((wiphy == NULL) ||
2155                 (dev == NULL) ||
2156                 (chan == NULL)) {
2157             break;
2158         }
2159
2160         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_channel.\n"));
2161
2162         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2163
2164         mtk_p2p_cfg80211func_channel_format_switch(chan,
2165                                         channel_type,
2166                                         &rRfChnlInfo,
2167                                         NULL);
2168
2169         p2pFuncSetChannel(prGlueInfo->prAdapter, &rRfChnlInfo);
2170
2171         i4Rslt = 0;
2172     }
2173 while (FALSE);
2174
2175     return i4Rslt;
2176
2177 }
2178 /* mtk_p2p_cfg80211_set_channel */
2179
2180 int
2181 mtk_p2p_cfg80211_set_bitrate_mask (
2182     IN struct wiphy *wiphy,
2183     IN struct net_device *dev,
2184     IN const u8 *peer,
2185     IN const struct cfg80211_bitrate_mask *mask
2186     )
2187 {
2188     INT_32 i4Rslt = -EINVAL;
2189     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
2190
2191     do {
2192         if ((wiphy == NULL) ||
2193                 (dev == NULL) ||
2194                 (mask == NULL)) {
2195             break;
2196         }
2197
2198         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_bitrate_mask\n"));
2199
2200         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2201
2202         // TODO: Set bitrate mask of the peer?
2203
2204         i4Rslt = 0;
2205     }
2206 while (FALSE);
2207
2208     return i4Rslt;
2209 } /* mtk_p2p_cfg80211_set_bitrate_mask */
2210
2211
2212 void
2213 mtk_p2p_cfg80211_mgmt_frame_register (
2214     IN struct wiphy *wiphy,
2215     IN struct net_device *dev,
2216     IN u16 frame_type,
2217     IN bool reg
2218     )
2219 {
2220 #if 1
2221     P_MSG_P2P_MGMT_FRAME_REGISTER_T prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)NULL;
2222 #endif
2223     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
2224
2225     do {
2226         if ((wiphy == NULL) ||
2227                 (dev == NULL)) {
2228             break;
2229         }
2230
2231         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2232
2233                 prMgmtFrameRegister = kmalloc(sizeof(MSG_P2P_MGMT_FRAME_REGISTER_T),GFP_ATOMIC);
2234 /*  this function is used to set HW filter to RX package, but if we use oringnal method, we may face wrong 
2235 cmd sequence to firmware (supplicant request 1. set probe request fiter  2. remain on channel  but for driver 1. send channel request
2236 first 2. then set RX filter). This wrong schedule sequence will cause other device can not find this DUT
2237 Solution:
2238 1. use mail box to handle set RX filter request
2239 2. use kmalloc to avoid sleep in atomic contex, if alloc mem fail, use oringal method
2240 */
2241
2242
2243                 if(prMgmtFrameRegister == NULL){
2244
2245                         printk("p2p set fitler error,can not alloc mem from kernel, use tx thread to set rx filter\n");
2246         switch (frame_type) {
2247         case MAC_FRAME_PROBE_REQ:
2248             if (reg) {
2249                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_PROBE_REQ;
2250                 DBGLOG(P2P, TRACE, ("Open packet filer probe request\n"));
2251             }
2252             else {
2253                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_PROBE_REQ;
2254                 DBGLOG(P2P, TRACE, ("Close packet filer probe request\n"));
2255             }
2256             break;
2257         case MAC_FRAME_ACTION:
2258             if (reg) {
2259                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_ACTION_FRAME;
2260                 DBGLOG(P2P, TRACE, ("Open packet filer action frame.\n"));
2261             }
2262             else {
2263                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_ACTION_FRAME;
2264                 DBGLOG(P2P, TRACE, ("Close packet filer action frame.\n"));
2265             }
2266             break;
2267         default:
2268                 DBGLOG(P2P, ERROR, ("Ask frog to add code for mgmt:%x\n", frame_type));
2269                 break;
2270         }
2271
2272
2273         
2274         if((prGlueInfo->prAdapter != NULL)  && (prGlueInfo->prAdapter->fgIsP2PRegistered == TRUE)){
2275
2276                    //prGlueInfo->u4Flag |= GLUE_FLAG_FRAME_FILTER;
2277                            set_bit(GLUE_FLAG_FRAME_FILTER_BIT, &prGlueInfo->u4Flag);
2278
2279         /* wake up main thread */
2280         wake_up_interruptible(&prGlueInfo->waitq);
2281
2282         if (in_interrupt()) {
2283             DBGLOG(P2P, TRACE, ("It is in interrupt level\n"));
2284            }
2285         }
2286                 }else{
2287
2288 #if 1
2289 #if 0
2290         prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)cnmMemAlloc(prGlueInfo->prAdapter, 
2291                                                                     RAM_TYPE_MSG, 
2292                                                                     sizeof(MSG_P2P_MGMT_FRAME_REGISTER_T));
2293
2294         if (prMgmtFrameRegister == NULL) {
2295             ASSERT(FALSE);
2296             break;
2297         }
2298         #endif
2299         prMgmtFrameRegister->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_FRAME_REGISTER;
2300
2301         prMgmtFrameRegister->u2FrameType = frame_type;
2302         prMgmtFrameRegister->fgIsRegister = reg;
2303
2304         mboxSendMsg(prGlueInfo->prAdapter,
2305                                     MBOX_ID_0,
2306                                     (P_MSG_HDR_T)prMgmtFrameRegister,
2307                                     MSG_SEND_METHOD_BUF);
2308
2309 #endif
2310                                 }
2311     } while (FALSE);
2312
2313     return;
2314 } /* mtk_p2p_cfg80211_mgmt_frame_register */
2315
2316
2317 BOOLEAN
2318 mtk_p2p_cfg80211func_channel_format_switch (
2319     IN struct ieee80211_channel *channel,
2320     IN enum nl80211_channel_type channel_type,
2321     IN P_RF_CHANNEL_INFO_T prRfChnlInfo,
2322     IN P_ENUM_CHNL_EXT_T prChnlSco
2323     )
2324 {
2325     BOOLEAN fgIsValid = FALSE;
2326
2327     do {
2328         if (channel == NULL) {
2329             break;
2330         }
2331
2332         if (prRfChnlInfo) {
2333             prRfChnlInfo->ucChannelNum = nicFreq2ChannelNum(channel->center_freq * 1000);
2334
2335             switch (channel->band) {
2336             case IEEE80211_BAND_2GHZ:
2337                 prRfChnlInfo->eBand = BAND_2G4;
2338                 break;
2339             case IEEE80211_BAND_5GHZ:
2340                 prRfChnlInfo->eBand = BAND_5G;
2341                 break;
2342             default:
2343                 prRfChnlInfo->eBand = BAND_2G4;
2344                 break;
2345             }
2346         
2347         }
2348
2349         
2350         if (prChnlSco) {
2351             
2352             switch (channel_type) {
2353             case NL80211_CHAN_NO_HT:
2354                 *prChnlSco = CHNL_EXT_SCN;
2355                 break;
2356             case NL80211_CHAN_HT20:
2357                 *prChnlSco = CHNL_EXT_SCN;
2358                 break;
2359             case NL80211_CHAN_HT40MINUS:
2360                 *prChnlSco = CHNL_EXT_SCA;
2361                 break;
2362             case NL80211_CHAN_HT40PLUS:
2363                 *prChnlSco = CHNL_EXT_SCB;
2364                 break;
2365             default:
2366                 ASSERT(FALSE);
2367                 *prChnlSco = CHNL_EXT_SCN;
2368                 break;
2369             }
2370         }
2371
2372         fgIsValid = TRUE;
2373     }
2374 while (FALSE);
2375
2376     return fgIsValid;
2377 }
2378 /* mtk_p2p_cfg80211func_channel_format_switch */
2379
2380
2381 #if CONFIG_NL80211_TESTMODE
2382 int mtk_p2p_cfg80211_testmode_cmd(
2383     IN struct wiphy *wiphy,
2384     IN void *data,
2385     IN int len
2386     )
2387 {
2388     P_GLUE_INFO_T prGlueInfo = NULL;
2389     P_NL80211_DRIVER_TEST_PARAMS prParams = (P_NL80211_DRIVER_TEST_PARAMS)NULL;
2390     BOOLEAN fgIsValid = FALSE;
2391
2392     ASSERT(wiphy);
2393
2394     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2395
2396         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_cmd\n"));
2397     
2398     if(data && len)
2399         prParams = (P_NL80211_DRIVER_TEST_PARAMS)data;
2400
2401     if(prParams->index >> 24 == 0x01) { 
2402         /* New version */
2403         prParams->index = prParams->index & ~ BITS(24,31);
2404     }
2405     else {  
2406         /* Old version*/
2407         mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(wiphy, data, len); 
2408                 fgIsValid = TRUE;
2409         return fgIsValid;
2410     }
2411
2412     /* Clear the version byte */
2413     prParams->index = prParams->index & ~ BITS(24,31);
2414
2415         if(prParams){
2416                 switch(prParams->index){
2417                     case 1: /* P2P Simga */
2418                             if(mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(wiphy, data, len))
2419                                         fgIsValid = TRUE;
2420                             break;
2421 #if CFG_SUPPORT_WFD 
2422                         case 2: /* WFD */
2423                                 if(mtk_p2p_cfg80211_testmode_wfd_update_cmd(wiphy, data, len))
2424                                         fgIsValid= TRUE;
2425                             break;
2426 #endif
2427             case 3: /* Hotspot Client Management */
2428                 if(mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(wiphy, data, len))
2429                                         fgIsValid = TRUE;
2430                 break;
2431                         default:
2432                                 fgIsValid = TRUE;
2433                             break;
2434                 }
2435         }
2436
2437         return fgIsValid;
2438
2439 }
2440
2441
2442 int mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(
2443     IN struct wiphy *wiphy,
2444     IN void *data,
2445     IN int len
2446     )
2447 {
2448     P_GLUE_INFO_T prGlueInfo = NULL;
2449         NL80211_DRIVER_TEST_PRE_PARAMS rParams;
2450         P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
2451     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
2452         UINT_32 index_mode;
2453         UINT_32 index;
2454     INT_32  value;
2455         int     status = 0;
2456         UINT_32 u4Leng;
2457
2458     ASSERT(wiphy);
2459
2460     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2461
2462         kalMemZero(&rParams, sizeof(NL80211_DRIVER_TEST_PRE_PARAMS));
2463
2464         prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
2465     prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
2466
2467         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd\n"));
2468
2469         if(data && len)
2470                 memcpy(&rParams, data, len);
2471
2472     DBGLOG(P2P, TRACE, ("NL80211_ATTR_TESTDATA,idx_mode=%d idx=%d value=%lu\n",
2473                 (INT_16)rParams.idx_mode, (INT_16)rParams.idx, rParams.value));
2474
2475     index_mode = rParams.idx_mode;
2476         index = rParams.idx;
2477         value = rParams.value;
2478
2479     switch (index) {
2480       case 0: /* Listen CH */
2481           break;
2482       case 1: /* P2p mode */
2483           break;
2484       case 4: /* Noa duration */
2485           prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
2486           // only to apply setting when setting NOA count
2487           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2488           break;
2489       case 5: /* Noa interval */
2490           prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
2491           // only to apply setting when setting NOA count
2492           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2493           break;
2494       case 6: /* Noa count */
2495           prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2496           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2497           break;
2498       case 100: /* Oper CH */
2499           // 20110920 - frog: User configurations are placed in ConnSettings.
2500           // prP2pConnSettings->ucOperatingChnl = value;
2501           break;
2502       case 101: /* Local config Method, for P2P SDK */
2503           prP2pConnSettings->u2LocalConfigMethod = value;
2504           break;
2505       case 102: /* Sigma P2p reset */
2506           //kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
2507           //prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO;
2508           p2pFsmUninit(prGlueInfo->prAdapter);
2509           p2pFsmInit(prGlueInfo->prAdapter);
2510           break;
2511       case 103: /* WPS MODE */
2512           kalP2PSetWscMode(prGlueInfo, value);
2513           break;
2514       case 104: /* P2p send persence, duration */
2515           break;
2516       case 105: /* P2p send persence, interval */
2517           break;
2518       case 106: /* P2P set sleep  */
2519             value = 1;
2520             kalIoctl(prGlueInfo,
2521                 wlanoidSetP2pPowerSaveProfile,
2522                 &value,
2523                 sizeof(value),
2524                 FALSE,
2525                 FALSE,
2526                 TRUE,
2527                 TRUE,
2528                 &u4Leng);
2529           break;
2530       case 107: /* P2P set opps, CTWindowl */
2531             prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
2532             //status = mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
2533           break;
2534       case 108: /* p2p_set_power_save */
2535             kalIoctl(prGlueInfo,
2536                 wlanoidSetP2pPowerSaveProfile,
2537                 &value,
2538                 sizeof(value),
2539                 FALSE,
2540                 FALSE,
2541                 TRUE,
2542                 TRUE,
2543                 &u4Leng);
2544
2545           break;
2546       default:
2547           break;
2548     }
2549
2550     return status;
2551
2552 }
2553
2554
2555 int
2556 mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(
2557     IN struct wiphy *wiphy,
2558     IN void *data,
2559     IN int len)
2560 {
2561     P_GLUE_INFO_T prGlueInfo = NULL;
2562     P_NL80211_DRIVER_P2P_SIGMA_PARAMS prParams = (P_NL80211_DRIVER_P2P_SIGMA_PARAMS)NULL;
2563         P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
2564     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
2565         UINT_32 index;
2566     INT_32  value;
2567         int     status = 0;
2568         UINT_32 u4Leng;
2569
2570     ASSERT(wiphy);
2571
2572     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2573
2574     prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
2575     prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
2576
2577     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_p2p_sigma_cmd\n"));
2578
2579     if(data && len)
2580         prParams = (P_NL80211_DRIVER_P2P_SIGMA_PARAMS)data;
2581
2582     index = (INT_32)prParams->idx;
2583     value = (INT_32)prParams->value;
2584
2585         DBGLOG(P2P, TRACE, ("NL80211_ATTR_TESTDATA, idx=%lu value=%lu\n",
2586                 (INT_32)prParams->idx, (INT_32)prParams->value));
2587
2588     switch (index) {
2589       case 0: /* Listen CH */
2590           break;
2591       case 1: /* P2p mode */
2592           break;
2593       case 4: /* Noa duration */
2594           prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
2595           // only to apply setting when setting NOA count
2596           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2597           break;
2598       case 5: /* Noa interval */
2599           prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
2600           // only to apply setting when setting NOA count
2601           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2602           break;
2603       case 6: /* Noa count */
2604           prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2605           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2606           break;
2607       case 100: /* Oper CH */
2608           // 20110920 - frog: User configurations are placed in ConnSettings.
2609           // prP2pConnSettings->ucOperatingChnl = value;
2610           break;
2611       case 101: /* Local config Method, for P2P SDK */
2612           prP2pConnSettings->u2LocalConfigMethod = value;
2613           break;
2614       case 102: /* Sigma P2p reset */
2615           //kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
2616           //prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO;
2617           break;
2618       case 103: /* WPS MODE */
2619           kalP2PSetWscMode(prGlueInfo, value);
2620           break;
2621       case 104: /* P2p send persence, duration */
2622           break;
2623       case 105: /* P2p send persence, interval */
2624           break;
2625       case 106: /* P2P set sleep  */
2626             value = 1;
2627             kalIoctl(prGlueInfo,
2628                 wlanoidSetP2pPowerSaveProfile,
2629                 &value,
2630                 sizeof(value),
2631                 FALSE,
2632                 FALSE,
2633                 TRUE,
2634                 TRUE,
2635                 &u4Leng);
2636           break;
2637       case 107: /* P2P set opps, CTWindowl */
2638             prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
2639             //status = mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
2640           break;
2641       case 108: /* p2p_set_power_save */
2642             kalIoctl(prGlueInfo,
2643                 wlanoidSetP2pPowerSaveProfile,
2644                 &value,
2645                 sizeof(value),
2646                 FALSE,
2647                 FALSE,
2648                 TRUE,
2649                 TRUE,
2650                 &u4Leng);
2651
2652           break;
2653       case 109: /* Max Clients*/
2654           kalP2PSetMaxClients(prGlueInfo, value);
2655           break;
2656       default:
2657           break;
2658     }
2659
2660     return status;
2661
2662 }
2663
2664 #if CFG_SUPPORT_WFD
2665 int
2666 mtk_p2p_cfg80211_testmode_wfd_update_cmd(
2667     IN struct wiphy *wiphy,
2668     IN void *data,
2669     IN int len)
2670 {
2671     P_GLUE_INFO_T prGlueInfo = NULL;
2672     P_NL80211_DRIVER_WFD_PARAMS prParams = (P_NL80211_DRIVER_WFD_PARAMS)NULL;
2673     int status = 0;
2674     P_WFD_CFG_SETTINGS_T prWfdCfgSettings = (P_WFD_CFG_SETTINGS_T)NULL;
2675     P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T prMsgWfdCfgUpdate = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)NULL;
2676
2677     ASSERT(wiphy);
2678
2679     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2680
2681     prParams = (P_NL80211_DRIVER_WFD_PARAMS)data;
2682
2683
2684     DBGLOG(P2P, INFO, ("mtk_p2p_cfg80211_testmode_wfd_update_cmd\n"));
2685
2686 #if 1
2687
2688     DBGLOG(P2P, INFO,("WFD Enable:%x\n", prParams->WfdEnable));
2689     DBGLOG(P2P, INFO,("WFD Session Available:%x\n", prParams->WfdSessionAvailable));
2690     DBGLOG(P2P, INFO,("WFD Couple Sink Status:%x\n", prParams->WfdCoupleSinkStatus));
2691     //aucReserved0[2]
2692     DBGLOG(P2P, INFO,("WFD Device Info:%x\n", prParams->WfdDevInfo));
2693     DBGLOG(P2P, INFO,("WFD Control Port:%x\n", prParams->WfdControlPort));
2694     DBGLOG(P2P, INFO,("WFD Maximum Throughput:%x\n", prParams->WfdMaximumTp));
2695     DBGLOG(P2P, INFO,("WFD Extend Capability:%x\n", prParams->WfdExtendCap));
2696     DBGLOG(P2P, INFO,("WFD Couple Sink Addr "MACSTR" \n", MAC2STR(prParams->WfdCoupleSinkAddress)));
2697     DBGLOG(P2P, INFO,("WFD Associated BSSID "MACSTR" \n", MAC2STR(prParams->WfdAssociatedBssid)));
2698     //UINT_8 aucVideolp[4];
2699     //UINT_8 aucAudiolp[4];
2700     DBGLOG(P2P, INFO,("WFD Video Port:%x\n", prParams->WfdVideoPort));
2701     DBGLOG(P2P, INFO,("WFD Audio Port:%x\n", prParams->WfdAudioPort));
2702     DBGLOG(P2P, INFO,("WFD Flag:%x\n", prParams->WfdFlag));
2703     DBGLOG(P2P, INFO,("WFD Policy:%x\n", prParams->WfdPolicy));
2704     DBGLOG(P2P, INFO,("WFD State:%x\n", prParams->WfdState));
2705     //UINT_8 aucWfdSessionInformationIE[24*8];
2706     DBGLOG(P2P, INFO,("WFD Session Info Length:%x\n", prParams->WfdSessionInformationIELen));
2707     //UINT_8 aucReserved1[2];
2708     DBGLOG(P2P, INFO,("WFD Primary Sink Addr "MACSTR" \n", MAC2STR(prParams->aucWfdPrimarySinkMac)));
2709     DBGLOG(P2P, INFO,("WFD Secondary Sink Addr "MACSTR" \n", MAC2STR(prParams->aucWfdSecondarySinkMac)));
2710     DBGLOG(P2P, INFO,("WFD Advanced Flag:%x\n", prParams->WfdAdvanceFlag));
2711     DBGLOG(P2P, INFO,("WFD Sigma mode:%x\n", prParams->WfdSigmaMode));
2712     //UINT_8 aucReserved2[64];
2713     //UINT_8 aucReserved3[64];
2714     //UINT_8 aucReserved4[64];
2715
2716 #endif
2717
2718     prWfdCfgSettings = &(prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo->rWfdConfigureSettings);
2719
2720     kalMemCopy(&prWfdCfgSettings->u4WfdCmdType, &prParams->WfdCmdType, sizeof(WFD_CFG_SETTINGS_T));
2721
2722     prMsgWfdCfgUpdate = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_WFD_CONFIG_SETTINGS_CHANGED_T));
2723
2724     if (prMsgWfdCfgUpdate == NULL) {
2725         ASSERT(FALSE);
2726         return status;
2727     }
2728
2729     prMsgWfdCfgUpdate->rMsgHdr.eMsgId = MID_MNY_P2P_WFD_CFG_UPDATE;
2730     prMsgWfdCfgUpdate->prWfdCfgSettings = prWfdCfgSettings;
2731
2732
2733     mboxSendMsg(prGlueInfo->prAdapter,
2734                         MBOX_ID_0,
2735                         (P_MSG_HDR_T)prMsgWfdCfgUpdate,
2736                         MSG_SEND_METHOD_BUF);
2737 #if 0 // Test Only
2738 //    prWfdCfgSettings->ucWfdEnable = 1;
2739 //    prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_DEV_INFO_VALID;
2740     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_DEV_INFO_VALID;
2741     prWfdCfgSettings->u2WfdDevInfo = 123;
2742     prWfdCfgSettings->u2WfdControlPort = 456;
2743     prWfdCfgSettings->u2WfdMaximumTp = 789;
2744
2745
2746     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_SINK_INFO_VALID;
2747     prWfdCfgSettings->ucWfdCoupleSinkStatus = 0xAB;
2748     {
2749         UINT_8 aucTestAddr[MAC_ADDR_LEN] = {0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
2750         COPY_MAC_ADDR(prWfdCfgSettings->aucWfdCoupleSinkAddress, aucTestAddr);
2751     }
2752
2753     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_EXT_CAPABILITY_VALID;
2754     prWfdCfgSettings->u2WfdExtendCap = 0xCDE;
2755
2756 #endif
2757
2758     return status;
2759
2760 }
2761 #endif /*  CFG_SUPPORT_WFD */
2762
2763
2764
2765 int
2766 mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(
2767     IN struct wiphy *wiphy,
2768     IN void *data,
2769     IN int len)
2770 {
2771     P_GLUE_INFO_T prGlueInfo = NULL;
2772     P_NL80211_DRIVER_hotspot_block_PARAMS prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)NULL;
2773     int fgIsValid = 0;
2774
2775     ASSERT(wiphy);
2776
2777     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2778
2779     if(data && len)
2780         prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)data;
2781
2782     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd\n"));
2783
2784     fgIsValid = kalP2PSetBlackList(prGlueInfo, prParams->aucBssid, prParams->ucblocked);
2785  
2786     return fgIsValid;
2787
2788 }
2789
2790 #endif
2791
2792
2793 #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
2794
2795 #endif // CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_WIFI_DIRECT_CFG_80211