Merge tag 'late-omap' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[firefly-linux-kernel-4.4.55.git] / drivers / staging / csr / sme_wext.c
1 /*
2  * ---------------------------------------------------------------------------
3  * FILE:     sme_wext.c
4  *
5  * PURPOSE:
6  *      Handlers for ioctls from iwconfig.
7  *      These provide the control plane operations.
8  *
9  * Copyright (C) 2007-2009 by Cambridge Silicon Radio Ltd.
10  *
11  * Refer to LICENSE.txt included with this source code for details on
12  * the license terms.
13  *
14  * ---------------------------------------------------------------------------
15  */
16 #include <linux/types.h>
17 #include <linux/etherdevice.h>
18 #include <linux/if_arp.h>
19 #include <asm/uaccess.h>
20 #include <linux/ctype.h>
21 #include "unifi_priv.h"
22 #include <linux/rtnetlink.h>
23
24 #define CHECK_INITED(_priv)                             \
25     do {                                                    \
26         if (_priv->init_progress != UNIFI_INIT_COMPLETED) { \
27             unifi_trace(_priv, UDBG2, "%s unifi not ready, failing wext call\n", __FUNCTION__); \
28             return -ENODEV;                                 \
29         }                                                   \
30     } while (0)
31
32 /* Workaround for the wpa_supplicant hanging issue - disabled on Android */
33 #ifndef ANDROID_BUILD
34 #define CSR_WIFI_WEXT_HANG_WORKAROUND
35 #endif
36
37 #ifdef CSR_WIFI_WEXT_HANG_WORKAROUND
38 # define UF_RTNL_LOCK()    rtnl_lock()
39 # define UF_RTNL_UNLOCK()  rtnl_unlock()
40 #else
41 # define UF_RTNL_LOCK()
42 # define UF_RTNL_UNLOCK()
43 #endif
44
45
46 /*
47  * ---------------------------------------------------------------------------
48  *      Helper functions
49  * ---------------------------------------------------------------------------
50  */
51
52 /*
53  * ---------------------------------------------------------------------------
54  *  wext_freq_to_channel
55  *  channel_to_mhz
56  *
57  *      These functions convert between channel number and frequency.
58  *
59  *  Arguments:
60  *      ch      Channel number, as defined in 802.11 specs
61  *      m, e    Mantissa and exponent as provided by wireless extension.
62  *
63  *  Returns:
64  *      channel or frequency (in MHz) value
65  * ---------------------------------------------------------------------------
66  */
67 static int
68 wext_freq_to_channel(int m, int e)
69 {
70     int mhz;
71
72     mhz = m;
73     while (e < 6) {
74         mhz /= 10;
75         e++;
76     }
77     while (e > 6) {
78         mhz *= 10;
79         e--;
80     }
81
82     if (mhz >= 5000) {
83         return ((mhz - 5000) / 5);
84     }
85
86     if (mhz == 2482) {
87         return 14;
88     }
89
90     if (mhz >= 2407) {
91         return ((mhz - 2407) / 5);
92     }
93
94     return 0;
95 } /* wext_freq_to_channel() */
96
97 static int
98 channel_to_mhz(int ch, int dot11a)
99 {
100
101     if (ch == 0) return 0;
102     if (ch > 200) return 0;
103
104     /* 5G */
105     if (dot11a) {
106         return (5000 + (5 * ch));
107     }
108
109     /* 2.4G */
110     if (ch == 14) {
111         return 2484;
112     }
113
114     if ((ch < 14) && (ch > 0)) {
115         return (2407 + (5 * ch));
116     }
117
118     return 0;
119 }
120 #ifdef CSR_SUPPORT_WEXT_AP
121 void uf_sme_wext_ap_set_defaults(unifi_priv_t *priv)
122 {
123     memcpy(priv->ap_config.ssid.ssid,"defaultssid",sizeof("defaultssid"));
124
125     priv->ap_config.ssid.length = 8;
126     priv->ap_config.channel = 6;
127     priv->ap_config.if_index = 1;
128     priv->ap_config.credentials.authType = 0;
129     priv->ap_config.max_connections=8;
130
131     priv->group_sec_config.apGroupkeyTimeout = 0;
132     priv->group_sec_config.apStrictGtkRekey = 0;
133     priv->group_sec_config.apGmkTimeout = 0;
134     priv->group_sec_config.apResponseTimeout = 100; /* Default*/
135     priv->group_sec_config.apRetransLimit = 3; /* Default*/
136     /* Set default params even if they may not be used*/
137     /* Until Here*/
138
139     priv->ap_mac_config.preamble = CSR_WIFI_SME_USE_LONG_PREAMBLE;
140     priv->ap_mac_config.shortSlotTimeEnabled = FALSE;
141     priv->ap_mac_config.ctsProtectionType=CSR_WIFI_SME_CTS_PROTECTION_AUTOMATIC;
142
143     priv->ap_mac_config.wmmEnabled = TRUE;
144     priv->ap_mac_config.wmmApParams[0].cwMin=4;
145     priv->ap_mac_config.wmmApParams[0].cwMax=10;
146     priv->ap_mac_config.wmmApParams[0].aifs=3;
147     priv->ap_mac_config.wmmApParams[0].txopLimit=0;
148     priv->ap_mac_config.wmmApParams[0].admissionControlMandatory=FALSE;
149     priv->ap_mac_config.wmmApParams[1].cwMin=4;
150     priv->ap_mac_config.wmmApParams[1].cwMax=10;
151     priv->ap_mac_config.wmmApParams[1].aifs=7;
152     priv->ap_mac_config.wmmApParams[1].txopLimit=0;
153     priv->ap_mac_config.wmmApParams[1].admissionControlMandatory=FALSE;
154     priv->ap_mac_config.wmmApParams[2].cwMin=3;
155     priv->ap_mac_config.wmmApParams[2].cwMax=4;
156     priv->ap_mac_config.wmmApParams[2].aifs=1;
157     priv->ap_mac_config.wmmApParams[2].txopLimit=94;
158     priv->ap_mac_config.wmmApParams[2].admissionControlMandatory=FALSE;
159     priv->ap_mac_config.wmmApParams[3].cwMin=2;
160     priv->ap_mac_config.wmmApParams[3].cwMax=3;
161     priv->ap_mac_config.wmmApParams[3].aifs=1;
162     priv->ap_mac_config.wmmApParams[3].txopLimit=47;
163     priv->ap_mac_config.wmmApParams[3].admissionControlMandatory=FALSE;
164
165     priv->ap_mac_config.wmmApBcParams[0].cwMin=4;
166     priv->ap_mac_config.wmmApBcParams[0].cwMax=10;
167     priv->ap_mac_config.wmmApBcParams[0].aifs=3;
168     priv->ap_mac_config.wmmApBcParams[0].txopLimit=0;
169     priv->ap_mac_config.wmmApBcParams[0].admissionControlMandatory=FALSE;
170     priv->ap_mac_config.wmmApBcParams[1].cwMin=4;
171     priv->ap_mac_config.wmmApBcParams[1].cwMax=10;
172     priv->ap_mac_config.wmmApBcParams[1].aifs=7;
173     priv->ap_mac_config.wmmApBcParams[1].txopLimit=0;
174     priv->ap_mac_config.wmmApBcParams[1].admissionControlMandatory=FALSE;
175     priv->ap_mac_config.wmmApBcParams[2].cwMin=3;
176     priv->ap_mac_config.wmmApBcParams[2].cwMax=4;
177     priv->ap_mac_config.wmmApBcParams[2].aifs=2;
178     priv->ap_mac_config.wmmApBcParams[2].txopLimit=94;
179     priv->ap_mac_config.wmmApBcParams[2].admissionControlMandatory=FALSE;
180     priv->ap_mac_config.wmmApBcParams[3].cwMin=2;
181     priv->ap_mac_config.wmmApBcParams[3].cwMax=3;
182     priv->ap_mac_config.wmmApBcParams[3].aifs=2;
183     priv->ap_mac_config.wmmApBcParams[3].txopLimit=47;
184     priv->ap_mac_config.wmmApBcParams[3].admissionControlMandatory=FALSE;
185
186     priv->ap_mac_config.accessType=CSR_WIFI_AP_ACCESS_TYPE_NONE;
187     priv->ap_mac_config.macAddressListCount=0;
188     priv->ap_mac_config.macAddressList=NULL;
189
190     priv->ap_mac_config.apHtParams.rxStbc=1;
191     priv->ap_mac_config.apHtParams.rifsModeAllowed=TRUE;
192     priv->ap_mac_config.apHtParams.greenfieldSupported=FALSE;
193     priv->ap_mac_config.apHtParams.shortGi20MHz=TRUE;
194     priv->ap_mac_config.apHtParams.htProtection=0;
195     priv->ap_mac_config.apHtParams.dualCtsProtection=FALSE;
196
197     priv->ap_mac_config.phySupportedBitmap =
198             (CSR_WIFI_SME_AP_PHY_SUPPORT_B|CSR_WIFI_SME_AP_PHY_SUPPORT_G|CSR_WIFI_SME_AP_PHY_SUPPORT_N);
199     priv->ap_mac_config.beaconInterval= 100;
200     priv->ap_mac_config.dtimPeriod=3;
201     priv->ap_mac_config.maxListenInterval=0x00ff;/* Set it to a large value
202                                                     to enable different types of
203                                                     devices to join us */
204     priv->ap_mac_config.supportedRatesCount =
205            uf_configure_supported_rates(priv->ap_mac_config.supportedRates,priv->ap_mac_config.phySupportedBitmap);
206 }
207 #endif
208 /*
209  * ---------------------------------------------------------------------------
210  *  uf_sme_wext_set_defaults
211  *
212  *      Set up power-on defaults for driver config.
213  *
214  *      Note: The SME Management API *cannot* be used in this function.
215  *
216  *  Arguments:
217  *      priv            Pointer to device private context struct
218  *
219  *  Returns:
220  *      None.
221  * ---------------------------------------------------------------------------
222  */
223 void
224 uf_sme_wext_set_defaults(unifi_priv_t *priv)
225 {
226     memset(&priv->connection_config, 0, sizeof(CsrWifiSmeConnectionConfig));
227
228     priv->connection_config.bssType = CSR_WIFI_SME_BSS_TYPE_INFRASTRUCTURE;
229     priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
230     priv->connection_config.encryptionModeMask = CSR_WIFI_SME_ENCRYPTION_CIPHER_NONE;
231     priv->connection_config.privacyMode = CSR_WIFI_SME_80211_PRIVACY_MODE_DISABLED;
232     priv->connection_config.wmmQosInfo = 0xFF;
233     priv->connection_config.ifIndex = CSR_WIFI_SME_RADIO_IF_BOTH;
234     priv->connection_config.adhocJoinOnly = FALSE;
235     priv->connection_config.adhocChannel = 6;
236
237     priv->wep_tx_key_index = 0;
238
239     priv->wext_wireless_stats.qual.qual = 0;
240     priv->wext_wireless_stats.qual.level = 0;
241     priv->wext_wireless_stats.qual.noise = 0;
242     priv->wext_wireless_stats.qual.updated = 0x70;
243 #ifdef CSR_SUPPORT_WEXT_AP
244     /* Initialize the default configuration for AP */
245     uf_sme_wext_ap_set_defaults(priv);
246 #endif
247
248
249 } /* uf_sme_wext_set_defaults() */
250
251
252 /*
253  * ---------------------------------------------------------------------------
254  *      WEXT methods
255  * ---------------------------------------------------------------------------
256  */
257
258 /*
259  * ---------------------------------------------------------------------------
260  *  unifi_giwname   - handler for SIOCGIWNAME
261  *  unifi_siwfreq   - handler for SIOCSIWFREQ
262  *  unifi_giwfreq   - handler for SIOCGIWFREQ
263  *  unifi_siwmode   - handler for SIOCSIWMODE
264  *  unifi_giwmode   - handler for SIOCGIWMODE
265  *  unifi_giwrange  - handler for SIOCGIWRANGE
266  *  unifi_siwap     - handler for SIOCSIWAP
267  *  unifi_giwap     - handler for SIOCGIWAP
268  *  unifi_siwscan   - handler for SIOCSIWSCAN
269  *  unifi_giwscan   - handler for SIOCGIWSCAN
270  *  unifi_siwessid  - handler for SIOCSIWESSID
271  *  unifi_giwessid  - handler for SIOCGIWESSID
272  *  unifi_siwencode - handler for SIOCSIWENCODE
273  *  unifi_giwencode - handler for SIOCGIWENCODE
274  *
275  *      Handler functions for IW extensions.
276  *      These are registered via the unifi_iw_handler_def struct below
277  *      and called by the generic IW driver support code.
278  *      See include/net/iw_handler.h.
279  *
280  *  Arguments:
281  *      None.
282  *
283  *  Returns:
284  *      None.
285  * ---------------------------------------------------------------------------
286  */
287 static int
288 iwprivsdefs(struct net_device *dev, struct iw_request_info *info,
289         union iwreq_data *wrqu, char *extra)
290 {
291     int r;
292     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
293     unifi_priv_t *priv = interfacePriv->privPtr;
294     CsrWifiSmeMibConfig mibConfig;
295     CsrWifiSmePowerConfig powerConfig;
296
297     unifi_trace(priv, UDBG1, "iwprivs80211defaults: reload defaults\n");
298
299     uf_sme_wext_set_defaults(priv);
300
301     /* Get, modify and set the MIB data */
302     r = sme_mgt_mib_config_get(priv, &mibConfig);
303     if (r) {
304         unifi_error(priv, "iwprivs80211defaults: Get CsrWifiSmeMibConfigValue failed.\n");
305         return r;
306     }
307     mibConfig.dot11RtsThreshold = 2347;
308     mibConfig.dot11FragmentationThreshold = 2346;
309     r = sme_mgt_mib_config_set(priv, &mibConfig);
310     if (r) {
311         unifi_error(priv, "iwprivs80211defaults: Set CsrWifiSmeMibConfigValue failed.\n");
312         return r;
313     }
314
315     powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_LOW;
316     powerConfig.listenIntervalTu = 100;
317     powerConfig.rxDtims = 1;
318
319     r = sme_mgt_power_config_set(priv, &powerConfig);
320     if (r) {
321         unifi_error(priv, "iwprivs80211defaults: Set unifi_PowerConfigValue failed.\n");
322         return r;
323     }
324
325     return 0;
326 } /* iwprivsdefs() */
327
328 static int
329 iwprivs80211ps(struct net_device *dev, struct iw_request_info *info,
330         union iwreq_data *wrqu, char *extra)
331 {
332     int r = 0;
333     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
334     unifi_priv_t *priv = interfacePriv->privPtr;
335
336     int ps_mode = (int)(*extra);
337     CsrWifiSmePowerConfig powerConfig;
338
339     unifi_trace(priv, UDBG1, "iwprivs80211ps: power save mode = %d\n", ps_mode);
340
341     r = sme_mgt_power_config_get(priv, &powerConfig);
342     if (r) {
343         unifi_error(priv, "iwprivs80211ps: Get unifi_PowerConfigValue failed.\n");
344         return r;
345     }
346
347     switch (ps_mode) {
348         case CSR_PMM_ACTIVE_MODE:
349             powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_LOW;
350             break;
351         case CSR_PMM_POWER_SAVE:
352             powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_HIGH;
353             break;
354         case CSR_PMM_FAST_POWER_SAVE:
355             powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_MED;
356             break;
357         default:
358             powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_AUTO;
359             break;
360     }
361
362     r = sme_mgt_power_config_set(priv, &powerConfig);
363     if (r) {
364         unifi_error(priv, "iwprivs80211ps: Set unifi_PowerConfigValue failed.\n");
365     }
366
367     return r;
368 }
369
370 static int
371 iwprivg80211ps(struct net_device *dev, struct iw_request_info *info,
372         union iwreq_data *wrqu, char *extra)
373 {
374     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
375     unifi_priv_t *priv = interfacePriv->privPtr;
376
377     CsrWifiSmePowerConfig powerConfig;
378     int r;
379
380     r = sme_mgt_power_config_get(priv, &powerConfig);
381     if (r) {
382         unifi_error(priv, "iwprivg80211ps: Get 802.11 power mode failed.\n");
383         return r;
384     }
385
386     switch (powerConfig.powerSaveLevel) {
387         case CSR_WIFI_SME_POWER_SAVE_LEVEL_LOW:
388             snprintf(extra, IWPRIV_POWER_SAVE_MAX_STRING,
389                      "Power save mode: %d (Active)",
390                      powerConfig.powerSaveLevel);
391             break;
392         case CSR_WIFI_SME_POWER_SAVE_LEVEL_MED:
393             snprintf(extra, IWPRIV_POWER_SAVE_MAX_STRING,
394                      "Power save mode: %d (Fast)",
395                      powerConfig.powerSaveLevel);
396             break;
397         case CSR_WIFI_SME_POWER_SAVE_LEVEL_HIGH:
398             snprintf(extra, IWPRIV_POWER_SAVE_MAX_STRING,
399                      "Power save mode: %d (Full)",
400                      powerConfig.powerSaveLevel);
401             break;
402         case CSR_WIFI_SME_POWER_SAVE_LEVEL_AUTO:
403             snprintf(extra, IWPRIV_POWER_SAVE_MAX_STRING,
404                      "Power save mode: %d (Auto)",
405                      powerConfig.powerSaveLevel);
406             break;
407         default:
408             snprintf(extra, IWPRIV_POWER_SAVE_MAX_STRING,
409                      "Power save mode: %d (Unknown)",
410                      powerConfig.powerSaveLevel);
411             break;
412     }
413
414     wrqu->data.length = strlen(extra) + 1;
415
416     return 0;
417 }
418
419 static int
420 iwprivssmedebug(struct net_device *dev, struct iw_request_info *info,
421         union iwreq_data *wrqu, char *extra)
422 {
423     /* No longer supported on the API */
424 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE)
425     unifi_debug_buf_dump();
426 #endif
427
428     return 0;
429 }
430
431 #ifdef CSR_SUPPORT_WEXT_AP
432 #define PARAM_TYPE_INT 0
433 #define PARAM_TYPE_STRING 1
434 #define CSR_WIFI_MAX_SSID_LEN 32
435 #define CSR_WIFI_MAX_SEC_LEN 16
436 #define CSR_WIFI_MAX_KEY_LEN 65
437
438 static int hex_look_up(char x)
439 {
440     if(x>='0' && x<='9')
441         return (x-48);
442     if(x>= 'a' && x <= 'f')
443         return (x-87);
444     return -1;
445 }
446
447 static int power (int a, int b)
448 {
449     int i;
450     int num =1;
451     for(i=0;i<b;i++)
452        num *=a;
453     return num;
454 }
455
456 static int decode_parameter_from_string(unifi_priv_t* priv, char **str_ptr,
457                                         const char *token, int param_type,
458                                         void  *dst, int param_max_len)
459 {
460     u8 int_str[7] = "0";
461     u32 param_str_len;
462     u8  *param_str_begin,*param_str_end;
463     u8  *orig_str = *str_ptr;
464
465     if (!strncmp(*str_ptr, token, strlen(token))) {
466         strsep(str_ptr, "=,");
467         param_str_begin = *str_ptr;
468         strsep(str_ptr, "=,");
469         if (*str_ptr == NULL) {
470             param_str_len = strlen(param_str_begin);
471         } else {
472             param_str_end = *str_ptr-1;
473             param_str_len = param_str_end - param_str_begin;
474         }
475         unifi_trace(priv,UDBG2,"'token:%s', len:%d, ", token, param_str_len);
476         if (param_str_len > param_max_len) {
477             unifi_notice(priv,"extracted param len:%d is > MAX:%d\n",param_str_len, param_max_len);
478             param_str_len = param_max_len;
479         }
480         switch (param_type) {
481             case PARAM_TYPE_INT:
482             {
483                 u32 *pdst_int = dst,num =0;
484                 int i,j=0;
485                 if (param_str_len > sizeof(int_str)) {
486                     param_str_len = sizeof(int_str);
487                 }
488                 memcpy(int_str, param_str_begin, param_str_len);
489                 for(i = param_str_len; i>0;i--) {
490                     if(int_str[i-1] >= '0' && int_str[i-1] <='9') {
491                         num += ((int_str[i-1]-'0')*power(10,j));
492                         j++;
493                     } else {
494                         unifi_error(priv,"decode_parameter_from_string:not a number %c\n",(int_str[i-1]));
495                         return -1;
496                     }
497                 }
498                 *pdst_int = num;
499                 unifi_trace(priv,UDBG2,"decode_parameter_from_string:decoded int = %d\n",*pdst_int);
500             }
501             break;
502             default:
503                 memcpy(dst, param_str_begin, param_str_len);
504                 *((char *)dst + param_str_len) = 0;
505                 unifi_trace(priv,UDBG2,"decode_parameter_from_string:decoded string = %s\n",(char *)dst);
506             break;
507         }
508     } else {
509         unifi_error(priv,"decode_parameter_from_string: Token:%s not found in %s \n",token,orig_str);
510         return -1;
511     }
512     return 0;
513 }
514 static int store_ap_advanced_config_from_string(unifi_priv_t *priv, char *param_str)
515 {
516     char * str_ptr=param_str;
517     int ret = 0,tmp_var;
518     char phy_mode[6];
519     CsrWifiSmeApMacConfig * ap_mac_config = &priv->ap_mac_config;
520
521     /* Check for BI */
522     ret = decode_parameter_from_string(priv, &str_ptr, "BI=",
523                                        PARAM_TYPE_INT, &tmp_var, 5);
524     if(ret) {
525         unifi_error(priv,"store_ap_advanced_config_from_string: BI not found\n");
526         return -1;
527     }
528     ap_mac_config->beaconInterval = tmp_var;
529     ret = decode_parameter_from_string(priv, &str_ptr, "DTIM_PER=",
530                                         PARAM_TYPE_INT, &tmp_var, 5);
531     if(ret) {
532         unifi_error(priv,"store_ap_advanced_config_from_string: DTIM_PER not found\n");
533         return -1;
534     }
535     ap_mac_config->dtimPeriod = tmp_var;
536     ret = decode_parameter_from_string(priv, &str_ptr, "WMM=",
537                                         PARAM_TYPE_INT, &tmp_var, 5);
538     if(ret) {
539         unifi_error(priv,"store_ap_advanced_config_from_string: WMM not found\n");
540         return -1;
541     }
542     ap_mac_config->wmmEnabled = tmp_var;
543     ret = decode_parameter_from_string(priv, &str_ptr, "PHY=",
544                                         PARAM_TYPE_STRING, phy_mode, 5);
545     if(ret) {
546         unifi_error(priv,"store_ap_advanced_config_from_string: PHY not found\n");
547     } else {
548        if(strstr(phy_mode,"b")){
549            ap_mac_config->phySupportedBitmap = CSR_WIFI_SME_AP_PHY_SUPPORT_B;
550        }
551        if(strstr(phy_mode,"g")) {
552            ap_mac_config->phySupportedBitmap |= CSR_WIFI_SME_AP_PHY_SUPPORT_G;
553        }
554        if(strstr(phy_mode,"n")) {
555            ap_mac_config->phySupportedBitmap |= CSR_WIFI_SME_AP_PHY_SUPPORT_N;
556        }
557        ap_mac_config->supportedRatesCount =
558        uf_configure_supported_rates(ap_mac_config->supportedRates, ap_mac_config->phySupportedBitmap);
559     }
560     return ret;
561 }
562
563 static int store_ap_config_from_string( unifi_priv_t * priv,char *param_str)
564
565 {
566     char *str_ptr = param_str;
567     char sub_cmd[16];
568     char sec[CSR_WIFI_MAX_SEC_LEN];
569     char key[CSR_WIFI_MAX_KEY_LEN];
570     int ret = 0,tmp_var;
571     CsrWifiSmeApConfig_t *ap_config = &priv->ap_config;
572     CsrWifiSmeApMacConfig * ap_mac_config = &priv->ap_mac_config;
573     memset(sub_cmd, 0, sizeof(sub_cmd));
574     if(!strstr(param_str,"END")) {
575         unifi_error(priv,"store_ap_config_from_string:Invalid config string:%s\n",param_str);
576         return -1;
577     }
578     if (decode_parameter_from_string(priv,&str_ptr, "ASCII_CMD=",
579         PARAM_TYPE_STRING, sub_cmd, 6) != 0) {
580          return -1;
581     }
582     if (strncmp(sub_cmd, "AP_CFG", 6)) {
583
584         if(!strncmp(sub_cmd ,"ADVCFG", 6)) {
585            return store_ap_advanced_config_from_string(priv, str_ptr);
586         }
587         unifi_error(priv,"store_ap_config_from_string: sub_cmd:%s != 'AP_CFG or ADVCFG'!\n", sub_cmd);
588         return -1;
589     }
590     memset(ap_config, 0, sizeof(CsrWifiSmeApConfig_t));
591     ret = decode_parameter_from_string(priv,&str_ptr, "SSID=",
592                                        PARAM_TYPE_STRING, ap_config->ssid.ssid,
593                                        CSR_WIFI_MAX_SSID_LEN);
594     if(ret) {
595         unifi_error(priv,"store_ap_config_from_string: SSID not found\n");
596         return -1;
597     }
598     ap_config->ssid.length = strlen(ap_config->ssid.ssid);
599
600     ret = decode_parameter_from_string(priv, &str_ptr, "SEC=",
601                                        PARAM_TYPE_STRING, sec, CSR_WIFI_MAX_SEC_LEN);
602     if(ret) {
603         unifi_error(priv,"store_ap_config_from_string: SEC not found\n");
604         return -1;
605     }
606     ret = decode_parameter_from_string(priv,&str_ptr, "KEY=",
607                          PARAM_TYPE_STRING,  key, CSR_WIFI_MAX_KEY_LEN);
608     if(!strcasecmp(sec,"open")) {
609         unifi_trace(priv,UDBG2,"store_ap_config_from_string: security open");
610         ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_OPEN_SYSTEM;
611         if(ret) {
612             unifi_notice(priv,"store_ap_config_from_string: KEY not found:fine with Open\n");
613         }
614     }
615     else if(!strcasecmp(sec,"wpa2-psk")) {
616         int i,j=0;
617         CsrWifiNmeApAuthPers *pers =
618                             ((CsrWifiNmeApAuthPers *)&(ap_config->credentials.nmeAuthType.authTypePersonal));
619         u8 *psk = pers->authPers_credentials.psk.psk;
620
621         unifi_trace(priv,UDBG2,"store_ap_config_from_string: security WPA2");
622         if(ret) {
623             unifi_error(priv,"store_ap_config_from_string: KEY not found for WPA2\n");
624             return -1;
625         }
626         ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_PERSONAL;
627         pers->authSupport = CSR_WIFI_SME_RSN_AUTH_WPA2PSK;
628         pers->rsnCapabilities =0;
629         pers->wapiCapabilities =0;
630         pers->pskOrPassphrase=CSR_WIFI_NME_AP_CREDENTIAL_TYPE_PSK;
631         pers->authPers_credentials.psk.encryptionMode =
632                  (CSR_WIFI_NME_ENCRYPTION_CIPHER_PAIRWISE_CCMP |CSR_WIFI_NME_ENCRYPTION_CIPHER_GROUP_CCMP) ;
633         for(i=0;i<32;i++){
634            psk[i] = (16*hex_look_up(key[j]))+hex_look_up(key[j+1]);
635            j+=2;
636         }
637
638     } else {
639        unifi_notice(priv,"store_ap_config_from_string: Unknown security: Assuming Open");
640        ap_config->credentials.authType = CSR_WIFI_SME_AP_AUTH_TYPE_OPEN_SYSTEM;
641        return -1;
642     }
643    /* Get the decoded value in a temp int variable to ensure that other fields within the struct
644       which are of type other than int are not over written */
645     ret = decode_parameter_from_string(priv,&str_ptr, "CHANNEL=", PARAM_TYPE_INT, &tmp_var, 5);
646     if(ret)
647         return -1;
648     ap_config->channel = tmp_var;
649     ret = decode_parameter_from_string(priv,&str_ptr, "PREAMBLE=", PARAM_TYPE_INT, &tmp_var, 5);
650     if(ret)
651         return -1;
652     ap_mac_config->preamble = tmp_var;
653     ret = decode_parameter_from_string(priv,&str_ptr, "MAX_SCB=", PARAM_TYPE_INT,  &tmp_var, 5);
654     ap_config->max_connections = tmp_var;
655     return ret;
656 }
657
658 static int
659 iwprivsapstart(struct net_device *dev, struct iw_request_info *info,
660                union iwreq_data *wrqu, char *extra)
661 {
662     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
663     unifi_priv_t *priv = interfacePriv->privPtr;
664     int r;
665
666     unifi_trace(priv, UDBG1, "iwprivsapstart\n" );
667     r = sme_ap_start(priv,interfacePriv->InterfaceTag,&priv->ap_config);
668     if(r) {
669         unifi_error(priv,"iwprivsapstart AP START failed : %d\n",-r);
670     }
671     return r;
672 }
673
674 static int
675 iwprivsapconfig(struct net_device *dev, struct iw_request_info *info,
676                 union iwreq_data *wrqu, char *extra)
677 {
678     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
679     unifi_priv_t *priv = interfacePriv->privPtr;
680     char  *cfg_str = NULL;
681     int r;
682
683     unifi_trace(priv, UDBG1, "iwprivsapconfig\n" );
684     if (wrqu->data.length != 0) {
685         char *str;
686         if (!(cfg_str = kmalloc(wrqu->data.length+1, GFP_KERNEL)))
687         {
688             return -ENOMEM;
689         }
690         if (copy_from_user(cfg_str, wrqu->data.pointer, wrqu->data.length)) {
691             kfree(cfg_str);
692             return -EFAULT;
693         }
694         cfg_str[wrqu->data.length] = 0;
695         unifi_trace(priv,UDBG2,"length:%d\n",wrqu->data.length);
696         unifi_trace(priv,UDBG2,"AP configuration string:%s\n",cfg_str);
697         str = cfg_str;
698        if ((r = store_ap_config_from_string(priv,str))) {
699            unifi_error(priv, "iwprivsapconfig:Failed  to decode the string %d\n",r);
700            kfree(cfg_str);
701            return -EIO;
702
703        }
704     } else {
705         unifi_error(priv,"iwprivsapconfig argument length = 0 \n");
706         return -EIO;
707     }
708     r = sme_ap_config(priv, &priv->ap_mac_config, &priv->group_sec_config);
709     if(r) {
710         unifi_error(priv,"iwprivsapstop AP Config failed : %d\n",-r);
711     } else if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
712         interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
713         unifi_trace(priv, UDBG1, "iwprivsapconfig: Starting the AP");
714         r = sme_ap_start(priv,interfacePriv->InterfaceTag,&priv->ap_config);
715         if(r) {
716             unifi_error(priv,"iwprivsapstart AP START failed : %d\n",-r);
717         }
718     }
719     kfree(cfg_str);
720     return r;
721 }
722
723 static int
724 iwprivsapstop(struct net_device *dev, struct iw_request_info *info,
725         union iwreq_data *wrqu, char *extra)
726 {
727     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
728     unifi_priv_t *priv = interfacePriv->privPtr;
729     int r;
730     u16 interface_tag = interfacePriv->InterfaceTag;
731
732     unifi_trace(priv, UDBG1, "iwprivsapstop\n" );
733     r = sme_ap_stop(priv,interface_tag);
734     if(r) {
735         unifi_error(priv,"iwprivsapstop AP STOP failed : %d\n",-r);
736     }
737     return r;
738 }
739
740 #ifdef ANDROID_BUILD
741 static int
742 iwprivsapfwreload(struct net_device *dev, struct iw_request_info *info,
743                   union iwreq_data *wrqu, char *extra)
744 {
745     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
746     unifi_priv_t *priv = interfacePriv->privPtr;
747
748     unifi_trace(priv, UDBG1, "iwprivsapfwreload\n" );
749     return 0;
750 }
751
752 static int
753 iwprivsstackstart(struct net_device *dev, struct iw_request_info *info,
754         union iwreq_data *wrqu, char *extra)
755 {
756     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
757     unifi_priv_t *priv = interfacePriv->privPtr;
758     unifi_trace(priv, UDBG1, "iwprivsstackstart\n" );
759     return 0;
760 }
761
762 static int
763 iwprivsstackstop(struct net_device *dev, struct iw_request_info *info,
764         union iwreq_data *wrqu, char *extra)
765 {
766     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
767     unifi_priv_t *priv = interfacePriv->privPtr;
768     int r = 0;
769     u16 interface_tag = interfacePriv->InterfaceTag;
770
771     unifi_trace(priv, UDBG1, "iwprivsstackstop\n" );
772
773     switch(interfacePriv->interfaceMode) {
774         case CSR_WIFI_ROUTER_CTRL_MODE_STA:
775         case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
776         case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
777             r = sme_mgt_disconnect(priv);
778             break;
779         case CSR_WIFI_ROUTER_CTRL_MODE_AP:
780         case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
781             r = sme_ap_stop(priv,interface_tag);
782             break;
783         default :
784             break;
785     }
786
787     if(r) {
788         unifi_error(priv,"iwprivsstackstop Stack stop failed : %d\n",-r);
789     }
790     return 0;
791 }
792 #endif /* ANDROID_BUILD */
793 #endif /* CSR_SUPPORT_WEXT_AP */
794
795 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
796 static int
797 iwprivsconfwapi(struct net_device *dev, struct iw_request_info *info,
798         union iwreq_data *wrqu, char *extra)
799 {
800     u8 enable;
801     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
802     unifi_priv_t *priv = interfacePriv->privPtr;
803
804     unifi_trace(priv, UDBG1, "iwprivsconfwapi\n" );
805
806     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
807        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
808        unifi_error(priv, "iwprivsconfwapi: not permitted in Mode %d\n",
809                                       interfacePriv->interfaceMode);
810        return -EPERM;
811     }
812
813     enable = *(u8*)(extra);
814
815     if (enable) {
816         priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
817         priv->connection_config.authModeMask |= (CSR_WIFI_SME_AUTH_MODE_WAPI_WAIPSK | CSR_WIFI_SME_AUTH_MODE_WAPI_WAI);
818         priv->connection_config.encryptionModeMask |=
819             CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_SMS4 | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_SMS4;
820     } else {
821         priv->connection_config.authModeMask &= ~(CSR_WIFI_SME_AUTH_MODE_WAPI_WAIPSK | CSR_WIFI_SME_AUTH_MODE_WAPI_WAI);
822         priv->connection_config.encryptionModeMask &=
823             ~(CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_SMS4 | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_SMS4);
824     }
825
826     return 0;
827 }
828
829 static int
830 iwprivswpikey(struct net_device *dev, struct iw_request_info *info,
831         union iwreq_data *wrqu, char *extra)
832 {
833     int r = 0, i;
834     CsrWifiSmeKey key;
835     unifiio_wapi_key_t inKey;
836     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
837     unifi_priv_t *priv = interfacePriv->privPtr;
838
839     unifi_trace(priv, UDBG1, "iwprivswpikey\n" );
840
841     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
842        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
843        unifi_error(priv, "iwprivswpikey: not permitted in Mode %d\n",
844                                       interfacePriv->interfaceMode);
845        return -EPERM;
846     }
847
848     inKey = *(unifiio_wapi_key_t*)(extra);
849
850     if (inKey.unicastKey) {
851         key.keyType   = CSR_WIFI_SME_KEY_TYPE_PAIRWISE;
852     } else {
853         key.keyType   = CSR_WIFI_SME_KEY_TYPE_GROUP;
854     }
855
856     key.keyIndex  = inKey.keyIndex;
857
858     /* memcpy(key.keyRsc, inKey.keyRsc, 16); */
859     for (i = 0; i < 16; i+= 2)
860     {
861         key.keyRsc[i/2] = inKey.keyRsc[i+1] << 8 | inKey.keyRsc[i];
862     }
863
864     memcpy(key.address.a, inKey.address, 6);
865     key.keyLength = 32;
866     memcpy(key.key, inKey.key, 32);
867     key.authenticator = 0;
868     key.wepTxKey = 0;
869
870     unifi_trace(priv, UDBG1, "keyType = %d, keyIndex = %d, wepTxKey = %d, keyRsc = %x:%x, auth = %d, address = %x:%x, "
871                 "keylength = %d, key = %x:%x\n", key.keyType, key.keyIndex, key.wepTxKey,
872                 key.keyRsc[0], key.keyRsc[7], key.authenticator,
873                 key.address.a[0], key.address.a[5], key.keyLength, key.key[0],
874                 key.key[15]);
875
876     r = sme_mgt_key(priv, &key, CSR_WIFI_SME_LIST_ACTION_ADD);
877     if (r) {
878         unifi_error(priv, "SETKEYS request was rejected with result %d\n", r);
879         return convert_sme_error(r);
880     }
881
882     return r;
883 }
884 #endif
885
886
887 static int
888 unifi_giwname(struct net_device *dev, struct iw_request_info *info,
889         union iwreq_data *wrqu, char *extra)
890 {
891     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
892     unifi_priv_t *priv = interfacePriv->privPtr;
893     char *name = wrqu->name;
894     unifi_trace(priv, UDBG2, "unifi_giwname\n");
895
896     if (priv->if_index == CSR_INDEX_5G) {
897         strcpy(name, "IEEE 802.11-a");
898     } else {
899         strcpy(name, "IEEE 802.11-bgn");
900     }
901     return 0;
902 } /* unifi_giwname() */
903
904
905 static int
906 unifi_siwfreq(struct net_device *dev, struct iw_request_info *info,
907         union iwreq_data *wrqu, char *extra)
908 {
909     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
910     unifi_priv_t *priv = interfacePriv->privPtr;
911     struct iw_freq *freq = (struct iw_freq *)wrqu;
912
913     unifi_trace(priv, UDBG2, "unifi_siwfreq\n");
914
915     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
916        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
917        unifi_error(priv, "unifi_siwfreq: not permitted in Mode %d\n",
918                                       interfacePriv->interfaceMode);
919        return -EPERM;
920     }
921
922
923     /*
924      * Channel is stored in the connection configuration,
925      * and set later when ask for a connection.
926      */
927     if ((freq->e == 0) && (freq->m <= 1000)) {
928         priv->connection_config.adhocChannel = freq->m;
929     } else {
930         priv->connection_config.adhocChannel = wext_freq_to_channel(freq->m, freq->e);
931     }
932
933     return 0;
934 } /* unifi_siwfreq() */
935
936
937 static int
938 unifi_giwfreq(struct net_device *dev, struct iw_request_info *info,
939         union iwreq_data *wrqu, char *extra)
940 {
941     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
942     unifi_priv_t *priv = interfacePriv->privPtr;
943     struct iw_freq *freq = (struct iw_freq *)wrqu;
944     int err = 0;
945     CsrWifiSmeConnectionInfo connectionInfo;
946
947     unifi_trace(priv, UDBG2, "unifi_giwfreq\n");
948     CHECK_INITED(priv);
949
950     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
951        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
952        unifi_error(priv, "unifi_giwfreq: not permitted in Mode %d\n",
953                                       interfacePriv->interfaceMode);
954        return -EPERM;
955     }
956
957
958     UF_RTNL_UNLOCK();
959     err = sme_mgt_connection_info_get(priv, &connectionInfo);
960     UF_RTNL_LOCK();
961
962     freq->m = channel_to_mhz(connectionInfo.channelNumber,
963             (connectionInfo.networkType80211 == CSR_WIFI_SME_RADIO_IF_GHZ_5_0));
964     freq->e = 6;
965
966     return convert_sme_error(err);
967 } /* unifi_giwfreq() */
968
969
970 static int
971 unifi_siwmode(struct net_device *dev, struct iw_request_info *info,
972         union iwreq_data *wrqu, char *extra)
973 {
974     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
975     unifi_priv_t *priv = interfacePriv->privPtr;
976
977     unifi_trace(priv, UDBG2, "unifi_siwmode\n");
978
979     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
980        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
981        unifi_error(priv, "unifi_siwmode: not permitted in Mode %d\n",
982                                       interfacePriv->interfaceMode);
983        return -EPERM;
984     }
985
986
987     switch(wrqu->mode) {
988         case IW_MODE_ADHOC:
989             priv->connection_config.bssType = CSR_WIFI_SME_BSS_TYPE_ADHOC;
990             break;
991         case IW_MODE_INFRA:
992             priv->connection_config.bssType = CSR_WIFI_SME_BSS_TYPE_INFRASTRUCTURE;
993             break;
994         case IW_MODE_AUTO:
995             priv->connection_config.bssType = CSR_WIFI_SME_BSS_TYPE_ANY_BSS;
996             break;
997         default:
998             unifi_notice(priv, "Unknown IW MODE value.\n");
999     }
1000
1001     /* Clear the SSID and BSSID configuration */
1002     priv->connection_config.ssid.length = 0;
1003     memset(priv->connection_config.bssid.a, 0xFF, ETH_ALEN);
1004
1005     return 0;
1006 } /* unifi_siwmode() */
1007
1008
1009
1010 static int
1011 unifi_giwmode(struct net_device *dev, struct iw_request_info *info,
1012         union iwreq_data *wrqu, char *extra)
1013 {
1014     int r = 0;
1015     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1016     unifi_priv_t *priv = interfacePriv->privPtr;
1017     CsrWifiSmeConnectionConfig connectionConfig;
1018
1019     unifi_trace(priv, UDBG2, "unifi_giwmode\n");
1020     CHECK_INITED(priv);
1021
1022     unifi_trace(priv, UDBG2, "unifi_giwmode: Exisitng mode = 0x%x\n",
1023                 interfacePriv->interfaceMode);
1024     switch(interfacePriv->interfaceMode) {
1025         case CSR_WIFI_ROUTER_CTRL_MODE_STA:
1026         case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
1027            wrqu->mode = IW_MODE_INFRA;
1028            break;
1029         case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1030         case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1031             wrqu->mode = IW_MODE_MASTER;
1032             break;
1033         case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
1034             wrqu->mode = IW_MODE_ADHOC;
1035             break;
1036         case CSR_WIFI_ROUTER_CTRL_MODE_P2P:
1037         case CSR_WIFI_ROUTER_CTRL_MODE_NONE:
1038             UF_RTNL_UNLOCK();
1039             r = sme_mgt_connection_config_get(priv, &connectionConfig);
1040             UF_RTNL_LOCK();
1041             if (r == 0) {
1042                 switch(connectionConfig.bssType) {
1043                     case CSR_WIFI_SME_BSS_TYPE_ADHOC:
1044                         wrqu->mode = IW_MODE_ADHOC;
1045                         break;
1046                     case CSR_WIFI_SME_BSS_TYPE_INFRASTRUCTURE:
1047                         wrqu->mode = IW_MODE_INFRA;
1048                         break;
1049                     default:
1050                         wrqu->mode = IW_MODE_AUTO;
1051                         unifi_notice(priv, "Unknown IW MODE value.\n");
1052                 }
1053             }
1054             break;
1055         default:
1056             wrqu->mode = IW_MODE_AUTO;
1057             unifi_notice(priv, "Unknown IW MODE value.\n");
1058
1059     }
1060     unifi_trace(priv, UDBG4, "unifi_giwmode: mode = 0x%x\n", wrqu->mode);
1061     return r;
1062 } /* unifi_giwmode() */
1063
1064
1065
1066 static int
1067 unifi_giwrange(struct net_device *dev, struct iw_request_info *info,
1068         union iwreq_data *wrqu, char *extra)
1069 {
1070     struct iw_point *dwrq = &wrqu->data;
1071     struct iw_range *range = (struct iw_range *) extra;
1072     int i;
1073
1074     unifi_trace(NULL, UDBG2, "unifi_giwrange\n");
1075
1076     dwrq->length = sizeof(struct iw_range);
1077     memset(range, 0, sizeof(*range));
1078     range->min_nwid = 0x0000;
1079     range->max_nwid = 0x0000;
1080
1081     /*
1082      * Don't report the frequency/channel table, then the channel
1083      * number returned elsewhere will be printed as a channel number.
1084      */
1085
1086     /* Ranges of values reported in quality structs */
1087     range->max_qual.qual  = 40;         /* Max expected qual value */
1088     range->max_qual.level = -120;       /* Noise floor in dBm */
1089     range->max_qual.noise = -120;       /* Noise floor in dBm */
1090
1091
1092     /* space for IW_MAX_BITRATES (8 up to WE15, 32 later) */
1093     i = 0;
1094 #if WIRELESS_EXT > 15
1095     range->bitrate[i++] =   2 * 500000;
1096     range->bitrate[i++] =   4 * 500000;
1097     range->bitrate[i++] =  11 * 500000;
1098     range->bitrate[i++] =  22 * 500000;
1099     range->bitrate[i++] =  12 * 500000;
1100     range->bitrate[i++] =  18 * 500000;
1101     range->bitrate[i++] =  24 * 500000;
1102     range->bitrate[i++] =  36 * 500000;
1103     range->bitrate[i++] =  48 * 500000;
1104     range->bitrate[i++] =  72 * 500000;
1105     range->bitrate[i++] =  96 * 500000;
1106     range->bitrate[i++] = 108 * 500000;
1107 #else
1108     range->bitrate[i++] =   2 * 500000;
1109     range->bitrate[i++] =   4 * 500000;
1110     range->bitrate[i++] =  11 * 500000;
1111     range->bitrate[i++] =  22 * 500000;
1112     range->bitrate[i++] =  24 * 500000;
1113     range->bitrate[i++] =  48 * 500000;
1114     range->bitrate[i++] =  96 * 500000;
1115     range->bitrate[i++] = 108 * 500000;
1116 #endif /* WIRELESS_EXT < 16 */
1117     range->num_bitrates = i;
1118
1119     range->max_encoding_tokens = NUM_WEPKEYS;
1120     range->num_encoding_sizes = 2;
1121     range->encoding_size[0] = 5;
1122     range->encoding_size[1] = 13;
1123
1124     range->we_version_source = 20;
1125     range->we_version_compiled = WIRELESS_EXT;
1126
1127     /* Number of channels available in h/w */
1128     range->num_channels = 14;
1129     /* Number of entries in freq[] array */
1130     range->num_frequency = 14;
1131     for (i = 0; (i < range->num_frequency) && (i < IW_MAX_FREQUENCIES); i++) {
1132         int chan = i + 1;
1133         range->freq[i].i = chan;
1134         range->freq[i].m = channel_to_mhz(chan, 0);
1135         range->freq[i].e = 6;
1136     }
1137     if ((i+3) < IW_MAX_FREQUENCIES) {
1138         range->freq[i].i = 36;
1139         range->freq[i].m = channel_to_mhz(36, 1);
1140         range->freq[i].e = 6;
1141         range->freq[i+1].i = 40;
1142         range->freq[i+1].m = channel_to_mhz(40, 1);
1143         range->freq[i+1].e = 6;
1144         range->freq[i+2].i = 44;
1145         range->freq[i+2].m = channel_to_mhz(44, 1);
1146         range->freq[i+2].e = 6;
1147         range->freq[i+3].i = 48;
1148         range->freq[i+3].m = channel_to_mhz(48, 1);
1149         range->freq[i+3].e = 6;
1150     }
1151
1152 #if WIRELESS_EXT > 16
1153     /* Event capability (kernel + driver) */
1154     range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1155             IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1156             IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1157             IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1158     range->event_capa[1] = IW_EVENT_CAPA_K_1;
1159     range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1160             IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1161             IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1162             IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1163 #endif /* WIRELESS_EXT > 16 */
1164
1165 #if WIRELESS_EXT > 17
1166     range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1167         IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1168 #endif /* WIRELESS_EXT > 17 */
1169
1170
1171     return 0;
1172 } /* unifi_giwrange() */
1173
1174
1175 static int
1176 unifi_siwap(struct net_device *dev, struct iw_request_info *info,
1177         union iwreq_data *wrqu, char *extra)
1178 {
1179     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1180     unifi_priv_t *priv = interfacePriv->privPtr;
1181     int err = 0;
1182
1183     CHECK_INITED(priv);
1184
1185     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1186        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1187        unifi_error(priv, "unifi_siwap: not permitted in Mode %d\n",
1188                                       interfacePriv->interfaceMode);
1189        return -EPERM;
1190     }
1191
1192
1193     if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) {
1194         return -EINVAL;
1195     }
1196
1197         unifi_trace(priv, UDBG1, "unifi_siwap: asked for %pM\n",
1198                 wrqu->ap_addr.sa_data);
1199
1200     if (is_zero_ether_addr(wrqu->ap_addr.sa_data)) {
1201         priv->ignore_bssid_join = FALSE;
1202         err = sme_mgt_disconnect(priv);
1203         if (err) {
1204             unifi_trace(priv, UDBG4, "unifi_siwap: Disconnect failed, status %d\n", err);
1205         }
1206         return 0;
1207     }
1208
1209     if (priv->ignore_bssid_join) {
1210         unifi_trace(priv, UDBG4, "unifi_siwap: ignoring second join\n");
1211         priv->ignore_bssid_join = FALSE;
1212     } else {
1213         memcpy(priv->connection_config.bssid.a, wrqu->ap_addr.sa_data, ETH_ALEN);
1214         unifi_trace(priv, UDBG1, "unifi_siwap: Joining %X:%X:%X:%X:%X:%X\n",
1215                     priv->connection_config.bssid.a[0],
1216                     priv->connection_config.bssid.a[1],
1217                     priv->connection_config.bssid.a[2],
1218                     priv->connection_config.bssid.a[3],
1219                     priv->connection_config.bssid.a[4],
1220                     priv->connection_config.bssid.a[5]);
1221         err = sme_mgt_connect(priv);
1222         if (err) {
1223             unifi_error(priv, "unifi_siwap: Join failed, status %d\n", err);
1224             return convert_sme_error(err);
1225         }
1226     }
1227
1228     return 0;
1229 } /* unifi_siwap() */
1230
1231
1232 static int
1233 unifi_giwap(struct net_device *dev, struct iw_request_info *info,
1234         union iwreq_data *wrqu, char *extra)
1235 {
1236     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1237     unifi_priv_t *priv = interfacePriv->privPtr;
1238     CsrWifiSmeConnectionInfo connectionInfo;
1239     int r = 0;
1240     u8 *bssid;
1241
1242     CHECK_INITED(priv);
1243     unifi_trace(priv, UDBG2, "unifi_giwap\n");
1244
1245     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1246        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1247        unifi_error(priv, "iwprivswpikey: not permitted in Mode %d\n",
1248                                       interfacePriv->interfaceMode);
1249        return -EPERM;
1250     }
1251
1252     UF_RTNL_UNLOCK();
1253     r = sme_mgt_connection_info_get(priv, &connectionInfo);
1254     UF_RTNL_LOCK();
1255
1256     if (r == 0) {
1257         bssid = connectionInfo.bssid.a;
1258         wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1259                 unifi_trace(priv, UDBG4, "unifi_giwap: BSSID = %pM\n", bssid);
1260
1261         memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1262     } else {
1263         memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1264     }
1265
1266     return 0;
1267 } /* unifi_giwap() */
1268
1269
1270 static int
1271 unifi_siwscan(struct net_device *dev, struct iw_request_info *info,
1272         union iwreq_data *wrqu, char *extra)
1273 {
1274     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1275     unifi_priv_t *priv = interfacePriv->privPtr;
1276     int scantype;
1277     int r;
1278     CsrWifiSsid scan_ssid;
1279     unsigned char *channel_list = NULL;
1280     int chans_good = 0;
1281 #if WIRELESS_EXT > 17
1282     struct iw_point *data = &wrqu->data;
1283     struct iw_scan_req *req = (struct iw_scan_req *) extra;
1284 #endif
1285
1286     CHECK_INITED(priv);
1287
1288     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1289        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1290        unifi_error(priv, "unifi_siwscan: not permitted in Mode %d\n",
1291                                       interfacePriv->interfaceMode);
1292        return -EPERM;
1293     }
1294
1295
1296     scantype = UNIFI_SCAN_ACTIVE;
1297
1298 #if WIRELESS_EXT > 17
1299     /* Providing a valid channel list will force an active scan */
1300     if (req) {
1301         if ((req->num_channels > 0) && (req->num_channels < IW_MAX_FREQUENCIES)) {
1302             channel_list = kmalloc(req->num_channels, GFP_KERNEL);
1303             if (channel_list) {
1304                 int i;
1305                 for (i = 0; i < req->num_channels; i++) {
1306                     /* Convert frequency to channel number */
1307                     int ch = wext_freq_to_channel(req->channel_list[i].m,
1308                             req->channel_list[i].e);
1309                     if (ch) {
1310                         channel_list[chans_good++] = ch;
1311                     }
1312                 }
1313                 unifi_trace(priv, UDBG1,
1314                             "SIWSCAN: Scanning %d channels\n", chans_good);
1315             } else {
1316                 /* Fall back to scanning all */
1317                 unifi_error(priv, "SIWSCAN: Can't alloc channel_list (%d)\n",
1318                         req->num_channels);
1319             }
1320         }
1321     }
1322
1323     if (req && (data->flags & IW_SCAN_THIS_ESSID)) {
1324         memcpy(scan_ssid.ssid, req->essid, req->essid_len);
1325         scan_ssid.length = req->essid_len;
1326         unifi_trace(priv, UDBG1,
1327                     "SIWSCAN: Scanning for %.*s\n",
1328                     scan_ssid.length, scan_ssid.ssid);
1329     } else
1330 #endif
1331     {
1332         unifi_trace(priv, UDBG1, "SIWSCAN: Scanning for all APs\n");
1333         scan_ssid.length = 0;
1334     }
1335
1336     r = sme_mgt_scan_full(priv, &scan_ssid, chans_good, channel_list);
1337     if (r) {
1338         unifi_error(priv, "SIWSCAN: Scan returned error %d\n", r);
1339     } else {
1340         unifi_trace(priv, UDBG1, "SIWSCAN: Scan done\n");
1341         wext_send_scan_results_event(priv);
1342     }
1343
1344     if (channel_list) {
1345         kfree(channel_list);
1346     }
1347
1348     return r;
1349
1350 } /* unifi_siwscan() */
1351
1352
1353 static const unsigned char *
1354 unifi_find_info_element(int id, const unsigned char *info, int len)
1355 {
1356     const unsigned char *ie = info;
1357
1358     while (len > 1)
1359     {
1360         int e_id, e_len;
1361         e_id = ie[0];
1362         e_len = ie[1];
1363
1364         /* Return if we find a match */
1365         if (e_id == id)
1366         {
1367             return ie;
1368         }
1369
1370         len -= (e_len + 2);
1371         ie  += (e_len + 2);
1372     }
1373
1374     return NULL;
1375 } /* unifi_find_info_element() */
1376
1377
1378 /*
1379  * Translate scan data returned from the card to a card independent
1380  * format that the Wireless Tools will understand - Jean II
1381  */
1382 int
1383 unifi_translate_scan(struct net_device *dev,
1384                      struct iw_request_info *info,
1385                      char *current_ev, char *end_buf,
1386                      CsrWifiSmeScanResult *scan_data,
1387                      int scan_index)
1388 {
1389     struct iw_event iwe;                /* Temporary buffer */
1390     unsigned char *info_elems;
1391     int info_elem_len;
1392     const unsigned char *elem;
1393     u16 capabilities;
1394     int signal, noise, snr;
1395     char *start_buf = current_ev;
1396     char *current_val;  /* For rates */
1397     int i, r;
1398
1399     info_elems    = scan_data->informationElements;
1400     info_elem_len = scan_data->informationElementsLength;
1401
1402     if (!scan_data->informationElementsLength || !scan_data->informationElements) {
1403         unifi_error(NULL, "*** NULL SCAN IEs ***\n");
1404         return -EIO;
1405     }
1406
1407     /* get capinfo bits */
1408     capabilities = scan_data->capabilityInformation;
1409
1410     unifi_trace(NULL, UDBG5, "Capabilities: 0x%x\n", capabilities);
1411
1412     /* First entry *MUST* be the AP MAC address */
1413     memset(&iwe, 0, sizeof(iwe));
1414     iwe.cmd = SIOCGIWAP;
1415     iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1416     memcpy(iwe.u.ap_addr.sa_data, scan_data->bssid.a, ETH_ALEN);
1417     iwe.len = IW_EV_ADDR_LEN;
1418     r = uf_iwe_stream_add_event(info, start_buf, end_buf, &iwe, IW_EV_ADDR_LEN);
1419     if (r < 0) {
1420         return r;
1421     }
1422     start_buf += r;
1423
1424     /* Other entries will be displayed in the order we give them */
1425
1426     /* Add the ESSID */
1427     /* find SSID in Info Elems */
1428     elem = unifi_find_info_element(IE_SSID_ID, info_elems, info_elem_len);
1429     if (elem) {
1430         int e_len = elem[1];
1431         const unsigned char *e_ptr = elem + 2;
1432         unsigned char buf[33];
1433
1434         memset(&iwe, 0, sizeof(iwe));
1435         iwe.cmd = SIOCGIWESSID;
1436         iwe.u.essid.length = e_len;
1437         if (iwe.u.essid.length > 32) {
1438             iwe.u.essid.length = 32;
1439         }
1440         iwe.u.essid.flags = scan_index;
1441         memcpy(buf, e_ptr, iwe.u.essid.length);
1442         buf[iwe.u.essid.length] = '\0';
1443         r = uf_iwe_stream_add_point(info, start_buf, end_buf, &iwe, buf);
1444         if (r < 0) {
1445             return r;
1446         }
1447         start_buf += r;
1448
1449     }
1450
1451     /* Add mode */
1452     memset(&iwe, 0, sizeof(iwe));
1453     iwe.cmd = SIOCGIWMODE;
1454     if (scan_data->bssType == CSR_WIFI_SME_BSS_TYPE_INFRASTRUCTURE) {
1455         iwe.u.mode = IW_MODE_INFRA;
1456     } else {
1457         iwe.u.mode = IW_MODE_ADHOC;
1458     }
1459     iwe.len = IW_EV_UINT_LEN;
1460     r = uf_iwe_stream_add_event(info, start_buf, end_buf, &iwe, IW_EV_UINT_LEN);
1461     if (r < 0) {
1462         return r;
1463     }
1464     start_buf += r;
1465
1466     /* Add frequency. iwlist will convert to channel using table given in giwrange */
1467     memset(&iwe, 0, sizeof(iwe));
1468     iwe.cmd = SIOCGIWFREQ;
1469     iwe.u.freq.m = scan_data->channelFrequency;
1470     iwe.u.freq.e = 6;
1471     r = uf_iwe_stream_add_event(info, start_buf, end_buf, &iwe, IW_EV_FREQ_LEN);
1472     if (r < 0) {
1473         return r;
1474     }
1475     start_buf += r;
1476
1477
1478     /* Add quality statistics */
1479     iwe.cmd = IWEVQUAL;
1480     /*
1481      * level and noise below are mapped into an unsigned 8 bit number,
1482      * ranging from [-192; 63]. The way this is achieved is simply to
1483      * add 0x100 onto the number if it is negative,
1484      * once clipped to the correct range.
1485      */
1486     signal = scan_data->rssi; /* This value is in dBm */
1487     /* Clip range of snr */
1488     snr    = (scan_data->snr > 0) ? scan_data->snr : 0; /* In dB relative, from 0 - 255 */
1489     snr    = (snr < 255) ? snr : 255;
1490     noise  = signal - snr;
1491
1492     /* Clip range of signal */
1493     signal = (signal < 63) ? signal : 63;
1494     signal = (signal > -192) ? signal : -192;
1495
1496     /* Clip range of noise */
1497     noise = (noise < 63) ? noise : 63;
1498     noise = (noise > -192) ? noise : -192;
1499
1500     /* Make u8 */
1501     signal = ( signal < 0 ) ? signal + 0x100 : signal;
1502     noise = ( noise < 0 ) ? noise + 0x100 : noise;
1503
1504     iwe.u.qual.level = (u8)signal; /* -192 : 63 */
1505     iwe.u.qual.noise = (u8)noise;  /* -192 : 63 */
1506     iwe.u.qual.qual = snr;         /* 0 : 255 */
1507     iwe.u.qual.updated = 0;
1508 #if WIRELESS_EXT > 16
1509     iwe.u.qual.updated |= IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED |
1510         IW_QUAL_QUAL_UPDATED;
1511 #if WIRELESS_EXT > 18
1512     iwe.u.qual.updated |= IW_QUAL_DBM;
1513 #endif
1514 #endif
1515     r = uf_iwe_stream_add_event(info, start_buf, end_buf, &iwe, IW_EV_QUAL_LEN);
1516     if (r < 0) {
1517         return r;
1518     }
1519     start_buf += r;
1520
1521     /* Add encryption capability */
1522     iwe.cmd = SIOCGIWENCODE;
1523     if (capabilities & SIG_CAP_PRIVACY) {
1524         iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1525     } else {
1526         iwe.u.data.flags = IW_ENCODE_DISABLED;
1527     }
1528     iwe.u.data.length = 0;
1529     iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1530     r = uf_iwe_stream_add_point(info, start_buf, end_buf, &iwe, "");
1531     if (r < 0) {
1532         return r;
1533     }
1534     start_buf += r;
1535
1536
1537     /*
1538      * Rate : stuffing multiple values in a single event require a bit
1539      * more of magic - Jean II
1540      */
1541     current_val = start_buf + IW_EV_LCP_LEN;
1542
1543     iwe.cmd = SIOCGIWRATE;
1544     /* Those two flags are ignored... */
1545     iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1546
1547     elem = unifi_find_info_element(IE_SUPPORTED_RATES_ID,
1548             info_elems, info_elem_len);
1549     if (elem) {
1550         int e_len = elem[1];
1551         const unsigned char *e_ptr = elem + 2;
1552
1553         /*
1554          * Count how many rates we have.
1555          * Zero marks the end of the list, if the list is not truncated.
1556          */
1557         /* Max 8 values */
1558         for (i = 0; i < e_len; i++) {
1559             if (e_ptr[i] == 0) {
1560                 break;
1561             }
1562             /* Bit rate given in 500 kb/s units (+ 0x80) */
1563             iwe.u.bitrate.value = ((e_ptr[i] & 0x7f) * 500000);
1564             /* Add new value to event */
1565             r = uf_iwe_stream_add_value(info, start_buf, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
1566             if (r < 0) {
1567                 return r;
1568             }
1569             current_val +=r;
1570
1571         }
1572     }
1573     elem = unifi_find_info_element(IE_EXTENDED_SUPPORTED_RATES_ID,
1574             info_elems, info_elem_len);
1575     if (elem) {
1576         int e_len = elem[1];
1577         const unsigned char *e_ptr = elem + 2;
1578
1579         /*
1580          * Count how many rates we have.
1581          * Zero marks the end of the list, if the list is not truncated.
1582          */
1583         /* Max 8 values */
1584         for (i = 0; i < e_len; i++) {
1585             if (e_ptr[i] == 0) {
1586                 break;
1587             }
1588             /* Bit rate given in 500 kb/s units (+ 0x80) */
1589             iwe.u.bitrate.value = ((e_ptr[i] & 0x7f) * 500000);
1590             /* Add new value to event */
1591             r = uf_iwe_stream_add_value(info, start_buf, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
1592             if (r < 0) {
1593                 return r;
1594             }
1595             current_val +=r;
1596         }
1597     }
1598     /* Check if we added any rates event */
1599     if ((current_val - start_buf) > IW_EV_LCP_LEN) {
1600         start_buf = current_val;
1601     }
1602
1603
1604 #if WIRELESS_EXT > 17
1605     memset(&iwe, 0, sizeof(iwe));
1606     iwe.cmd = IWEVGENIE;
1607     iwe.u.data.length = info_elem_len;
1608
1609     r = uf_iwe_stream_add_point(info, start_buf, end_buf, &iwe, info_elems);
1610     if (r < 0) {
1611         return r;
1612     }
1613
1614     start_buf += r;
1615 #endif /* WE > 17 */
1616
1617     return (start_buf - current_ev);
1618 } /* unifi_translate_scan() */
1619
1620
1621
1622 static int
1623 unifi_giwscan(struct net_device *dev, struct iw_request_info *info,
1624               union iwreq_data *wrqu, char *extra)
1625 {
1626     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1627     unifi_priv_t *priv = interfacePriv->privPtr;
1628     struct iw_point *dwrq = &wrqu->data;
1629     int r;
1630
1631     CHECK_INITED(priv);
1632
1633     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1634        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1635        unifi_error(priv, "unifi_giwscan: not permitted in Mode %d\n",
1636                                       interfacePriv->interfaceMode);
1637        return -EPERM;
1638     }
1639
1640
1641     unifi_trace(priv, UDBG1,
1642             "unifi_giwscan: buffer (%d bytes) \n",
1643             dwrq->length);
1644     UF_RTNL_UNLOCK();
1645     r = sme_mgt_scan_results_get_async(priv, info, extra, dwrq->length);
1646     UF_RTNL_LOCK();
1647     if (r < 0) {
1648         unifi_trace(priv, UDBG1,
1649                 "unifi_giwscan: buffer (%d bytes) not big enough.\n",
1650                 dwrq->length);
1651         return r;
1652     }
1653
1654     dwrq->length = r;
1655     dwrq->flags = 0;
1656
1657     return 0;
1658 } /* unifi_giwscan() */
1659
1660
1661 /*
1662  * ---------------------------------------------------------------------------
1663  *  unifi_siwessid
1664  *
1665  *      Request to join a network or start and AdHoc.
1666  *
1667  *  Arguments:
1668  *      dev             Pointer to network device struct.
1669  *      info            Pointer to broken-out ioctl request.
1670  *      data            Pointer to argument data.
1671  *      essid           Pointer to string giving name of network to join
1672  *                      or start
1673  *
1674  *  Returns:
1675  *      0 on success and everything complete
1676  *      -EINPROGRESS to have the higher level call the commit method.
1677  * ---------------------------------------------------------------------------
1678  */
1679 static int
1680 unifi_siwessid(struct net_device *dev, struct iw_request_info *info,
1681                struct iw_point *data, char *essid)
1682 {
1683     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1684     unifi_priv_t *priv = interfacePriv->privPtr;
1685     int len;
1686     int err = 0;
1687
1688     CHECK_INITED(priv);
1689
1690     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1691        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1692        unifi_error(priv, "unifi_siwessid: not permitted in Mode %d\n",
1693                                       interfacePriv->interfaceMode);
1694        return -EPERM;
1695     }
1696
1697
1698     len = 0;
1699     if (data->flags & 1) {
1700         /* Limit length  */
1701         len = data->length;
1702         if (len > UNIFI_MAX_SSID_LEN) {
1703             len = UNIFI_MAX_SSID_LEN;
1704         }
1705     }
1706
1707 #ifdef UNIFI_DEBUG
1708     {
1709         char essid_str[UNIFI_MAX_SSID_LEN+1];
1710         int i;
1711
1712         for (i = 0; i < len; i++) {
1713             essid_str[i] = (isprint(essid[i]) ? essid[i] : '?');
1714         }
1715         essid_str[i] = '\0';
1716
1717         unifi_trace(priv, UDBG1, "unifi_siwessid: asked for '%*s' (%d)\n", len, essid_str, len);
1718         unifi_trace(priv, UDBG2, " with authModeMask = %d", priv->connection_config.authModeMask);
1719     }
1720 #endif
1721
1722     memset(priv->connection_config.bssid.a, 0xFF, ETH_ALEN);
1723     if (len) {
1724         if (essid[len - 1] == 0) {
1725             len --;
1726         }
1727
1728         memcpy(priv->connection_config.ssid.ssid, essid, len);
1729         priv->connection_config.ssid.length = len;
1730
1731     } else {
1732         priv->connection_config.ssid.length = 0;
1733     }
1734
1735     UF_RTNL_UNLOCK();
1736     err = sme_mgt_connect(priv);
1737     UF_RTNL_LOCK();
1738     if (err) {
1739         unifi_error(priv, "unifi_siwessid: Join failed, status %d\n", err);
1740         return convert_sme_error(err);
1741     }
1742
1743     return 0;
1744 } /* unifi_siwessid() */
1745
1746
1747 static int
1748 unifi_giwessid(struct net_device *dev, struct iw_request_info *info,
1749                union iwreq_data *wrqu, char *essid)
1750 {
1751     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1752     unifi_priv_t *priv = interfacePriv->privPtr;
1753     struct iw_point *data = &wrqu->essid;
1754     CsrWifiSmeConnectionInfo connectionInfo;
1755     int r = 0;
1756
1757     unifi_trace(priv, UDBG2, "unifi_giwessid\n");
1758     CHECK_INITED(priv);
1759
1760     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
1761        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
1762        unifi_error(priv, "unifi_giwessid: not permitted in Mode %d\n",
1763                                       interfacePriv->interfaceMode);
1764        return -EPERM;
1765     }
1766
1767     UF_RTNL_UNLOCK();
1768     r = sme_mgt_connection_info_get(priv, &connectionInfo);
1769     UF_RTNL_LOCK();
1770
1771     if (r == 0) {
1772         data->length = connectionInfo.ssid.length;
1773         strncpy(essid,
1774                 connectionInfo.ssid.ssid,
1775                 data->length);
1776         data->flags = 1;            /* active */
1777
1778         unifi_trace(priv, UDBG2, "unifi_giwessid: %.*s\n",
1779                 data->length, essid);
1780     }
1781
1782
1783     return 0;
1784 } /* unifi_giwessid() */
1785
1786
1787 static int
1788 unifi_siwrate(struct net_device *dev, struct iw_request_info *info,
1789               union iwreq_data *wrqu, char *extra)
1790 {
1791     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1792     unifi_priv_t *priv = interfacePriv->privPtr;
1793     struct iw_param *args = &wrqu->bitrate;
1794     CsrWifiSmeMibConfig mibConfig;
1795     int r;
1796
1797     CHECK_INITED(priv);
1798     unifi_trace(priv, UDBG2, "unifi_siwrate\n");
1799
1800     /*
1801      * If args->fixed == 0, value is max rate or -1 for best
1802      * If args->fixed == 1, value is rate to set or -1 for best
1803      * args->disabled and args->flags are not used in SIOCSIWRATE
1804      */
1805
1806     /* Get, modify and set the MIB data */
1807     UF_RTNL_UNLOCK();
1808     r = sme_mgt_mib_config_get(priv, &mibConfig);
1809     UF_RTNL_LOCK();
1810     if (r) {
1811         unifi_error(priv, "unifi_siwrate: Get CsrWifiSmeMibConfigValue failed.\n");
1812         return r;
1813     }
1814
1815     /* Default to auto rate algorithm */
1816     /* in 500Kbit/s, 0 means auto */
1817     mibConfig.unifiFixTxDataRate = 0;
1818
1819     if (args->value != -1) {
1820         mibConfig.unifiFixTxDataRate = args->value / 500000;
1821     }
1822
1823     /* 1 means rate is a maximum, 2 means rate is a set value */
1824     if (args->fixed == 1) {
1825         mibConfig.unifiFixMaxTxDataRate = 0;
1826     } else {
1827         mibConfig.unifiFixMaxTxDataRate = 1;
1828     }
1829     UF_RTNL_UNLOCK();
1830     r = sme_mgt_mib_config_set(priv, &mibConfig);
1831     UF_RTNL_LOCK();
1832     if (r) {
1833         unifi_error(priv, "unifi_siwrate: Set CsrWifiSmeMibConfigValue failed.\n");
1834         return r;
1835     }
1836
1837
1838     return 0;
1839 } /* unifi_siwrate() */
1840
1841
1842
1843 static int
1844 unifi_giwrate(struct net_device *dev, struct iw_request_info *info,
1845               union iwreq_data *wrqu, char *extra)
1846 {
1847     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1848     unifi_priv_t *priv = interfacePriv->privPtr;
1849     struct iw_param *args = &wrqu->bitrate;
1850     int r;
1851     int bitrate, flag;
1852     CsrWifiSmeMibConfig mibConfig;
1853     CsrWifiSmeConnectionStats connectionStats;
1854
1855     unifi_trace(priv, UDBG2, "unifi_giwrate\n");
1856     CHECK_INITED(priv);
1857
1858     flag = 0;
1859     bitrate = 0;
1860     UF_RTNL_UNLOCK();
1861     r = sme_mgt_mib_config_get(priv, &mibConfig);
1862     UF_RTNL_LOCK();
1863     if (r) {
1864         unifi_error(priv, "unifi_giwrate: Get CsrWifiSmeMibConfigValue failed.\n");
1865         return r;
1866     }
1867
1868     bitrate = mibConfig.unifiFixTxDataRate;
1869     flag = mibConfig.unifiFixMaxTxDataRate;
1870
1871     /* Used the value returned by the SME if MIB returns 0 */
1872     if (bitrate == 0) {
1873         UF_RTNL_UNLOCK();
1874         r = sme_mgt_connection_stats_get(priv, &connectionStats);
1875         UF_RTNL_LOCK();
1876         /* Ignore errors, we may be disconnected */
1877         if (r == 0) {
1878             bitrate = connectionStats.unifiTxDataRate;
1879         }
1880     }
1881
1882     args->value = bitrate * 500000;
1883     args->fixed = !flag;
1884
1885     return 0;
1886 } /* unifi_giwrate() */
1887
1888
1889 static int
1890 unifi_siwrts(struct net_device *dev, struct iw_request_info *info,
1891              union iwreq_data *wrqu, char *extra)
1892 {
1893     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1894     unifi_priv_t *priv = interfacePriv->privPtr;
1895     int val = wrqu->rts.value;
1896     int r = 0;
1897     CsrWifiSmeMibConfig mibConfig;
1898
1899     unifi_trace(priv, UDBG2, "unifi_siwrts\n");
1900     CHECK_INITED(priv);
1901
1902     if (wrqu->rts.disabled) {
1903         val = 2347;
1904     }
1905
1906     if ( (val < 0) || (val > 2347) )
1907     {
1908         return -EINVAL;
1909     }
1910
1911     /* Get, modify and set the MIB data */
1912     UF_RTNL_UNLOCK();
1913     r = sme_mgt_mib_config_get(priv, &mibConfig);
1914     UF_RTNL_LOCK();
1915     if (r) {
1916         unifi_error(priv, "unifi_siwrts: Get CsrWifiSmeMibConfigValue failed.\n");
1917         return r;
1918     }
1919     mibConfig.dot11RtsThreshold = val;
1920     UF_RTNL_UNLOCK();
1921     r = sme_mgt_mib_config_set(priv, &mibConfig);
1922     UF_RTNL_LOCK();
1923     if (r) {
1924         unifi_error(priv, "unifi_siwrts: Set CsrWifiSmeMibConfigValue failed.\n");
1925         return r;
1926     }
1927
1928     return 0;
1929 }
1930
1931
1932 static int
1933 unifi_giwrts(struct net_device *dev, struct iw_request_info *info,
1934              union iwreq_data *wrqu, char *extra)
1935 {
1936     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1937     unifi_priv_t *priv = interfacePriv->privPtr;
1938     int r;
1939     int rts_thresh;
1940     CsrWifiSmeMibConfig mibConfig;
1941
1942     unifi_trace(priv, UDBG2, "unifi_giwrts\n");
1943     CHECK_INITED(priv);
1944
1945     UF_RTNL_UNLOCK();
1946     r = sme_mgt_mib_config_get(priv, &mibConfig);
1947     UF_RTNL_LOCK();
1948     if (r) {
1949         unifi_error(priv, "unifi_giwrts: Get CsrWifiSmeMibConfigValue failed.\n");
1950         return r;
1951     }
1952
1953     rts_thresh = mibConfig.dot11RtsThreshold;
1954     if (rts_thresh > 2347) {
1955         rts_thresh = 2347;
1956     }
1957
1958     wrqu->rts.value = rts_thresh;
1959     wrqu->rts.disabled = (rts_thresh == 2347);
1960     wrqu->rts.fixed = 1;
1961
1962     return 0;
1963 }
1964
1965
1966 static int
1967 unifi_siwfrag(struct net_device *dev, struct iw_request_info *info,
1968               union iwreq_data *wrqu, char *extra)
1969 {
1970     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1971     unifi_priv_t *priv = interfacePriv->privPtr;
1972     int val = wrqu->frag.value;
1973     int r = 0;
1974     CsrWifiSmeMibConfig mibConfig;
1975
1976     unifi_trace(priv, UDBG2, "unifi_siwfrag\n");
1977     CHECK_INITED(priv);
1978
1979     if (wrqu->frag.disabled)
1980         val = 2346;
1981
1982     if ( (val < 256) || (val > 2347) )
1983         return -EINVAL;
1984
1985     /* Get, modify and set the MIB data */
1986     UF_RTNL_UNLOCK();
1987     r = sme_mgt_mib_config_get(priv, &mibConfig);
1988     UF_RTNL_LOCK();
1989     if (r) {
1990         unifi_error(priv, "unifi_siwfrag: Get CsrWifiSmeMibConfigValue failed.\n");
1991         return r;
1992     }
1993     /* Fragmentation Threashold must be even */
1994     mibConfig.dot11FragmentationThreshold = (val & ~0x1);
1995     UF_RTNL_UNLOCK();
1996     r = sme_mgt_mib_config_set(priv, &mibConfig);
1997     UF_RTNL_LOCK();
1998     if (r) {
1999         unifi_error(priv, "unifi_siwfrag: Set CsrWifiSmeMibConfigValue failed.\n");
2000         return r;
2001     }
2002
2003     return 0;
2004 }
2005
2006
2007 static int
2008 unifi_giwfrag(struct net_device *dev, struct iw_request_info *info,
2009               union iwreq_data *wrqu, char *extra)
2010 {
2011     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2012     unifi_priv_t *priv = interfacePriv->privPtr;
2013     int r;
2014     int frag_thresh;
2015     CsrWifiSmeMibConfig mibConfig;
2016
2017     unifi_trace(priv, UDBG2, "unifi_giwfrag\n");
2018     CHECK_INITED(priv);
2019
2020     UF_RTNL_UNLOCK();
2021     r = sme_mgt_mib_config_get(priv, &mibConfig);
2022     UF_RTNL_LOCK();
2023     if (r) {
2024         unifi_error(priv, "unifi_giwfrag: Get CsrWifiSmeMibConfigValue failed.\n");
2025         return r;
2026     }
2027
2028     frag_thresh = mibConfig.dot11FragmentationThreshold;
2029
2030     /* Build the return structure */
2031     wrqu->frag.value = frag_thresh;
2032     wrqu->frag.disabled = (frag_thresh >= 2346);
2033     wrqu->frag.fixed = 1;
2034
2035     return 0;
2036 }
2037
2038
2039 static int
2040 unifi_siwencode(struct net_device *dev, struct iw_request_info *info,
2041                 union iwreq_data *wrqu, char *extra)
2042 {
2043     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2044     unifi_priv_t *priv = interfacePriv->privPtr;
2045     struct iw_point *erq = &wrqu->encoding;
2046     int index;
2047     int rc = 0;
2048     int privacy = -1;
2049     CsrWifiSmeKey sme_key;
2050
2051     unifi_trace(priv, UDBG2, "unifi_siwencode\n");
2052
2053     CHECK_INITED(priv);
2054
2055     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2056        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2057        unifi_error(priv, "unifi_siwencode: not permitted in Mode %d\n",
2058                                       interfacePriv->interfaceMode);
2059        return -EPERM;
2060     }
2061
2062
2063     /*
2064      * Key index is encoded in the flags.
2065      * 0 - use current default,
2066      * 1-4 - if a key value is given set that key
2067      *       if not use that key
2068      */
2069     index = (erq->flags & IW_ENCODE_INDEX);  /* key number, 1-4 */
2070     if ((index < 0) || (index > 4)) {
2071         unifi_error(priv, "unifi_siwencode: Request to set an invalid key (index:%d)", index);
2072         return -EINVAL;
2073     }
2074
2075     /*
2076      * Basic checking: do we have a key to set ?
2077      * The IW_ENCODE_NOKEY flag is set when no key is present (only change flags),
2078      * but older versions rely on sending a key id 1-4.
2079      */
2080     if (erq->length > 0) {
2081
2082         /* Check the size of the key */
2083         if ((erq->length > LARGE_KEY_SIZE) || (erq->length < SMALL_KEY_SIZE)) {
2084             unifi_error(priv, "unifi_siwencode: Request to set an invalid key (length:%d)",
2085                         erq->length);
2086             return -EINVAL;
2087         }
2088
2089         /* Check the index (none (i.e. 0) means use current) */
2090         if ((index < 1) || (index > 4)) {
2091             /* If we do not have a previous key, use 1 as default */
2092             if (!priv->wep_tx_key_index) {
2093                 priv->wep_tx_key_index = 1;
2094             }
2095             index = priv->wep_tx_key_index;
2096         }
2097
2098         /* If we didn't have a key and a valid index is set, we want to remember it*/
2099         if (!priv->wep_tx_key_index) {
2100             priv->wep_tx_key_index = index;
2101         }
2102
2103         unifi_trace(priv, UDBG1, "Tx key Index is %d\n", priv->wep_tx_key_index);
2104
2105         privacy = 1;
2106
2107         /* Check if the key is not marked as invalid */
2108         if ((erq->flags & IW_ENCODE_NOKEY) == 0) {
2109
2110             unifi_trace(priv, UDBG1, "New %s key (len=%d, index=%d)\n",
2111                         (priv->wep_tx_key_index == index) ? "tx" : "",
2112                         erq->length, index);
2113
2114             sme_key.wepTxKey = (priv->wep_tx_key_index == index);
2115             if (priv->wep_tx_key_index == index) {
2116                 sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_PAIRWISE;
2117             } else {
2118                 sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_GROUP;
2119             }
2120             /* Key index is zero based in SME but 1 based in wext */
2121             sme_key.keyIndex = (index - 1);
2122             sme_key.keyLength = erq->length;
2123             sme_key.authenticator = 0;
2124             memset(sme_key.address.a, 0xFF, ETH_ALEN);
2125             memcpy(sme_key.key, extra, erq->length);
2126
2127             UF_RTNL_UNLOCK();
2128             rc = sme_mgt_key(priv, &sme_key, CSR_WIFI_SME_LIST_ACTION_ADD);
2129             UF_RTNL_LOCK();
2130             if (rc) {
2131                 unifi_error(priv, "unifi_siwencode: Set key failed (%d)", rc);
2132                 return convert_sme_error(rc);
2133             }
2134
2135             /* Store the key to be reported by the SIOCGIWENCODE handler */
2136             priv->wep_keys[index - 1].len = erq->length;
2137             memcpy(priv->wep_keys[index - 1].key, extra, erq->length);
2138         }
2139     } else {
2140         /*
2141          * No additional key data, so it must be a request to change the
2142          * active key.
2143          */
2144         if (index != 0) {
2145             unifi_trace(priv, UDBG1, "Tx key Index is %d\n", index - 1);
2146
2147             /* Store the index to be reported by the SIOCGIWENCODE handler */
2148             priv->wep_tx_key_index = index;
2149
2150             sme_key.wepTxKey = 1;
2151             sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_PAIRWISE;
2152
2153             /* Key index is zero based in SME but 1 based in wext */
2154             sme_key.keyIndex = (index - 1);
2155             sme_key.keyLength = 0;
2156             sme_key.authenticator = 0;
2157             UF_RTNL_UNLOCK();
2158             rc = sme_mgt_key(priv, &sme_key, CSR_WIFI_SME_LIST_ACTION_ADD);
2159             UF_RTNL_LOCK();
2160             if (rc) {
2161                 unifi_error(priv, "unifi_siwencode: Set key failed (%d)", rc);
2162                 return convert_sme_error(rc);
2163             }
2164
2165             /* Turn on encryption */
2166             privacy = 1;
2167         }
2168     }
2169
2170     /* Read the flags */
2171     if (erq->flags & IW_ENCODE_DISABLED) {
2172         /* disable encryption */
2173         unifi_trace(priv, UDBG1, "disable WEP encryption\n");
2174         privacy = 0;
2175
2176         priv->wep_tx_key_index = 0;
2177
2178         unifi_trace(priv, UDBG1, "IW_ENCODE_DISABLED: CSR_WIFI_SME_AUTH_MODE_80211_OPEN\n");
2179         priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
2180     }
2181
2182     if (erq->flags & IW_ENCODE_RESTRICTED) {
2183         /* Use shared key auth */
2184         unifi_trace(priv, UDBG1, "IW_ENCODE_RESTRICTED: CSR_WIFI_SME_AUTH_MODE_80211_SHARED\n");
2185         priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_SHARED;
2186
2187         /* Turn on encryption */
2188         privacy = 1;
2189     }
2190     if (erq->flags & IW_ENCODE_OPEN) {
2191         unifi_trace(priv, UDBG1, "IW_ENCODE_OPEN: CSR_WIFI_SME_AUTH_MODE_80211_OPEN\n");
2192         priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
2193     }
2194
2195     /* Commit the changes to flags if needed */
2196     if (privacy != -1) {
2197         priv->connection_config.privacyMode = privacy ? CSR_WIFI_SME_80211_PRIVACY_MODE_ENABLED : CSR_WIFI_SME_80211_PRIVACY_MODE_DISABLED;
2198         priv->connection_config.encryptionModeMask = privacy ? (CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_WEP40 |
2199                 CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_WEP104 |
2200                 CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP40 |
2201                 CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP104) :
2202             CSR_WIFI_SME_ENCRYPTION_CIPHER_NONE;
2203     }
2204
2205     return convert_sme_error(rc);
2206
2207 } /* unifi_siwencode() */
2208
2209
2210
2211 static int
2212 unifi_giwencode(struct net_device *dev, struct iw_request_info *info,
2213                 union iwreq_data *wrqu, char *extra)
2214 {
2215     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2216     unifi_priv_t *priv = interfacePriv->privPtr;
2217     struct iw_point *erq = &wrqu->encoding;
2218
2219     unifi_trace(priv, UDBG2, "unifi_giwencode\n");
2220
2221     CHECK_INITED(priv);
2222
2223     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2224        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2225        unifi_error(priv, "unifi_giwencode: not permitted in Mode %d\n",
2226                                       interfacePriv->interfaceMode);
2227        return -EPERM;
2228     }
2229
2230
2231     if (priv->connection_config.authModeMask == CSR_WIFI_SME_AUTH_MODE_80211_SHARED) {
2232         erq->flags = IW_ENCODE_RESTRICTED;
2233     }
2234     else {
2235         if (priv->connection_config.privacyMode == CSR_WIFI_SME_80211_PRIVACY_MODE_DISABLED) {
2236             erq->flags = IW_ENCODE_DISABLED;
2237         } else {
2238             erq->flags = IW_ENCODE_OPEN;
2239         }
2240     }
2241
2242     erq->length = 0;
2243
2244     if (erq->flags != IW_ENCODE_DISABLED) {
2245         int index = priv->wep_tx_key_index;
2246
2247         if ((index > 0) && (index <= NUM_WEPKEYS)) {
2248             erq->flags |= (index & IW_ENCODE_INDEX);
2249             erq->length = priv->wep_keys[index - 1].len;
2250             memcpy(extra, priv->wep_keys[index - 1].key, erq->length);
2251         } else {
2252             unifi_notice(priv, "unifi_giwencode: Surprise, do not have a valid key index (%d)\n",
2253                          index);
2254         }
2255     }
2256
2257     return 0;
2258 } /* unifi_giwencode() */
2259
2260
2261 static int
2262 unifi_siwpower(struct net_device *dev, struct iw_request_info *info,
2263                union iwreq_data *wrqu, char *extra)
2264 {
2265     struct iw_param *args = &wrqu->power;
2266     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2267     unifi_priv_t *priv = interfacePriv->privPtr;
2268     int listen_interval, wake_for_dtim;
2269     int r = 0;
2270     CsrWifiSmePowerConfig powerConfig;
2271
2272     unifi_trace(priv, UDBG2, "unifi_siwpower\n");
2273
2274     CHECK_INITED(priv);
2275
2276     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2277        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2278        unifi_error(priv, "unifi_siwpower: not permitted in Mode %d\n",
2279                                       interfacePriv->interfaceMode);
2280        return -EPERM;
2281     }
2282
2283     UF_RTNL_UNLOCK();
2284     r = sme_mgt_power_config_get(priv, &powerConfig);
2285     UF_RTNL_LOCK();
2286     if (r) {
2287         unifi_error(priv, "unifi_siwpower: Get unifi_PowerConfigValue failed.\n");
2288         return r;
2289     }
2290
2291     listen_interval = -1;
2292     wake_for_dtim = -1;
2293     if (args->disabled) {
2294         powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_LOW;
2295     }
2296     else
2297     {
2298         powerConfig.powerSaveLevel = CSR_WIFI_SME_POWER_SAVE_LEVEL_HIGH;
2299
2300         switch (args->flags & IW_POWER_TYPE) {
2301             case 0:
2302                 /* not specified */
2303                 break;
2304             case IW_POWER_PERIOD:
2305                 listen_interval = args->value / 1000;
2306                 break;
2307             default:
2308                 return -EINVAL;
2309         }
2310
2311         switch (args->flags & IW_POWER_MODE) {
2312             case 0:
2313                 /* not specified */
2314                 break;
2315             case IW_POWER_UNICAST_R:
2316                 /* not interested in broadcast packets */
2317                 wake_for_dtim = 0;
2318                 break;
2319             case IW_POWER_ALL_R:
2320                 /* yes, we are interested in broadcast packets */
2321                 wake_for_dtim = 1;
2322                 break;
2323             default:
2324                 return -EINVAL;
2325         }
2326     }
2327
2328     if (listen_interval > 0) {
2329         powerConfig.listenIntervalTu = listen_interval;
2330         unifi_trace(priv, UDBG4, "unifi_siwpower: new Listen Interval = %d.\n",
2331                     powerConfig.listenIntervalTu);
2332     }
2333
2334     if (wake_for_dtim >= 0) {
2335         powerConfig.rxDtims = wake_for_dtim;
2336     }
2337     UF_RTNL_UNLOCK();
2338     r = sme_mgt_power_config_set(priv, &powerConfig);
2339     UF_RTNL_LOCK();
2340     if (r) {
2341         unifi_error(priv, "unifi_siwpower: Set unifi_PowerConfigValue failed.\n");
2342         return r;
2343     }
2344
2345     return 0;
2346 } /* unifi_siwpower() */
2347
2348
2349 static int
2350 unifi_giwpower(struct net_device *dev, struct iw_request_info *info,
2351                union iwreq_data *wrqu, char *extra)
2352 {
2353     struct iw_param *args = &wrqu->power;
2354     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2355     unifi_priv_t *priv = interfacePriv->privPtr;
2356     CsrWifiSmePowerConfig powerConfig;
2357     int r;
2358
2359     unifi_trace(priv, UDBG2, "unifi_giwpower\n");
2360
2361     CHECK_INITED(priv);
2362
2363     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2364        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2365        unifi_error(priv, "unifi_giwpower: not permitted in Mode %d\n",
2366                                       interfacePriv->interfaceMode);
2367        return -EPERM;
2368     }
2369
2370
2371     args->flags = 0;
2372     UF_RTNL_UNLOCK();
2373     r = sme_mgt_power_config_get(priv, &powerConfig);
2374     UF_RTNL_LOCK();
2375     if (r) {
2376         unifi_error(priv, "unifi_giwpower: Get unifi_PowerConfigValue failed.\n");
2377         return r;
2378     }
2379
2380     unifi_trace(priv, UDBG4, "unifi_giwpower: mode=%d\n",
2381                 powerConfig.powerSaveLevel);
2382
2383     args->disabled = (powerConfig.powerSaveLevel == CSR_WIFI_SME_POWER_SAVE_LEVEL_LOW);
2384     if (args->disabled) {
2385         args->flags = 0;
2386         return 0;
2387     }
2388
2389     args->value = powerConfig.listenIntervalTu * 1000;
2390     args->flags |= IW_POWER_PERIOD;
2391
2392     if (powerConfig.rxDtims) {
2393         args->flags |= IW_POWER_ALL_R;
2394     } else {
2395         args->flags |= IW_POWER_UNICAST_R;
2396     }
2397
2398     return 0;
2399 } /* unifi_giwpower() */
2400
2401
2402 /*
2403  * ---------------------------------------------------------------------------
2404  *  unifi_siwcommit - handler for SIOCSIWCOMMIT
2405  *
2406  *      Apply all the parameters that have been set.
2407  *      In practice this means:
2408  *       - do a scan
2409  *       - join a network or start an AdHoc
2410  *       - authenticate and associate.
2411  *
2412  *  Arguments:
2413  *      None.
2414  *
2415  *  Returns:
2416  *      None.
2417  * ---------------------------------------------------------------------------
2418  */
2419 static int
2420 unifi_siwcommit(struct net_device *dev, struct iw_request_info *info,
2421                 union iwreq_data *wrqu, char *extra)
2422 {
2423     return 0;
2424 } /* unifi_siwcommit() */
2425
2426
2427
2428 static int
2429 unifi_siwmlme(struct net_device *dev, struct iw_request_info *info,
2430               union iwreq_data *wrqu, char *extra)
2431 {
2432     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2433     unifi_priv_t *priv = interfacePriv->privPtr;
2434     struct iw_mlme *mlme = (struct iw_mlme *)extra;
2435
2436     unifi_trace(priv, UDBG2, "unifi_siwmlme\n");
2437     CHECK_INITED(priv);
2438
2439     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2440        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2441        unifi_error(priv, "unifi_siwmlme: not permitted in Mode %d\n",
2442                                       interfacePriv->interfaceMode);
2443        return -EPERM;
2444     }
2445
2446
2447     switch (mlme->cmd) {
2448         case IW_MLME_DEAUTH:
2449         case IW_MLME_DISASSOC:
2450             UF_RTNL_UNLOCK();
2451             sme_mgt_disconnect(priv);
2452             UF_RTNL_LOCK();
2453             break;
2454         default:
2455             return -EOPNOTSUPP;
2456     }
2457
2458     return 0;
2459 } /* unifi_siwmlme() */
2460
2461
2462 /*
2463  * ---------------------------------------------------------------------------
2464  *  unifi_siwgenie
2465  *  unifi_giwgenie
2466  *
2467  *      WPA : Generic IEEE 802.11 information element (e.g., for WPA/RSN/WMM).
2468  *      Handlers for SIOCSIWGENIE, SIOCGIWGENIE - set/get generic IE
2469  *
2470  *      The host program (e.g. wpa_supplicant) uses this call to set the
2471  *      additional IEs to accompany the next (Associate?) request.
2472  *
2473  *  Arguments:
2474  *      None.
2475  *
2476  *  Returns:
2477  *      None.
2478  *  Notes:
2479  *      From wireless.h:
2480  *        This ioctl uses struct iw_point and data buffer that includes IE id
2481  *        and len fields. More than one IE may be included in the
2482  *        request. Setting the generic IE to empty buffer (len=0) removes the
2483  *        generic IE from the driver.
2484  * ---------------------------------------------------------------------------
2485  */
2486 static int
2487 unifi_siwgenie(struct net_device *dev, struct iw_request_info *info,
2488                union iwreq_data *wrqu, char *extra)
2489 {
2490     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2491     unifi_priv_t *priv = interfacePriv->privPtr;
2492     int len;
2493
2494     unifi_trace(priv, UDBG2, "unifi_siwgenie\n");
2495
2496     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2497        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2498        unifi_error(priv, "unifi_siwgenie: not permitted in Mode %d\n",
2499                                       interfacePriv->interfaceMode);
2500        return -EPERM;
2501     }
2502
2503
2504     if ( priv->connection_config.mlmeAssociateReqInformationElements) {
2505         kfree( priv->connection_config.mlmeAssociateReqInformationElements);
2506     }
2507     priv->connection_config.mlmeAssociateReqInformationElementsLength = 0;
2508     priv->connection_config.mlmeAssociateReqInformationElements = NULL;
2509
2510     len = wrqu->data.length;
2511     if (len == 0) {
2512         return 0;
2513     }
2514
2515     priv->connection_config.mlmeAssociateReqInformationElements = kmalloc(len, GFP_KERNEL);
2516     if (priv->connection_config.mlmeAssociateReqInformationElements == NULL) {
2517         return -ENOMEM;
2518     }
2519
2520     priv->connection_config.mlmeAssociateReqInformationElementsLength = len;
2521     memcpy( priv->connection_config.mlmeAssociateReqInformationElements, extra, len);
2522
2523     return 0;
2524 } /* unifi_siwgenie() */
2525
2526
2527 static int
2528 unifi_giwgenie(struct net_device *dev, struct iw_request_info *info,
2529                union iwreq_data *wrqu, char *extra)
2530 {
2531     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2532     unifi_priv_t *priv = interfacePriv->privPtr;
2533     int len;
2534
2535     unifi_trace(priv, UDBG2, "unifi_giwgenie\n");
2536
2537     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2538        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2539        unifi_error(priv, "unifi_giwgenie: not permitted in Mode %d\n",
2540                                       interfacePriv->interfaceMode);
2541        return -EPERM;
2542     }
2543
2544
2545     len = priv->connection_config.mlmeAssociateReqInformationElementsLength;
2546
2547     if (len == 0) {
2548         wrqu->data.length = 0;
2549         return 0;
2550     }
2551
2552     if (wrqu->data.length < len) {
2553         return -E2BIG;
2554     }
2555
2556     wrqu->data.length = len;
2557     memcpy(extra, priv->connection_config.mlmeAssociateReqInformationElements, len);
2558
2559     return 0;
2560 } /* unifi_giwgenie() */
2561
2562
2563 /*
2564  * ---------------------------------------------------------------------------
2565  *  unifi_siwauth
2566  *  unifi_giwauth
2567  *
2568  *      Handlers for SIOCSIWAUTH, SIOCGIWAUTH
2569  *      Set/get various authentication parameters.
2570  *
2571  *  Arguments:
2572  *
2573  *
2574  *  Returns:
2575  *      None.
2576  * ---------------------------------------------------------------------------
2577  */
2578 static int
2579 _unifi_siwauth(struct net_device *dev, struct iw_request_info *info,
2580                union iwreq_data *wrqu, char *extra)
2581 {
2582     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2583     unifi_priv_t *priv = interfacePriv->privPtr;
2584     CsrWifiSmeAuthModeMask new_auth;
2585
2586     unifi_trace(priv, UDBG2, "unifi_siwauth\n");
2587
2588     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2589        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2590        unifi_error(priv, "unifi_siwauth: not permitted in Mode %d\n",
2591                                       interfacePriv->interfaceMode);
2592        return -EPERM;
2593     }
2594
2595
2596     /*
2597      * This ioctl is safe to call even when UniFi is powered off.
2598      * wpa_supplicant calls it to test whether we support WPA.
2599      */
2600
2601     switch (wrqu->param.flags & IW_AUTH_INDEX) {
2602
2603         case IW_AUTH_WPA_ENABLED:
2604             unifi_trace(priv, UDBG1, "IW_AUTH_WPA_ENABLED: %d\n", wrqu->param.value);
2605
2606             if (wrqu->param.value == 0) {
2607                 unifi_trace(priv, UDBG5, "IW_AUTH_WPA_ENABLED: CSR_WIFI_SME_AUTH_MODE_80211_OPEN\n");
2608                 priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
2609             }
2610             break;
2611
2612         case IW_AUTH_PRIVACY_INVOKED:
2613             unifi_trace(priv, UDBG1, "IW_AUTH_PRIVACY_INVOKED: %d\n", wrqu->param.value);
2614
2615             priv->connection_config.privacyMode = wrqu->param.value ? CSR_WIFI_SME_80211_PRIVACY_MODE_ENABLED : CSR_WIFI_SME_80211_PRIVACY_MODE_DISABLED;
2616             if (wrqu->param.value == CSR_WIFI_SME_80211_PRIVACY_MODE_DISABLED)
2617             {
2618                 priv->connection_config.encryptionModeMask = CSR_WIFI_SME_ENCRYPTION_CIPHER_NONE;
2619             }
2620             break;
2621
2622         case IW_AUTH_80211_AUTH_ALG:
2623             /*
2624                IW_AUTH_ALG_OPEN_SYSTEM      0x00000001
2625                IW_AUTH_ALG_SHARED_KEY       0x00000002
2626                IW_AUTH_ALG_LEAP             0x00000004
2627                */
2628             new_auth = 0;
2629             if (wrqu->param.value & IW_AUTH_ALG_OPEN_SYSTEM) {
2630                 unifi_trace(priv, UDBG1, "IW_AUTH_80211_AUTH_ALG: %d (IW_AUTH_ALG_OPEN_SYSTEM)\n", wrqu->param.value);
2631                 new_auth |= CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
2632             }
2633             if (wrqu->param.value & IW_AUTH_ALG_SHARED_KEY) {
2634                 unifi_trace(priv, UDBG1, "IW_AUTH_80211_AUTH_ALG: %d (IW_AUTH_ALG_SHARED_KEY)\n", wrqu->param.value);
2635                 new_auth |= CSR_WIFI_SME_AUTH_MODE_80211_SHARED;
2636             }
2637             if (wrqu->param.value & IW_AUTH_ALG_LEAP) {
2638                 /* Initial exchanges using open-system to set EAP */
2639                 unifi_trace(priv, UDBG1, "IW_AUTH_80211_AUTH_ALG: %d (IW_AUTH_ALG_LEAP)\n", wrqu->param.value);
2640                 new_auth |= CSR_WIFI_SME_AUTH_MODE_8021X_OTHER1X;
2641             }
2642             if (new_auth == 0) {
2643                 unifi_trace(priv, UDBG1, "IW_AUTH_80211_AUTH_ALG: invalid value %d\n",
2644                         wrqu->param.value);
2645                 return -EINVAL;
2646             } else {
2647                 priv->connection_config.authModeMask = new_auth;
2648             }
2649             break;
2650
2651         case IW_AUTH_WPA_VERSION:
2652             unifi_trace(priv, UDBG1, "IW_AUTH_WPA_VERSION: %d\n", wrqu->param.value);
2653             priv->ignore_bssid_join = TRUE;
2654             /*
2655                IW_AUTH_WPA_VERSION_DISABLED 0x00000001
2656                IW_AUTH_WPA_VERSION_WPA      0x00000002
2657                IW_AUTH_WPA_VERSION_WPA2     0x00000004
2658                */
2659
2660             if (!(wrqu->param.value & IW_AUTH_WPA_VERSION_DISABLED)) {
2661
2662                 priv->connection_config.authModeMask = CSR_WIFI_SME_AUTH_MODE_80211_OPEN;
2663
2664                 if (wrqu->param.value & IW_AUTH_WPA_VERSION_WPA) {
2665                     unifi_trace(priv, UDBG4, "IW_AUTH_WPA_VERSION: WPA, WPA-PSK\n");
2666                     priv->connection_config.authModeMask |= (CSR_WIFI_SME_AUTH_MODE_8021X_WPA | CSR_WIFI_SME_AUTH_MODE_8021X_WPAPSK);
2667                 }
2668                 if (wrqu->param.value & IW_AUTH_WPA_VERSION_WPA2) {
2669                     unifi_trace(priv, UDBG4, "IW_AUTH_WPA_VERSION: WPA2, WPA2-PSK\n");
2670                     priv->connection_config.authModeMask |= (CSR_WIFI_SME_AUTH_MODE_8021X_WPA2 | CSR_WIFI_SME_AUTH_MODE_8021X_WPA2PSK);
2671                 }
2672             }
2673             break;
2674
2675         case IW_AUTH_CIPHER_PAIRWISE:
2676             unifi_trace(priv, UDBG1, "IW_AUTH_CIPHER_PAIRWISE: %d\n", wrqu->param.value);
2677             /*
2678              * one of:
2679              IW_AUTH_CIPHER_NONE        0x00000001
2680              IW_AUTH_CIPHER_WEP40       0x00000002
2681              IW_AUTH_CIPHER_TKIP        0x00000004
2682              IW_AUTH_CIPHER_CCMP        0x00000008
2683              IW_AUTH_CIPHER_WEP104      0x00000010
2684              */
2685
2686             priv->connection_config.encryptionModeMask = CSR_WIFI_SME_ENCRYPTION_CIPHER_NONE;
2687
2688             if (wrqu->param.value & IW_AUTH_CIPHER_WEP40) {
2689                 priv->connection_config.encryptionModeMask |=
2690                     CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_WEP40 | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP40;
2691             }
2692             if (wrqu->param.value & IW_AUTH_CIPHER_WEP104) {
2693                 priv->connection_config.encryptionModeMask |=
2694                     CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_WEP104 | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP104;
2695             }
2696             if (wrqu->param.value & IW_AUTH_CIPHER_TKIP) {
2697                 priv->connection_config.encryptionModeMask |=
2698                     CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_TKIP | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_TKIP;
2699             }
2700             if (wrqu->param.value & IW_AUTH_CIPHER_CCMP) {
2701                 priv->connection_config.encryptionModeMask |=
2702                     CSR_WIFI_SME_ENCRYPTION_CIPHER_PAIRWISE_CCMP | CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_CCMP;
2703             }
2704
2705             break;
2706
2707         case IW_AUTH_CIPHER_GROUP:
2708             unifi_trace(priv, UDBG1, "IW_AUTH_CIPHER_GROUP: %d\n", wrqu->param.value);
2709             /*
2710              * Use the WPA version and the group cipher suite to set the permitted
2711              * group key in the MIB. f/w uses this value to validate WPA and RSN IEs
2712              * in the probe responses from the desired BSS(ID)
2713              */
2714
2715             priv->connection_config.encryptionModeMask &= ~(CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP40 |
2716                     CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP104 |
2717                     CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_TKIP |
2718                     CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_CCMP);
2719             if (wrqu->param.value & IW_AUTH_CIPHER_WEP40) {
2720                 priv->connection_config.encryptionModeMask |= CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP40;
2721             }
2722             if (wrqu->param.value & IW_AUTH_CIPHER_WEP104) {
2723                 priv->connection_config.encryptionModeMask |= CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_WEP104;
2724             }
2725             if (wrqu->param.value & IW_AUTH_CIPHER_TKIP) {
2726                 priv->connection_config.encryptionModeMask |= CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_TKIP;
2727             }
2728             if (wrqu->param.value & IW_AUTH_CIPHER_CCMP) {
2729                 priv->connection_config.encryptionModeMask |= CSR_WIFI_SME_ENCRYPTION_CIPHER_GROUP_CCMP;
2730             }
2731
2732             break;
2733
2734         case IW_AUTH_KEY_MGMT:
2735             unifi_trace(priv, UDBG1, "IW_AUTH_KEY_MGMT: %d\n", wrqu->param.value);
2736             /*
2737                IW_AUTH_KEY_MGMT_802_1X 1
2738                IW_AUTH_KEY_MGMT_PSK    2
2739                */
2740             if (priv->connection_config.authModeMask & (CSR_WIFI_SME_AUTH_MODE_8021X_WPA | CSR_WIFI_SME_AUTH_MODE_8021X_WPAPSK)) {
2741                 /* Check for explicitly set mode. */
2742                 if (wrqu->param.value == IW_AUTH_KEY_MGMT_802_1X) {
2743                     priv->connection_config.authModeMask &= ~CSR_WIFI_SME_AUTH_MODE_8021X_WPAPSK;
2744                 }
2745                 if (wrqu->param.value == IW_AUTH_KEY_MGMT_PSK) {
2746                     priv->connection_config.authModeMask &= ~CSR_WIFI_SME_AUTH_MODE_8021X_WPA;
2747                 }
2748                 unifi_trace(priv, UDBG5, "IW_AUTH_KEY_MGMT: WPA: %d\n",
2749                             priv->connection_config.authModeMask);
2750             }
2751             if (priv->connection_config.authModeMask & (CSR_WIFI_SME_AUTH_MODE_8021X_WPA2 | CSR_WIFI_SME_AUTH_MODE_8021X_WPA2PSK)) {
2752                 /* Check for explicitly set mode. */
2753                 if (wrqu->param.value == IW_AUTH_KEY_MGMT_802_1X) {
2754                     priv->connection_config.authModeMask &= ~CSR_WIFI_SME_AUTH_MODE_8021X_WPA2PSK;
2755                 }
2756                 if (wrqu->param.value == IW_AUTH_KEY_MGMT_PSK) {
2757                     priv->connection_config.authModeMask &= ~CSR_WIFI_SME_AUTH_MODE_8021X_WPA2;
2758                 }
2759                 unifi_trace(priv, UDBG5, "IW_AUTH_KEY_MGMT: WPA2: %d\n",
2760                             priv->connection_config.authModeMask);
2761             }
2762
2763             break;
2764         case IW_AUTH_TKIP_COUNTERMEASURES:
2765             /*
2766              * Set to true at the start of the 60 second backup-off period
2767              * following 2 MichaelMIC failures within 60s.
2768              */
2769             unifi_trace(priv, UDBG1, "IW_AUTH_TKIP_COUNTERMEASURES: %d\n", wrqu->param.value);
2770             break;
2771
2772         case IW_AUTH_DROP_UNENCRYPTED:
2773             /*
2774              * Set to true on init.
2775              * Set to false just before associate if encryption will not be
2776              * required.
2777              *
2778              * Note this is not the same as the 802.1X controlled port
2779              */
2780             unifi_trace(priv, UDBG1, "IW_AUTH_DROP_UNENCRYPTED: %d\n", wrqu->param.value);
2781             break;
2782
2783         case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2784             /*
2785              * This is set by wpa_supplicant to allow unencrypted EAPOL messages
2786              * even if pairwise keys are set when not using WPA. IEEE 802.1X
2787              * specifies that these frames are not encrypted, but WPA encrypts
2788              * them when pairwise keys are in use.
2789              * I think the UniFi f/w handles this decision for us.
2790              */
2791             unifi_trace(priv, UDBG1, "IW_AUTH_RX_UNENCRYPTED_EAPOL: %d\n", wrqu->param.value);
2792             break;
2793
2794         case IW_AUTH_ROAMING_CONTROL:
2795             unifi_trace(priv, UDBG1, "IW_AUTH_ROAMING_CONTROL: %d\n", wrqu->param.value);
2796             break;
2797
2798         default:
2799             unifi_trace(priv, UDBG1, "Unsupported auth param %d to 0x%X\n",
2800                         wrqu->param.flags & IW_AUTH_INDEX,
2801                         wrqu->param.value);
2802             return -EOPNOTSUPP;
2803     }
2804
2805     unifi_trace(priv, UDBG2, "authModeMask = %d", priv->connection_config.authModeMask);
2806
2807     return 0;
2808 } /* _unifi_siwauth() */
2809
2810
2811 static int
2812 unifi_siwauth(struct net_device *dev, struct iw_request_info *info,
2813         union iwreq_data *wrqu, char *extra)
2814 {
2815     int err = 0;
2816
2817     UF_RTNL_UNLOCK();
2818     err = _unifi_siwauth(dev, info, wrqu, extra);
2819     UF_RTNL_LOCK();
2820
2821     return err;
2822 } /* unifi_siwauth() */
2823
2824
2825 static int
2826 unifi_giwauth(struct net_device *dev, struct iw_request_info *info,
2827         union iwreq_data *wrqu, char *extra)
2828 {
2829     unifi_trace(NULL, UDBG2, "unifi_giwauth\n");
2830     return -EOPNOTSUPP;
2831 } /* unifi_giwauth() */
2832
2833 /*
2834  * ---------------------------------------------------------------------------
2835  *  unifi_siwencodeext
2836  *  unifi_giwencodeext
2837  *
2838  *      Handlers for SIOCSIWENCODEEXT, SIOCGIWENCODEEXT - set/get
2839  *      encoding token & mode
2840  *
2841  *  Arguments:
2842  *      None.
2843  *
2844  *  Returns:
2845  *      None.
2846  *
2847  *  Notes:
2848  *      For WPA/WPA2 we don't take note of the IW_ENCODE_EXT_SET_TX_KEY flag.
2849  *      This flag means "use this key to encode transmissions"; we just
2850  *      assume only one key will be set and that is the one to use.
2851  * ---------------------------------------------------------------------------
2852  */
2853 static int
2854 _unifi_siwencodeext(struct net_device *dev, struct iw_request_info *info,
2855         union iwreq_data *wrqu, char *extra)
2856 {
2857     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2858     unifi_priv_t *priv = interfacePriv->privPtr;
2859     struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2860     int r = 0;
2861     unsigned char *keydata;
2862     unsigned char tkip_key[32];
2863     int keyid;
2864     unsigned char *a = (unsigned char *)ext->addr.sa_data;
2865     CsrWifiSmeKey sme_key;
2866     CsrWifiSmeKeyType key_type;
2867
2868     CHECK_INITED(priv);
2869
2870     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2871        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2872        unifi_error(priv, "unifi_siwencodeext: not permitted in Mode %d\n",
2873                                       interfacePriv->interfaceMode);
2874        return -EPERM;
2875     }
2876
2877
2878     unifi_trace(priv, UDBG1, "siwencodeext: flags=0x%X, alg=%d, ext_flags=0x%X, len=%d, index=%d,\n",
2879                 wrqu->encoding.flags, ext->alg, ext->ext_flags,
2880                 ext->key_len, (wrqu->encoding.flags & IW_ENCODE_INDEX));
2881         unifi_trace(priv, UDBG3, "              addr=%pM\n", a);
2882
2883     if ((ext->key_len == 0) && (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
2884         /* This means use a different key (given by key_idx) for Tx. */
2885         /* NYI */
2886         unifi_trace(priv, UDBG1, KERN_ERR "unifi_siwencodeext: NYI should change tx key id here!!\n");
2887         return -ENOTSUPP;
2888     }
2889
2890     memset(&sme_key, 0, sizeof(sme_key));
2891
2892     keydata = (unsigned char *)(ext + 1);
2893     keyid = (wrqu->encoding.flags & IW_ENCODE_INDEX);
2894
2895     /*
2896      * Check for request to delete keys for an address.
2897      */
2898     /* Pick out request for no privacy. */
2899     if (ext->alg == IW_ENCODE_ALG_NONE) {
2900
2901         unifi_trace(priv, UDBG1, "Deleting %s key %d\n",
2902                     (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) ? "GROUP" : "PAIRWISE",
2903                     keyid);
2904
2905         if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2906             sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_GROUP;
2907         } else {
2908             sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_PAIRWISE;
2909         }
2910         sme_key.keyIndex = (keyid - 1);
2911         sme_key.keyLength = 0;
2912         sme_key.authenticator = 0;
2913         memcpy(sme_key.address.a, a, ETH_ALEN);
2914         UF_RTNL_UNLOCK();
2915         r = sme_mgt_key(priv, &sme_key, CSR_WIFI_SME_LIST_ACTION_REMOVE);
2916         UF_RTNL_LOCK();
2917         if (r) {
2918             unifi_error(priv, "Delete key request was rejected with result %d\n", r);
2919             return convert_sme_error(r);
2920         }
2921
2922         return 0;
2923     }
2924
2925     /*
2926      * Request is to set a key, not delete
2927      */
2928
2929     /* Pick out WEP and use set_wep_key(). */
2930     if (ext->alg == IW_ENCODE_ALG_WEP) {
2931         /* WEP-40, WEP-104 */
2932
2933         /* Check for valid key length */
2934         if (!((ext->key_len == 5) || (ext->key_len == 13))) {
2935             unifi_trace(priv, UDBG1, KERN_ERR "Invalid length for WEP key: %d\n", ext->key_len);
2936             return -EINVAL;
2937         }
2938
2939         unifi_trace(priv, UDBG1, "Setting WEP key %d tx:%d\n",
2940                     keyid, ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY);
2941
2942         if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2943             sme_key.wepTxKey = TRUE;
2944             sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_PAIRWISE;
2945         } else {
2946             sme_key.wepTxKey = FALSE;
2947             sme_key.keyType = CSR_WIFI_SME_KEY_TYPE_GROUP;
2948         }
2949         sme_key.keyIndex = (keyid - 1);
2950         sme_key.keyLength = ext->key_len;
2951         sme_key.authenticator = 0;
2952         memset(sme_key.address.a, 0xFF, ETH_ALEN);
2953         memcpy(sme_key.key, keydata, ext->key_len);
2954         UF_RTNL_UNLOCK();
2955         r = sme_mgt_key(priv, &sme_key, CSR_WIFI_SME_LIST_ACTION_ADD);
2956         UF_RTNL_LOCK();
2957         if (r) {
2958             unifi_error(priv, "siwencodeext: Set key failed (%d)", r);
2959             return convert_sme_error(r);
2960         }
2961
2962         return 0;
2963     }
2964
2965     /*
2966      *
2967      * If we reach here, we are dealing with a WPA/WPA2 key
2968      *
2969      */
2970     if (ext->key_len > 32) {
2971         return -EINVAL;
2972     }
2973
2974     /*
2975      * TKIP keys from wpa_supplicant need swapping.
2976      * What about other supplicants (when they come along)?
2977      */
2978     if ((ext->alg == IW_ENCODE_ALG_TKIP) && (ext->key_len == 32)) {
2979         memcpy(tkip_key, keydata, 16);
2980         memcpy(tkip_key + 16, keydata + 24, 8);
2981         memcpy(tkip_key + 24, keydata + 16, 8);
2982         keydata = tkip_key;
2983     }
2984
2985     key_type = (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) ?
2986         CSR_WIFI_SME_KEY_TYPE_GROUP : /* Group Key */
2987         CSR_WIFI_SME_KEY_TYPE_PAIRWISE; /* Pairwise Key */
2988
2989     sme_key.keyType = key_type;
2990     sme_key.keyIndex = (keyid - 1);
2991     sme_key.keyLength = ext->key_len;
2992     sme_key.authenticator = 0;
2993     memcpy(sme_key.address.a, ext->addr.sa_data, ETH_ALEN);
2994     if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2995
2996                 unifi_trace(priv, UDBG5, "RSC first 6 bytes = %*phC\n",
2997                                          6, ext->rx_seq);
2998
2999         /* memcpy((u8*)(&sme_key.keyRsc), ext->rx_seq, 8); */
3000         sme_key.keyRsc[0] = ext->rx_seq[1] << 8 | ext->rx_seq[0];
3001         sme_key.keyRsc[1] = ext->rx_seq[3] << 8 | ext->rx_seq[2];
3002         sme_key.keyRsc[2] = ext->rx_seq[5] << 8 | ext->rx_seq[4];
3003         sme_key.keyRsc[3] = ext->rx_seq[7] << 8 | ext->rx_seq[6];
3004
3005     }
3006
3007     memcpy(sme_key.key, keydata, ext->key_len);
3008     UF_RTNL_UNLOCK();
3009     r = sme_mgt_key(priv, &sme_key, CSR_WIFI_SME_LIST_ACTION_ADD);
3010     UF_RTNL_LOCK();
3011     if (r) {
3012         unifi_error(priv, "SETKEYS request was rejected with result %d\n", r);
3013         return convert_sme_error(r);
3014     }
3015
3016     return r;
3017 } /* _unifi_siwencodeext() */
3018
3019
3020 static int
3021 unifi_siwencodeext(struct net_device *dev, struct iw_request_info *info,
3022         union iwreq_data *wrqu, char *extra)
3023 {
3024     int err = 0;
3025
3026     err = _unifi_siwencodeext(dev, info, wrqu, extra);
3027
3028     return err;
3029 } /* unifi_siwencodeext() */
3030
3031
3032 static int
3033 unifi_giwencodeext(struct net_device *dev, struct iw_request_info *info,
3034         union iwreq_data *wrqu, char *extra)
3035 {
3036     return -EOPNOTSUPP;
3037 } /* unifi_giwencodeext() */
3038
3039
3040 /*
3041  * ---------------------------------------------------------------------------
3042  *  unifi_siwpmksa
3043  *
3044  *      SIOCSIWPMKSA - PMKSA cache operation
3045  *      The caller passes a pmksa structure:
3046  *        - cmd         one of ADD, REMOVE, FLUSH
3047  *        - bssid       MAC address
3048  *        - pmkid       ID string (16 bytes)
3049  *
3050  *  Arguments:
3051  *      None.
3052  *
3053  *  Returns:
3054  *      None.
3055  *
3056  *  Notes:
3057  *      This is not needed since we provide a siwgenie method.
3058  * ---------------------------------------------------------------------------
3059  */
3060 #define UNIFI_PMKID_KEY_SIZE 16
3061 static int
3062 unifi_siwpmksa(struct net_device *dev, struct iw_request_info *info,
3063         union iwreq_data *wrqu, char *extra)
3064 {
3065     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
3066     unifi_priv_t *priv = interfacePriv->privPtr;
3067     struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
3068     CsrResult r = 0;
3069     CsrWifiSmePmkidList pmkid_list;
3070     CsrWifiSmePmkid pmkid;
3071     CsrWifiSmeListAction action;
3072
3073     CHECK_INITED(priv);
3074
3075     if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
3076        interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
3077        unifi_error(priv, "unifi_siwpmksa: not permitted in Mode %d\n",
3078                                       interfacePriv->interfaceMode);
3079        return -EPERM;
3080     }
3081
3082
3083         unifi_trace(priv, UDBG1, "SIWPMKSA: cmd %d, %pM\n", pmksa->cmd,
3084                 pmksa->bssid.sa_data);
3085
3086     pmkid_list.pmkids = NULL;
3087     switch (pmksa->cmd) {
3088       case IW_PMKSA_ADD:
3089         pmkid_list.pmkids = &pmkid;
3090         action = CSR_WIFI_SME_LIST_ACTION_ADD;
3091         pmkid_list.pmkidsCount = 1;
3092         memcpy(pmkid.bssid.a, pmksa->bssid.sa_data, ETH_ALEN);
3093         memcpy(pmkid.pmkid, pmksa->pmkid, UNIFI_PMKID_KEY_SIZE);
3094         break;
3095       case IW_PMKSA_REMOVE:
3096         pmkid_list.pmkids = &pmkid;
3097         action = CSR_WIFI_SME_LIST_ACTION_REMOVE;
3098         pmkid_list.pmkidsCount = 1;
3099         memcpy(pmkid.bssid.a, pmksa->bssid.sa_data, ETH_ALEN);
3100         memcpy(pmkid.pmkid, pmksa->pmkid, UNIFI_PMKID_KEY_SIZE);
3101         break;
3102       case IW_PMKSA_FLUSH:
3103         /* Replace current PMKID's with an empty list */
3104         pmkid_list.pmkidsCount = 0;
3105         action = CSR_WIFI_SME_LIST_ACTION_FLUSH;
3106         break;
3107       default:
3108         unifi_notice(priv, "SIWPMKSA: Unknown command (0x%x)\n", pmksa->cmd);
3109         return -EINVAL;
3110     }
3111
3112     /* Set the Value the pmkid's will have 1 added OR 1 removed OR be cleared at this point */
3113     UF_RTNL_UNLOCK();
3114     r = sme_mgt_pmkid(priv, action, &pmkid_list);
3115     UF_RTNL_LOCK();
3116     if (r) {
3117         unifi_error(priv, "SIWPMKSA: Set PMKID's Failed.\n");
3118     }
3119
3120     return r;
3121
3122 } /* unifi_siwpmksa() */
3123
3124
3125 /*
3126  * ---------------------------------------------------------------------------
3127  *  unifi_get_wireless_stats
3128  *
3129  *      get_wireless_stats method for Linux wireless extensions.
3130  *
3131  *  Arguments:
3132  *      dev             Pointer to associated netdevice.
3133  *
3134  *  Returns:
3135  *      Pointer to iw_statistics struct.
3136  * ---------------------------------------------------------------------------
3137  */
3138 struct iw_statistics *
3139 unifi_get_wireless_stats(struct net_device *dev)
3140 {
3141     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
3142     unifi_priv_t *priv = interfacePriv->privPtr;
3143
3144     if (priv->init_progress != UNIFI_INIT_COMPLETED) {
3145         return NULL;
3146     }
3147
3148     return &priv->wext_wireless_stats;
3149 } /* unifi_get_wireless_stats() */
3150
3151
3152 /*
3153  * Structures to export the Wireless Handlers
3154  */
3155
3156 static const struct iw_priv_args unifi_private_args[] = {
3157     /*{ cmd,         set_args,                            get_args, name } */
3158     { SIOCIWS80211POWERSAVEPRIV, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
3159         IW_PRIV_TYPE_NONE, "iwprivs80211ps" },
3160     { SIOCIWG80211POWERSAVEPRIV, IW_PRIV_TYPE_NONE,
3161         IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IWPRIV_POWER_SAVE_MAX_STRING, "iwprivg80211ps" },
3162     { SIOCIWS80211RELOADDEFAULTSPRIV, IW_PRIV_TYPE_NONE,
3163         IW_PRIV_TYPE_NONE, "iwprivsdefs" },
3164     { SIOCIWSSMEDEBUGPRIV, IW_PRIV_TYPE_CHAR | IWPRIV_SME_DEBUG_MAX_STRING, IW_PRIV_TYPE_NONE, "iwprivssmedebug" },
3165 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
3166     { SIOCIWSCONFWAPIPRIV, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
3167         IW_PRIV_TYPE_NONE, "iwprivsconfwapi" },
3168     { SIOCIWSWAPIKEYPRIV, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(unifiio_wapi_key_t),
3169         IW_PRIV_TYPE_NONE, "iwprivswpikey" },
3170 #endif
3171 #ifdef CSR_SUPPORT_WEXT_AP
3172     { SIOCIWSAPCFGPRIV, IW_PRIV_TYPE_CHAR | 256, IW_PRIV_TYPE_NONE, "AP_SET_CFG" },
3173     { SIOCIWSAPSTARTPRIV, 0,IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED|IWPRIV_SME_MAX_STRING,"AP_BSS_START" },
3174     { SIOCIWSAPSTOPPRIV, IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|0,
3175       IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|0, "AP_BSS_STOP" },
3176 #ifdef ANDROID_BUILD
3177     { SIOCIWSFWRELOADPRIV, IW_PRIV_TYPE_CHAR |256,
3178       IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|0, "WL_FW_RELOAD" },
3179     { SIOCIWSSTACKSTART, 0,
3180       IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|IWPRIV_SME_MAX_STRING, "START" },
3181     { SIOCIWSSTACKSTOP, 0,
3182       IW_PRIV_TYPE_CHAR |IW_PRIV_SIZE_FIXED|IWPRIV_SME_MAX_STRING, "STOP" },
3183 #endif /* ANDROID_BUILD */
3184 #endif /* CSR_SUPPORT_WEXT_AP */
3185 };
3186
3187 static const iw_handler unifi_handler[] =
3188 {
3189     (iw_handler) unifi_siwcommit,           /* SIOCSIWCOMMIT */
3190     (iw_handler) unifi_giwname,             /* SIOCGIWNAME */
3191     (iw_handler) NULL,                      /* SIOCSIWNWID */
3192     (iw_handler) NULL,                      /* SIOCGIWNWID */
3193     (iw_handler) unifi_siwfreq,             /* SIOCSIWFREQ */
3194     (iw_handler) unifi_giwfreq,             /* SIOCGIWFREQ */
3195     (iw_handler) unifi_siwmode,             /* SIOCSIWMODE */
3196     (iw_handler) unifi_giwmode,             /* SIOCGIWMODE */
3197     (iw_handler) NULL,                      /* SIOCSIWSENS */
3198     (iw_handler) NULL,                      /* SIOCGIWSENS */
3199     (iw_handler) NULL,                      /* SIOCSIWRANGE */
3200     (iw_handler) unifi_giwrange,            /* SIOCGIWRANGE */
3201     (iw_handler) NULL,                      /* SIOCSIWPRIV */
3202     (iw_handler) NULL,                      /* SIOCGIWPRIV */
3203     (iw_handler) NULL,                      /* SIOCSIWSTATS */
3204     (iw_handler) NULL,                      /* SIOCGIWSTATS */
3205     (iw_handler) NULL,                      /* SIOCSIWSPY */
3206     (iw_handler) NULL,                      /* SIOCGIWSPY */
3207     (iw_handler) NULL,                      /* SIOCSIWTHRSPY */
3208     (iw_handler) NULL,                      /* SIOCGIWTHRSPY */
3209     (iw_handler) unifi_siwap,               /* SIOCSIWAP */
3210     (iw_handler) unifi_giwap,               /* SIOCGIWAP */
3211 #if WIRELESS_EXT > 17
3212     /* WPA : IEEE 802.11 MLME requests */
3213     unifi_siwmlme,              /* SIOCSIWMLME, request MLME operation */
3214 #else
3215     (iw_handler) NULL,                      /* -- hole -- */
3216 #endif
3217     (iw_handler) NULL,                      /* SIOCGIWAPLIST */
3218     (iw_handler) unifi_siwscan,             /* SIOCSIWSCAN */
3219     (iw_handler) unifi_giwscan,             /* SIOCGIWSCAN */
3220     (iw_handler) unifi_siwessid,            /* SIOCSIWESSID */
3221     (iw_handler) unifi_giwessid,            /* SIOCGIWESSID */
3222     (iw_handler) NULL,                      /* SIOCSIWNICKN */
3223     (iw_handler) NULL,                      /* SIOCGIWNICKN */
3224     (iw_handler) NULL,                      /* -- hole -- */
3225     (iw_handler) NULL,                      /* -- hole -- */
3226     unifi_siwrate,                          /* SIOCSIWRATE */
3227     unifi_giwrate,                          /* SIOCGIWRATE */
3228     unifi_siwrts,                           /* SIOCSIWRTS */
3229     unifi_giwrts,                           /* SIOCGIWRTS */
3230     unifi_siwfrag,                          /* SIOCSIWFRAG */
3231     unifi_giwfrag,                          /* SIOCGIWFRAG */
3232     (iw_handler) NULL,                      /* SIOCSIWTXPOW */
3233     (iw_handler) NULL,                      /* SIOCGIWTXPOW */
3234     (iw_handler) NULL,                      /* SIOCSIWRETRY */
3235     (iw_handler) NULL,                      /* SIOCGIWRETRY */
3236     unifi_siwencode,                        /* SIOCSIWENCODE */
3237     unifi_giwencode,                        /* SIOCGIWENCODE */
3238     unifi_siwpower,                         /* SIOCSIWPOWER */
3239     unifi_giwpower,                         /* SIOCGIWPOWER */
3240 #if WIRELESS_EXT > 17
3241     (iw_handler) NULL,                      /* -- hole -- */
3242     (iw_handler) NULL,                      /* -- hole -- */
3243
3244     /* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM). */
3245     unifi_siwgenie,             /* SIOCSIWGENIE */      /* set generic IE */
3246     unifi_giwgenie,             /* SIOCGIWGENIE */      /* get generic IE */
3247
3248     /* WPA : Authentication mode parameters */
3249     unifi_siwauth,              /* SIOCSIWAUTH */       /* set authentication mode params */
3250     unifi_giwauth,              /* SIOCGIWAUTH */       /* get authentication mode params */
3251
3252     /* WPA : Extended version of encoding configuration */
3253     unifi_siwencodeext,         /* SIOCSIWENCODEEXT */  /* set encoding token & mode */
3254     unifi_giwencodeext,         /* SIOCGIWENCODEEXT */  /* get encoding token & mode */
3255
3256     /* WPA2 : PMKSA cache management */
3257     unifi_siwpmksa,             /* SIOCSIWPMKSA */      /* PMKSA cache operation */
3258     (iw_handler) NULL,          /* -- hole -- */
3259 #endif /* WIRELESS_EXT > 17 */
3260 };
3261
3262
3263 static const iw_handler unifi_private_handler[] =
3264 {
3265     iwprivs80211ps,                 /* SIOCIWFIRSTPRIV */
3266     iwprivg80211ps,                 /* SIOCIWFIRSTPRIV + 1 */
3267     iwprivsdefs,                    /* SIOCIWFIRSTPRIV + 2 */
3268     (iw_handler) NULL,
3269 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
3270     iwprivsconfwapi,                /* SIOCIWFIRSTPRIV + 4 */
3271     (iw_handler) NULL,              /* SIOCIWFIRSTPRIV + 5 */
3272     iwprivswpikey,                  /* SIOCIWFIRSTPRIV + 6 */
3273 #else
3274     (iw_handler) NULL,
3275     (iw_handler) NULL,
3276     (iw_handler) NULL,
3277 #endif
3278     (iw_handler) NULL,
3279     iwprivssmedebug,                /* SIOCIWFIRSTPRIV + 8 */
3280 #ifdef CSR_SUPPORT_WEXT_AP
3281     (iw_handler) NULL,
3282     iwprivsapconfig,
3283     (iw_handler) NULL,
3284     iwprivsapstart,
3285     (iw_handler) NULL,
3286     iwprivsapstop,
3287     (iw_handler) NULL,
3288 #ifdef ANDROID_BUILD
3289     iwprivsapfwreload,
3290     (iw_handler) NULL,
3291     iwprivsstackstart,
3292     (iw_handler) NULL,
3293     iwprivsstackstop,
3294 #else
3295     (iw_handler) NULL,
3296     (iw_handler) NULL,
3297     (iw_handler) NULL,
3298     (iw_handler) NULL,
3299     (iw_handler) NULL,
3300 #endif /* ANDROID_BUILD */
3301 #else
3302     (iw_handler) NULL,
3303     (iw_handler) NULL,
3304     (iw_handler) NULL,
3305     (iw_handler) NULL,
3306     (iw_handler) NULL,
3307     (iw_handler) NULL,
3308     (iw_handler) NULL,
3309     (iw_handler) NULL,
3310     (iw_handler) NULL,
3311     (iw_handler) NULL,
3312     (iw_handler) NULL,
3313     (iw_handler) NULL,
3314 #endif /* CSR_SUPPORT_WEXT_AP */
3315 };
3316
3317 struct iw_handler_def unifi_iw_handler_def =
3318 {
3319     .num_standard       = sizeof(unifi_handler) / sizeof(iw_handler),
3320     .num_private        = sizeof(unifi_private_handler) / sizeof(iw_handler),
3321     .num_private_args   = sizeof(unifi_private_args) / sizeof(struct iw_priv_args),
3322     .standard           = (iw_handler *) unifi_handler,
3323     .private            = (iw_handler *) unifi_private_handler,
3324     .private_args       = (struct iw_priv_args *) unifi_private_args,
3325 #if IW_HANDLER_VERSION >= 6
3326     .get_wireless_stats = unifi_get_wireless_stats,
3327 #endif
3328 };
3329
3330