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