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