2 ** $Id: @(#) gl_p2p_cfg80211.c@@
5 /*! \file gl_p2p_cfg80211.c
6 \brief Main routines of Linux driver interface for Wi-Fi Direct
7 using cfg80211 interface
9 This file contains the main routines of Linux driver for MediaTek Inc. 802.11
10 Wireless LAN Adapters.
13 /*******************************************************************************
14 * Copyright (c) 2007 MediaTek Inc.
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
20 ********************************************************************************
23 /*******************************************************************************
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.
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.
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
52 ********************************************************************************
56 ** $Log: gl_p2p_cfg80211.c $
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.
62 ** 08 21 2012 yuche.tsai
64 ** Fix compile warning.
66 ** 08 20 2012 yuche.tsai
68 ** Fix possible KE issue.
70 ** 08 17 2012 yuche.tsai
72 ** Fix compile warning.
74 ** 08 16 2012 yuche.tsai
76 ** Fix compile warning.
78 ** 08 14 2012 yuche.tsai
80 ** Fix p2p bug find on ALPS.JB trunk.
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.
86 ** 07 19 2012 yuche.tsai
88 ** Code update for JB.
90 * 07 17 2012 yuche.tsai
92 * Fix compile error for JB.
94 * 07 17 2012 yuche.tsai
96 * Compile no error before trial run.
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
104 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
106 * 06 06 2010 kevin.huang
107 * [WPD00003832][MT6620 5931] Create driver base
108 * [MT6620 5931] Create driver base
111 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
112 * add cfg80211 interface, which is to replace WE, for further extension
117 /*******************************************************************************
118 * C O M P I L E R F L A G S
119 ********************************************************************************
122 /*******************************************************************************
123 * E X T E R N A L R E F E R E N C E S
124 ********************************************************************************
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>
138 /*******************************************************************************
140 ********************************************************************************
143 /*******************************************************************************
145 ********************************************************************************
148 /*******************************************************************************
149 * P U B L I C D A T A
150 ********************************************************************************
153 /*******************************************************************************
154 * P R I V A T E D A T A
155 ********************************************************************************
158 /*******************************************************************************
160 ********************************************************************************
163 /*******************************************************************************
164 * F U N C T I O N D E C L A R A T I O N S
165 ********************************************************************************
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
177 /*******************************************************************************
179 ********************************************************************************
182 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
183 int mtk_p2p_cfg80211_add_key(
185 struct net_device *ndev,
189 struct key_params *params
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;
200 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
202 kalMemZero(&rKey, sizeof(P2P_PARAM_KEY_T));
204 rKey.u4KeyIndex = key_index;
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;
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);
223 rKey.u4KeyIndex |= BIT(31);
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); //????
237 //rKey.aucKeyMaterial[0] = kalMemAlloc(params->key_len, VIR_MEM_TYPE);
238 kalMemCopy(rKey.aucKeyMaterial, params->key, params->key_len);
240 rKey.u4KeyLength = params->key_len;
241 rKey.u4Length = ((UINT_32)&(((P_P2P_PARAM_KEY_T)0)->aucKeyMaterial)) + rKey.u4KeyLength;
243 rStatus = kalIoctl(prGlueInfo,
252 if (rStatus == WLAN_STATUS_SUCCESS)
259 int mtk_p2p_cfg80211_get_key(
261 struct net_device *ndev,
266 void (*callback)(void *cookie, struct key_params*)
269 P_GLUE_INFO_T prGlueInfo = NULL;
273 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
275 // not implemented yet
280 int mtk_p2p_cfg80211_del_key(
282 struct net_device *ndev,
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;
296 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
298 kalMemZero(&prRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
300 memcpy(prRemoveKey.arBSSID, mac_addr, PARAM_MAC_ADDR_LEN);
301 prRemoveKey.u4KeyIndex = key_index;
302 prRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
304 rStatus = kalIoctl(prGlueInfo,
305 wlanoidSetRemoveP2PKey,
307 prRemoveKey.u4Length,
314 if (rStatus == WLAN_STATUS_SUCCESS)
322 mtk_p2p_cfg80211_set_default_key (
324 struct net_device *netdev,
330 P_GLUE_INFO_T prGlueInfo = NULL;
334 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
336 // not implemented yet
341 int mtk_p2p_cfg80211_get_station(
343 struct net_device *ndev,
345 struct station_info *sinfo
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;
356 if ((wiphy == NULL) ||
363 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_get_station\n"));
365 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
366 prP2pGlueInfo = prGlueInfo->prP2PInfo;
370 /* Get station information. */
371 /* 1. Inactive time? */
372 p2pFuncGetStationInfo(prGlueInfo->prAdapter,
377 sinfo->filled |= STATION_INFO_INACTIVE_TIME;
378 sinfo->inactive_time = rP2pStaInfo.u4InactiveTime;
379 sinfo->generation = prP2pGlueInfo->i4Generation;
388 mtk_p2p_cfg80211_scan (
390 struct net_device *ndev,
391 struct cfg80211_scan_request *request
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;
404 /* [---------Channel---------] [---------SSID---------][---------IE---------] */
408 if ((wiphy == NULL) || (request == NULL)) {
412 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
414 prP2pGlueInfo = prGlueInfo->prP2PInfo;
416 if (prP2pGlueInfo == NULL) {
421 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_scan.\n"));
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"));
430 prP2pGlueInfo->prScanRequest = request;
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"));
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)) +
443 prMsgScanRequest = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, u4MsgSize);
445 if (prMsgScanRequest == NULL) {
451 DBGLOG(P2P, TRACE, ("Generating scan request message.\n"));
453 prMsgScanRequest->rMsgHdr.eMsgId = MID_MNY_P2P_DEVICE_DISCOVERY;
457 DBGLOG(P2P, TRACE, ("Requesting channel number:%d.\n", request->n_channels));
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];
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;
472 case IEEE80211_BAND_5GHZ:
473 prRfChannelInfo->eBand = BAND_5G;
476 DBGLOG(P2P, TRACE, ("UNKNOWN Band info from supplicant\n"));
477 prRfChannelInfo->eBand = BAND_NULL;
484 prMsgScanRequest->u4NumChannel = request->n_channels;
486 DBGLOG(P2P, TRACE, ("Finish channel list.\n"));
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;
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);
506 prMsgScanRequest->i4SsidNum = request->n_ssids;
508 DBGLOG(P2P, TRACE, ("Finish SSID list:%d.\n", request->n_ssids));
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;
517 DBGLOG(P2P, TRACE, ("Finish IE Buffer.\n"));
520 mboxSendMsg(prGlueInfo->prAdapter,
522 (P_MSG_HDR_T)prMsgScanRequest,
523 MSG_SEND_METHOD_BUF);
529 } /* mtk_p2p_cfg80211_scan */
531 int mtk_p2p_cfg80211_set_wiphy_params(
536 INT_32 i4Rslt = -EINVAL;
537 P_GLUE_INFO_T prGlueInfo = NULL;
545 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_wiphy_params\n"));
546 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
548 if (changed & WIPHY_PARAM_RETRY_SHORT) {
550 DBGLOG(P2P, TRACE, ("The RETRY short param is changed.\n"));
553 if (changed & WIPHY_PARAM_RETRY_LONG) {
555 DBGLOG(P2P, TRACE, ("The RETRY long param is changed.\n"));
559 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
561 DBGLOG(P2P, TRACE, ("The RETRY fragmentation threshold is changed.\n"));
564 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
566 DBGLOG(P2P, TRACE, ("The RETRY RTS threshold is changed.\n"));
569 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
571 DBGLOG(P2P, TRACE, ("The coverage class is changed???\n"));
581 } /* mtk_p2p_cfg80211_set_wiphy_params */
586 mtk_p2p_cfg80211_join_ibss(
588 struct net_device *dev,
589 struct cfg80211_ibss_params *params
592 P_GLUE_INFO_T prGlueInfo = NULL;
596 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
598 // not implemented yet
604 mtk_p2p_cfg80211_leave_ibss(
606 struct net_device *dev
609 P_GLUE_INFO_T prGlueInfo = NULL;
613 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
615 // not implemented yet
621 mtk_p2p_cfg80211_set_txpower(
623 enum nl80211_tx_power_setting type,
627 P_GLUE_INFO_T prGlueInfo = NULL;
631 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
633 // not implemented yet
639 mtk_p2p_cfg80211_get_txpower(
644 P_GLUE_INFO_T prGlueInfo = NULL;
648 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
650 // not implemented yet
656 mtk_p2p_cfg80211_set_power_mgmt(
658 struct net_device *dev,
663 P_GLUE_INFO_T prGlueInfo = NULL;
667 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
669 // not implemented yet
675 //&&&&&&&&&&&&&&&&&&&&&&&&&& Add for ICS Wi-Fi Direct Support. &&&&&&&&&&&&&&&&&&&&&&&
676 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
678 mtk_p2p_cfg80211_start_ap (
680 struct net_device *dev,
681 struct cfg80211_ap_settings *settings
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;
692 if ((wiphy == NULL) || (settings == NULL)) {
696 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_start_ap.\n"));
697 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
699 prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
700 prGlueInfo->prAdapter,
702 (sizeof(MSG_P2P_BEACON_UPDATE_T) + settings->beacon.head_len + settings->beacon.tail_len));
704 if (prP2pBcnUpdateMsg == NULL) {
711 prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
712 pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
714 if (settings->beacon.head_len != 0) {
715 kalMemCopy(pucBuffer, settings->beacon.head, settings->beacon.head_len);
717 prP2pBcnUpdateMsg->u4BcnHdrLen = settings->beacon.head_len;
719 prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
721 pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)settings->beacon.head_len);
724 prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
726 prP2pBcnUpdateMsg->pucBcnHdr = NULL;
729 if (settings->beacon.tail_len != 0) {
730 UINT_8 ucLen = settings->beacon.tail_len;
732 prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
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);
744 kalMemCopy(pucBuffer, settings->beacon.tail, settings->beacon.tail_len);
746 prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
749 prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
751 prP2pBcnUpdateMsg->pucBcnBody = NULL;
755 mboxSendMsg(prGlueInfo->prAdapter,
757 (P_MSG_HDR_T)prP2pBcnUpdateMsg,
758 MSG_SEND_METHOD_BUF);
761 prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
762 prGlueInfo->prAdapter,
764 sizeof(MSG_P2P_START_AP_T));
766 if (prP2pStartAPMsg == NULL) {
772 prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
774 prP2pStartAPMsg->fgIsPrivacy = settings->privacy;
776 prP2pStartAPMsg->u4BcnInterval = settings->beacon_interval;
778 prP2pStartAPMsg->u4DtimPeriod = settings->dtim_period;
781 prP2pStartAPMsg->ucHiddenSsidType = settings->hidden_ssid;
783 COPY_SSID(prP2pStartAPMsg->aucSsid,
784 prP2pStartAPMsg->u2SsidLen,
788 mboxSendMsg(prGlueInfo->prAdapter,
790 (P_MSG_HDR_T)prP2pStartAPMsg,
791 MSG_SEND_METHOD_BUF);
800 /////////////////////////
802 * struct cfg80211_ap_settings - AP configuration
804 * Used to configure an AP interface.
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
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.
818 // struct cfg80211_ap_settings {
819 // struct cfg80211_beacon_data beacon;
821 // int beacon_interval, dtim_period;
824 // enum nl80211_hidden_ssid hidden_ssid;
825 // struct cfg80211_crypto_settings crypto;
827 // enum nl80211_auth_type auth_type;
828 // int inactivity_timeout;
833 } /* mtk_p2p_cfg80211_start_ap */
837 mtk_p2p_cfg80211_change_beacon (
839 struct net_device *dev,
840 struct cfg80211_beacon_data *info
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;
849 if ((wiphy == NULL) || (info == NULL)) {
853 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_beacon.\n"));
854 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
856 prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
857 prGlueInfo->prAdapter,
859 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
862 if (prP2pBcnUpdateMsg == NULL) {
868 prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
869 pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
871 if (info->head_len != 0) {
872 kalMemCopy(pucBuffer, info->head, info->head_len);
874 prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
876 prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
878 pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
881 prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
883 prP2pBcnUpdateMsg->pucBcnHdr = NULL;
886 if (info->tail_len != 0) {
887 UINT_8 ucLen = info->tail_len;
889 prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
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);
901 kalMemCopy(pucBuffer, info->tail, info->tail_len);
903 prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
906 prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
908 prP2pBcnUpdateMsg->pucBcnBody = NULL;
912 mboxSendMsg(prGlueInfo->prAdapter,
914 (P_MSG_HDR_T)prP2pBcnUpdateMsg,
915 MSG_SEND_METHOD_BUF);
917 ////////////////////////////
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
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)
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;
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;
951 ////////////////////////////
956 } /* mtk_p2p_cfg80211_change_beacon */
960 mtk_p2p_cfg80211_add_set_beacon (
962 struct net_device *dev,
963 struct beacon_parameters *info
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;
974 if ((wiphy == NULL) || (info == NULL)) {
978 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_add_set_beacon.\n"));
979 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
981 prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T)cnmMemAlloc(
982 prGlueInfo->prAdapter,
984 (sizeof(MSG_P2P_BEACON_UPDATE_T) + info->head_len + info->tail_len));
986 if (prP2pBcnUpdateMsg == NULL) {
993 prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
994 pucBuffer = prP2pBcnUpdateMsg->aucBuffer;
996 if (info->head_len != 0) {
997 kalMemCopy(pucBuffer, info->head, info->head_len);
999 prP2pBcnUpdateMsg->u4BcnHdrLen = info->head_len;
1001 prP2pBcnUpdateMsg->pucBcnHdr = pucBuffer;
1003 pucBuffer = (PUINT_8)((UINT_32)pucBuffer + (UINT_32)info->head_len);
1006 prP2pBcnUpdateMsg->u4BcnHdrLen = 0;
1008 prP2pBcnUpdateMsg->pucBcnHdr = NULL;
1011 if (info->tail_len != 0) {
1012 UINT_8 ucLen = info->tail_len;
1014 prP2pBcnUpdateMsg->pucBcnBody = pucBuffer;
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);
1026 kalMemCopy(pucBuffer, info->tail, info->tail_len);
1028 prP2pBcnUpdateMsg->u4BcnBodyLen = ucLen;
1031 prP2pBcnUpdateMsg->u4BcnBodyLen = 0;
1033 prP2pBcnUpdateMsg->pucBcnBody = NULL;
1037 mboxSendMsg(prGlueInfo->prAdapter,
1039 (P_MSG_HDR_T)prP2pBcnUpdateMsg,
1040 MSG_SEND_METHOD_BUF);
1043 prP2pStartAPMsg = (P_MSG_P2P_START_AP_T)cnmMemAlloc(
1044 prGlueInfo->prAdapter,
1046 sizeof(MSG_P2P_START_AP_T));
1048 if (prP2pStartAPMsg == NULL) {
1054 prP2pStartAPMsg->rMsgHdr.eMsgId = MID_MNY_P2P_START_AP;
1056 prP2pStartAPMsg->fgIsPrivacy = FALSE;
1058 prP2pStartAPMsg->u4BcnInterval = info->interval;
1060 prP2pStartAPMsg->u4DtimPeriod = info->dtim_period;
1063 prP2pStartAPMsg->ucHiddenSsidType = ENUM_HIDDEN_SSID_NONE;
1066 if (info->head_len > OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem)) {
1067 P_WLAN_BEACON_FRAME_T prWlanBcnFrame = info->head;
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)),
1075 kalMemCopy(prP2pStartAPMsg->aucSsid, SSID_IE(prSsidIE)->aucSSID, IE_LEN(prSsidIE));
1080 mboxSendMsg(prGlueInfo->prAdapter,
1082 (P_MSG_HDR_T)prP2pStartAPMsg,
1083 MSG_SEND_METHOD_BUF);
1091 /* mtk_p2p_cfg80211_add_set_beacon */
1095 mtk_p2p_cfg80211_stop_ap (
1096 struct wiphy *wiphy,
1097 struct net_device *dev
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;
1105 if (wiphy == NULL) {
1110 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_stop_ap.\n"));
1111 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1114 prP2pSwitchMode = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
1116 if (prP2pSwitchMode == NULL) {
1122 prP2pSwitchMode->rMsgHdr.eMsgId = MID_MNY_P2P_STOP_AP;
1124 mboxSendMsg(prGlueInfo->prAdapter,
1126 (P_MSG_HDR_T)prP2pSwitchMode,
1127 MSG_SEND_METHOD_BUF);
1134 } /* mtk_p2p_cfg80211_stop_ap */
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)
1147 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1151 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1153 // not implemented yet
1154 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_deauth.\n"));
1157 } /* mtk_p2p_cfg80211_deauth */
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)
1171 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1175 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1177 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disassoc.\n"));
1179 // not implemented yet
1182 } /* mtk_p2p_cfg80211_disassoc */
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,
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;
1202 if ((wiphy == NULL) ||
1209 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1210 prGlueP2pInfo = prGlueInfo->prP2PInfo;
1212 *cookie = prGlueP2pInfo->u8Cookie++;
1214 prMsgChnlReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_REQUEST_T));
1216 if (prMsgChnlReq == NULL) {
1222 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_remain_on_channel\n"));
1224 prMsgChnlReq->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_REQ;
1225 prMsgChnlReq->u8Cookie = *cookie;
1226 prMsgChnlReq->u4Duration = duration;
1229 mtk_p2p_cfg80211func_channel_format_switch(chan,
1231 &prMsgChnlReq->rChannelInfo,
1232 &prMsgChnlReq->eChnlSco);
1234 mboxSendMsg(prGlueInfo->prAdapter,
1236 (P_MSG_HDR_T)prMsgChnlReq,
1237 MSG_SEND_METHOD_BUF);
1247 /* mtk_p2p_cfg80211_remain_on_channel */
1251 mtk_p2p_cfg80211_cancel_remain_on_channel (
1252 struct wiphy *wiphy,
1253 struct net_device *dev,
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;
1262 if ((wiphy == NULL) || (dev == NULL)) {
1267 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1269 prMsgChnlAbort = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CHNL_ABORT_T));
1271 if (prMsgChnlAbort == NULL) {
1277 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_cancel_remain_on_channel\n"));
1279 prMsgChnlAbort->rMsgHdr.eMsgId = MID_MNY_P2P_CHNL_ABORT;
1280 prMsgChnlAbort->u8Cookie = cookie;
1283 mboxSendMsg(prGlueInfo->prAdapter,
1285 (P_MSG_HDR_T)prMsgChnlAbort,
1286 MSG_SEND_METHOD_BUF);
1292 } /* mtk_p2p_cfg80211_cancel_remain_on_channel */
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,
1302 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
1304 bool dont_wait_for_ack,
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;
1317 if ((wiphy == NULL) ||
1325 //DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_mgmt_tx\n"));
1327 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1328 prGlueP2pInfo = prGlueInfo->prP2PInfo;
1330 *cookie = prGlueP2pInfo->u8Cookie++;
1332 /* Channel & Channel Type & Wait time are ignored. */
1333 prMsgTxReq = cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_MGMT_TX_REQUEST_T));
1335 if (prMsgTxReq == NULL) {
1341 prMsgTxReq->fgNoneCckRate = FALSE;
1342 prMsgTxReq->fgIsWaitRsp = TRUE;
1344 prMgmtFrame = cnmMgtPktAlloc(prGlueInfo->prAdapter, (UINT_32)(len + MAC_TX_RESERVED_FIELD));
1346 if ((prMsgTxReq->prMgmtMsduInfo = prMgmtFrame) == NULL) {
1352 prMsgTxReq->u8Cookie = *cookie;
1353 prMsgTxReq->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_TX;
1355 pucFrameBuf = (PUINT_8)((UINT_32)prMgmtFrame->prPacket + MAC_TX_RESERVED_FIELD);
1357 kalMemCopy(pucFrameBuf, buf, len);
1359 prMgmtFrame->u2FrameLength = len;
1361 mboxSendMsg(prGlueInfo->prAdapter,
1363 (P_MSG_HDR_T)prMsgTxReq,
1364 MSG_SEND_METHOD_BUF);
1369 if ((i4Rslt != 0) && (prMsgTxReq != NULL)) {
1370 if (prMsgTxReq->prMgmtMsduInfo != NULL) {
1371 cnmMgtPktFree(prGlueInfo->prAdapter, prMsgTxReq->prMgmtMsduInfo);
1374 cnmMemFree(prGlueInfo->prAdapter, prMsgTxReq);
1378 } /* mtk_p2p_cfg80211_mgmt_tx */
1383 mtk_p2p_cfg80211_change_bss (
1384 struct wiphy *wiphy,
1385 struct net_device *dev,
1386 struct bss_parameters *params
1389 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1390 INT_32 i4Rslt = -EINVAL;
1394 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1397 switch (params->use_cts_prot) {
1399 DBGLOG(P2P, TRACE, ("CTS protection no change\n"));
1402 DBGLOG(P2P, TRACE, ("CTS protection disable.\n"));
1405 DBGLOG(P2P, TRACE, ("CTS protection enable\n"));
1408 DBGLOG(P2P, TRACE, ("CTS protection unknown\n"));
1414 switch (params->use_short_preamble) {
1416 DBGLOG(P2P, TRACE, ("Short prreamble no change\n"));
1419 DBGLOG(P2P, TRACE, ("Short prreamble disable.\n"));
1422 DBGLOG(P2P, TRACE, ("Short prreamble enable\n"));
1425 DBGLOG(P2P, TRACE, ("Short prreamble unknown\n"));
1432 // not implemented yet
1433 p2pFuncChangeBssParam(prGlueInfo->prAdapter,
1434 prBssInfo->fgIsProtection,
1435 prBssInfo->fgIsShortPreambleAllowed,
1436 prBssInfo->fgUseShortSlotTime,
1447 } /* mtk_p2p_cfg80211_change_bss */
1452 mtk_p2p_cfg80211_del_station (
1453 struct wiphy *wiphy,
1454 struct net_device *dev,
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;
1465 if ((wiphy == NULL) ||
1474 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_del_station.\n"));
1476 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
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));
1481 if (prDisconnectMsg == NULL) {
1487 prDisconnectMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
1488 COPY_MAC_ADDR(prDisconnectMsg->aucTargetID, mac);
1489 prDisconnectMsg->u2ReasonCode = REASON_CODE_UNSPECIFIED;
1491 mboxSendMsg(prGlueInfo->prAdapter,
1493 (P_MSG_HDR_T)prDisconnectMsg,
1494 MSG_SEND_METHOD_BUF);
1501 } /* mtk_p2p_cfg80211_del_station */
1505 mtk_p2p_cfg80211_connect (
1506 struct wiphy *wiphy,
1507 struct net_device *dev,
1508 struct cfg80211_connect_params *sme
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;
1517 if ((wiphy == NULL) ||
1523 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_connect.\n"));
1525 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1527 prConnReqMsg = (P_MSG_P2P_CONNECTION_REQUEST_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, (sizeof(MSG_P2P_CONNECTION_REQUEST_T) + sme->ie_len));
1529 if (prConnReqMsg == NULL) {
1535 prConnReqMsg->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
1537 COPY_SSID(prConnReqMsg->rSsid.aucSsid,
1538 prConnReqMsg->rSsid.ucSsidLen,
1542 COPY_MAC_ADDR(prConnReqMsg->aucBssid, sme->bssid);
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;
1548 mtk_p2p_cfg80211func_channel_format_switch(sme->channel,
1550 &prConnReqMsg->rChannelInfo,
1551 &prConnReqMsg->eChnlSco);
1553 mboxSendMsg(prGlueInfo->prAdapter,
1555 (P_MSG_HDR_T)prConnReqMsg,
1556 MSG_SEND_METHOD_BUF);
1563 } /* mtk_p2p_cfg80211_connect */
1566 mtk_p2p_cfg80211_disconnect (
1567 struct wiphy *wiphy,
1568 struct net_device *dev,
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;
1578 if ((wiphy == NULL) ||
1583 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_disconnect.\n"));
1585 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
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));
1590 if (prDisconnMsg == NULL) {
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);
1601 mboxSendMsg(prGlueInfo->prAdapter,
1603 (P_MSG_HDR_T)prDisconnMsg,
1604 MSG_SEND_METHOD_UNBUF);
1610 } /* mtk_p2p_cfg80211_disconnect */
1614 mtk_p2p_cfg80211_change_iface (
1615 IN struct wiphy *wiphy,
1616 IN struct net_device *ndev,
1617 IN enum nl80211_iftype type,
1619 IN struct vif_params *params
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;
1627 if ((wiphy == NULL) ||
1632 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_change_iface.\n"));
1634 if (ndev->ieee80211_ptr) {
1635 ndev->ieee80211_ptr->iftype = type;
1638 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1642 prSwitchModeMsg = (P_MSG_P2P_SWITCH_OP_MODE_T)cnmMemAlloc(prGlueInfo->prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_SWITCH_OP_MODE_T));
1644 if (prSwitchModeMsg == NULL) {
1650 prSwitchModeMsg->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
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"));
1659 prSwitchModeMsg->eOpMode = OP_MODE_INFRASTRUCTURE;
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"));
1667 prSwitchModeMsg->eOpMode = OP_MODE_ACCESS_POINT;
1670 DBGLOG(P2P, TRACE, ("Other type :%d .\n", type));
1671 prSwitchModeMsg->eOpMode = OP_MODE_P2P_DEVICE;
1676 mboxSendMsg(prGlueInfo->prAdapter,
1678 (P_MSG_HDR_T)prSwitchModeMsg,
1679 MSG_SEND_METHOD_BUF);
1687 } /* mtk_p2p_cfg80211_change_iface */
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)
1697 INT_32 i4Rslt = -EINVAL;
1698 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1699 RF_CHANNEL_INFO_T rRfChnlInfo;
1702 if ((wiphy == NULL) ||
1708 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_channel.\n"));
1710 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1712 mtk_p2p_cfg80211func_channel_format_switch(chan,
1717 p2pFuncSetChannel(prGlueInfo->prAdapter, &rRfChnlInfo);
1726 /* mtk_p2p_cfg80211_set_channel */
1729 mtk_p2p_cfg80211_set_bitrate_mask (
1730 IN struct wiphy *wiphy,
1731 IN struct net_device *dev,
1733 IN const struct cfg80211_bitrate_mask *mask
1736 INT_32 i4Rslt = -EINVAL;
1737 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1740 if ((wiphy == NULL) ||
1746 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_set_bitrate_mask\n"));
1748 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1750 // TODO: Set bitrate mask of the peer?
1757 } /* mtk_p2p_cfg80211_set_bitrate_mask */
1761 mtk_p2p_cfg80211_mgmt_frame_register (
1762 IN struct wiphy *wiphy,
1763 IN struct net_device *dev,
1769 P_MSG_P2P_MGMT_FRAME_REGISTER_T prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)NULL;
1771 P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T)NULL;
1774 if ((wiphy == NULL) ||
1779 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_mgmt_frame_register\n"));
1781 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1784 switch (frame_type) {
1785 case MAC_FRAME_PROBE_REQ:
1787 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_PROBE_REQ;
1788 DBGLOG(P2P, TRACE, ("Open packet filer probe request\n"));
1791 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_PROBE_REQ;
1792 DBGLOG(P2P, TRACE, ("Close packet filer probe request\n"));
1795 case MAC_FRAME_ACTION:
1797 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter |= PARAM_PACKET_FILTER_ACTION_FRAME;
1798 DBGLOG(P2P, TRACE, ("Open packet filer action frame.\n"));
1801 prGlueInfo->prP2PInfo->u4OsMgmtFrameFilter &= ~PARAM_PACKET_FILTER_ACTION_FRAME;
1802 DBGLOG(P2P, TRACE, ("Close packet filer action frame.\n"));
1806 DBGLOG(P2P, ERROR, ("Ask frog to add code for mgmt:%x\n", frame_type));
1812 prGlueInfo->u4Flag |= GLUE_FLAG_FRAME_FILTER;
1814 /* wake up main thread */
1815 wake_up_interruptible(&prGlueInfo->waitq);
1817 if (in_interrupt()) {
1818 DBGLOG(P2P, TRACE, ("It is in interrupt level\n"));
1826 prMgmtFrameRegister = (P_MSG_P2P_MGMT_FRAME_REGISTER_T)cnmMemAlloc(prGlueInfo->prAdapter,
1828 sizeof(MSG_P2P_MGMT_FRAME_REGISTER_T));
1830 if (prMgmtFrameRegister == NULL) {
1835 prMgmtFrameRegister->rMsgHdr.eMsgId = MID_MNY_P2P_MGMT_FRAME_REGISTER;
1837 prMgmtFrameRegister->u2FrameType = frame_type;
1838 prMgmtFrameRegister->fgIsRegister = reg;
1840 mboxSendMsg(prGlueInfo->prAdapter,
1842 (P_MSG_HDR_T)prMgmtFrameRegister,
1843 MSG_SEND_METHOD_BUF);
1851 } /* mtk_p2p_cfg80211_mgmt_frame_register */
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
1862 BOOLEAN fgIsValid = FALSE;
1865 if (channel == NULL) {
1870 prRfChnlInfo->ucChannelNum = nicFreq2ChannelNum(channel->center_freq * 1000);
1872 switch (channel->band) {
1873 case IEEE80211_BAND_2GHZ:
1874 prRfChnlInfo->eBand = BAND_2G4;
1876 case IEEE80211_BAND_5GHZ:
1877 prRfChnlInfo->eBand = BAND_5G;
1880 prRfChnlInfo->eBand = BAND_2G4;
1889 switch (channel_type) {
1890 case NL80211_CHAN_NO_HT:
1891 *prChnlSco = CHNL_EXT_SCN;
1893 case NL80211_CHAN_HT20:
1894 *prChnlSco = CHNL_EXT_SCN;
1896 case NL80211_CHAN_HT40MINUS:
1897 *prChnlSco = CHNL_EXT_SCA;
1899 case NL80211_CHAN_HT40PLUS:
1900 *prChnlSco = CHNL_EXT_SCB;
1904 *prChnlSco = CHNL_EXT_SCN;
1915 /* mtk_p2p_cfg80211func_channel_format_switch */
1918 #if CONFIG_NL80211_TESTMODE
1919 int mtk_p2p_cfg80211_testmode_cmd(
1920 IN struct wiphy *wiphy,
1925 P_GLUE_INFO_T prGlueInfo = NULL;
1926 P_NL80211_DRIVER_TEST_PARAMS prParams = (P_NL80211_DRIVER_TEST_PARAMS)NULL;
1927 BOOLEAN fgIsValid = FALSE;
1931 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1933 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_cmd\n"));
1936 prParams = (P_NL80211_DRIVER_TEST_PARAMS)data;
1938 if(prParams->index >> 24 == 0x01) {
1940 prParams->index = prParams->index & ~ BITS(24,31);
1944 mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(wiphy, data, len);
1947 /* Clear the version byte */
1948 prParams->index = prParams->index & ~ BITS(24,31);
1951 switch(prParams->index){
1952 case 1: /* P2P Simga */
1953 if(mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(wiphy, data, len))
1958 case 3: /* Hotspot Client Management */
1959 if(mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(wiphy, data, len))
1973 int mtk_p2p_cfg80211_testmode_p2p_sigma_pre_cmd(
1974 IN struct wiphy *wiphy,
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;
1991 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
1993 kalMemZero(&rParams, sizeof(NL80211_DRIVER_TEST_PRE_PARAMS));
1995 prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
1996 prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
1998 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_cmd\n"));
2001 memcpy(&rParams, data, len);
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));
2006 index_mode = rParams.idx_mode;
2007 index = rParams.idx;
2008 value = rParams.value;
2011 case 0: /* Listen CH */
2013 case 1: /* P2p mode */
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);
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);
2025 case 6: /* Noa count */
2026 prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2027 //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2029 case 100: /* Oper CH */
2030 // 20110920 - frog: User configurations are placed in ConnSettings.
2031 // prP2pConnSettings->ucOperatingChnl = value;
2033 case 101: /* Local config Method, for P2P SDK */
2034 prP2pConnSettings->u2LocalConfigMethod = value;
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);
2042 case 103: /* WPS MODE */
2043 kalP2PSetWscMode(prGlueInfo, value);
2045 case 104: /* P2p send persence, duration */
2047 case 105: /* P2p send persence, interval */
2049 case 106: /* P2P set sleep */
2051 kalIoctl(prGlueInfo,
2052 wlanoidSetP2pPowerSaveProfile,
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);
2065 case 108: /* p2p_set_power_save */
2066 kalIoctl(prGlueInfo,
2067 wlanoidSetP2pPowerSaveProfile,
2087 mtk_p2p_cfg80211_testmode_p2p_sigma_cmd(
2088 IN struct wiphy *wiphy,
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;
2103 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2105 prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
2106 prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
2108 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_p2p_sigma_cmd\n"));
2111 prParams = (P_NL80211_DRIVER_P2P_SIGMA_PARAMS)data;
2113 index = (INT_32)prParams->idx;
2114 value = (INT_32)prParams->value;
2116 DBGLOG(P2P, TRACE, ("NL80211_ATTR_TESTDATA, idx=%lu value=%lu\n",
2117 (INT_32)prParams->idx, (INT_32)prParams->value));
2120 case 0: /* Listen CH */
2122 case 1: /* P2p mode */
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);
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);
2134 case 6: /* Noa count */
2135 prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
2136 //status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
2138 case 100: /* Oper CH */
2139 // 20110920 - frog: User configurations are placed in ConnSettings.
2140 // prP2pConnSettings->ucOperatingChnl = value;
2142 case 101: /* Local config Method, for P2P SDK */
2143 prP2pConnSettings->u2LocalConfigMethod = value;
2145 case 102: /* Sigma P2p reset */
2146 //kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
2147 //prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO;
2149 case 103: /* WPS MODE */
2150 kalP2PSetWscMode(prGlueInfo, value);
2152 case 104: /* P2p send persence, duration */
2154 case 105: /* P2p send persence, interval */
2156 case 106: /* P2P set sleep */
2158 kalIoctl(prGlueInfo,
2159 wlanoidSetP2pPowerSaveProfile,
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);
2172 case 108: /* p2p_set_power_save */
2173 kalIoctl(prGlueInfo,
2174 wlanoidSetP2pPowerSaveProfile,
2184 case 109: /* Max Clients*/
2185 kalP2PSetMaxClients(prGlueInfo, value);
2197 mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd(
2198 IN struct wiphy *wiphy,
2202 P_GLUE_INFO_T prGlueInfo = NULL;
2203 P_NL80211_DRIVER_hotspot_block_PARAMS prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)NULL;
2208 prGlueInfo = *((P_GLUE_INFO_T *) wiphy_priv(wiphy));
2211 prParams = (P_NL80211_DRIVER_hotspot_block_PARAMS)data;
2213 DBGLOG(P2P, TRACE, ("mtk_p2p_cfg80211_testmode_hotspot_block_list_cmd\n"));
2215 fgIsValid = kalP2PSetBlackList(prGlueInfo, prParams->aucBssid, prParams->ucblocked);
2224 #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
2226 #endif // CFG_ENABLE_WIFI_DIRECT && CFG_ENABLE_WIFI_DIRECT_CFG_80211