support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6620 / wlan / os / linux / gl_cfg80211.c
1 /*
2 ** $Id: @(#) gl_cfg80211.c@@
3 */
4
5 /*! \file   gl_cfg80211.c
6     \brief  Main routines for supporintg MT6620 cfg80211 control interface
7
8     This file contains the support routines of Linux driver for MediaTek Inc. 802.11
9     Wireless LAN Adapters.
10 */
11
12
13
14 /*
15 ** $Log: gl_cfg80211.c $
16 **
17 ** 09 12 2012 wcpadmin
18 ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
19 ** .
20 ** 
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..
24 ** 
25 ** 08 29 2012 chinglan.wang
26 ** [ALPS00349655] [Need Patch] [Volunteer Patch] [ALPS.JB] Daily build warning on [mt6575_phone_mhl-eng]
27 ** .
28  *
29 **
30 */
31
32 /*******************************************************************************
33 *                         C O M P I L E R   F L A G S
34 ********************************************************************************
35 */
36
37 /*******************************************************************************
38 *                    E X T E R N A L   R E F E R E N C E S
39 ********************************************************************************
40 */
41 #include "gl_os.h"
42 #include "debug.h"
43 #include "wlan_lib.h"
44 #include "gl_wext.h"
45 #include "precomp.h"
46
47 /*******************************************************************************
48 *                              C O N S T A N T S
49 ********************************************************************************
50 */
51
52 /*******************************************************************************
53 *                             D A T A   T Y P E S
54 ********************************************************************************
55 */
56
57 /*******************************************************************************
58 *                            P U B L I C   D A T A
59 ********************************************************************************
60 */
61
62 #if CFG_SUPPORT_WAPI
63     extern UINT_8 keyStructBuf[1024];   /* add/remove key shared buffer */
64 #else
65     extern UINT_8 keyStructBuf[100];   /* add/remove key shared buffer */
66 #endif
67
68 /*******************************************************************************
69 *                           P R I V A T E   D A T A
70 ********************************************************************************
71 */
72
73 /*******************************************************************************
74 *                                 M A C R O S
75 ********************************************************************************
76 */
77
78 /*******************************************************************************
79 *                   F U N C T I O N   D E C L A R A T I O N S
80 ********************************************************************************
81 */
82
83 /*******************************************************************************
84 *                              F U N C T I O N S
85 ********************************************************************************
86 */
87
88 /*----------------------------------------------------------------------------*/
89 /*!
90  * @brief This routine is responsible for change STA type between
91  *        1. Infrastructure Client (Non-AP STA)
92  *        2. Ad-Hoc IBSS
93  *
94  * @param
95  *
96  * @retval 0:       successful
97  *         others:  failure
98  */
99 /*----------------------------------------------------------------------------*/
100 int 
101 mtk_cfg80211_change_iface (
102     struct wiphy *wiphy,
103     struct net_device *ndev,
104     enum nl80211_iftype type,
105     u32 *flags,
106     struct vif_params *params
107     )
108 {
109     P_GLUE_INFO_T prGlueInfo = NULL;
110     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
111     ENUM_PARAM_OP_MODE_T eOpMode;
112     UINT_32 u4BufLen;
113
114     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
115     ASSERT(prGlueInfo);
116
117     if(type == NL80211_IFTYPE_STATION) {
118         eOpMode = NET_TYPE_INFRA;
119     }
120     else if(type == NL80211_IFTYPE_ADHOC) {
121         eOpMode = NET_TYPE_IBSS;
122     }
123     else {
124         return -EINVAL;
125     }
126
127     rStatus = kalIoctl(prGlueInfo,
128             wlanoidSetInfrastructureMode,
129             &eOpMode,
130             sizeof(eOpMode),
131             FALSE,
132             FALSE,
133             TRUE,
134             FALSE,
135             &u4BufLen);
136     
137     if (rStatus != WLAN_STATUS_SUCCESS) {
138         DBGLOG(REQ, WARN, ("set infrastructure mode error:%lx\n", rStatus));
139     }
140
141     /* reset wpa info */
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;
149 #endif
150
151     return 0;
152 }
153
154
155 /*----------------------------------------------------------------------------*/
156 /*!
157  * @brief This routine is responsible for adding key 
158  *
159  * @param 
160  *
161  * @retval 0:       successful
162  *         others:  failure
163  */
164 /*----------------------------------------------------------------------------*/
165 int
166 mtk_cfg80211_add_key (
167     struct wiphy *wiphy,
168     struct net_device *ndev,
169     u8 key_index,
170     bool pairwise,
171     const u8 *mac_addr,
172     struct key_params *params
173     )
174 {
175     PARAM_KEY_T rKey;
176     P_GLUE_INFO_T prGlueInfo = NULL;
177     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
178     INT_32 i4Rslt = -EINVAL;
179     UINT_32 u4BufLen = 0;
180     UINT_8 tmp1[8];
181     UINT_8 tmp2[8];
182
183     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
184     ASSERT(prGlueInfo);
185     
186     kalMemZero(&rKey, sizeof(PARAM_KEY_T));
187
188     rKey.u4KeyIndex = key_index;
189     
190     if(mac_addr) {
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;
200         }
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);
206         }
207     }
208     else {
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 
216     }
217     
218     if(params->key) {
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, &params->key[16], 8);
223             kalMemCopy(tmp2, &params->key[24], 8);        
224             kalMemCopy(&rKey.aucKeyMaterial[16], tmp2, 8);
225             kalMemCopy(&rKey.aucKeyMaterial[24], tmp1, 8);
226         }
227     }
228
229     rKey.u4KeyLength = params->key_len;
230     rKey.u4Length =  ((UINT_32)&(((P_P2P_PARAM_KEY_T)0)->aucKeyMaterial)) + rKey.u4KeyLength;
231     
232     rStatus = kalIoctl(prGlueInfo,
233             wlanoidSetAddKey,
234             &rKey,
235             rKey.u4Length,
236             FALSE,
237             FALSE,
238             TRUE,
239             FALSE,
240             &u4BufLen);
241     
242     if (rStatus == WLAN_STATUS_SUCCESS)
243         i4Rslt = 0;
244
245     return i4Rslt;
246 }
247
248
249 /*----------------------------------------------------------------------------*/
250 /*!
251  * @brief This routine is responsible for getting key for specified STA
252  *
253  * @param 
254  *
255  * @retval 0:       successful
256  *         others:  failure
257  */
258 /*----------------------------------------------------------------------------*/
259 int 
260 mtk_cfg80211_get_key (
261     struct wiphy *wiphy,
262     struct net_device *ndev,
263     u8 key_index,
264     bool pairwise,
265     const u8 *mac_addr,
266     void *cookie,
267     void (*callback)(void *cookie, struct key_params*)
268     )
269 {
270     P_GLUE_INFO_T prGlueInfo = NULL;
271
272     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
273     ASSERT(prGlueInfo);
274
275
276     /* not implemented */
277
278     return -EINVAL;
279 }
280
281
282 /*----------------------------------------------------------------------------*/
283 /*!
284  * @brief This routine is responsible for removing key for specified STA
285  *
286  * @param 
287  *
288  * @retval 0:       successful
289  *         others:  failure
290  */
291 /*----------------------------------------------------------------------------*/
292 int
293 mtk_cfg80211_del_key (
294     struct wiphy *wiphy,
295     struct net_device *ndev,
296     u8 key_index,
297     bool pairwise,
298     const u8 *mac_addr
299     )
300 {
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;
306
307     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
308     ASSERT(prGlueInfo);
309
310     kalMemZero(&rRemoveKey, sizeof(PARAM_REMOVE_KEY_T));
311     if(mac_addr)
312         COPY_MAC_ADDR(rRemoveKey.arBSSID, mac_addr);
313     rRemoveKey.u4KeyIndex = key_index;
314     rRemoveKey.u4Length = sizeof(PARAM_REMOVE_KEY_T);
315     
316
317     rStatus = kalIoctl(prGlueInfo,
318             wlanoidSetRemoveKey,
319             &rRemoveKey,
320             rRemoveKey.u4Length,
321             FALSE,
322             FALSE,
323             TRUE,
324             FALSE,
325             &u4BufLen);
326
327     if (rStatus != WLAN_STATUS_SUCCESS) {
328         DBGLOG(REQ, WARN, ("remove key error:%lx\n", rStatus));
329     }
330     else {
331         i4Rslt = 0;
332     }
333
334     return i4Rslt;
335 }
336
337
338 /*----------------------------------------------------------------------------*/
339 /*!
340  * @brief This routine is responsible for setting default key on an interface
341  *
342  * @param 
343  *
344  * @retval 0:       successful
345  *         others:  failure
346  */
347 /*----------------------------------------------------------------------------*/
348 int 
349 mtk_cfg80211_set_default_key (
350     struct wiphy *wiphy,
351     struct net_device *ndev,
352     u8 key_index,
353     bool unicast,
354     bool multicast
355     )
356 {
357     P_GLUE_INFO_T prGlueInfo = NULL;
358
359     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
360     ASSERT(prGlueInfo);
361
362
363
364 /* for wpa_supplicant 2.0 need to set default key, return 0.
365     // not implemented 
366     return -EINVAL;
367 */
368         return 0;
369
370 }
371
372
373 /*----------------------------------------------------------------------------*/
374 /*!
375  * @brief This routine is responsible for getting station information such as RSSI
376  *
377  * @param 
378  *
379  * @retval 0:       successful
380  *         others:  failure
381  */
382 /*----------------------------------------------------------------------------*/
383
384 int
385 mtk_cfg80211_get_station (
386     struct wiphy *wiphy,
387     struct net_device *ndev,
388     u8 *mac,
389     struct station_info *sinfo
390     )
391 {
392     P_GLUE_INFO_T prGlueInfo = NULL;
393     WLAN_STATUS rStatus;
394     PARAM_MAC_ADDRESS arBssid;
395     UINT_32 u4BufLen, u4Rate;
396     INT_32 i4Rssi;
397
398     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
399     ASSERT(prGlueInfo);
400
401     kalMemZero(arBssid, MAC_ADDR_LEN);
402     wlanQueryInformation(prGlueInfo->prAdapter,
403             wlanoidQueryBssid,
404             &arBssid[0],
405             sizeof(arBssid),
406             &u4BufLen);
407
408     /* 1. check BSSID */
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)));
413         return -ENOENT;
414     }
415
416     /* 2. fill TX rate */
417     rStatus = kalIoctl(prGlueInfo,
418         wlanoidQueryLinkSpeed,
419         &u4Rate,
420         sizeof(u4Rate),
421         TRUE,
422         FALSE,
423         FALSE,
424         FALSE,
425         &u4BufLen);
426
427     if (rStatus != WLAN_STATUS_SUCCESS) {
428         DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
429     }
430     else {
431         sinfo->filled |= STATION_INFO_TX_BITRATE;
432         sinfo->txrate.legacy = u4Rate / 1000; /* convert from 100bps to 100kbps */
433     }
434
435     if(prGlueInfo->eParamMediaStateIndicated != PARAM_MEDIA_STATE_CONNECTED) {
436         /* not connected */
437         DBGLOG(REQ, WARN, ("not yet connected\n"));
438     }
439     else {
440         /* 3. fill RSSI */
441         rStatus = kalIoctl(prGlueInfo,
442                 wlanoidQueryRssi,
443                 &i4Rssi,
444                 sizeof(i4Rssi),
445                 TRUE,
446                 FALSE,
447                 FALSE,
448                 FALSE,
449                 &u4BufLen);
450         
451         if (rStatus != WLAN_STATUS_SUCCESS) {
452             DBGLOG(REQ, WARN, ("unable to retrieve link speed\n"));
453         }
454         else {
455             sinfo->filled |= STATION_INFO_SIGNAL;
456             //in the cfg80211 layer, the signal is a signed char variable.
457             if(i4Rssi < -128)
458                 sinfo->signal = -128;
459             else
460                 sinfo->signal = i4Rssi; /* dBm */
461         }
462     }
463
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;
468
469 #if 1
470    {
471             WLAN_STATUS rStatus;
472             UINT_32 u4XmitError = 0;
473 //           UINT_32 u4XmitOk = 0;
474 //          UINT_32 u4RecvError = 0;
475 //           UINT_32 u4RecvOk = 0;
476 //           UINT_32 u4BufLen;
477
478            /* @FIX ME: need a more clear way to do this */
479
480
481             rStatus = kalIoctl(prGlueInfo,
482                     wlanoidQueryXmitError,
483                     &u4XmitError,
484                     sizeof(UINT_32),
485                     TRUE,
486                     TRUE,
487                     TRUE,
488                     FALSE,
489                     &u4BufLen);
490
491            prGlueInfo->rNetDevStats.tx_errors = u4XmitError;
492
493    }
494 #else
495          prGlueInfo->rNetDevStats.tx_errors = 0;
496 #endif
497
498     sinfo->tx_failed = prGlueInfo->rNetDevStats.tx_errors;
499
500     return 0;
501 }
502
503 static PARAM_SCAN_REQUEST_EXT_T rScanRequest;
504 /*----------------------------------------------------------------------------*/
505 /*!
506  * @brief This routine is responsible for requesting to do a scan
507  *
508  * @param 
509  *
510  * @retval 0:       successful
511  *         others:  failure
512  */
513 /*----------------------------------------------------------------------------*/
514 int 
515 mtk_cfg80211_scan (
516     struct wiphy *wiphy,
517     struct net_device *ndev,
518     struct cfg80211_scan_request *request
519     )
520 {
521     P_GLUE_INFO_T prGlueInfo = NULL;
522     WLAN_STATUS rStatus;
523     UINT_32 u4BufLen;
524 //    PARAM_SCAN_REQUEST_EXT_T rScanRequest;
525
526     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
527     ASSERT(prGlueInfo);
528     
529     kalMemZero(&rScanRequest, sizeof(PARAM_SCAN_REQUEST_EXT_T));
530     
531     /* check if there is any pending scan not yet finished */
532     if(prGlueInfo->prScanRequest != NULL) {
533         return -EBUSY;
534     }
535
536     if(request->n_ssids == 0) {
537         rScanRequest.rSsid.u4SsidLen = 0;
538     }
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);
541     }
542     else {
543         return -EINVAL;
544     }
545
546     if(request->ie_len > 0) {
547         rScanRequest.u4IELength = request->ie_len;
548         rScanRequest.pucIE = (PUINT_8)(request->ie);
549     }
550     else {
551         rScanRequest.u4IELength = 0;
552     }
553
554     rStatus = kalIoctl(prGlueInfo,
555         wlanoidSetBssidListScanExt,
556         &rScanRequest,
557         sizeof(PARAM_SCAN_REQUEST_EXT_T),
558         FALSE,
559         FALSE,
560         FALSE,
561         FALSE,
562         &u4BufLen);
563
564     if (rStatus != WLAN_STATUS_SUCCESS) {
565         DBGLOG(REQ, WARN, ("scan error:%lx\n", rStatus));
566         return -EINVAL;
567     }
568
569     prGlueInfo->prScanRequest = request;
570
571     return 0;
572 }
573
574 static UINT_8 wepBuf[48];
575
576 /*----------------------------------------------------------------------------*/
577 /*!
578  * @brief This routine is responsible for requesting to connect to 
579  *        the ESS with the specified parameters
580  *
581  * @param 
582  *
583  * @retval 0:       successful
584  *         others:  failure
585  */
586 /*----------------------------------------------------------------------------*/
587 int
588 mtk_cfg80211_connect (
589     struct wiphy *wiphy,
590     struct net_device *ndev,
591     struct cfg80211_connect_params *sme
592     )
593 {
594     P_GLUE_INFO_T prGlueInfo = NULL;
595     WLAN_STATUS rStatus;
596     UINT_32 u4BufLen;
597     ENUM_PARAM_ENCRYPTION_STATUS_T eEncStatus;
598     ENUM_PARAM_AUTH_MODE_T eAuthMode;
599     UINT_32 cipher;
600     PARAM_SSID_T rNewSsid;
601     BOOLEAN fgCarryWPSIE = FALSE;
602     ENUM_PARAM_OP_MODE_T eOpMode;
603
604     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
605     ASSERT(prGlueInfo);
606
607     if (prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode > NET_TYPE_AUTO_SWITCH)
608                 eOpMode = NET_TYPE_AUTO_SWITCH;
609         else 
610             eOpMode = prGlueInfo->prAdapter->rWifiVar.rConnSettings.eOPMode;
611         
612         rStatus = kalIoctl(prGlueInfo,
613                 wlanoidSetInfrastructureMode,
614                 &eOpMode,
615                 sizeof(eOpMode),
616                 FALSE,
617                 FALSE,
618                 TRUE,
619                 FALSE,
620                 &u4BufLen);
621
622         if (rStatus != WLAN_STATUS_SUCCESS) {
623                 DBGLOG(INIT, INFO, ("wlanoidSetInfrastructureMode fail 0x%lx\n", rStatus));
624                 return -EFAULT;
625         }
626
627         /* after set operation mode, key table are cleared */
628
629         /* reset wpa info */
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;
637 #endif
638
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;
643     else
644         prGlueInfo->rWpaInfo.u4WpaVersion = IW_AUTH_WPA_VERSION_DISABLED;
645  
646     switch (sme->auth_type) {
647     case NL80211_AUTHTYPE_OPEN_SYSTEM:
648         prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM;
649         break;
650     case NL80211_AUTHTYPE_SHARED_KEY:
651         prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_SHARED_KEY;
652         break;
653     default:
654         prGlueInfo->rWpaInfo.u4AuthAlg = IW_AUTH_ALG_OPEN_SYSTEM | IW_AUTH_ALG_SHARED_KEY;
655         break;
656     }
657
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;
663             break;
664         case WLAN_CIPHER_SUITE_WEP104:
665             prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_WEP104;
666             break;
667         case WLAN_CIPHER_SUITE_TKIP:
668             prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_TKIP;
669             break;
670         case WLAN_CIPHER_SUITE_CCMP:
671             prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
672             break;
673         case WLAN_CIPHER_SUITE_AES_CMAC:
674             prGlueInfo->rWpaInfo.u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
675             break;
676         default:
677             DBGLOG(REQ, WARN, ("invalid cipher pairwise (%d)\n",
678                    sme->crypto.ciphers_pairwise[0]));
679             return -EINVAL;
680         }
681     }
682
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;
688             break;          
689         case WLAN_CIPHER_SUITE_WEP104:
690             prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_WEP104;
691             break;
692         case WLAN_CIPHER_SUITE_TKIP:
693             prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_TKIP;
694             break;
695         case WLAN_CIPHER_SUITE_CCMP:
696             prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
697             break;
698         case WLAN_CIPHER_SUITE_AES_CMAC:
699             prGlueInfo->rWpaInfo.u4CipherGroup = IW_AUTH_CIPHER_CCMP;
700             break;
701         default:
702             DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
703                    sme->crypto.cipher_group));
704             return -EINVAL;
705         }
706     }
707
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;
714                 break;
715             case WLAN_AKM_SUITE_PSK:
716                 eAuthMode = AUTH_MODE_WPA_PSK;
717             break;
718             default:
719                 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
720                        sme->crypto.cipher_group));
721                 return -EINVAL;
722             }
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;
727             break;
728             case WLAN_AKM_SUITE_PSK:
729             eAuthMode = AUTH_MODE_WPA2_PSK;
730             break;
731             default:
732                 DBGLOG(REQ, WARN, ("invalid cipher group (%d)\n",
733                        sme->crypto.cipher_group));
734                 return -EINVAL;
735             }
736         }
737     }
738
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;
742     }
743
744     prGlueInfo->rWpaInfo.fgPrivacyInvoke = sme->privacy;
745
746     //prGlueInfo->prAdapter->rWifiVar.rConnSettings.fgWapiMode = FALSE;
747     //prGlueInfo->prAdapter->prGlueInfo->u2WapiAssocInfoIESz = 0;
748     prGlueInfo->fgWpsActive = FALSE;
749     //prGlueInfo->prAdapter->prGlueInfo->u2WSCAssocInfoIELen = 0;
750
751     if (sme->ie && sme->ie_len > 0) {
752         WLAN_STATUS rStatus;
753         UINT_32 u4BufLen;
754         PUINT_8 prDesiredIE = NULL;
755
756 #if CFG_SUPPORT_WAPI
757         rStatus = kalIoctl(prGlueInfo,
758                 wlanoidSetWapiAssocInfo,
759                 sme->ie,
760                 sme->ie_len,
761                 FALSE,
762                 FALSE,
763                 FALSE,
764                 FALSE,
765                 &u4BufLen);
766         
767         if (rStatus != WLAN_STATUS_SUCCESS) {
768             DBGLOG(SEC, WARN, ("[wapi] set wapi assoc info error:%lx\n", rStatus));
769         }
770 #endif
771 #if CFG_SUPPORT_WPS2
772         if (wextSrchDesiredWPSIE(sme->ie,
773                     sme->ie_len,
774                     0xDD,
775                     (PUINT_8 *)&prDesiredIE)) {
776             prGlueInfo->fgWpsActive = TRUE;
777             fgCarryWPSIE = TRUE;
778
779             rStatus = kalIoctl(prGlueInfo,
780                     wlanoidSetWSCAssocInfo,
781                     prDesiredIE,
782                     IE_SIZE(prDesiredIE),
783                     FALSE,
784                     FALSE,
785                     FALSE,
786                     FALSE,
787                     &u4BufLen);
788             if (rStatus != WLAN_STATUS_SUCCESS) {
789                 DBGLOG(SEC, WARN, ("WSC] set WSC assoc info error:%lx\n", rStatus));
790             }
791         }
792 #endif
793     }
794
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;
799     }
800
801     rStatus = kalIoctl(prGlueInfo,
802             wlanoidSetAuthMode,
803             &eAuthMode,
804             sizeof(eAuthMode),
805             FALSE,
806             FALSE,
807             FALSE,
808             FALSE,
809             &u4BufLen);
810     if (rStatus != WLAN_STATUS_SUCCESS) {
811         DBGLOG(REQ, WARN, ("set auth mode error:%lx\n", rStatus));
812     }
813
814     cipher = prGlueInfo->rWpaInfo.u4CipherGroup | prGlueInfo->rWpaInfo.u4CipherPairwise;
815
816     if (prGlueInfo->rWpaInfo.fgPrivacyInvoke) {
817         if (cipher & IW_AUTH_CIPHER_CCMP) {
818             eEncStatus = ENUM_ENCRYPTION3_ENABLED;
819         }
820         else if (cipher & IW_AUTH_CIPHER_TKIP) {
821             eEncStatus = ENUM_ENCRYPTION2_ENABLED;
822         }
823         else if (cipher & (IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_WEP40)) {
824             eEncStatus = ENUM_ENCRYPTION1_ENABLED;
825         }
826         else if (cipher & IW_AUTH_CIPHER_NONE){
827             if (prGlueInfo->rWpaInfo.fgPrivacyInvoke)
828                 eEncStatus = ENUM_ENCRYPTION1_ENABLED;
829             else
830                 eEncStatus = ENUM_ENCRYPTION_DISABLED;
831         }
832         else {
833             eEncStatus = ENUM_ENCRYPTION_DISABLED;
834         }
835     }
836     else {
837         eEncStatus = ENUM_ENCRYPTION_DISABLED;
838     }
839     
840     rStatus = kalIoctl(prGlueInfo,
841             wlanoidSetEncryptionStatus,
842             &eEncStatus,
843             sizeof(eEncStatus),
844             FALSE,
845             FALSE,
846             FALSE,
847             FALSE,
848             &u4BufLen);
849     if (rStatus != WLAN_STATUS_SUCCESS) {
850         DBGLOG(REQ, WARN, ("set encryption mode error:%lx\n", rStatus));
851     }
852
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;
855         
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));
863             return -EINVAL;
864         }
865         kalMemCopy(prWepKey->aucKeyMaterial, sme->key, prWepKey->u4KeyLength);
866
867         rStatus = kalIoctl(prGlueInfo,
868                      wlanoidSetAddWep,
869                      prWepKey,
870                      prWepKey->u4Length,
871                      FALSE,
872                      FALSE,
873                      TRUE,
874                      FALSE,
875                      &u4BufLen);
876         
877         if (rStatus != WLAN_STATUS_SUCCESS) {
878             DBGLOG(INIT, INFO, ("wlanoidSetAddWep fail 0x%lx\n", rStatus));
879             return -EFAULT;
880         }
881     }
882
883     if(sme->ssid_len > 0) {
884         /* connect by SSID */
885         COPY_SSID(rNewSsid.aucSsid, rNewSsid.u4SsidLen, sme->ssid, sme->ssid_len);
886
887         rStatus = kalIoctl(prGlueInfo,
888                 wlanoidSetSsid,
889                 (PVOID) &rNewSsid,
890                 sizeof(PARAM_SSID_T),
891                 FALSE,
892                 FALSE,
893                 TRUE,
894                 FALSE,
895                 &u4BufLen);
896
897         if (rStatus != WLAN_STATUS_SUCCESS) {
898             DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
899             return -EINVAL;
900         }
901     }
902     else {
903         /* connect by BSSID */
904         rStatus = kalIoctl(prGlueInfo,
905                 wlanoidSetBssid,
906                 (PVOID) sme->bssid,
907                 sizeof(MAC_ADDR_LEN),
908                 FALSE,
909                 FALSE,
910                 TRUE,
911                 FALSE,
912                 &u4BufLen);
913
914         if (rStatus != WLAN_STATUS_SUCCESS) {
915             DBGLOG(REQ, WARN, ("set BSSID:%lx\n", rStatus));
916             return -EINVAL;
917         }
918     }
919
920     return 0;
921 }
922
923
924 /*----------------------------------------------------------------------------*/
925 /*!
926  * @brief This routine is responsible for requesting to disconnect from
927  *        currently connected ESS
928  *
929  * @param 
930  *
931  * @retval 0:       successful
932  *         others:  failure
933  */
934 /*----------------------------------------------------------------------------*/
935 int 
936 mtk_cfg80211_disconnect (
937     struct wiphy *wiphy,
938     struct net_device *ndev,
939     u16 reason_code
940     )
941 {
942     P_GLUE_INFO_T prGlueInfo = NULL;
943     WLAN_STATUS rStatus;
944     UINT_32 u4BufLen;
945
946     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
947     ASSERT(prGlueInfo);
948
949     rStatus = kalIoctl(prGlueInfo,
950         wlanoidSetDisassociate,
951         NULL,
952         0,
953         FALSE,
954         FALSE,
955         TRUE,
956         FALSE,
957         &u4BufLen);
958
959     if (rStatus != WLAN_STATUS_SUCCESS) {
960         DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
961         return -EFAULT;
962     }
963
964     return 0;
965 }
966
967
968 /*----------------------------------------------------------------------------*/
969 /*!
970  * @brief This routine is responsible for requesting to join an IBSS group
971  *
972  * @param 
973  *
974  * @retval 0:       successful
975  *         others:  failure
976  */
977 /*----------------------------------------------------------------------------*/
978 int
979 mtk_cfg80211_join_ibss (
980     struct wiphy *wiphy,
981     struct net_device *ndev,
982     struct cfg80211_ibss_params *params
983     )
984 {
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;
989     WLAN_STATUS rStatus;
990
991     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
992     ASSERT(prGlueInfo);
993
994     /* set channel */
995     if(params->channel) {
996         u4ChnlFreq = nicChannelNum2Freq(params->channel->hw_value);
997
998         rStatus = kalIoctl(prGlueInfo,
999                            wlanoidSetFrequency,
1000                            &u4ChnlFreq,
1001                            sizeof(u4ChnlFreq),
1002                            FALSE,
1003                            FALSE,
1004                            FALSE,
1005                            FALSE,
1006                            &u4BufLen);
1007         if (rStatus != WLAN_STATUS_SUCCESS) {
1008             return -EFAULT;
1009         }
1010     }
1011
1012     /* set SSID */
1013     kalMemCopy(rNewSsid.aucSsid, params->ssid, params->ssid_len);
1014     rStatus = kalIoctl(prGlueInfo,
1015             wlanoidSetSsid,
1016             (PVOID) &rNewSsid,
1017             sizeof(PARAM_SSID_T),
1018             FALSE,
1019             FALSE,
1020             TRUE,
1021             FALSE,
1022             &u4BufLen);
1023
1024     if (rStatus != WLAN_STATUS_SUCCESS) {
1025         DBGLOG(REQ, WARN, ("set SSID:%lx\n", rStatus));
1026         return -EFAULT;
1027     }
1028
1029     return 0;
1030
1031
1032     return -EINVAL;
1033 }
1034
1035
1036 /*----------------------------------------------------------------------------*/
1037 /*!
1038  * @brief This routine is responsible for requesting to leave from IBSS group
1039  *
1040  * @param 
1041  *
1042  * @retval 0:       successful
1043  *         others:  failure
1044  */
1045 /*----------------------------------------------------------------------------*/
1046 int
1047 mtk_cfg80211_leave_ibss (
1048     struct wiphy *wiphy,
1049     struct net_device *ndev
1050     )
1051 {
1052     P_GLUE_INFO_T prGlueInfo = NULL;
1053     WLAN_STATUS rStatus;
1054     UINT_32 u4BufLen;
1055
1056     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1057     ASSERT(prGlueInfo);
1058
1059     rStatus = kalIoctl(prGlueInfo,
1060         wlanoidSetDisassociate,
1061         NULL,
1062         0,
1063         FALSE,
1064         FALSE,
1065         TRUE,
1066         FALSE,
1067         &u4BufLen);
1068
1069     if (rStatus != WLAN_STATUS_SUCCESS) {
1070         DBGLOG(REQ, WARN, ("disassociate error:%lx\n", rStatus));
1071         return -EFAULT;
1072     }
1073
1074     return 0;
1075 }
1076
1077
1078 /*----------------------------------------------------------------------------*/
1079 /*!
1080  * @brief This routine is responsible for requesting to configure 
1081  *        WLAN power managemenet
1082  *
1083  * @param 
1084  *
1085  * @retval 0:       successful
1086  *         others:  failure
1087  */
1088 /*----------------------------------------------------------------------------*/
1089 int
1090 mtk_cfg80211_set_power_mgmt (
1091     struct wiphy *wiphy,
1092     struct net_device *ndev,
1093     bool enabled,
1094     int timeout
1095     )
1096 {
1097     P_GLUE_INFO_T prGlueInfo = NULL;
1098     WLAN_STATUS rStatus;
1099     UINT_32 u4BufLen;
1100     PARAM_POWER_MODE ePowerMode;
1101
1102     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1103     ASSERT(prGlueInfo);
1104
1105     if(enabled) {
1106         if(timeout == -1) {
1107             ePowerMode = Param_PowerModeFast_PSP;
1108         }
1109         else {
1110             ePowerMode = Param_PowerModeMAX_PSP;
1111         }
1112     }
1113     else {
1114         ePowerMode = Param_PowerModeCAM;
1115     }
1116
1117     rStatus = kalIoctl(prGlueInfo,
1118         wlanoidSet802dot11PowerSaveProfile,
1119         &ePowerMode,
1120         sizeof(ePowerMode),
1121         FALSE,
1122         FALSE,
1123         TRUE,
1124         FALSE,
1125         &u4BufLen);
1126
1127     if (rStatus != WLAN_STATUS_SUCCESS) {
1128         DBGLOG(REQ, WARN, ("set_power_mgmt error:%lx\n", rStatus));
1129         return -EFAULT;
1130     }
1131
1132     return 0;
1133 }
1134
1135
1136 /*----------------------------------------------------------------------------*/
1137 /*!
1138  * @brief This routine is responsible for requesting to cache
1139  *        a PMKID for a BSSID
1140  *
1141  * @param 
1142  *
1143  * @retval 0:       successful
1144  *         others:  failure
1145  */
1146 /*----------------------------------------------------------------------------*/
1147 int
1148 mtk_cfg80211_set_pmksa (
1149     struct wiphy *wiphy,
1150     struct net_device *ndev,
1151     struct cfg80211_pmksa *pmksa
1152     )
1153 {
1154     P_GLUE_INFO_T prGlueInfo = NULL;
1155     WLAN_STATUS    rStatus;
1156     UINT_32        u4BufLen;
1157     P_PARAM_PMKID_T  prPmkid;
1158
1159     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1160     ASSERT(prGlueInfo);
1161
1162     prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8 + sizeof(PARAM_BSSID_INFO_T), VIR_MEM_TYPE);
1163     if (!prPmkid) {
1164         DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_ADD\n"));
1165         return -ENOMEM;
1166     }
1167     
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);
1172     
1173     rStatus = kalIoctl(prGlueInfo,
1174                  wlanoidSetPmkid,
1175                  prPmkid,
1176                  sizeof(PARAM_PMKID_T),
1177                  FALSE,
1178                  FALSE,
1179                  FALSE,
1180                  FALSE,
1181                  &u4BufLen);
1182     
1183     if (rStatus != WLAN_STATUS_SUCCESS) {
1184         DBGLOG(INIT, INFO, ("add pmkid error:%lx\n", rStatus));
1185     }
1186     kalMemFree(prPmkid, VIR_MEM_TYPE, 8 + sizeof(PARAM_BSSID_INFO_T));
1187
1188     return 0;
1189 }
1190
1191
1192 /*----------------------------------------------------------------------------*/
1193 /*!
1194  * @brief This routine is responsible for requesting to remove
1195  *        a cached PMKID for a BSSID
1196  *
1197  * @param 
1198  *
1199  * @retval 0:       successful
1200  *         others:  failure
1201  */
1202 /*----------------------------------------------------------------------------*/
1203 int
1204 mtk_cfg80211_del_pmksa (
1205     struct wiphy *wiphy,
1206     struct net_device *ndev,
1207     struct cfg80211_pmksa *pmksa
1208     )
1209 {
1210
1211     return 0;
1212 }
1213
1214
1215 /*----------------------------------------------------------------------------*/
1216 /*!
1217  * @brief This routine is responsible for requesting to flush
1218  *        all cached PMKID
1219  *
1220  * @param 
1221  *
1222  * @retval 0:       successful
1223  *         others:  failure
1224  */
1225 /*----------------------------------------------------------------------------*/
1226 int
1227 mtk_cfg80211_flush_pmksa (
1228     struct wiphy *wiphy,
1229     struct net_device *ndev
1230     )
1231 {
1232     P_GLUE_INFO_T prGlueInfo = NULL;
1233     WLAN_STATUS    rStatus;
1234     UINT_32        u4BufLen;
1235     P_PARAM_PMKID_T  prPmkid;
1236
1237     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1238     ASSERT(prGlueInfo);
1239
1240     prPmkid =(P_PARAM_PMKID_T)kalMemAlloc(8, VIR_MEM_TYPE);
1241     if (!prPmkid) {
1242         DBGLOG(INIT, INFO, ("Can not alloc memory for IW_PMKSA_FLUSH\n"));
1243         return -ENOMEM;
1244     }
1245     
1246     prPmkid->u4Length = 8;
1247     prPmkid->u4BSSIDInfoCount = 0;
1248     
1249     rStatus = kalIoctl(prGlueInfo,
1250                  wlanoidSetPmkid,
1251                  prPmkid,
1252                  sizeof(PARAM_PMKID_T),
1253                  FALSE,
1254                  FALSE,
1255                  FALSE,
1256                  FALSE,
1257                  &u4BufLen);
1258     
1259     if (rStatus != WLAN_STATUS_SUCCESS) {
1260         DBGLOG(INIT, INFO, ("flush pmkid error:%lx\n", rStatus));
1261     }
1262     kalMemFree(prPmkid, VIR_MEM_TYPE, 8);
1263
1264     return 0;
1265 }
1266
1267
1268 /*----------------------------------------------------------------------------*/
1269 /*!
1270  * @brief This routine is responsible for requesting to stay on a 
1271  *        specified channel
1272  *
1273  * @param 
1274  *
1275  * @retval 0:       successful
1276  *         others:  failure
1277  */
1278 /*----------------------------------------------------------------------------*/
1279 int 
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,
1286     u64 *cookie
1287     )
1288 {
1289     P_GLUE_INFO_T prGlueInfo = NULL;
1290
1291     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1292     ASSERT(prGlueInfo);
1293
1294
1295
1296     /* not implemented */
1297
1298     return -EINVAL;
1299 }
1300
1301
1302 /*----------------------------------------------------------------------------*/
1303 /*!
1304  * @brief This routine is responsible for requesting to cancel staying 
1305  *        on a specified channel
1306  *
1307  * @param 
1308  *
1309  * @retval 0:       successful
1310  *         others:  failure
1311  */
1312 /*----------------------------------------------------------------------------*/
1313 int
1314 mtk_cfg80211_cancel_remain_on_channel (
1315     struct wiphy *wiphy,
1316     struct net_device *ndev,
1317     u64 cookie
1318     )
1319 {
1320     P_GLUE_INFO_T prGlueInfo = NULL;
1321
1322     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1323     ASSERT(prGlueInfo);
1324
1325
1326     /* not implemented */
1327
1328     return -EINVAL;
1329 }
1330
1331
1332 /*----------------------------------------------------------------------------*/
1333 /*!
1334  * @brief This routine is responsible for requesting to send a management frame
1335  *
1336  * @param 
1337  *
1338  * @retval 0:       successful
1339  *         others:  failure
1340  */
1341 /*----------------------------------------------------------------------------*/
1342 int
1343 mtk_cfg80211_mgmt_tx (
1344     struct wiphy *wiphy,
1345     struct net_device *ndev,
1346     struct ieee80211_channel *channel,
1347     bool offscan,
1348     enum nl80211_channel_type channel_type,
1349     bool channel_type_valid,
1350     unsigned int wait,
1351     const u8 *buf,
1352     size_t len,
1353     bool no_cck,
1354     bool dont_wait_for_ack,
1355     u64 *cookie
1356     )
1357 {
1358     P_GLUE_INFO_T prGlueInfo = NULL;
1359
1360     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1361     ASSERT(prGlueInfo);
1362
1363
1364     /* not implemented */
1365
1366     return -EINVAL;
1367 }
1368
1369
1370 /*----------------------------------------------------------------------------*/
1371 /*!
1372  * @brief This routine is responsible for requesting to cancel the wait time
1373  *        from transmitting a management frame on another channel
1374  *
1375  * @param 
1376  *
1377  * @retval 0:       successful
1378  *         others:  failure
1379  */
1380 /*----------------------------------------------------------------------------*/
1381 int
1382 mtk_cfg80211_mgmt_tx_cancel_wait (
1383     struct wiphy *wiphy,
1384     struct net_device *ndev,
1385     u64 cookie
1386     )
1387 {
1388     P_GLUE_INFO_T prGlueInfo = NULL;
1389
1390     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1391     ASSERT(prGlueInfo);
1392
1393
1394     /* not implemented */
1395
1396     return -EINVAL;
1397 }
1398
1399
1400 #if CONFIG_NL80211_TESTMODE
1401
1402 #if CFG_SUPPORT_WAPI
1403 int
1404 mtk_cfg80211_testmode_set_key_ext(
1405     IN struct wiphy *wiphy,
1406     IN void *data,
1407     IN int len)
1408 {
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;
1413     int     fgIsValid = 0;
1414     UINT_32 u4BufLen = 0;
1415     
1416     P_PARAM_WPI_KEY_T prWpiKey = (P_PARAM_WPI_KEY_T) keyStructBuf;
1417     memset(keyStructBuf, 0, sizeof(keyStructBuf));
1418
1419     ASSERT(wiphy);
1420     
1421     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1422         
1423
1424     if(data && len) {
1425         prParams = (P_NL80211_DRIVER_SET_KEY_EXTS)data;
1426     }
1427     
1428     if(prParams) {
1429         prIWEncExt = (struct iw_encode_exts *) &prParams->ext;
1430     }
1431
1432     if (prIWEncExt->alg == IW_ENCODE_ALG_SMS4) {
1433         /* KeyID */
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);
1439             return -EINVAL;
1440         }
1441
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);
1445             return -EINVAL;
1446         }
1447
1448         //printk(KERN_INFO "[wapi] %d ext_flags %d\n", prEnc->flags, prIWEncExt->ext_flags);
1449
1450         if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1451             prWpiKey->eKeyType = ENUM_WPI_GROUP_KEY;
1452             prWpiKey->eDirection = ENUM_WPI_RX;
1453         }
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;
1457         }
1458
1459 //#if CFG_SUPPORT_WAPI
1460         //handle_sec_msg_final(prIWEncExt->key, 32, prIWEncExt->key, NULL);
1461 //#endif
1462         /* PN */
1463         memcpy(prWpiKey->aucPN, prIWEncExt->tx_seq, IW_ENCODE_SEQ_MAX_SIZE * 2);
1464
1465         /* BSSID */
1466         memcpy(prWpiKey->aucAddrIndex, prIWEncExt->addr, 6);
1467
1468         memcpy(prWpiKey->aucWPIEK, prIWEncExt->key, 16);
1469         prWpiKey->u4LenWPIEK = 16;
1470
1471         memcpy(prWpiKey->aucWPICK, &prIWEncExt->key[16], 16);
1472         prWpiKey->u4LenWPICK = 16;
1473
1474         rstatus = kalIoctl(prGlueInfo,
1475                      wlanoidSetWapiKey,
1476                      prWpiKey,
1477                      sizeof(PARAM_WPI_KEY_T),
1478                      FALSE,
1479                      FALSE,
1480                      TRUE,
1481                      FALSE,
1482                      &u4BufLen);
1483
1484         if (rstatus != WLAN_STATUS_SUCCESS) {
1485             //printk(KERN_INFO "[wapi] add key error:%lx\n", rStatus);
1486             fgIsValid = -EFAULT;
1487         }
1488
1489     }
1490     return fgIsValid;
1491 }
1492 #endif
1493
1494
1495 int
1496 mtk_cfg80211_testmode_sw_cmd(
1497     IN struct wiphy *wiphy,
1498     IN void *data,
1499     IN int len)
1500 {
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;
1504     int     fgIsValid = 0;
1505     UINT_32 u4SetInfoLen = 0;
1506
1507     ASSERT(wiphy);
1508
1509     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1510
1511
1512
1513     if(data && len)
1514         prParams = (P_NL80211_DRIVER_SW_CMD_PARAMS)data;
1515
1516     if(prParams) {
1517         if(prParams->set == 1){
1518             rstatus = kalIoctl(prGlueInfo,
1519                     (PFN_OID_HANDLER_FUNC)wlanoidSetSwCtrlWrite,
1520                     &prParams->adr,
1521                     (UINT_32)8,
1522                     FALSE,
1523                     FALSE,
1524                     TRUE,
1525                     FALSE,
1526                     &u4SetInfoLen);
1527         }
1528     }
1529
1530     if (WLAN_STATUS_SUCCESS != rstatus) {
1531         fgIsValid = -EFAULT;
1532     }
1533  
1534     return fgIsValid;
1535 }
1536
1537 int mtk_cfg80211_testmode_cmd(
1538     IN struct wiphy *wiphy,
1539     IN void *data,
1540     IN int len
1541     )
1542 {
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;
1546
1547     ASSERT(wiphy);
1548
1549     prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(wiphy);
1550
1551
1552
1553     if(data && len)
1554         prParams = (P_NL80211_DRIVER_TEST_MODE_PARAMS)data;
1555         
1556     /* Clear the version byte */
1557     prParams->index = prParams->index & ~ BITS(24,31);
1558     
1559     if(prParams){
1560         switch(prParams->index){
1561             case 1: /* SW cmd */
1562                 if(mtk_cfg80211_testmode_sw_cmd(wiphy, data, len))
1563                     fgIsValid = TRUE;
1564                 break;
1565             case 2: /* WAPI */
1566 #if CFG_SUPPORT_WAPI
1567                 if(mtk_cfg80211_testmode_set_key_ext(wiphy, data, len))
1568                     fgIsValid = TRUE;
1569 #endif
1570                 break;
1571             default:
1572                 fgIsValid = TRUE;
1573                 break;
1574         }
1575     }
1576
1577     return fgIsValid;
1578 }
1579 #endif
1580