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