mwifiex: fix potential buffer overflow in dt configuration
[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
3c68ef5b
AP
23static char *reg_alpha2;
24module_param(reg_alpha2, charp, 0);
25
cd8440da
AP
26static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
27 {
a4df8f56
AP
28 .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
29 BIT(NL80211_IFTYPE_P2P_GO) |
30 BIT(NL80211_IFTYPE_P2P_CLIENT),
cd8440da
AP
31 },
32 {
33 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
34 },
35};
36
37static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
38 .limits = mwifiex_ap_sta_limits,
39 .num_different_channels = 1,
40 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
41 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
42 .beacon_int_infra_match = true,
43};
44
cc0ba0d5
AK
45static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
46 .n_reg_rules = 7,
47 .alpha2 = "99",
48 .reg_rules = {
49 /* Channel 1 - 11 */
50 REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
51 /* Channel 12 - 13 */
52 REG_RULE(2467-10, 2472+10, 20, 3, 20,
8fe02e16 53 NL80211_RRF_NO_IR),
cc0ba0d5
AK
54 /* Channel 14 */
55 REG_RULE(2484-10, 2484+10, 20, 3, 20,
8fe02e16 56 NL80211_RRF_NO_IR |
cc0ba0d5
AK
57 NL80211_RRF_NO_OFDM),
58 /* Channel 36 - 48 */
59 REG_RULE(5180-10, 5240+10, 40, 3, 20,
8fe02e16 60 NL80211_RRF_NO_IR),
cc0ba0d5
AK
61 /* Channel 149 - 165 */
62 REG_RULE(5745-10, 5825+10, 40, 3, 20,
8fe02e16 63 NL80211_RRF_NO_IR),
cc0ba0d5
AK
64 /* Channel 52 - 64 */
65 REG_RULE(5260-10, 5320+10, 40, 3, 30,
8fe02e16 66 NL80211_RRF_NO_IR |
cc0ba0d5
AK
67 NL80211_RRF_DFS),
68 /* Channel 100 - 140 */
69 REG_RULE(5500-10, 5700+10, 40, 3, 30,
8fe02e16 70 NL80211_RRF_NO_IR |
cc0ba0d5
AK
71 NL80211_RRF_DFS),
72 }
73};
74
5e6e3a92
BZ
75/*
76 * This function maps the nl802.11 channel type into driver channel type.
77 *
78 * The mapping is as follows -
21c3ba34
AK
79 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
80 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
81 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
82 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
83 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
5e6e3a92 84 */
7feb4c48 85u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
5e6e3a92 86{
05910f4a 87 switch (chan_type) {
5e6e3a92
BZ
88 case NL80211_CHAN_NO_HT:
89 case NL80211_CHAN_HT20:
21c3ba34 90 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 91 case NL80211_CHAN_HT40PLUS:
21c3ba34 92 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
5e6e3a92 93 case NL80211_CHAN_HT40MINUS:
21c3ba34 94 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
5e6e3a92 95 default:
21c3ba34 96 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 97 }
5e6e3a92
BZ
98}
99
5e6e3a92
BZ
100/*
101 * This function checks whether WEP is set.
102 */
103static int
104mwifiex_is_alg_wep(u32 cipher)
105{
5e6e3a92 106 switch (cipher) {
2be50b8d
YAP
107 case WLAN_CIPHER_SUITE_WEP40:
108 case WLAN_CIPHER_SUITE_WEP104:
270e58e8 109 return 1;
5e6e3a92 110 default:
5e6e3a92
BZ
111 break;
112 }
270e58e8
YAP
113
114 return 0;
5e6e3a92
BZ
115}
116
5e6e3a92
BZ
117/*
118 * This function retrieves the private structure from kernel wiphy structure.
119 */
67fdf39e 120static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
5e6e3a92
BZ
121{
122 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
123}
124
125/*
126 * CFG802.11 operation handler to delete a network key.
127 */
128static int
129mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
130 u8 key_index, bool pairwise, const u8 *mac_addr)
131{
f540f9f3 132 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
75edd2c6
AP
133 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
134 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 135
53b11231 136 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
5e6e3a92
BZ
137 wiphy_err(wiphy, "deleting the crypto keys\n");
138 return -EFAULT;
139 }
140
141 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
142 return 0;
143}
144
e39faa73
SP
145/*
146 * This function forms an skb for management frame.
147 */
148static int
149mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
150{
151 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
152 u16 pkt_len;
153 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
154 struct timeval tv;
155
156 pkt_len = len + ETH_ALEN;
157
158 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
159 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
160 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
161
162 memcpy(skb_push(skb, sizeof(tx_control)),
163 &tx_control, sizeof(tx_control));
164
165 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
166
167 /* Add packet data and address4 */
168 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
169 sizeof(struct ieee80211_hdr_3addr));
170 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
171 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
172 buf + sizeof(struct ieee80211_hdr_3addr),
173 len - sizeof(struct ieee80211_hdr_3addr));
174
175 skb->priority = LOW_PRIO_TID;
176 do_gettimeofday(&tv);
177 skb->tstamp = timeval_to_ktime(tv);
178
179 return 0;
180}
181
182/*
183 * CFG802.11 operation handler to transmit a management frame.
184 */
185static int
186mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
b176e629 187 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
e39faa73 188{
b176e629
AO
189 const u8 *buf = params->buf;
190 size_t len = params->len;
e39faa73
SP
191 struct sk_buff *skb;
192 u16 pkt_len;
193 const struct ieee80211_mgmt *mgmt;
231d83e2 194 struct mwifiex_txinfo *tx_info;
e39faa73
SP
195 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
196
197 if (!buf || !len) {
198 wiphy_err(wiphy, "invalid buffer and length\n");
199 return -EFAULT;
200 }
201
202 mgmt = (const struct ieee80211_mgmt *)buf;
203 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
204 ieee80211_is_probe_resp(mgmt->frame_control)) {
205 /* Since we support offload probe resp, we need to skip probe
206 * resp in AP or GO mode */
207 wiphy_dbg(wiphy,
208 "info: skip to send probe resp in AP or GO mode\n");
209 return 0;
210 }
211
212 pkt_len = len + ETH_ALEN;
213 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
214 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
215 pkt_len + sizeof(pkt_len));
216
217 if (!skb) {
218 wiphy_err(wiphy, "allocate skb failed for management frame\n");
219 return -ENOMEM;
220 }
221
231d83e2
HY
222 tx_info = MWIFIEX_SKB_TXCB(skb);
223 tx_info->bss_num = priv->bss_num;
224 tx_info->bss_type = priv->bss_type;
a1ed4849 225 tx_info->pkt_len = pkt_len;
231d83e2 226
e39faa73
SP
227 mwifiex_form_mgmt_frame(skb, buf, len);
228 mwifiex_queue_tx_pkt(priv, skb);
229
e00adf39 230 *cookie = prandom_u32() | 1;
e39faa73
SP
231 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, GFP_ATOMIC);
232
233 wiphy_dbg(wiphy, "info: management frame transmitted\n");
234 return 0;
235}
236
3cec6870
SP
237/*
238 * CFG802.11 operation handler to register a mgmt frame.
239 */
240static void
241mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
242 struct wireless_dev *wdev,
243 u16 frame_type, bool reg)
244{
245 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4481b2db 246 u32 mask;
3cec6870
SP
247
248 if (reg)
4481b2db 249 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
3cec6870 250 else
4481b2db
SP
251 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
252
253 if (mask != priv->mgmt_frame_mask) {
254 priv->mgmt_frame_mask = mask;
255 mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
256 HostCmd_ACT_GEN_SET, 0,
257 &priv->mgmt_frame_mask);
258 wiphy_dbg(wiphy, "info: mgmt frame registered\n");
259 }
3cec6870
SP
260}
261
7feb4c48
SP
262/*
263 * CFG802.11 operation handler to remain on channel.
264 */
265static int
266mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
267 struct wireless_dev *wdev,
268 struct ieee80211_channel *chan,
7feb4c48
SP
269 unsigned int duration, u64 *cookie)
270{
271 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
272 int ret;
273
274 if (!chan || !cookie) {
275 wiphy_err(wiphy, "Invalid parameter for ROC\n");
276 return -EINVAL;
277 }
278
279 if (priv->roc_cfg.cookie) {
280 wiphy_dbg(wiphy, "info: ongoing ROC, cookie = 0x%llu\n",
281 priv->roc_cfg.cookie);
282 return -EBUSY;
283 }
284
285 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
42d97a59 286 duration);
7feb4c48
SP
287
288 if (!ret) {
e00adf39 289 *cookie = prandom_u32() | 1;
7feb4c48
SP
290 priv->roc_cfg.cookie = *cookie;
291 priv->roc_cfg.chan = *chan;
7feb4c48 292
42d97a59 293 cfg80211_ready_on_channel(wdev, *cookie, chan,
7feb4c48
SP
294 duration, GFP_ATOMIC);
295
296 wiphy_dbg(wiphy, "info: ROC, cookie = 0x%llx\n", *cookie);
297 }
298
299 return ret;
300}
301
302/*
303 * CFG802.11 operation handler to cancel remain on channel.
304 */
305static int
306mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
307 struct wireless_dev *wdev, u64 cookie)
308{
309 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
310 int ret;
311
312 if (cookie != priv->roc_cfg.cookie)
313 return -ENOENT;
314
315 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
42d97a59 316 &priv->roc_cfg.chan, 0);
7feb4c48
SP
317
318 if (!ret) {
319 cfg80211_remain_on_channel_expired(wdev, cookie,
320 &priv->roc_cfg.chan,
7feb4c48
SP
321 GFP_ATOMIC);
322
323 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
324
325 wiphy_dbg(wiphy, "info: cancel ROC, cookie = 0x%llx\n", cookie);
326 }
327
328 return ret;
329}
330
5e6e3a92
BZ
331/*
332 * CFG802.11 operation handler to set Tx power.
333 */
334static int
335mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
c8442118 336 struct wireless_dev *wdev,
5e6e3a92 337 enum nl80211_tx_power_setting type,
742c29fd 338 int mbm)
5e6e3a92 339{
67fdf39e
AP
340 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
341 struct mwifiex_private *priv;
600f5d90 342 struct mwifiex_power_cfg power_cfg;
742c29fd 343 int dbm = MBM_TO_DBM(mbm);
5e6e3a92 344
600f5d90
AK
345 if (type == NL80211_TX_POWER_FIXED) {
346 power_cfg.is_power_auto = 0;
347 power_cfg.power_level = dbm;
348 } else {
349 power_cfg.is_power_auto = 1;
350 }
351
67fdf39e
AP
352 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
353
636c4598 354 return mwifiex_set_tx_power(priv, &power_cfg);
5e6e3a92
BZ
355}
356
357/*
358 * CFG802.11 operation handler to set Power Save option.
359 *
360 * The timeout value, if provided, is currently ignored.
361 */
362static int
363mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
364 struct net_device *dev,
365 bool enabled, int timeout)
366{
f540f9f3 367 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
600f5d90 368 u32 ps_mode;
5e6e3a92
BZ
369
370 if (timeout)
371 wiphy_dbg(wiphy,
aea0701e 372 "info: ignore timeout value for IEEE Power Save\n");
5e6e3a92 373
600f5d90 374 ps_mode = enabled;
5e6e3a92 375
636c4598 376 return mwifiex_drv_set_power(priv, &ps_mode);
5e6e3a92
BZ
377}
378
379/*
380 * CFG802.11 operation handler to set the default network key.
381 */
382static int
383mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
384 u8 key_index, bool unicast,
385 bool multicast)
386{
f540f9f3 387 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
5e6e3a92 388
2d3d0a88 389 /* Return if WEP key not configured */
5eb02e44 390 if (!priv->sec_info.wep_enabled)
2d3d0a88
AK
391 return 0;
392
96893538
AP
393 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
394 priv->wep_key_curr_index = key_index;
53b11231
YL
395 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
396 NULL, 0)) {
636c4598 397 wiphy_err(wiphy, "set default Tx key index\n");
5e6e3a92 398 return -EFAULT;
636c4598 399 }
5e6e3a92
BZ
400
401 return 0;
402}
403
404/*
405 * CFG802.11 operation handler to add a network key.
406 */
407static int
408mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
409 u8 key_index, bool pairwise, const u8 *mac_addr,
410 struct key_params *params)
411{
f540f9f3 412 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
96893538 413 struct mwifiex_wep_key *wep_key;
75edd2c6
AP
414 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
415 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 416
96893538
AP
417 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
418 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
419 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
420 if (params->key && params->key_len) {
421 wep_key = &priv->wep_key[key_index];
422 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
423 memcpy(wep_key->key_material, params->key,
424 params->key_len);
425 wep_key->key_index = key_index;
426 wep_key->key_length = params->key_len;
427 priv->sec_info.wep_enabled = 1;
428 }
429 return 0;
430 }
431
53b11231 432 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
75edd2c6 433 key_index, peer_mac, 0)) {
636c4598 434 wiphy_err(wiphy, "crypto keys added\n");
5e6e3a92 435 return -EFAULT;
636c4598 436 }
5e6e3a92
BZ
437
438 return 0;
439}
440
441/*
442 * This function sends domain information to the firmware.
443 *
444 * The following information are passed to the firmware -
445 * - Country codes
446 * - Sub bands (first channel, number of channels, maximum Tx power)
447 */
448static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
449{
450 u8 no_of_triplet = 0;
451 struct ieee80211_country_ie_triplet *t;
452 u8 no_of_parsed_chan = 0;
453 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
454 u8 i, flag = 0;
455 enum ieee80211_band band;
456 struct ieee80211_supported_band *sband;
457 struct ieee80211_channel *ch;
67fdf39e
AP
458 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
459 struct mwifiex_private *priv;
5e6e3a92 460 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
5e6e3a92
BZ
461
462 /* Set country code */
67fdf39e
AP
463 domain_info->country_code[0] = adapter->country_code[0];
464 domain_info->country_code[1] = adapter->country_code[1];
5e6e3a92
BZ
465 domain_info->country_code[2] = ' ';
466
467 band = mwifiex_band_to_radio_type(adapter->config_bands);
468 if (!wiphy->bands[band]) {
469 wiphy_err(wiphy, "11D: setting domain info in FW\n");
470 return -1;
471 }
472
473 sband = wiphy->bands[band];
474
475 for (i = 0; i < sband->n_channels ; i++) {
476 ch = &sband->channels[i];
477 if (ch->flags & IEEE80211_CHAN_DISABLED)
478 continue;
479
480 if (!flag) {
481 flag = 1;
482 first_chan = (u32) ch->hw_value;
483 next_chan = first_chan;
22db2497 484 max_pwr = ch->max_power;
5e6e3a92
BZ
485 no_of_parsed_chan = 1;
486 continue;
487 }
488
489 if (ch->hw_value == next_chan + 1 &&
22db2497 490 ch->max_power == max_pwr) {
5e6e3a92
BZ
491 next_chan++;
492 no_of_parsed_chan++;
493 } else {
494 t = &domain_info->triplet[no_of_triplet];
495 t->chans.first_channel = first_chan;
496 t->chans.num_channels = no_of_parsed_chan;
497 t->chans.max_power = max_pwr;
498 no_of_triplet++;
499 first_chan = (u32) ch->hw_value;
500 next_chan = first_chan;
22db2497 501 max_pwr = ch->max_power;
5e6e3a92
BZ
502 no_of_parsed_chan = 1;
503 }
504 }
505
506 if (flag) {
507 t = &domain_info->triplet[no_of_triplet];
508 t->chans.first_channel = first_chan;
509 t->chans.num_channels = no_of_parsed_chan;
510 t->chans.max_power = max_pwr;
511 no_of_triplet++;
512 }
513
514 domain_info->no_of_triplet = no_of_triplet;
636c4598 515
67fdf39e
AP
516 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
517
636c4598 518 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
aea0701e 519 HostCmd_ACT_GEN_SET, 0, NULL)) {
5e6e3a92 520 wiphy_err(wiphy, "11D: setting domain info in FW\n");
636c4598
YAP
521 return -1;
522 }
5e6e3a92 523
636c4598 524 return 0;
5e6e3a92
BZ
525}
526
527/*
528 * CFG802.11 regulatory domain callback function.
529 *
530 * This function is called when the regulatory domain is changed due to the
531 * following reasons -
532 * - Set by driver
533 * - Set by system core
534 * - Set by user
535 * - Set bt Country IE
536 */
0c0280bd
LR
537static void mwifiex_reg_notifier(struct wiphy *wiphy,
538 struct regulatory_request *request)
5e6e3a92 539{
67fdf39e 540 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
82efa16a
BZ
541 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
542 MWIFIEX_BSS_ROLE_ANY);
5e6e3a92 543
67fdf39e
AP
544 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
545 request->alpha2[0], request->alpha2[1]);
5e6e3a92 546
5e6e3a92
BZ
547 switch (request->initiator) {
548 case NL80211_REGDOM_SET_BY_DRIVER:
549 case NL80211_REGDOM_SET_BY_CORE:
550 case NL80211_REGDOM_SET_BY_USER:
5e6e3a92
BZ
551 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
552 break;
dd4a9ac0
BZ
553 default:
554 wiphy_err(wiphy, "unknown regdom initiator: %d\n",
555 request->initiator);
556 return;
557 }
558
559 /* Don't send world or same regdom info to firmware */
560 if (strncmp(request->alpha2, "00", 2) &&
561 strncmp(request->alpha2, adapter->country_code,
562 sizeof(request->alpha2))) {
563 memcpy(adapter->country_code, request->alpha2,
564 sizeof(request->alpha2));
565 mwifiex_send_domain_info_cmd_fw(wiphy);
82efa16a
BZ
566
567 if (adapter->dt_node) {
568 char txpwr[] = {"marvell,00_txpwrlimit"};
569
570 memcpy(&txpwr[8], adapter->country_code, 2);
571 mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
572 txpwr);
573 }
5e6e3a92 574 }
5e6e3a92
BZ
575}
576
5e6e3a92
BZ
577/*
578 * This function sets the fragmentation threshold.
579 *
600f5d90 580 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
5e6e3a92
BZ
581 * and MWIFIEX_FRAG_MAX_VALUE.
582 */
583static int
584mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
585{
aea0701e
YAP
586 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
587 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
9b930eae 588 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
5e6e3a92 589
9b930eae
AP
590 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
591 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
592 &frag_thr);
5e6e3a92
BZ
593}
594
595/*
596 * This function sets the RTS threshold.
600f5d90
AK
597
598 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
599 * and MWIFIEX_RTS_MAX_VALUE.
5e6e3a92
BZ
600 */
601static int
602mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
603{
5e6e3a92
BZ
604 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
605 rts_thr = MWIFIEX_RTS_MAX_VALUE;
606
636c4598 607 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
600f5d90
AK
608 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
609 &rts_thr);
5e6e3a92
BZ
610}
611
612/*
613 * CFG802.11 operation handler to set wiphy parameters.
614 *
615 * This function can be used to set the RTS threshold and the
616 * Fragmentation threshold of the driver.
617 */
618static int
619mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
620{
67fdf39e 621 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
9b930eae
AP
622 struct mwifiex_private *priv;
623 struct mwifiex_uap_bss_param *bss_cfg;
624 int ret, bss_started, i;
625
626 for (i = 0; i < adapter->priv_num; i++) {
627 priv = adapter->priv[i];
628
629 switch (priv->bss_role) {
630 case MWIFIEX_BSS_ROLE_UAP:
631 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
632 GFP_KERNEL);
633 if (!bss_cfg)
634 return -ENOMEM;
635
636 mwifiex_set_sys_config_invalid_data(bss_cfg);
637
638 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
639 bss_cfg->rts_threshold = wiphy->rts_threshold;
640 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
641 bss_cfg->frag_threshold = wiphy->frag_threshold;
642 if (changed & WIPHY_PARAM_RETRY_LONG)
643 bss_cfg->retry_limit = wiphy->retry_long;
644
645 bss_started = priv->bss_started;
646
647 ret = mwifiex_send_cmd_sync(priv,
648 HostCmd_CMD_UAP_BSS_STOP,
649 HostCmd_ACT_GEN_SET, 0,
650 NULL);
651 if (ret) {
652 wiphy_err(wiphy, "Failed to stop the BSS\n");
653 kfree(bss_cfg);
654 return ret;
655 }
656
657 ret = mwifiex_send_cmd_async(priv,
658 HostCmd_CMD_UAP_SYS_CONFIG,
659 HostCmd_ACT_GEN_SET,
e76268da 660 UAP_BSS_PARAMS_I, bss_cfg);
5e6e3a92 661
9b930eae
AP
662 kfree(bss_cfg);
663
664 if (ret) {
665 wiphy_err(wiphy, "Failed to set bss config\n");
666 return ret;
667 }
5e6e3a92 668
9b930eae
AP
669 if (!bss_started)
670 break;
671
672 ret = mwifiex_send_cmd_async(priv,
673 HostCmd_CMD_UAP_BSS_START,
674 HostCmd_ACT_GEN_SET, 0,
675 NULL);
676 if (ret) {
677 wiphy_err(wiphy, "Failed to start BSS\n");
678 return ret;
679 }
680
681 break;
682 case MWIFIEX_BSS_ROLE_STA:
683 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
684 ret = mwifiex_set_rts(priv,
685 wiphy->rts_threshold);
686 if (ret)
687 return ret;
688 }
689 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
690 ret = mwifiex_set_frag(priv,
691 wiphy->frag_threshold);
692 if (ret)
693 return ret;
694 }
695 break;
696 }
697 }
698
699 return 0;
5e6e3a92
BZ
700}
701
e1a2b7a3
SP
702static int
703mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
704{
705 u16 mode = P2P_MODE_DISABLE;
706
9197ab9e
SP
707 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA)
708 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_STA);
709
e1a2b7a3
SP
710 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
711 HostCmd_ACT_GEN_SET, 0, &mode))
712 return -1;
713
714 return 0;
715}
716
717/*
718 * This function initializes the functionalities for P2P client.
719 * The P2P client initialization sequence is:
720 * disable -> device -> client
721 */
722static int
723mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
724{
725 u16 mode;
726
727 if (mwifiex_cfg80211_deinit_p2p(priv))
728 return -1;
729
730 mode = P2P_MODE_DEVICE;
731 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
732 HostCmd_ACT_GEN_SET, 0, &mode))
733 return -1;
734
735 mode = P2P_MODE_CLIENT;
736 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
737 HostCmd_ACT_GEN_SET, 0, &mode))
738 return -1;
739
740 return 0;
741}
742
9197ab9e
SP
743/*
744 * This function initializes the functionalities for P2P GO.
745 * The P2P GO initialization sequence is:
746 * disable -> device -> GO
747 */
748static int
749mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
750{
751 u16 mode;
752
753 if (mwifiex_cfg80211_deinit_p2p(priv))
754 return -1;
755
756 mode = P2P_MODE_DEVICE;
757 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
758 HostCmd_ACT_GEN_SET, 0, &mode))
759 return -1;
760
761 mode = P2P_MODE_GO;
762 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_P2P_MODE_CFG,
763 HostCmd_ACT_GEN_SET, 0, &mode))
764 return -1;
765
766 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
767 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_UAP);
768
769 return 0;
770}
771
5e6e3a92
BZ
772/*
773 * CFG802.11 operation handler to change interface type.
5e6e3a92
BZ
774 */
775static int
776mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
777 struct net_device *dev,
778 enum nl80211_iftype type, u32 *flags,
779 struct vif_params *params)
780{
270e58e8 781 int ret;
5e6e3a92 782 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 783
4f02341a 784 switch (dev->ieee80211_ptr->iftype) {
5e6e3a92 785 case NL80211_IFTYPE_ADHOC:
4f02341a
AP
786 switch (type) {
787 case NL80211_IFTYPE_STATION:
788 break;
789 case NL80211_IFTYPE_UNSPECIFIED:
790 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
791 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
792 return 0;
793 case NL80211_IFTYPE_AP:
794 default:
795 wiphy_err(wiphy, "%s: changing to %d not supported\n",
796 dev->name, type);
797 return -EOPNOTSUPP;
798 }
5e6e3a92
BZ
799 break;
800 case NL80211_IFTYPE_STATION:
4f02341a
AP
801 switch (type) {
802 case NL80211_IFTYPE_ADHOC:
803 break;
e1a2b7a3
SP
804 case NL80211_IFTYPE_P2P_CLIENT:
805 if (mwifiex_cfg80211_init_p2p_client(priv))
806 return -EFAULT;
807 dev->ieee80211_ptr->iftype = type;
808 return 0;
9197ab9e
SP
809 case NL80211_IFTYPE_P2P_GO:
810 if (mwifiex_cfg80211_init_p2p_go(priv))
811 return -EFAULT;
812 dev->ieee80211_ptr->iftype = type;
813 return 0;
4f02341a
AP
814 case NL80211_IFTYPE_UNSPECIFIED:
815 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
816 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
817 return 0;
818 case NL80211_IFTYPE_AP:
819 default:
820 wiphy_err(wiphy, "%s: changing to %d not supported\n",
821 dev->name, type);
822 return -EOPNOTSUPP;
823 }
824 break;
825 case NL80211_IFTYPE_AP:
826 switch (type) {
827 case NL80211_IFTYPE_UNSPECIFIED:
828 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
829 case NL80211_IFTYPE_AP: /* This shouldn't happen */
830 return 0;
831 case NL80211_IFTYPE_ADHOC:
832 case NL80211_IFTYPE_STATION:
833 default:
834 wiphy_err(wiphy, "%s: changing to %d not supported\n",
835 dev->name, type);
836 return -EOPNOTSUPP;
837 }
5e6e3a92 838 break;
e1a2b7a3 839 case NL80211_IFTYPE_P2P_CLIENT:
9197ab9e 840 case NL80211_IFTYPE_P2P_GO:
e1a2b7a3
SP
841 switch (type) {
842 case NL80211_IFTYPE_STATION:
843 if (mwifiex_cfg80211_deinit_p2p(priv))
844 return -EFAULT;
845 dev->ieee80211_ptr->iftype = type;
846 return 0;
847 default:
848 return -EOPNOTSUPP;
849 }
850 break;
5e6e3a92 851 default:
4f02341a
AP
852 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
853 dev->name, dev->ieee80211_ptr->iftype);
854 return -EOPNOTSUPP;
5e6e3a92 855 }
5e6e3a92 856
4f02341a
AP
857 dev->ieee80211_ptr->iftype = type;
858 priv->bss_mode = type;
600f5d90 859 mwifiex_deauthenticate(priv, NULL);
eecd8250 860
f986b6d5 861 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
eecd8250 862
600f5d90
AK
863 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
864 HostCmd_ACT_GEN_SET, 0, NULL);
eecd8250 865
5e6e3a92
BZ
866 return ret;
867}
868
a5f39056
YAP
869static void
870mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
871 struct rate_info *rate)
872{
873 struct mwifiex_adapter *adapter = priv->adapter;
874
875 if (adapter->is_hw_11ac_capable) {
876 /* bit[1-0]: 00=LG 01=HT 10=VHT */
877 if (tx_htinfo & BIT(0)) {
878 /* HT */
879 rate->mcs = priv->tx_rate;
880 rate->flags |= RATE_INFO_FLAGS_MCS;
881 }
882 if (tx_htinfo & BIT(1)) {
883 /* VHT */
884 rate->mcs = priv->tx_rate & 0x0F;
885 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
886 }
887
888 if (tx_htinfo & (BIT(1) | BIT(0))) {
889 /* HT or VHT */
890 switch (tx_htinfo & (BIT(3) | BIT(2))) {
891 case 0:
892 /* This will be 20MHz */
893 break;
894 case (BIT(2)):
895 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
896 break;
897 case (BIT(3)):
898 rate->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
899 break;
900 case (BIT(3) | BIT(2)):
901 rate->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
902 break;
903 }
904
905 if (tx_htinfo & BIT(4))
906 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
907
908 if ((priv->tx_rate >> 4) == 1)
909 rate->nss = 2;
910 else
911 rate->nss = 1;
912 }
913 } else {
914 /*
915 * Bit 0 in tx_htinfo indicates that current Tx rate
916 * is 11n rate. Valid MCS index values for us are 0 to 15.
917 */
918 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
919 rate->mcs = priv->tx_rate;
920 rate->flags |= RATE_INFO_FLAGS_MCS;
921 if (tx_htinfo & BIT(1))
922 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
923 if (tx_htinfo & BIT(2))
924 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
925 }
926 }
927}
928
5e6e3a92
BZ
929/*
930 * This function dumps the station information on a buffer.
931 *
932 * The following information are shown -
933 * - Total bytes transmitted
934 * - Total bytes received
935 * - Total packets transmitted
936 * - Total packets received
937 * - Signal quality level
938 * - Transmission rate
939 */
940static int
941mwifiex_dump_station_info(struct mwifiex_private *priv,
942 struct station_info *sinfo)
943{
006606c0 944 u32 rate;
5e6e3a92
BZ
945
946 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
7013d3e2
AK
947 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
948 STATION_INFO_TX_BITRATE |
949 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
5e6e3a92
BZ
950
951 /* Get signal information from the firmware */
958a4a86
AK
952 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
953 HostCmd_ACT_GEN_GET, 0, NULL)) {
954 dev_err(priv->adapter->dev, "failed to get signal information\n");
955 return -EFAULT;
5e6e3a92
BZ
956 }
957
958 if (mwifiex_drv_get_data_rate(priv, &rate)) {
959 dev_err(priv->adapter->dev, "getting data rate\n");
958a4a86 960 return -EFAULT;
5e6e3a92
BZ
961 }
962
caf60a6c
AK
963 /* Get DTIM period information from firmware */
964 mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
965 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
966 &priv->dtim_period);
967
a5f39056 968 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
4ec6f9c0 969
7013d3e2 970 sinfo->signal_avg = priv->bcn_rssi_avg;
5e6e3a92
BZ
971 sinfo->rx_bytes = priv->stats.rx_bytes;
972 sinfo->tx_bytes = priv->stats.tx_bytes;
973 sinfo->rx_packets = priv->stats.rx_packets;
974 sinfo->tx_packets = priv->stats.tx_packets;
958a4a86 975 sinfo->signal = priv->bcn_rssi_avg;
4ec6f9c0 976 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
006606c0 977 sinfo->txrate.legacy = rate * 5;
5e6e3a92 978
c4f3b972
AK
979 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
980 sinfo->filled |= STATION_INFO_BSS_PARAM;
981 sinfo->bss_param.flags = 0;
982 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
983 WLAN_CAPABILITY_SHORT_PREAMBLE)
984 sinfo->bss_param.flags |=
985 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
986 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
987 WLAN_CAPABILITY_SHORT_SLOT_TIME)
988 sinfo->bss_param.flags |=
989 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
caf60a6c 990 sinfo->bss_param.dtim_period = priv->dtim_period;
c4f3b972
AK
991 sinfo->bss_param.beacon_interval =
992 priv->curr_bss_params.bss_descriptor.beacon_period;
993 }
994
958a4a86 995 return 0;
5e6e3a92
BZ
996}
997
998/*
999 * CFG802.11 operation handler to get station information.
1000 *
1001 * This function only works in connected mode, and dumps the
1002 * requested station information, if available.
1003 */
1004static int
1005mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1006 u8 *mac, struct station_info *sinfo)
1007{
1008 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1009
5e6e3a92
BZ
1010 if (!priv->media_connected)
1011 return -ENOENT;
1012 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1013 return -ENOENT;
1014
636c4598 1015 return mwifiex_dump_station_info(priv, sinfo);
5e6e3a92
BZ
1016}
1017
f85aae6b
AK
1018/*
1019 * CFG802.11 operation handler to dump station information.
1020 */
1021static int
1022mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1023 int idx, u8 *mac, struct station_info *sinfo)
1024{
1025 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1026
1027 if (!priv->media_connected || idx)
1028 return -ENOENT;
1029
1030 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
1031
1032 return mwifiex_dump_station_info(priv, sinfo);
1033}
1034
5e6e3a92 1035/* Supported rates to be advertised to the cfg80211 */
5e6e3a92
BZ
1036static struct ieee80211_rate mwifiex_rates[] = {
1037 {.bitrate = 10, .hw_value = 2, },
1038 {.bitrate = 20, .hw_value = 4, },
1039 {.bitrate = 55, .hw_value = 11, },
1040 {.bitrate = 110, .hw_value = 22, },
5e6e3a92
BZ
1041 {.bitrate = 60, .hw_value = 12, },
1042 {.bitrate = 90, .hw_value = 18, },
1043 {.bitrate = 120, .hw_value = 24, },
1044 {.bitrate = 180, .hw_value = 36, },
1045 {.bitrate = 240, .hw_value = 48, },
1046 {.bitrate = 360, .hw_value = 72, },
1047 {.bitrate = 480, .hw_value = 96, },
1048 {.bitrate = 540, .hw_value = 108, },
5e6e3a92
BZ
1049};
1050
1051/* Channel definitions to be advertised to cfg80211 */
5e6e3a92
BZ
1052static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1053 {.center_freq = 2412, .hw_value = 1, },
1054 {.center_freq = 2417, .hw_value = 2, },
1055 {.center_freq = 2422, .hw_value = 3, },
1056 {.center_freq = 2427, .hw_value = 4, },
1057 {.center_freq = 2432, .hw_value = 5, },
1058 {.center_freq = 2437, .hw_value = 6, },
1059 {.center_freq = 2442, .hw_value = 7, },
1060 {.center_freq = 2447, .hw_value = 8, },
1061 {.center_freq = 2452, .hw_value = 9, },
1062 {.center_freq = 2457, .hw_value = 10, },
1063 {.center_freq = 2462, .hw_value = 11, },
1064 {.center_freq = 2467, .hw_value = 12, },
1065 {.center_freq = 2472, .hw_value = 13, },
1066 {.center_freq = 2484, .hw_value = 14, },
1067};
1068
1069static struct ieee80211_supported_band mwifiex_band_2ghz = {
1070 .channels = mwifiex_channels_2ghz,
1071 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1072 .bitrates = mwifiex_rates,
8763848e 1073 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
5e6e3a92
BZ
1074};
1075
1076static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1077 {.center_freq = 5040, .hw_value = 8, },
1078 {.center_freq = 5060, .hw_value = 12, },
1079 {.center_freq = 5080, .hw_value = 16, },
1080 {.center_freq = 5170, .hw_value = 34, },
1081 {.center_freq = 5190, .hw_value = 38, },
1082 {.center_freq = 5210, .hw_value = 42, },
1083 {.center_freq = 5230, .hw_value = 46, },
1084 {.center_freq = 5180, .hw_value = 36, },
1085 {.center_freq = 5200, .hw_value = 40, },
1086 {.center_freq = 5220, .hw_value = 44, },
1087 {.center_freq = 5240, .hw_value = 48, },
1088 {.center_freq = 5260, .hw_value = 52, },
1089 {.center_freq = 5280, .hw_value = 56, },
1090 {.center_freq = 5300, .hw_value = 60, },
1091 {.center_freq = 5320, .hw_value = 64, },
1092 {.center_freq = 5500, .hw_value = 100, },
1093 {.center_freq = 5520, .hw_value = 104, },
1094 {.center_freq = 5540, .hw_value = 108, },
1095 {.center_freq = 5560, .hw_value = 112, },
1096 {.center_freq = 5580, .hw_value = 116, },
1097 {.center_freq = 5600, .hw_value = 120, },
1098 {.center_freq = 5620, .hw_value = 124, },
1099 {.center_freq = 5640, .hw_value = 128, },
1100 {.center_freq = 5660, .hw_value = 132, },
1101 {.center_freq = 5680, .hw_value = 136, },
1102 {.center_freq = 5700, .hw_value = 140, },
1103 {.center_freq = 5745, .hw_value = 149, },
1104 {.center_freq = 5765, .hw_value = 153, },
1105 {.center_freq = 5785, .hw_value = 157, },
1106 {.center_freq = 5805, .hw_value = 161, },
1107 {.center_freq = 5825, .hw_value = 165, },
1108};
1109
1110static struct ieee80211_supported_band mwifiex_band_5ghz = {
1111 .channels = mwifiex_channels_5ghz,
1112 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
eb416ad3
AP
1113 .bitrates = mwifiex_rates + 4,
1114 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
5e6e3a92
BZ
1115};
1116
1117
1118/* Supported crypto cipher suits to be advertised to cfg80211 */
5e6e3a92
BZ
1119static const u32 mwifiex_cipher_suites[] = {
1120 WLAN_CIPHER_SUITE_WEP40,
1121 WLAN_CIPHER_SUITE_WEP104,
1122 WLAN_CIPHER_SUITE_TKIP,
1123 WLAN_CIPHER_SUITE_CCMP,
53b11231 1124 WLAN_CIPHER_SUITE_AES_CMAC,
5e6e3a92
BZ
1125};
1126
83719be8
SP
1127/* Supported mgmt frame types to be advertised to cfg80211 */
1128static const struct ieee80211_txrx_stypes
1129mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1130 [NL80211_IFTYPE_STATION] = {
1131 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1132 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1133 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1134 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1135 },
1136 [NL80211_IFTYPE_AP] = {
1137 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1138 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1139 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1140 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1141 },
1142 [NL80211_IFTYPE_P2P_CLIENT] = {
1143 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1144 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1145 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1146 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1147 },
1148 [NL80211_IFTYPE_P2P_GO] = {
1149 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1150 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1151 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1152 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1153 },
1154};
1155
5d82c53a
YAP
1156/*
1157 * CFG802.11 operation handler for setting bit rates.
1158 *
433c3990
AK
1159 * Function configures data rates to firmware using bitrate mask
1160 * provided by cfg80211.
5d82c53a
YAP
1161 */
1162static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1163 struct net_device *dev,
1164 const u8 *peer,
1165 const struct cfg80211_bitrate_mask *mask)
1166{
5d82c53a 1167 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
433c3990
AK
1168 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1169 enum ieee80211_band band;
5d82c53a 1170
433c3990
AK
1171 if (!priv->media_connected) {
1172 dev_err(priv->adapter->dev,
1173 "Can not set Tx data rate in disconnected state\n");
1174 return -EINVAL;
5d82c53a
YAP
1175 }
1176
433c3990 1177 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5d82c53a 1178
433c3990 1179 memset(bitmap_rates, 0, sizeof(bitmap_rates));
5d82c53a 1180
433c3990
AK
1181 /* Fill HR/DSSS rates. */
1182 if (band == IEEE80211_BAND_2GHZ)
1183 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
5d82c53a 1184
433c3990
AK
1185 /* Fill OFDM rates */
1186 if (band == IEEE80211_BAND_2GHZ)
1187 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1188 else
1189 bitmap_rates[1] = mask->control[band].legacy;
1190
d1e33e65
JD
1191 /* Fill HT MCS rates */
1192 bitmap_rates[2] = mask->control[band].ht_mcs[0];
433c3990 1193 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
d1e33e65 1194 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
433c3990
AK
1195
1196 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
1197 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
5d82c53a
YAP
1198}
1199
fa444bf8
AK
1200/*
1201 * CFG802.11 operation handler for connection quality monitoring.
1202 *
1203 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1204 * events to FW.
1205 */
1206static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1207 struct net_device *dev,
1208 s32 rssi_thold, u32 rssi_hyst)
1209{
1210 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1211 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1212
1213 priv->cqm_rssi_thold = rssi_thold;
1214 priv->cqm_rssi_hyst = rssi_hyst;
1215
1216 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1217 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1218
1219 /* Subscribe/unsubscribe low and high rssi events */
1220 if (rssi_thold && rssi_hyst) {
1221 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1222 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1223 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1224 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1225 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
1226 return mwifiex_send_cmd_sync(priv,
1227 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1228 0, 0, &subsc_evt);
1229 } else {
1230 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
1231 return mwifiex_send_cmd_sync(priv,
1232 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1233 0, 0, &subsc_evt);
1234 }
1235
1236 return 0;
1237}
1238
5370c836
AP
1239/* cfg80211 operation handler for change_beacon.
1240 * Function retrieves and sets modified management IEs to FW.
1241 */
1242static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1243 struct net_device *dev,
1244 struct cfg80211_beacon_data *data)
1245{
1246 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1247
9197ab9e 1248 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
5370c836
AP
1249 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
1250 return -EINVAL;
1251 }
1252
1253 if (!priv->bss_started) {
1254 wiphy_err(wiphy, "%s: bss not started\n", __func__);
1255 return -EINVAL;
1256 }
1257
1258 if (mwifiex_set_mgmt_ies(priv, data)) {
1259 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
1260 return -EFAULT;
1261 }
1262
1263 return 0;
1264}
1265
0f9e9b8b
AP
1266/* cfg80211 operation handler for del_station.
1267 * Function deauthenticates station which value is provided in mac parameter.
1268 * If mac is NULL/broadcast, all stations in associated station list are
1269 * deauthenticated. If bss is not started or there are no stations in
1270 * associated stations list, no action is taken.
1271 */
1272static int
1273mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1274 u8 *mac)
1275{
1276 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1277 struct mwifiex_sta_node *sta_node;
1278 unsigned long flags;
1279
1280 if (list_empty(&priv->sta_list) || !priv->bss_started)
1281 return 0;
1282
1283 if (!mac || is_broadcast_ether_addr(mac)) {
1284 wiphy_dbg(wiphy, "%s: NULL/broadcast mac address\n", __func__);
1285 list_for_each_entry(sta_node, &priv->sta_list, list) {
1286 if (mwifiex_send_cmd_sync(priv,
1287 HostCmd_CMD_UAP_STA_DEAUTH,
1288 HostCmd_ACT_GEN_SET, 0,
1289 sta_node->mac_addr))
1290 return -1;
1291 mwifiex_uap_del_sta_data(priv, sta_node);
1292 }
1293 } else {
1294 wiphy_dbg(wiphy, "%s: mac address %pM\n", __func__, mac);
1295 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1296 sta_node = mwifiex_get_sta_entry(priv, mac);
1297 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1298 if (sta_node) {
1299 if (mwifiex_send_cmd_sync(priv,
1300 HostCmd_CMD_UAP_STA_DEAUTH,
1301 HostCmd_ACT_GEN_SET, 0,
1302 sta_node->mac_addr))
1303 return -1;
1304 mwifiex_uap_del_sta_data(priv, sta_node);
1305 }
1306 }
1307
1308 return 0;
1309}
1310
8a279d5b
AK
1311static int
1312mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1313{
1314 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1315 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1316 MWIFIEX_BSS_ROLE_ANY);
1317 struct mwifiex_ds_ant_cfg ant_cfg;
1318
1319 if (!tx_ant || !rx_ant)
1320 return -EOPNOTSUPP;
1321
1322 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1323 /* Not a MIMO chip. User should provide specific antenna number
1324 * for Tx/Rx path or enable all antennas for diversity
1325 */
1326 if (tx_ant != rx_ant)
1327 return -EOPNOTSUPP;
1328
1329 if ((tx_ant & (tx_ant - 1)) &&
1330 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1331 return -EOPNOTSUPP;
1332
1333 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1334 (priv->adapter->number_of_antenna > 1)) {
1335 tx_ant = RF_ANTENNA_AUTO;
1336 rx_ant = RF_ANTENNA_AUTO;
1337 }
1338 }
1339
1340 ant_cfg.tx_ant = tx_ant;
1341 ant_cfg.rx_ant = rx_ant;
1342
1343 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
1344 HostCmd_ACT_GEN_SET, 0, &ant_cfg);
1345}
1346
12190c5d
AP
1347/* cfg80211 operation handler for stop ap.
1348 * Function stops BSS running at uAP interface.
1349 */
1350static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1351{
1352 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1353
40bbc21a
AP
1354 if (mwifiex_del_mgmt_ies(priv))
1355 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
1356
c8258913
AP
1357 priv->ap_11n_enabled = 0;
1358
12190c5d
AP
1359 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1360 HostCmd_ACT_GEN_SET, 0, NULL)) {
1361 wiphy_err(wiphy, "Failed to stop the BSS\n");
1362 return -1;
1363 }
1364
1365 return 0;
1366}
1367
1368/* cfg80211 operation handler for start_ap.
1369 * Function sets beacon period, DTIM period, SSID and security into
1370 * AP config structure.
1371 * AP is configured with these settings and BSS is started.
1372 */
1373static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1374 struct net_device *dev,
1375 struct cfg80211_ap_settings *params)
1376{
1377 struct mwifiex_uap_bss_param *bss_cfg;
1378 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
05910f4a 1379 u8 config_bands = 0;
12190c5d 1380
9197ab9e 1381 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
f752dcd5 1382 return -1;
adb6ed0c 1383 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
f31acabe 1384 return -1;
f752dcd5 1385
12190c5d
AP
1386 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1387 if (!bss_cfg)
1388 return -ENOMEM;
1389
1390 mwifiex_set_sys_config_invalid_data(bss_cfg);
1391
1392 if (params->beacon_interval)
1393 bss_cfg->beacon_period = params->beacon_interval;
1394 if (params->dtim_period)
1395 bss_cfg->dtim_period = params->dtim_period;
1396
1397 if (params->ssid && params->ssid_len) {
1398 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1399 bss_cfg->ssid.ssid_len = params->ssid_len;
1400 }
1401
7a1c9934
AP
1402 switch (params->hidden_ssid) {
1403 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1404 bss_cfg->bcast_ssid_ctl = 1;
1405 break;
1406 case NL80211_HIDDEN_SSID_ZERO_LEN:
1407 bss_cfg->bcast_ssid_ctl = 0;
1408 break;
1409 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1410 /* firmware doesn't support this type of hidden SSID */
1411 default:
b3190466 1412 kfree(bss_cfg);
7a1c9934
AP
1413 return -EINVAL;
1414 }
1415
683b6d3b
JB
1416 bss_cfg->channel = ieee80211_frequency_to_channel(
1417 params->chandef.chan->center_freq);
0abd79e5 1418
05910f4a 1419 /* Set appropriate bands */
683b6d3b 1420 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
a3c2c4f6 1421 bss_cfg->band_cfg = BAND_CONFIG_BG;
a5f39056 1422 config_bands = BAND_B | BAND_G;
a3c2c4f6 1423
a5f39056
YAP
1424 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1425 config_bands |= BAND_GN;
1426
1427 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1428 config_bands |= BAND_GAC;
05910f4a 1429 } else {
a3c2c4f6 1430 bss_cfg->band_cfg = BAND_CONFIG_A;
a5f39056 1431 config_bands = BAND_A;
a3c2c4f6 1432
a5f39056
YAP
1433 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1434 config_bands |= BAND_AN;
1435
1436 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1437 config_bands |= BAND_AAC;
0abd79e5
AP
1438 }
1439
05910f4a
AK
1440 if (!((config_bands | priv->adapter->fw_bands) &
1441 ~priv->adapter->fw_bands))
1442 priv->adapter->config_bands = config_bands;
1443
a3c2c4f6 1444 mwifiex_set_uap_rates(bss_cfg, params);
05910f4a
AK
1445 mwifiex_send_domain_info_cmd_fw(wiphy);
1446
f752dcd5
AP
1447 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1448 kfree(bss_cfg);
1449 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1450 return -1;
1451 }
1452
22281256 1453 mwifiex_set_ht_params(priv, bss_cfg, params);
83c78da9
YAP
1454
1455 if (priv->adapter->is_hw_11ac_capable) {
1456 mwifiex_set_vht_params(priv, bss_cfg, params);
1457 mwifiex_set_vht_width(priv, params->chandef.width,
1458 priv->ap_11ac_enabled);
1459 }
1460
2b6254da
AP
1461 if (priv->ap_11ac_enabled)
1462 mwifiex_set_11ac_ba_params(priv);
1463 else
1464 mwifiex_set_ba_params(priv);
1465
54428c57 1466 mwifiex_set_wmm_params(priv, bss_cfg, params);
22281256 1467
8b4509f6
KG
1468 if (params->inactivity_timeout > 0) {
1469 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1470 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1471 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1472 }
1473
12190c5d
AP
1474 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_UAP_BSS_STOP,
1475 HostCmd_ACT_GEN_SET, 0, NULL)) {
1476 wiphy_err(wiphy, "Failed to stop the BSS\n");
1477 kfree(bss_cfg);
1478 return -1;
1479 }
1480
1481 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
e76268da
AP
1482 HostCmd_ACT_GEN_SET,
1483 UAP_BSS_PARAMS_I, bss_cfg)) {
12190c5d
AP
1484 wiphy_err(wiphy, "Failed to set the SSID\n");
1485 kfree(bss_cfg);
1486 return -1;
1487 }
1488
1489 kfree(bss_cfg);
1490
1491 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_BSS_START,
1492 HostCmd_ACT_GEN_SET, 0, NULL)) {
1493 wiphy_err(wiphy, "Failed to start the BSS\n");
1494 return -1;
1495 }
1496
96893538
AP
1497 if (priv->sec_info.wep_enabled)
1498 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1499 else
1500 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1501
1502 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1503 HostCmd_ACT_GEN_SET, 0,
1504 &priv->curr_pkt_filter))
1505 return -1;
1506
12190c5d
AP
1507 return 0;
1508}
1509
5e6e3a92
BZ
1510/*
1511 * CFG802.11 operation handler for disconnection request.
1512 *
1513 * This function does not work when there is already a disconnection
1514 * procedure going on.
1515 */
1516static int
1517mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1518 u16 reason_code)
1519{
1520 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1521
600f5d90 1522 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1523 return -EFAULT;
1524
1525 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1526 " reason code %d\n", priv->cfg_bssid, reason_code);
1527
38c9d664 1528 memset(priv->cfg_bssid, 0, ETH_ALEN);
587b36d3 1529 priv->hs2_enabled = false;
5e6e3a92
BZ
1530
1531 return 0;
1532}
1533
1534/*
1535 * This function informs the CFG802.11 subsystem of a new IBSS.
1536 *
1537 * The following information are sent to the CFG802.11 subsystem
1538 * to register the new IBSS. If we do not register the new IBSS,
1539 * a kernel panic will result.
1540 * - SSID
1541 * - SSID length
1542 * - BSSID
1543 * - Channel
1544 */
1545static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1546{
5e6e3a92
BZ
1547 struct ieee80211_channel *chan;
1548 struct mwifiex_bss_info bss_info;
aa95a48d 1549 struct cfg80211_bss *bss;
270e58e8 1550 int ie_len;
5e6e3a92 1551 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
4ed5d521 1552 enum ieee80211_band band;
5e6e3a92 1553
636c4598
YAP
1554 if (mwifiex_get_bss_info(priv, &bss_info))
1555 return -1;
5e6e3a92
BZ
1556
1557 ie_buf[0] = WLAN_EID_SSID;
1558 ie_buf[1] = bss_info.ssid.ssid_len;
1559
1560 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
aea0701e 1561 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
5e6e3a92
BZ
1562 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1563
4ed5d521 1564 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5e6e3a92
BZ
1565 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1566 ieee80211_channel_to_frequency(bss_info.bss_chan,
4ed5d521 1567 band));
5e6e3a92 1568
aa95a48d 1569 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
aea0701e
YAP
1570 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1571 0, ie_buf, ie_len, 0, GFP_KERNEL);
5b112d3d 1572 cfg80211_put_bss(priv->wdev->wiphy, bss);
5e6e3a92
BZ
1573 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1574
636c4598 1575 return 0;
5e6e3a92
BZ
1576}
1577
5e6e3a92
BZ
1578/*
1579 * This function connects with a BSS.
1580 *
1581 * This function handles both Infra and Ad-Hoc modes. It also performs
1582 * validity checking on the provided parameters, disconnects from the
1583 * current BSS (if any), sets up the association/scan parameters,
1584 * including security settings, and performs specific SSID scan before
1585 * trying to connect.
1586 *
1587 * For Infra mode, the function returns failure if the specified SSID
1588 * is not found in scan table. However, for Ad-Hoc mode, it can create
1589 * the IBSS if it does not exist. On successful completion in either case,
7c6fa2a8 1590 * the function notifies the CFG802.11 subsystem of the new BSS connection.
5e6e3a92
BZ
1591 */
1592static int
1593mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, u8 *ssid,
1594 u8 *bssid, int mode, struct ieee80211_channel *channel,
1595 struct cfg80211_connect_params *sme, bool privacy)
1596{
b9be5f39 1597 struct cfg80211_ssid req_ssid;
270e58e8 1598 int ret, auth_type = 0;
7c6fa2a8 1599 struct cfg80211_bss *bss = NULL;
d7b9c520 1600 u8 is_scanning_required = 0;
5e6e3a92 1601
b9be5f39 1602 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
5e6e3a92
BZ
1603
1604 req_ssid.ssid_len = ssid_len;
1605 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1606 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1607 return -EINVAL;
1608 }
1609
1610 memcpy(req_ssid.ssid, ssid, ssid_len);
1611 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1612 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1613 return -EINVAL;
1614 }
1615
1616 /* disconnect before try to associate */
600f5d90 1617 mwifiex_deauthenticate(priv, NULL);
5e6e3a92 1618
6670f15b
AK
1619 /* As this is new association, clear locally stored
1620 * keys and security related flags */
1621 priv->sec_info.wpa_enabled = false;
1622 priv->sec_info.wpa2_enabled = false;
1623 priv->wep_key_curr_index = 0;
00f157b4 1624 priv->sec_info.encryption_mode = 0;
a0f6d6ca 1625 priv->sec_info.is_authtype_auto = 0;
53b11231 1626 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
5e6e3a92 1627
eecd8250 1628 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1629 /* "privacy" is set only for ad-hoc mode */
1630 if (privacy) {
1631 /*
2be50b8d 1632 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
5e6e3a92
BZ
1633 * the firmware can find a matching network from the
1634 * scan. The cfg80211 does not give us the encryption
1635 * mode at this stage so just setting it to WEP here.
1636 */
203afeca 1637 priv->sec_info.encryption_mode =
2be50b8d 1638 WLAN_CIPHER_SUITE_WEP104;
203afeca 1639 priv->sec_info.authentication_mode =
f986b6d5 1640 NL80211_AUTHTYPE_OPEN_SYSTEM;
5e6e3a92
BZ
1641 }
1642
1643 goto done;
1644 }
1645
1646 /* Now handle infra mode. "sme" is valid for infra mode only */
a0f6d6ca 1647 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
f986b6d5 1648 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
a0f6d6ca
AK
1649 priv->sec_info.is_authtype_auto = 1;
1650 } else {
1651 auth_type = sme->auth_type;
1652 }
5e6e3a92
BZ
1653
1654 if (sme->crypto.n_ciphers_pairwise) {
2be50b8d
YAP
1655 priv->sec_info.encryption_mode =
1656 sme->crypto.ciphers_pairwise[0];
203afeca 1657 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1658 }
1659
1660 if (sme->crypto.cipher_group) {
2be50b8d 1661 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
203afeca 1662 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1663 }
1664 if (sme->ie)
1665 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1666
1667 if (sme->key) {
e6faada5 1668 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
5e6e3a92
BZ
1669 dev_dbg(priv->adapter->dev,
1670 "info: setting wep encryption"
1671 " with key len %d\n", sme->key_len);
6670f15b 1672 priv->wep_key_curr_index = sme->key_idx;
53b11231
YL
1673 ret = mwifiex_set_encode(priv, NULL, sme->key,
1674 sme->key_len, sme->key_idx,
1675 NULL, 0);
5e6e3a92
BZ
1676 }
1677 }
1678done:
7c6fa2a8
AK
1679 /*
1680 * Scan entries are valid for some time (15 sec). So we can save one
1681 * active scan time if we just try cfg80211_get_bss first. If it fails
1682 * then request scan and cfg80211_get_bss() again for final output.
1683 */
1684 while (1) {
1685 if (is_scanning_required) {
1686 /* Do specific SSID scanning */
1687 if (mwifiex_request_scan(priv, &req_ssid)) {
1688 dev_err(priv->adapter->dev, "scan error\n");
1689 return -EFAULT;
1690 }
1691 }
5e6e3a92 1692
7c6fa2a8
AK
1693 /* Find the BSS we want using available scan results */
1694 if (mode == NL80211_IFTYPE_ADHOC)
1695 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1696 bssid, ssid, ssid_len,
1697 WLAN_CAPABILITY_IBSS,
1698 WLAN_CAPABILITY_IBSS);
1699 else
1700 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1701 bssid, ssid, ssid_len,
1702 WLAN_CAPABILITY_ESS,
1703 WLAN_CAPABILITY_ESS);
1704
1705 if (!bss) {
1706 if (is_scanning_required) {
aea0701e
YAP
1707 dev_warn(priv->adapter->dev,
1708 "assoc: requested bss not found in scan results\n");
7c6fa2a8
AK
1709 break;
1710 }
1711 is_scanning_required = 1;
1712 } else {
aea0701e
YAP
1713 dev_dbg(priv->adapter->dev,
1714 "info: trying to associate to '%s' bssid %pM\n",
1715 (char *) req_ssid.ssid, bss->bssid);
7c6fa2a8
AK
1716 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1717 break;
1718 }
5e6e3a92
BZ
1719 }
1720
06975884
AK
1721 ret = mwifiex_bss_start(priv, bss, &req_ssid);
1722 if (ret)
1723 return ret;
5e6e3a92 1724
eecd8250 1725 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1726 /* Inform the BSS information to kernel, otherwise
1727 * kernel will give a panic after successful assoc */
1728 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1729 return -EFAULT;
1730 }
1731
1732 return ret;
1733}
1734
1735/*
1736 * CFG802.11 operation handler for association request.
1737 *
1738 * This function does not work when the current mode is set to Ad-Hoc, or
1739 * when there is already an association procedure going on. The given BSS
1740 * information is used to associate.
1741 */
1742static int
1743mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1744 struct cfg80211_connect_params *sme)
1745{
1746 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
8bc77a4d 1747 int ret;
5e6e3a92 1748
953b3539 1749 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
8bc77a4d 1750 wiphy_err(wiphy,
953b3539 1751 "%s: reject infra assoc request in non-STA role\n",
8bc77a4d
BZ
1752 dev->name);
1753 return -EINVAL;
e568634a
AP
1754 }
1755
5e6e3a92 1756 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
aea0701e 1757 (char *) sme->ssid, sme->bssid);
5e6e3a92
BZ
1758
1759 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
eecd8250 1760 priv->bss_mode, sme->channel, sme, 0);
38c9d664
AK
1761 if (!ret) {
1762 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1763 NULL, 0, WLAN_STATUS_SUCCESS,
1764 GFP_KERNEL);
1765 dev_dbg(priv->adapter->dev,
1766 "info: associated to bssid %pM successfully\n",
1767 priv->cfg_bssid);
1768 } else {
1769 dev_dbg(priv->adapter->dev,
1770 "info: association to bssid %pM failed\n",
1771 priv->cfg_bssid);
1772 memset(priv->cfg_bssid, 0, ETH_ALEN);
06975884
AK
1773
1774 if (ret > 0)
1775 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1776 NULL, 0, NULL, 0, ret,
1777 GFP_KERNEL);
1778 else
1779 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1780 NULL, 0, NULL, 0,
1781 WLAN_STATUS_UNSPECIFIED_FAILURE,
1782 GFP_KERNEL);
38c9d664
AK
1783 }
1784
06975884 1785 return 0;
5e6e3a92
BZ
1786}
1787
05910f4a
AK
1788/*
1789 * This function sets following parameters for ibss network.
1790 * - channel
1791 * - start band
1792 * - 11n flag
1793 * - secondary channel offset
1794 */
1795static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1796 struct cfg80211_ibss_params *params)
1797{
1798 struct wiphy *wiphy = priv->wdev->wiphy;
1799 struct mwifiex_adapter *adapter = priv->adapter;
1800 int index = 0, i;
1801 u8 config_bands = 0;
1802
683b6d3b 1803 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
05910f4a
AK
1804 if (!params->basic_rates) {
1805 config_bands = BAND_B | BAND_G;
1806 } else {
1807 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1808 /*
1809 * Rates below 6 Mbps in the table are CCK
1810 * rates; 802.11b and from 6 they are OFDM;
1811 * 802.11G
1812 */
1813 if (mwifiex_rates[i].bitrate == 60) {
1814 index = 1 << i;
1815 break;
1816 }
1817 }
1818
1819 if (params->basic_rates < index) {
1820 config_bands = BAND_B;
1821 } else {
1822 config_bands = BAND_G;
1823 if (params->basic_rates % index)
1824 config_bands |= BAND_B;
1825 }
1826 }
1827
683b6d3b
JB
1828 if (cfg80211_get_chandef_type(&params->chandef) !=
1829 NL80211_CHAN_NO_HT)
3b86acb8 1830 config_bands |= BAND_G | BAND_GN;
05910f4a 1831 } else {
c3ff0b2d 1832 if (cfg80211_get_chandef_type(&params->chandef) ==
683b6d3b 1833 NL80211_CHAN_NO_HT)
05910f4a
AK
1834 config_bands = BAND_A;
1835 else
1836 config_bands = BAND_AN | BAND_A;
1837 }
1838
1839 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1840 adapter->config_bands = config_bands;
1841 adapter->adhoc_start_band = config_bands;
1842
1843 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1844 adapter->adhoc_11n_enabled = true;
1845 else
1846 adapter->adhoc_11n_enabled = false;
1847 }
1848
1849 adapter->sec_chan_offset =
683b6d3b
JB
1850 mwifiex_chan_type_to_sec_chan_offset(
1851 cfg80211_get_chandef_type(&params->chandef));
1852 priv->adhoc_channel = ieee80211_frequency_to_channel(
1853 params->chandef.chan->center_freq);
05910f4a
AK
1854
1855 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1856 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1857
1858 return 0;
1859}
1860
5e6e3a92
BZ
1861/*
1862 * CFG802.11 operation handler to join an IBSS.
1863 *
1864 * This function does not work in any mode other than Ad-Hoc, or if
1865 * a join operation is already in progress.
1866 */
1867static int
1868mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1869 struct cfg80211_ibss_params *params)
1870{
f540f9f3 1871 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1872 int ret = 0;
5e6e3a92 1873
eecd8250 1874 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1875 wiphy_err(wiphy, "request to join ibss received "
1876 "when station is not in ibss mode\n");
1877 goto done;
1878 }
1879
5e6e3a92 1880 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
aea0701e 1881 (char *) params->ssid, params->bssid);
5e6e3a92 1882
05910f4a
AK
1883 mwifiex_set_ibss_params(priv, params);
1884
5e6e3a92 1885 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
aea0701e 1886 params->bssid, priv->bss_mode,
683b6d3b
JB
1887 params->chandef.chan, NULL,
1888 params->privacy);
5e6e3a92 1889done:
38c9d664
AK
1890 if (!ret) {
1891 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1892 dev_dbg(priv->adapter->dev,
1893 "info: joined/created adhoc network with bssid"
1894 " %pM successfully\n", priv->cfg_bssid);
1895 } else {
1896 dev_dbg(priv->adapter->dev,
1897 "info: failed creating/joining adhoc network\n");
1898 }
1899
5e6e3a92
BZ
1900 return ret;
1901}
1902
1903/*
1904 * CFG802.11 operation handler to leave an IBSS.
1905 *
1906 * This function does not work if a leave operation is
1907 * already in progress.
1908 */
1909static int
1910mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1911{
f540f9f3 1912 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1913
5e6e3a92 1914 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
aea0701e 1915 priv->cfg_bssid);
600f5d90 1916 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1917 return -EFAULT;
1918
38c9d664 1919 memset(priv->cfg_bssid, 0, ETH_ALEN);
5e6e3a92
BZ
1920
1921 return 0;
1922}
1923
1924/*
1925 * CFG802.11 operation handler for scan request.
1926 *
1927 * This function issues a scan request to the firmware based upon
1928 * the user specified scan configuration. On successfull completion,
1929 * it also informs the results.
1930 */
1931static int
fd014284 1932mwifiex_cfg80211_scan(struct wiphy *wiphy,
5e6e3a92
BZ
1933 struct cfg80211_scan_request *request)
1934{
fd014284 1935 struct net_device *dev = request->wdev->netdev;
5e6e3a92 1936 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
c2476335 1937 int i, offset, ret;
38c9d664 1938 struct ieee80211_channel *chan;
ea021f56 1939 struct ieee_types_header *ie;
75ab753d 1940 struct mwifiex_user_scan_cfg *user_scan_cfg;
5e6e3a92
BZ
1941
1942 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1943
e45a8419
AK
1944 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
1945 atomic_read(&priv->wmm.tx_pkts_queued) >=
de09364e
AK
1946 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1947 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1948 return -EBUSY;
1949 }
1950
75ab753d
AK
1951 /* Block scan request if scan operation or scan cleanup when interface
1952 * is disabled is in process
1953 */
1954 if (priv->scan_request || priv->scan_aborting) {
f162cac8
AK
1955 dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
1956 return -EBUSY;
1957 }
1958
75ab753d
AK
1959 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1960 if (!user_scan_cfg)
38c9d664 1961 return -ENOMEM;
be0b281e 1962
6fcf2b10
BZ
1963 priv->scan_request = request;
1964
75ab753d
AK
1965 user_scan_cfg->num_ssids = request->n_ssids;
1966 user_scan_cfg->ssid_list = request->ssids;
be0b281e 1967
13d7ba78 1968 if (request->ie && request->ie_len) {
ea021f56 1969 offset = 0;
13d7ba78
AP
1970 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1971 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1972 continue;
1973 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
ea021f56
SP
1974 ie = (struct ieee_types_header *)(request->ie + offset);
1975 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
1976 offset += sizeof(*ie) + ie->len;
1977
1978 if (offset >= request->ie_len)
1979 break;
13d7ba78
AP
1980 }
1981 }
1982
901ceba4
SP
1983 for (i = 0; i < min_t(u32, request->n_channels,
1984 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
38c9d664 1985 chan = request->channels[i];
75ab753d
AK
1986 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1987 user_scan_cfg->chan_list[i].radio_type = chan->band;
38c9d664 1988
8fe02e16 1989 if (chan->flags & IEEE80211_CHAN_NO_IR)
75ab753d 1990 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1991 MWIFIEX_SCAN_TYPE_PASSIVE;
38c9d664 1992 else
75ab753d 1993 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1994 MWIFIEX_SCAN_TYPE_ACTIVE;
38c9d664 1995
75ab753d 1996 user_scan_cfg->chan_list[i].scan_time = 0;
38c9d664 1997 }
c2476335 1998
75ab753d
AK
1999 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2000 kfree(user_scan_cfg);
c2476335
BZ
2001 if (ret) {
2002 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
75ab753d 2003 priv->scan_aborting = false;
6fcf2b10 2004 priv->scan_request = NULL;
c2476335
BZ
2005 return ret;
2006 }
38c9d664 2007
13d7ba78
AP
2008 if (request->ie && request->ie_len) {
2009 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2010 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2011 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2012 memset(&priv->vs_ie[i].ie, 0,
2013 MWIFIEX_MAX_VSIE_LEN);
2014 }
2015 }
2016 }
5e6e3a92
BZ
2017 return 0;
2018}
2019
a5f39056
YAP
2020static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2021 struct mwifiex_private *priv)
2022{
2023 struct mwifiex_adapter *adapter = priv->adapter;
a5f39056
YAP
2024
2025 vht_info->vht_supported = true;
2026
43283feb 2027 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
a5f39056
YAP
2028 /* Update MCS support for VHT */
2029 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2030 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2031 vht_info->vht_mcs.rx_highest = 0;
2032 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2033 adapter->hw_dot_11ac_mcs_support >> 16);
2034 vht_info->vht_mcs.tx_highest = 0;
2035}
2036
5e6e3a92
BZ
2037/*
2038 * This function sets up the CFG802.11 specific HT capability fields
2039 * with default values.
2040 *
2041 * The following default values are set -
2042 * - HT Supported = True
a46b7b5c
AK
2043 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2044 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2045 * - HT Capabilities supported by firmware
5e6e3a92
BZ
2046 * - MCS information, Rx mask = 0xff
2047 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2048 */
2049static void
2050mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2051 struct mwifiex_private *priv)
2052{
2053 int rx_mcs_supp;
2054 struct ieee80211_mcs_info mcs_set;
2055 u8 *mcs = (u8 *)&mcs_set;
2056 struct mwifiex_adapter *adapter = priv->adapter;
2057
2058 ht_info->ht_supported = true;
a46b7b5c
AK
2059 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2060 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
5e6e3a92
BZ
2061
2062 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
5e6e3a92 2063
a46b7b5c
AK
2064 /* Fill HT capability information */
2065 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2066 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2067 else
2068 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2069
2070 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2071 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2072 else
2073 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2074
2075 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2076 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2077 else
2078 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2079
2080 if (ISSUPP_RXSTBC(adapter->hw_dot_11n_dev_cap))
2081 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
2082 else
2083 ht_info->cap &= ~(3 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
2084
2085 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2086 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2087 else
2088 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2089
dd0d83c2
AP
2090 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2091 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2092 else
2093 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2094
2095 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2096 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2097 else
2098 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2099
2100 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2101 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2102 else
2103 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2104
a46b7b5c
AK
2105 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2106 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2107
2108 rx_mcs_supp = GET_RXMCSSUPP(adapter->hw_dev_mcs_support);
5e6e3a92
BZ
2109 /* Set MCS for 1x1 */
2110 memset(mcs, 0xff, rx_mcs_supp);
2111 /* Clear all the other values */
2112 memset(&mcs[rx_mcs_supp], 0,
aea0701e 2113 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
eecd8250 2114 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
aea0701e 2115 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
5e6e3a92
BZ
2116 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2117 SETHT_MCS32(mcs_set.rx_mask);
2118
2119 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2120
2121 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2122}
2123
93a1df48
YAP
2124/*
2125 * create a new virtual interface with the given name
2126 */
84efbb84 2127struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
552bff0c 2128 const char *name,
84efbb84
JB
2129 enum nl80211_iftype type,
2130 u32 *flags,
2131 struct vif_params *params)
93a1df48 2132{
67fdf39e
AP
2133 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2134 struct mwifiex_private *priv;
93a1df48
YAP
2135 struct net_device *dev;
2136 void *mdev_priv;
d6bffe8b 2137 struct wireless_dev *wdev;
93a1df48 2138
93a1df48 2139 if (!adapter)
858faa57 2140 return ERR_PTR(-EFAULT);
93a1df48
YAP
2141
2142 switch (type) {
2143 case NL80211_IFTYPE_UNSPECIFIED:
2144 case NL80211_IFTYPE_STATION:
2145 case NL80211_IFTYPE_ADHOC:
d6bffe8b 2146 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
93a1df48 2147 if (priv->bss_mode) {
d6bffe8b
AP
2148 wiphy_err(wiphy,
2149 "cannot create multiple sta/adhoc ifaces\n");
858faa57 2150 return ERR_PTR(-EINVAL);
93a1df48
YAP
2151 }
2152
d6bffe8b
AP
2153 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2154 if (!wdev)
858faa57 2155 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2156
2157 wdev->wiphy = wiphy;
2158 priv->wdev = wdev;
2159 wdev->iftype = NL80211_IFTYPE_STATION;
2160
93a1df48
YAP
2161 if (type == NL80211_IFTYPE_UNSPECIFIED)
2162 priv->bss_mode = NL80211_IFTYPE_STATION;
2163 else
2164 priv->bss_mode = type;
2165
2166 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2167 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2168 priv->bss_priority = 0;
93a1df48 2169 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
93a1df48
YAP
2170 priv->bss_num = 0;
2171
d6bffe8b
AP
2172 break;
2173 case NL80211_IFTYPE_AP:
2174 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
2175
2176 if (priv->bss_mode) {
2177 wiphy_err(wiphy, "Can't create multiple AP interfaces");
858faa57 2178 return ERR_PTR(-EINVAL);
d6bffe8b
AP
2179 }
2180
2181 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2182 if (!wdev)
858faa57 2183 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2184
2185 priv->wdev = wdev;
2186 wdev->wiphy = wiphy;
2187 wdev->iftype = NL80211_IFTYPE_AP;
2188
2189 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2190 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2191 priv->bss_priority = 0;
d6bffe8b
AP
2192 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2193 priv->bss_started = 0;
2194 priv->bss_num = 0;
2195 priv->bss_mode = type;
2196
197f4a2e
SP
2197 break;
2198 case NL80211_IFTYPE_P2P_CLIENT:
2199 priv = adapter->priv[MWIFIEX_BSS_TYPE_P2P];
2200
2201 if (priv->bss_mode) {
2202 wiphy_err(wiphy, "Can't create multiple P2P ifaces");
2203 return ERR_PTR(-EINVAL);
2204 }
2205
2206 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2207 if (!wdev)
2208 return ERR_PTR(-ENOMEM);
2209
2210 priv->wdev = wdev;
2211 wdev->wiphy = wiphy;
2212
2213 /* At start-up, wpa_supplicant tries to change the interface
2214 * to NL80211_IFTYPE_STATION if it is not managed mode.
197f4a2e 2215 */
5586d3e2
PS
2216 wdev->iftype = NL80211_IFTYPE_P2P_CLIENT;
2217 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
197f4a2e
SP
2218
2219 /* Setting bss_type to P2P tells firmware that this interface
2220 * is receiving P2P peers found during find phase and doing
2221 * action frame handshake.
2222 */
2223 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2224
2225 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2226 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2227 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2228 priv->bss_started = 0;
2229 priv->bss_num = 0;
2230
bec568ff
AK
2231 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2232 wdev = ERR_PTR(-EFAULT);
2233 goto done;
2234 }
66aa1ae2 2235
93a1df48
YAP
2236 break;
2237 default:
2238 wiphy_err(wiphy, "type not supported\n");
858faa57 2239 return ERR_PTR(-EINVAL);
93a1df48
YAP
2240 }
2241
47411a06
AP
2242 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2243 ether_setup, IEEE80211_NUM_ACS, 1);
93a1df48
YAP
2244 if (!dev) {
2245 wiphy_err(wiphy, "no memory available for netdevice\n");
858faa57 2246 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
bec568ff
AK
2247 wdev = ERR_PTR(-ENOMEM);
2248 goto done;
93a1df48
YAP
2249 }
2250
d6bffe8b
AP
2251 mwifiex_init_priv_params(priv, dev);
2252 priv->netdev = dev;
2253
2254 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
a5f39056
YAP
2255 if (adapter->is_hw_11ac_capable)
2256 mwifiex_setup_vht_caps(
2257 &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
d6bffe8b
AP
2258
2259 if (adapter->config_bands & BAND_A)
2260 mwifiex_setup_ht_caps(
2261 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
2262
a5f39056
YAP
2263 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2264 mwifiex_setup_vht_caps(
2265 &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
2266
93a1df48
YAP
2267 dev_net_set(dev, wiphy_net(wiphy));
2268 dev->ieee80211_ptr = priv->wdev;
2269 dev->ieee80211_ptr->iftype = priv->bss_mode;
2270 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
93a1df48
YAP
2271 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2272
2273 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2274 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2275 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
0d7f53e3 2276 dev->ethtool_ops = &mwifiex_ethtool_ops;
93a1df48
YAP
2277
2278 mdev_priv = netdev_priv(dev);
2279 *((unsigned long *) mdev_priv) = (unsigned long) priv;
2280
93a1df48
YAP
2281 SET_NETDEV_DEV(dev, adapter->dev);
2282
2283 /* Register network device */
2284 if (register_netdevice(dev)) {
2285 wiphy_err(wiphy, "cannot register virtual network device\n");
858faa57
BZ
2286 free_netdev(dev);
2287 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
bec568ff
AK
2288 priv->netdev = NULL;
2289 wdev = ERR_PTR(-EFAULT);
2290 goto done;
93a1df48
YAP
2291 }
2292
2293 sema_init(&priv->async_sem, 1);
93a1df48
YAP
2294
2295 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
2296
2297#ifdef CONFIG_DEBUG_FS
2298 mwifiex_dev_debugfs_init(priv);
2299#endif
bec568ff
AK
2300
2301done:
2302 if (IS_ERR(wdev)) {
2303 kfree(priv->wdev);
2304 priv->wdev = NULL;
2305 }
2306
84efbb84 2307 return wdev;
93a1df48
YAP
2308}
2309EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
2310
2311/*
2312 * del_virtual_intf: remove the virtual interface determined by dev
2313 */
84efbb84 2314int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
93a1df48 2315{
84efbb84 2316 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
93a1df48
YAP
2317
2318#ifdef CONFIG_DEBUG_FS
2319 mwifiex_dev_debugfs_remove(priv);
2320#endif
2321
47411a06 2322 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
93a1df48
YAP
2323
2324 if (netif_carrier_ok(priv->netdev))
2325 netif_carrier_off(priv->netdev);
2326
84efbb84
JB
2327 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2328 unregister_netdevice(wdev->netdev);
93a1df48 2329
93a1df48 2330 /* Clear the priv in adapter */
98a4635b 2331 priv->netdev->ieee80211_ptr = NULL;
93a1df48 2332 priv->netdev = NULL;
98a4635b
AK
2333 kfree(wdev);
2334 priv->wdev = NULL;
93a1df48
YAP
2335
2336 priv->media_connected = false;
2337
93a1df48
YAP
2338 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2339
2340 return 0;
2341}
2342EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
2343
7da060c1 2344static bool
0434c464
AK
2345mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
2346 u8 max_byte_seq)
7da060c1
AK
2347{
2348 int j, k, valid_byte_cnt = 0;
2349 bool dont_care_byte = false;
2350
2351 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
2352 for (k = 0; k < 8; k++) {
2353 if (pat->mask[j] & 1 << k) {
2354 memcpy(byte_seq + valid_byte_cnt,
2355 &pat->pattern[j * 8 + k], 1);
2356 valid_byte_cnt++;
2357 if (dont_care_byte)
2358 return false;
2359 } else {
2360 if (valid_byte_cnt)
2361 dont_care_byte = true;
2362 }
2363
0434c464 2364 if (valid_byte_cnt > max_byte_seq)
7da060c1
AK
2365 return false;
2366 }
2367 }
2368
0434c464 2369 byte_seq[max_byte_seq] = valid_byte_cnt;
7da060c1
AK
2370
2371 return true;
2372}
2373
d1e2586f 2374#ifdef CONFIG_PM
7da060c1
AK
2375static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
2376 struct cfg80211_wowlan *wowlan)
2377{
2378 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2379 struct mwifiex_ds_mef_cfg mef_cfg;
2380 struct mwifiex_mef_entry *mef_entry;
2381 int i, filt_num = 0, ret;
2382 bool first_pat = true;
3f4e854a 2383 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
7da060c1
AK
2384 const u8 ipv4_mc_mac[] = {0x33, 0x33};
2385 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
2386 struct mwifiex_private *priv =
2387 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
2388
2389 if (!wowlan) {
2390 dev_warn(adapter->dev, "None of the WOWLAN triggers enabled\n");
2391 return 0;
2392 }
2393
2394 if (!priv->media_connected) {
2395 dev_warn(adapter->dev,
2396 "Can not configure WOWLAN in disconnected state\n");
2397 return 0;
2398 }
2399
c678fb2a
BZ
2400 mef_entry = kzalloc(sizeof(*mef_entry), GFP_KERNEL);
2401 if (!mef_entry)
2402 return -ENOMEM;
2403
7da060c1
AK
2404 memset(&mef_cfg, 0, sizeof(mef_cfg));
2405 mef_cfg.num_entries = 1;
7da060c1
AK
2406 mef_cfg.mef_entry = mef_entry;
2407 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2408 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
2409
2410 for (i = 0; i < wowlan->n_patterns; i++) {
2411 memset(byte_seq, 0, sizeof(byte_seq));
2412 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
0434c464
AK
2413 byte_seq,
2414 MWIFIEX_MEF_MAX_BYTESEQ)) {
7da060c1
AK
2415 wiphy_err(wiphy, "Pattern not supported\n");
2416 kfree(mef_entry);
2417 return -EOPNOTSUPP;
2418 }
2419
2420 if (!wowlan->patterns[i].pkt_offset) {
2421 if (!(byte_seq[0] & 0x01) &&
3f4e854a 2422 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
7da060c1
AK
2423 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2424 continue;
2425 } else if (is_broadcast_ether_addr(byte_seq)) {
2426 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST;
2427 continue;
2428 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3f4e854a 2429 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
7da060c1 2430 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3f4e854a 2431 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
7da060c1
AK
2432 mef_cfg.criteria |= MWIFIEX_CRITERIA_MULTICAST;
2433 continue;
2434 }
2435 }
2436
2437 mef_entry->filter[filt_num].repeat = 1;
2438 mef_entry->filter[filt_num].offset =
2439 wowlan->patterns[i].pkt_offset;
2440 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
2441 sizeof(byte_seq));
2442 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2443
2444 if (first_pat)
2445 first_pat = false;
2446 else
2447 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2448
2449 filt_num++;
2450 }
2451
2452 if (wowlan->magic_pkt) {
2453 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2454 mef_entry->filter[filt_num].repeat = 16;
2455 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2456 ETH_ALEN);
3f4e854a
AK
2457 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
2458 ETH_ALEN;
7da060c1
AK
2459 mef_entry->filter[filt_num].offset = 14;
2460 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2461 if (filt_num)
2462 mef_entry->filter[filt_num].filt_action = TYPE_OR;
2463 }
2464
2465 if (!mef_cfg.criteria)
2466 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
2467 MWIFIEX_CRITERIA_UNICAST |
2468 MWIFIEX_CRITERIA_MULTICAST;
2469
2470 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MEF_CFG,
2471 HostCmd_ACT_GEN_SET, 0,
2472 &mef_cfg);
2473
2474 kfree(mef_entry);
2475 return ret;
2476}
2477
2478static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
2479{
2480 return 0;
2481}
2482
2483static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
2484 bool enabled)
2485{
2486 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2487
2488 device_set_wakeup_enable(adapter->dev, enabled);
2489}
2490#endif
2491
562fc5b3
AK
2492static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
2493{
2494 const u8 ipv4_mc_mac[] = {0x33, 0x33};
2495 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
2496 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
2497
2498 if ((byte_seq[0] & 0x01) &&
2499 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
2500 return PACKET_TYPE_UNICAST;
2501 else if (!memcmp(byte_seq, bc_mac, 4))
2502 return PACKET_TYPE_BROADCAST;
2503 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
2504 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
2505 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
2506 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
2507 return PACKET_TYPE_MULTICAST;
2508
2509 return 0;
2510}
2511
2512static int
2513mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
2514 struct cfg80211_coalesce_rules *crule,
2515 struct mwifiex_coalesce_rule *mrule)
2516{
2517 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
2518 struct filt_field_param *param;
2519 int i;
2520
2521 mrule->max_coalescing_delay = crule->delay;
2522
2523 param = mrule->params;
2524
2525 for (i = 0; i < crule->n_patterns; i++) {
2526 memset(byte_seq, 0, sizeof(byte_seq));
2527 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
2528 byte_seq,
2529 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
2530 dev_err(priv->adapter->dev, "Pattern not supported\n");
2531 return -EOPNOTSUPP;
2532 }
2533
2534 if (!crule->patterns[i].pkt_offset) {
2535 u8 pkt_type;
2536
2537 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
2538 if (pkt_type && mrule->pkt_type) {
2539 dev_err(priv->adapter->dev,
2540 "Multiple packet types not allowed\n");
2541 return -EOPNOTSUPP;
2542 } else if (pkt_type) {
2543 mrule->pkt_type = pkt_type;
2544 continue;
2545 }
2546 }
2547
2548 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
2549 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
2550 else
2551 param->operation = RECV_FILTER_MATCH_TYPE_NE;
2552
2553 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
2554 memcpy(param->operand_byte_stream, byte_seq,
2555 param->operand_len);
2556 param->offset = crule->patterns[i].pkt_offset;
2557 param++;
2558
2559 mrule->num_of_fields++;
2560 }
2561
2562 if (!mrule->pkt_type) {
2563 dev_err(priv->adapter->dev,
2564 "Packet type can not be determined\n");
2565 return -EOPNOTSUPP;
2566 }
2567
2568 return 0;
2569}
2570
2571static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
2572 struct cfg80211_coalesce *coalesce)
2573{
2574 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2575 int i, ret;
2576 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
2577 struct mwifiex_private *priv =
2578 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
2579
2580 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
2581 if (!coalesce) {
2582 dev_dbg(adapter->dev,
2583 "Disable coalesce and reset all previous rules\n");
2584 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_COALESCE_CFG,
2585 HostCmd_ACT_GEN_SET, 0,
2586 &coalesce_cfg);
2587 }
2588
2589 coalesce_cfg.num_of_rules = coalesce->n_rules;
2590 for (i = 0; i < coalesce->n_rules; i++) {
2591 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
2592 &coalesce_cfg.rule[i]);
2593 if (ret) {
2594 dev_err(priv->adapter->dev,
2595 "Recheck the patterns provided for rule %d\n",
2596 i + 1);
2597 return ret;
2598 }
2599 }
2600
2601 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_COALESCE_CFG,
2602 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg);
2603}
2604
5e6e3a92
BZ
2605/* station cfg80211 operations */
2606static struct cfg80211_ops mwifiex_cfg80211_ops = {
93a1df48
YAP
2607 .add_virtual_intf = mwifiex_add_virtual_intf,
2608 .del_virtual_intf = mwifiex_del_virtual_intf,
5e6e3a92
BZ
2609 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
2610 .scan = mwifiex_cfg80211_scan,
2611 .connect = mwifiex_cfg80211_connect,
2612 .disconnect = mwifiex_cfg80211_disconnect,
2613 .get_station = mwifiex_cfg80211_get_station,
f85aae6b 2614 .dump_station = mwifiex_cfg80211_dump_station,
5e6e3a92 2615 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
5e6e3a92
BZ
2616 .join_ibss = mwifiex_cfg80211_join_ibss,
2617 .leave_ibss = mwifiex_cfg80211_leave_ibss,
2618 .add_key = mwifiex_cfg80211_add_key,
2619 .del_key = mwifiex_cfg80211_del_key,
e39faa73 2620 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
3cec6870 2621 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
7feb4c48
SP
2622 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
2623 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
5e6e3a92
BZ
2624 .set_default_key = mwifiex_cfg80211_set_default_key,
2625 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
2626 .set_tx_power = mwifiex_cfg80211_set_tx_power,
5d82c53a 2627 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
12190c5d
AP
2628 .start_ap = mwifiex_cfg80211_start_ap,
2629 .stop_ap = mwifiex_cfg80211_stop_ap,
5370c836 2630 .change_beacon = mwifiex_cfg80211_change_beacon,
fa444bf8 2631 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
8a279d5b 2632 .set_antenna = mwifiex_cfg80211_set_antenna,
0f9e9b8b 2633 .del_station = mwifiex_cfg80211_del_station,
7da060c1
AK
2634#ifdef CONFIG_PM
2635 .suspend = mwifiex_cfg80211_suspend,
2636 .resume = mwifiex_cfg80211_resume,
2637 .set_wakeup = mwifiex_cfg80211_set_wakeup,
2638#endif
d1e2586f 2639 .set_coalesce = mwifiex_cfg80211_set_coalesce,
5e6e3a92
BZ
2640};
2641
964dc9e2
JB
2642#ifdef CONFIG_PM
2643static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
2644 .flags = WIPHY_WOWLAN_MAGIC_PKT,
3f4e854a 2645 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
964dc9e2
JB
2646 .pattern_min_len = 1,
2647 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
2648 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2649};
2650#endif
2651
3c68ef5b
AP
2652static bool mwifiex_is_valid_alpha2(const char *alpha2)
2653{
2654 if (!alpha2 || strlen(alpha2) != 2)
2655 return false;
2656
2657 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
2658 return true;
2659
2660 return false;
2661}
2662
562fc5b3
AK
2663static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
2664 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
2665 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
2666 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
2667 .pattern_min_len = 1,
2668 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
2669 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2670};
2671
5e6e3a92
BZ
2672/*
2673 * This function registers the device with CFG802.11 subsystem.
2674 *
2675 * The function creates the wireless device/wiphy, populates it with
2676 * default parameters and handler function pointers, and finally
2677 * registers the device.
2678 */
d6bffe8b
AP
2679
2680int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
5e6e3a92 2681{
270e58e8
YAP
2682 int ret;
2683 void *wdev_priv;
d6bffe8b
AP
2684 struct wiphy *wiphy;
2685 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
9e04a7c6 2686 u8 *country_code;
5e6e3a92 2687
d6bffe8b
AP
2688 /* create a new wiphy for use with cfg80211 */
2689 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
2690 sizeof(struct mwifiex_adapter *));
2691 if (!wiphy) {
2692 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
5e6e3a92
BZ
2693 return -ENOMEM;
2694 }
d6bffe8b
AP
2695 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
2696 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
83719be8 2697 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
7feb4c48 2698 wiphy->max_remain_on_channel_duration = 5000;
d6bffe8b
AP
2699 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2700 BIT(NL80211_IFTYPE_ADHOC) |
197f4a2e
SP
2701 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2702 BIT(NL80211_IFTYPE_P2P_GO) |
d6bffe8b
AP
2703 BIT(NL80211_IFTYPE_AP);
2704
2705 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
2706 if (adapter->config_bands & BAND_A)
2707 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
2708 else
2709 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
5e6e3a92 2710
cd8440da
AP
2711 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
2712 wiphy->n_iface_combinations = 1;
2713
5e6e3a92 2714 /* Initialize cipher suits */
d6bffe8b
AP
2715 wiphy->cipher_suites = mwifiex_cipher_suites;
2716 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
5e6e3a92 2717
d6bffe8b
AP
2718 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
2719 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2dd2bd6b 2720 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
cc0ba0d5 2721 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
54428c57 2722 WIPHY_FLAG_AP_UAPSD |
7feb4c48 2723 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
a2f73b6c
LR
2724 wiphy->regulatory_flags |=
2725 REGULATORY_CUSTOM_REG |
2726 REGULATORY_STRICT_REG;
cc0ba0d5
AK
2727
2728 wiphy_apply_custom_regulatory(wiphy, &mwifiex_world_regdom_custom);
2dd2bd6b 2729
7da060c1 2730#ifdef CONFIG_PM
964dc9e2 2731 wiphy->wowlan = &mwifiex_wowlan_support;
7da060c1
AK
2732#endif
2733
562fc5b3
AK
2734 wiphy->coalesce = &mwifiex_coalesce_support;
2735
2dd2bd6b 2736 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
e39faa73
SP
2737 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2738 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5e6e3a92 2739
8a279d5b
AK
2740 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
2741 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
5e6e3a92 2742
b292219f 2743 wiphy->features |= NL80211_FEATURE_HT_IBSS |
e45a8419
AK
2744 NL80211_FEATURE_INACTIVITY_TIMER |
2745 NL80211_FEATURE_LOW_PRIORITY_SCAN;
05910f4a 2746
b5abcf02 2747 /* Reserve space for mwifiex specific private data for BSS */
d6bffe8b 2748 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
5116f3ce 2749
d6bffe8b 2750 wiphy->reg_notifier = mwifiex_reg_notifier;
5e6e3a92 2751
67fdf39e 2752 /* Set struct mwifiex_adapter pointer in wiphy_priv */
d6bffe8b 2753 wdev_priv = wiphy_priv(wiphy);
67fdf39e 2754 *(unsigned long *)wdev_priv = (unsigned long)adapter;
5e6e3a92 2755
2c208890 2756 set_wiphy_dev(wiphy, priv->adapter->dev);
a7b21165 2757
d6bffe8b 2758 ret = wiphy_register(wiphy);
5e6e3a92 2759 if (ret < 0) {
d6bffe8b
AP
2760 dev_err(adapter->dev,
2761 "%s: wiphy_register failed: %d\n", __func__, ret);
2762 wiphy_free(wiphy);
5e6e3a92 2763 return ret;
5e6e3a92 2764 }
3c68ef5b
AP
2765
2766 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
2767 wiphy_info(wiphy, "driver hint alpha2: %2.2s\n", reg_alpha2);
2768 regulatory_hint(wiphy, reg_alpha2);
2769 } else {
2770 country_code = mwifiex_11d_code_2_region(adapter->region_code);
2771 if (country_code)
2772 wiphy_info(wiphy, "ignoring F/W country code %2.2s\n",
2773 country_code);
2774 }
5e6e3a92 2775
d6bffe8b 2776 adapter->wiphy = wiphy;
5e6e3a92
BZ
2777 return ret;
2778}
This page took 0.465016 seconds and 5 git commands to generate.