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