bffe396693821994045d5c7d4c033f31d74fcd9a
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6628 / 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
15 /*
16 ** $Log: gl_p2p_cfg80211.c $
17 **
18 ** 01 30 2013 yuche.tsai
19 ** [ALPS00455459] [GN_WIFI]??wifi direct???????????
20 ** Fix possible race condition under GO mode.
21 ** 
22 ** 09 12 2012 wcpadmin
23 ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
24 ** .
25 ** 
26 ** 09 05 2012 wh.su
27 ** [ALPS00351547] [6577JB][WiFi direct]The 3rd device fail to establish p2p connection with GO sometimes
28 ** sync with the ICS code.
29 ** 
30 ** 08 31 2012 yuche.tsai
31 ** [ALPS00349585] [6577JB][WiFi direct][KE]Establish p2p connection while both device have connected to AP previously,one device reboots automatically with KE
32 ** Fix possible KE when concurrent & disconnect.
33 ** 
34 ** 08 21 2012 yuche.tsai
35 ** NULL
36 ** Fix compile warning.
37 ** 
38 ** 08 20 2012 yuche.tsai
39 ** NULL
40 ** Fix possible KE issue.
41 ** 
42 ** 08 17 2012 yuche.tsai
43 ** NULL
44 ** Fix compile warning.
45 ** 
46 ** 08 16 2012 yuche.tsai
47 ** NULL
48 ** Fix compile warning.
49 ** 
50 ** 08 14 2012 yuche.tsai
51 ** NULL
52 ** Fix p2p bug find on ALPS.JB trunk.
53 **
54 ** 07 26 2012 yuche.tsai
55 ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
56 ** Update driver code of ALPS.JB for hot-spot.
57 **
58 ** 07 19 2012 yuche.tsai
59 ** NULL
60 ** Code update for JB.
61  *
62  * 07 17 2012 yuche.tsai
63  * NULL
64  * Fix compile error for JB.
65  *
66  * 07 17 2012 yuche.tsai
67  * NULL
68  * Compile no error before trial run.
69  *
70  * 09 21 2010 kevin.huang
71  * [WCXRP00000054] [MT6620 Wi-Fi][Driver] Restructure driver for second Interface
72  * Isolate P2P related function for Hardware Software Bundle
73  *
74  * 07 08 2010 cp.wu
75  *
76  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
77  *
78  * 06 06 2010 kevin.huang
79  * [WPD00003832][MT6620 5931] Create driver base
80  * [MT6620 5931] Create driver base
81  *
82  * 05 31 2010 cp.wu
83  * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
84  * add cfg80211 interface, which is to replace WE, for further extension
85  *
86 **
87 */
88
89 /*******************************************************************************
90 *                         C O M P I L E R   F L A G S
91 ********************************************************************************
92 */
93
94 /*******************************************************************************
95 *                    E X T E R N A L   R E F E R E N C E S
96 ********************************************************************************
97 */
98
99 #include "config.h"
100
101 #if CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_WIFI_DIRECT_CFG_80211
102 #include <linux/kernel.h>
103 #include <linux/netdevice.h>
104 #include <linux/wireless.h>
105 #include <linux/ieee80211.h>
106 #include <net/cfg80211.h>
107
108 #include "precomp.h"
109 #ifdef __GNUC__
110 #pragma GCC diagnostic ignored "-Wformat"
111 #endif
112
113 /*******************************************************************************
114 *                              C O N S T A N T S
115 ********************************************************************************
116 */
117
118 /*******************************************************************************
119 *                             D A T A   T Y P E S
120 ********************************************************************************
121 */
122
123 /*******************************************************************************
124 *                            P U B L I C   D A T A
125 ********************************************************************************
126 */
127
128 /*******************************************************************************
129 *                           P R I V A T E   D A T A
130 ********************************************************************************
131 */
132
133 /*******************************************************************************
134 *                                 M A C R O S
135 ********************************************************************************
136 */
137
138 /*******************************************************************************
139 *                   F U N C T I O N   D E C L A R A T I O N S
140 ********************************************************************************
141 */
142
143
144 BOOLEAN
145 mtk_p2p_cfg80211func_channel_format_switch(
146     IN struct ieee80211_channel *channel,
147     IN enum nl80211_channel_type channel_type,
148     IN P_RF_CHANNEL_INFO_T prRfChnlInfo,
149     IN P_ENUM_CHNL_EXT_T prChnlSco
150     );
151
152 /*******************************************************************************
153 *                              F U N C T I O N S
154 ********************************************************************************
155 */
156
157 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
158 int mtk_p2p_cfg80211_add_key(
159     struct wiphy *wiphy,
160     struct net_device *ndev,
161     u8 key_index,
162     bool pairwise,
163     const u8 *mac_addr,
164     struct key_params *params
165     )
166 {
167     P_GLUE_INFO_T prGlueInfo = NULL;
168         INT_32 i4Rslt = -EINVAL;
169         WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
170         UINT_32 u4BufLen = 0;
171         P2P_PARAM_KEY_T rKey;
172
173     ASSERT(wiphy);
174
175     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
176
177     kalMemZero(&rKey, sizeof(P2P_PARAM_KEY_T));
178
179         rKey.u4KeyIndex = key_index;
180     if(mac_addr) {
181         memcpy(rKey.arBSSID, mac_addr, ETH_ALEN);
182         if ((rKey.arBSSID[0] == 0x00) && (rKey.arBSSID[1] == 0x00) && (rKey.arBSSID[2] == 0x00) &&
183             (rKey.arBSSID[3] == 0x00) && (rKey.arBSSID[4] == 0x00) && (rKey.arBSSID[5] == 0x00)) {
184             rKey.arBSSID[0] = 0xff;
185             rKey.arBSSID[1] = 0xff;
186             rKey.arBSSID[2] = 0xff;
187             rKey.arBSSID[3] = 0xff;
188             rKey.arBSSID[4] = 0xff;
189             rKey.arBSSID[5] = 0xff;
190         }
191         if (rKey.arBSSID[0] != 0xFF) {
192             rKey.u4KeyIndex |= BIT(31);
193             if ((rKey.arBSSID[0] != 0x00) || (rKey.arBSSID[1] != 0x00) || (rKey.arBSSID[2] != 0x00) ||
194                 (rKey.arBSSID[3] != 0x00) || (rKey.arBSSID[4] != 0x00) || (rKey.arBSSID[5] != 0x00))
195                 rKey.u4KeyIndex |= BIT(30);
196         }
197         else {
198             rKey.u4KeyIndex |= BIT(31);
199         }
200     }
201     else {
202             rKey.arBSSID[0] = 0xff;
203             rKey.arBSSID[1] = 0xff;
204             rKey.arBSSID[2] = 0xff;
205             rKey.arBSSID[3] = 0xff;
206             rKey.arBSSID[4] = 0xff;
207             rKey.arBSSID[5] = 0xff;
208             rKey.u4KeyIndex |= BIT(31); //????
209     }
210         if(params->key)
211         {
212         //rKey.aucKeyMaterial[0] = kalMemAlloc(params->key_len, VIR_MEM_TYPE);
213             kalMemCopy(rKey.aucKeyMaterial, params->key, params->key_len);
214         }
215         rKey.u4KeyLength = params->key_len;
216         rKey.u4Length =  ((UINT_32)&(((P_P2P_PARAM_KEY_T)0)->aucKeyMaterial)) + rKey.u4KeyLength;
217
218         rStatus = kalIoctl(prGlueInfo,
219             wlanoidSetAddP2PKey,
220             &rKey,
221             rKey.u4Length,
222             FALSE,
223             FALSE,
224             TRUE,
225             TRUE,
226             &u4BufLen);
227     if (rStatus == WLAN_STATUS_SUCCESS)
228                 i4Rslt = 0;
229
230     return i4Rslt;
231 }
232
233
234 int mtk_p2p_cfg80211_get_key(
235     struct wiphy *wiphy,
236     struct net_device *ndev,
237     u8 key_index,
238     bool pairwise,
239     const u8 *mac_addr,
240     void *cookie,
241     void (*callback)(void *cookie, struct key_params*)
242     )
243 {
244     P_GLUE_INFO_T prGlueInfo = NULL;
245
246     ASSERT(wiphy);
247
248     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
249
250     // not implemented yet
251
252     return -EINVAL;
253 }
254
255 int mtk_p2p_cfg80211_del_key(
256     struct wiphy *wiphy,
257     struct net_device *ndev,
258     u8 key_index,
259     bool pairwise,
260     const u8 *mac_addr
261     )
262 {
263     P_GLUE_INFO_T prGlueInfo = NULL;
264         PARAM_REMOVE_KEY_T prRemoveKey;
265         INT_32 i4Rslt = -EINVAL;
266         WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
267         UINT_32 u4BufLen = 0;
268
269     ASSERT(wiphy);
270
271     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
272
273     kalMemZero(&prRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
274         if(mac_addr)
275                 memcpy(prRemoveKey.arBSSID, mac_addr, PARAM_MAC_ADDR_LEN);
276         prRemoveKey.u4KeyIndex = key_index;
277         prRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
278
279     rStatus = kalIoctl(prGlueInfo,
280             wlanoidSetRemoveP2PKey,
281             &prRemoveKey,
282             prRemoveKey.u4Length,
283             FALSE,
284             FALSE,
285             TRUE,
286             TRUE,
287             &u4BufLen);
288
289     if (rStatus == WLAN_STATUS_SUCCESS)
290                 i4Rslt = 0;
291
292     return i4Rslt;
293 }
294
295
296 int
297 mtk_p2p_cfg80211_set_default_key (
298     struct wiphy *wiphy,
299     struct net_device *netdev,
300     u8 key_index,
301     bool unicast,
302     bool multicast
303     )
304 {
305     P_GLUE_INFO_T prGlueInfo = NULL;
306
307     ASSERT(wiphy);
308
309     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
310
311     // not implemented yet
312
313     return -EINVAL;
314 }
315
316 int mtk_p2p_cfg80211_get_station(
317     struct wiphy *wiphy,
318     struct net_device *ndev,
319     u8 *mac,
320     struct station_info *sinfo
321     )
322 {
323     INT_32 i4RetRslt = -EINVAL;
324     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
325     P_GL_P2P_INFO_T prP2pGlueInfo = (P_GL_P2P_INFO_T)NULL;
326     P2P_STATION_INFO_T rP2pStaInfo;
327
328     ASSERT(wiphy);
329
330     do {
331         if ((wiphy == NULL) ||
332                 (ndev == NULL) ||
333                 (sinfo == NULL) ||
334                 (mac == NULL)) {
335             break;
336         }
337
338         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_get_station\n"));
339
340         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
341         prP2pGlueInfo = prGlueInfo->prP2PInfo;
342
343         sinfo->filled = 0;
344
345         /* Get station information. */
346         /* 1. Inactive time? */
347         p2pFuncGetStationInfo(prGlueInfo->prAdapter,
348                                                 mac,
349                                                 &rP2pStaInfo);
350
351         /* Inactive time. */
352         sinfo->filled |= STATION_INFO_INACTIVE_TIME;
353         sinfo->inactive_time = rP2pStaInfo.u4InactiveTime;
354         sinfo->generation = prP2pGlueInfo->i4Generation;
355
356         i4RetRslt = 0;
357     } while (FALSE);
358
359     return i4RetRslt;
360 }
361
362 int
363 mtk_p2p_cfg80211_scan (
364     struct wiphy *wiphy,
365     struct net_device *ndev,
366     struct cfg80211_scan_request *request
367     )
368 {
369     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
370     P_GL_P2P_INFO_T prP2pGlueInfo = (P_GL_P2P_INFO_T)NULL;
371     P_MSG_P2P_SCAN_REQUEST_T prMsgScanRequest = (P_MSG_P2P_SCAN_REQUEST_T)NULL;
372     UINT_32 u4MsgSize = 0, u4Idx = 0;
373     INT_32 i4RetRslt = -EINVAL;
374     P_RF_CHANNEL_INFO_T prRfChannelInfo = (P_RF_CHANNEL_INFO_T)NULL;
375     P_P2P_SSID_STRUCT_T prSsidStruct = (P_P2P_SSID_STRUCT_T)NULL;
376     struct ieee80211_channel *prChannel = NULL;
377     struct cfg80211_ssid *prSsid = NULL;
378
379     /* [---------Channel---------] [---------SSID---------][---------IE---------] */
380
381
382     do {
383         if ((wiphy == NULL) || (request == NULL)) {
384             break;
385         }
386
387         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
388
389         prP2pGlueInfo = prGlueInfo->prP2PInfo;
390
391         if (prP2pGlueInfo == NULL) {
392             ASSERT(FALSE);
393             break;
394         }
395
396         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_scan.\n"));
397
398
399         if (prP2pGlueInfo->prScanRequest != NULL) {
400             /* There have been a scan request on-going processing. */
401             DBGLOG(P2P, TRACE, ("There have been a scan request on-going processing.\n"));
402             break;
403         }
404
405         prP2pGlueInfo->prScanRequest = request;
406
407         /* Should find out why the n_channels so many? */
408         if (request->n_channels > MAXIMUM_OPERATION_CHANNEL_LIST) {
409             request->n_channels = MAXIMUM_OPERATION_CHANNEL_LIST;
410             DBGLOG(P2P, TRACE, ("Channel list exceed the maximun support.\n"));
411         }
412
413         u4MsgSize = sizeof(MSG_P2P_SCAN_REQUEST_T) +
414                                     (request->n_channels * sizeof(RF_CHANNEL_INFO_T)) +
415                                     (request->n_ssids * sizeof(PARAM_SSID_T)) +
416                                     request->ie_len;
417
418         prMsgScanRequest = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, u4MsgSize);
419
420         if (prMsgScanRequest == NULL) {
421             ASSERT(FALSE);
422             i4RetRslt = -ENOMEM;
423             break;
424         }
425
426         DBGLOG(P2P, TRACE, ("Generating scan request message.\n"));
427
428         prMsgScanRequest->rMsgHdr.eMsgId = MID_MNY_P2P_DEVICE_DISCOVERY;
429
430
431
432         DBGLOG(P2P, TRACE, ("Requesting channel number:%d.\n", request->n_channels));
433
434         for (u4Idx = 0; u4Idx < request->n_channels; u4Idx++) {
435             /* Translate Freq from MHz to channel number. */
436             prRfChannelInfo = &(prMsgScanRequest->arChannelListInfo[u4Idx]);
437             prChannel = request->channels[u4Idx];
438
439             prRfChannelInfo->ucChannelNum = nicFreq2ChannelNum(prChannel->center_freq * 1000);
440             DBGLOG(P2P, TRACE, ("Scanning Channel:%d,  freq: %d\n",
441                                                         prRfChannelInfo->ucChannelNum,
442                                                         prChannel->center_freq));
443             switch (prChannel->band) {
444             case IEEE80211_BAND_2GHZ:
445                 prRfChannelInfo->eBand = BAND_2G4;
446                 break;
447             case IEEE80211_BAND_5GHZ:
448                 prRfChannelInfo->eBand = BAND_5G;
449                 break;
450             default:
451                 DBGLOG(P2P, TRACE, ("UNKNOWN Band info from supplicant\n"));
452                 prRfChannelInfo->eBand = BAND_NULL;
453                 break;
454             }
455
456             /* Iteration. */
457             prRfChannelInfo++;
458         }
459         prMsgScanRequest->u4NumChannel = request->n_channels;
460
461         DBGLOG(P2P, TRACE, ("Finish channel list.\n"));
462
463         /* SSID */
464         prSsid = request->ssids;
465         prSsidStruct = (P_P2P_SSID_STRUCT_T)prRfChannelInfo;
466         if (request->n_ssids) {
467             ASSERT(prSsidStruct == &(prMsgScanRequest->arChannelListInfo[u4Idx]));
468             prMsgScanRequest->prSSID = prSsidStruct;
469         }
470
471         for (u4Idx = 0; u4Idx < request->n_ssids; u4Idx++) {
472             COPY_SSID(prSsidStruct->aucSsid,
473                             prSsidStruct->ucSsidLen,
474                             request->ssids->ssid,
475                             request->ssids->ssid_len);
476
477             prSsidStruct++;
478             prSsid++;
479         }
480
481         prMsgScanRequest->i4SsidNum = request->n_ssids;
482
483         DBGLOG(P2P, TRACE, ("Finish SSID list:%d.\n", request->n_ssids));
484
485         /* IE BUFFERS */
486         prMsgScanRequest->pucIEBuf = (PUINT_8)prSsidStruct;
487         if (request->ie_len) {
488             kalMemCopy(prMsgScanRequest->pucIEBuf, request->ie, request->ie_len);
489             prMsgScanRequest->u4IELen = request->ie_len;
490         }
491
492         DBGLOG(P2P, TRACE, ("Finish IE Buffer.\n"));
493
494
495         mboxSendMsg(prGlueInfo->prAdapter,
496                 MBOX_ID_0,
497                 (P_MSG_HDR_T)prMsgScanRequest,
498                 MSG_SEND_METHOD_BUF);
499
500         i4RetRslt = 0;
501     } while (FALSE);
502
503     return i4RetRslt;
504 } /* mtk_p2p_cfg80211_scan */
505
506 int mtk_p2p_cfg80211_set_wiphy_params(
507     struct wiphy *wiphy,
508     u32 changed
509     )
510 {
511     INT_32 i4Rslt = -EINVAL;
512     P_GLUE_INFO_T prGlueInfo = NULL;
513
514
515     do {
516         if (wiphy == NULL) {
517             break;
518         }
519
520         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_wiphy_params\n"));
521         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
522
523         if (changed & WIPHY_PARAM_RETRY_SHORT) {
524             // TODO:
525             DBGLOG(P2P, TRACE, ("The RETRY short param is changed.\n"));
526         }
527
528         if (changed & WIPHY_PARAM_RETRY_LONG) {
529             // TODO:
530             DBGLOG(P2P, TRACE, ("The RETRY long param is changed.\n"));
531         }
532
533
534         if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
535             // TODO:
536             DBGLOG(P2P, TRACE, ("The RETRY fragmentation threshold is changed.\n"));
537         }
538
539         if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
540             // TODO:
541             DBGLOG(P2P, TRACE, ("The RETRY RTS threshold is changed.\n"));
542         }
543
544         if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
545             // TODO:
546             DBGLOG(P2P, TRACE, ("The coverage class is changed???\n"));
547         }
548
549         i4Rslt = 0;
550     } while (FALSE);
551
552
553
554
555     return i4Rslt;
556 } /* mtk_p2p_cfg80211_set_wiphy_params */
557
558
559
560 int
561 mtk_p2p_cfg80211_join_ibss(
562     struct wiphy *wiphy,
563     struct net_device *dev,
564     struct cfg80211_ibss_params *params
565     )
566 {
567     P_GLUE_INFO_T prGlueInfo = NULL;
568
569     ASSERT(wiphy);
570
571     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
572
573     // not implemented yet
574
575     return -EINVAL;
576 }
577
578 int
579 mtk_p2p_cfg80211_leave_ibss(
580     struct wiphy *wiphy,
581     struct net_device *dev
582     )
583 {
584     P_GLUE_INFO_T prGlueInfo = NULL;
585
586     ASSERT(wiphy);
587
588     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
589
590     // not implemented yet
591
592     return -EINVAL;
593 }
594
595 int
596 mtk_p2p_cfg80211_set_txpower(
597     struct wiphy *wiphy,
598     enum nl80211_tx_power_setting type,
599     int mbm
600     )
601 {
602     P_GLUE_INFO_T prGlueInfo = NULL;
603
604     ASSERT(wiphy);
605
606     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
607
608     // not implemented yet
609
610     return -EINVAL;
611 }
612
613 int
614 mtk_p2p_cfg80211_get_txpower(
615     struct wiphy *wiphy,
616     int *dbm
617     )
618 {
619     P_GLUE_INFO_T prGlueInfo = NULL;
620
621     ASSERT(wiphy);
622
623     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
624
625     // not implemented yet
626
627     return -EINVAL;
628 }
629
630 int
631 mtk_p2p_cfg80211_set_power_mgmt(
632     struct wiphy *wiphy,
633     struct net_device *dev,
634     bool enabled,
635     int timeout
636     )
637 {
638     P_GLUE_INFO_T prGlueInfo = NULL;
639
640     ASSERT(wiphy);
641
642     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
643
644     // not implemented yet
645     // TODO: for JB.
646
647     return -EINVAL;
648 }
649
650 //&&&&&&&&&&&&&&&&&&&&&&&&&& Add for ICS Wi-Fi Direct Support. &&&&&&&&&&&&&&&&&&&&&&&
651 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
652 int
653 mtk_p2p_cfg80211_start_ap (
654     struct wiphy *wiphy,
655     struct net_device *dev,
656     struct cfg80211_ap_settings *settings
657     )
658 {
659     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
660     INT_32 i4Rslt = -EINVAL;
661     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
662     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
663     PUINT_8 pucBuffer = (PUINT_8)NULL;
664 //    P_IE_SSID_T prSsidIE = (P_IE_SSID_T)NULL;
665
666     do {
667         if ((wiphy == NULL) || (settings == NULL)) {
668             break;
669         }
670
671         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_start_ap.\n"));
672         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
673
674         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
675                                                                 prGlueInfo->prAdapter,
676                                                                 RAM_TYPE_MSG,
677                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + settings->beacon.head_len + settings->beacon.tail_len));
678
679         if (prP2pBcnUpdateMsg == NULL) {
680             ASSERT(FALSE);
681             i4Rslt = -ENOMEM;
682             break;
683         }
684
685
686         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
687         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
688
689         if (settings->beacon.head_len != 0) {
690             kalMemCopy(pucBuffer, settings->beacon.head, settings->beacon.head_len);
691
692             prP2pBcnUpdateMsg->u4BcnHdrLen = settings->beacon.head_len;
693
694             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
695
696             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)settings->beacon.head_len);
697         }
698         else {
699             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
700
701             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
702         }
703
704         if (settings->beacon.tail_len != 0) {
705             UINT_8 ucLen = settings->beacon.tail_len;
706
707             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
708
709             /*Add TIM IE*/
710             // IEEE 802.11 2007 - 7.3.2.6
711             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
712             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
713             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
714             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
715             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
716             ucLen += IE_SIZE(pucBuffer);
717             pucBuffer += IE_SIZE(pucBuffer);
718
719             kalMemCopy(pucBuffer, settings->beacon.tail, settings->beacon.tail_len);
720
721             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
722         }
723         else {
724             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
725
726             prP2pBcnUpdateMsg->pucBcnBody = NULL;
727         }
728
729
730         mboxSendMsg(prGlueInfo->prAdapter,
731                             MBOX_ID_0,
732                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
733                             MSG_SEND_METHOD_BUF);
734
735
736         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
737                                                         prGlueInfo->prAdapter,
738                                                         RAM_TYPE_MSG,
739                                                         sizeof(MSG_P2P_START_AP_T));
740
741         if (prP2pStartAPMsg == NULL) {
742             ASSERT(FALSE);
743             i4Rslt = -ENOMEM;
744             break;
745         }
746
747         prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
748
749         prP2pStartAPMsg->fgIsPrivacy = settings->privacy;
750
751         prP2pStartAPMsg->u4BcnInterval = settings->beacon_interval;
752
753         prP2pStartAPMsg->u4DtimPeriod = settings->dtim_period;
754
755         /* Copy NO SSID. */
756         prP2pStartAPMsg->ucHiddenSsidType = settings->hidden_ssid;
757
758         COPY_SSID(prP2pStartAPMsg->aucSsid,
759                         prP2pStartAPMsg->u2SsidLen,
760                         settings->ssid,
761                         settings->ssid_len);
762
763         mboxSendMsg(prGlueInfo->prAdapter,
764                             MBOX_ID_0,
765                             (P_MSG_HDR_T)prP2pStartAPMsg,
766                             MSG_SEND_METHOD_BUF);
767
768         i4Rslt = 0;
769
770     } while (FALSE);
771
772     return i4Rslt;
773
774
775 /////////////////////////
776     /**
777          * struct cfg80211_ap_settings - AP configuration
778          *
779          * Used to configure an AP interface.
780          *
781          * @beacon: beacon data
782          * @beacon_interval: beacon interval
783          * @dtim_period: DTIM period
784          * @ssid: SSID to be used in the BSS (note: may be %NULL if not provided from
785          *      user space)
786          * @ssid_len: length of @ssid
787          * @hidden_ssid: whether to hide the SSID in Beacon/Probe Response frames
788          * @crypto: crypto settings
789          * @privacy: the BSS uses privacy
790          * @auth_type: Authentication type (algorithm)
791          * @inactivity_timeout: time in seconds to determine station's inactivity.
792          */
793 //        struct cfg80211_ap_settings {
794 //                struct cfg80211_beacon_data beacon;
795 //
796 //                int beacon_interval, dtim_period;
797 //                const u8 *ssid;
798 //                size_t ssid_len;
799 //                enum nl80211_hidden_ssid hidden_ssid;
800 //                struct cfg80211_crypto_settings crypto;
801 //                bool privacy;
802 //                enum nl80211_auth_type auth_type;
803 //                int inactivity_timeout;
804 //        };
805 ////////////////////
806
807     return i4Rslt;
808 } /* mtk_p2p_cfg80211_start_ap */
809
810
811 int
812 mtk_p2p_cfg80211_change_beacon (
813     struct wiphy *wiphy,
814     struct net_device *dev,
815     struct cfg80211_beacon_data *info
816     )
817 {
818     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
819     INT_32 i4Rslt = -EINVAL;
820     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
821     PUINT_8 pucBuffer = (PUINT_8)NULL;
822
823     do {
824         if ((wiphy == NULL) || (info == NULL)) {
825             break;
826         }
827
828         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_beacon.\n"));
829         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
830
831         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
832                                                                 prGlueInfo->prAdapter,
833                                                                 RAM_TYPE_MSG,
834                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
835
836
837         if (prP2pBcnUpdateMsg == NULL) {
838             ASSERT(FALSE);
839             i4Rslt = -ENOMEM;
840             break;
841         }
842
843         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
844         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
845
846         if (info->head_len != 0) {
847             kalMemCopy(pucBuffer, info->head, info->head_len);
848
849             prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
850
851             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
852
853             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
854         }
855         else {
856             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
857
858             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
859         }
860
861         if (info->tail_len != 0) {
862             UINT_8 ucLen = info->tail_len;
863
864             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
865
866             /*Add TIM IE*/
867             // IEEE 802.11 2007 - 7.3.2.6
868             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
869             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
870             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
871             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
872             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
873             ucLen += IE_SIZE(pucBuffer);
874             pucBuffer += IE_SIZE(pucBuffer);
875
876             kalMemCopy(pucBuffer, info->tail, info->tail_len);
877
878             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
879         }
880         else {
881             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
882
883             prP2pBcnUpdateMsg->pucBcnBody = NULL;
884         }
885
886
887         mboxSendMsg(prGlueInfo->prAdapter,
888                             MBOX_ID_0,
889                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
890                             MSG_SEND_METHOD_BUF);
891
892 ////////////////////////////
893 /**
894  * struct cfg80211_beacon_data - beacon data
895  * @head: head portion of beacon (before TIM IE)
896  *     or %NULL if not changed
897  * @tail: tail portion of beacon (after TIM IE)
898  *     or %NULL if not changed
899  * @head_len: length of @head
900  * @tail_len: length of @tail
901  * @beacon_ies: extra information element(s) to add into Beacon frames or %NULL
902  * @beacon_ies_len: length of beacon_ies in octets
903  * @proberesp_ies: extra information element(s) to add into Probe Response
904  *      frames or %NULL
905  * @proberesp_ies_len: length of proberesp_ies in octets
906  * @assocresp_ies: extra information element(s) to add into (Re)Association
907  *      Response frames or %NULL
908  * @assocresp_ies_len: length of assocresp_ies in octets
909  * @probe_resp_len: length of probe response template (@probe_resp)
910  * @probe_resp: probe response template (AP mode only)
911  */
912 //struct cfg80211_beacon_data {
913 //        const u8 *head, *tail;
914 //        const u8 *beacon_ies;
915 //        const u8 *proberesp_ies;
916 //        const u8 *assocresp_ies;
917 //        const u8 *probe_resp;
918
919 //        size_t head_len, tail_len;
920 //        size_t beacon_ies_len;
921 //        size_t proberesp_ies_len;
922 //        size_t assocresp_ies_len;
923 //        size_t probe_resp_len;
924 //};
925
926 ////////////////////////////
927
928     } while (FALSE);
929
930     return i4Rslt;
931 } /* mtk_p2p_cfg80211_change_beacon */
932
933 #else
934 int
935 mtk_p2p_cfg80211_add_set_beacon (
936     struct wiphy *wiphy,
937     struct net_device *dev,
938     struct beacon_parameters *info
939     )
940 {
941     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
942     INT_32 i4Rslt = -EINVAL;
943     P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)NULL;
944     P_MSG_P2P_START_AP_T prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)NULL;
945     PUINT_8 pucBuffer = (PUINT_8)NULL;
946     P_IE_SSID_T prSsidIE = (P_IE_SSID_T)NULL;
947
948     do {
949         if ((wiphy == NULL) || (info == NULL)) {
950             break;
951         }
952
953         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_add_set_beacon.\n"));
954         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
955
956         prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
957                                                                 prGlueInfo->prAdapter,
958                                                                 RAM_TYPE_MSG,
959                                                                 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
960
961         if (prP2pBcnUpdateMsg == NULL) {
962             ASSERT(FALSE);
963             i4Rslt = -ENOMEM;
964             break;
965         }
966
967
968         prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
969         pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
970
971         if (info->head_len != 0) {
972             kalMemCopy(pucBuffer, info->head, info->head_len);
973
974             prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
975
976             prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
977
978             pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
979         }
980         else {
981             prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
982
983             prP2pBcnUpdateMsg->pucBcnHdr = NULL;
984         }
985
986         if (info->tail_len != 0) {
987             UINT_8 ucLen = info->tail_len;
988
989             prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
990
991             /*Add TIM IE*/
992             // IEEE 802.11 2007 - 7.3.2.6
993             TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
994             TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP)/*((u4N2 - u4N1) + 4)*/; // NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only)
995             TIM_IE(pucBuffer)->ucDTIMCount = 0/*prBssInfo->ucDTIMCount*/; // will be overwrite by FW
996             TIM_IE(pucBuffer)->ucDTIMPeriod = 1;
997             TIM_IE(pucBuffer)->ucBitmapControl = 0/*ucBitmapControl | (UINT_8)u4N1*/; // will be overwrite by FW
998             ucLen += IE_SIZE(pucBuffer);
999             pucBuffer += IE_SIZE(pucBuffer);
1000
1001             kalMemCopy(pucBuffer, info->tail, info->tail_len);
1002
1003             prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
1004         }
1005         else {
1006             prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
1007
1008             prP2pBcnUpdateMsg->pucBcnBody = NULL;
1009         }
1010
1011
1012         mboxSendMsg(prGlueInfo->prAdapter,
1013                             MBOX_ID_0,
1014                             (P_MSG_HDR_T)prP2pBcnUpdateMsg,
1015                             MSG_SEND_METHOD_BUF);
1016
1017
1018         prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
1019                                                         prGlueInfo->prAdapter,
1020                                                         RAM_TYPE_MSG,
1021                                                         sizeof(MSG_P2P_START_AP_T));
1022
1023         if (prP2pStartAPMsg == NULL) {
1024             ASSERT(FALSE);
1025             i4Rslt = -ENOMEM;
1026             break;
1027         }
1028
1029         prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
1030
1031         prP2pStartAPMsg->fgIsPrivacy = FALSE;
1032
1033         prP2pStartAPMsg->u4BcnInterval = info->interval;
1034
1035         prP2pStartAPMsg->u4DtimPeriod = info->dtim_period;
1036
1037         /* Copy NO SSID. */
1038         prP2pStartAPMsg->ucHiddenSsidType = ENUM_HIDDEN_SSID_NONE;
1039
1040 #if 0
1041         if (info->head_len > OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)) {
1042             P_WLAN_BEACON_FRAME_T prWlanBcnFrame = info->head;
1043
1044             prSsidIE = (P_IE_HDR_T)p2pFuncGetSpecIE(prGlueInfo->prAdapter,
1045                                     (PUINT_8)prWlanBcnFrame->aucInfoElem,
1046                                     (info->head_len - OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)),
1047                                     ELEM_ID_SSID,
1048                                     NULL);
1049
1050             kalMemCopy(prP2pStartAPMsg->aucSsid, SSID_IE(prSsidIE)->aucSSID, IE_LEN(prSsidIE));
1051
1052         }
1053 #endif
1054
1055         mboxSendMsg(prGlueInfo->prAdapter,
1056                             MBOX_ID_0,
1057                             (P_MSG_HDR_T)prP2pStartAPMsg,
1058                             MSG_SEND_METHOD_BUF);
1059
1060         i4Rslt = 0;
1061
1062     } while (FALSE);
1063
1064     return i4Rslt;
1065 }
1066 /* mtk_p2p_cfg80211_add_set_beacon */
1067 #endif
1068
1069 int
1070 mtk_p2p_cfg80211_stop_ap (
1071     struct wiphy *wiphy,
1072     struct net_device *dev
1073     )
1074 {
1075     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1076     INT_32 i4Rslt = -EINVAL;
1077     P_MSG_P2P_SWITCH_OP_MODE_T prP2pSwitchMode = (P_MSG_P2P_SWITCH_OP_MODE_T)NULL;
1078
1079     do {
1080         if (wiphy == NULL) {
1081             break;
1082         }
1083
1084
1085         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_stop_ap.\n"));
1086         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1087
1088         // Switch OP MOde.
1089         prP2pSwitchMode = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
1090
1091         if (prP2pSwitchMode == NULL) {
1092             ASSERT(FALSE);
1093             i4Rslt = -ENOMEM;
1094             break;
1095         }
1096
1097         prP2pSwitchMode->rMsgHdr.eMsgId = MID_MNY_P2P_STOP_AP;
1098
1099         mboxSendMsg(prGlueInfo->prAdapter,
1100                             MBOX_ID_0,
1101                             (P_MSG_HDR_T)prP2pSwitchMode,
1102                             MSG_SEND_METHOD_BUF);
1103
1104         i4Rslt = 0;
1105     } while (FALSE);
1106
1107
1108     return i4Rslt;
1109 } /* mtk_p2p_cfg80211_stop_ap */
1110
1111 // TODO:
1112 int
1113 mtk_p2p_cfg80211_deauth (
1114     struct wiphy *wiphy,
1115     struct net_device *dev,
1116     struct cfg80211_deauth_request *req
1117 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
1118     , void *cookie
1119 #endif
1120     )
1121 {
1122     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1123
1124     ASSERT(wiphy);
1125
1126     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1127
1128     // not implemented yet
1129     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_deauth.\n"));
1130
1131     return -EINVAL;
1132 } /* mtk_p2p_cfg80211_deauth */
1133
1134
1135 // TODO:
1136 int
1137 mtk_p2p_cfg80211_disassoc (
1138     struct wiphy *wiphy,
1139     struct net_device *dev,
1140     struct cfg80211_disassoc_request *req
1141 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
1142     , void *cookie
1143 #endif
1144     )
1145 {
1146     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1147
1148     ASSERT(wiphy);
1149
1150     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1151
1152     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disassoc.\n"));
1153
1154     // not implemented yet
1155
1156     return -EINVAL;
1157 } /* mtk_p2p_cfg80211_disassoc */
1158
1159
1160 int
1161 mtk_p2p_cfg80211_remain_on_channel (
1162     struct wiphy *wiphy,
1163     struct net_device *dev,
1164     struct ieee80211_channel *chan,
1165     enum nl80211_channel_type channel_type,
1166     unsigned int duration,
1167     u64 *cookie
1168     )
1169 {
1170     INT_32 i4Rslt = -EINVAL;
1171     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1172     P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1173     P_MSG_P2P_CHNL_REQUEST_T prMsgChnlReq = (P_MSG_P2P_CHNL_REQUEST_T)NULL;
1174
1175
1176     do {
1177         if ((wiphy == NULL) ||
1178                 (dev == NULL) ||
1179                 (chan == NULL) ||
1180                 (cookie == NULL)) {
1181             break;
1182         }
1183
1184         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1185         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1186
1187         *cookie = prGlueP2pInfo->u8Cookie++;
1188
1189         prMsgChnlReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_REQUEST_T));
1190
1191         if (prMsgChnlReq == NULL) {
1192             ASSERT(FALSE);
1193             i4Rslt = -ENOMEM;
1194             break;
1195         }
1196
1197         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_remain_on_channel\n"));
1198
1199         prMsgChnlReq->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_REQ;
1200         prMsgChnlReq->u8Cookie = *cookie;
1201         prMsgChnlReq->u4Duration = duration;
1202
1203
1204         mtk_p2p_cfg80211func_channel_format_switch(chan,
1205                                                     channel_type,
1206                                                     &prMsgChnlReq->rChannelInfo,
1207                                                     &prMsgChnlReq->eChnlSco);
1208
1209         mboxSendMsg(prGlueInfo->prAdapter,
1210                             MBOX_ID_0,
1211                             (P_MSG_HDR_T)prMsgChnlReq,
1212                             MSG_SEND_METHOD_BUF);
1213
1214         i4Rslt = 0;
1215
1216         i4Rslt = 0;
1217     } while (FALSE);
1218
1219
1220     return i4Rslt;
1221 }
1222 /* mtk_p2p_cfg80211_remain_on_channel */
1223
1224
1225 int
1226 mtk_p2p_cfg80211_cancel_remain_on_channel (
1227     struct wiphy *wiphy,
1228     struct net_device *dev,
1229     u64 cookie
1230     )
1231 {
1232     INT_32 i4Rslt = -EINVAL;
1233     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1234     P_MSG_P2P_CHNL_ABORT_T prMsgChnlAbort = (P_MSG_P2P_CHNL_ABORT_T)NULL;
1235
1236     do {
1237         if ((wiphy == NULL) || (dev == NULL)) {
1238             break;
1239         }
1240
1241
1242         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1243
1244         prMsgChnlAbort = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_ABORT_T));
1245
1246         if (prMsgChnlAbort == NULL) {
1247             ASSERT(FALSE);
1248             i4Rslt = -ENOMEM;
1249             break;
1250         }
1251
1252         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_cancel_remain_on_channel\n"));
1253
1254         prMsgChnlAbort->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_ABORT;
1255         prMsgChnlAbort->u8Cookie = cookie;
1256
1257
1258         mboxSendMsg(prGlueInfo->prAdapter,
1259                                     MBOX_ID_0,
1260                                     (P_MSG_HDR_T)prMsgChnlAbort,
1261                                     MSG_SEND_METHOD_BUF);
1262
1263         i4Rslt = 0;
1264     } while (FALSE);
1265
1266     return i4Rslt;
1267 } /* mtk_p2p_cfg80211_cancel_remain_on_channel */
1268
1269 int
1270 mtk_p2p_cfg80211_mgmt_tx (
1271     struct wiphy *wiphy, struct net_device *dev,
1272     struct ieee80211_channel *chan, bool offchan,
1273     enum nl80211_channel_type channel_type,
1274     bool channel_type_valid, unsigned int wait,
1275     const u8 *buf,
1276     size_t len,
1277 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
1278     bool no_cck,
1279     bool dont_wait_for_ack,
1280 #endif
1281     u64 *cookie
1282     )
1283 {
1284     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1285     P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T)NULL;
1286     INT_32 i4Rslt = -EINVAL;
1287     P_MSG_P2P_MGMT_TX_REQUEST_T prMsgTxReq = (P_MSG_P2P_MGMT_TX_REQUEST_T)NULL;
1288     P_MSDU_INFO_T prMgmtFrame = (P_MSDU_INFO_T)NULL;
1289     PUINT_8 pucFrameBuf = (PUINT_8)NULL;
1290
1291     do {
1292         if ((wiphy == NULL) ||
1293                 (buf == NULL) ||
1294                 (len == 0) ||
1295                 (dev == NULL) ||
1296                 (cookie == NULL)) {
1297             break;
1298         }
1299
1300         //DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_mgmt_tx\n"));
1301
1302         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1303         prGlueP2pInfo = prGlueInfo->prP2PInfo;
1304
1305         *cookie = prGlueP2pInfo->u8Cookie++;
1306
1307         /* Channel & Channel Type & Wait time are ignored. */
1308         prMsgTxReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_MGMT_TX_REQUEST_T));
1309
1310         if (prMsgTxReq == NULL) {
1311             ASSERT(FALSE);
1312             i4Rslt = -ENOMEM;
1313             break;
1314         }
1315
1316         prMsgTxReq->fgNoneCckRate = FALSE;
1317         prMsgTxReq->fgIsWaitRsp = TRUE;
1318
1319         prMgmtFrame = cnmMgtPktAlloc(prGlueInfo->prAdapter, (UINT_32)(len + MAC_TX_RESERVED_FIELD));
1320
1321         if ((prMsgTxReq->prMgmtMsduInfo = prMgmtFrame) == NULL) {
1322             ASSERT(FALSE);
1323             i4Rslt = -ENOMEM;
1324             break;
1325         }
1326
1327         prMsgTxReq->u8Cookie = *cookie;
1328         prMsgTxReq->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_TX;
1329
1330         pucFrameBuf = (PUINT_8)((UINT_32)prMgmtFrame->prPacket + MAC_TX_RESERVED_FIELD);
1331
1332         kalMemCopy(pucFrameBuf, buf, len);
1333
1334         prMgmtFrame->u2FrameLength = len;
1335
1336         mboxSendMsg(prGlueInfo->prAdapter,
1337                             MBOX_ID_0,
1338                             (P_MSG_HDR_T)prMsgTxReq,
1339                             MSG_SEND_METHOD_BUF);
1340
1341         i4Rslt = 0;
1342     } while (FALSE);
1343
1344     if ((i4Rslt != 0) && (prMsgTxReq != NULL)) {
1345         if (prMsgTxReq->prMgmtMsduInfo != NULL) {
1346             cnmMgtPktFree(prGlueInfo->prAdapter, prMsgTxReq->prMgmtMsduInfo);
1347         }
1348
1349         cnmMemFree(prGlueInfo->prAdapter, prMsgTxReq);
1350     }
1351
1352     return i4Rslt;
1353 } /* mtk_p2p_cfg80211_mgmt_tx */
1354
1355
1356
1357 int
1358 mtk_p2p_cfg80211_change_bss (
1359     struct wiphy *wiphy,
1360     struct net_device *dev,
1361     struct bss_parameters *params
1362     )
1363 {
1364     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1365     INT_32 i4Rslt = -EINVAL;
1366
1367     ASSERT(wiphy);
1368
1369     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1370
1371
1372     switch (params->use_cts_prot) {
1373     case -1:
1374         DBGLOG(P2P, TRACE, ("CTS protection no change\n"));
1375         break;
1376     case 0:
1377         DBGLOG(P2P, TRACE, ("CTS protection disable.\n"));
1378         break;
1379     case 1:
1380         DBGLOG(P2P, TRACE, ("CTS protection enable\n"));
1381         break;
1382     default:
1383         DBGLOG(P2P, TRACE, ("CTS protection unknown\n"));
1384         break;
1385     }
1386
1387
1388
1389     switch (params->use_short_preamble) {
1390     case -1:
1391         DBGLOG(P2P, TRACE, ("Short prreamble no change\n"));
1392         break;
1393     case 0:
1394         DBGLOG(P2P, TRACE, ("Short prreamble disable.\n"));
1395         break;
1396     case 1:
1397         DBGLOG(P2P, TRACE, ("Short prreamble enable\n"));
1398         break;
1399     default:
1400         DBGLOG(P2P, TRACE, ("Short prreamble unknown\n"));
1401         break;
1402     }
1403
1404
1405
1406 #if 0
1407     // not implemented yet
1408     p2pFuncChangeBssParam(prGlueInfo->prAdapter,
1409                         prBssInfo->fgIsProtection,
1410                         prBssInfo->fgIsShortPreambleAllowed,
1411                         prBssInfo->fgUseShortSlotTime,
1412                         // Basic rates
1413                         // basic rates len
1414                         // ap isolate
1415                         // ht opmode.
1416                         );
1417 #else
1418     i4Rslt = 0;
1419 #endif
1420
1421     return i4Rslt;
1422 } /* mtk_p2p_cfg80211_change_bss */
1423
1424
1425
1426 int
1427 mtk_p2p_cfg80211_del_station (
1428     struct wiphy *wiphy,
1429     struct net_device *dev,
1430     u8 *mac
1431     )
1432 {
1433     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1434     INT_32 i4Rslt = -EINVAL;
1435     P_MSG_P2P_CONNECTION_ABORT_T prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
1436     UINT_8 aucBcMac[] = BC_MAC_ADDR;
1437
1438
1439     do {
1440         if ((wiphy == NULL) ||
1441                     (dev == NULL)) {
1442             break;
1443         }
1444
1445         if (mac == NULL) {
1446             mac = aucBcMac;
1447         }
1448
1449         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_del_station.\n"));
1450
1451         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1452
1453         //prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)kalMemAlloc(sizeof(MSG_P2P_CONNECTION_ABORT_T), VIR_MEM_TYPE);
1454         prDisconnectMsg = (P_MSG_P2P_CONNECTION_ABORT_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
1455
1456         if (prDisconnectMsg == NULL) {
1457             ASSERT(FALSE);
1458             i4Rslt = -ENOMEM;
1459             break;
1460         }
1461
1462         prDisconnectMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
1463         COPY_MAC_ADDR(prDisconnectMsg->aucTargetID, mac);
1464         prDisconnectMsg->u2ReasonCode = REASON_CODE_UNSPECIFIED;
1465
1466         mboxSendMsg(prGlueInfo->prAdapter,
1467                         MBOX_ID_0,
1468                         (P_MSG_HDR_T)prDisconnectMsg,
1469                         MSG_SEND_METHOD_BUF);
1470
1471         i4Rslt = 0;
1472     } while (FALSE);
1473
1474     return i4Rslt;
1475
1476 } /* mtk_p2p_cfg80211_del_station */
1477
1478
1479 int 
1480 mtk_p2p_cfg80211_connect (
1481     struct wiphy *wiphy,
1482     struct net_device *dev,
1483     struct cfg80211_connect_params *sme
1484     )
1485 {
1486     INT_32 i4Rslt = -EINVAL;
1487     P_GLUE_INFO_T prGlueInfo = NULL;
1488     P_MSG_P2P_CONNECTION_REQUEST_T prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)NULL;
1489
1490
1491     do {
1492         if ((wiphy == NULL) ||
1493                 (dev == NULL) ||
1494                 (sme == NULL)) {
1495             break;
1496         }
1497
1498         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_connect.\n"));
1499
1500         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1501
1502         prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, (sizeof(MSG_P2P_CONNECTION_REQUEST_T) + sme->ie_len));
1503
1504         if (prConnReqMsg == NULL) {
1505             ASSERT(FALSE);
1506             i4Rslt = -ENOMEM;
1507             break;
1508         }
1509
1510         prConnReqMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
1511
1512         COPY_SSID(prConnReqMsg->rSsid.aucSsid,
1513                                 prConnReqMsg->rSsid.ucSsidLen,
1514                                 sme->ssid,
1515                                 sme->ssid_len);
1516
1517         COPY_MAC_ADDR(prConnReqMsg->aucBssid, sme->bssid);
1518
1519         DBGLOG(P2P, TRACE, ("Assoc Req IE Buffer Length:%d\n", sme->ie_len));
1520         kalMemCopy(prConnReqMsg->aucIEBuf, sme->ie, sme->ie_len);
1521         prConnReqMsg->u4IELen = sme->ie_len;
1522
1523         mtk_p2p_cfg80211func_channel_format_switch(sme->channel,
1524                                                     NL80211_CHAN_NO_HT,
1525                                                     &prConnReqMsg->rChannelInfo,
1526                                                     &prConnReqMsg->eChnlSco);
1527
1528         mboxSendMsg(prGlueInfo->prAdapter,
1529                         MBOX_ID_0,
1530                         (P_MSG_HDR_T)prConnReqMsg,
1531                         MSG_SEND_METHOD_BUF);
1532
1533
1534         i4Rslt = 0;
1535     } while (FALSE);
1536
1537     return i4Rslt;
1538 } /* mtk_p2p_cfg80211_connect */
1539
1540 int 
1541 mtk_p2p_cfg80211_disconnect (
1542     struct wiphy *wiphy,
1543     struct net_device *dev,
1544     u16 reason_code
1545     )
1546 {
1547     INT_32 i4Rslt = -EINVAL;
1548     P_GLUE_INFO_T prGlueInfo = NULL;
1549     P_MSG_P2P_CONNECTION_ABORT_T prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)NULL;
1550     UINT_8 aucBCAddr[] = BC_MAC_ADDR;
1551
1552     do {
1553         if ((wiphy == NULL) ||
1554                 (dev == NULL)) {
1555             break;
1556         }
1557
1558         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disconnect.\n"));
1559
1560         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1561
1562 //        prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)kalMemAlloc(sizeof(P_MSG_P2P_CONNECTION_ABORT_T), VIR_MEM_TYPE);
1563         prDisconnMsg = (P_MSG_P2P_CONNECTION_ABORT_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
1564
1565         if (prDisconnMsg == NULL) {
1566             ASSERT(FALSE);
1567             i4Rslt = -ENOMEM;
1568             break;
1569         }
1570
1571         prDisconnMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
1572         prDisconnMsg->u2ReasonCode = reason_code;
1573         prDisconnMsg->fgSendDeauth = TRUE;
1574         COPY_MAC_ADDR(prDisconnMsg->aucTargetID, aucBCAddr);
1575
1576         mboxSendMsg(prGlueInfo->prAdapter,
1577                                 MBOX_ID_0,
1578                                 (P_MSG_HDR_T)prDisconnMsg,
1579                                 MSG_SEND_METHOD_BUF);
1580
1581         i4Rslt = 0;
1582     } while (FALSE);
1583
1584     return i4Rslt;
1585 } /* mtk_p2p_cfg80211_disconnect */
1586
1587
1588 int
1589 mtk_p2p_cfg80211_change_iface (
1590     IN struct wiphy *wiphy,
1591     IN struct net_device *ndev,
1592     IN enum nl80211_iftype type,
1593     IN u32 *flags,
1594     IN struct vif_params *params
1595     )
1596 {
1597     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1598     INT_32 i4Rslt = -EINVAL;
1599     P_MSG_P2P_SWITCH_OP_MODE_T prSwitchModeMsg = (P_MSG_P2P_SWITCH_OP_MODE_T)NULL;
1600
1601     do {
1602         if ((wiphy == NULL) ||
1603                 (ndev == NULL)) {
1604             break;
1605         }
1606
1607         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_iface.\n"));
1608
1609         if (ndev->ieee80211_ptr) {
1610             ndev->ieee80211_ptr->iftype = type;
1611         }
1612
1613         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1614
1615
1616         // Switch OP MOde.
1617         prSwitchModeMsg = (P_MSG_P2P_SWITCH_OP_MODE_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
1618
1619         if (prSwitchModeMsg == NULL) {
1620             ASSERT(FALSE);
1621             i4Rslt = -ENOMEM;
1622             break;
1623         }
1624
1625         prSwitchModeMsg->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
1626
1627         switch (type) {
1628         case NL80211_IFTYPE_P2P_CLIENT:
1629             DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_P2P_CLIENT.\n"));
1630         case NL80211_IFTYPE_STATION:
1631             if (type == NL80211_IFTYPE_STATION) {
1632                 DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_STATION.\n"));
1633             }
1634             prSwitchModeMsg->eOpMode = OP_MODE_INFRASTRUCTURE;
1635             break;
1636         case NL80211_IFTYPE_AP:
1637             DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_AP.\n"));
1638         case NL80211_IFTYPE_P2P_GO:
1639             if (type == NL80211_IFTYPE_P2P_GO) {
1640                 DBGLOG(P2P, TRACE, ("NL80211_IFTYPE_P2P_GO not AP.\n"));
1641             }
1642             prSwitchModeMsg->eOpMode = OP_MODE_ACCESS_POINT;
1643             break;
1644         default:
1645             DBGLOG(P2P, TRACE, ("Other type :%d .\n", type));
1646             prSwitchModeMsg->eOpMode = OP_MODE_P2P_DEVICE;
1647             break;
1648         }
1649
1650
1651         mboxSendMsg(prGlueInfo->prAdapter,
1652                             MBOX_ID_0,
1653                             (P_MSG_HDR_T)prSwitchModeMsg,
1654                             MSG_SEND_METHOD_BUF);
1655
1656         i4Rslt = 0;
1657
1658     } while (FALSE);
1659
1660     return i4Rslt;
1661
1662 } /* mtk_p2p_cfg80211_change_iface */
1663
1664
1665 int
1666 mtk_p2p_cfg80211_set_channel (
1667     IN struct wiphy *wiphy,
1668     IN struct net_device *dev,
1669     IN struct ieee80211_channel *chan,
1670     IN enum nl80211_channel_type channel_type)
1671 {
1672     INT_32 i4Rslt = -EINVAL;
1673     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1674     RF_CHANNEL_INFO_T rRfChnlInfo;
1675
1676     do {
1677         if ((wiphy == NULL) ||
1678                 (dev == NULL) ||
1679                 (chan == NULL)) {
1680             break;
1681         }
1682
1683         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_channel.\n"));
1684
1685         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1686
1687         mtk_p2p_cfg80211func_channel_format_switch(chan,
1688                                         channel_type,
1689                                         &rRfChnlInfo,
1690                                         NULL);
1691
1692         p2pFuncSetChannel(prGlueInfo->prAdapter, &rRfChnlInfo);
1693
1694         i4Rslt = 0;
1695     }
1696 while (FALSE);
1697
1698     return i4Rslt;
1699
1700 }
1701 /* mtk_p2p_cfg80211_set_channel */
1702
1703 int
1704 mtk_p2p_cfg80211_set_bitrate_mask (
1705     IN struct wiphy *wiphy,
1706     IN struct net_device *dev,
1707     IN const u8 *peer,
1708     IN const struct cfg80211_bitrate_mask *mask
1709     )
1710 {
1711     INT_32 i4Rslt = -EINVAL;
1712     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1713
1714     do {
1715         if ((wiphy == NULL) ||
1716                 (dev == NULL) ||
1717                 (mask == NULL)) {
1718             break;
1719         }
1720
1721         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_bitrate_mask\n"));
1722
1723         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1724
1725         // TODO: Set bitrate mask of the peer?
1726
1727         i4Rslt = 0;
1728     }
1729 while (FALSE);
1730
1731     return i4Rslt;
1732 } /* mtk_p2p_cfg80211_set_bitrate_mask */
1733
1734
1735 void
1736 mtk_p2p_cfg80211_mgmt_frame_register (
1737     IN struct wiphy *wiphy,
1738     IN struct net_device *dev,
1739     IN u16 frame_type,
1740     IN bool reg
1741     )
1742 {
1743 #if 0
1744     P_MSG_P2P_MGMT_FRAME_REGISTER_T prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)NULL;
1745 #endif
1746     P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1747
1748     do {
1749         if ((wiphy == NULL) ||
1750                 (dev == NULL)) {
1751             break;
1752         }
1753
1754         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_mgmt_frame_register\n"));
1755
1756         prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1757
1758
1759         switch (frame_type) {
1760         case MAC_FRAME_PROBE_REQ:
1761             if (reg) {
1762                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_PROBE_REQ;
1763                 DBGLOG(P2P, TRACE, ("Open packet filer probe request\n"));
1764             }
1765             else {
1766                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_PROBE_REQ;
1767                 DBGLOG(P2P, TRACE, ("Close packet filer probe request\n"));
1768             }
1769             break;
1770         case MAC_FRAME_ACTION:
1771             if (reg) {
1772                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_ACTION_FRAME;
1773                 DBGLOG(P2P, TRACE, ("Open packet filer action frame.\n"));
1774             }
1775             else {
1776                 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_ACTION_FRAME;
1777                 DBGLOG(P2P, TRACE, ("Close packet filer action frame.\n"));
1778             }
1779             break;
1780         default:
1781                 DBGLOG(P2P, ERROR, ("Ask frog to add code for mgmt:%x\n", frame_type));
1782                 break;
1783         }
1784
1785         
1786
1787         if((prGlueInfo->prAdapter != NULL)  && (prGlueInfo->prAdapter->fgIsP2PRegistered == TRUE)){
1788
1789            prGlueInfo->u4Flag |= GLUE_FLAG_FRAME_FILTER;
1790
1791         /* wake up main thread */
1792         wake_up_interruptible(&prGlueInfo->waitq);
1793
1794            if (in_interrupt()) {
1795               DBGLOG(P2P, TRACE, ("It is in interrupt level\n"));
1796            }
1797         }
1798
1799
1800 #if 0
1801
1802
1803         prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)cnmMemAlloc(prGlueInfo->prAdapter, 
1804                                                                     RAM_TYPE_MSG, 
1805                                                                     sizeof(MSG_P2P_MGMT_FRAME_REGISTER_T));
1806
1807         if (prMgmtFrameRegister == NULL) {
1808             ASSERT(FALSE);
1809             break;
1810         }
1811
1812         prMgmtFrameRegister->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_FRAME_REGISTER;
1813
1814         prMgmtFrameRegister->u2FrameType = frame_type;
1815         prMgmtFrameRegister->fgIsRegister = reg;
1816
1817         mboxSendMsg(prGlueInfo->prAdapter,
1818                                     MBOX_ID_0,
1819                                     (P_MSG_HDR_T)prMgmtFrameRegister,
1820                                     MSG_SEND_METHOD_BUF);
1821
1822 #endif
1823
1824     } while (FALSE);
1825
1826
1827     return;
1828 } /* mtk_p2p_cfg80211_mgmt_frame_register */
1829
1830
1831 BOOLEAN
1832 mtk_p2p_cfg80211func_channel_format_switch (
1833     IN struct ieee80211_channel *channel,
1834     IN enum nl80211_channel_type channel_type,
1835     IN P_RF_CHANNEL_INFO_T prRfChnlInfo,
1836     IN P_ENUM_CHNL_EXT_T prChnlSco
1837     )
1838 {
1839     BOOLEAN fgIsValid = FALSE;
1840
1841     do {
1842         if (channel == NULL) {
1843             break;
1844         }
1845
1846         if (prRfChnlInfo) {
1847             prRfChnlInfo->ucChannelNum = nicFreq2ChannelNum(channel->center_freq * 1000);
1848
1849             switch (channel->band) {
1850             case IEEE80211_BAND_2GHZ:
1851                 prRfChnlInfo->eBand = BAND_2G4;
1852                 break;
1853             case IEEE80211_BAND_5GHZ:
1854                 prRfChnlInfo->eBand = BAND_5G;
1855                 break;
1856             default:
1857                 prRfChnlInfo->eBand = BAND_2G4;
1858                 break;
1859             }
1860         
1861         }
1862
1863         
1864         if (prChnlSco) {
1865             
1866             switch (channel_type) {
1867             case NL80211_CHAN_NO_HT:
1868                 *prChnlSco = CHNL_EXT_SCN;
1869                 break;
1870             case NL80211_CHAN_HT20:
1871                 *prChnlSco = CHNL_EXT_SCN;
1872                 break;
1873             case NL80211_CHAN_HT40MINUS:
1874                 *prChnlSco = CHNL_EXT_SCA;
1875                 break;
1876             case NL80211_CHAN_HT40PLUS:
1877                 *prChnlSco = CHNL_EXT_SCB;
1878                 break;
1879             default:
1880                 ASSERT(FALSE);
1881                 *prChnlSco = CHNL_EXT_SCN;
1882                 break;
1883             }
1884         }
1885
1886         fgIsValid = TRUE;
1887     }
1888 while (FALSE);
1889
1890     return fgIsValid;
1891 }
1892 /* mtk_p2p_cfg80211func_channel_format_switch */
1893
1894
1895 #if CONFIG_NL80211_TESTMODE
1896 int mtk_p2p_cfg80211_testmode_cmd(
1897     IN struct wiphy *wiphy,
1898     IN void *data,
1899     IN int len
1900     )
1901 {
1902     P_GLUE_INFO_T prGlueInfo = NULL;
1903     P_NL80211_DRIVER_TEST_PARAMS prParams = (P_NL80211_DRIVER_TEST_PARAMS)NULL;
1904     BOOLEAN fgIsValid = FALSE;
1905
1906     ASSERT(wiphy);
1907
1908     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1909
1910         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_cmd\n"));
1911     
1912  
1913     if(data && len)
1914         prParams = (P_NL80211_DRIVER_TEST_PARAMS)data;
1915
1916     if(prParams->index >> 24 == 0x01) { 
1917         /* New version */
1918         prParams->index = prParams->index & ~ BITS(24,31);
1919     }
1920     else {  
1921         /* Old version*/
1922         mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(wiphy, data, len); 
1923                 fgIsValid = TRUE;
1924         return fgIsValid;
1925     }
1926
1927     /* Clear the version byte */
1928     prParams->index = prParams->index & ~ BITS(24,31);
1929
1930         if(prParams){
1931                 switch(prParams->index){
1932                     case 1: /* P2P Simga */
1933                             if(mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(wiphy, data, len))
1934                                         fgIsValid = TRUE;
1935                             break;
1936 #if CFG_SUPPORT_WFD 
1937                         case 2: /* WFD */
1938                                 if(mtk_p2p_cfg80211_testmode_wfd_update_cmd(wiphy, data, len))
1939                                         fgIsValid= TRUE;
1940                             break;
1941 #endif
1942             case 3: /* Hotspot Client Management */
1943                 if(mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(wiphy, data, len))
1944                                         fgIsValid = TRUE;
1945                 break;
1946                         default:
1947                                 fgIsValid = TRUE;
1948                             break;
1949                 }
1950         }
1951
1952         return fgIsValid;
1953
1954 }
1955
1956
1957 int mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(
1958     IN struct wiphy *wiphy,
1959     IN void *data,
1960     IN int len
1961     )
1962 {
1963     P_GLUE_INFO_T prGlueInfo = NULL;
1964         NL80211_DRIVER_TEST_PRE_PARAMS rParams;
1965         P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
1966     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
1967         UINT_32 index_mode;
1968         UINT_32 index;
1969     INT_32  value;
1970         int     status = 0;
1971         UINT_32 u4Leng;
1972
1973     ASSERT(wiphy);
1974
1975     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1976
1977         kalMemZero(&rParams, sizeof(NL80211_DRIVER_TEST_PRE_PARAMS));
1978
1979         prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
1980     prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
1981
1982         DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd\n"));
1983
1984         if(data && len)
1985                 memcpy(&rParams, data, len);
1986
1987     DBGLOG(P2P, TRACE, ("NL80211_ATTR_TESTDATA,idx_mode=%d idx=%d value=%lu\n",
1988                 (INT_16)rParams.idx_mode, (INT_16)rParams.idx, rParams.value));
1989
1990     index_mode = rParams.idx_mode;
1991         index = rParams.idx;
1992         value = rParams.value;
1993
1994     switch (index) {
1995       case 0: /* Listen CH */
1996           break;
1997       case 1: /* P2p mode */
1998           break;
1999       case 4: /* Noa duration */
2000           prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
2001           // only to apply setting when setting NOA count
2002           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2003           break;
2004       case 5: /* Noa interval */
2005           prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
2006           // only to apply setting when setting NOA count
2007           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2008           break;
2009       case 6: /* Noa count */
2010           prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2011           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2012           break;
2013       case 100: /* Oper CH */
2014           // 20110920 - frog: User configurations are placed in ConnSettings.
2015           // prP2pConnSettings->ucOperatingChnl = value;
2016           break;
2017       case 101: /* Local config Method, for P2P SDK */
2018           prP2pConnSettings->u2LocalConfigMethod = value;
2019           break;
2020       case 102: /* Sigma P2p reset */
2021           //kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
2022           //prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO;
2023           p2pFsmUninit(prGlueInfo->prAdapter);
2024           p2pFsmInit(prGlueInfo->prAdapter);
2025           break;
2026       case 103: /* WPS MODE */
2027           kalP2PSetWscMode(prGlueInfo, value);
2028           break;
2029       case 104: /* P2p send persence, duration */
2030           break;
2031       case 105: /* P2p send persence, interval */
2032           break;
2033       case 106: /* P2P set sleep  */
2034             value = 1;
2035             kalIoctl(prGlueInfo,
2036                 wlanoidSetP2pPowerSaveProfile,
2037                 &value,
2038                 sizeof(value),
2039                 FALSE,
2040                 FALSE,
2041                 TRUE,
2042                 TRUE,
2043                 &u4Leng);
2044           break;
2045       case 107: /* P2P set opps, CTWindowl */
2046             prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
2047             //status = mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
2048           break;
2049       case 108: /* p2p_set_power_save */
2050             kalIoctl(prGlueInfo,
2051                 wlanoidSetP2pPowerSaveProfile,
2052                 &value,
2053                 sizeof(value),
2054                 FALSE,
2055                 FALSE,
2056                 TRUE,
2057                 TRUE,
2058                 &u4Leng);
2059
2060           break;
2061       default:
2062           break;
2063     }
2064
2065     return status;
2066
2067 }
2068
2069
2070 int
2071 mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(
2072     IN struct wiphy *wiphy,
2073     IN void *data,
2074     IN int len)
2075 {
2076     P_GLUE_INFO_T prGlueInfo = NULL;
2077     P_NL80211_DRIVER_P2P_SIGMA_PARAMS prParams = (P_NL80211_DRIVER_P2P_SIGMA_PARAMS)NULL;
2078         P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T)NULL;
2079     P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T)NULL;
2080         UINT_32 index;
2081     INT_32  value;
2082         int     status = 0;
2083         UINT_32 u4Leng;
2084
2085     ASSERT(wiphy);
2086
2087     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2088
2089     prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
2090     prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
2091
2092     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_p2p_sigma_cmd\n"));
2093
2094     if(data && len)
2095         prParams = (P_NL80211_DRIVER_P2P_SIGMA_PARAMS)data;
2096
2097     index = (INT_32)prParams->idx;
2098     value = (INT_32)prParams->value;
2099
2100         DBGLOG(P2P, TRACE, ("NL80211_ATTR_TESTDATA, idx=%lu value=%lu\n",
2101                 (INT_32)prParams->idx, (INT_32)prParams->value));
2102
2103     switch (index) {
2104       case 0: /* Listen CH */
2105           break;
2106       case 1: /* P2p mode */
2107           break;
2108       case 4: /* Noa duration */
2109           prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
2110           // only to apply setting when setting NOA count
2111           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2112           break;
2113       case 5: /* Noa interval */
2114           prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
2115           // only to apply setting when setting NOA count
2116           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2117           break;
2118       case 6: /* Noa count */
2119           prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2120           //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2121           break;
2122       case 100: /* Oper CH */
2123           // 20110920 - frog: User configurations are placed in ConnSettings.
2124           // prP2pConnSettings->ucOperatingChnl = value;
2125           break;
2126       case 101: /* Local config Method, for P2P SDK */
2127           prP2pConnSettings->u2LocalConfigMethod = value;
2128           break;
2129       case 102: /* Sigma P2p reset */
2130           //kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
2131           //prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO;
2132           break;
2133       case 103: /* WPS MODE */
2134           kalP2PSetWscMode(prGlueInfo, value);
2135           break;
2136       case 104: /* P2p send persence, duration */
2137           break;
2138       case 105: /* P2p send persence, interval */
2139           break;
2140       case 106: /* P2P set sleep  */
2141             value = 1;
2142             kalIoctl(prGlueInfo,
2143                 wlanoidSetP2pPowerSaveProfile,
2144                 &value,
2145                 sizeof(value),
2146                 FALSE,
2147                 FALSE,
2148                 TRUE,
2149                 TRUE,
2150                 &u4Leng);
2151           break;
2152       case 107: /* P2P set opps, CTWindowl */
2153             prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
2154             //status = mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
2155           break;
2156       case 108: /* p2p_set_power_save */
2157             kalIoctl(prGlueInfo,
2158                 wlanoidSetP2pPowerSaveProfile,
2159                 &value,
2160                 sizeof(value),
2161                 FALSE,
2162                 FALSE,
2163                 TRUE,
2164                 TRUE,
2165                 &u4Leng);
2166
2167           break;
2168       case 109: /* Max Clients*/
2169           kalP2PSetMaxClients(prGlueInfo, value);
2170           break;
2171       case 110: /* Hotspot WPS mode */
2172             kalIoctl(prGlueInfo,
2173                 wlanoidSetP2pWPSmode,
2174                 &value,
2175                 sizeof(value),
2176                 FALSE,
2177                 FALSE,
2178                 TRUE,
2179                 TRUE,
2180                 &u4Leng);  
2181           break;
2182       default:
2183           break;
2184     }
2185
2186     return status;
2187
2188 }
2189
2190 #if CFG_SUPPORT_WFD
2191 int
2192 mtk_p2p_cfg80211_testmode_wfd_update_cmd(
2193     IN struct wiphy *wiphy,
2194     IN void *data,
2195     IN int len)
2196 {
2197     P_GLUE_INFO_T prGlueInfo = NULL;
2198     P_NL80211_DRIVER_WFD_PARAMS prParams = (P_NL80211_DRIVER_WFD_PARAMS)NULL;
2199     int status = 0;
2200     P_WFD_CFG_SETTINGS_T prWfdCfgSettings = (P_WFD_CFG_SETTINGS_T)NULL;
2201     P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T prMsgWfdCfgUpdate = (P_MSG_WFD_CONFIG_SETTINGS_CHANGED_T)NULL;
2202
2203     ASSERT(wiphy);
2204
2205     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2206
2207     prParams = (P_NL80211_DRIVER_WFD_PARAMS)data;
2208
2209
2210     DBGLOG(P2P, INFO, ("mtk_p2p_cfg80211_testmode_wfd_update_cmd\n"));
2211
2212 #if 1
2213
2214     DBGLOG(P2P, INFO,("WFD Enable:%x\n", prParams->WfdEnable));
2215     DBGLOG(P2P, INFO,("WFD Session Available:%x\n", prParams->WfdSessionAvailable));
2216     DBGLOG(P2P, INFO,("WFD Couple Sink Status:%x\n", prParams->WfdCoupleSinkStatus));
2217     //aucReserved0[2]
2218     DBGLOG(P2P, INFO,("WFD Device Info:%x\n", prParams->WfdDevInfo));
2219     DBGLOG(P2P, INFO,("WFD Control Port:%x\n", prParams->WfdControlPort));
2220     DBGLOG(P2P, INFO,("WFD Maximum Throughput:%x\n", prParams->WfdMaximumTp));
2221     DBGLOG(P2P, INFO,("WFD Extend Capability:%x\n", prParams->WfdExtendCap));
2222     DBGLOG(P2P, INFO,("WFD Couple Sink Addr "MACSTR" \n", MAC2STR(prParams->WfdCoupleSinkAddress)));
2223     DBGLOG(P2P, INFO,("WFD Associated BSSID "MACSTR" \n", MAC2STR(prParams->WfdAssociatedBssid)));
2224     //UINT_8 aucVideolp[4];
2225     //UINT_8 aucAudiolp[4];
2226     DBGLOG(P2P, INFO,("WFD Video Port:%x\n", prParams->WfdVideoPort));
2227     DBGLOG(P2P, INFO,("WFD Audio Port:%x\n", prParams->WfdAudioPort));
2228     DBGLOG(P2P, INFO,("WFD Flag:%x\n", prParams->WfdFlag));
2229     DBGLOG(P2P, INFO,("WFD Policy:%x\n", prParams->WfdPolicy));
2230     DBGLOG(P2P, INFO,("WFD State:%x\n", prParams->WfdState));
2231     //UINT_8 aucWfdSessionInformationIE[24*8];
2232     DBGLOG(P2P, INFO,("WFD Session Info Length:%x\n", prParams->WfdSessionInformationIELen));
2233     //UINT_8 aucReserved1[2];
2234     DBGLOG(P2P, INFO,("WFD Primary Sink Addr "MACSTR" \n", MAC2STR(prParams->aucWfdPrimarySinkMac)));
2235     DBGLOG(P2P, INFO,("WFD Secondary Sink Addr "MACSTR" \n", MAC2STR(prParams->aucWfdSecondarySinkMac)));
2236     DBGLOG(P2P, INFO,("WFD Advanced Flag:%x\n", prParams->WfdAdvanceFlag));
2237     DBGLOG(P2P, INFO,("WFD Sigma mode:%x\n", prParams->WfdSigmaMode));
2238     //UINT_8 aucReserved2[64];
2239     //UINT_8 aucReserved3[64];
2240     //UINT_8 aucReserved4[64];
2241
2242 #endif
2243
2244     prWfdCfgSettings = &(prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo->rWfdConfigureSettings);
2245
2246     kalMemCopy(&prWfdCfgSettings->u4WfdCmdType, &prParams->WfdCmdType, sizeof(WFD_CFG_SETTINGS_T));
2247
2248     prMsgWfdCfgUpdate = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_WFD_CONFIG_SETTINGS_CHANGED_T));
2249
2250     if (prMsgWfdCfgUpdate == NULL) {
2251         ASSERT(FALSE);
2252         return status;
2253     }
2254
2255     prMsgWfdCfgUpdate->rMsgHdr.eMsgId = MID_MNY_P2P_WFD_CFG_UPDATE;
2256     prMsgWfdCfgUpdate->prWfdCfgSettings = prWfdCfgSettings;
2257
2258
2259     mboxSendMsg(prGlueInfo->prAdapter,
2260                         MBOX_ID_0,
2261                         (P_MSG_HDR_T)prMsgWfdCfgUpdate,
2262                         MSG_SEND_METHOD_BUF);
2263 #if 0 // Test Only
2264 //    prWfdCfgSettings->ucWfdEnable = 1;
2265 //    prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_DEV_INFO_VALID;
2266     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_DEV_INFO_VALID;
2267     prWfdCfgSettings->u2WfdDevInfo = 123;
2268     prWfdCfgSettings->u2WfdControlPort = 456;
2269     prWfdCfgSettings->u2WfdMaximumTp = 789;
2270
2271
2272     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_SINK_INFO_VALID;
2273     prWfdCfgSettings->ucWfdCoupleSinkStatus = 0xAB;
2274     {
2275         UINT_8 aucTestAddr[MAC_ADDR_LEN] = {0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
2276         COPY_MAC_ADDR(prWfdCfgSettings->aucWfdCoupleSinkAddress, aucTestAddr);
2277     }
2278
2279     prWfdCfgSettings->u4WfdFlag |= WFD_FLAGS_EXT_CAPABILITY_VALID;
2280     prWfdCfgSettings->u2WfdExtendCap = 0xCDE;
2281
2282 #endif
2283
2284     return status;
2285
2286 }
2287 #endif /*  CFG_SUPPORT_WFD */
2288
2289
2290
2291 int
2292 mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(
2293     IN struct wiphy *wiphy,
2294     IN void *data,
2295     IN int len)
2296 {
2297     P_GLUE_INFO_T prGlueInfo = NULL;
2298     P_NL80211_DRIVER_hotspot_block_PARAMS prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)NULL;
2299     int fgIsValid = 0;
2300
2301     ASSERT(wiphy);
2302
2303     prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2304
2305     if(data && len)
2306         prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)data;
2307
2308     DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd\n"));
2309
2310     fgIsValid = kalP2PSetBlackList(prGlueInfo, prParams->aucBssid, prParams->ucblocked);
2311  
2312     return fgIsValid;
2313
2314 }
2315
2316 #endif
2317
2318
2319 #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
2320
2321 #endif // CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_WIFI_DIRECT_CFG_80211