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 ** 11 23 2012 yuche.tsai
18 ** [ALPS00398671] [Acer-Tablet] Remove Wi-Fi Direct completely
19 ** Fix bug of WiFi may reboot under user load, when WiFi Direct is removed..
21 ** 09 12 2012 wcpadmin
22 ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
25 ** 08 30 2012 chinglan.wang
26 ** [ALPS00349664] [6577JB][WIFI] Phone can not connect to AP secured with AES via WPS in 802.11n Only
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 printk("--> %s()\n", __func__);
279 /* not implemented */
285 /*----------------------------------------------------------------------------*/
287 * @brief This routine is responsible for removing key for specified STA
291 * @retval 0: successful
294 /*----------------------------------------------------------------------------*/
296 mtk_cfg80211_del_key (
298 struct net_device *ndev,
304 P_GLUE_INFO_T prGlueInfo = NULL;
305 WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
306 PARAM_REMOVE_KEY_T rRemoveKey;
307 UINT_32 u4BufLen = 0;
308 INT_32 i4Rslt = -EINVAL;
310 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
313 kalMemZero(&rRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
315 COPY_MAC_ADDR(rRemoveKey.arBSSID, mac_addr);
316 rRemoveKey.u4KeyIndex = key_index;
317 rRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
320 rStatus = kalIoctl(prGlueInfo,
330 if (rStatus != WLAN_STATUS_SUCCESS) {
331 DBGLOG(REQ, WARN, ("remove key error:%lx\n", rStatus));
341 /*----------------------------------------------------------------------------*/
343 * @brief This routine is responsible for setting default key on an interface
347 * @retval 0: successful
350 /*----------------------------------------------------------------------------*/
352 mtk_cfg80211_set_default_key (
354 struct net_device *ndev,
360 P_GLUE_INFO_T prGlueInfo = NULL;
362 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
366 printk("--> %s()\n", __func__);
369 /* not implemented */
375 /*----------------------------------------------------------------------------*/
377 * @brief This routine is responsible for getting station information such as RSSI
381 * @retval 0: successful
384 /*----------------------------------------------------------------------------*/
387 mtk_cfg80211_get_station (
389 struct net_device *ndev,
391 struct station_info *sinfo
394 P_GLUE_INFO_T prGlueInfo = NULL;
396 PARAM_MAC_ADDRESS arBssid;
397 UINT_32 u4BufLen, u4Rate;
400 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
403 kalMemZero(arBssid, MAC_ADDR_LEN);
404 wlanQueryInformation(prGlueInfo->prAdapter,
411 if(UNEQUAL_MAC_ADDR(arBssid, mac)) {
412 /* wrong MAC address */
413 DBGLOG(REQ, WARN, ("incorrect BSSID: ["MACSTR"] currently connected BSSID["MACSTR"]\n",
414 MAC2STR(mac), MAC2STR(arBssid)));
418 /* 2. fill TX rate */
419 rStatus = kalIoctl(prGlueInfo,
420 wlanoidQueryLinkSpeed,
429 if (rStatus != WLAN_STATUS_SUCCESS) {
430 DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
433 sinfo->filled |= STATION_INFO_TX_BITRATE;
434 sinfo->txrate.legacy = u4Rate / 1000; /* convert from 100bps to 100kbps */
437 if(prGlueInfo->eParamMediaStateIndicated != PARAM_MEDIA_STATE_CONNECTED) {
439 DBGLOG(REQ, WARN, ("not yet connected\n"));
443 rStatus = kalIoctl(prGlueInfo,
453 if (rStatus != WLAN_STATUS_SUCCESS) {
454 DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
457 sinfo->filled |= STATION_INFO_SIGNAL;
458 //in the cfg80211 layer, the signal is a signed char variable.
460 sinfo->signal = -128;
462 sinfo->signal = i4Rssi; /* dBm */
466 sinfo->rx_packets = prGlueInfo->rNetDevStats.rx_packets;
467 sinfo->filled |= STATION_INFO_TX_PACKETS;
468 sinfo->tx_packets = prGlueInfo->rNetDevStats.tx_packets;
469 sinfo->filled |= STATION_INFO_TX_FAILED;
474 UINT_32 u4XmitError = 0;
475 // UINT_32 u4XmitOk = 0;
476 // UINT_32 u4RecvError = 0;
477 // UINT_32 u4RecvOk = 0;
480 /* @FIX ME: need a more clear way to do this */
483 rStatus = kalIoctl(prGlueInfo,
484 wlanoidQueryXmitError,
493 prGlueInfo->rNetDevStats.tx_errors = u4XmitError;
497 prGlueInfo->rNetDevStats.tx_errors = 0;
500 sinfo->tx_failed = prGlueInfo->rNetDevStats.tx_errors;
506 /*----------------------------------------------------------------------------*/
508 * @brief This routine is responsible for requesting to do a scan
512 * @retval 0: successful
515 /*----------------------------------------------------------------------------*/
519 struct net_device *ndev,
520 struct cfg80211_scan_request *request
523 P_GLUE_INFO_T prGlueInfo = NULL;
526 PARAM_SCAN_REQUEST_EXT_T rScanRequest;
528 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
531 kalMemZero(&rScanRequest, sizeof(PARAM_SCAN_REQUEST_EXT_T));
533 /* check if there is any pending scan not yet finished */
534 if(prGlueInfo->prScanRequest != NULL) {
538 if(request->n_ssids == 0) {
539 rScanRequest.rSsid.u4SsidLen = 0;
541 else if(request->n_ssids == 1) {
542 COPY_SSID(rScanRequest.rSsid.aucSsid, rScanRequest.rSsid.u4SsidLen, request->ssids[0].ssid, request->ssids[0].ssid_len);
548 if(request->ie_len > 0) {
549 rScanRequest.u4IELength = request->ie_len;
550 rScanRequest.pucIE = (PUINT_8)(request->ie);
553 rScanRequest.u4IELength = 0;
556 rStatus = kalIoctl(prGlueInfo,
557 wlanoidSetBssidListScanExt,
559 sizeof(PARAM_SCAN_REQUEST_EXT_T),
566 if (rStatus != WLAN_STATUS_SUCCESS) {
567 DBGLOG(REQ, WARN, ("scan error:%lx\n", rStatus));
571 prGlueInfo->prScanRequest = request;
576 static UINT_8 wepBuf[48];
578 /*----------------------------------------------------------------------------*/
580 * @brief This routine is responsible for requesting to connect to
581 * the ESS with the specified parameters
585 * @retval 0: successful
588 /*----------------------------------------------------------------------------*/
590 mtk_cfg80211_connect (
592 struct net_device *ndev,
593 struct cfg80211_connect_params *sme
596 P_GLUE_INFO_T prGlueInfo = NULL;
599 ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
600 ENUM_PARAM_AUTH_MODE_T eAuthMode;
602 PARAM_SSID_T rNewSsid;
603 BOOLEAN fgCarryWPSIE = FALSE;
604 ENUM_PARAM_OP_MODE_T eOpMode;
606 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
609 if (prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode > NET_TYPE_AUTO_SWITCH)
610 eOpMode = NET_TYPE_AUTO_SWITCH;
612 eOpMode = prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode;
614 rStatus = kalIoctl(prGlueInfo,
615 wlanoidSetInfrastructureMode,
624 if (rStatus != WLAN_STATUS_SUCCESS) {
625 DBGLOG(INIT, INFO, ("wlanoidSetInfrastructureMode fail 0x%lx\n", rStatus));
629 /* after set operation mode, key table are cleared */
632 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
633 prGlueInfo->rWpaInfo.u4KeyMgmt = 0;
634 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_NONE;
635 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_NONE;
636 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
637 #if CFG_SUPPORT_802_11W
638 prGlueInfo->rWpaInfo.u4Mfp = IW_AUTH_MFP_DISABLED;
641 if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
642 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_WPA;
643 else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
644 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_WPA2;
646 prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
648 switch (sme->auth_type) {
649 case NL80211_AUTHTYPE_OPEN_SYSTEM:
650 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
652 case NL80211_AUTHTYPE_SHARED_KEY:
653 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_SHARED_KEY;
656 prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM | IW_AUTH_ALG_SHARED_KEY;
660 if (sme->crypto.n_ciphers_pairwise) {
661 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4PairwiseKeyCipherSuite[0] = sme->crypto.ciphers_pairwise[0];
662 switch (sme->crypto.ciphers_pairwise[0]) {
663 case WLAN_CIPHER_SUITE_WEP40:
664 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP40;
666 case WLAN_CIPHER_SUITE_WEP104:
667 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP104;
669 case WLAN_CIPHER_SUITE_TKIP:
670 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_TKIP;
672 case WLAN_CIPHER_SUITE_CCMP:
673 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
675 case WLAN_CIPHER_SUITE_AES_CMAC:
676 prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
679 DBGLOG(REQ, WARN, ("invalid cipher pairwise (%d)\n",
680 sme->crypto.ciphers_pairwise[0]));
685 if (sme->crypto.cipher_group) {
686 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.u4GroupKeyCipherSuite = sme->crypto.cipher_group;
687 switch (sme->crypto.cipher_group) {
688 case WLAN_CIPHER_SUITE_WEP40:
689 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP40;
691 case WLAN_CIPHER_SUITE_WEP104:
692 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP104;
694 case WLAN_CIPHER_SUITE_TKIP:
695 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_TKIP;
697 case WLAN_CIPHER_SUITE_CCMP:
698 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
700 case WLAN_CIPHER_SUITE_AES_CMAC:
701 prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
704 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
705 sme->crypto.cipher_group));
710 if (sme->crypto.n_akm_suites) {
711 prGlueInfo->prAdapter->rWifiVar.rConnSettings.rRsnInfo.au4AuthKeyMgtSuite[0] = sme->crypto.akm_suites[0];
712 if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA) {
713 switch (sme->crypto.akm_suites[0]) {
714 case WLAN_AKM_SUITE_8021X:
715 eAuthMode = AUTH_MODE_WPA;
717 case WLAN_AKM_SUITE_PSK:
718 eAuthMode = AUTH_MODE_WPA_PSK;
721 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
722 sme->crypto.cipher_group));
725 } else if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_WPA2) {
726 switch (sme->crypto.akm_suites[0]) {
727 case WLAN_AKM_SUITE_8021X:
728 eAuthMode = AUTH_MODE_WPA2;
730 case WLAN_AKM_SUITE_PSK:
731 eAuthMode = AUTH_MODE_WPA2_PSK;
734 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
735 sme->crypto.cipher_group));
741 if (prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_DISABLED) {
742 eAuthMode = (prGlueInfo->rWpaInfo.u4AuthAlg == IW_AUTH_ALG_OPEN_SYSTEM) ?
743 AUTH_MODE_OPEN : AUTH_MODE_AUTO_SWITCH;
746 prGlueInfo->rWpaInfo.fgPrivacyInvoke = sme->privacy;
748 //prGlueInfo->prAdapter->rWifiVar.rConnSettings.fgWapiMode = FALSE;
749 //prGlueInfo->prAdapter->prGlueInfo->u2WapiAssocInfoIESz = 0;
750 prGlueInfo->fgWpsActive = FALSE;
751 //prGlueInfo->prAdapter->prGlueInfo->u2WSCAssocInfoIELen = 0;
753 if (sme->ie && sme->ie_len > 0) {
756 PUINT_8 prDesiredIE = NULL;
759 rStatus = kalIoctl(prGlueInfo,
760 wlanoidSetWapiAssocInfo,
769 if (rStatus != WLAN_STATUS_SUCCESS) {
770 DBGLOG(SEC, WARN, ("[wapi] set wapi assoc info error:%lx\n", rStatus));
774 if (wextSrchDesiredWPSIE(sme->ie,
777 (PUINT_8 *)&prDesiredIE)) {
778 prGlueInfo->fgWpsActive = TRUE;
781 rStatus = kalIoctl(prGlueInfo,
782 wlanoidSetWSCAssocInfo,
784 IE_SIZE(prDesiredIE),
790 if (rStatus != WLAN_STATUS_SUCCESS) {
791 DBGLOG(SEC, WARN, ("WSC] set WSC assoc info error:%lx\n", rStatus));
797 /* clear WSC Assoc IE buffer in case WPS IE is not detected */
798 if(fgCarryWPSIE == FALSE) {
799 kalMemZero(&prGlueInfo->aucWSCAssocInfoIE, 200);
800 prGlueInfo->u2WSCAssocInfoIELen = 0;
803 rStatus = kalIoctl(prGlueInfo,
812 if (rStatus != WLAN_STATUS_SUCCESS) {
813 DBGLOG(REQ, WARN, ("set auth mode error:%lx\n", rStatus));
816 cipher = prGlueInfo->rWpaInfo.u4CipherGroup | prGlueInfo->rWpaInfo.u4CipherPairwise;
818 if (prGlueInfo->rWpaInfo.fgPrivacyInvoke) {
819 if (cipher & IW_AUTH_CIPHER_CCMP) {
820 eEncStatus = ENUM_ENCRYPTION3_ENABLED;
822 else if (cipher & IW_AUTH_CIPHER_TKIP) {
823 eEncStatus = ENUM_ENCRYPTION2_ENABLED;
825 else if (cipher & (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
826 eEncStatus = ENUM_ENCRYPTION1_ENABLED;
828 else if (cipher & IW_AUTH_CIPHER_NONE){
829 if (prGlueInfo->rWpaInfo.fgPrivacyInvoke)
830 eEncStatus = ENUM_ENCRYPTION1_ENABLED;
832 eEncStatus = ENUM_ENCRYPTION_DISABLED;
835 eEncStatus = ENUM_ENCRYPTION_DISABLED;
839 eEncStatus = ENUM_ENCRYPTION_DISABLED;
842 rStatus = kalIoctl(prGlueInfo,
843 wlanoidSetEncryptionStatus,
851 if (rStatus != WLAN_STATUS_SUCCESS) {
852 DBGLOG(REQ, WARN, ("set encryption mode error:%lx\n", rStatus));
855 if (sme->key_len != 0 && prGlueInfo->rWpaInfo.u4WpaVersion == IW_AUTH_WPA_VERSION_DISABLED) {
856 P_PARAM_WEP_T prWepKey = (P_PARAM_WEP_T) wepBuf;
858 kalMemSet(prWepKey, 0, sizeof(prWepKey));
859 prWepKey->u4Length = 12 + sme->key_len;
860 prWepKey->u4KeyLength = (UINT_32) sme->key_len;
861 prWepKey->u4KeyIndex = (UINT_32) sme->key_idx;
862 prWepKey->u4KeyIndex |= BIT(31);
863 if (prWepKey->u4KeyLength > 32) {
864 DBGLOG(REQ, WARN, ("Too long key length (%u)\n", prWepKey->u4KeyLength));
867 kalMemCopy(prWepKey->aucKeyMaterial, sme->key, prWepKey->u4KeyLength);
869 rStatus = kalIoctl(prGlueInfo,
879 if (rStatus != WLAN_STATUS_SUCCESS) {
880 DBGLOG(INIT, INFO, ("wlanoidSetAddWep fail 0x%lx\n", rStatus));
885 if(sme->ssid_len > 0) {
886 /* connect by SSID */
887 COPY_SSID(rNewSsid.aucSsid, rNewSsid.u4SsidLen, sme->ssid, sme->ssid_len);
889 rStatus = kalIoctl(prGlueInfo,
892 sizeof(PARAM_SSID_T),
899 if (rStatus != WLAN_STATUS_SUCCESS) {
900 DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
905 /* connect by BSSID */
906 rStatus = kalIoctl(prGlueInfo,
909 sizeof(MAC_ADDR_LEN),
916 if (rStatus != WLAN_STATUS_SUCCESS) {
917 DBGLOG(REQ, WARN, ("set BSSID:%lx\n", rStatus));
926 /*----------------------------------------------------------------------------*/
928 * @brief This routine is responsible for requesting to disconnect from
929 * currently connected ESS
933 * @retval 0: successful
936 /*----------------------------------------------------------------------------*/
938 mtk_cfg80211_disconnect (
940 struct net_device *ndev,
944 P_GLUE_INFO_T prGlueInfo = NULL;
948 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
951 rStatus = kalIoctl(prGlueInfo,
952 wlanoidSetDisassociate,
961 if (rStatus != WLAN_STATUS_SUCCESS) {
962 DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
970 /*----------------------------------------------------------------------------*/
972 * @brief This routine is responsible for requesting to join an IBSS group
976 * @retval 0: successful
979 /*----------------------------------------------------------------------------*/
981 mtk_cfg80211_join_ibss (
983 struct net_device *ndev,
984 struct cfg80211_ibss_params *params
987 PARAM_SSID_T rNewSsid;
988 P_GLUE_INFO_T prGlueInfo = NULL;
989 UINT_32 u4ChnlFreq; /* Store channel or frequency information */
990 UINT_32 u4BufLen = 0;
993 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
997 if(params->channel) {
998 u4ChnlFreq = nicChannelNum2Freq(params->channel->hw_value);
1000 rStatus = kalIoctl(prGlueInfo,
1001 wlanoidSetFrequency,
1009 if (rStatus != WLAN_STATUS_SUCCESS) {
1015 kalMemCopy(rNewSsid.aucSsid, params->ssid, params->ssid_len);
1016 rStatus = kalIoctl(prGlueInfo,
1019 sizeof(PARAM_SSID_T),
1026 if (rStatus != WLAN_STATUS_SUCCESS) {
1027 DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
1038 /*----------------------------------------------------------------------------*/
1040 * @brief This routine is responsible for requesting to leave from IBSS group
1044 * @retval 0: successful
1047 /*----------------------------------------------------------------------------*/
1049 mtk_cfg80211_leave_ibss (
1050 struct wiphy *wiphy,
1051 struct net_device *ndev
1054 P_GLUE_INFO_T prGlueInfo = NULL;
1055 WLAN_STATUS rStatus;
1058 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1061 rStatus = kalIoctl(prGlueInfo,
1062 wlanoidSetDisassociate,
1071 if (rStatus != WLAN_STATUS_SUCCESS) {
1072 DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
1080 /*----------------------------------------------------------------------------*/
1082 * @brief This routine is responsible for requesting to configure
1083 * WLAN power managemenet
1087 * @retval 0: successful
1090 /*----------------------------------------------------------------------------*/
1092 mtk_cfg80211_set_power_mgmt (
1093 struct wiphy *wiphy,
1094 struct net_device *ndev,
1099 P_GLUE_INFO_T prGlueInfo = NULL;
1100 WLAN_STATUS rStatus;
1102 PARAM_POWER_MODE ePowerMode;
1104 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1109 ePowerMode = Param_PowerModeFast_PSP;
1112 ePowerMode = Param_PowerModeMAX_PSP;
1116 ePowerMode = Param_PowerModeCAM;
1119 rStatus = kalIoctl(prGlueInfo,
1120 wlanoidSet802dot11PowerSaveProfile,
1129 if (rStatus != WLAN_STATUS_SUCCESS) {
1130 DBGLOG(REQ, WARN, ("set_power_mgmt error:%lx\n", rStatus));
1138 /*----------------------------------------------------------------------------*/
1140 * @brief This routine is responsible for requesting to cache
1141 * a PMKID for a BSSID
1145 * @retval 0: successful
1148 /*----------------------------------------------------------------------------*/
1150 mtk_cfg80211_set_pmksa (
1151 struct wiphy *wiphy,
1152 struct net_device *ndev,
1153 struct cfg80211_pmksa *pmksa
1156 P_GLUE_INFO_T prGlueInfo = NULL;
1157 WLAN_STATUS rStatus;
1159 P_PARAM_PMKID_T prPmkid;
1161 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1164 prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8 + sizeof(PARAM_BSSID_INFO_T), VIR_MEM_TYPE);
1166 DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_ADD\n"));
1170 prPmkid->u4Length = 8 + sizeof(PARAM_BSSID_INFO_T);
1171 prPmkid->u4BSSIDInfoCount = 1;
1172 kalMemCopy(prPmkid->arBSSIDInfo->arBSSID, pmksa->bssid, 6);
1173 kalMemCopy(prPmkid->arBSSIDInfo->arPMKID, pmksa->pmkid, IW_PMKID_LEN);
1175 rStatus = kalIoctl(prGlueInfo,
1178 sizeof(PARAM_PMKID_T),
1185 if (rStatus != WLAN_STATUS_SUCCESS) {
1186 DBGLOG(INIT, INFO, ("add pmkid error:%lx\n", rStatus));
1188 kalMemFree(prPmkid, VIR_MEM_TYPE, 8 + sizeof(PARAM_BSSID_INFO_T));
1194 /*----------------------------------------------------------------------------*/
1196 * @brief This routine is responsible for requesting to remove
1197 * a cached PMKID for a BSSID
1201 * @retval 0: successful
1204 /*----------------------------------------------------------------------------*/
1206 mtk_cfg80211_del_pmksa (
1207 struct wiphy *wiphy,
1208 struct net_device *ndev,
1209 struct cfg80211_pmksa *pmksa
1217 /*----------------------------------------------------------------------------*/
1219 * @brief This routine is responsible for requesting to flush
1224 * @retval 0: successful
1227 /*----------------------------------------------------------------------------*/
1229 mtk_cfg80211_flush_pmksa (
1230 struct wiphy *wiphy,
1231 struct net_device *ndev
1234 P_GLUE_INFO_T prGlueInfo = NULL;
1235 WLAN_STATUS rStatus;
1237 P_PARAM_PMKID_T prPmkid;
1239 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1242 prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8, VIR_MEM_TYPE);
1244 DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_FLUSH\n"));
1248 prPmkid->u4Length = 8;
1249 prPmkid->u4BSSIDInfoCount = 0;
1251 rStatus = kalIoctl(prGlueInfo,
1254 sizeof(PARAM_PMKID_T),
1261 if (rStatus != WLAN_STATUS_SUCCESS) {
1262 DBGLOG(INIT, INFO, ("flush pmkid error:%lx\n", rStatus));
1264 kalMemFree(prPmkid, VIR_MEM_TYPE, 8);
1270 /*----------------------------------------------------------------------------*/
1272 * @brief This routine is responsible for requesting to stay on a
1277 * @retval 0: successful
1280 /*----------------------------------------------------------------------------*/
1282 mtk_cfg80211_remain_on_channel (
1283 struct wiphy *wiphy,
1284 struct net_device *ndev,
1285 struct ieee80211_channel *chan,
1286 enum nl80211_channel_type channel_type,
1287 unsigned int duration,
1291 P_GLUE_INFO_T prGlueInfo = NULL;
1293 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1297 printk("--> %s()\n", __func__);
1300 /* not implemented */
1306 /*----------------------------------------------------------------------------*/
1308 * @brief This routine is responsible for requesting to cancel staying
1309 * on a specified channel
1313 * @retval 0: successful
1316 /*----------------------------------------------------------------------------*/
1318 mtk_cfg80211_cancel_remain_on_channel (
1319 struct wiphy *wiphy,
1320 struct net_device *ndev,
1324 P_GLUE_INFO_T prGlueInfo = NULL;
1326 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1330 printk("--> %s()\n", __func__);
1333 /* not implemented */
1339 /*----------------------------------------------------------------------------*/
1341 * @brief This routine is responsible for requesting to send a management frame
1345 * @retval 0: successful
1348 /*----------------------------------------------------------------------------*/
1350 mtk_cfg80211_mgmt_tx (
1351 struct wiphy *wiphy,
1352 struct net_device *ndev,
1353 struct ieee80211_channel *channel,
1355 enum nl80211_channel_type channel_type,
1356 bool channel_type_valid,
1361 bool dont_wait_for_ack,
1365 P_GLUE_INFO_T prGlueInfo = NULL;
1367 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1371 printk("--> %s()\n", __func__);
1374 /* not implemented */
1380 /*----------------------------------------------------------------------------*/
1382 * @brief This routine is responsible for requesting to cancel the wait time
1383 * from transmitting a management frame on another channel
1387 * @retval 0: successful
1390 /*----------------------------------------------------------------------------*/
1392 mtk_cfg80211_mgmt_tx_cancel_wait (
1393 struct wiphy *wiphy,
1394 struct net_device *ndev,
1398 P_GLUE_INFO_T prGlueInfo = NULL;
1400 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1404 printk("--> %s()\n", __func__);
1407 /* not implemented */
1413 #if CONFIG_NL80211_TESTMODE
1415 #if CFG_SUPPORT_WAPI
1417 mtk_cfg80211_testmode_set_key_ext(
1418 IN struct wiphy *wiphy,
1422 P_GLUE_INFO_T prGlueInfo = NULL;
1423 P_NL80211_DRIVER_SET_KEY_EXTS prParams = (P_NL80211_DRIVER_SET_KEY_EXTS)NULL;
1424 struct iw_encode_exts *prIWEncExt = (struct iw_encode_exts *)NULL;
1425 WLAN_STATUS rstatus = WLAN_STATUS_SUCCESS;
1427 UINT_32 u4BufLen = 0;
1429 P_PARAM_WPI_KEY_T prWpiKey = (P_PARAM_WPI_KEY_T) keyStructBuf;
1430 memset(keyStructBuf, 0, sizeof(keyStructBuf));
1434 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1437 printk("--> %s()\n", __func__);
1441 prParams = (P_NL80211_DRIVER_SET_KEY_EXTS)data;
1445 prIWEncExt = (struct iw_encode_exts *) &prParams->ext;
1448 if (prIWEncExt->alg == IW_ENCODE_ALG_SMS4) {
1450 prWpiKey->ucKeyID = prParams->key_index;
1451 prWpiKey->ucKeyID --;
1452 if (prWpiKey->ucKeyID > 1) {
1453 /* key id is out of range */
1454 //printk(KERN_INFO "[wapi] add key error: key_id invalid %d\n", prWpiKey->ucKeyID);
1458 if (prIWEncExt->key_len != 32) {
1459 /* key length not valid */
1460 //printk(KERN_INFO "[wapi] add key error: key_len invalid %d\n", prIWEncExt->key_len);
1464 //printk(KERN_INFO "[wapi] %d ext_flags %d\n", prEnc->flags, prIWEncExt->ext_flags);
1466 if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1467 prWpiKey->eKeyType = ENUM_WPI_GROUP_KEY;
1468 prWpiKey->eDirection = ENUM_WPI_RX;
1470 else if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1471 prWpiKey->eKeyType = ENUM_WPI_PAIRWISE_KEY;
1472 prWpiKey->eDirection = ENUM_WPI_RX_TX;
1475 //#if CFG_SUPPORT_WAPI
1476 //handle_sec_msg_final(prIWEncExt->key, 32, prIWEncExt->key, NULL);
1479 memcpy(prWpiKey->aucPN, prIWEncExt->tx_seq, IW_ENCODE_SEQ_MAX_SIZE * 2);
1482 memcpy(prWpiKey->aucAddrIndex, prIWEncExt->addr, 6);
1484 memcpy(prWpiKey->aucWPIEK, prIWEncExt->key, 16);
1485 prWpiKey->u4LenWPIEK = 16;
1487 memcpy(prWpiKey->aucWPICK, &prIWEncExt->key[16], 16);
1488 prWpiKey->u4LenWPICK = 16;
1490 rstatus = kalIoctl(prGlueInfo,
1493 sizeof(PARAM_WPI_KEY_T),
1500 if (rstatus != WLAN_STATUS_SUCCESS) {
1501 //printk(KERN_INFO "[wapi] add key error:%lx\n", rStatus);
1502 fgIsValid = -EFAULT;
1512 mtk_cfg80211_testmode_sw_cmd(
1513 IN struct wiphy *wiphy,
1517 P_GLUE_INFO_T prGlueInfo = NULL;
1518 P_NL80211_DRIVER_SW_CMD_PARAMS prParams = (P_NL80211_DRIVER_SW_CMD_PARAMS)NULL;
1519 WLAN_STATUS rstatus = WLAN_STATUS_SUCCESS;
1521 UINT_32 u4SetInfoLen = 0;
1525 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1528 printk("--> %s()\n", __func__);
1532 prParams = (P_NL80211_DRIVER_SW_CMD_PARAMS)data;
1535 if(prParams->set == 1){
1536 rstatus = kalIoctl(prGlueInfo,
1537 (PFN_OID_HANDLER_FUNC)wlanoidSetSwCtrlWrite,
1548 if (WLAN_STATUS_SUCCESS != rstatus) {
1549 fgIsValid = -EFAULT;
1555 int mtk_cfg80211_testmode_cmd(
1556 IN struct wiphy *wiphy,
1561 P_GLUE_INFO_T prGlueInfo = NULL;
1562 P_NL80211_DRIVER_TEST_MODE_PARAMS prParams = (P_NL80211_DRIVER_TEST_MODE_PARAMS)NULL;
1563 BOOLEAN fgIsValid = 0;
1567 prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1570 printk("--> %s()\n", __func__);
1574 prParams = (P_NL80211_DRIVER_TEST_MODE_PARAMS)data;
1576 /* Clear the version byte */
1577 prParams->index = prParams->index & ~ BITS(24,31);
1580 switch(prParams->index){
1581 case 1: /* SW cmd */
1582 if(mtk_cfg80211_testmode_sw_cmd(wiphy, data, len))
1586 #if CFG_SUPPORT_WAPI
1587 if(mtk_cfg80211_testmode_set_key_ext(wiphy, data, len))