spi/topcliff-pch: Fix Kconfig dependencies
[cascardo/linux.git] / drivers / staging / rtl8187se / ieee80211 / ieee80211_wx.c
1 /*
2  *  Copyright(c) 2004 Intel Corporation. All rights reserved.
3  *
4  * Portions of this file are based on the WEP enablement code provided by the
5  * Host AP project hostap-drivers v0.1.3
6  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7  * <jkmaline@cc.hut.fi>
8  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of version 2 of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17  * more details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program; if not, write to the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The full GNU General Public License is included in this distribution in the
24  * file called LICENSE.
25  *
26  * Contact Information:
27  * James P. Ketrenos <ipw2100-admin@linux.intel.com>
28  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29  */
30
31 #include <linux/wireless.h>
32 #include <linux/kmod.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/etherdevice.h>
36
37 #include "ieee80211.h"
38 static const char *ieee80211_modes[] = {
39         "?", "a", "b", "ab", "g", "ag", "bg", "abg"
40 };
41
42 #define MAX_CUSTOM_LEN 64
43 static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
44                                            char *start, char *stop,
45                                            struct ieee80211_network *network,
46                                            struct iw_request_info *info)
47 {
48         char custom[MAX_CUSTOM_LEN];
49         char *p;
50         struct iw_event iwe;
51         int i, j;
52         u8 max_rate, rate;
53
54         /* First entry *MUST* be the AP MAC address */
55         iwe.cmd = SIOCGIWAP;
56         iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
57         ether_addr_copy(iwe.u.ap_addr.sa_data, network->bssid);
58         start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
59
60         /* Remaining entries will be displayed in the order we provide them */
61
62         /* Add the ESSID */
63         iwe.cmd = SIOCGIWESSID;
64         iwe.u.data.flags = 1;
65         if (network->ssid_len == 0) {
66                 iwe.u.data.length = sizeof("<hidden>");
67                 start = iwe_stream_add_point(info, start, stop, &iwe, "<hidden>");
68         } else {
69                 iwe.u.data.length = min_t(u8, network->ssid_len, 32);
70                 start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid);
71         }
72         /* Add the protocol name */
73         iwe.cmd = SIOCGIWNAME;
74         snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]);
75         start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
76
77         /* Add mode */
78         iwe.cmd = SIOCGIWMODE;
79         if (network->capability &
80             (WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) {
81                 if (network->capability & WLAN_CAPABILITY_BSS)
82                         iwe.u.mode = IW_MODE_MASTER;
83                 else
84                         iwe.u.mode = IW_MODE_ADHOC;
85
86                 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
87         }
88
89         /* Add frequency/channel */
90         iwe.cmd = SIOCGIWFREQ;
91         iwe.u.freq.m = network->channel;
92         iwe.u.freq.e = 0;
93         iwe.u.freq.i = 0;
94         start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
95
96         /* Add encryption capability */
97         iwe.cmd = SIOCGIWENCODE;
98         if (network->capability & WLAN_CAPABILITY_PRIVACY)
99                 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
100         else
101                 iwe.u.data.flags = IW_ENCODE_DISABLED;
102         iwe.u.data.length = 0;
103         start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid);
104
105         /* Add basic and extended rates */
106         max_rate = 0;
107         p = custom;
108         p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
109         for (i = 0, j = 0; i < network->rates_len; ) {
110                 if (j < network->rates_ex_len &&
111                     ((network->rates_ex[j] & 0x7F) <
112                      (network->rates[i] & 0x7F)))
113                         rate = network->rates_ex[j++] & 0x7F;
114                 else
115                         rate = network->rates[i++] & 0x7F;
116                 if (rate > max_rate)
117                         max_rate = rate;
118                 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
119                               "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
120         }
121         for (; j < network->rates_ex_len; j++) {
122                 rate = network->rates_ex[j] & 0x7F;
123                 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
124                               "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
125                 if (rate > max_rate)
126                         max_rate = rate;
127         }
128
129         iwe.cmd = SIOCGIWRATE;
130         iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
131         iwe.u.bitrate.value = max_rate * 500000;
132         start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN);
133
134         iwe.cmd = IWEVCUSTOM;
135         iwe.u.data.length = p - custom;
136         if (iwe.u.data.length)
137                 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
138
139         /* Add quality statistics */
140         /* TODO: Fix these values... */
141         if (network->stats.signal == 0 || network->stats.rssi == 0)
142                 netdev_info(ieee->dev, "========>signal:%d, rssi:%d\n",
143                             network->stats.signal, network->stats.rssi);
144         iwe.cmd = IWEVQUAL;
145         iwe.u.qual.qual = network->stats.signalstrength;
146         iwe.u.qual.level = network->stats.signal;
147         iwe.u.qual.noise = network->stats.noise;
148         iwe.u.qual.updated = network->stats.mask & IEEE80211_STATMASK_WEMASK;
149         if (!(network->stats.mask & IEEE80211_STATMASK_RSSI))
150                 iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
151         if (!(network->stats.mask & IEEE80211_STATMASK_NOISE))
152                 iwe.u.qual.updated |= IW_QUAL_NOISE_INVALID;
153         if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL))
154                 iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID;
155         iwe.u.qual.updated = 7;
156         start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
157
158         iwe.cmd = IWEVCUSTOM;
159         p = custom;
160
161         iwe.u.data.length = p - custom;
162         if (iwe.u.data.length)
163                 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
164
165         memset(&iwe, 0, sizeof(iwe));
166         if (network->wpa_ie_len) {
167                 char buf[MAX_WPA_IE_LEN];
168                 memcpy(buf, network->wpa_ie, network->wpa_ie_len);
169                 iwe.cmd = IWEVGENIE;
170                 iwe.u.data.length = network->wpa_ie_len;
171                 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
172         }
173
174         memset(&iwe, 0, sizeof(iwe));
175         if (network->rsn_ie_len) {
176                 char buf[MAX_WPA_IE_LEN];
177                 memcpy(buf, network->rsn_ie, network->rsn_ie_len);
178                 iwe.cmd = IWEVGENIE;
179                 iwe.u.data.length = network->rsn_ie_len;
180                 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
181         }
182
183         /* Add EXTRA: Age to display seconds since last beacon/probe response
184          * for given network.
185          */
186         iwe.cmd = IWEVCUSTOM;
187         p = custom;
188         p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
189                       " Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100));
190         iwe.u.data.length = p - custom;
191         if (iwe.u.data.length)
192                 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
193
194         return start;
195 }
196
197 int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
198                           struct iw_request_info *info,
199                           union iwreq_data *wrqu, char *extra)
200 {
201         struct ieee80211_network *network;
202         unsigned long flags;
203         int err = 0;
204         char *ev = extra;
205         char *stop = ev + wrqu->data.length;
206         int i = 0;
207
208         IEEE80211_DEBUG_WX("Getting scan\n");
209         down(&ieee->wx_sem);
210         spin_lock_irqsave(&ieee->lock, flags);
211
212         if (!ieee->bHwRadioOff) {
213                 list_for_each_entry(network, &ieee->network_list, list) {
214                         i++;
215
216                         if ((stop-ev) < 200) {
217                                 err = -E2BIG;
218                                 break;
219                         }
220                         if (ieee->scan_age == 0 ||
221                             time_after(network->last_scanned + ieee->scan_age, jiffies)) {
222                                 ev = rtl818x_translate_scan(ieee, ev, stop, network, info);
223                         } else
224                                 IEEE80211_DEBUG_SCAN(
225                                         "Not showing network '%s ("
226                                         "%pM)' due to age (%lums).\n",
227                                         escape_essid(network->ssid,
228                                                      network->ssid_len),
229                                         network->bssid,
230                                         (jiffies - network->last_scanned) / (HZ / 100));
231                 }
232         }
233         spin_unlock_irqrestore(&ieee->lock, flags);
234         up(&ieee->wx_sem);
235         wrqu->data.length = ev -  extra;
236         wrqu->data.flags = 0;
237         IEEE80211_DEBUG_WX("exit: %d networks returned.\n", i);
238
239         return err;
240 }
241
242 int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
243                             struct iw_request_info *info,
244                             union iwreq_data *wrqu, char *keybuf)
245 {
246         struct iw_point *erq = &(wrqu->encoding);
247         struct net_device *dev = ieee->dev;
248         struct ieee80211_security sec = {
249                 .flags = 0
250         };
251         int i, key, key_provided, len;
252         struct ieee80211_crypt_data **crypt;
253
254         IEEE80211_DEBUG_WX("SET_ENCODE\n");
255
256         key = erq->flags & IW_ENCODE_INDEX;
257         if (key) {
258                 if (key > WEP_KEYS)
259                         return -EINVAL;
260                 key--;
261                 key_provided = 1;
262         } else {
263                 key_provided = 0;
264                 key = ieee->tx_keyidx;
265         }
266
267         IEEE80211_DEBUG_WX("Key: %d [%s]\n", key, key_provided ?
268                            "provided" : "default");
269
270         crypt = &ieee->crypt[key];
271
272         if (erq->flags & IW_ENCODE_DISABLED) {
273                 if (key_provided && *crypt) {
274                         IEEE80211_DEBUG_WX("Disabling encryption on key %d.\n",
275                                            key);
276                         ieee80211_crypt_delayed_deinit(ieee, crypt);
277                 } else
278                         IEEE80211_DEBUG_WX("Disabling encryption.\n");
279
280                 /* Check all the keys to see if any are still configured,
281                  * and if no key index was provided, de-init them all.
282                  */
283                 for (i = 0; i < WEP_KEYS; i++) {
284                         if (ieee->crypt[i] != NULL) {
285                                 if (key_provided)
286                                         break;
287                                 ieee80211_crypt_delayed_deinit(
288                                         ieee, &ieee->crypt[i]);
289                         }
290                 }
291
292                 if (i == WEP_KEYS) {
293                         sec.enabled = 0;
294                         sec.level = SEC_LEVEL_0;
295                         sec.flags |= SEC_ENABLED | SEC_LEVEL;
296                 }
297
298                 goto done;
299         }
300
301         sec.enabled = 1;
302         sec.flags |= SEC_ENABLED;
303
304         if (*crypt != NULL && (*crypt)->ops != NULL &&
305             strcmp((*crypt)->ops->name, "WEP") != 0) {
306                 /* changing to use WEP; deinit previously used algorithm
307                  * on this key.
308                  */
309                 ieee80211_crypt_delayed_deinit(ieee, crypt);
310         }
311
312         if (*crypt == NULL) {
313                 struct ieee80211_crypt_data *new_crypt;
314
315                 /* take WEP into use */
316                 new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
317                                     GFP_KERNEL);
318                 if (new_crypt == NULL)
319                         return -ENOMEM;
320                 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
321                 if (!new_crypt->ops)
322                         new_crypt->ops = ieee80211_get_crypto_ops("WEP");
323
324                 if (new_crypt->ops)
325                         new_crypt->priv = new_crypt->ops->init(key);
326
327                 if (!new_crypt->ops || !new_crypt->priv) {
328                         kfree(new_crypt);
329                         new_crypt = NULL;
330
331                         netdev_warn(ieee->dev,
332                                     "could not initialize WEP: load module ieee80211_crypt_wep\n");
333                         return -EOPNOTSUPP;
334                 }
335                 *crypt = new_crypt;
336         }
337
338         /* If a new key was provided, set it up */
339         if (erq->length > 0) {
340                 len = erq->length <= 5 ? 5 : 13;
341                 memcpy(sec.keys[key], keybuf, erq->length);
342                 if (len > erq->length)
343                         memset(sec.keys[key] + erq->length, 0,
344                                len - erq->length);
345                 IEEE80211_DEBUG_WX("Setting key %d to '%s' (%d:%d bytes)\n",
346                                    key, escape_essid(sec.keys[key], len),
347                                    erq->length, len);
348                 sec.key_sizes[key] = len;
349                 (*crypt)->ops->set_key(sec.keys[key], len, NULL,
350                                        (*crypt)->priv);
351                 sec.flags |= (1 << key);
352                 /* This ensures a key will be activated if no key is
353                  * explicitly set.
354                  */
355                 if (key == sec.active_key)
356                         sec.flags |= SEC_ACTIVE_KEY;
357                 ieee->tx_keyidx = key;
358         } else {
359                 len = (*crypt)->ops->get_key(sec.keys[key], WEP_KEY_LEN,
360                                              NULL, (*crypt)->priv);
361                 if (len == 0) {
362                         /* Set a default key of all 0 */
363                         IEEE80211_DEBUG_WX("Setting key %d to all zero.\n",
364                                            key);
365                         memset(sec.keys[key], 0, 13);
366                         (*crypt)->ops->set_key(sec.keys[key], 13, NULL,
367                                                (*crypt)->priv);
368                         sec.key_sizes[key] = 13;
369                         sec.flags |= (1 << key);
370                 }
371
372                 /* No key data - just set the default TX key index */
373                 if (key_provided) {
374                         IEEE80211_DEBUG_WX(
375                                 "Setting key %d to default Tx key.\n", key);
376                         ieee->tx_keyidx = key;
377                         sec.active_key = key;
378                         sec.flags |= SEC_ACTIVE_KEY;
379                 }
380         }
381
382  done:
383         ieee->open_wep = !(erq->flags & IW_ENCODE_RESTRICTED);
384         sec.auth_mode = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
385         sec.flags |= SEC_AUTH_MODE;
386         IEEE80211_DEBUG_WX("Auth: %s\n", sec.auth_mode == WLAN_AUTH_OPEN ?
387                            "OPEN" : "SHARED KEY");
388
389         /* For now we just support WEP, so only set that security level...
390          * TODO: When WPA is added this is one place that needs to change
391          */
392         sec.flags |= SEC_LEVEL;
393         sec.level = SEC_LEVEL_1; /* 40 and 104 bit WEP */
394
395         if (ieee->set_security)
396                 ieee->set_security(dev, &sec);
397
398         /* Do not reset port if card is in Managed mode since resetting will
399          * generate new IEEE 802.11 authentication which may end up in looping
400          * with IEEE 802.1X.  If your hardware requires a reset after WEP
401          * configuration (for example... Prism2), implement the reset_port in
402          * the callbacks structures used to initialize the 802.11 stack.
403          */
404         if (ieee->reset_on_keychange &&
405             ieee->iw_mode != IW_MODE_INFRA &&
406             ieee->reset_port && ieee->reset_port(dev)) {
407                 netdev_dbg(ieee->dev, "reset_port failed\n");
408                 return -EINVAL;
409         }
410         return 0;
411 }
412
413 int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
414                             struct iw_request_info *info,
415                             union iwreq_data *wrqu, char *keybuf)
416 {
417         struct iw_point *erq = &(wrqu->encoding);
418         int len, key;
419         struct ieee80211_crypt_data *crypt;
420
421         IEEE80211_DEBUG_WX("GET_ENCODE\n");
422
423         if (ieee->iw_mode == IW_MODE_MONITOR)
424                 return -1;
425
426         key = erq->flags & IW_ENCODE_INDEX;
427         if (key) {
428                 if (key > WEP_KEYS)
429                         return -EINVAL;
430                 key--;
431         } else
432                 key = ieee->tx_keyidx;
433
434         crypt = ieee->crypt[key];
435         erq->flags = key + 1;
436
437         if (crypt == NULL || crypt->ops == NULL) {
438                 erq->length = 0;
439                 erq->flags |= IW_ENCODE_DISABLED;
440                 return 0;
441         }
442
443         if (strcmp(crypt->ops->name, "WEP") != 0) {
444                 /* only WEP is supported with wireless extensions, so just
445                  * report that encryption is used.
446                  */
447                 erq->length = 0;
448                 erq->flags |= IW_ENCODE_ENABLED;
449                 return 0;
450         }
451
452         len = crypt->ops->get_key(keybuf, WEP_KEY_LEN, NULL, crypt->priv);
453         erq->length = (len >= 0 ? len : 0);
454
455         erq->flags |= IW_ENCODE_ENABLED;
456
457         if (ieee->open_wep)
458                 erq->flags |= IW_ENCODE_OPEN;
459         else
460                 erq->flags |= IW_ENCODE_RESTRICTED;
461
462         return 0;
463 }
464
465 int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
466                                 struct iw_request_info *info,
467                                 union iwreq_data *wrqu, char *extra)
468 {
469         struct net_device *dev = ieee->dev;
470         struct iw_point *encoding = &wrqu->encoding;
471         struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
472         int i, idx, ret = 0;
473         int group_key = 0;
474         const char *alg;
475         struct ieee80211_crypto_ops *ops;
476         struct ieee80211_crypt_data **crypt;
477
478         struct ieee80211_security sec = {
479                 .flags = 0,
480         };
481         idx = encoding->flags & IW_ENCODE_INDEX;
482         if (idx) {
483                 if (idx < 1 || idx > WEP_KEYS)
484                         return -EINVAL;
485                 idx--;
486         } else
487                 idx = ieee->tx_keyidx;
488
489         if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
490                 crypt = &ieee->crypt[idx];
491                 group_key = 1;
492         } else {
493                 /* some Cisco APs use idx>0 for unicast in dynamic WEP */
494                 if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP)
495                         return -EINVAL;
496                 if (ieee->iw_mode == IW_MODE_INFRA)
497                         crypt = &ieee->crypt[idx];
498                 else
499                         return -EINVAL;
500         }
501
502         sec.flags |= SEC_ENABLED;
503         if ((encoding->flags & IW_ENCODE_DISABLED) ||
504             ext->alg == IW_ENCODE_ALG_NONE) {
505                 if (*crypt)
506                         ieee80211_crypt_delayed_deinit(ieee, crypt);
507
508                 for (i = 0; i < WEP_KEYS; i++)
509                         if (ieee->crypt[i] != NULL)
510                                 break;
511
512                 if (i == WEP_KEYS) {
513                         sec.enabled = 0;
514                         sec.level = SEC_LEVEL_0;
515                         sec.flags |= SEC_LEVEL;
516                 }
517                 goto done;
518         }
519
520         sec.enabled = 1;
521
522         switch (ext->alg) {
523         case IW_ENCODE_ALG_WEP:
524                 alg = "WEP";
525                 break;
526         case IW_ENCODE_ALG_TKIP:
527                 alg = "TKIP";
528                 break;
529         case IW_ENCODE_ALG_CCMP:
530                 alg = "CCMP";
531                 break;
532         default:
533                 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
534                                    dev->name, ext->alg);
535                 ret = -EINVAL;
536                 goto done;
537         }
538
539         ops = ieee80211_get_crypto_ops(alg);
540         if (ops == NULL)
541                 ops = ieee80211_get_crypto_ops(alg);
542         if (ops == NULL) {
543                 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
544                                    dev->name, ext->alg);
545                 netdev_err(ieee->dev, "========>unknown crypto alg %d\n",
546                            ext->alg);
547                 ret = -EINVAL;
548                 goto done;
549         }
550
551         if (*crypt == NULL || (*crypt)->ops != ops) {
552                 struct ieee80211_crypt_data *new_crypt;
553
554                 ieee80211_crypt_delayed_deinit(ieee, crypt);
555
556                 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
557                 if (new_crypt == NULL) {
558                         ret = -ENOMEM;
559                         goto done;
560                 }
561                 new_crypt->ops = ops;
562                 if (new_crypt->ops)
563                         new_crypt->priv = new_crypt->ops->init(idx);
564                 if (new_crypt->priv == NULL) {
565                         kfree(new_crypt);
566                         ret = -EINVAL;
567                         goto done;
568                 }
569                 *crypt = new_crypt;
570
571         }
572
573         if (ext->key_len > 0 && (*crypt)->ops->set_key &&
574             (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
575                                    (*crypt)->priv) < 0) {
576                 IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name);
577                 netdev_err(ieee->dev, "key setting failed\n");
578                 ret = -EINVAL;
579                 goto done;
580         }
581 #if 1
582         if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
583                 ieee->tx_keyidx = idx;
584                 sec.active_key = idx;
585                 sec.flags |= SEC_ACTIVE_KEY;
586         }
587
588         if (ext->alg != IW_ENCODE_ALG_NONE) {
589                 memcpy(sec.keys[idx], ext->key, ext->key_len);
590                 sec.key_sizes[idx] = ext->key_len;
591                 sec.flags |= (1 << idx);
592                 if (ext->alg == IW_ENCODE_ALG_WEP) {
593                         sec.flags |= SEC_LEVEL;
594                         sec.level = SEC_LEVEL_1;
595                 } else if (ext->alg == IW_ENCODE_ALG_TKIP) {
596                         sec.flags |= SEC_LEVEL;
597                         sec.level = SEC_LEVEL_2;
598                 } else if (ext->alg == IW_ENCODE_ALG_CCMP) {
599                         sec.flags |= SEC_LEVEL;
600                         sec.level = SEC_LEVEL_3;
601                 }
602                 /* Don't set sec level for group keys. */
603                 if (group_key)
604                         sec.flags &= ~SEC_LEVEL;
605         }
606 #endif
607 done:
608         if (ieee->set_security)
609                 ieee->set_security(ieee->dev, &sec);
610
611         if (ieee->reset_on_keychange &&
612             ieee->iw_mode != IW_MODE_INFRA &&
613             ieee->reset_port && ieee->reset_port(dev)) {
614                 IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name);
615                 return -EINVAL;
616         }
617
618         return ret;
619 }
620
621 int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
622                           struct iw_request_info *info,
623                           union iwreq_data *wrqu, char *extra)
624 {
625         struct iw_mlme *mlme = (struct iw_mlme *) extra;
626 #if 1
627         switch (mlme->cmd) {
628         case IW_MLME_DEAUTH:
629         case IW_MLME_DISASSOC:
630                 ieee80211_disassociate(ieee);
631                 break;
632         default:
633                 return -EOPNOTSUPP;
634         }
635 #endif
636         return 0;
637 }
638
639 int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
640                           struct iw_request_info *info,
641                           struct iw_param *data, char *extra)
642 {
643         switch (data->flags & IW_AUTH_INDEX) {
644         case IW_AUTH_WPA_VERSION:
645                 /* need to support wpa2 here */
646                 break;
647         case IW_AUTH_CIPHER_PAIRWISE:
648         case IW_AUTH_CIPHER_GROUP:
649         case IW_AUTH_KEY_MGMT:
650                 /* Host AP driver does not use these parameters and allows
651                  * wpa_supplicant to control them internally.
652                  */
653                 break;
654         case IW_AUTH_TKIP_COUNTERMEASURES:
655                 ieee->tkip_countermeasures = data->value;
656                 break;
657         case IW_AUTH_DROP_UNENCRYPTED:
658                 ieee->drop_unencrypted = data->value;
659                 break;
660
661         case IW_AUTH_80211_AUTH_ALG:
662                 ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM) ? 1 : 0;
663                 break;
664
665 #if 1
666         case IW_AUTH_WPA_ENABLED:
667                 ieee->wpa_enabled = (data->value) ? 1 : 0;
668                 break;
669
670 #endif
671         case IW_AUTH_RX_UNENCRYPTED_EAPOL:
672                 ieee->ieee802_1x = data->value;
673                 break;
674         case IW_AUTH_PRIVACY_INVOKED:
675                 ieee->privacy_invoked = data->value;
676                 break;
677         default:
678                 return -EOPNOTSUPP;
679         }
680         return 0;
681 }
682
683 #if 1
684 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
685 {
686         u8 *buf = NULL;
687
688         if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
689                 netdev_err(ieee->dev, "return error out, len:%zu\n", len);
690         return -EINVAL;
691         }
692
693         if (len) {
694                 if (len != ie[1]+2) {
695                         netdev_err(ieee->dev, "len:%zu, ie:%d\n", len, ie[1]);
696                         return -EINVAL;
697                 }
698                 buf = kmemdup(ie, len, GFP_KERNEL);
699                 if (buf == NULL)
700                         return -ENOMEM;
701                 kfree(ieee->wpa_ie);
702                 ieee->wpa_ie = buf;
703                 ieee->wpa_ie_len = len;
704         } else {
705                 kfree(ieee->wpa_ie);
706                 ieee->wpa_ie = NULL;
707                 ieee->wpa_ie_len = 0;
708         }
709
710         return 0;
711
712 }
713 #endif