blob: ec0895f4e8d34863c90486f3eb1738ce2bd8f39b [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: CFG80211
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "cfg80211.h"
21#include "main.h"
22
23/*
24 * This function maps the nl802.11 channel type into driver channel type.
25 *
26 * The mapping is as follows -
27 * NL80211_CHAN_NO_HT -> NO_SEC_CHANNEL
28 * NL80211_CHAN_HT20 -> NO_SEC_CHANNEL
29 * NL80211_CHAN_HT40PLUS -> SEC_CHANNEL_ABOVE
30 * NL80211_CHAN_HT40MINUS -> SEC_CHANNEL_BELOW
31 * Others -> NO_SEC_CHANNEL
32 */
33static int
34mwifiex_cfg80211_channel_type_to_mwifiex_channels(enum nl80211_channel_type
35 channel_type)
36{
37 int channel;
38 switch (channel_type) {
39 case NL80211_CHAN_NO_HT:
40 case NL80211_CHAN_HT20:
41 channel = NO_SEC_CHANNEL;
42 break;
43 case NL80211_CHAN_HT40PLUS:
44 channel = SEC_CHANNEL_ABOVE;
45 break;
46 case NL80211_CHAN_HT40MINUS:
47 channel = SEC_CHANNEL_BELOW;
48 break;
49 default:
50 channel = NO_SEC_CHANNEL;
51 }
52 return channel;
53}
54
55/*
56 * This function maps the driver channel type into nl802.11 channel type.
57 *
58 * The mapping is as follows -
59 * NO_SEC_CHANNEL -> NL80211_CHAN_HT20
60 * SEC_CHANNEL_ABOVE -> NL80211_CHAN_HT40PLUS
61 * SEC_CHANNEL_BELOW -> NL80211_CHAN_HT40MINUS
62 * Others -> NL80211_CHAN_HT20
63 */
64static enum nl80211_channel_type
65mwifiex_channels_to_cfg80211_channel_type(int channel_type)
66{
67 int channel;
68 switch (channel_type) {
69 case NO_SEC_CHANNEL:
70 channel = NL80211_CHAN_HT20;
71 break;
72 case SEC_CHANNEL_ABOVE:
73 channel = NL80211_CHAN_HT40PLUS;
74 break;
75 case SEC_CHANNEL_BELOW:
76 channel = NL80211_CHAN_HT40MINUS;
77 break;
78 default:
79 channel = NL80211_CHAN_HT20;
80 }
81 return channel;
82}
83
84/*
85 * This function checks whether WEP is set.
86 */
87static int
88mwifiex_is_alg_wep(u32 cipher)
89{
90 int alg = 0;
91
92 switch (cipher) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070093 case WLAN_CIPHER_SUITE_WEP40:
94 case WLAN_CIPHER_SUITE_WEP104:
Bing Zhao5e6e3a92011-03-21 18:00:50 -070095 alg = 1;
96 break;
97 default:
98 alg = 0;
99 break;
100 }
101 return alg;
102}
103
104/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700105 * This function retrieves the private structure from kernel wiphy structure.
106 */
107static void *mwifiex_cfg80211_get_priv(struct wiphy *wiphy)
108{
109 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
110}
111
112/*
113 * CFG802.11 operation handler to delete a network key.
114 */
115static int
116mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
117 u8 key_index, bool pairwise, const u8 *mac_addr)
118{
119 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
120 int ret = 0;
121
122 ret = mwifiex_set_encode(priv, NULL, 0, key_index, 1);
123 if (ret) {
124 wiphy_err(wiphy, "deleting the crypto keys\n");
125 return -EFAULT;
126 }
127
128 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
129 return 0;
130}
131
132/*
133 * CFG802.11 operation handler to set Tx power.
134 */
135static int
136mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
137 enum nl80211_tx_power_setting type,
138 int dbm)
139{
140 int ret = 0;
141 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
142
143 ret = mwifiex_set_tx_power(priv, type, dbm);
144
145 return ret;
146}
147
148/*
149 * CFG802.11 operation handler to set Power Save option.
150 *
151 * The timeout value, if provided, is currently ignored.
152 */
153static int
154mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
155 struct net_device *dev,
156 bool enabled, int timeout)
157{
158 int ret = 0;
159 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
160
161 if (timeout)
162 wiphy_dbg(wiphy,
163 "info: ignoring the timeout value"
164 " for IEEE power save\n");
165
166 ret = mwifiex_drv_set_power(priv, enabled);
167
168 return ret;
169}
170
171/*
172 * CFG802.11 operation handler to set the default network key.
173 */
174static int
175mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
176 u8 key_index, bool unicast,
177 bool multicast)
178{
179 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
180 int ret;
181
Amitkumar Karwar2d3d0a82011-04-01 18:36:46 -0700182 /* Return if WEP key not configured */
183 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED)
184 return 0;
185
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700186 ret = mwifiex_set_encode(priv, NULL, 0, key_index, 0);
187
188 wiphy_dbg(wiphy, "info: set default Tx key index\n");
189
190 if (ret)
191 return -EFAULT;
192
193 return 0;
194}
195
196/*
197 * CFG802.11 operation handler to add a network key.
198 */
199static int
200mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
201 u8 key_index, bool pairwise, const u8 *mac_addr,
202 struct key_params *params)
203{
204 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
205 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700206
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700207 ret = mwifiex_set_encode(priv, params->key, params->key_len,
208 key_index, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700209
210 wiphy_dbg(wiphy, "info: crypto keys added\n");
211
212 if (ret)
213 return -EFAULT;
214
215 return 0;
216}
217
218/*
219 * This function sends domain information to the firmware.
220 *
221 * The following information are passed to the firmware -
222 * - Country codes
223 * - Sub bands (first channel, number of channels, maximum Tx power)
224 */
225static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
226{
227 u8 no_of_triplet = 0;
228 struct ieee80211_country_ie_triplet *t;
229 u8 no_of_parsed_chan = 0;
230 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
231 u8 i, flag = 0;
232 enum ieee80211_band band;
233 struct ieee80211_supported_band *sband;
234 struct ieee80211_channel *ch;
235 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
236 struct mwifiex_adapter *adapter = priv->adapter;
237 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
238 int ret = 0;
239
240 /* Set country code */
241 domain_info->country_code[0] = priv->country_code[0];
242 domain_info->country_code[1] = priv->country_code[1];
243 domain_info->country_code[2] = ' ';
244
245 band = mwifiex_band_to_radio_type(adapter->config_bands);
246 if (!wiphy->bands[band]) {
247 wiphy_err(wiphy, "11D: setting domain info in FW\n");
248 return -1;
249 }
250
251 sband = wiphy->bands[band];
252
253 for (i = 0; i < sband->n_channels ; i++) {
254 ch = &sband->channels[i];
255 if (ch->flags & IEEE80211_CHAN_DISABLED)
256 continue;
257
258 if (!flag) {
259 flag = 1;
260 first_chan = (u32) ch->hw_value;
261 next_chan = first_chan;
262 max_pwr = ch->max_power;
263 no_of_parsed_chan = 1;
264 continue;
265 }
266
267 if (ch->hw_value == next_chan + 1 &&
268 ch->max_power == max_pwr) {
269 next_chan++;
270 no_of_parsed_chan++;
271 } else {
272 t = &domain_info->triplet[no_of_triplet];
273 t->chans.first_channel = first_chan;
274 t->chans.num_channels = no_of_parsed_chan;
275 t->chans.max_power = max_pwr;
276 no_of_triplet++;
277 first_chan = (u32) ch->hw_value;
278 next_chan = first_chan;
279 max_pwr = ch->max_power;
280 no_of_parsed_chan = 1;
281 }
282 }
283
284 if (flag) {
285 t = &domain_info->triplet[no_of_triplet];
286 t->chans.first_channel = first_chan;
287 t->chans.num_channels = no_of_parsed_chan;
288 t->chans.max_power = max_pwr;
289 no_of_triplet++;
290 }
291
292 domain_info->no_of_triplet = no_of_triplet;
293 /* Send cmd to FW to set domain info */
294 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
295 HostCmd_ACT_GEN_SET, 0, NULL, NULL);
296 if (ret)
297 wiphy_err(wiphy, "11D: setting domain info in FW\n");
298
299 return ret;
300}
301
302/*
303 * CFG802.11 regulatory domain callback function.
304 *
305 * This function is called when the regulatory domain is changed due to the
306 * following reasons -
307 * - Set by driver
308 * - Set by system core
309 * - Set by user
310 * - Set bt Country IE
311 */
312static int mwifiex_reg_notifier(struct wiphy *wiphy,
313 struct regulatory_request *request)
314{
315 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
316
317 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for domain"
318 " %c%c\n", request->alpha2[0], request->alpha2[1]);
319
320 memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
321
322 switch (request->initiator) {
323 case NL80211_REGDOM_SET_BY_DRIVER:
324 case NL80211_REGDOM_SET_BY_CORE:
325 case NL80211_REGDOM_SET_BY_USER:
326 break;
327 /* Todo: apply driver specific changes in channel flags based
328 on the request initiator if necessary. */
329 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
330 break;
331 }
332 mwifiex_send_domain_info_cmd_fw(wiphy);
333
334 return 0;
335}
336
337/*
338 * This function sets the RF channel.
339 *
340 * This function creates multiple IOCTL requests, populates them accordingly
341 * and issues them to set the band/channel and frequency.
342 */
343static int
344mwifiex_set_rf_channel(struct mwifiex_private *priv,
345 struct ieee80211_channel *chan,
346 enum nl80211_channel_type channel_type)
347{
348 struct mwifiex_chan_freq_power cfp;
349 int ret = 0;
350 int status = 0;
351 struct mwifiex_ds_band_cfg band_cfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352 u32 config_bands = 0;
353 struct wiphy *wiphy = priv->wdev->wiphy;
354
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 if (chan) {
356 memset(&band_cfg, 0, sizeof(band_cfg));
357 /* Set appropriate bands */
358 if (chan->band == IEEE80211_BAND_2GHZ)
359 config_bands = BAND_B | BAND_G | BAND_GN;
360 else
361 config_bands = BAND_AN | BAND_A;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700362 if (priv->bss_mode == NL80211_IFTYPE_STATION
363 || priv->bss_mode == NL80211_IFTYPE_UNSPECIFIED) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700364 band_cfg.config_bands = config_bands;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700365 } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366 band_cfg.config_bands = config_bands;
367 band_cfg.adhoc_start_band = config_bands;
368 }
369 /* Set channel offset */
370 band_cfg.sec_chan_offset =
371 mwifiex_cfg80211_channel_type_to_mwifiex_channels
372 (channel_type);
373 status = mwifiex_radio_ioctl_band_cfg(priv, HostCmd_ACT_GEN_SET,
374 &band_cfg);
375
376 if (status)
377 return -EFAULT;
378 mwifiex_send_domain_info_cmd_fw(wiphy);
379 }
380
381 wiphy_dbg(wiphy, "info: setting band %d, channel offset %d and "
Bing Zhaoeecd8252011-03-28 17:55:41 -0700382 "mode %d\n", config_bands, band_cfg.sec_chan_offset,
383 priv->bss_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700384 if (!chan)
385 return ret;
386
387 memset(&cfp, 0, sizeof(cfp));
388 cfp.freq = chan->center_freq;
389 /* Convert frequency to channel */
390 cfp.channel = ieee80211_frequency_to_channel(chan->center_freq);
391
392 status = mwifiex_bss_ioctl_channel(priv, HostCmd_ACT_GEN_SET, &cfp);
393 if (status)
394 return -EFAULT;
395
396 ret = mwifiex_drv_change_adhoc_chan(priv, cfp.channel);
397
398 return ret;
399}
400
401/*
402 * CFG802.11 operation handler to set channel.
403 *
404 * This function can only be used when station is not connected.
405 */
406static int
407mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
408 struct ieee80211_channel *chan,
409 enum nl80211_channel_type channel_type)
410{
411 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
412
413 if (priv->media_connected) {
414 wiphy_err(wiphy, "This setting is valid only when station "
415 "is not connected\n");
416 return -EINVAL;
417 }
418
419 return mwifiex_set_rf_channel(priv, chan, channel_type);
420}
421
422/*
423 * This function sets the fragmentation threshold.
424 *
425 * This function creates an IOCTL request, populates it accordingly
426 * and issues an IOCTL.
427 *
428 * The fragmentation threshold value must lies between MWIFIEX_FRAG_MIN_VALUE
429 * and MWIFIEX_FRAG_MAX_VALUE.
430 */
431static int
432mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
433{
434 int ret = 0;
435 int status = 0;
436 struct mwifiex_wait_queue *wait = NULL;
437 u8 wait_option = MWIFIEX_IOCTL_WAIT;
438
439 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE
440 || frag_thr > MWIFIEX_FRAG_MAX_VALUE)
441 return -EINVAL;
442
443 wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
444 if (!wait)
445 return -ENOMEM;
446
447 status = mwifiex_snmp_mib_ioctl(priv, wait, FRAG_THRESH_I,
448 HostCmd_ACT_GEN_SET, &frag_thr);
449
450 if (mwifiex_request_ioctl(priv, wait, status, wait_option))
451 ret = -EFAULT;
452
453 kfree(wait);
454 return ret;
455}
456
457/*
458 * This function sets the RTS threshold.
459 *
460 * This function creates an IOCTL request, populates it accordingly
461 * and issues an IOCTL.
462 */
463static int
464mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
465{
466 int ret = 0;
467 struct mwifiex_wait_queue *wait = NULL;
468 int status = 0;
469 u8 wait_option = MWIFIEX_IOCTL_WAIT;
470
471 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
472 rts_thr = MWIFIEX_RTS_MAX_VALUE;
473
474 wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
475 if (!wait)
476 return -ENOMEM;
477
478 status = mwifiex_snmp_mib_ioctl(priv, wait, RTS_THRESH_I,
479 HostCmd_ACT_GEN_SET, &rts_thr);
480
481 if (mwifiex_request_ioctl(priv, wait, status, wait_option))
482 ret = -EFAULT;
483
484 kfree(wait);
485 return ret;
486}
487
488/*
489 * CFG802.11 operation handler to set wiphy parameters.
490 *
491 * This function can be used to set the RTS threshold and the
492 * Fragmentation threshold of the driver.
493 */
494static int
495mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
496{
497 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
498
499 int ret = 0;
500
501 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
502 ret = mwifiex_set_rts(priv, wiphy->rts_threshold);
503
504 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
505 ret = mwifiex_set_frag(priv, wiphy->frag_threshold);
506
507 return ret;
508}
509
510/*
511 * CFG802.11 operation handler to change interface type.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700512 */
513static int
514mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
515 struct net_device *dev,
516 enum nl80211_iftype type, u32 *flags,
517 struct vif_params *params)
518{
519 int ret = 0;
520 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 struct mwifiex_wait_queue *wait = NULL;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700522
523 if (priv->bss_mode == type) {
524 wiphy_warn(wiphy, "already set to required type\n");
525 return 0;
526 }
527
528 priv->bss_mode = type;
529
530 switch (type) {
531 case NL80211_IFTYPE_ADHOC:
532 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_ADHOC;
533 wiphy_dbg(wiphy, "info: setting interface type to adhoc\n");
534 break;
535 case NL80211_IFTYPE_STATION:
536 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
537 wiphy_dbg(wiphy, "info: setting interface type to managed\n");
538 break;
539 case NL80211_IFTYPE_UNSPECIFIED:
540 dev->ieee80211_ptr->iftype = NL80211_IFTYPE_STATION;
541 wiphy_dbg(wiphy, "info: setting interface type to auto\n");
542 return 0;
543 default:
544 wiphy_err(wiphy, "unknown interface type: %d\n", type);
545 return -EINVAL;
546 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700547
548 wait = mwifiex_alloc_fill_wait_queue(priv, MWIFIEX_IOCTL_WAIT);
549 if (!wait)
550 return -ENOMEM;
551
Bing Zhaoeecd8252011-03-28 17:55:41 -0700552 mwifiex_deauthenticate(priv, wait, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553
Marc Yangf986b6d2011-03-28 17:55:42 -0700554 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhaoeecd8252011-03-28 17:55:41 -0700555
556 ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
557 HostCmd_ACT_GEN_SET, 0, wait, NULL);
558 if (!ret)
559 ret = -EINPROGRESS;
560
561 ret = mwifiex_request_ioctl(priv, wait, ret, MWIFIEX_IOCTL_WAIT);
562 if (ret)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 ret = -EFAULT;
564
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 kfree(wait);
566 return ret;
567}
568
569/*
570 * This function dumps the station information on a buffer.
571 *
572 * The following information are shown -
573 * - Total bytes transmitted
574 * - Total bytes received
575 * - Total packets transmitted
576 * - Total packets received
577 * - Signal quality level
578 * - Transmission rate
579 */
580static int
581mwifiex_dump_station_info(struct mwifiex_private *priv,
582 struct station_info *sinfo)
583{
584 struct mwifiex_ds_get_signal signal;
585 struct mwifiex_rate_cfg rate;
586 int ret = 0;
587
588 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
589 STATION_INFO_RX_PACKETS |
590 STATION_INFO_TX_PACKETS
591 | STATION_INFO_SIGNAL | STATION_INFO_TX_BITRATE;
592
593 /* Get signal information from the firmware */
594 memset(&signal, 0, sizeof(struct mwifiex_ds_get_signal));
595 if (mwifiex_get_signal_info(priv, MWIFIEX_IOCTL_WAIT, &signal)) {
596 dev_err(priv->adapter->dev, "getting signal information\n");
597 ret = -EFAULT;
598 }
599
600 if (mwifiex_drv_get_data_rate(priv, &rate)) {
601 dev_err(priv->adapter->dev, "getting data rate\n");
602 ret = -EFAULT;
603 }
604
605 sinfo->rx_bytes = priv->stats.rx_bytes;
606 sinfo->tx_bytes = priv->stats.tx_bytes;
607 sinfo->rx_packets = priv->stats.rx_packets;
608 sinfo->tx_packets = priv->stats.tx_packets;
609 sinfo->signal = priv->w_stats.qual.level;
610 sinfo->txrate.legacy = rate.rate;
611
612 return ret;
613}
614
615/*
616 * CFG802.11 operation handler to get station information.
617 *
618 * This function only works in connected mode, and dumps the
619 * requested station information, if available.
620 */
621static int
622mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
623 u8 *mac, struct station_info *sinfo)
624{
625 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
626 int ret = 0;
627
628 mwifiex_dump_station_info(priv, sinfo);
629
630 if (!priv->media_connected)
631 return -ENOENT;
632 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
633 return -ENOENT;
634
635
636 ret = mwifiex_dump_station_info(priv, sinfo);
637
638 return ret;
639}
640
641/* Supported rates to be advertised to the cfg80211 */
642
643static struct ieee80211_rate mwifiex_rates[] = {
644 {.bitrate = 10, .hw_value = 2, },
645 {.bitrate = 20, .hw_value = 4, },
646 {.bitrate = 55, .hw_value = 11, },
647 {.bitrate = 110, .hw_value = 22, },
648 {.bitrate = 220, .hw_value = 44, },
649 {.bitrate = 60, .hw_value = 12, },
650 {.bitrate = 90, .hw_value = 18, },
651 {.bitrate = 120, .hw_value = 24, },
652 {.bitrate = 180, .hw_value = 36, },
653 {.bitrate = 240, .hw_value = 48, },
654 {.bitrate = 360, .hw_value = 72, },
655 {.bitrate = 480, .hw_value = 96, },
656 {.bitrate = 540, .hw_value = 108, },
657 {.bitrate = 720, .hw_value = 144, },
658};
659
660/* Channel definitions to be advertised to cfg80211 */
661
662static struct ieee80211_channel mwifiex_channels_2ghz[] = {
663 {.center_freq = 2412, .hw_value = 1, },
664 {.center_freq = 2417, .hw_value = 2, },
665 {.center_freq = 2422, .hw_value = 3, },
666 {.center_freq = 2427, .hw_value = 4, },
667 {.center_freq = 2432, .hw_value = 5, },
668 {.center_freq = 2437, .hw_value = 6, },
669 {.center_freq = 2442, .hw_value = 7, },
670 {.center_freq = 2447, .hw_value = 8, },
671 {.center_freq = 2452, .hw_value = 9, },
672 {.center_freq = 2457, .hw_value = 10, },
673 {.center_freq = 2462, .hw_value = 11, },
674 {.center_freq = 2467, .hw_value = 12, },
675 {.center_freq = 2472, .hw_value = 13, },
676 {.center_freq = 2484, .hw_value = 14, },
677};
678
679static struct ieee80211_supported_band mwifiex_band_2ghz = {
680 .channels = mwifiex_channels_2ghz,
681 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
682 .bitrates = mwifiex_rates,
683 .n_bitrates = 14,
684};
685
686static struct ieee80211_channel mwifiex_channels_5ghz[] = {
687 {.center_freq = 5040, .hw_value = 8, },
688 {.center_freq = 5060, .hw_value = 12, },
689 {.center_freq = 5080, .hw_value = 16, },
690 {.center_freq = 5170, .hw_value = 34, },
691 {.center_freq = 5190, .hw_value = 38, },
692 {.center_freq = 5210, .hw_value = 42, },
693 {.center_freq = 5230, .hw_value = 46, },
694 {.center_freq = 5180, .hw_value = 36, },
695 {.center_freq = 5200, .hw_value = 40, },
696 {.center_freq = 5220, .hw_value = 44, },
697 {.center_freq = 5240, .hw_value = 48, },
698 {.center_freq = 5260, .hw_value = 52, },
699 {.center_freq = 5280, .hw_value = 56, },
700 {.center_freq = 5300, .hw_value = 60, },
701 {.center_freq = 5320, .hw_value = 64, },
702 {.center_freq = 5500, .hw_value = 100, },
703 {.center_freq = 5520, .hw_value = 104, },
704 {.center_freq = 5540, .hw_value = 108, },
705 {.center_freq = 5560, .hw_value = 112, },
706 {.center_freq = 5580, .hw_value = 116, },
707 {.center_freq = 5600, .hw_value = 120, },
708 {.center_freq = 5620, .hw_value = 124, },
709 {.center_freq = 5640, .hw_value = 128, },
710 {.center_freq = 5660, .hw_value = 132, },
711 {.center_freq = 5680, .hw_value = 136, },
712 {.center_freq = 5700, .hw_value = 140, },
713 {.center_freq = 5745, .hw_value = 149, },
714 {.center_freq = 5765, .hw_value = 153, },
715 {.center_freq = 5785, .hw_value = 157, },
716 {.center_freq = 5805, .hw_value = 161, },
717 {.center_freq = 5825, .hw_value = 165, },
718};
719
720static struct ieee80211_supported_band mwifiex_band_5ghz = {
721 .channels = mwifiex_channels_5ghz,
722 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
723 .bitrates = mwifiex_rates - 4,
724 .n_bitrates = ARRAY_SIZE(mwifiex_rates) + 4,
725};
726
727
728/* Supported crypto cipher suits to be advertised to cfg80211 */
729
730static const u32 mwifiex_cipher_suites[] = {
731 WLAN_CIPHER_SUITE_WEP40,
732 WLAN_CIPHER_SUITE_WEP104,
733 WLAN_CIPHER_SUITE_TKIP,
734 WLAN_CIPHER_SUITE_CCMP,
735};
736
737/*
738 * CFG802.11 operation handler for disconnection request.
739 *
740 * This function does not work when there is already a disconnection
741 * procedure going on.
742 */
743static int
744mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
745 u16 reason_code)
746{
747 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
748
749 if (priv->disconnect)
750 return -EBUSY;
751
752 priv->disconnect = 1;
753 if (mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL))
754 return -EFAULT;
755
756 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
757 " reason code %d\n", priv->cfg_bssid, reason_code);
758
759 queue_work(priv->workqueue, &priv->cfg_workqueue);
760
761 return 0;
762}
763
764/*
765 * This function informs the CFG802.11 subsystem of a new IBSS.
766 *
767 * The following information are sent to the CFG802.11 subsystem
768 * to register the new IBSS. If we do not register the new IBSS,
769 * a kernel panic will result.
770 * - SSID
771 * - SSID length
772 * - BSSID
773 * - Channel
774 */
775static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
776{
777 int ret = 0;
778 struct ieee80211_channel *chan;
779 struct mwifiex_bss_info bss_info;
780 int ie_len = 0;
781 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
782
783 ret = mwifiex_get_bss_info(priv, &bss_info);
784 if (ret)
785 return ret;
786
787 ie_buf[0] = WLAN_EID_SSID;
788 ie_buf[1] = bss_info.ssid.ssid_len;
789
790 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
791 &bss_info.ssid.ssid,
792 bss_info.ssid.ssid_len);
793 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
794
795 chan = __ieee80211_get_channel(priv->wdev->wiphy,
796 ieee80211_channel_to_frequency(bss_info.bss_chan,
797 priv->curr_bss_params.band));
798
799 cfg80211_inform_bss(priv->wdev->wiphy, chan,
800 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
801 0, ie_buf, ie_len, 0, GFP_KERNEL);
802 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
803
804 return ret;
805}
806
807/*
808 * This function informs the CFG802.11 subsystem of a new BSS connection.
809 *
810 * The following information are sent to the CFG802.11 subsystem
811 * to register the new BSS connection. If we do not register the new BSS,
812 * a kernel panic will result.
813 * - MAC address
814 * - Capabilities
815 * - Beacon period
816 * - RSSI value
817 * - Channel
818 * - Supported rates IE
819 * - Extended capabilities IE
820 * - DS parameter set IE
821 * - HT Capability IE
822 * - Vendor Specific IE (221)
823 * - WPA IE
824 * - RSN IE
825 */
826static int mwifiex_inform_bss_from_scan_result(struct mwifiex_private *priv,
827 struct mwifiex_802_11_ssid *ssid)
828{
829 struct mwifiex_scan_resp scan_resp;
830 struct mwifiex_bssdescriptor *scan_table;
831 int i, j;
832 struct ieee80211_channel *chan;
833 u8 *ie, *tmp, *ie_buf;
834 u32 ie_len;
835 u64 ts = 0;
836 u8 *beacon;
837 int beacon_size;
838 u8 element_id, element_len;
839
840 memset(&scan_resp, 0, sizeof(scan_resp));
841 if (mwifiex_get_scan_table(priv, MWIFIEX_IOCTL_WAIT, &scan_resp))
842 return -EFAULT;
843
844#define MAX_IE_BUF 2048
845 ie_buf = kzalloc(MAX_IE_BUF, GFP_KERNEL);
846 if (!ie_buf) {
847 dev_err(priv->adapter->dev, "%s: failed to alloc ie_buf\n",
848 __func__);
849 return -ENOMEM;
850 }
851
852 scan_table = (struct mwifiex_bssdescriptor *) scan_resp.scan_table;
853 for (i = 0; i < scan_resp.num_in_scan_table; i++) {
854 if (ssid) {
855 /* Inform specific BSS only */
856 if (memcmp(ssid->ssid, scan_table[i].ssid.ssid,
857 ssid->ssid_len))
858 continue;
859 }
860 memset(ie_buf, 0, MAX_IE_BUF);
861 ie_buf[0] = WLAN_EID_SSID;
862 ie_buf[1] = scan_table[i].ssid.ssid_len;
863 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
864 scan_table[i].ssid.ssid, ie_buf[1]);
865
866 ie = ie_buf + ie_buf[1] + sizeof(struct ieee_types_header);
867 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
868
869 ie[0] = WLAN_EID_SUPP_RATES;
870
871 for (j = 0; j < sizeof(scan_table[i].supported_rates); j++) {
872 if (!scan_table[i].supported_rates[j])
873 break;
874 else
875 ie[j + sizeof(struct ieee_types_header)] =
876 scan_table[i].supported_rates[j];
877 }
878
879 ie[1] = j;
880 ie_len += ie[1] + sizeof(struct ieee_types_header);
881
882 beacon = scan_table[i].beacon_buf;
883 beacon_size = scan_table[i].beacon_buf_size;
884
885 /* Skip time stamp, beacon interval and capability */
886
887 if (beacon) {
888 beacon += sizeof(scan_table[i].beacon_period)
889 + sizeof(scan_table[i].time_stamp) +
890 +sizeof(scan_table[i].cap_info_bitmap);
891
892 beacon_size -= sizeof(scan_table[i].beacon_period)
893 + sizeof(scan_table[i].time_stamp)
894 + sizeof(scan_table[i].cap_info_bitmap);
895 }
896
897 while (beacon_size >= sizeof(struct ieee_types_header)) {
898 ie = ie_buf + ie_len;
899 element_id = *beacon;
900 element_len = *(beacon + 1);
901 if (beacon_size < (int) element_len +
902 sizeof(struct ieee_types_header)) {
903 dev_err(priv->adapter->dev, "%s: in processing"
904 " IE, bytes left < IE length\n",
905 __func__);
906 break;
907 }
908 switch (element_id) {
909 case WLAN_EID_EXT_CAPABILITY:
910 case WLAN_EID_DS_PARAMS:
911 case WLAN_EID_HT_CAPABILITY:
912 case WLAN_EID_VENDOR_SPECIFIC:
913 case WLAN_EID_RSN:
914 case WLAN_EID_BSS_AC_ACCESS_DELAY:
915 ie[0] = element_id;
916 ie[1] = element_len;
917 tmp = (u8 *) beacon;
918 memcpy(&ie[sizeof(struct ieee_types_header)],
919 tmp + sizeof(struct ieee_types_header),
920 element_len);
921 ie_len += ie[1] +
922 sizeof(struct ieee_types_header);
923 break;
924 default:
925 break;
926 }
927 beacon += element_len +
928 sizeof(struct ieee_types_header);
929 beacon_size -= element_len +
930 sizeof(struct ieee_types_header);
931 }
932 chan = ieee80211_get_channel(priv->wdev->wiphy,
933 scan_table[i].freq);
934 cfg80211_inform_bss(priv->wdev->wiphy, chan,
935 scan_table[i].mac_address,
936 ts, scan_table[i].cap_info_bitmap,
937 scan_table[i].beacon_period,
938 ie_buf, ie_len,
939 scan_table[i].rssi, GFP_KERNEL);
940 }
941
942 kfree(ie_buf);
943 return 0;
944}
945
946/*
947 * This function connects with a BSS.
948 *
949 * This function handles both Infra and Ad-Hoc modes. It also performs
950 * validity checking on the provided parameters, disconnects from the
951 * current BSS (if any), sets up the association/scan parameters,
952 * including security settings, and performs specific SSID scan before
953 * trying to connect.
954 *
955 * For Infra mode, the function returns failure if the specified SSID
956 * is not found in scan table. However, for Ad-Hoc mode, it can create
957 * the IBSS if it does not exist. On successful completion in either case,
958 * the function notifies the CFG802.11 subsystem of the new BSS connection,
959 * otherwise the kernel will panic.
960 */
961static int
962mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
963 u8 *bssid, int mode, struct ieee80211_channel *channel,
964 struct cfg80211_connect_params *sme, bool privacy)
965{
966 struct mwifiex_802_11_ssid req_ssid;
967 struct mwifiex_ssid_bssid ssid_bssid;
968 int ret = 0;
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -0700969 int auth_type = 0, pairwise_encrypt_mode = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970 int group_encrypt_mode = 0;
971 int alg_is_wep = 0;
972
973 memset(&req_ssid, 0, sizeof(struct mwifiex_802_11_ssid));
974 memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
975
976 req_ssid.ssid_len = ssid_len;
977 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
978 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
979 return -EINVAL;
980 }
981
982 memcpy(req_ssid.ssid, ssid, ssid_len);
983 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
984 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
985 return -EINVAL;
986 }
987
988 /* disconnect before try to associate */
989 mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL);
990
991 if (channel)
992 ret = mwifiex_set_rf_channel(priv, channel,
993 mwifiex_channels_to_cfg80211_channel_type
994 (priv->adapter->chan_offset));
995
996 ret = mwifiex_set_encode(priv, NULL, 0, 0, 1); /* Disable keys */
997
Bing Zhaoeecd8252011-03-28 17:55:41 -0700998 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700999 /* "privacy" is set only for ad-hoc mode */
1000 if (privacy) {
1001 /*
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001002 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003 * the firmware can find a matching network from the
1004 * scan. The cfg80211 does not give us the encryption
1005 * mode at this stage so just setting it to WEP here.
1006 */
Marc Yang203afec2011-03-24 20:49:39 -07001007 priv->sec_info.encryption_mode =
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001008 WLAN_CIPHER_SUITE_WEP104;
Marc Yang203afec2011-03-24 20:49:39 -07001009 priv->sec_info.authentication_mode =
Marc Yangf986b6d2011-03-28 17:55:42 -07001010 NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001011 }
1012
1013 goto done;
1014 }
1015
1016 /* Now handle infra mode. "sme" is valid for infra mode only */
1017 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC
1018 || sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
Marc Yangf986b6d2011-03-28 17:55:42 -07001019 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020 else if (sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY)
Marc Yangf986b6d2011-03-28 17:55:42 -07001021 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022
1023 if (sme->crypto.n_ciphers_pairwise) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001024 priv->sec_info.encryption_mode =
1025 sme->crypto.ciphers_pairwise[0];
Marc Yang203afec2011-03-24 20:49:39 -07001026 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001027 }
1028
1029 if (sme->crypto.cipher_group) {
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -07001030 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
Marc Yang203afec2011-03-24 20:49:39 -07001031 priv->sec_info.authentication_mode = auth_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032 }
1033 if (sme->ie)
1034 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1035
1036 if (sme->key) {
1037 alg_is_wep = mwifiex_is_alg_wep(pairwise_encrypt_mode)
1038 | mwifiex_is_alg_wep(group_encrypt_mode);
1039 if (alg_is_wep) {
1040 dev_dbg(priv->adapter->dev,
1041 "info: setting wep encryption"
1042 " with key len %d\n", sme->key_len);
1043 ret = mwifiex_set_encode(priv, sme->key, sme->key_len,
1044 sme->key_idx, 0);
1045 }
1046 }
1047done:
1048 /* Do specific SSID scanning */
1049 if (mwifiex_request_scan(priv, MWIFIEX_IOCTL_WAIT, &req_ssid)) {
1050 dev_err(priv->adapter->dev, "scan error\n");
1051 return -EFAULT;
1052 }
1053
1054
1055 memcpy(&ssid_bssid.ssid, &req_ssid, sizeof(struct mwifiex_802_11_ssid));
1056
Bing Zhaoeecd8252011-03-28 17:55:41 -07001057 if (mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 if (mwifiex_find_best_bss(priv, MWIFIEX_IOCTL_WAIT,
1059 &ssid_bssid))
1060 return -EFAULT;
1061 /* Inform the BSS information to kernel, otherwise
1062 * kernel will give a panic after successful assoc */
1063 if (mwifiex_inform_bss_from_scan_result(priv, &req_ssid))
1064 return -EFAULT;
1065 }
1066
1067 dev_dbg(priv->adapter->dev, "info: trying to associate to %s and bssid %pM\n",
1068 (char *) req_ssid.ssid, ssid_bssid.bssid);
1069
1070 memcpy(&priv->cfg_bssid, ssid_bssid.bssid, 6);
1071
1072 /* Connect to BSS by ESSID */
1073 memset(&ssid_bssid.bssid, 0, ETH_ALEN);
1074
1075 if (mwifiex_bss_start(priv, MWIFIEX_IOCTL_WAIT, &ssid_bssid))
1076 return -EFAULT;
1077
Bing Zhaoeecd8252011-03-28 17:55:41 -07001078 if (mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 /* Inform the BSS information to kernel, otherwise
1080 * kernel will give a panic after successful assoc */
1081 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1082 return -EFAULT;
1083 }
1084
1085 return ret;
1086}
1087
1088/*
1089 * CFG802.11 operation handler for association request.
1090 *
1091 * This function does not work when the current mode is set to Ad-Hoc, or
1092 * when there is already an association procedure going on. The given BSS
1093 * information is used to associate.
1094 */
1095static int
1096mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1097 struct cfg80211_connect_params *sme)
1098{
1099 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1100 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001101
1102 if (priv->assoc_request)
1103 return -EBUSY;
1104
Bing Zhaoeecd8252011-03-28 17:55:41 -07001105 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 wiphy_err(wiphy, "received infra assoc request "
1107 "when station is in ibss mode\n");
1108 goto done;
1109 }
1110
1111 priv->assoc_request = 1;
1112
1113 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
1114 (char *) sme->ssid, sme->bssid);
1115
1116 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001117 priv->bss_mode, sme->channel, sme, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001118
1119done:
1120 priv->assoc_result = ret;
1121 queue_work(priv->workqueue, &priv->cfg_workqueue);
1122 return ret;
1123}
1124
1125/*
1126 * CFG802.11 operation handler to join an IBSS.
1127 *
1128 * This function does not work in any mode other than Ad-Hoc, or if
1129 * a join operation is already in progress.
1130 */
1131static int
1132mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1133 struct cfg80211_ibss_params *params)
1134{
1135 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
1136 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001137
1138 if (priv->ibss_join_request)
1139 return -EBUSY;
1140
Bing Zhaoeecd8252011-03-28 17:55:41 -07001141 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001142 wiphy_err(wiphy, "request to join ibss received "
1143 "when station is not in ibss mode\n");
1144 goto done;
1145 }
1146
1147 priv->ibss_join_request = 1;
1148
1149 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
1150 (char *) params->ssid, params->bssid);
1151
1152 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
Bing Zhaoeecd8252011-03-28 17:55:41 -07001153 params->bssid, priv->bss_mode,
1154 params->channel, NULL, params->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001155done:
1156 priv->ibss_join_result = ret;
1157 queue_work(priv->workqueue, &priv->cfg_workqueue);
1158 return ret;
1159}
1160
1161/*
1162 * CFG802.11 operation handler to leave an IBSS.
1163 *
1164 * This function does not work if a leave operation is
1165 * already in progress.
1166 */
1167static int
1168mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1169{
1170 struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
1171
1172 if (priv->disconnect)
1173 return -EBUSY;
1174
1175 priv->disconnect = 1;
1176
1177 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
1178 priv->cfg_bssid);
1179 if (mwifiex_disconnect(priv, MWIFIEX_IOCTL_WAIT, NULL))
1180 return -EFAULT;
1181
1182 queue_work(priv->workqueue, &priv->cfg_workqueue);
1183
1184 return 0;
1185}
1186
1187/*
1188 * CFG802.11 operation handler for scan request.
1189 *
1190 * This function issues a scan request to the firmware based upon
1191 * the user specified scan configuration. On successfull completion,
1192 * it also informs the results.
1193 */
1194static int
1195mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
1196 struct cfg80211_scan_request *request)
1197{
1198 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1199
1200 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1201
1202 if (priv->scan_request && priv->scan_request != request)
1203 return -EBUSY;
1204
1205 priv->scan_request = request;
1206
1207 queue_work(priv->workqueue, &priv->cfg_workqueue);
1208 return 0;
1209}
1210
1211/*
1212 * This function sets up the CFG802.11 specific HT capability fields
1213 * with default values.
1214 *
1215 * The following default values are set -
1216 * - HT Supported = True
1217 * - Maximum AMPDU length factor = 0x3
1218 * - Minimum AMPDU spacing = 0x6
1219 * - HT Capabilities map = IEEE80211_HT_CAP_SUP_WIDTH_20_40 (0x0002)
1220 * - MCS information, Rx mask = 0xff
1221 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
1222 */
1223static void
1224mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
1225 struct mwifiex_private *priv)
1226{
1227 int rx_mcs_supp;
1228 struct ieee80211_mcs_info mcs_set;
1229 u8 *mcs = (u8 *)&mcs_set;
1230 struct mwifiex_adapter *adapter = priv->adapter;
1231
1232 ht_info->ht_supported = true;
1233 ht_info->ampdu_factor = 0x3;
1234 ht_info->ampdu_density = 0x6;
1235
1236 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
1237 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1238
1239 rx_mcs_supp = GET_RXMCSSUPP(priv->adapter->hw_dev_mcs_support);
1240 /* Set MCS for 1x1 */
1241 memset(mcs, 0xff, rx_mcs_supp);
1242 /* Clear all the other values */
1243 memset(&mcs[rx_mcs_supp], 0,
1244 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001245 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
Marc Yang6d2bd912011-03-25 19:47:02 -07001246 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001247 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
1248 SETHT_MCS32(mcs_set.rx_mask);
1249
1250 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
1251
1252 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1253}
1254
1255/* station cfg80211 operations */
1256static struct cfg80211_ops mwifiex_cfg80211_ops = {
1257 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
1258 .scan = mwifiex_cfg80211_scan,
1259 .connect = mwifiex_cfg80211_connect,
1260 .disconnect = mwifiex_cfg80211_disconnect,
1261 .get_station = mwifiex_cfg80211_get_station,
1262 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
1263 .set_channel = mwifiex_cfg80211_set_channel,
1264 .join_ibss = mwifiex_cfg80211_join_ibss,
1265 .leave_ibss = mwifiex_cfg80211_leave_ibss,
1266 .add_key = mwifiex_cfg80211_add_key,
1267 .del_key = mwifiex_cfg80211_del_key,
1268 .set_default_key = mwifiex_cfg80211_set_default_key,
1269 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
1270 .set_tx_power = mwifiex_cfg80211_set_tx_power,
1271};
1272
1273/*
1274 * This function registers the device with CFG802.11 subsystem.
1275 *
1276 * The function creates the wireless device/wiphy, populates it with
1277 * default parameters and handler function pointers, and finally
1278 * registers the device.
1279 */
1280int mwifiex_register_cfg80211(struct net_device *dev, u8 *mac,
1281 struct mwifiex_private *priv)
1282{
1283 int ret = 0;
1284 void *wdev_priv = NULL;
1285 struct wireless_dev *wdev;
1286
1287 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1288 if (!wdev) {
1289 dev_err(priv->adapter->dev, "%s: allocating wireless device\n",
1290 __func__);
1291 return -ENOMEM;
1292 }
1293 wdev->wiphy =
1294 wiphy_new(&mwifiex_cfg80211_ops,
1295 sizeof(struct mwifiex_private *));
1296 if (!wdev->wiphy)
1297 return -ENOMEM;
1298 wdev->iftype = NL80211_IFTYPE_STATION;
1299 wdev->wiphy->max_scan_ssids = 10;
1300 wdev->wiphy->interface_modes =
1301 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
1302 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
1303 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
1304
1305 /* Initialize cipher suits */
1306 wdev->wiphy->cipher_suites = mwifiex_cipher_suites;
1307 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
1308
1309 /* Initialize parameters for 2GHz band */
1310
1311 mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap,
1312 priv);
1313 mwifiex_setup_ht_caps(&wdev->wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap,
1314 priv);
1315
1316 memcpy(wdev->wiphy->perm_addr, mac, 6);
1317 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1318
1319 /* We are using custom domains */
1320 wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
1321
1322 wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
1323
1324 /* Set struct mwifiex_private pointer in wiphy_priv */
1325 wdev_priv = wiphy_priv(wdev->wiphy);
1326
1327 *(unsigned long *) wdev_priv = (unsigned long) priv;
1328
1329 ret = wiphy_register(wdev->wiphy);
1330 if (ret < 0) {
1331 dev_err(priv->adapter->dev, "%s: registering cfg80211 device\n",
1332 __func__);
1333 wiphy_free(wdev->wiphy);
1334 return ret;
1335 } else {
1336 dev_dbg(priv->adapter->dev,
1337 "info: successfully registered wiphy device\n");
1338 }
1339
1340 dev_net_set(dev, wiphy_net(wdev->wiphy));
1341 dev->ieee80211_ptr = wdev;
1342 memcpy(dev->dev_addr, wdev->wiphy->perm_addr, 6);
1343 memcpy(dev->perm_addr, wdev->wiphy->perm_addr, 6);
1344 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1345 priv->wdev = wdev;
1346
1347 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1348 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
1349 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
1350
1351 return ret;
1352}
1353
1354/*
1355 * This function handles the result of different pending network operations.
1356 *
1357 * The following operations are handled and CFG802.11 subsystem is
1358 * notified accordingly -
1359 * - Scan request completion
1360 * - Association request completion
1361 * - IBSS join request completion
1362 * - Disconnect request completion
1363 */
1364void
1365mwifiex_cfg80211_results(struct work_struct *work)
1366{
1367 struct mwifiex_private *priv =
1368 container_of(work, struct mwifiex_private, cfg_workqueue);
1369 struct mwifiex_user_scan_cfg *scan_req;
1370 int ret = 0, i;
1371 struct ieee80211_channel *chan;
1372
1373 if (priv->scan_request) {
1374 scan_req = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
1375 GFP_KERNEL);
1376 if (!scan_req) {
1377 dev_err(priv->adapter->dev, "failed to alloc "
1378 "scan_req\n");
1379 return;
1380 }
1381 for (i = 0; i < priv->scan_request->n_ssids; i++) {
1382 memcpy(scan_req->ssid_list[i].ssid,
1383 priv->scan_request->ssids[i].ssid,
1384 priv->scan_request->ssids[i].ssid_len);
1385 scan_req->ssid_list[i].max_len =
1386 priv->scan_request->ssids[i].ssid_len;
1387 }
1388 for (i = 0; i < priv->scan_request->n_channels; i++) {
1389 chan = priv->scan_request->channels[i];
1390 scan_req->chan_list[i].chan_number = chan->hw_value;
1391 scan_req->chan_list[i].radio_type = chan->band;
1392 if (chan->flags & IEEE80211_CHAN_DISABLED)
1393 scan_req->chan_list[i].scan_type =
1394 MWIFIEX_SCAN_TYPE_PASSIVE;
1395 else
1396 scan_req->chan_list[i].scan_type =
1397 MWIFIEX_SCAN_TYPE_ACTIVE;
1398 scan_req->chan_list[i].scan_time = 0;
1399 }
1400 if (mwifiex_set_user_scan_ioctl(priv, scan_req)) {
1401 ret = -EFAULT;
1402 goto done;
1403 }
1404 if (mwifiex_inform_bss_from_scan_result(priv, NULL))
1405 ret = -EFAULT;
1406done:
1407 priv->scan_result_status = ret;
1408 dev_dbg(priv->adapter->dev, "info: %s: sending scan results\n",
1409 __func__);
1410 cfg80211_scan_done(priv->scan_request,
1411 (priv->scan_result_status < 0));
1412 priv->scan_request = NULL;
1413 kfree(scan_req);
1414 }
1415
1416 if (priv->assoc_request) {
1417 if (!priv->assoc_result) {
1418 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1419 NULL, 0, NULL, 0,
1420 WLAN_STATUS_SUCCESS,
1421 GFP_KERNEL);
1422 dev_dbg(priv->adapter->dev,
1423 "info: associated to bssid %pM successfully\n",
1424 priv->cfg_bssid);
1425 } else {
1426 dev_dbg(priv->adapter->dev,
1427 "info: association to bssid %pM failed\n",
1428 priv->cfg_bssid);
1429 memset(priv->cfg_bssid, 0, ETH_ALEN);
1430 }
1431 priv->assoc_request = 0;
1432 priv->assoc_result = 0;
1433 }
1434
1435 if (priv->ibss_join_request) {
1436 if (!priv->ibss_join_result) {
1437 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
1438 GFP_KERNEL);
1439 dev_dbg(priv->adapter->dev,
1440 "info: joined/created adhoc network with bssid"
1441 " %pM successfully\n", priv->cfg_bssid);
1442 } else {
1443 dev_dbg(priv->adapter->dev,
1444 "info: failed creating/joining adhoc network\n");
1445 }
1446 priv->ibss_join_request = 0;
1447 priv->ibss_join_result = 0;
1448 }
1449
1450 if (priv->disconnect) {
1451 memset(priv->cfg_bssid, 0, ETH_ALEN);
1452 priv->disconnect = 0;
1453 }
1454
1455 return;
1456}