root/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. rtl819x_translate_scan
  2. ieee80211_wx_get_scan
  3. ieee80211_wx_set_encode
  4. ieee80211_wx_get_encode
  5. ieee80211_wx_set_encode_ext
  6. ieee80211_wx_get_encode_ext
  7. ieee80211_wx_set_mlme
  8. ieee80211_wx_set_auth
  9. ieee80211_wx_set_gen_ie

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

/* [<][>][^][v][top][bottom][index][help] */