2 ** $Id: @(#) gl_cfg80211.c@@
5 /*! \file gl_cfg80211.c
6 \brief Main routines for supporintg MT6620 cfg80211 control interface
8 This file contains the support routines of Linux driver for MediaTek Inc. 802.11
15 ** $Log: gl_cfg80211.c $
17 ** 09 12 2012 wcpadmin
18 ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
21 ** 11 23 2012 yuche.tsai
22 ** [ALPS00398671] [Acer-Tablet] Remove Wi-Fi Direct completely
23 ** Fix bug of WiFi may reboot under user load, when WiFi Direct is removed..
25 ** 08 29 2012 chinglan.wang
26 ** [ALPS00349655] [Need Patch] [Volunteer Patch] [ALPS.JB] Daily build warning on [mt6575_phone_mhl-eng]
32 /*******************************************************************************
33 * C O M P I L E R F L A G S
34 ********************************************************************************
37 /*******************************************************************************
38 * E X T E R N A L R E F E R E N C E S
39 ********************************************************************************
47 /*******************************************************************************
49 ********************************************************************************
52 /*******************************************************************************
54 ********************************************************************************
57 /*******************************************************************************
59 ********************************************************************************
63 extern UINT_8 keyStructBuf[1024]; /* add/remove key shared buffer */
65 extern UINT_8 keyStructBuf[100]; /* add/remove key shared buffer */
68 /*******************************************************************************
69 * P R I V A T E D A T A
70 ********************************************************************************
73 /*******************************************************************************
75 ********************************************************************************
78 /*******************************************************************************
79 * F U N C T I O N D E C L A R A T I O N S
80 ********************************************************************************
83 /*******************************************************************************
85 ********************************************************************************
88 /*----------------------------------------------------------------------------*/
90 * @brief This routine is responsible for change STA type between
91 * 1. Infrastructure Client (Non-AP STA)
96 * @retval 0: successful
99 /*----------------------------------------------------------------------------*/
101 mtk_cfg80211_change_iface (
103 struct net_device *ndev,
104 enum nl80211_iftype type,
106 struct vif_params *params
109 P_GLUE_INFO_T prGlueInfo = NULL;
110 WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
111 ENUM_PARAM_OP_MODE_T eOpMode;
114 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
117 if(type == NL80211_IFTYPE_STATION) {
118 eOpMode = NET_TYPE_INFRA;
120 else if(type == NL80211_IFTYPE_ADHOC) {
121 eOpMode = NET_TYPE_IBSS;
127 rStatus = kalIoctl(prGlueInfo,
128 wlanoidSetInfrastructureMode,
137 if (rStatus != WLAN_STATUS_SUCCESS) {
138 DBGLOG(REQ, WARN, ("set infrastructure mode error:%lx\n", rStatus));
142 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
143 prGlueInfo->rWpaInfo.u4KeyMgmt = 0;
144 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_NONE;
145 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_NONE;
146 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
147 #if CFG_SUPPORT_802_11W
148 prGlueInfo->rWpaInfo.u4Mfp = IW_AUTH_MFP_DISABLED;
155 /*----------------------------------------------------------------------------*/
157 * @brief This routine is responsible for adding key
161 * @retval 0: successful
164 /*----------------------------------------------------------------------------*/
166 mtk_cfg80211_add_key (
168 struct net_device *ndev,
172 struct key_params *params
176 P_GLUE_INFO_T prGlueInfo = NULL;
177 WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
178 INT_32 i4Rslt = -EINVAL;
179 UINT_32 u4BufLen = 0;
183 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
186 kalMemZero(&rKey, sizeof(PARAM_KEY_T));
188 rKey.u4KeyIndex = key_index;
191 COPY_MAC_ADDR(rKey.arBSSID, mac_addr);
192 if ((rKey.arBSSID[0] == 0x00) && (rKey.arBSSID[1] == 0x00) && (rKey.arBSSID[2] == 0x00) &&
193 (rKey.arBSSID[3] == 0x00) && (rKey.arBSSID[4] == 0x00) && (rKey.arBSSID[5] == 0x00)) {
194 rKey.arBSSID[0] = 0xff;
195 rKey.arBSSID[1] = 0xff;
196 rKey.arBSSID[2] = 0xff;
197 rKey.arBSSID[3] = 0xff;
198 rKey.arBSSID[4] = 0xff;
199 rKey.arBSSID[5] = 0xff;
201 if (rKey.arBSSID[0] != 0xFF) {
202 rKey.u4KeyIndex |= BIT(31);
203 if ((rKey.arBSSID[0] != 0x00) || (rKey.arBSSID[1] != 0x00) || (rKey.arBSSID[2] != 0x00) ||
204 (rKey.arBSSID[3] != 0x00) || (rKey.arBSSID[4] != 0x00) || (rKey.arBSSID[5] != 0x00))
205 rKey.u4KeyIndex |= BIT(30);
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 //rKey.u4KeyIndex |= BIT(31); //Enable BIT 31 will make tx use bc key id, should use pairwise key id 0
219 //rKey.aucKeyMaterial[0] = kalMemAlloc(params->key_len, VIR_MEM_TYPE);
220 kalMemCopy(rKey.aucKeyMaterial, params->key, params->key_len);
221 if (params->key_len == 32) {
222 kalMemCopy(tmp1, ¶ms->key[16], 8);
223 kalMemCopy(tmp2, ¶ms->key[24], 8);
224 kalMemCopy(&rKey.aucKeyMaterial[16], tmp2, 8);
225 kalMemCopy(&rKey.aucKeyMaterial[24], tmp1, 8);
229 rKey.u4KeyLength = params->key_len;
230 rKey.u4Length = ((UINT_32)&(((P_P2P_PARAM_KEY_T)0)->aucKeyMaterial)) + rKey.u4KeyLength;
232 rStatus = kalIoctl(prGlueInfo,
242 if (rStatus == WLAN_STATUS_SUCCESS)
249 /*----------------------------------------------------------------------------*/
251 * @brief This routine is responsible for getting key for specified STA
255 * @retval 0: successful
258 /*----------------------------------------------------------------------------*/
260 mtk_cfg80211_get_key (
262 struct net_device *ndev,
267 void (*callback)(void *cookie, struct key_params*)
270 P_GLUE_INFO_T prGlueInfo = NULL;
272 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
276 /* not implemented */
282 /*----------------------------------------------------------------------------*/
284 * @brief This routine is responsible for removing key for specified STA
288 * @retval 0: successful
291 /*----------------------------------------------------------------------------*/
293 mtk_cfg80211_del_key (
295 struct net_device *ndev,
301 P_GLUE_INFO_T prGlueInfo = NULL;
302 WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
303 PARAM_REMOVE_KEY_T rRemoveKey;
304 UINT_32 u4BufLen = 0;
305 INT_32 i4Rslt = -EINVAL;
307 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
310 kalMemZero(&rRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
312 COPY_MAC_ADDR(rRemoveKey.arBSSID, mac_addr);
313 rRemoveKey.u4KeyIndex = key_index;
314 rRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
317 rStatus = kalIoctl(prGlueInfo,
327 if (rStatus != WLAN_STATUS_SUCCESS) {
328 DBGLOG(REQ, WARN, ("remove key error:%lx\n", rStatus));
338 /*----------------------------------------------------------------------------*/
340 * @brief This routine is responsible for setting default key on an interface
344 * @retval 0: successful
347 /*----------------------------------------------------------------------------*/
349 mtk_cfg80211_set_default_key (
351 struct net_device *ndev,
357 P_GLUE_INFO_T prGlueInfo = NULL;
359 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
364 /* for wpa_supplicant 2.0 need to set default key, return 0.
373 /*----------------------------------------------------------------------------*/
375 * @brief This routine is responsible for getting station information such as RSSI
379 * @retval 0: successful
382 /*----------------------------------------------------------------------------*/
385 mtk_cfg80211_get_station (
387 struct net_device *ndev,
389 struct station_info *sinfo
392 P_GLUE_INFO_T prGlueInfo = NULL;
394 PARAM_MAC_ADDRESS arBssid;
395 UINT_32 u4BufLen, u4Rate;
398 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
401 kalMemZero(arBssid, MAC_ADDR_LEN);
402 wlanQueryInformation(prGlueInfo->prAdapter,
409 if(UNEQUAL_MAC_ADDR(arBssid, mac)) {
410 /* wrong MAC address */
411 DBGLOG(REQ, WARN, ("incorrect BSSID: ["MACSTR"] currently connected BSSID["MACSTR"]\n",
412 MAC2STR(mac), MAC2STR(arBssid)));
416 /* 2. fill TX rate */
417 rStatus = kalIoctl(prGlueInfo,
418 wlanoidQueryLinkSpeed,
427 if (rStatus != WLAN_STATUS_SUCCESS) {
428 DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
431 sinfo->filled |= STATION_INFO_TX_BITRATE;
432 sinfo->txrate.legacy = u4Rate / 1000; /* convert from 100bps to 100kbps */
435 if(prGlueInfo->eParamMediaStateIndicated != PARAM_MEDIA_STATE_CONNECTED) {
437 DBGLOG(REQ, WARN, ("not yet connected\n"));
441 rStatus = kalIoctl(prGlueInfo,
451 if (rStatus != WLAN_STATUS_SUCCESS) {
452 DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
455 sinfo->filled |= STATION_INFO_SIGNAL;
456 //in the cfg80211 layer, the signal is a signed char variable.
458 sinfo->signal = -128;
460 sinfo->signal = i4Rssi; /* dBm */
464 sinfo->rx_packets = prGlueInfo->rNetDevStats.rx_packets;
465 sinfo->filled |= STATION_INFO_TX_PACKETS;
466 sinfo->tx_packets = prGlueInfo->rNetDevStats.tx_packets;
467 sinfo->filled |= STATION_INFO_TX_FAILED;
472 UINT_32 u4XmitError = 0;
473 // UINT_32 u4XmitOk = 0;
474 // UINT_32 u4RecvError = 0;
475 // UINT_32 u4RecvOk = 0;
478 /* @FIX ME: need a more clear way to do this */
481 rStatus = kalIoctl(prGlueInfo,
482 wlanoidQueryXmitError,
491 prGlueInfo->rNetDevStats.tx_errors = u4XmitError;
495 prGlueInfo->rNetDevStats.tx_errors = 0;
498 sinfo->tx_failed = prGlueInfo->rNetDevStats.tx_errors;
503 static PARAM_SCAN_REQUEST_EXT_T rScanRequest;
504 /*----------------------------------------------------------------------------*/
506 * @brief This routine is responsible for requesting to do a scan
510 * @retval 0: successful
513 /*----------------------------------------------------------------------------*/
517 struct net_device *ndev,
518 struct cfg80211_scan_request *request
521 P_GLUE_INFO_T prGlueInfo = NULL;
524 // PARAM_SCAN_REQUEST_EXT_T rScanRequest;
526 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
529 kalMemZero(&rScanRequest, sizeof(PARAM_SCAN_REQUEST_EXT_T));
531 /* check if there is any pending scan not yet finished */
532 if(prGlueInfo->prScanRequest != NULL) {
536 if(request->n_ssids == 0) {
537 rScanRequest.rSsid.u4SsidLen = 0;
539 else if(request->n_ssids == 1) {
540 COPY_SSID(rScanRequest.rSsid.aucSsid, rScanRequest.rSsid.u4SsidLen, request->ssids[0].ssid, request->ssids[0].ssid_len);
546 if(request->ie_len > 0) {
547 rScanRequest.u4IELength = request->ie_len;
548 rScanRequest.pucIE = (PUINT_8)(request->ie);
551 rScanRequest.u4IELength = 0;
554 rStatus = kalIoctl(prGlueInfo,
555 wlanoidSetBssidListScanExt,
557 sizeof(PARAM_SCAN_REQUEST_EXT_T),
564 if (rStatus != WLAN_STATUS_SUCCESS) {
565 DBGLOG(REQ, WARN, ("scan error:%lx\n", rStatus));
569 prGlueInfo->prScanRequest = request;
574 static UINT_8 wepBuf[48];
576 /*----------------------------------------------------------------------------*/
578 * @brief This routine is responsible for requesting to connect to
579 * the ESS with the specified parameters
583 * @retval 0: successful
586 /*----------------------------------------------------------------------------*/
588 mtk_cfg80211_connect (
590 struct net_device *ndev,
591 struct cfg80211_connect_params *sme
594 P_GLUE_INFO_T prGlueInfo = NULL;
597 ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
598 ENUM_PARAM_AUTH_MODE_T eAuthMode;
600 PARAM_SSID_T rNewSsid;
601 BOOLEAN fgCarryWPSIE = FALSE;
602 ENUM_PARAM_OP_MODE_T eOpMode;
604 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
607 if (prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode > NET_TYPE_AUTO_SWITCH)
608 eOpMode = NET_TYPE_AUTO_SWITCH;
610 eOpMode = prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode;
612 rStatus = kalIoctl(prGlueInfo,
613 wlanoidSetInfrastructureMode,
622 if (rStatus != WLAN_STATUS_SUCCESS) {
623 DBGLOG(INIT, INFO, ("wlanoidSetInfrastructureMode fail 0x%lx\n", rStatus));
627 /* after set operation mode, key table are cleared */
630 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
631 prGlueInfo->rWpaInfo.u4KeyMgmt = 0;
632 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_NONE;
633 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_NONE;
634 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
635 #if CFG_SUPPORT_802_11W
636 prGlueInfo->rWpaInfo.u4Mfp = IW_AUTH_MFP_DISABLED;
639 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
640 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_WPA;
641 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
642 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_WPA2;
644 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
646 switch (sme->auth_type) {
647 case NL80211_AUTHTYPE_OPEN_SYSTEM:
648 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
650 case NL80211_AUTHTYPE_SHARED_KEY:
651 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_SHARED_KEY;
654 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM | IW_AUTH_ALG_SHARED_KEY;
658 if (sme->crypto.n_ciphers_pairwise) {
659 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4PairwiseKeyCipherSuite[0] = sme->crypto.ciphers_pairwise[0];
660 switch (sme->crypto.ciphers_pairwise[0]) {
661 case WLAN_CIPHER_SUITE_WEP40:
662 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP40;
664 case WLAN_CIPHER_SUITE_WEP104:
665 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP104;
667 case WLAN_CIPHER_SUITE_TKIP:
668 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_TKIP;
670 case WLAN_CIPHER_SUITE_CCMP:
671 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
673 case WLAN_CIPHER_SUITE_AES_CMAC:
674 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
677 DBGLOG(REQ, WARN, ("invalid cipher pairwise (%d)\n",
678 sme->crypto.ciphers_pairwise[0]));
683 if (sme->crypto.cipher_group) {
684 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.u4GroupKeyCipherSuite = sme->crypto.cipher_group;
685 switch (sme->crypto.cipher_group) {
686 case WLAN_CIPHER_SUITE_WEP40:
687 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP40;
689 case WLAN_CIPHER_SUITE_WEP104:
690 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP104;
692 case WLAN_CIPHER_SUITE_TKIP:
693 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_TKIP;
695 case WLAN_CIPHER_SUITE_CCMP:
696 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
698 case WLAN_CIPHER_SUITE_AES_CMAC:
699 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
702 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
703 sme->crypto.cipher_group));
708 if (sme->crypto.n_akm_suites) {
709 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4AuthKeyMgtSuite[0] = sme->crypto.akm_suites[0];
710 if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA) {
711 switch (sme->crypto.akm_suites[0]) {
712 case WLAN_AKM_SUITE_8021X:
713 eAuthMode = AUTH_MODE_WPA;
715 case WLAN_AKM_SUITE_PSK:
716 eAuthMode = AUTH_MODE_WPA_PSK;
719 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
720 sme->crypto.cipher_group));
723 } else if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA2) {
724 switch (sme->crypto.akm_suites[0]) {
725 case WLAN_AKM_SUITE_8021X:
726 eAuthMode = AUTH_MODE_WPA2;
728 case WLAN_AKM_SUITE_PSK:
729 eAuthMode = AUTH_MODE_WPA2_PSK;
732 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
733 sme->crypto.cipher_group));
739 if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_DISABLED) {
740 eAuthMode = (prGlueInfo->rWpaInfo.u4AuthAlg == IW_AUTH_ALG_OPEN_SYSTEM) ?
741 AUTH_MODE_OPEN : AUTH_MODE_AUTO_SWITCH;
744 prGlueInfo->rWpaInfo.fgPrivacyInvoke = sme->privacy;
746 //prGlueInfo->prAdapter->rWifiVar.rConnSettings.fgWapiMode = FALSE;
747 //prGlueInfo->prAdapter->prGlueInfo->u2WapiAssocInfoIESz = 0;
748 prGlueInfo->fgWpsActive = FALSE;
749 //prGlueInfo->prAdapter->prGlueInfo->u2WSCAssocInfoIELen = 0;
751 if (sme->ie && sme->ie_len > 0) {
754 PUINT_8 prDesiredIE = NULL;
757 rStatus = kalIoctl(prGlueInfo,
758 wlanoidSetWapiAssocInfo,
767 if (rStatus != WLAN_STATUS_SUCCESS) {
768 DBGLOG(SEC, WARN, ("[wapi] set wapi assoc info error:%lx\n", rStatus));
772 if (wextSrchDesiredWPSIE(sme->ie,
775 (PUINT_8 *)&prDesiredIE)) {
776 prGlueInfo->fgWpsActive = TRUE;
779 rStatus = kalIoctl(prGlueInfo,
780 wlanoidSetWSCAssocInfo,
782 IE_SIZE(prDesiredIE),
788 if (rStatus != WLAN_STATUS_SUCCESS) {
789 DBGLOG(SEC, WARN, ("WSC] set WSC assoc info error:%lx\n", rStatus));
795 /* clear WSC Assoc IE buffer in case WPS IE is not detected */
796 if(fgCarryWPSIE == FALSE) {
797 kalMemZero(&prGlueInfo->aucWSCAssocInfoIE, 200);
798 prGlueInfo->u2WSCAssocInfoIELen = 0;
801 rStatus = kalIoctl(prGlueInfo,
810 if (rStatus != WLAN_STATUS_SUCCESS) {
811 DBGLOG(REQ, WARN, ("set auth mode error:%lx\n", rStatus));
814 cipher = prGlueInfo->rWpaInfo.u4CipherGroup | prGlueInfo->rWpaInfo.u4CipherPairwise;
816 if (prGlueInfo->rWpaInfo.fgPrivacyInvoke) {
817 if (cipher & IW_AUTH_CIPHER_CCMP) {
818 eEncStatus = ENUM_ENCRYPTION3_ENABLED;
820 else if (cipher & IW_AUTH_CIPHER_TKIP) {
821 eEncStatus = ENUM_ENCRYPTION2_ENABLED;
823 else if (cipher & (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
824 eEncStatus = ENUM_ENCRYPTION1_ENABLED;
826 else if (cipher & IW_AUTH_CIPHER_NONE){
827 if (prGlueInfo->rWpaInfo.fgPrivacyInvoke)
828 eEncStatus = ENUM_ENCRYPTION1_ENABLED;
830 eEncStatus = ENUM_ENCRYPTION_DISABLED;
833 eEncStatus = ENUM_ENCRYPTION_DISABLED;
837 eEncStatus = ENUM_ENCRYPTION_DISABLED;
840 rStatus = kalIoctl(prGlueInfo,
841 wlanoidSetEncryptionStatus,
849 if (rStatus != WLAN_STATUS_SUCCESS) {
850 DBGLOG(REQ, WARN, ("set encryption mode error:%lx\n", rStatus));
853 if (sme->key_len != 0 && prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_DISABLED) {
854 P_PARAM_WEP_T prWepKey = (P_PARAM_WEP_T) wepBuf;
856 kalMemSet(prWepKey, 0, sizeof(prWepKey));
857 prWepKey->u4Length = 12 + sme->key_len;
858 prWepKey->u4KeyLength = (UINT_32) sme->key_len;
859 prWepKey->u4KeyIndex = (UINT_32) sme->key_idx;
860 prWepKey->u4KeyIndex |= BIT(31);
861 if (prWepKey->u4KeyLength > 32) {
862 DBGLOG(REQ, WARN, ("Too long key length (%u)\n", prWepKey->u4KeyLength));
865 kalMemCopy(prWepKey->aucKeyMaterial, sme->key, prWepKey->u4KeyLength);
867 rStatus = kalIoctl(prGlueInfo,
877 if (rStatus != WLAN_STATUS_SUCCESS) {
878 DBGLOG(INIT, INFO, ("wlanoidSetAddWep fail 0x%lx\n", rStatus));
883 if(sme->ssid_len > 0) {
884 /* connect by SSID */
885 COPY_SSID(rNewSsid.aucSsid, rNewSsid.u4SsidLen, sme->ssid, sme->ssid_len);
887 rStatus = kalIoctl(prGlueInfo,
890 sizeof(PARAM_SSID_T),
897 if (rStatus != WLAN_STATUS_SUCCESS) {
898 DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
903 /* connect by BSSID */
904 rStatus = kalIoctl(prGlueInfo,
907 sizeof(MAC_ADDR_LEN),
914 if (rStatus != WLAN_STATUS_SUCCESS) {
915 DBGLOG(REQ, WARN, ("set BSSID:%lx\n", rStatus));
924 /*----------------------------------------------------------------------------*/
926 * @brief This routine is responsible for requesting to disconnect from
927 * currently connected ESS
931 * @retval 0: successful
934 /*----------------------------------------------------------------------------*/
936 mtk_cfg80211_disconnect (
938 struct net_device *ndev,
942 P_GLUE_INFO_T prGlueInfo = NULL;
946 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
949 rStatus = kalIoctl(prGlueInfo,
950 wlanoidSetDisassociate,
959 if (rStatus != WLAN_STATUS_SUCCESS) {
960 DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
968 /*----------------------------------------------------------------------------*/
970 * @brief This routine is responsible for requesting to join an IBSS group
974 * @retval 0: successful
977 /*----------------------------------------------------------------------------*/
979 mtk_cfg80211_join_ibss (
981 struct net_device *ndev,
982 struct cfg80211_ibss_params *params
985 PARAM_SSID_T rNewSsid;
986 P_GLUE_INFO_T prGlueInfo = NULL;
987 UINT_32 u4ChnlFreq; /* Store channel or frequency information */
988 UINT_32 u4BufLen = 0;
991 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
995 if(params->channel) {
996 u4ChnlFreq = nicChannelNum2Freq(params->channel->hw_value);
998 rStatus = kalIoctl(prGlueInfo,
1007 if (rStatus != WLAN_STATUS_SUCCESS) {
1013 kalMemCopy(rNewSsid.aucSsid, params->ssid, params->ssid_len);
1014 rStatus = kalIoctl(prGlueInfo,
1017 sizeof(PARAM_SSID_T),
1024 if (rStatus != WLAN_STATUS_SUCCESS) {
1025 DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
1036 /*----------------------------------------------------------------------------*/
1038 * @brief This routine is responsible for requesting to leave from IBSS group
1042 * @retval 0: successful
1045 /*----------------------------------------------------------------------------*/
1047 mtk_cfg80211_leave_ibss (
1048 struct wiphy *wiphy,
1049 struct net_device *ndev
1052 P_GLUE_INFO_T prGlueInfo = NULL;
1053 WLAN_STATUS rStatus;
1056 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1059 rStatus = kalIoctl(prGlueInfo,
1060 wlanoidSetDisassociate,
1069 if (rStatus != WLAN_STATUS_SUCCESS) {
1070 DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
1078 /*----------------------------------------------------------------------------*/
1080 * @brief This routine is responsible for requesting to configure
1081 * WLAN power managemenet
1085 * @retval 0: successful
1088 /*----------------------------------------------------------------------------*/
1090 mtk_cfg80211_set_power_mgmt (
1091 struct wiphy *wiphy,
1092 struct net_device *ndev,
1097 P_GLUE_INFO_T prGlueInfo = NULL;
1098 WLAN_STATUS rStatus;
1100 PARAM_POWER_MODE ePowerMode;
1102 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1107 ePowerMode = Param_PowerModeFast_PSP;
1110 ePowerMode = Param_PowerModeMAX_PSP;
1114 ePowerMode = Param_PowerModeCAM;
1117 rStatus = kalIoctl(prGlueInfo,
1118 wlanoidSet802dot11PowerSaveProfile,
1127 if (rStatus != WLAN_STATUS_SUCCESS) {
1128 DBGLOG(REQ, WARN, ("set_power_mgmt error:%lx\n", rStatus));
1136 /*----------------------------------------------------------------------------*/
1138 * @brief This routine is responsible for requesting to cache
1139 * a PMKID for a BSSID
1143 * @retval 0: successful
1146 /*----------------------------------------------------------------------------*/
1148 mtk_cfg80211_set_pmksa (
1149 struct wiphy *wiphy,
1150 struct net_device *ndev,
1151 struct cfg80211_pmksa *pmksa
1154 P_GLUE_INFO_T prGlueInfo = NULL;
1155 WLAN_STATUS rStatus;
1157 P_PARAM_PMKID_T prPmkid;
1159 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1162 prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8 + sizeof(PARAM_BSSID_INFO_T), VIR_MEM_TYPE);
1164 DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_ADD\n"));
1168 prPmkid->u4Length = 8 + sizeof(PARAM_BSSID_INFO_T);
1169 prPmkid->u4BSSIDInfoCount = 1;
1170 kalMemCopy(prPmkid->arBSSIDInfo->arBSSID, pmksa->bssid, 6);
1171 kalMemCopy(prPmkid->arBSSIDInfo->arPMKID, pmksa->pmkid, IW_PMKID_LEN);
1173 rStatus = kalIoctl(prGlueInfo,
1176 sizeof(PARAM_PMKID_T),
1183 if (rStatus != WLAN_STATUS_SUCCESS) {
1184 DBGLOG(INIT, INFO, ("add pmkid error:%lx\n", rStatus));
1186 kalMemFree(prPmkid, VIR_MEM_TYPE, 8 + sizeof(PARAM_BSSID_INFO_T));
1192 /*----------------------------------------------------------------------------*/
1194 * @brief This routine is responsible for requesting to remove
1195 * a cached PMKID for a BSSID
1199 * @retval 0: successful
1202 /*----------------------------------------------------------------------------*/
1204 mtk_cfg80211_del_pmksa (
1205 struct wiphy *wiphy,
1206 struct net_device *ndev,
1207 struct cfg80211_pmksa *pmksa
1215 /*----------------------------------------------------------------------------*/
1217 * @brief This routine is responsible for requesting to flush
1222 * @retval 0: successful
1225 /*----------------------------------------------------------------------------*/
1227 mtk_cfg80211_flush_pmksa (
1228 struct wiphy *wiphy,
1229 struct net_device *ndev
1232 P_GLUE_INFO_T prGlueInfo = NULL;
1233 WLAN_STATUS rStatus;
1235 P_PARAM_PMKID_T prPmkid;
1237 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1240 prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8, VIR_MEM_TYPE);
1242 DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_FLUSH\n"));
1246 prPmkid->u4Length = 8;
1247 prPmkid->u4BSSIDInfoCount = 0;
1249 rStatus = kalIoctl(prGlueInfo,
1252 sizeof(PARAM_PMKID_T),
1259 if (rStatus != WLAN_STATUS_SUCCESS) {
1260 DBGLOG(INIT, INFO, ("flush pmkid error:%lx\n", rStatus));
1262 kalMemFree(prPmkid, VIR_MEM_TYPE, 8);
1268 /*----------------------------------------------------------------------------*/
1270 * @brief This routine is responsible for requesting to stay on a
1275 * @retval 0: successful
1278 /*----------------------------------------------------------------------------*/
1280 mtk_cfg80211_remain_on_channel (
1281 struct wiphy *wiphy,
1282 struct net_device *ndev,
1283 struct ieee80211_channel *chan,
1284 enum nl80211_channel_type channel_type,
1285 unsigned int duration,
1289 P_GLUE_INFO_T prGlueInfo = NULL;
1291 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1296 /* not implemented */
1302 /*----------------------------------------------------------------------------*/
1304 * @brief This routine is responsible for requesting to cancel staying
1305 * on a specified channel
1309 * @retval 0: successful
1312 /*----------------------------------------------------------------------------*/
1314 mtk_cfg80211_cancel_remain_on_channel (
1315 struct wiphy *wiphy,
1316 struct net_device *ndev,
1320 P_GLUE_INFO_T prGlueInfo = NULL;
1322 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1326 /* not implemented */
1332 /*----------------------------------------------------------------------------*/
1334 * @brief This routine is responsible for requesting to send a management frame
1338 * @retval 0: successful
1341 /*----------------------------------------------------------------------------*/
1343 mtk_cfg80211_mgmt_tx (
1344 struct wiphy *wiphy,
1345 struct net_device *ndev,
1346 struct ieee80211_channel *channel,
1348 enum nl80211_channel_type channel_type,
1349 bool channel_type_valid,
1354 bool dont_wait_for_ack,
1358 P_GLUE_INFO_T prGlueInfo = NULL;
1360 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1364 /* not implemented */
1370 /*----------------------------------------------------------------------------*/
1372 * @brief This routine is responsible for requesting to cancel the wait time
1373 * from transmitting a management frame on another channel
1377 * @retval 0: successful
1380 /*----------------------------------------------------------------------------*/
1382 mtk_cfg80211_mgmt_tx_cancel_wait (
1383 struct wiphy *wiphy,
1384 struct net_device *ndev,
1388 P_GLUE_INFO_T prGlueInfo = NULL;
1390 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1394 /* not implemented */
1400 #if CONFIG_NL80211_TESTMODE
1402 #if CFG_SUPPORT_WAPI
1404 mtk_cfg80211_testmode_set_key_ext(
1405 IN struct wiphy *wiphy,
1409 P_GLUE_INFO_T prGlueInfo = NULL;
1410 P_NL80211_DRIVER_SET_KEY_EXTS prParams = (P_NL80211_DRIVER_SET_KEY_EXTS)NULL;
1411 struct iw_encode_exts *prIWEncExt = (struct iw_encode_exts *)NULL;
1412 WLAN_STATUS rstatus = WLAN_STATUS_SUCCESS;
1414 UINT_32 u4BufLen = 0;
1416 P_PARAM_WPI_KEY_T prWpiKey = (P_PARAM_WPI_KEY_T) keyStructBuf;
1417 memset(keyStructBuf, 0, sizeof(keyStructBuf));
1421 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1425 prParams = (P_NL80211_DRIVER_SET_KEY_EXTS)data;
1429 prIWEncExt = (struct iw_encode_exts *) &prParams->ext;
1432 if (prIWEncExt->alg == IW_ENCODE_ALG_SMS4) {
1434 prWpiKey->ucKeyID = prParams->key_index;
1435 prWpiKey->ucKeyID --;
1436 if (prWpiKey->ucKeyID > 1) {
1437 /* key id is out of range */
1438 //printk(KERN_INFO "[wapi] add key error: key_id invalid %d\n", prWpiKey->ucKeyID);
1442 if (prIWEncExt->key_len != 32) {
1443 /* key length not valid */
1444 //printk(KERN_INFO "[wapi] add key error: key_len invalid %d\n", prIWEncExt->key_len);
1448 //printk(KERN_INFO "[wapi] %d ext_flags %d\n", prEnc->flags, prIWEncExt->ext_flags);
1450 if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1451 prWpiKey->eKeyType = ENUM_WPI_GROUP_KEY;
1452 prWpiKey->eDirection = ENUM_WPI_RX;
1454 else if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1455 prWpiKey->eKeyType = ENUM_WPI_PAIRWISE_KEY;
1456 prWpiKey->eDirection = ENUM_WPI_RX_TX;
1459 //#if CFG_SUPPORT_WAPI
1460 //handle_sec_msg_final(prIWEncExt->key, 32, prIWEncExt->key, NULL);
1463 memcpy(prWpiKey->aucPN, prIWEncExt->tx_seq, IW_ENCODE_SEQ_MAX_SIZE * 2);
1466 memcpy(prWpiKey->aucAddrIndex, prIWEncExt->addr, 6);
1468 memcpy(prWpiKey->aucWPIEK, prIWEncExt->key, 16);
1469 prWpiKey->u4LenWPIEK = 16;
1471 memcpy(prWpiKey->aucWPICK, &prIWEncExt->key[16], 16);
1472 prWpiKey->u4LenWPICK = 16;
1474 rstatus = kalIoctl(prGlueInfo,
1477 sizeof(PARAM_WPI_KEY_T),
1484 if (rstatus != WLAN_STATUS_SUCCESS) {
1485 //printk(KERN_INFO "[wapi] add key error:%lx\n", rStatus);
1486 fgIsValid = -EFAULT;
1496 mtk_cfg80211_testmode_sw_cmd(
1497 IN struct wiphy *wiphy,
1501 P_GLUE_INFO_T prGlueInfo = NULL;
1502 P_NL80211_DRIVER_SW_CMD_PARAMS prParams = (P_NL80211_DRIVER_SW_CMD_PARAMS)NULL;
1503 WLAN_STATUS rstatus = WLAN_STATUS_SUCCESS;
1505 UINT_32 u4SetInfoLen = 0;
1509 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1514 prParams = (P_NL80211_DRIVER_SW_CMD_PARAMS)data;
1517 if(prParams->set == 1){
1518 rstatus = kalIoctl(prGlueInfo,
1519 (PFN_OID_HANDLER_FUNC)wlanoidSetSwCtrlWrite,
1530 if (WLAN_STATUS_SUCCESS != rstatus) {
1531 fgIsValid = -EFAULT;
1537 int mtk_cfg80211_testmode_cmd(
1538 IN struct wiphy *wiphy,
1543 P_GLUE_INFO_T prGlueInfo = NULL;
1544 P_NL80211_DRIVER_TEST_MODE_PARAMS prParams = (P_NL80211_DRIVER_TEST_MODE_PARAMS)NULL;
1545 BOOLEAN fgIsValid = 0;
1549 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1554 prParams = (P_NL80211_DRIVER_TEST_MODE_PARAMS)data;
1556 /* Clear the version byte */
1557 prParams->index = prParams->index & ~ BITS(24,31);
1560 switch(prParams->index){
1561 case 1: /* SW cmd */
1562 if(mtk_cfg80211_testmode_sw_cmd(wiphy, data, len))
1566 #if CFG_SUPPORT_WAPI
1567 if(mtk_cfg80211_testmode_set_key_ext(wiphy, data, len))