]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/marvell/mwifiex/cfg80211.c
mwifiex: correct channel stat buffer overflows
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / marvell / mwifiex / cfg80211.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: CFG80211
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
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"
b0497597 22#include "11n.h"
54f00849 23#include "wmm.h"
5e6e3a92 24
3c68ef5b
AP
25static char *reg_alpha2;
26module_param(reg_alpha2, charp, 0);
27
cd8440da
AP
28static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
29 {
eb5d912e 30 .max = 3, .types = BIT(NL80211_IFTYPE_STATION) |
a4df8f56 31 BIT(NL80211_IFTYPE_P2P_GO) |
eb5d912e
SL
32 BIT(NL80211_IFTYPE_P2P_CLIENT) |
33 BIT(NL80211_IFTYPE_AP),
cd8440da
AP
34 },
35};
36
cc7359b5
AP
37static const struct ieee80211_iface_combination
38mwifiex_iface_comb_ap_sta = {
cd8440da
AP
39 .limits = mwifiex_ap_sta_limits,
40 .num_different_channels = 1,
41 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
42 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
43 .beacon_int_infra_match = true,
cc7359b5
AP
44 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
45 BIT(NL80211_CHAN_WIDTH_20) |
46 BIT(NL80211_CHAN_WIDTH_40),
47};
48
49static const struct ieee80211_iface_combination
50mwifiex_iface_comb_ap_sta_vht = {
51 .limits = mwifiex_ap_sta_limits,
52 .num_different_channels = 1,
53 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
54 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
55 .beacon_int_infra_match = true,
56 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
57 BIT(NL80211_CHAN_WIDTH_20) |
58 BIT(NL80211_CHAN_WIDTH_40) |
59 BIT(NL80211_CHAN_WIDTH_80),
cd8440da
AP
60};
61
de9e9932 62static const struct
cc7359b5 63ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
de9e9932
AP
64 .limits = mwifiex_ap_sta_limits,
65 .num_different_channels = 2,
66 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
67 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
68 .beacon_int_infra_match = true,
69};
70
5e6e3a92
BZ
71/*
72 * This function maps the nl802.11 channel type into driver channel type.
73 *
74 * The mapping is as follows -
21c3ba34
AK
75 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
76 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
77 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
78 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
79 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
5e6e3a92 80 */
7feb4c48 81u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
5e6e3a92 82{
05910f4a 83 switch (chan_type) {
5e6e3a92
BZ
84 case NL80211_CHAN_NO_HT:
85 case NL80211_CHAN_HT20:
21c3ba34 86 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 87 case NL80211_CHAN_HT40PLUS:
21c3ba34 88 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
5e6e3a92 89 case NL80211_CHAN_HT40MINUS:
21c3ba34 90 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
5e6e3a92 91 default:
21c3ba34 92 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 93 }
5e6e3a92
BZ
94}
95
7ee38bf4
XH
96/* This function maps IEEE HT secondary channel type to NL80211 channel type
97 */
98u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset)
99{
100 switch (second_chan_offset) {
101 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
102 return NL80211_CHAN_HT20;
103 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
104 return NL80211_CHAN_HT40PLUS;
105 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
106 return NL80211_CHAN_HT40MINUS;
107 default:
108 return NL80211_CHAN_HT20;
109 }
110}
111
5e6e3a92
BZ
112/*
113 * This function checks whether WEP is set.
114 */
115static int
116mwifiex_is_alg_wep(u32 cipher)
117{
5e6e3a92 118 switch (cipher) {
2be50b8d
YAP
119 case WLAN_CIPHER_SUITE_WEP40:
120 case WLAN_CIPHER_SUITE_WEP104:
270e58e8 121 return 1;
5e6e3a92 122 default:
5e6e3a92
BZ
123 break;
124 }
270e58e8
YAP
125
126 return 0;
5e6e3a92
BZ
127}
128
5e6e3a92
BZ
129/*
130 * This function retrieves the private structure from kernel wiphy structure.
131 */
67fdf39e 132static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
5e6e3a92
BZ
133{
134 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
135}
136
137/*
138 * CFG802.11 operation handler to delete a network key.
139 */
140static int
141mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
142 u8 key_index, bool pairwise, const u8 *mac_addr)
143{
f540f9f3 144 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
75edd2c6
AP
145 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
146 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 147
53b11231 148 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
acebe8c1 149 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
5e6e3a92
BZ
150 return -EFAULT;
151 }
152
acebe8c1 153 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
5e6e3a92
BZ
154 return 0;
155}
156
e39faa73
SP
157/*
158 * This function forms an skb for management frame.
159 */
160static int
161mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
162{
163 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
164 u16 pkt_len;
165 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
e39faa73
SP
166
167 pkt_len = len + ETH_ALEN;
168
169 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
170 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
171 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
172
173 memcpy(skb_push(skb, sizeof(tx_control)),
174 &tx_control, sizeof(tx_control));
175
176 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
177
178 /* Add packet data and address4 */
59ae1d12
JB
179 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
180 skb_put_data(skb, addr, ETH_ALEN);
181 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
182 len - sizeof(struct ieee80211_hdr_3addr));
e39faa73
SP
183
184 skb->priority = LOW_PRIO_TID;
c64800e7 185 __net_timestamp(skb);
e39faa73
SP
186
187 return 0;
188}
189
190/*
191 * CFG802.11 operation handler to transmit a management frame.
192 */
193static int
194mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
b176e629 195 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
e39faa73 196{
b176e629
AO
197 const u8 *buf = params->buf;
198 size_t len = params->len;
e39faa73
SP
199 struct sk_buff *skb;
200 u16 pkt_len;
201 const struct ieee80211_mgmt *mgmt;
231d83e2 202 struct mwifiex_txinfo *tx_info;
e39faa73
SP
203 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
204
205 if (!buf || !len) {
acebe8c1 206 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
e39faa73
SP
207 return -EFAULT;
208 }
209
210 mgmt = (const struct ieee80211_mgmt *)buf;
211 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
212 ieee80211_is_probe_resp(mgmt->frame_control)) {
213 /* Since we support offload probe resp, we need to skip probe
214 * resp in AP or GO mode */
acebe8c1
ZL
215 mwifiex_dbg(priv->adapter, INFO,
216 "info: skip to send probe resp in AP or GO mode\n");
e39faa73
SP
217 return 0;
218 }
219
220 pkt_len = len + ETH_ALEN;
221 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
222 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
223 pkt_len + sizeof(pkt_len));
224
225 if (!skb) {
acebe8c1
ZL
226 mwifiex_dbg(priv->adapter, ERROR,
227 "allocate skb failed for management frame\n");
e39faa73
SP
228 return -ENOMEM;
229 }
230
231d83e2 231 tx_info = MWIFIEX_SKB_TXCB(skb);
701a9e61 232 memset(tx_info, 0, sizeof(*tx_info));
231d83e2
HY
233 tx_info->bss_num = priv->bss_num;
234 tx_info->bss_type = priv->bss_type;
a1ed4849 235 tx_info->pkt_len = pkt_len;
231d83e2 236
e39faa73 237 mwifiex_form_mgmt_frame(skb, buf, len);
e00adf39 238 *cookie = prandom_u32() | 1;
18ca4382
AK
239
240 if (ieee80211_is_action(mgmt->frame_control))
241 skb = mwifiex_clone_skb_for_tx_status(priv,
242 skb,
243 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
244 else
245 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
246 GFP_ATOMIC);
247
248 mwifiex_queue_tx_pkt(priv, skb);
e39faa73 249
acebe8c1 250 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
e39faa73
SP
251 return 0;
252}
253
3cec6870
SP
254/*
255 * CFG802.11 operation handler to register a mgmt frame.
256 */
257static void
258mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
259 struct wireless_dev *wdev,
260 u16 frame_type, bool reg)
261{
262 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4481b2db 263 u32 mask;
3cec6870
SP
264
265 if (reg)
4481b2db 266 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
3cec6870 267 else
4481b2db
SP
268 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
269
270 if (mask != priv->mgmt_frame_mask) {
271 priv->mgmt_frame_mask = mask;
fa0ecbb9
BZ
272 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
273 HostCmd_ACT_GEN_SET, 0,
274 &priv->mgmt_frame_mask, false);
acebe8c1 275 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
4481b2db 276 }
3cec6870
SP
277}
278
7feb4c48
SP
279/*
280 * CFG802.11 operation handler to remain on channel.
281 */
282static int
283mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
284 struct wireless_dev *wdev,
285 struct ieee80211_channel *chan,
7feb4c48
SP
286 unsigned int duration, u64 *cookie)
287{
288 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
289 int ret;
290
291 if (!chan || !cookie) {
acebe8c1 292 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
7feb4c48
SP
293 return -EINVAL;
294 }
295
296 if (priv->roc_cfg.cookie) {
acebe8c1
ZL
297 mwifiex_dbg(priv->adapter, INFO,
298 "info: ongoing ROC, cookie = 0x%llx\n",
299 priv->roc_cfg.cookie);
7feb4c48
SP
300 return -EBUSY;
301 }
302
303 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
42d97a59 304 duration);
7feb4c48
SP
305
306 if (!ret) {
e00adf39 307 *cookie = prandom_u32() | 1;
7feb4c48
SP
308 priv->roc_cfg.cookie = *cookie;
309 priv->roc_cfg.chan = *chan;
7feb4c48 310
42d97a59 311 cfg80211_ready_on_channel(wdev, *cookie, chan,
7feb4c48
SP
312 duration, GFP_ATOMIC);
313
acebe8c1
ZL
314 mwifiex_dbg(priv->adapter, INFO,
315 "info: ROC, cookie = 0x%llx\n", *cookie);
7feb4c48
SP
316 }
317
318 return ret;
319}
320
321/*
322 * CFG802.11 operation handler to cancel remain on channel.
323 */
324static int
325mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
326 struct wireless_dev *wdev, u64 cookie)
327{
328 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
329 int ret;
330
331 if (cookie != priv->roc_cfg.cookie)
332 return -ENOENT;
333
334 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
42d97a59 335 &priv->roc_cfg.chan, 0);
7feb4c48
SP
336
337 if (!ret) {
338 cfg80211_remain_on_channel_expired(wdev, cookie,
339 &priv->roc_cfg.chan,
7feb4c48
SP
340 GFP_ATOMIC);
341
342 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
343
acebe8c1
ZL
344 mwifiex_dbg(priv->adapter, INFO,
345 "info: cancel ROC, cookie = 0x%llx\n", cookie);
7feb4c48
SP
346 }
347
348 return ret;
349}
350
5e6e3a92
BZ
351/*
352 * CFG802.11 operation handler to set Tx power.
353 */
354static int
355mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
c8442118 356 struct wireless_dev *wdev,
5e6e3a92 357 enum nl80211_tx_power_setting type,
742c29fd 358 int mbm)
5e6e3a92 359{
67fdf39e
AP
360 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
361 struct mwifiex_private *priv;
600f5d90 362 struct mwifiex_power_cfg power_cfg;
742c29fd 363 int dbm = MBM_TO_DBM(mbm);
5e6e3a92 364
600f5d90
AK
365 if (type == NL80211_TX_POWER_FIXED) {
366 power_cfg.is_power_auto = 0;
367 power_cfg.power_level = dbm;
368 } else {
369 power_cfg.is_power_auto = 1;
370 }
371
67fdf39e
AP
372 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
373
636c4598 374 return mwifiex_set_tx_power(priv, &power_cfg);
5e6e3a92
BZ
375}
376
7d54baca
JMC
377/*
378 * CFG802.11 operation handler to get Tx power.
379 */
380static int
381mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
382 struct wireless_dev *wdev,
383 int *dbm)
384{
385 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
386 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
387 MWIFIEX_BSS_ROLE_ANY);
388 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
389 HostCmd_ACT_GEN_GET, 0, NULL, true);
390
391 if (ret < 0)
392 return ret;
393
394 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
395 *dbm = priv->tx_power_level;
396
397 return 0;
398}
399
5e6e3a92
BZ
400/*
401 * CFG802.11 operation handler to set Power Save option.
402 *
403 * The timeout value, if provided, is currently ignored.
404 */
405static int
406mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
407 struct net_device *dev,
408 bool enabled, int timeout)
409{
f540f9f3 410 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
600f5d90 411 u32 ps_mode;
5e6e3a92
BZ
412
413 if (timeout)
acebe8c1
ZL
414 mwifiex_dbg(priv->adapter, INFO,
415 "info: ignore timeout value for IEEE Power Save\n");
5e6e3a92 416
600f5d90 417 ps_mode = enabled;
5e6e3a92 418
636c4598 419 return mwifiex_drv_set_power(priv, &ps_mode);
5e6e3a92
BZ
420}
421
422/*
423 * CFG802.11 operation handler to set the default network key.
424 */
425static int
426mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
427 u8 key_index, bool unicast,
428 bool multicast)
429{
f540f9f3 430 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
5e6e3a92 431
2d3d0a88 432 /* Return if WEP key not configured */
5eb02e44 433 if (!priv->sec_info.wep_enabled)
2d3d0a88
AK
434 return 0;
435
96893538
AP
436 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
437 priv->wep_key_curr_index = key_index;
53b11231
YL
438 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
439 NULL, 0)) {
acebe8c1 440 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
5e6e3a92 441 return -EFAULT;
636c4598 442 }
5e6e3a92
BZ
443
444 return 0;
445}
446
447/*
448 * CFG802.11 operation handler to add a network key.
449 */
450static int
451mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
452 u8 key_index, bool pairwise, const u8 *mac_addr,
453 struct key_params *params)
454{
f540f9f3 455 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
96893538 456 struct mwifiex_wep_key *wep_key;
75edd2c6
AP
457 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
458 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 459
96893538
AP
460 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
461 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
462 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
463 if (params->key && params->key_len) {
464 wep_key = &priv->wep_key[key_index];
465 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
466 memcpy(wep_key->key_material, params->key,
467 params->key_len);
468 wep_key->key_index = key_index;
469 wep_key->key_length = params->key_len;
470 priv->sec_info.wep_enabled = 1;
471 }
472 return 0;
473 }
474
53b11231 475 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
75edd2c6 476 key_index, peer_mac, 0)) {
acebe8c1 477 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
5e6e3a92 478 return -EFAULT;
636c4598 479 }
5e6e3a92
BZ
480
481 return 0;
482}
483
89951db2
GB
484/*
485 * CFG802.11 operation handler to set default mgmt key.
486 */
487static int
488mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
489 struct net_device *netdev,
490 u8 key_index)
491{
492 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
493 struct mwifiex_ds_encrypt_key encrypt_key;
494
495 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
496
497 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
498 encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
499 encrypt_key.key_index = key_index;
500 encrypt_key.is_igtk_def_key = true;
501 eth_broadcast_addr(encrypt_key.mac_addr);
502
503 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
504 HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
505}
506
5e6e3a92
BZ
507/*
508 * This function sends domain information to the firmware.
509 *
510 * The following information are passed to the firmware -
511 * - Country codes
512 * - Sub bands (first channel, number of channels, maximum Tx power)
513 */
65d48e59 514int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
5e6e3a92
BZ
515{
516 u8 no_of_triplet = 0;
517 struct ieee80211_country_ie_triplet *t;
518 u8 no_of_parsed_chan = 0;
519 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
520 u8 i, flag = 0;
57fbcce3 521 enum nl80211_band band;
5e6e3a92
BZ
522 struct ieee80211_supported_band *sband;
523 struct ieee80211_channel *ch;
67fdf39e
AP
524 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
525 struct mwifiex_private *priv;
5e6e3a92 526 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
5e6e3a92
BZ
527
528 /* Set country code */
67fdf39e
AP
529 domain_info->country_code[0] = adapter->country_code[0];
530 domain_info->country_code[1] = adapter->country_code[1];
5e6e3a92
BZ
531 domain_info->country_code[2] = ' ';
532
533 band = mwifiex_band_to_radio_type(adapter->config_bands);
534 if (!wiphy->bands[band]) {
acebe8c1
ZL
535 mwifiex_dbg(adapter, ERROR,
536 "11D: setting domain info in FW\n");
5e6e3a92
BZ
537 return -1;
538 }
539
540 sband = wiphy->bands[band];
541
542 for (i = 0; i < sband->n_channels ; i++) {
543 ch = &sband->channels[i];
544 if (ch->flags & IEEE80211_CHAN_DISABLED)
545 continue;
546
547 if (!flag) {
548 flag = 1;
549 first_chan = (u32) ch->hw_value;
550 next_chan = first_chan;
22db2497 551 max_pwr = ch->max_power;
5e6e3a92
BZ
552 no_of_parsed_chan = 1;
553 continue;
554 }
555
556 if (ch->hw_value == next_chan + 1 &&
22db2497 557 ch->max_power == max_pwr) {
5e6e3a92
BZ
558 next_chan++;
559 no_of_parsed_chan++;
560 } else {
561 t = &domain_info->triplet[no_of_triplet];
562 t->chans.first_channel = first_chan;
563 t->chans.num_channels = no_of_parsed_chan;
564 t->chans.max_power = max_pwr;
565 no_of_triplet++;
566 first_chan = (u32) ch->hw_value;
567 next_chan = first_chan;
22db2497 568 max_pwr = ch->max_power;
5e6e3a92
BZ
569 no_of_parsed_chan = 1;
570 }
571 }
572
573 if (flag) {
574 t = &domain_info->triplet[no_of_triplet];
575 t->chans.first_channel = first_chan;
576 t->chans.num_channels = no_of_parsed_chan;
577 t->chans.max_power = max_pwr;
578 no_of_triplet++;
579 }
580
581 domain_info->no_of_triplet = no_of_triplet;
636c4598 582
67fdf39e
AP
583 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
584
fa0ecbb9
BZ
585 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
586 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
acebe8c1
ZL
587 mwifiex_dbg(adapter, INFO,
588 "11D: setting domain info in FW\n");
636c4598
YAP
589 return -1;
590 }
5e6e3a92 591
636c4598 592 return 0;
5e6e3a92
BZ
593}
594
1aed8964
KA
595static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
596{
597 struct ieee80211_supported_band *sband;
598 struct ieee80211_channel *chan;
599 unsigned int i;
600
601 if (!wiphy->bands[NL80211_BAND_5GHZ])
602 return;
603 sband = wiphy->bands[NL80211_BAND_5GHZ];
604
605 for (i = 0; i < sband->n_channels; i++) {
606 chan = &sband->channels[i];
607 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
608 (chan->flags & IEEE80211_CHAN_RADAR))
609 chan->flags |= IEEE80211_CHAN_NO_IR;
610 }
611}
612
5e6e3a92
BZ
613/*
614 * CFG802.11 regulatory domain callback function.
615 *
616 * This function is called when the regulatory domain is changed due to the
617 * following reasons -
618 * - Set by driver
619 * - Set by system core
620 * - Set by user
621 * - Set bt Country IE
622 */
0c0280bd
LR
623static void mwifiex_reg_notifier(struct wiphy *wiphy,
624 struct regulatory_request *request)
5e6e3a92 625{
67fdf39e 626 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
82efa16a
BZ
627 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
628 MWIFIEX_BSS_ROLE_ANY);
acebe8c1
ZL
629 mwifiex_dbg(adapter, INFO,
630 "info: cfg80211 regulatory domain callback for %c%c\n",
631 request->alpha2[0], request->alpha2[1]);
1aed8964 632 mwifiex_reg_apply_radar_flags(wiphy);
5e6e3a92 633
5e6e3a92
BZ
634 switch (request->initiator) {
635 case NL80211_REGDOM_SET_BY_DRIVER:
636 case NL80211_REGDOM_SET_BY_CORE:
637 case NL80211_REGDOM_SET_BY_USER:
5e6e3a92
BZ
638 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
639 break;
dd4a9ac0 640 default:
acebe8c1
ZL
641 mwifiex_dbg(adapter, ERROR,
642 "unknown regdom initiator: %d\n",
643 request->initiator);
dd4a9ac0
BZ
644 return;
645 }
646
647 /* Don't send world or same regdom info to firmware */
648 if (strncmp(request->alpha2, "00", 2) &&
649 strncmp(request->alpha2, adapter->country_code,
650 sizeof(request->alpha2))) {
651 memcpy(adapter->country_code, request->alpha2,
652 sizeof(request->alpha2));
653 mwifiex_send_domain_info_cmd_fw(wiphy);
b58df446 654 mwifiex_dnld_txpwr_table(priv);
5e6e3a92 655 }
5e6e3a92
BZ
656}
657
5e6e3a92
BZ
658/*
659 * This function sets the fragmentation threshold.
660 *
600f5d90 661 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
5e6e3a92
BZ
662 * and MWIFIEX_FRAG_MAX_VALUE.
663 */
664static int
665mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
666{
aea0701e
YAP
667 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
668 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
9b930eae 669 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
5e6e3a92 670
fa0ecbb9
BZ
671 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
672 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
673 &frag_thr, true);
5e6e3a92
BZ
674}
675
676/*
677 * This function sets the RTS threshold.
600f5d90
AK
678
679 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
680 * and MWIFIEX_RTS_MAX_VALUE.
5e6e3a92
BZ
681 */
682static int
683mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
684{
5e6e3a92
BZ
685 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
686 rts_thr = MWIFIEX_RTS_MAX_VALUE;
687
fa0ecbb9
BZ
688 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
689 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
690 &rts_thr, true);
5e6e3a92
BZ
691}
692
693/*
694 * CFG802.11 operation handler to set wiphy parameters.
695 *
696 * This function can be used to set the RTS threshold and the
697 * Fragmentation threshold of the driver.
698 */
699static int
700mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
701{
67fdf39e 702 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
9b930eae
AP
703 struct mwifiex_private *priv;
704 struct mwifiex_uap_bss_param *bss_cfg;
09f63ae6
AP
705 int ret;
706
707 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
9b930eae 708
09f63ae6
AP
709 switch (priv->bss_role) {
710 case MWIFIEX_BSS_ROLE_UAP:
711 if (priv->bss_started) {
acebe8c1
ZL
712 mwifiex_dbg(adapter, ERROR,
713 "cannot change wiphy params when bss started");
09f63ae6
AP
714 return -EINVAL;
715 }
5e6e3a92 716
09f63ae6
AP
717 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
718 if (!bss_cfg)
719 return -ENOMEM;
9b930eae 720
09f63ae6 721 mwifiex_set_sys_config_invalid_data(bss_cfg);
5e6e3a92 722
09f63ae6
AP
723 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
724 bss_cfg->rts_threshold = wiphy->rts_threshold;
725 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
726 bss_cfg->frag_threshold = wiphy->frag_threshold;
727 if (changed & WIPHY_PARAM_RETRY_LONG)
728 bss_cfg->retry_limit = wiphy->retry_long;
9b930eae 729
09f63ae6
AP
730 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
731 HostCmd_ACT_GEN_SET,
732 UAP_BSS_PARAMS_I, bss_cfg,
733 false);
734
735 kfree(bss_cfg);
736 if (ret) {
acebe8c1
ZL
737 mwifiex_dbg(adapter, ERROR,
738 "Failed to set wiphy phy params\n");
09f63ae6
AP
739 return ret;
740 }
741 break;
9b930eae 742
32962d5b 743 case MWIFIEX_BSS_ROLE_STA:
09f63ae6 744 if (priv->media_connected) {
acebe8c1
ZL
745 mwifiex_dbg(adapter, ERROR,
746 "cannot change wiphy params when connected");
09f63ae6
AP
747 return -EINVAL;
748 }
749 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
750 ret = mwifiex_set_rts(priv,
751 wiphy->rts_threshold);
752 if (ret)
753 return ret;
9b930eae 754 }
09f63ae6
AP
755 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
756 ret = mwifiex_set_frag(priv,
757 wiphy->frag_threshold);
758 if (ret)
759 return ret;
760 }
761 break;
9b930eae
AP
762 }
763
764 return 0;
5e6e3a92
BZ
765}
766
e1a2b7a3
SP
767static int
768mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
769{
770 u16 mode = P2P_MODE_DISABLE;
771
fa0ecbb9
BZ
772 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
773 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
774 return -1;
775
776 return 0;
777}
778
779/*
780 * This function initializes the functionalities for P2P client.
781 * The P2P client initialization sequence is:
782 * disable -> device -> client
783 */
784static int
785mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
786{
787 u16 mode;
788
789 if (mwifiex_cfg80211_deinit_p2p(priv))
790 return -1;
791
792 mode = P2P_MODE_DEVICE;
fa0ecbb9
BZ
793 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
794 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
795 return -1;
796
797 mode = P2P_MODE_CLIENT;
fa0ecbb9
BZ
798 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
799 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
800 return -1;
801
802 return 0;
803}
804
9197ab9e
SP
805/*
806 * This function initializes the functionalities for P2P GO.
807 * The P2P GO initialization sequence is:
808 * disable -> device -> GO
809 */
810static int
811mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
812{
813 u16 mode;
814
815 if (mwifiex_cfg80211_deinit_p2p(priv))
816 return -1;
817
818 mode = P2P_MODE_DEVICE;
fa0ecbb9
BZ
819 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
820 HostCmd_ACT_GEN_SET, 0, &mode, true))
9197ab9e
SP
821 return -1;
822
823 mode = P2P_MODE_GO;
fa0ecbb9
BZ
824 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
825 HostCmd_ACT_GEN_SET, 0, &mode, true))
9197ab9e
SP
826 return -1;
827
047eaaf6
AP
828 return 0;
829}
830
831static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
832{
a9adbcb3
AP
833 struct mwifiex_adapter *adapter = priv->adapter;
834 unsigned long flags;
835
047eaaf6
AP
836 priv->mgmt_frame_mask = 0;
837 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
838 HostCmd_ACT_GEN_SET, 0,
839 &priv->mgmt_frame_mask, false)) {
acebe8c1
ZL
840 mwifiex_dbg(adapter, ERROR,
841 "could not unregister mgmt frame rx\n");
047eaaf6
AP
842 return -1;
843 }
844
845 mwifiex_deauthenticate(priv, NULL);
a9adbcb3
AP
846
847 spin_lock_irqsave(&adapter->main_proc_lock, flags);
848 adapter->main_locked = true;
849 if (adapter->mwifiex_processing) {
850 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
851 flush_workqueue(adapter->workqueue);
852 } else {
853 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
854 }
855
856 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
857 adapter->rx_locked = true;
858 if (adapter->rx_processing) {
859 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
860 flush_workqueue(adapter->rx_workqueue);
861 } else {
862 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
863 }
864
047eaaf6
AP
865 mwifiex_free_priv(priv);
866 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
867 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
868 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
869
870 return 0;
871}
872
873static int
874mwifiex_init_new_priv_params(struct mwifiex_private *priv,
875 struct net_device *dev,
876 enum nl80211_iftype type)
877{
a9adbcb3
AP
878 struct mwifiex_adapter *adapter = priv->adapter;
879 unsigned long flags;
880
047eaaf6
AP
881 mwifiex_init_priv(priv);
882
883 priv->bss_mode = type;
884 priv->wdev.iftype = type;
885
886 mwifiex_init_priv_params(priv, priv->netdev);
887 priv->bss_started = 0;
888
889 switch (type) {
890 case NL80211_IFTYPE_STATION:
891 case NL80211_IFTYPE_ADHOC:
5b13d3e1
SL
892 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
893 MWIFIEX_BSS_TYPE_STA);
047eaaf6 894 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
047eaaf6
AP
895 break;
896 case NL80211_IFTYPE_P2P_CLIENT:
5b13d3e1
SL
897 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
898 MWIFIEX_BSS_TYPE_P2P);
047eaaf6 899 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
047eaaf6 900 break;
ae86c587 901 case NL80211_IFTYPE_P2P_GO:
5b13d3e1
SL
902 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
903 MWIFIEX_BSS_TYPE_P2P);
ae86c587 904 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
ae86c587 905 break;
047eaaf6 906 case NL80211_IFTYPE_AP:
5b13d3e1
SL
907 priv->bss_num = mwifiex_get_unused_bss_num(adapter,
908 MWIFIEX_BSS_TYPE_UAP);
047eaaf6
AP
909 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
910 break;
911 default:
acebe8c1
ZL
912 mwifiex_dbg(adapter, ERROR,
913 "%s: changing to %d not supported\n",
914 dev->name, type);
047eaaf6
AP
915 return -EOPNOTSUPP;
916 }
9197ab9e 917
a9adbcb3
AP
918 spin_lock_irqsave(&adapter->main_proc_lock, flags);
919 adapter->main_locked = false;
920 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
921
922 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
923 adapter->rx_locked = false;
924 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
925
9197ab9e
SP
926 return 0;
927}
928
047eaaf6
AP
929static int
930mwifiex_change_vif_to_p2p(struct net_device *dev,
931 enum nl80211_iftype curr_iftype,
818a986e 932 enum nl80211_iftype type,
047eaaf6
AP
933 struct vif_params *params)
934{
935 struct mwifiex_private *priv;
936 struct mwifiex_adapter *adapter;
937
938 priv = mwifiex_netdev_get_priv(dev);
939
940 if (!priv)
941 return -1;
942
943 adapter = priv->adapter;
944
945 if (adapter->curr_iface_comb.p2p_intf ==
946 adapter->iface_limit.p2p_intf) {
acebe8c1
ZL
947 mwifiex_dbg(adapter, ERROR,
948 "cannot create multiple P2P ifaces\n");
047eaaf6
AP
949 return -1;
950 }
951
acebe8c1
ZL
952 mwifiex_dbg(adapter, INFO,
953 "%s: changing role to p2p\n", dev->name);
047eaaf6
AP
954
955 if (mwifiex_deinit_priv_params(priv))
956 return -1;
957 if (mwifiex_init_new_priv_params(priv, dev, type))
958 return -1;
959
960 switch (type) {
961 case NL80211_IFTYPE_P2P_CLIENT:
962 if (mwifiex_cfg80211_init_p2p_client(priv))
963 return -EFAULT;
964 break;
965 case NL80211_IFTYPE_P2P_GO:
966 if (mwifiex_cfg80211_init_p2p_go(priv))
967 return -EFAULT;
968 break;
969 default:
acebe8c1
ZL
970 mwifiex_dbg(adapter, ERROR,
971 "%s: changing to %d not supported\n",
972 dev->name, type);
047eaaf6
AP
973 return -EOPNOTSUPP;
974 }
975
976 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
977 HostCmd_ACT_GEN_SET, 0, NULL, true))
978 return -1;
979
980 if (mwifiex_sta_init_cmd(priv, false, false))
981 return -1;
982
983 switch (curr_iftype) {
984 case NL80211_IFTYPE_STATION:
985 case NL80211_IFTYPE_ADHOC:
986 adapter->curr_iface_comb.sta_intf--;
987 break;
988 case NL80211_IFTYPE_AP:
989 adapter->curr_iface_comb.uap_intf--;
990 break;
991 default:
992 break;
993 }
994
995 adapter->curr_iface_comb.p2p_intf++;
996 dev->ieee80211_ptr->iftype = type;
997
998 return 0;
999}
1000
1001static int
1002mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
1003 enum nl80211_iftype curr_iftype,
818a986e 1004 enum nl80211_iftype type,
047eaaf6
AP
1005 struct vif_params *params)
1006{
1007 struct mwifiex_private *priv;
1008 struct mwifiex_adapter *adapter;
1009
1010 priv = mwifiex_netdev_get_priv(dev);
1011
1012 if (!priv)
1013 return -1;
1014
1015 adapter = priv->adapter;
1016
1017 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
1018 curr_iftype != NL80211_IFTYPE_P2P_GO) &&
1019 (adapter->curr_iface_comb.sta_intf ==
1020 adapter->iface_limit.sta_intf)) {
acebe8c1
ZL
1021 mwifiex_dbg(adapter, ERROR,
1022 "cannot create multiple station/adhoc ifaces\n");
047eaaf6
AP
1023 return -1;
1024 }
1025
1026 if (type == NL80211_IFTYPE_STATION)
acebe8c1
ZL
1027 mwifiex_dbg(adapter, INFO,
1028 "%s: changing role to station\n", dev->name);
047eaaf6 1029 else
acebe8c1
ZL
1030 mwifiex_dbg(adapter, INFO,
1031 "%s: changing role to adhoc\n", dev->name);
047eaaf6
AP
1032
1033 if (mwifiex_deinit_priv_params(priv))
1034 return -1;
1035 if (mwifiex_init_new_priv_params(priv, dev, type))
1036 return -1;
1037 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1038 HostCmd_ACT_GEN_SET, 0, NULL, true))
1039 return -1;
1040 if (mwifiex_sta_init_cmd(priv, false, false))
1041 return -1;
1042
1043 switch (curr_iftype) {
1044 case NL80211_IFTYPE_P2P_CLIENT:
1045 case NL80211_IFTYPE_P2P_GO:
1046 adapter->curr_iface_comb.p2p_intf--;
1047 break;
1048 case NL80211_IFTYPE_AP:
1049 adapter->curr_iface_comb.uap_intf--;
1050 break;
1051 default:
1052 break;
1053 }
1054
1055 adapter->curr_iface_comb.sta_intf++;
1056 dev->ieee80211_ptr->iftype = type;
1057 return 0;
1058}
1059
1060static int
1061mwifiex_change_vif_to_ap(struct net_device *dev,
1062 enum nl80211_iftype curr_iftype,
818a986e 1063 enum nl80211_iftype type,
047eaaf6
AP
1064 struct vif_params *params)
1065{
1066 struct mwifiex_private *priv;
1067 struct mwifiex_adapter *adapter;
1068
1069 priv = mwifiex_netdev_get_priv(dev);
1070
1071 if (!priv)
1072 return -1;
1073
1074 adapter = priv->adapter;
1075
1076 if (adapter->curr_iface_comb.uap_intf ==
1077 adapter->iface_limit.uap_intf) {
acebe8c1
ZL
1078 mwifiex_dbg(adapter, ERROR,
1079 "cannot create multiple AP ifaces\n");
047eaaf6
AP
1080 return -1;
1081 }
1082
acebe8c1
ZL
1083 mwifiex_dbg(adapter, INFO,
1084 "%s: changing role to AP\n", dev->name);
047eaaf6
AP
1085
1086 if (mwifiex_deinit_priv_params(priv))
1087 return -1;
1088 if (mwifiex_init_new_priv_params(priv, dev, type))
1089 return -1;
1090 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1091 HostCmd_ACT_GEN_SET, 0, NULL, true))
1092 return -1;
1093 if (mwifiex_sta_init_cmd(priv, false, false))
1094 return -1;
1095
1096 switch (curr_iftype) {
1097 case NL80211_IFTYPE_P2P_CLIENT:
1098 case NL80211_IFTYPE_P2P_GO:
1099 adapter->curr_iface_comb.p2p_intf--;
1100 break;
1101 case NL80211_IFTYPE_STATION:
1102 case NL80211_IFTYPE_ADHOC:
1103 adapter->curr_iface_comb.sta_intf--;
1104 break;
1105 default:
1106 break;
1107 }
1108
1109 adapter->curr_iface_comb.uap_intf++;
1110 dev->ieee80211_ptr->iftype = type;
1111 return 0;
1112}
5e6e3a92
BZ
1113/*
1114 * CFG802.11 operation handler to change interface type.
5e6e3a92
BZ
1115 */
1116static int
1117mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1118 struct net_device *dev,
818a986e 1119 enum nl80211_iftype type,
5e6e3a92
BZ
1120 struct vif_params *params)
1121{
5e6e3a92 1122 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
047eaaf6 1123 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
5e6e3a92 1124
047eaaf6 1125 switch (curr_iftype) {
5e6e3a92 1126 case NL80211_IFTYPE_ADHOC:
4f02341a
AP
1127 switch (type) {
1128 case NL80211_IFTYPE_STATION:
047eaaf6
AP
1129 priv->bss_mode = type;
1130 priv->sec_info.authentication_mode =
1131 NL80211_AUTHTYPE_OPEN_SYSTEM;
1132 dev->ieee80211_ptr->iftype = type;
1133 mwifiex_deauthenticate(priv, NULL);
1134 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1135 HostCmd_ACT_GEN_SET, 0, NULL,
1136 true);
1137 case NL80211_IFTYPE_P2P_CLIENT:
1138 case NL80211_IFTYPE_P2P_GO:
1139 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
818a986e 1140 type, params);
047eaaf6
AP
1141 case NL80211_IFTYPE_AP:
1142 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
818a986e 1143 params);
4f02341a 1144 case NL80211_IFTYPE_UNSPECIFIED:
acebe8c1
ZL
1145 mwifiex_dbg(priv->adapter, INFO,
1146 "%s: kept type as IBSS\n", dev->name);
4f02341a
AP
1147 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
1148 return 0;
4f02341a 1149 default:
acebe8c1
ZL
1150 mwifiex_dbg(priv->adapter, ERROR,
1151 "%s: changing to %d not supported\n",
1152 dev->name, type);
4f02341a
AP
1153 return -EOPNOTSUPP;
1154 }
5e6e3a92
BZ
1155 break;
1156 case NL80211_IFTYPE_STATION:
4f02341a
AP
1157 switch (type) {
1158 case NL80211_IFTYPE_ADHOC:
047eaaf6
AP
1159 priv->bss_mode = type;
1160 priv->sec_info.authentication_mode =
1161 NL80211_AUTHTYPE_OPEN_SYSTEM;
e1a2b7a3 1162 dev->ieee80211_ptr->iftype = type;
047eaaf6
AP
1163 mwifiex_deauthenticate(priv, NULL);
1164 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1165 HostCmd_ACT_GEN_SET, 0, NULL,
1166 true);
1167 case NL80211_IFTYPE_P2P_CLIENT:
9197ab9e 1168 case NL80211_IFTYPE_P2P_GO:
047eaaf6 1169 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
818a986e 1170 type, params);
047eaaf6
AP
1171 case NL80211_IFTYPE_AP:
1172 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
818a986e 1173 params);
4f02341a 1174 case NL80211_IFTYPE_UNSPECIFIED:
acebe8c1
ZL
1175 mwifiex_dbg(priv->adapter, INFO,
1176 "%s: kept type as STA\n", dev->name);
4f02341a
AP
1177 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
1178 return 0;
4f02341a 1179 default:
acebe8c1
ZL
1180 mwifiex_dbg(priv->adapter, ERROR,
1181 "%s: changing to %d not supported\n",
1182 dev->name, type);
4f02341a
AP
1183 return -EOPNOTSUPP;
1184 }
1185 break;
1186 case NL80211_IFTYPE_AP:
1187 switch (type) {
047eaaf6
AP
1188 case NL80211_IFTYPE_ADHOC:
1189 case NL80211_IFTYPE_STATION:
1190 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
818a986e 1191 type, params);
047eaaf6
AP
1192 break;
1193 case NL80211_IFTYPE_P2P_CLIENT:
1194 case NL80211_IFTYPE_P2P_GO:
1195 return mwifiex_change_vif_to_p2p(dev, curr_iftype,
818a986e 1196 type, params);
4f02341a 1197 case NL80211_IFTYPE_UNSPECIFIED:
acebe8c1
ZL
1198 mwifiex_dbg(priv->adapter, INFO,
1199 "%s: kept type as AP\n", dev->name);
4f02341a
AP
1200 case NL80211_IFTYPE_AP: /* This shouldn't happen */
1201 return 0;
4f02341a 1202 default:
acebe8c1
ZL
1203 mwifiex_dbg(priv->adapter, ERROR,
1204 "%s: changing to %d not supported\n",
1205 dev->name, type);
4f02341a
AP
1206 return -EOPNOTSUPP;
1207 }
5e6e3a92 1208 break;
e1a2b7a3 1209 case NL80211_IFTYPE_P2P_CLIENT:
9197ab9e 1210 case NL80211_IFTYPE_P2P_GO:
e1a2b7a3
SP
1211 switch (type) {
1212 case NL80211_IFTYPE_STATION:
e79801ff 1213 if (mwifiex_cfg80211_deinit_p2p(priv))
e1a2b7a3 1214 return -EFAULT;
e79801ff
AN
1215 priv->adapter->curr_iface_comb.p2p_intf--;
1216 priv->adapter->curr_iface_comb.sta_intf++;
e1a2b7a3 1217 dev->ieee80211_ptr->iftype = type;
3d8bd85c
K
1218 if (mwifiex_deinit_priv_params(priv))
1219 return -1;
1220 if (mwifiex_init_new_priv_params(priv, dev, type))
1221 return -1;
1222 if (mwifiex_sta_init_cmd(priv, false, false))
1223 return -1;
047eaaf6
AP
1224 break;
1225 case NL80211_IFTYPE_ADHOC:
1226 if (mwifiex_cfg80211_deinit_p2p(priv))
1227 return -EFAULT;
1228 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
818a986e 1229 type, params);
047eaaf6
AP
1230 break;
1231 case NL80211_IFTYPE_AP:
1232 if (mwifiex_cfg80211_deinit_p2p(priv))
1233 return -EFAULT;
1234 return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
818a986e 1235 params);
047eaaf6 1236 case NL80211_IFTYPE_UNSPECIFIED:
acebe8c1
ZL
1237 mwifiex_dbg(priv->adapter, INFO,
1238 "%s: kept type as P2P\n", dev->name);
047eaaf6
AP
1239 case NL80211_IFTYPE_P2P_CLIENT:
1240 case NL80211_IFTYPE_P2P_GO:
e1a2b7a3
SP
1241 return 0;
1242 default:
acebe8c1
ZL
1243 mwifiex_dbg(priv->adapter, ERROR,
1244 "%s: changing to %d not supported\n",
1245 dev->name, type);
e1a2b7a3
SP
1246 return -EOPNOTSUPP;
1247 }
1248 break;
5e6e3a92 1249 default:
acebe8c1
ZL
1250 mwifiex_dbg(priv->adapter, ERROR,
1251 "%s: unknown iftype: %d\n",
1252 dev->name, dev->ieee80211_ptr->iftype);
4f02341a 1253 return -EOPNOTSUPP;
5e6e3a92 1254 }
5e6e3a92 1255
eecd8250 1256
047eaaf6 1257 return 0;
5e6e3a92
BZ
1258}
1259
a5f39056
YAP
1260static void
1261mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
1262 struct rate_info *rate)
1263{
1264 struct mwifiex_adapter *adapter = priv->adapter;
1265
1266 if (adapter->is_hw_11ac_capable) {
1267 /* bit[1-0]: 00=LG 01=HT 10=VHT */
1268 if (tx_htinfo & BIT(0)) {
1269 /* HT */
1270 rate->mcs = priv->tx_rate;
1271 rate->flags |= RATE_INFO_FLAGS_MCS;
1272 }
1273 if (tx_htinfo & BIT(1)) {
1274 /* VHT */
1275 rate->mcs = priv->tx_rate & 0x0F;
1276 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
1277 }
1278
1279 if (tx_htinfo & (BIT(1) | BIT(0))) {
1280 /* HT or VHT */
1281 switch (tx_htinfo & (BIT(3) | BIT(2))) {
1282 case 0:
b51f3bee 1283 rate->bw = RATE_INFO_BW_20;
a5f39056
YAP
1284 break;
1285 case (BIT(2)):
b51f3bee 1286 rate->bw = RATE_INFO_BW_40;
a5f39056
YAP
1287 break;
1288 case (BIT(3)):
b51f3bee 1289 rate->bw = RATE_INFO_BW_80;
a5f39056
YAP
1290 break;
1291 case (BIT(3) | BIT(2)):
b51f3bee 1292 rate->bw = RATE_INFO_BW_160;
a5f39056
YAP
1293 break;
1294 }
1295
1296 if (tx_htinfo & BIT(4))
1297 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1298
1299 if ((priv->tx_rate >> 4) == 1)
1300 rate->nss = 2;
1301 else
1302 rate->nss = 1;
1303 }
1304 } else {
1305 /*
1306 * Bit 0 in tx_htinfo indicates that current Tx rate
1307 * is 11n rate. Valid MCS index values for us are 0 to 15.
1308 */
1309 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
1310 rate->mcs = priv->tx_rate;
1311 rate->flags |= RATE_INFO_FLAGS_MCS;
b51f3bee 1312 rate->bw = RATE_INFO_BW_20;
a5f39056 1313 if (tx_htinfo & BIT(1))
b51f3bee 1314 rate->bw = RATE_INFO_BW_40;
a5f39056
YAP
1315 if (tx_htinfo & BIT(2))
1316 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
1317 }
1318 }
1319}
1320
5e6e3a92
BZ
1321/*
1322 * This function dumps the station information on a buffer.
1323 *
1324 * The following information are shown -
1325 * - Total bytes transmitted
1326 * - Total bytes received
1327 * - Total packets transmitted
1328 * - Total packets received
1329 * - Signal quality level
1330 * - Transmission rate
1331 */
1332static int
1333mwifiex_dump_station_info(struct mwifiex_private *priv,
8baca1a3 1334 struct mwifiex_sta_node *node,
5e6e3a92
BZ
1335 struct station_info *sinfo)
1336{
006606c0 1337 u32 rate;
5e6e3a92 1338
319090bf
JB
1339 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | BIT(NL80211_STA_INFO_TX_BYTES) |
1340 BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
1341 BIT(NL80211_STA_INFO_TX_BITRATE) |
1342 BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_SIGNAL_AVG);
5e6e3a92 1343
8baca1a3
XH
1344 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1345 if (!node)
1346 return -ENOENT;
1347
1348 sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
1349 BIT(NL80211_STA_INFO_TX_FAILED);
1350 sinfo->inactive_time =
1351 jiffies_to_msecs(jiffies - node->stats.last_rx);
1352
1353 sinfo->signal = node->stats.rssi;
1354 sinfo->signal_avg = node->stats.rssi;
1355 sinfo->rx_bytes = node->stats.rx_bytes;
1356 sinfo->tx_bytes = node->stats.tx_bytes;
1357 sinfo->rx_packets = node->stats.rx_packets;
1358 sinfo->tx_packets = node->stats.tx_packets;
1359 sinfo->tx_failed = node->stats.tx_failed;
1360
1361 mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
1362 &sinfo->txrate);
1363 sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
1364
1365 return 0;
1366 }
1367
5e6e3a92 1368 /* Get signal information from the firmware */
fa0ecbb9
BZ
1369 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
1370 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
acebe8c1
ZL
1371 mwifiex_dbg(priv->adapter, ERROR,
1372 "failed to get signal information\n");
958a4a86 1373 return -EFAULT;
5e6e3a92
BZ
1374 }
1375
1376 if (mwifiex_drv_get_data_rate(priv, &rate)) {
acebe8c1
ZL
1377 mwifiex_dbg(priv->adapter, ERROR,
1378 "getting data rate error\n");
958a4a86 1379 return -EFAULT;
5e6e3a92
BZ
1380 }
1381
caf60a6c 1382 /* Get DTIM period information from firmware */
fa0ecbb9
BZ
1383 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
1384 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
1385 &priv->dtim_period, true);
caf60a6c 1386
a5f39056 1387 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
4ec6f9c0 1388
7013d3e2 1389 sinfo->signal_avg = priv->bcn_rssi_avg;
5e6e3a92
BZ
1390 sinfo->rx_bytes = priv->stats.rx_bytes;
1391 sinfo->tx_bytes = priv->stats.tx_bytes;
1392 sinfo->rx_packets = priv->stats.rx_packets;
1393 sinfo->tx_packets = priv->stats.tx_packets;
958a4a86 1394 sinfo->signal = priv->bcn_rssi_avg;
4ec6f9c0 1395 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
006606c0 1396 sinfo->txrate.legacy = rate * 5;
5e6e3a92 1397
c4f3b972 1398 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
319090bf 1399 sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
c4f3b972
AK
1400 sinfo->bss_param.flags = 0;
1401 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1402 WLAN_CAPABILITY_SHORT_PREAMBLE)
1403 sinfo->bss_param.flags |=
1404 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
1405 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
1406 WLAN_CAPABILITY_SHORT_SLOT_TIME)
1407 sinfo->bss_param.flags |=
1408 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
caf60a6c 1409 sinfo->bss_param.dtim_period = priv->dtim_period;
c4f3b972
AK
1410 sinfo->bss_param.beacon_interval =
1411 priv->curr_bss_params.bss_descriptor.beacon_period;
1412 }
1413
958a4a86 1414 return 0;
5e6e3a92
BZ
1415}
1416
1417/*
1418 * CFG802.11 operation handler to get station information.
1419 *
1420 * This function only works in connected mode, and dumps the
1421 * requested station information, if available.
1422 */
1423static int
1424mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 1425 const u8 *mac, struct station_info *sinfo)
5e6e3a92
BZ
1426{
1427 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1428
5e6e3a92
BZ
1429 if (!priv->media_connected)
1430 return -ENOENT;
1431 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
1432 return -ENOENT;
1433
8baca1a3 1434 return mwifiex_dump_station_info(priv, NULL, sinfo);
5e6e3a92
BZ
1435}
1436
f85aae6b
AK
1437/*
1438 * CFG802.11 operation handler to dump station information.
1439 */
1440static int
1441mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
1442 int idx, u8 *mac, struct station_info *sinfo)
1443{
1444 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
8baca1a3
XH
1445 static struct mwifiex_sta_node *node;
1446
1447 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1448 priv->media_connected && idx == 0) {
1449 ether_addr_copy(mac, priv->cfg_bssid);
1450 return mwifiex_dump_station_info(priv, NULL, sinfo);
1451 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1452 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
1453 HostCmd_ACT_GEN_GET, 0, NULL, true);
1454
1455 if (node && (&node->list == &priv->sta_list)) {
1456 node = NULL;
1457 return -ENOENT;
1458 }
f85aae6b 1459
8baca1a3
XH
1460 node = list_prepare_entry(node, &priv->sta_list, list);
1461 list_for_each_entry_continue(node, &priv->sta_list, list) {
1462 ether_addr_copy(mac, node->mac_addr);
1463 return mwifiex_dump_station_info(priv, node, sinfo);
1464 }
1465 }
f85aae6b 1466
8baca1a3 1467 return -ENOENT;
f85aae6b
AK
1468}
1469
6bc6c49f
XH
1470static int
1471mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1472 int idx, struct survey_info *survey)
1473{
1474 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1475 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
57fbcce3 1476 enum nl80211_band band;
6bc6c49f 1477
acebe8c1 1478 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
6bc6c49f
XH
1479
1480 memset(survey, 0, sizeof(struct survey_info));
1481
1482 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
1483 priv->media_connected && idx == 0) {
1484 u8 curr_bss_band = priv->curr_bss_params.band;
1485 u32 chan = priv->curr_bss_params.bss_descriptor.channel;
1486
1487 band = mwifiex_band_to_radio_type(curr_bss_band);
1488 survey->channel = ieee80211_get_channel(wiphy,
1489 ieee80211_channel_to_frequency(chan, band));
1490
1491 if (priv->bcn_nf_last) {
1492 survey->filled = SURVEY_INFO_NOISE_DBM;
1493 survey->noise = priv->bcn_nf_last;
1494 }
1495 return 0;
1496 }
1497
1498 if (idx >= priv->adapter->num_in_chan_stats)
1499 return -ENOENT;
1500
1501 if (!pchan_stats[idx].cca_scan_dur)
1502 return 0;
1503
1504 band = pchan_stats[idx].bandcfg;
1505 survey->channel = ieee80211_get_channel(wiphy,
1506 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
1507 survey->filled = SURVEY_INFO_NOISE_DBM |
4ed20beb
JB
1508 SURVEY_INFO_TIME |
1509 SURVEY_INFO_TIME_BUSY;
6bc6c49f 1510 survey->noise = pchan_stats[idx].noise;
4ed20beb
JB
1511 survey->time = pchan_stats[idx].cca_scan_dur;
1512 survey->time_busy = pchan_stats[idx].cca_busy_dur;
6bc6c49f
XH
1513
1514 return 0;
1515}
1516
5e6e3a92 1517/* Supported rates to be advertised to the cfg80211 */
5e6e3a92
BZ
1518static struct ieee80211_rate mwifiex_rates[] = {
1519 {.bitrate = 10, .hw_value = 2, },
1520 {.bitrate = 20, .hw_value = 4, },
1521 {.bitrate = 55, .hw_value = 11, },
1522 {.bitrate = 110, .hw_value = 22, },
5e6e3a92
BZ
1523 {.bitrate = 60, .hw_value = 12, },
1524 {.bitrate = 90, .hw_value = 18, },
1525 {.bitrate = 120, .hw_value = 24, },
1526 {.bitrate = 180, .hw_value = 36, },
1527 {.bitrate = 240, .hw_value = 48, },
1528 {.bitrate = 360, .hw_value = 72, },
1529 {.bitrate = 480, .hw_value = 96, },
1530 {.bitrate = 540, .hw_value = 108, },
5e6e3a92
BZ
1531};
1532
1533/* Channel definitions to be advertised to cfg80211 */
5e6e3a92
BZ
1534static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1535 {.center_freq = 2412, .hw_value = 1, },
1536 {.center_freq = 2417, .hw_value = 2, },
1537 {.center_freq = 2422, .hw_value = 3, },
1538 {.center_freq = 2427, .hw_value = 4, },
1539 {.center_freq = 2432, .hw_value = 5, },
1540 {.center_freq = 2437, .hw_value = 6, },
1541 {.center_freq = 2442, .hw_value = 7, },
1542 {.center_freq = 2447, .hw_value = 8, },
1543 {.center_freq = 2452, .hw_value = 9, },
1544 {.center_freq = 2457, .hw_value = 10, },
1545 {.center_freq = 2462, .hw_value = 11, },
1546 {.center_freq = 2467, .hw_value = 12, },
1547 {.center_freq = 2472, .hw_value = 13, },
1548 {.center_freq = 2484, .hw_value = 14, },
1549};
1550
1551static struct ieee80211_supported_band mwifiex_band_2ghz = {
1552 .channels = mwifiex_channels_2ghz,
1553 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1554 .bitrates = mwifiex_rates,
8763848e 1555 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
5e6e3a92
BZ
1556};
1557
1558static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1559 {.center_freq = 5040, .hw_value = 8, },
1560 {.center_freq = 5060, .hw_value = 12, },
1561 {.center_freq = 5080, .hw_value = 16, },
1562 {.center_freq = 5170, .hw_value = 34, },
1563 {.center_freq = 5190, .hw_value = 38, },
1564 {.center_freq = 5210, .hw_value = 42, },
1565 {.center_freq = 5230, .hw_value = 46, },
1566 {.center_freq = 5180, .hw_value = 36, },
1567 {.center_freq = 5200, .hw_value = 40, },
1568 {.center_freq = 5220, .hw_value = 44, },
1569 {.center_freq = 5240, .hw_value = 48, },
1570 {.center_freq = 5260, .hw_value = 52, },
1571 {.center_freq = 5280, .hw_value = 56, },
1572 {.center_freq = 5300, .hw_value = 60, },
1573 {.center_freq = 5320, .hw_value = 64, },
1574 {.center_freq = 5500, .hw_value = 100, },
1575 {.center_freq = 5520, .hw_value = 104, },
1576 {.center_freq = 5540, .hw_value = 108, },
1577 {.center_freq = 5560, .hw_value = 112, },
1578 {.center_freq = 5580, .hw_value = 116, },
1579 {.center_freq = 5600, .hw_value = 120, },
1580 {.center_freq = 5620, .hw_value = 124, },
1581 {.center_freq = 5640, .hw_value = 128, },
1582 {.center_freq = 5660, .hw_value = 132, },
1583 {.center_freq = 5680, .hw_value = 136, },
1584 {.center_freq = 5700, .hw_value = 140, },
1585 {.center_freq = 5745, .hw_value = 149, },
1586 {.center_freq = 5765, .hw_value = 153, },
1587 {.center_freq = 5785, .hw_value = 157, },
1588 {.center_freq = 5805, .hw_value = 161, },
1589 {.center_freq = 5825, .hw_value = 165, },
1590};
1591
1592static struct ieee80211_supported_band mwifiex_band_5ghz = {
1593 .channels = mwifiex_channels_5ghz,
1594 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
eb416ad3
AP
1595 .bitrates = mwifiex_rates + 4,
1596 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
5e6e3a92
BZ
1597};
1598
1599
1600/* Supported crypto cipher suits to be advertised to cfg80211 */
5e6e3a92
BZ
1601static const u32 mwifiex_cipher_suites[] = {
1602 WLAN_CIPHER_SUITE_WEP40,
1603 WLAN_CIPHER_SUITE_WEP104,
1604 WLAN_CIPHER_SUITE_TKIP,
1605 WLAN_CIPHER_SUITE_CCMP,
5eab6777 1606 WLAN_CIPHER_SUITE_SMS4,
53b11231 1607 WLAN_CIPHER_SUITE_AES_CMAC,
5e6e3a92
BZ
1608};
1609
83719be8
SP
1610/* Supported mgmt frame types to be advertised to cfg80211 */
1611static const struct ieee80211_txrx_stypes
1612mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1613 [NL80211_IFTYPE_STATION] = {
1614 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1615 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1616 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1617 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1618 },
1619 [NL80211_IFTYPE_AP] = {
1620 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1621 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1622 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1623 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1624 },
1625 [NL80211_IFTYPE_P2P_CLIENT] = {
1626 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1627 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1628 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1629 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1630 },
1631 [NL80211_IFTYPE_P2P_GO] = {
1632 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1633 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1634 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1635 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1636 },
1637};
1638
5d82c53a
YAP
1639/*
1640 * CFG802.11 operation handler for setting bit rates.
1641 *
433c3990
AK
1642 * Function configures data rates to firmware using bitrate mask
1643 * provided by cfg80211.
5d82c53a
YAP
1644 */
1645static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1646 struct net_device *dev,
1647 const u8 *peer,
1648 const struct cfg80211_bitrate_mask *mask)
1649{
5d82c53a 1650 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
433c3990 1651 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
57fbcce3 1652 enum nl80211_band band;
c44379e2 1653 struct mwifiex_adapter *adapter = priv->adapter;
5d82c53a 1654
433c3990 1655 if (!priv->media_connected) {
acebe8c1
ZL
1656 mwifiex_dbg(adapter, ERROR,
1657 "Can not set Tx data rate in disconnected state\n");
433c3990 1658 return -EINVAL;
5d82c53a
YAP
1659 }
1660
433c3990 1661 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5d82c53a 1662
433c3990 1663 memset(bitmap_rates, 0, sizeof(bitmap_rates));
5d82c53a 1664
433c3990 1665 /* Fill HR/DSSS rates. */
57fbcce3 1666 if (band == NL80211_BAND_2GHZ)
433c3990 1667 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
5d82c53a 1668
433c3990 1669 /* Fill OFDM rates */
57fbcce3 1670 if (band == NL80211_BAND_2GHZ)
433c3990
AK
1671 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1672 else
1673 bitmap_rates[1] = mask->control[band].legacy;
1674
d1e33e65
JD
1675 /* Fill HT MCS rates */
1676 bitmap_rates[2] = mask->control[band].ht_mcs[0];
c44379e2 1677 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
d1e33e65 1678 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
433c3990 1679
c44379e2
AK
1680 /* Fill VHT MCS rates */
1681 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1682 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1683 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1684 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1685 }
1686
fa0ecbb9
BZ
1687 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1688 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
5d82c53a
YAP
1689}
1690
fa444bf8
AK
1691/*
1692 * CFG802.11 operation handler for connection quality monitoring.
1693 *
1694 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1695 * events to FW.
1696 */
1697static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1698 struct net_device *dev,
1699 s32 rssi_thold, u32 rssi_hyst)
1700{
1701 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1702 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1703
1704 priv->cqm_rssi_thold = rssi_thold;
1705 priv->cqm_rssi_hyst = rssi_hyst;
1706
1707 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1708 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1709
1710 /* Subscribe/unsubscribe low and high rssi events */
1711 if (rssi_thold && rssi_hyst) {
1712 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1713 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1714 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1715 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1716 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
fa0ecbb9
BZ
1717 return mwifiex_send_cmd(priv,
1718 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1719 0, 0, &subsc_evt, true);
fa444bf8
AK
1720 } else {
1721 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
fa0ecbb9
BZ
1722 return mwifiex_send_cmd(priv,
1723 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1724 0, 0, &subsc_evt, true);
fa444bf8
AK
1725 }
1726
1727 return 0;
1728}
1729
5370c836
AP
1730/* cfg80211 operation handler for change_beacon.
1731 * Function retrieves and sets modified management IEs to FW.
1732 */
1733static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1734 struct net_device *dev,
1735 struct cfg80211_beacon_data *data)
1736{
1737 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
dec277f7
XH
1738 struct mwifiex_adapter *adapter = priv->adapter;
1739
1740 mwifiex_cancel_scan(adapter);
5370c836 1741
9197ab9e 1742 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
acebe8c1
ZL
1743 mwifiex_dbg(priv->adapter, ERROR,
1744 "%s: bss_type mismatched\n", __func__);
5370c836
AP
1745 return -EINVAL;
1746 }
1747
1748 if (!priv->bss_started) {
acebe8c1
ZL
1749 mwifiex_dbg(priv->adapter, ERROR,
1750 "%s: bss not started\n", __func__);
5370c836
AP
1751 return -EINVAL;
1752 }
1753
1754 if (mwifiex_set_mgmt_ies(priv, data)) {
acebe8c1
ZL
1755 mwifiex_dbg(priv->adapter, ERROR,
1756 "%s: setting mgmt ies failed\n", __func__);
5370c836
AP
1757 return -EFAULT;
1758 }
1759
1760 return 0;
1761}
1762
0f9e9b8b
AP
1763/* cfg80211 operation handler for del_station.
1764 * Function deauthenticates station which value is provided in mac parameter.
1765 * If mac is NULL/broadcast, all stations in associated station list are
1766 * deauthenticated. If bss is not started or there are no stations in
1767 * associated stations list, no action is taken.
1768 */
1769static int
1770mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
89c771e5 1771 struct station_del_parameters *params)
0f9e9b8b
AP
1772{
1773 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1774 struct mwifiex_sta_node *sta_node;
fc99dd08 1775 u8 deauth_mac[ETH_ALEN];
0f9e9b8b
AP
1776 unsigned long flags;
1777
abffd274
XH
1778 if (!priv->bss_started && priv->wdev.cac_started) {
1779 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
1780 mwifiex_abort_cac(priv);
1781 }
1782
0f9e9b8b
AP
1783 if (list_empty(&priv->sta_list) || !priv->bss_started)
1784 return 0;
1785
fc99dd08
AP
1786 if (!params->mac || is_broadcast_ether_addr(params->mac))
1787 return 0;
1788
acebe8c1
ZL
1789 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
1790 __func__, params->mac);
fc99dd08 1791
93803b33 1792 eth_zero_addr(deauth_mac);
fc99dd08
AP
1793
1794 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1795 sta_node = mwifiex_get_sta_entry(priv, params->mac);
1796 if (sta_node)
1797 ether_addr_copy(deauth_mac, params->mac);
1798 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1799
1800 if (is_valid_ether_addr(deauth_mac)) {
1801 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1802 HostCmd_ACT_GEN_SET, 0,
1803 deauth_mac, true))
1804 return -1;
0f9e9b8b
AP
1805 }
1806
1807 return 0;
1808}
1809
8a279d5b
AK
1810static int
1811mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1812{
1813 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1814 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1815 MWIFIEX_BSS_ROLE_ANY);
1816 struct mwifiex_ds_ant_cfg ant_cfg;
1817
1818 if (!tx_ant || !rx_ant)
1819 return -EOPNOTSUPP;
1820
1821 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1822 /* Not a MIMO chip. User should provide specific antenna number
1823 * for Tx/Rx path or enable all antennas for diversity
1824 */
1825 if (tx_ant != rx_ant)
1826 return -EOPNOTSUPP;
1827
1828 if ((tx_ant & (tx_ant - 1)) &&
1829 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1830 return -EOPNOTSUPP;
1831
1832 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1833 (priv->adapter->number_of_antenna > 1)) {
1834 tx_ant = RF_ANTENNA_AUTO;
1835 rx_ant = RF_ANTENNA_AUTO;
1836 }
a5333914
AK
1837 } else {
1838 struct ieee80211_sta_ht_cap *ht_info;
1839 int rx_mcs_supp;
57fbcce3 1840 enum nl80211_band band;
a5333914
AK
1841
1842 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1843 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1844 if (adapter->is_hw_11ac_capable)
1845 adapter->usr_dot_11ac_mcs_support =
1846 MWIFIEX_11AC_MCS_MAP_1X1;
1847 } else {
1848 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1849 if (adapter->is_hw_11ac_capable)
1850 adapter->usr_dot_11ac_mcs_support =
1851 MWIFIEX_11AC_MCS_MAP_2X2;
1852 }
1853
57fbcce3 1854 for (band = 0; band < NUM_NL80211_BANDS; band++) {
a5333914
AK
1855 if (!adapter->wiphy->bands[band])
1856 continue;
1857
1858 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1859 rx_mcs_supp =
1860 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1861 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1862 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1863 }
8a279d5b
AK
1864 }
1865
1866 ant_cfg.tx_ant = tx_ant;
1867 ant_cfg.rx_ant = rx_ant;
1868
fa0ecbb9
BZ
1869 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1870 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
8a279d5b
AK
1871}
1872
3ee71285
SL
1873static int
1874mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1875{
1876 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1877 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1878 MWIFIEX_BSS_ROLE_ANY);
1879 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1880 HostCmd_ACT_GEN_GET, 0, NULL, true);
1881
1882 *tx_ant = priv->tx_ant;
1883 *rx_ant = priv->rx_ant;
1884
1885 return 0;
1886}
1887
12190c5d
AP
1888/* cfg80211 operation handler for stop ap.
1889 * Function stops BSS running at uAP interface.
1890 */
1891static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1892{
1893 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1894
85afb186
AP
1895 mwifiex_abort_cac(priv);
1896
40bbc21a 1897 if (mwifiex_del_mgmt_ies(priv))
acebe8c1
ZL
1898 mwifiex_dbg(priv->adapter, ERROR,
1899 "Failed to delete mgmt IEs!\n");
40bbc21a 1900
c8258913 1901 priv->ap_11n_enabled = 0;
35c739b5 1902 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
c8258913 1903
fa0ecbb9
BZ
1904 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1905 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
acebe8c1
ZL
1906 mwifiex_dbg(priv->adapter, ERROR,
1907 "Failed to stop the BSS\n");
12190c5d
AP
1908 return -1;
1909 }
1910
ed5cfbe6
AP
1911 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
1912 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
1913 mwifiex_dbg(priv->adapter, ERROR,
1914 "Failed to reset BSS\n");
1915 return -1;
1916 }
1917
0117e78a
MF
1918 if (netif_carrier_ok(priv->netdev))
1919 netif_carrier_off(priv->netdev);
1920 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
1921
12190c5d
AP
1922 return 0;
1923}
1924
1925/* cfg80211 operation handler for start_ap.
1926 * Function sets beacon period, DTIM period, SSID and security into
1927 * AP config structure.
1928 * AP is configured with these settings and BSS is started.
1929 */
1930static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1931 struct net_device *dev,
1932 struct cfg80211_ap_settings *params)
1933{
1934 struct mwifiex_uap_bss_param *bss_cfg;
1935 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1936
9197ab9e 1937 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
f752dcd5
AP
1938 return -1;
1939
12190c5d
AP
1940 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1941 if (!bss_cfg)
1942 return -ENOMEM;
1943
1944 mwifiex_set_sys_config_invalid_data(bss_cfg);
1945
1946 if (params->beacon_interval)
1947 bss_cfg->beacon_period = params->beacon_interval;
1948 if (params->dtim_period)
1949 bss_cfg->dtim_period = params->dtim_period;
1950
1951 if (params->ssid && params->ssid_len) {
1952 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1953 bss_cfg->ssid.ssid_len = params->ssid_len;
1954 }
b654ca18
AP
1955 if (params->inactivity_timeout > 0) {
1956 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1957 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1958 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1959 }
12190c5d 1960
7a1c9934
AP
1961 switch (params->hidden_ssid) {
1962 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1963 bss_cfg->bcast_ssid_ctl = 1;
1964 break;
1965 case NL80211_HIDDEN_SSID_ZERO_LEN:
1966 bss_cfg->bcast_ssid_ctl = 0;
1967 break;
1968 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1969 /* firmware doesn't support this type of hidden SSID */
1970 default:
b3190466 1971 kfree(bss_cfg);
7a1c9934
AP
1972 return -EINVAL;
1973 }
1974
7ee38bf4 1975 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
a3c2c4f6 1976 mwifiex_set_uap_rates(bss_cfg, params);
05910f4a 1977
f752dcd5 1978 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
acebe8c1 1979 mwifiex_dbg(priv->adapter, ERROR,
3334c28e 1980 "Failed to parse security parameters!\n");
4028a514 1981 goto out;
f752dcd5
AP
1982 }
1983
22281256 1984 mwifiex_set_ht_params(priv, bss_cfg, params);
83c78da9
YAP
1985
1986 if (priv->adapter->is_hw_11ac_capable) {
1987 mwifiex_set_vht_params(priv, bss_cfg, params);
1988 mwifiex_set_vht_width(priv, params->chandef.width,
1989 priv->ap_11ac_enabled);
1990 }
1991
2b6254da
AP
1992 if (priv->ap_11ac_enabled)
1993 mwifiex_set_11ac_ba_params(priv);
1994 else
1995 mwifiex_set_ba_params(priv);
1996
54428c57 1997 mwifiex_set_wmm_params(priv, bss_cfg, params);
22281256 1998
8a73dd63
AP
1999 if (mwifiex_is_11h_active(priv))
2000 mwifiex_set_tpc_params(priv, bss_cfg, params);
2001
cf075eac
AP
2002 if (mwifiex_is_11h_active(priv) &&
2003 !cfg80211_chandef_dfs_required(wiphy, &params->chandef,
2004 priv->bss_mode)) {
acebe8c1
ZL
2005 mwifiex_dbg(priv->adapter, INFO,
2006 "Disable 11h extensions in FW\n");
cf075eac 2007 if (mwifiex_11h_activate(priv, false)) {
acebe8c1
ZL
2008 mwifiex_dbg(priv->adapter, ERROR,
2009 "Failed to disable 11h extensions!!");
4028a514 2010 goto out;
cf075eac 2011 }
7b716625 2012 priv->state_11h.is_11h_active = false;
cf075eac
AP
2013 }
2014
b654ca18 2015 if (mwifiex_config_start_uap(priv, bss_cfg)) {
acebe8c1
ZL
2016 mwifiex_dbg(priv->adapter, ERROR,
2017 "Failed to start AP\n");
4028a514 2018 goto out;
12190c5d
AP
2019 }
2020
b0d4c5ec 2021 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
4028a514 2022 goto out;
0117e78a
MF
2023
2024 if (!netif_carrier_ok(priv->netdev))
2025 netif_carrier_on(priv->netdev);
2026 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
b0d4c5ec 2027
35c739b5 2028 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
12190c5d 2029 kfree(bss_cfg);
12190c5d 2030 return 0;
4028a514
WY
2031
2032out:
2033 kfree(bss_cfg);
2034 return -1;
12190c5d
AP
2035}
2036
5e6e3a92
BZ
2037/*
2038 * CFG802.11 operation handler for disconnection request.
2039 *
2040 * This function does not work when there is already a disconnection
2041 * procedure going on.
2042 */
2043static int
2044mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
2045 u16 reason_code)
2046{
2047 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2048
0c9b7f22 2049 if (!mwifiex_stop_bg_scan(priv))
b34939b9 2050 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
0c9b7f22 2051
600f5d90 2052 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
2053 return -EFAULT;
2054
93803b33 2055 eth_zero_addr(priv->cfg_bssid);
587b36d3 2056 priv->hs2_enabled = false;
5e6e3a92
BZ
2057
2058 return 0;
2059}
2060
2061/*
2062 * This function informs the CFG802.11 subsystem of a new IBSS.
2063 *
2064 * The following information are sent to the CFG802.11 subsystem
2065 * to register the new IBSS. If we do not register the new IBSS,
2066 * a kernel panic will result.
2067 * - SSID
2068 * - SSID length
2069 * - BSSID
2070 * - Channel
2071 */
2072static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
2073{
5e6e3a92
BZ
2074 struct ieee80211_channel *chan;
2075 struct mwifiex_bss_info bss_info;
aa95a48d 2076 struct cfg80211_bss *bss;
270e58e8 2077 int ie_len;
5e6e3a92 2078 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
57fbcce3 2079 enum nl80211_band band;
5e6e3a92 2080
636c4598
YAP
2081 if (mwifiex_get_bss_info(priv, &bss_info))
2082 return -1;
5e6e3a92
BZ
2083
2084 ie_buf[0] = WLAN_EID_SSID;
2085 ie_buf[1] = bss_info.ssid.ssid_len;
2086
2087 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
aea0701e 2088 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
5e6e3a92
BZ
2089 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
2090
4ed5d521 2091 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
543b921b 2092 chan = ieee80211_get_channel(priv->wdev.wiphy,
5e6e3a92 2093 ieee80211_channel_to_frequency(bss_info.bss_chan,
4ed5d521 2094 band));
5e6e3a92 2095
4facc34a 2096 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
5bc8c1f2 2097 CFG80211_BSS_FTYPE_UNKNOWN,
aea0701e
YAP
2098 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
2099 0, ie_buf, ie_len, 0, GFP_KERNEL);
02421dd3
XH
2100 if (bss) {
2101 cfg80211_put_bss(priv->wdev.wiphy, bss);
2102 ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
2103 }
5e6e3a92 2104
636c4598 2105 return 0;
5e6e3a92
BZ
2106}
2107
5e6e3a92
BZ
2108/*
2109 * This function connects with a BSS.
2110 *
2111 * This function handles both Infra and Ad-Hoc modes. It also performs
2112 * validity checking on the provided parameters, disconnects from the
2113 * current BSS (if any), sets up the association/scan parameters,
2114 * including security settings, and performs specific SSID scan before
2115 * trying to connect.
2116 *
2117 * For Infra mode, the function returns failure if the specified SSID
2118 * is not found in scan table. However, for Ad-Hoc mode, it can create
2119 * the IBSS if it does not exist. On successful completion in either case,
7c6fa2a8 2120 * the function notifies the CFG802.11 subsystem of the new BSS connection.
5e6e3a92
BZ
2121 */
2122static int
664834de
JM
2123mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
2124 const u8 *ssid, const u8 *bssid, int mode,
2125 struct ieee80211_channel *channel,
5e6e3a92
BZ
2126 struct cfg80211_connect_params *sme, bool privacy)
2127{
b9be5f39 2128 struct cfg80211_ssid req_ssid;
270e58e8 2129 int ret, auth_type = 0;
7c6fa2a8 2130 struct cfg80211_bss *bss = NULL;
d7b9c520 2131 u8 is_scanning_required = 0;
5e6e3a92 2132
b9be5f39 2133 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
5e6e3a92
BZ
2134
2135 req_ssid.ssid_len = ssid_len;
2136 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
acebe8c1 2137 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
5e6e3a92
BZ
2138 return -EINVAL;
2139 }
2140
2141 memcpy(req_ssid.ssid, ssid, ssid_len);
2142 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
acebe8c1 2143 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
5e6e3a92
BZ
2144 return -EINVAL;
2145 }
2146
6670f15b
AK
2147 /* As this is new association, clear locally stored
2148 * keys and security related flags */
2149 priv->sec_info.wpa_enabled = false;
2150 priv->sec_info.wpa2_enabled = false;
2151 priv->wep_key_curr_index = 0;
00f157b4 2152 priv->sec_info.encryption_mode = 0;
a0f6d6ca 2153 priv->sec_info.is_authtype_auto = 0;
53b11231 2154 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
5e6e3a92 2155
eecd8250 2156 if (mode == NL80211_IFTYPE_ADHOC) {
e267e71e
K
2157 u16 enable = true;
2158
2159 /* set ibss coalescing_status */
2160 ret = mwifiex_send_cmd(
2161 priv,
2162 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2163 HostCmd_ACT_GEN_SET, 0, &enable, true);
2164 if (ret)
2165 return ret;
2166
5e6e3a92
BZ
2167 /* "privacy" is set only for ad-hoc mode */
2168 if (privacy) {
2169 /*
2be50b8d 2170 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
5e6e3a92
BZ
2171 * the firmware can find a matching network from the
2172 * scan. The cfg80211 does not give us the encryption
2173 * mode at this stage so just setting it to WEP here.
2174 */
203afeca 2175 priv->sec_info.encryption_mode =
2be50b8d 2176 WLAN_CIPHER_SUITE_WEP104;
203afeca 2177 priv->sec_info.authentication_mode =
f986b6d5 2178 NL80211_AUTHTYPE_OPEN_SYSTEM;
5e6e3a92
BZ
2179 }
2180
2181 goto done;
2182 }
2183
2184 /* Now handle infra mode. "sme" is valid for infra mode only */
a0f6d6ca 2185 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
f986b6d5 2186 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
a0f6d6ca
AK
2187 priv->sec_info.is_authtype_auto = 1;
2188 } else {
2189 auth_type = sme->auth_type;
2190 }
5e6e3a92
BZ
2191
2192 if (sme->crypto.n_ciphers_pairwise) {
2be50b8d
YAP
2193 priv->sec_info.encryption_mode =
2194 sme->crypto.ciphers_pairwise[0];
203afeca 2195 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
2196 }
2197
2198 if (sme->crypto.cipher_group) {
2be50b8d 2199 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
203afeca 2200 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
2201 }
2202 if (sme->ie)
2203 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
2204
2205 if (sme->key) {
e6faada5 2206 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
acebe8c1
ZL
2207 mwifiex_dbg(priv->adapter, INFO,
2208 "info: setting wep encryption\t"
2209 "with key len %d\n", sme->key_len);
6670f15b 2210 priv->wep_key_curr_index = sme->key_idx;
53b11231
YL
2211 ret = mwifiex_set_encode(priv, NULL, sme->key,
2212 sme->key_len, sme->key_idx,
2213 NULL, 0);
5e6e3a92
BZ
2214 }
2215 }
2216done:
7c6fa2a8
AK
2217 /*
2218 * Scan entries are valid for some time (15 sec). So we can save one
2219 * active scan time if we just try cfg80211_get_bss first. If it fails
2220 * then request scan and cfg80211_get_bss() again for final output.
2221 */
2222 while (1) {
2223 if (is_scanning_required) {
2224 /* Do specific SSID scanning */
2225 if (mwifiex_request_scan(priv, &req_ssid)) {
acebe8c1 2226 mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
7c6fa2a8
AK
2227 return -EFAULT;
2228 }
2229 }
5e6e3a92 2230
7c6fa2a8
AK
2231 /* Find the BSS we want using available scan results */
2232 if (mode == NL80211_IFTYPE_ADHOC)
4facc34a 2233 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
7c6fa2a8 2234 bssid, ssid, ssid_len,
6eb18137
DL
2235 IEEE80211_BSS_TYPE_IBSS,
2236 IEEE80211_PRIVACY_ANY);
7c6fa2a8 2237 else
4facc34a 2238 bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
7c6fa2a8 2239 bssid, ssid, ssid_len,
6eb18137
DL
2240 IEEE80211_BSS_TYPE_ESS,
2241 IEEE80211_PRIVACY_ANY);
7c6fa2a8
AK
2242
2243 if (!bss) {
2244 if (is_scanning_required) {
acebe8c1
ZL
2245 mwifiex_dbg(priv->adapter, WARN,
2246 "assoc: requested bss not found in scan results\n");
7c6fa2a8
AK
2247 break;
2248 }
2249 is_scanning_required = 1;
2250 } else {
acebe8c1 2251 mwifiex_dbg(priv->adapter, MSG,
fcd2042e
BN
2252 "info: trying to associate to '%.*s' bssid %pM\n",
2253 req_ssid.ssid_len, (char *)req_ssid.ssid,
2254 bss->bssid);
7c6fa2a8
AK
2255 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2256 break;
2257 }
5e6e3a92
BZ
2258 }
2259
06975884
AK
2260 ret = mwifiex_bss_start(priv, bss, &req_ssid);
2261 if (ret)
2262 return ret;
5e6e3a92 2263
eecd8250 2264 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
2265 /* Inform the BSS information to kernel, otherwise
2266 * kernel will give a panic after successful assoc */
2267 if (mwifiex_cfg80211_inform_ibss_bss(priv))
2268 return -EFAULT;
2269 }
2270
2271 return ret;
2272}
2273
2274/*
2275 * CFG802.11 operation handler for association request.
2276 *
2277 * This function does not work when the current mode is set to Ad-Hoc, or
2278 * when there is already an association procedure going on. The given BSS
2279 * information is used to associate.
2280 */
2281static int
2282mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2283 struct cfg80211_connect_params *sme)
2284{
2285 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
e00483f7 2286 struct mwifiex_adapter *adapter = priv->adapter;
8bc77a4d 2287 int ret;
5e6e3a92 2288
953b3539 2289 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
acebe8c1
ZL
2290 mwifiex_dbg(adapter, ERROR,
2291 "%s: reject infra assoc request in non-STA role\n",
2292 dev->name);
8bc77a4d 2293 return -EINVAL;
e568634a
AP
2294 }
2295
4facc34a 2296 if (priv->wdev.current_bss) {
acebe8c1
ZL
2297 mwifiex_dbg(adapter, ERROR,
2298 "%s: already connected\n", dev->name);
71954f24
UR
2299 return -EALREADY;
2300 }
2301
b74d6e74
AK
2302 if (priv->scan_block)
2303 priv->scan_block = false;
2304
e00483f7 2305 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
acebe8c1
ZL
2306 mwifiex_dbg(adapter, ERROR,
2307 "%s: Ignore connection.\t"
2308 "Card removed or FW in bad state\n",
2309 dev->name);
e00483f7
AK
2310 return -EFAULT;
2311 }
2312
acebe8c1 2313 mwifiex_dbg(adapter, INFO,
fcd2042e
BN
2314 "info: Trying to associate to %.*s and bssid %pM\n",
2315 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
5e6e3a92 2316
0c9b7f22 2317 if (!mwifiex_stop_bg_scan(priv))
b34939b9 2318 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
0c9b7f22 2319
5e6e3a92 2320 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
eecd8250 2321 priv->bss_mode, sme->channel, sme, 0);
38c9d664
AK
2322 if (!ret) {
2323 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
2324 NULL, 0, WLAN_STATUS_SUCCESS,
2325 GFP_KERNEL);
acebe8c1
ZL
2326 mwifiex_dbg(priv->adapter, MSG,
2327 "info: associated to bssid %pM successfully\n",
2328 priv->cfg_bssid);
9927baa3
AP
2329 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
2330 priv->adapter->auto_tdls &&
2331 priv->bss_type == MWIFIEX_BSS_TYPE_STA)
2332 mwifiex_setup_auto_tdls_timer(priv);
38c9d664 2333 } else {
acebe8c1
ZL
2334 mwifiex_dbg(priv->adapter, ERROR,
2335 "info: association to bssid %pM failed\n",
2336 priv->cfg_bssid);
93803b33 2337 eth_zero_addr(priv->cfg_bssid);
06975884
AK
2338
2339 if (ret > 0)
2340 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2341 NULL, 0, NULL, 0, ret,
2342 GFP_KERNEL);
2343 else
2344 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
2345 NULL, 0, NULL, 0,
2346 WLAN_STATUS_UNSPECIFIED_FAILURE,
2347 GFP_KERNEL);
38c9d664
AK
2348 }
2349
06975884 2350 return 0;
5e6e3a92
BZ
2351}
2352
05910f4a
AK
2353/*
2354 * This function sets following parameters for ibss network.
2355 * - channel
2356 * - start band
2357 * - 11n flag
2358 * - secondary channel offset
2359 */
2360static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
2361 struct cfg80211_ibss_params *params)
2362{
05910f4a
AK
2363 struct mwifiex_adapter *adapter = priv->adapter;
2364 int index = 0, i;
2365 u8 config_bands = 0;
2366
57fbcce3 2367 if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
05910f4a
AK
2368 if (!params->basic_rates) {
2369 config_bands = BAND_B | BAND_G;
2370 } else {
2371 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
2372 /*
2373 * Rates below 6 Mbps in the table are CCK
2374 * rates; 802.11b and from 6 they are OFDM;
2375 * 802.11G
2376 */
2377 if (mwifiex_rates[i].bitrate == 60) {
2378 index = 1 << i;
2379 break;
2380 }
2381 }
2382
2383 if (params->basic_rates < index) {
2384 config_bands = BAND_B;
2385 } else {
2386 config_bands = BAND_G;
2387 if (params->basic_rates % index)
2388 config_bands |= BAND_B;
2389 }
2390 }
2391
683b6d3b
JB
2392 if (cfg80211_get_chandef_type(&params->chandef) !=
2393 NL80211_CHAN_NO_HT)
3b86acb8 2394 config_bands |= BAND_G | BAND_GN;
05910f4a 2395 } else {
c3ff0b2d 2396 if (cfg80211_get_chandef_type(&params->chandef) ==
683b6d3b 2397 NL80211_CHAN_NO_HT)
05910f4a
AK
2398 config_bands = BAND_A;
2399 else
2400 config_bands = BAND_AN | BAND_A;
2401 }
2402
2403 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
2404 adapter->config_bands = config_bands;
2405 adapter->adhoc_start_band = config_bands;
2406
2407 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
2408 adapter->adhoc_11n_enabled = true;
2409 else
2410 adapter->adhoc_11n_enabled = false;
2411 }
2412
2413 adapter->sec_chan_offset =
683b6d3b
JB
2414 mwifiex_chan_type_to_sec_chan_offset(
2415 cfg80211_get_chandef_type(&params->chandef));
2416 priv->adhoc_channel = ieee80211_frequency_to_channel(
2417 params->chandef.chan->center_freq);
05910f4a 2418
acebe8c1
ZL
2419 mwifiex_dbg(adapter, INFO,
2420 "info: set ibss band %d, chan %d, chan offset %d\n",
2421 config_bands, priv->adhoc_channel,
2422 adapter->sec_chan_offset);
05910f4a
AK
2423
2424 return 0;
2425}
2426
5e6e3a92
BZ
2427/*
2428 * CFG802.11 operation handler to join an IBSS.
2429 *
2430 * This function does not work in any mode other than Ad-Hoc, or if
2431 * a join operation is already in progress.
2432 */
2433static int
2434mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2435 struct cfg80211_ibss_params *params)
2436{
f540f9f3 2437 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 2438 int ret = 0;
5e6e3a92 2439
eecd8250 2440 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
acebe8c1
ZL
2441 mwifiex_dbg(priv->adapter, ERROR,
2442 "request to join ibss received\t"
2443 "when station is not in ibss mode\n");
5e6e3a92
BZ
2444 goto done;
2445 }
2446
acebe8c1 2447 mwifiex_dbg(priv->adapter, MSG,
fcd2042e
BN
2448 "info: trying to join to %.*s and bssid %pM\n",
2449 params->ssid_len, (char *)params->ssid, params->bssid);
5e6e3a92 2450
05910f4a
AK
2451 mwifiex_set_ibss_params(priv, params);
2452
5e6e3a92 2453 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
aea0701e 2454 params->bssid, priv->bss_mode,
683b6d3b
JB
2455 params->chandef.chan, NULL,
2456 params->privacy);
5e6e3a92 2457done:
38c9d664 2458 if (!ret) {
fe94f3a4
AQ
2459 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
2460 params->chandef.chan, GFP_KERNEL);
acebe8c1
ZL
2461 mwifiex_dbg(priv->adapter, MSG,
2462 "info: joined/created adhoc network with bssid\t"
2463 "%pM successfully\n", priv->cfg_bssid);
38c9d664 2464 } else {
acebe8c1
ZL
2465 mwifiex_dbg(priv->adapter, ERROR,
2466 "info: failed creating/joining adhoc network\n");
38c9d664
AK
2467 }
2468
5e6e3a92
BZ
2469 return ret;
2470}
2471
2472/*
2473 * CFG802.11 operation handler to leave an IBSS.
2474 *
2475 * This function does not work if a leave operation is
2476 * already in progress.
2477 */
2478static int
2479mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2480{
f540f9f3 2481 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 2482
acebe8c1
ZL
2483 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
2484 priv->cfg_bssid);
600f5d90 2485 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
2486 return -EFAULT;
2487
93803b33 2488 eth_zero_addr(priv->cfg_bssid);
5e6e3a92
BZ
2489
2490 return 0;
2491}
2492
2493/*
2494 * CFG802.11 operation handler for scan request.
2495 *
2496 * This function issues a scan request to the firmware based upon
a484804b 2497 * the user specified scan configuration. On successful completion,
5e6e3a92
BZ
2498 * it also informs the results.
2499 */
2500static int
fd014284 2501mwifiex_cfg80211_scan(struct wiphy *wiphy,
5e6e3a92
BZ
2502 struct cfg80211_scan_request *request)
2503{
fd014284 2504 struct net_device *dev = request->wdev->netdev;
5e6e3a92 2505 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
c2476335 2506 int i, offset, ret;
38c9d664 2507 struct ieee80211_channel *chan;
ea021f56 2508 struct ieee_types_header *ie;
75ab753d 2509 struct mwifiex_user_scan_cfg *user_scan_cfg;
5e6e3a92 2510
acebe8c1
ZL
2511 mwifiex_dbg(priv->adapter, CMD,
2512 "info: received scan request on %s\n", dev->name);
5e6e3a92 2513
75ab753d
AK
2514 /* Block scan request if scan operation or scan cleanup when interface
2515 * is disabled is in process
2516 */
2517 if (priv->scan_request || priv->scan_aborting) {
acebe8c1
ZL
2518 mwifiex_dbg(priv->adapter, WARN,
2519 "cmd: Scan already in process..\n");
f162cac8
AK
2520 return -EBUSY;
2521 }
2522
b74d6e74
AK
2523 if (!priv->wdev.current_bss && priv->scan_block)
2524 priv->scan_block = false;
2525
0c9b7f22 2526 if (!mwifiex_stop_bg_scan(priv))
b34939b9 2527 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
0c9b7f22 2528
75ab753d
AK
2529 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
2530 if (!user_scan_cfg)
38c9d664 2531 return -ENOMEM;
be0b281e 2532
6fcf2b10
BZ
2533 priv->scan_request = request;
2534
c2a8f0ff
GB
2535 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
2536 ether_addr_copy(priv->random_mac, request->mac_addr);
2537 for (i = 0; i < ETH_ALEN; i++) {
2538 priv->random_mac[i] &= request->mac_addr_mask[i];
2539 priv->random_mac[i] |= get_random_int() &
2540 ~(request->mac_addr_mask[i]);
2541 }
7e2f18f0
BN
2542 ether_addr_copy(user_scan_cfg->random_mac, priv->random_mac);
2543 } else {
2544 eth_zero_addr(priv->random_mac);
c2a8f0ff
GB
2545 }
2546
75ab753d
AK
2547 user_scan_cfg->num_ssids = request->n_ssids;
2548 user_scan_cfg->ssid_list = request->ssids;
be0b281e 2549
13d7ba78 2550 if (request->ie && request->ie_len) {
ea021f56 2551 offset = 0;
13d7ba78
AP
2552 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2553 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2554 continue;
2555 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
ea021f56
SP
2556 ie = (struct ieee_types_header *)(request->ie + offset);
2557 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2558 offset += sizeof(*ie) + ie->len;
2559
2560 if (offset >= request->ie_len)
2561 break;
13d7ba78
AP
2562 }
2563 }
2564
901ceba4
SP
2565 for (i = 0; i < min_t(u32, request->n_channels,
2566 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
38c9d664 2567 chan = request->channels[i];
75ab753d
AK
2568 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
2569 user_scan_cfg->chan_list[i].radio_type = chan->band;
38c9d664 2570
a9c1c89e 2571 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
75ab753d 2572 user_scan_cfg->chan_list[i].scan_type =
aea0701e 2573 MWIFIEX_SCAN_TYPE_PASSIVE;
38c9d664 2574 else
75ab753d 2575 user_scan_cfg->chan_list[i].scan_type =
aea0701e 2576 MWIFIEX_SCAN_TYPE_ACTIVE;
38c9d664 2577
75ab753d 2578 user_scan_cfg->chan_list[i].scan_time = 0;
38c9d664 2579 }
c2476335 2580
cb91be87
AP
2581 if (priv->adapter->scan_chan_gap_enabled &&
2582 mwifiex_is_any_intf_active(priv))
2583 user_scan_cfg->scan_chan_gap =
2584 priv->adapter->scan_chan_gap_time;
2585
75ab753d
AK
2586 ret = mwifiex_scan_networks(priv, user_scan_cfg);
2587 kfree(user_scan_cfg);
c2476335 2588 if (ret) {
acebe8c1
ZL
2589 mwifiex_dbg(priv->adapter, ERROR,
2590 "scan failed: %d\n", ret);
75ab753d 2591 priv->scan_aborting = false;
6fcf2b10 2592 priv->scan_request = NULL;
c2476335
BZ
2593 return ret;
2594 }
38c9d664 2595
13d7ba78
AP
2596 if (request->ie && request->ie_len) {
2597 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2598 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2599 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2600 memset(&priv->vs_ie[i].ie, 0,
2601 MWIFIEX_MAX_VSIE_LEN);
2602 }
2603 }
2604 }
5e6e3a92
BZ
2605 return 0;
2606}
2607
0c9b7f22
XH
2608/* CFG802.11 operation handler for sched_scan_start.
2609 *
2610 * This function issues a bgscan config request to the firmware based upon
2611 * the user specified sched_scan configuration. On successful completion,
2612 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
2613 * query command to get sched_scan results from firmware.
2614 */
2615static int
2616mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
2617 struct net_device *dev,
2618 struct cfg80211_sched_scan_request *request)
2619{
2620 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2621 int i, offset;
2622 struct ieee80211_channel *chan;
2623 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2624 struct ieee_types_header *ie;
2625
2626 if (!request || (!request->n_ssids && !request->n_match_sets)) {
2627 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
2628 __func__);
2629 return -EINVAL;
2630 }
2631
2632 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
2633 request->n_ssids, request->n_match_sets);
2634 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
2635 request->n_channels, request->scan_plans->interval,
2636 (int)request->ie_len);
2637
2638 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2639 if (!bgscan_cfg)
2640 return -ENOMEM;
2641
2642 if (priv->scan_request || priv->scan_aborting)
2643 bgscan_cfg->start_later = true;
2644
2645 bgscan_cfg->num_ssids = request->n_match_sets;
2646 bgscan_cfg->ssid_list = request->match_sets;
2647
2648 if (request->ie && request->ie_len) {
2649 offset = 0;
2650 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2651 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
2652 continue;
2653 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
2654 ie = (struct ieee_types_header *)(request->ie + offset);
2655 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
2656 offset += sizeof(*ie) + ie->len;
2657
2658 if (offset >= request->ie_len)
2659 break;
2660 }
2661 }
2662
2663 for (i = 0; i < min_t(u32, request->n_channels,
2664 MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
2665 chan = request->channels[i];
2666 bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
2667 bgscan_cfg->chan_list[i].radio_type = chan->band;
2668
2669 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
2670 bgscan_cfg->chan_list[i].scan_type =
2671 MWIFIEX_SCAN_TYPE_PASSIVE;
2672 else
2673 bgscan_cfg->chan_list[i].scan_type =
2674 MWIFIEX_SCAN_TYPE_ACTIVE;
2675
2676 bgscan_cfg->chan_list[i].scan_time = 0;
2677 }
2678
2679 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
2680 MWIFIEX_BG_SCAN_CHAN_MAX);
2681
2682 /* Use at least 15 second for per scan cycle */
2683 bgscan_cfg->scan_interval = (request->scan_plans->interval >
2684 MWIFIEX_BGSCAN_INTERVAL) ?
2685 request->scan_plans->interval :
2686 MWIFIEX_BGSCAN_INTERVAL;
2687
2688 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
2689 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
2690 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
2691 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2692 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2693 bgscan_cfg->enable = true;
fdcab083
GB
2694 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
2695 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
2696 bgscan_cfg->rssi_threshold = request->min_rssi_thold;
2697 }
0c9b7f22
XH
2698
2699 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2700 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2701 kfree(bgscan_cfg);
2702 return -EFAULT;
2703 }
2704
2705 priv->sched_scanning = true;
2706
2707 kfree(bgscan_cfg);
2708 return 0;
2709}
2710
2711/* CFG802.11 operation handler for sched_scan_stop.
2712 *
2713 * This function issues a bgscan config command to disable
2714 * previous bgscan configuration in the firmware
2715 */
2716static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
3a3ecf1d 2717 struct net_device *dev, u64 reqid)
0c9b7f22
XH
2718{
2719 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2720
2721 wiphy_info(wiphy, "sched scan stop!");
2722 mwifiex_stop_bg_scan(priv);
2723
2724 return 0;
2725}
2726
a5f39056
YAP
2727static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2728 struct mwifiex_private *priv)
2729{
2730 struct mwifiex_adapter *adapter = priv->adapter;
a5f39056
YAP
2731
2732 vht_info->vht_supported = true;
2733
43283feb 2734 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
a5f39056
YAP
2735 /* Update MCS support for VHT */
2736 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2737 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2738 vht_info->vht_mcs.rx_highest = 0;
2739 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2740 adapter->hw_dot_11ac_mcs_support >> 16);
2741 vht_info->vht_mcs.tx_highest = 0;
2742}
2743
5e6e3a92
BZ
2744/*
2745 * This function sets up the CFG802.11 specific HT capability fields
2746 * with default values.
2747 *
2748 * The following default values are set -
2749 * - HT Supported = True
a46b7b5c
AK
2750 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2751 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2752 * - HT Capabilities supported by firmware
5e6e3a92
BZ
2753 * - MCS information, Rx mask = 0xff
2754 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2755 */
2756static void
2757mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2758 struct mwifiex_private *priv)
2759{
2760 int rx_mcs_supp;
2761 struct ieee80211_mcs_info mcs_set;
2762 u8 *mcs = (u8 *)&mcs_set;
2763 struct mwifiex_adapter *adapter = priv->adapter;
2764
2765 ht_info->ht_supported = true;
a46b7b5c
AK
2766 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2767 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
5e6e3a92
BZ
2768
2769 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
5e6e3a92 2770
a46b7b5c
AK
2771 /* Fill HT capability information */
2772 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2773 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2774 else
2775 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2776
2777 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2778 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2779 else
2780 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2781
2782 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2783 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2784 else
2785 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2786
474a41e9 2787 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
ae1799a1 2788 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
a46b7b5c 2789 else
474a41e9 2790 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
a46b7b5c
AK
2791
2792 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2793 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2794 else
2795 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2796
dd0d83c2
AP
2797 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2798 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2799 else
2800 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2801
2802 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2803 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2804 else
2805 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2806
2807 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2808 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2809 else
2810 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2811
a46b7b5c
AK
2812 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2813 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2814
a5333914
AK
2815 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2816 /* Set MCS for 1x1/2x2 */
5e6e3a92
BZ
2817 memset(mcs, 0xff, rx_mcs_supp);
2818 /* Clear all the other values */
2819 memset(&mcs[rx_mcs_supp], 0,
aea0701e 2820 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
eecd8250 2821 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
aea0701e 2822 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
5e6e3a92
BZ
2823 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2824 SETHT_MCS32(mcs_set.rx_mask);
2825
2826 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2827
2828 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2829}
2830
93a1df48 2831/*
6bab2e19 2832 * create a new virtual interface with the given name and name assign type
93a1df48 2833 */
84efbb84 2834struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
552bff0c 2835 const char *name,
6bab2e19 2836 unsigned char name_assign_type,
84efbb84 2837 enum nl80211_iftype type,
84efbb84 2838 struct vif_params *params)
93a1df48 2839{
67fdf39e
AP
2840 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2841 struct mwifiex_private *priv;
93a1df48
YAP
2842 struct net_device *dev;
2843 void *mdev_priv;
7311ea85 2844 int ret;
93a1df48 2845
93a1df48 2846 if (!adapter)
858faa57 2847 return ERR_PTR(-EFAULT);
93a1df48
YAP
2848
2849 switch (type) {
2850 case NL80211_IFTYPE_UNSPECIFIED:
2851 case NL80211_IFTYPE_STATION:
2852 case NL80211_IFTYPE_ADHOC:
cf052335
AP
2853 if (adapter->curr_iface_comb.sta_intf ==
2854 adapter->iface_limit.sta_intf) {
acebe8c1
ZL
2855 mwifiex_dbg(adapter, ERROR,
2856 "cannot create multiple sta/adhoc ifaces\n");
858faa57 2857 return ERR_PTR(-EINVAL);
93a1df48
YAP
2858 }
2859
5b13d3e1
SL
2860 priv = mwifiex_get_unused_priv_by_bss_type(
2861 adapter, MWIFIEX_BSS_TYPE_STA);
cf052335 2862 if (!priv) {
acebe8c1
ZL
2863 mwifiex_dbg(adapter, ERROR,
2864 "could not get free private struct\n");
cf052335
AP
2865 return ERR_PTR(-EFAULT);
2866 }
2867
4facc34a
AP
2868 priv->wdev.wiphy = wiphy;
2869 priv->wdev.iftype = NL80211_IFTYPE_STATION;
d6bffe8b 2870
93a1df48
YAP
2871 if (type == NL80211_IFTYPE_UNSPECIFIED)
2872 priv->bss_mode = NL80211_IFTYPE_STATION;
2873 else
2874 priv->bss_mode = type;
2875
2876 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2877 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2878 priv->bss_priority = 0;
93a1df48 2879 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
93a1df48 2880
d6bffe8b
AP
2881 break;
2882 case NL80211_IFTYPE_AP:
cf052335
AP
2883 if (adapter->curr_iface_comb.uap_intf ==
2884 adapter->iface_limit.uap_intf) {
acebe8c1
ZL
2885 mwifiex_dbg(adapter, ERROR,
2886 "cannot create multiple AP ifaces\n");
858faa57 2887 return ERR_PTR(-EINVAL);
d6bffe8b
AP
2888 }
2889
5b13d3e1
SL
2890 priv = mwifiex_get_unused_priv_by_bss_type(
2891 adapter, MWIFIEX_BSS_TYPE_UAP);
cf052335 2892 if (!priv) {
acebe8c1
ZL
2893 mwifiex_dbg(adapter, ERROR,
2894 "could not get free private struct\n");
cf052335
AP
2895 return ERR_PTR(-EFAULT);
2896 }
2897
4facc34a
AP
2898 priv->wdev.wiphy = wiphy;
2899 priv->wdev.iftype = NL80211_IFTYPE_AP;
d6bffe8b
AP
2900
2901 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2902 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2903 priv->bss_priority = 0;
d6bffe8b
AP
2904 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2905 priv->bss_started = 0;
d6bffe8b
AP
2906 priv->bss_mode = type;
2907
197f4a2e
SP
2908 break;
2909 case NL80211_IFTYPE_P2P_CLIENT:
cf052335
AP
2910 if (adapter->curr_iface_comb.p2p_intf ==
2911 adapter->iface_limit.p2p_intf) {
acebe8c1
ZL
2912 mwifiex_dbg(adapter, ERROR,
2913 "cannot create multiple P2P ifaces\n");
197f4a2e
SP
2914 return ERR_PTR(-EINVAL);
2915 }
2916
5b13d3e1
SL
2917 priv = mwifiex_get_unused_priv_by_bss_type(
2918 adapter, MWIFIEX_BSS_TYPE_P2P);
cf052335 2919 if (!priv) {
acebe8c1
ZL
2920 mwifiex_dbg(adapter, ERROR,
2921 "could not get free private struct\n");
cf052335
AP
2922 return ERR_PTR(-EFAULT);
2923 }
197f4a2e 2924
cf052335 2925 priv->wdev.wiphy = wiphy;
197f4a2e
SP
2926 /* At start-up, wpa_supplicant tries to change the interface
2927 * to NL80211_IFTYPE_STATION if it is not managed mode.
197f4a2e 2928 */
4facc34a 2929 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
5586d3e2 2930 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
197f4a2e
SP
2931
2932 /* Setting bss_type to P2P tells firmware that this interface
2933 * is receiving P2P peers found during find phase and doing
2934 * action frame handshake.
2935 */
2936 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2937
2938 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2939 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2940 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2941 priv->bss_started = 0;
197f4a2e 2942
bec568ff 2943 if (mwifiex_cfg80211_init_p2p_client(priv)) {
4facc34a
AP
2944 memset(&priv->wdev, 0, sizeof(priv->wdev));
2945 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
2946 return ERR_PTR(-EFAULT);
bec568ff 2947 }
66aa1ae2 2948
93a1df48
YAP
2949 break;
2950 default:
acebe8c1 2951 mwifiex_dbg(adapter, ERROR, "type not supported\n");
858faa57 2952 return ERR_PTR(-EINVAL);
93a1df48
YAP
2953 }
2954
47411a06 2955 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
6bab2e19 2956 name_assign_type, ether_setup,
c835a677 2957 IEEE80211_NUM_ACS, 1);
93a1df48 2958 if (!dev) {
acebe8c1
ZL
2959 mwifiex_dbg(adapter, ERROR,
2960 "no memory available for netdevice\n");
8535107a
BN
2961 ret = -ENOMEM;
2962 goto err_alloc_netdev;
93a1df48
YAP
2963 }
2964
d6bffe8b
AP
2965 mwifiex_init_priv_params(priv, dev);
2966 priv->netdev = dev;
2967
7311ea85
AK
2968 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
2969 HostCmd_ACT_GEN_SET, 0, NULL, true);
f152bdad 2970 if (ret)
8535107a 2971 goto err_set_bss_mode;
7311ea85
AK
2972
2973 ret = mwifiex_sta_init_cmd(priv, false, false);
f152bdad 2974 if (ret)
8535107a 2975 goto err_sta_init;
7311ea85 2976
57fbcce3 2977 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
a5f39056
YAP
2978 if (adapter->is_hw_11ac_capable)
2979 mwifiex_setup_vht_caps(
57fbcce3 2980 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
d6bffe8b
AP
2981
2982 if (adapter->config_bands & BAND_A)
2983 mwifiex_setup_ht_caps(
57fbcce3 2984 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
d6bffe8b 2985
a5f39056
YAP
2986 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2987 mwifiex_setup_vht_caps(
57fbcce3 2988 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
a5f39056 2989
93a1df48 2990 dev_net_set(dev, wiphy_net(wiphy));
4facc34a 2991 dev->ieee80211_ptr = &priv->wdev;
93a1df48
YAP
2992 dev->ieee80211_ptr->iftype = priv->bss_mode;
2993 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
93a1df48
YAP
2994 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2995
2996 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2997 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2998 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
0d7f53e3 2999 dev->ethtool_ops = &mwifiex_ethtool_ops;
93a1df48
YAP
3000
3001 mdev_priv = netdev_priv(dev);
3002 *((unsigned long *) mdev_priv) = (unsigned long) priv;
3003
93a1df48
YAP
3004 SET_NETDEV_DEV(dev, adapter->dev);
3005
ffdcad05 3006 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
85afb186
AP
3007 WQ_HIGHPRI |
3008 WQ_MEM_RECLAIM |
ffdcad05 3009 WQ_UNBOUND, 1, name);
85afb186 3010 if (!priv->dfs_cac_workqueue) {
8535107a
BN
3011 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
3012 ret = -ENOMEM;
3013 goto err_alloc_cac;
85afb186
AP
3014 }
3015
3016 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
3017
ffdcad05 3018 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
7d652034 3019 WQ_HIGHPRI | WQ_UNBOUND |
ffdcad05 3020 WQ_MEM_RECLAIM, 1, name);
7d652034 3021 if (!priv->dfs_chan_sw_workqueue) {
8535107a
BN
3022 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
3023 ret = -ENOMEM;
3024 goto err_alloc_chsw;
7d652034
AP
3025 }
3026
3027 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
3028 mwifiex_dfs_chan_sw_work_queue);
3029
1abf9ae7 3030 mutex_init(&priv->async_mutex);
93a1df48 3031
8535107a
BN
3032 /* Register network device */
3033 if (register_netdevice(dev)) {
3034 mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
3035 ret = -EFAULT;
3036 goto err_reg_netdev;
3037 }
3038
acebe8c1
ZL
3039 mwifiex_dbg(adapter, INFO,
3040 "info: %s: Marvell 802.11 Adapter\n", dev->name);
93a1df48
YAP
3041
3042#ifdef CONFIG_DEBUG_FS
3043 mwifiex_dev_debugfs_init(priv);
3044#endif
bec568ff 3045
cf052335
AP
3046 switch (type) {
3047 case NL80211_IFTYPE_UNSPECIFIED:
3048 case NL80211_IFTYPE_STATION:
3049 case NL80211_IFTYPE_ADHOC:
3050 adapter->curr_iface_comb.sta_intf++;
3051 break;
3052 case NL80211_IFTYPE_AP:
3053 adapter->curr_iface_comb.uap_intf++;
3054 break;
3055 case NL80211_IFTYPE_P2P_CLIENT:
3056 adapter->curr_iface_comb.p2p_intf++;
3057 break;
3058 default:
8535107a 3059 /* This should be dead code; checked above */
acebe8c1 3060 mwifiex_dbg(adapter, ERROR, "type not supported\n");
cf052335
AP
3061 return ERR_PTR(-EINVAL);
3062 }
3063
4facc34a 3064 return &priv->wdev;
8535107a
BN
3065
3066err_reg_netdev:
3067 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3068 priv->dfs_chan_sw_workqueue = NULL;
3069err_alloc_chsw:
3070 destroy_workqueue(priv->dfs_cac_workqueue);
3071 priv->dfs_cac_workqueue = NULL;
3072err_alloc_cac:
3073 free_netdev(dev);
3074 priv->netdev = NULL;
3075err_sta_init:
3076err_set_bss_mode:
3077err_alloc_netdev:
3078 memset(&priv->wdev, 0, sizeof(priv->wdev));
3079 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
3080 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3081 return ERR_PTR(ret);
93a1df48
YAP
3082}
3083EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
3084
3085/*
3086 * del_virtual_intf: remove the virtual interface determined by dev
3087 */
84efbb84 3088int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
93a1df48 3089{
84efbb84 3090 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
cf052335 3091 struct mwifiex_adapter *adapter = priv->adapter;
a1777327 3092 struct sk_buff *skb, *tmp;
93a1df48
YAP
3093
3094#ifdef CONFIG_DEBUG_FS
3095 mwifiex_dev_debugfs_remove(priv);
3096#endif
3097
0c9b7f22
XH
3098 if (priv->sched_scanning)
3099 priv->sched_scanning = false;
3100
cf052335 3101 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
93a1df48 3102
c44c0403
AK
3103 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
3104 skb_unlink(skb, &priv->bypass_txq);
a1777327 3105 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
c44c0403 3106 }
a1777327 3107
93a1df48
YAP
3108 if (netif_carrier_ok(priv->netdev))
3109 netif_carrier_off(priv->netdev);
3110
84efbb84
JB
3111 if (wdev->netdev->reg_state == NETREG_REGISTERED)
3112 unregister_netdevice(wdev->netdev);
93a1df48 3113
85afb186
AP
3114 if (priv->dfs_cac_workqueue) {
3115 flush_workqueue(priv->dfs_cac_workqueue);
3116 destroy_workqueue(priv->dfs_cac_workqueue);
3117 priv->dfs_cac_workqueue = NULL;
3118 }
3119
7d652034
AP
3120 if (priv->dfs_chan_sw_workqueue) {
3121 flush_workqueue(priv->dfs_chan_sw_workqueue);
3122 destroy_workqueue(priv->dfs_chan_sw_workqueue);
3123 priv->dfs_chan_sw_workqueue = NULL;
3124 }
93a1df48 3125 /* Clear the priv in adapter */
98a4635b 3126 priv->netdev->ieee80211_ptr = NULL;
93a1df48 3127 priv->netdev = NULL;
4facc34a 3128 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
93a1df48
YAP
3129
3130 priv->media_connected = false;
3131
cf052335
AP
3132 switch (priv->bss_mode) {
3133 case NL80211_IFTYPE_UNSPECIFIED:
3134 case NL80211_IFTYPE_STATION:
3135 case NL80211_IFTYPE_ADHOC:
65405c51 3136 adapter->curr_iface_comb.sta_intf--;
cf052335
AP
3137 break;
3138 case NL80211_IFTYPE_AP:
65405c51 3139 adapter->curr_iface_comb.uap_intf--;
cf052335
AP
3140 break;
3141 case NL80211_IFTYPE_P2P_CLIENT:
3142 case NL80211_IFTYPE_P2P_GO:
65405c51 3143 adapter->curr_iface_comb.p2p_intf--;
cf052335
AP
3144 break;
3145 default:
acebe8c1
ZL
3146 mwifiex_dbg(adapter, ERROR,
3147 "del_virtual_intf: type not supported\n");
cf052335
AP
3148 break;
3149 }
3150
93a1df48
YAP
3151 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
3152
cbf6e055
XH
3153 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
3154 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
3155 kfree(priv->hist_data);
3156
93a1df48
YAP
3157 return 0;
3158}
3159EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
3160
7da060c1 3161static bool
0434c464
AK
3162mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
3163 u8 max_byte_seq)
7da060c1
AK
3164{
3165 int j, k, valid_byte_cnt = 0;
3166 bool dont_care_byte = false;
3167
3168 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
3169 for (k = 0; k < 8; k++) {
3170 if (pat->mask[j] & 1 << k) {
3171 memcpy(byte_seq + valid_byte_cnt,
3172 &pat->pattern[j * 8 + k], 1);
3173 valid_byte_cnt++;
3174 if (dont_care_byte)
3175 return false;
3176 } else {
3177 if (valid_byte_cnt)
3178 dont_care_byte = true;
3179 }
3180
c8ac6a8e
XH
3181 /* wildcard bytes record as the offset
3182 * before the valid byte
3183 */
3184 if (!valid_byte_cnt && !dont_care_byte)
3185 pat->pkt_offset++;
3186
0434c464 3187 if (valid_byte_cnt > max_byte_seq)
7da060c1
AK
3188 return false;
3189 }
3190 }
3191
0434c464 3192 byte_seq[max_byte_seq] = valid_byte_cnt;
7da060c1
AK
3193
3194 return true;
3195}
3196
d1e2586f 3197#ifdef CONFIG_PM
b533be18
MH
3198static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
3199 struct mwifiex_mef_entry *mef_entry)
3200{
3201 int i, filt_num = 0, num_ipv4 = 0;
3202 struct in_device *in_dev;
3203 struct in_ifaddr *ifa;
3204 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
3205 struct mwifiex_adapter *adapter = priv->adapter;
3206
3207 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3208 mef_entry->action = MEF_ACTION_AUTO_ARP;
3209
3210 /* Enable ARP offload feature */
3211 memset(ips, 0, sizeof(ips));
3212 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
3213 if (adapter->priv[i]->netdev) {
3214 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
3215 if (!in_dev)
3216 continue;
3217 ifa = in_dev->ifa_list;
3218 if (!ifa || !ifa->ifa_local)
3219 continue;
3220 ips[i] = ifa->ifa_local;
3221 num_ipv4++;
3222 }
3223 }
3224
3225 for (i = 0; i < num_ipv4; i++) {
3226 if (!ips[i])
3227 continue;
3228 mef_entry->filter[filt_num].repeat = 1;
3229 memcpy(mef_entry->filter[filt_num].byte_seq,
3230 (u8 *)&ips[i], sizeof(ips[i]));
3231 mef_entry->filter[filt_num].
3232 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
3233 sizeof(ips[i]);
3234 mef_entry->filter[filt_num].offset = 46;
3235 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3236 if (filt_num) {
3237 mef_entry->filter[filt_num].filt_action =
3238 TYPE_OR;
3239 }
3240 filt_num++;
3241 }
3242
3243 mef_entry->filter[filt_num].repeat = 1;
3244 mef_entry->filter[filt_num].byte_seq[0] = 0x08;
3245 mef_entry->filter[filt_num].byte_seq[1] = 0x06;
3246 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
3247 mef_entry->filter[filt_num].offset = 20;
3248 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3249 mef_entry->filter[filt_num].filt_action = TYPE_AND;
3250}
3251
3252static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
3253 struct mwifiex_ds_mef_cfg *mef_cfg,
3254 struct mwifiex_mef_entry *mef_entry,
3255 struct cfg80211_wowlan *wowlan)
7da060c1 3256{
468133c5 3257 int i, filt_num = 0, ret = 0;
7da060c1 3258 bool first_pat = true;
3f4e854a 3259 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
7da060c1
AK
3260 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3261 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
7da060c1 3262
7da060c1
AK
3263 mef_entry->mode = MEF_MODE_HOST_SLEEP;
3264 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
3265
3266 for (i = 0; i < wowlan->n_patterns; i++) {
3267 memset(byte_seq, 0, sizeof(byte_seq));
3268 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
468133c5
MH
3269 byte_seq,
3270 MWIFIEX_MEF_MAX_BYTESEQ)) {
acebe8c1
ZL
3271 mwifiex_dbg(priv->adapter, ERROR,
3272 "Pattern not supported\n");
7da060c1
AK
3273 return -EOPNOTSUPP;
3274 }
3275
3276 if (!wowlan->patterns[i].pkt_offset) {
3277 if (!(byte_seq[0] & 0x01) &&
3f4e854a 3278 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
b533be18 3279 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
7da060c1
AK
3280 continue;
3281 } else if (is_broadcast_ether_addr(byte_seq)) {
b533be18 3282 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
7da060c1
AK
3283 continue;
3284 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3f4e854a 3285 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
7da060c1 3286 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3f4e854a 3287 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
b533be18 3288 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
7da060c1
AK
3289 continue;
3290 }
3291 }
7da060c1
AK
3292 mef_entry->filter[filt_num].repeat = 1;
3293 mef_entry->filter[filt_num].offset =
468133c5 3294 wowlan->patterns[i].pkt_offset;
7da060c1 3295 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
468133c5 3296 sizeof(byte_seq));
7da060c1
AK
3297 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3298
5323b53d 3299 if (first_pat) {
7da060c1 3300 first_pat = false;
5323b53d 3301 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
3302 } else {
7da060c1 3303 mef_entry->filter[filt_num].filt_action = TYPE_AND;
5323b53d 3304 }
7da060c1
AK
3305
3306 filt_num++;
3307 }
3308
3309 if (wowlan->magic_pkt) {
b533be18 3310 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
7da060c1
AK
3311 mef_entry->filter[filt_num].repeat = 16;
3312 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
468133c5 3313 ETH_ALEN);
3f4e854a 3314 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
468133c5 3315 ETH_ALEN;
09e65f5b 3316 mef_entry->filter[filt_num].offset = 28;
7da060c1
AK
3317 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3318 if (filt_num)
3319 mef_entry->filter[filt_num].filt_action = TYPE_OR;
4dbc13fa
ZY
3320
3321 filt_num++;
3322 mef_entry->filter[filt_num].repeat = 16;
3323 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
468133c5 3324 ETH_ALEN);
4dbc13fa 3325 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
468133c5 3326 ETH_ALEN;
4dbc13fa
ZY
3327 mef_entry->filter[filt_num].offset = 56;
3328 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
3329 mef_entry->filter[filt_num].filt_action = TYPE_OR;
5323b53d 3330 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
7da060c1 3331 }
b533be18
MH
3332 return ret;
3333}
3334
3335static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
3336 struct cfg80211_wowlan *wowlan)
3337{
3338 int ret = 0, num_entries = 1;
3339 struct mwifiex_ds_mef_cfg mef_cfg;
3340 struct mwifiex_mef_entry *mef_entry;
3341
3342 if (wowlan->n_patterns || wowlan->magic_pkt)
3343 num_entries++;
3344
3345 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
3346 if (!mef_entry)
3347 return -ENOMEM;
3348
3349 memset(&mef_cfg, 0, sizeof(mef_cfg));
3350 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
3351 MWIFIEX_CRITERIA_UNICAST;
3352 mef_cfg.num_entries = num_entries;
3353 mef_cfg.mef_entry = mef_entry;
3354
3355 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
3356
722d2668 3357 if (wowlan->n_patterns || wowlan->magic_pkt) {
b533be18
MH
3358 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
3359 &mef_entry[1], wowlan);
722d2668
JL
3360 if (ret)
3361 goto err;
3362 }
7da060c1
AK
3363
3364 if (!mef_cfg.criteria)
3365 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
468133c5
MH
3366 MWIFIEX_CRITERIA_UNICAST |
3367 MWIFIEX_CRITERIA_MULTICAST;
7da060c1 3368
fa0ecbb9 3369 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
b533be18
MH
3370 HostCmd_ACT_GEN_SET, 0,
3371 &mef_cfg, true);
722d2668
JL
3372
3373err:
7da060c1
AK
3374 kfree(mef_entry);
3375 return ret;
3376}
3377
468133c5
MH
3378static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
3379 struct cfg80211_wowlan *wowlan)
3380{
3381 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
8a40084e 3382 struct mwifiex_ds_hs_cfg hs_cfg;
54f00849 3383 int i, ret = 0, retry_num = 10;
5ff46f79 3384 struct mwifiex_private *priv;
322397b2
AK
3385 struct mwifiex_private *sta_priv =
3386 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
5ff46f79 3387
16d25da9 3388 sta_priv->scan_aborting = true;
5ff46f79
AP
3389 for (i = 0; i < adapter->priv_num; i++) {
3390 priv = adapter->priv[i];
3391 mwifiex_abort_cac(priv);
3392 }
3393
3394 mwifiex_cancel_all_pending_cmd(adapter);
468133c5 3395
54f00849
AK
3396 for (i = 0; i < adapter->priv_num; i++) {
3397 priv = adapter->priv[i];
0026b32d 3398 if (priv && priv->netdev) {
54f00849 3399 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
0026b32d
AK
3400 if (netif_carrier_ok(priv->netdev))
3401 netif_carrier_off(priv->netdev);
3402 }
54f00849
AK
3403 }
3404
3405 for (i = 0; i < retry_num; i++) {
3406 if (!mwifiex_wmm_lists_empty(adapter) ||
3407 !mwifiex_bypass_txlist_empty(adapter) ||
3408 !skb_queue_empty(&adapter->tx_data_q))
3409 usleep_range(10000, 15000);
3410 else
3411 break;
3412 }
3413
468133c5 3414 if (!wowlan) {
acebe8c1
ZL
3415 mwifiex_dbg(adapter, ERROR,
3416 "None of the WOWLAN triggers enabled\n");
16d25da9
AK
3417 ret = 0;
3418 goto done;
468133c5
MH
3419 }
3420
322397b2 3421 if (!sta_priv->media_connected && !wowlan->nd_config) {
acebe8c1
ZL
3422 mwifiex_dbg(adapter, ERROR,
3423 "Can not configure WOWLAN in disconnected state\n");
16d25da9
AK
3424 ret = 0;
3425 goto done;
468133c5
MH
3426 }
3427
322397b2 3428 ret = mwifiex_set_mef_filter(sta_priv, wowlan);
b533be18 3429 if (ret) {
acebe8c1 3430 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
16d25da9 3431 goto done;
468133c5
MH
3432 }
3433
7d7f07d8 3434 memset(&hs_cfg, 0, sizeof(hs_cfg));
3435 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
3436
3437 if (wowlan->nd_config) {
3438 mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
3439 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
322397b2 3440 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
7d7f07d8 3441 wowlan->nd_config);
3442 }
3443
8a40084e 3444 if (wowlan->disconnect) {
7d7f07d8 3445 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
322397b2 3446 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
8a40084e
MH
3447 }
3448
7d7f07d8 3449 hs_cfg.is_invoke_hostcmd = false;
3450 hs_cfg.gpio = adapter->hs_cfg.gpio;
3451 hs_cfg.gap = adapter->hs_cfg.gap;
322397b2 3452 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
7d7f07d8 3453 MWIFIEX_SYNC_CMD, &hs_cfg);
16d25da9
AK
3454 if (ret)
3455 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
7d7f07d8 3456
16d25da9
AK
3457done:
3458 sta_priv->scan_aborting = false;
468133c5
MH
3459 return ret;
3460}
3461
7da060c1
AK
3462static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
3463{
8de00f1b 3464 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
54f00849 3465 struct mwifiex_private *priv;
8de00f1b 3466 struct mwifiex_ds_wakeup_reason wakeup_reason;
3467 struct cfg80211_wowlan_wakeup wakeup_report;
3468 int i;
df228862 3469 bool report_wakeup_reason = true;
8de00f1b 3470
54f00849
AK
3471 for (i = 0; i < adapter->priv_num; i++) {
3472 priv = adapter->priv[i];
0026b32d
AK
3473 if (priv && priv->netdev) {
3474 if (!netif_carrier_ok(priv->netdev))
3475 netif_carrier_on(priv->netdev);
54f00849 3476 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
0026b32d 3477 }
54f00849
AK
3478 }
3479
d286af9b
AK
3480 if (!wiphy->wowlan_config)
3481 goto done;
3482
54f00849 3483 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
8de00f1b 3484 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
3485 &wakeup_reason);
3486 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
3487
3488 wakeup_report.pattern_idx = -1;
3489
3490 switch (wakeup_reason.hs_wakeup_reason) {
3491 case NO_HSWAKEUP_REASON:
3492 break;
3493 case BCAST_DATA_MATCHED:
3494 break;
3495 case MCAST_DATA_MATCHED:
3496 break;
3497 case UCAST_DATA_MATCHED:
3498 break;
3499 case MASKTABLE_EVENT_MATCHED:
3500 break;
3501 case NON_MASKABLE_EVENT_MATCHED:
3502 if (wiphy->wowlan_config->disconnect)
3503 wakeup_report.disconnect = true;
3504 if (wiphy->wowlan_config->nd_config)
3505 wakeup_report.net_detect = adapter->nd_info;
3506 break;
3507 case NON_MASKABLE_CONDITION_MATCHED:
3508 break;
3509 case MAGIC_PATTERN_MATCHED:
3510 if (wiphy->wowlan_config->magic_pkt)
3511 wakeup_report.magic_pkt = true;
3512 if (wiphy->wowlan_config->n_patterns)
3513 wakeup_report.pattern_idx = 1;
3514 break;
8fa0a0dc
GB
3515 case GTK_REKEY_FAILURE:
3516 if (wiphy->wowlan_config->gtk_rekey_failure)
3517 wakeup_report.gtk_rekey_failure = true;
3518 break;
8de00f1b 3519 default:
df228862 3520 report_wakeup_reason = false;
8de00f1b 3521 break;
3522 }
3523
df228862 3524 if (report_wakeup_reason)
8de00f1b 3525 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
3526 GFP_KERNEL);
3527
d286af9b 3528done:
8de00f1b 3529 if (adapter->nd_info) {
3530 for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
3531 kfree(adapter->nd_info->matches[i]);
3532 kfree(adapter->nd_info);
3533 adapter->nd_info = NULL;
3534 }
3535
7da060c1
AK
3536 return 0;
3537}
3538
3539static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
3540 bool enabled)
3541{
3542 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3543
3544 device_set_wakeup_enable(adapter->dev, enabled);
3545}
f6b1cbe0
GB
3546
3547static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
3548 struct cfg80211_gtk_rekey_data *data)
3549{
3550 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3551
3552 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
3553 HostCmd_ACT_GEN_SET, 0, data, true);
3554}
3555
7da060c1
AK
3556#endif
3557
562fc5b3
AK
3558static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
3559{
3560 const u8 ipv4_mc_mac[] = {0x33, 0x33};
3561 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
3562 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
3563
3564 if ((byte_seq[0] & 0x01) &&
3565 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
3566 return PACKET_TYPE_UNICAST;
3567 else if (!memcmp(byte_seq, bc_mac, 4))
3568 return PACKET_TYPE_BROADCAST;
3569 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3570 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
3571 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3572 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
3573 return PACKET_TYPE_MULTICAST;
3574
3575 return 0;
3576}
3577
3578static int
3579mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
3580 struct cfg80211_coalesce_rules *crule,
3581 struct mwifiex_coalesce_rule *mrule)
3582{
3583 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
3584 struct filt_field_param *param;
3585 int i;
3586
3587 mrule->max_coalescing_delay = crule->delay;
3588
3589 param = mrule->params;
3590
3591 for (i = 0; i < crule->n_patterns; i++) {
3592 memset(byte_seq, 0, sizeof(byte_seq));
3593 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
3594 byte_seq,
3595 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
acebe8c1
ZL
3596 mwifiex_dbg(priv->adapter, ERROR,
3597 "Pattern not supported\n");
562fc5b3
AK
3598 return -EOPNOTSUPP;
3599 }
3600
3601 if (!crule->patterns[i].pkt_offset) {
3602 u8 pkt_type;
3603
3604 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
3605 if (pkt_type && mrule->pkt_type) {
acebe8c1
ZL
3606 mwifiex_dbg(priv->adapter, ERROR,
3607 "Multiple packet types not allowed\n");
562fc5b3
AK
3608 return -EOPNOTSUPP;
3609 } else if (pkt_type) {
3610 mrule->pkt_type = pkt_type;
3611 continue;
3612 }
3613 }
3614
3615 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
3616 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
3617 else
3618 param->operation = RECV_FILTER_MATCH_TYPE_NE;
3619
3620 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
3621 memcpy(param->operand_byte_stream, byte_seq,
3622 param->operand_len);
3623 param->offset = crule->patterns[i].pkt_offset;
3624 param++;
3625
3626 mrule->num_of_fields++;
3627 }
3628
3629 if (!mrule->pkt_type) {
acebe8c1
ZL
3630 mwifiex_dbg(priv->adapter, ERROR,
3631 "Packet type can not be determined\n");
562fc5b3
AK
3632 return -EOPNOTSUPP;
3633 }
3634
3635 return 0;
3636}
3637
3638static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
3639 struct cfg80211_coalesce *coalesce)
3640{
3641 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3642 int i, ret;
3643 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
3644 struct mwifiex_private *priv =
3645 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
3646
3647 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
3648 if (!coalesce) {
acebe8c1
ZL
3649 mwifiex_dbg(adapter, WARN,
3650 "Disable coalesce and reset all previous rules\n");
fa0ecbb9
BZ
3651 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3652 HostCmd_ACT_GEN_SET, 0,
3653 &coalesce_cfg, true);
562fc5b3
AK
3654 }
3655
3656 coalesce_cfg.num_of_rules = coalesce->n_rules;
3657 for (i = 0; i < coalesce->n_rules; i++) {
3658 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
3659 &coalesce_cfg.rule[i]);
3660 if (ret) {
acebe8c1
ZL
3661 mwifiex_dbg(adapter, ERROR,
3662 "Recheck the patterns provided for rule %d\n",
562fc5b3
AK
3663 i + 1);
3664 return ret;
3665 }
3666 }
3667
fa0ecbb9
BZ
3668 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
3669 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
562fc5b3
AK
3670}
3671
b23bce29
AP
3672/* cfg80211 ops handler for tdls_mgmt.
3673 * Function prepares TDLS action frame packets and forwards them to FW
3674 */
3675static int
3676mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 3677 const u8 *peer, u8 action_code, u8 dialog_token,
df942e7b 3678 u16 status_code, u32 peer_capability,
31fa97c5
AN
3679 bool initiator, const u8 *extra_ies,
3680 size_t extra_ies_len)
b23bce29
AP
3681{
3682 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3683 int ret;
3684
3685 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3686 return -ENOTSUPP;
3687
3688 /* make sure we are in station mode and connected */
3689 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3690 return -ENOTSUPP;
3691
3692 switch (action_code) {
3693 case WLAN_TDLS_SETUP_REQUEST:
acebe8c1
ZL
3694 mwifiex_dbg(priv->adapter, MSG,
3695 "Send TDLS Setup Request to %pM status_code=%d\n",
3696 peer, status_code);
9927baa3 3697 mwifiex_add_auto_tdls_peer(priv, peer);
b23bce29
AP
3698 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3699 dialog_token, status_code,
3700 extra_ies, extra_ies_len);
3701 break;
3702 case WLAN_TDLS_SETUP_RESPONSE:
9927baa3 3703 mwifiex_add_auto_tdls_peer(priv, peer);
acebe8c1
ZL
3704 mwifiex_dbg(priv->adapter, MSG,
3705 "Send TDLS Setup Response to %pM status_code=%d\n",
3706 peer, status_code);
b23bce29
AP
3707 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3708 dialog_token, status_code,
3709 extra_ies, extra_ies_len);
3710 break;
3711 case WLAN_TDLS_SETUP_CONFIRM:
acebe8c1
ZL
3712 mwifiex_dbg(priv->adapter, MSG,
3713 "Send TDLS Confirm to %pM status_code=%d\n", peer,
3714 status_code);
b23bce29
AP
3715 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3716 dialog_token, status_code,
3717 extra_ies, extra_ies_len);
3718 break;
3719 case WLAN_TDLS_TEARDOWN:
acebe8c1
ZL
3720 mwifiex_dbg(priv->adapter, MSG,
3721 "Send TDLS Tear down to %pM\n", peer);
b23bce29
AP
3722 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3723 dialog_token, status_code,
3724 extra_ies, extra_ies_len);
3725 break;
3726 case WLAN_TDLS_DISCOVERY_REQUEST:
acebe8c1
ZL
3727 mwifiex_dbg(priv->adapter, MSG,
3728 "Send TDLS Discovery Request to %pM\n", peer);
b23bce29
AP
3729 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
3730 dialog_token, status_code,
3731 extra_ies, extra_ies_len);
3732 break;
3733 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
acebe8c1
ZL
3734 mwifiex_dbg(priv->adapter, MSG,
3735 "Send TDLS Discovery Response to %pM\n", peer);
b23bce29
AP
3736 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
3737 dialog_token, status_code,
3738 extra_ies, extra_ies_len);
3739 break;
3740 default:
acebe8c1
ZL
3741 mwifiex_dbg(priv->adapter, ERROR,
3742 "Unknown TDLS mgmt/action frame %pM\n", peer);
b23bce29
AP
3743 ret = -EINVAL;
3744 break;
3745 }
3746
3747 return ret;
3748}
3749
429d90d2
AP
3750static int
3751mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 3752 const u8 *peer, enum nl80211_tdls_operation action)
429d90d2
AP
3753{
3754 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3755
3756 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
3757 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
3758 return -ENOTSUPP;
3759
3760 /* make sure we are in station mode and connected */
3761 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
3762 return -ENOTSUPP;
3763
acebe8c1
ZL
3764 mwifiex_dbg(priv->adapter, MSG,
3765 "TDLS peer=%pM, oper=%d\n", peer, action);
429d90d2
AP
3766
3767 switch (action) {
3768 case NL80211_TDLS_ENABLE_LINK:
3769 action = MWIFIEX_TDLS_ENABLE_LINK;
3770 break;
3771 case NL80211_TDLS_DISABLE_LINK:
3772 action = MWIFIEX_TDLS_DISABLE_LINK;
3773 break;
3774 case NL80211_TDLS_TEARDOWN:
3775 /* shouldn't happen!*/
acebe8c1
ZL
3776 mwifiex_dbg(priv->adapter, ERROR,
3777 "tdls_oper: teardown from driver not supported\n");
429d90d2
AP
3778 return -EINVAL;
3779 case NL80211_TDLS_SETUP:
3780 /* shouldn't happen!*/
acebe8c1
ZL
3781 mwifiex_dbg(priv->adapter, ERROR,
3782 "tdls_oper: setup from driver not supported\n");
429d90d2
AP
3783 return -EINVAL;
3784 case NL80211_TDLS_DISCOVERY_REQ:
3785 /* shouldn't happen!*/
acebe8c1
ZL
3786 mwifiex_dbg(priv->adapter, ERROR,
3787 "tdls_oper: discovery from driver not supported\n");
429d90d2
AP
3788 return -EINVAL;
3789 default:
acebe8c1
ZL
3790 mwifiex_dbg(priv->adapter, ERROR,
3791 "tdls_oper: operation not supported\n");
429d90d2
AP
3792 return -ENOTSUPP;
3793 }
3794
3795 return mwifiex_tdls_oper(priv, peer, action);
3796}
3797
b0497597
XH
3798static int
3799mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
3800 const u8 *addr, u8 oper_class,
3801 struct cfg80211_chan_def *chandef)
3802{
3803 struct mwifiex_sta_node *sta_ptr;
3804 unsigned long flags;
3805 u16 chan;
3806 u8 second_chan_offset, band;
3807 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3808
3809 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3810 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3811 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3812
3813 if (!sta_ptr) {
3814 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3815 __func__, addr);
3816 return -ENOENT;
3817 }
3818
3819 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
3820 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
3821 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
3822 return -ENOENT;
3823 }
3824
3825 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3826 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
3827 wiphy_err(wiphy, "channel switch is running, abort request\n");
3828 return -EALREADY;
3829 }
3830
3831 chan = chandef->chan->hw_value;
3832 second_chan_offset = mwifiex_get_sec_chan_offset(chan);
3833 band = chandef->chan->band;
3834 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
3835
3836 return 0;
3837}
3838
3839static void
3840mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
3841 struct net_device *dev,
3842 const u8 *addr)
3843{
3844 struct mwifiex_sta_node *sta_ptr;
3845 unsigned long flags;
3846 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3847
3848 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
3849 sta_ptr = mwifiex_get_sta_entry(priv, addr);
3850 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
3851
3852 if (!sta_ptr) {
3853 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
3854 __func__, addr);
3855 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
3856 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
3857 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
3858 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
3859 addr);
3860 } else
3861 mwifiex_stop_tdls_cs(priv, addr);
3862}
3863
e48e0de0 3864static int
3b3a0162
JB
3865mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3866 const u8 *mac, struct station_parameters *params)
e48e0de0
AP
3867{
3868 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3869
3870 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3871 return -ENOTSUPP;
3872
3873 /* make sure we are in station mode and connected */
3874 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
3875 return -ENOTSUPP;
3876
3877 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
3878}
3879
7d652034
AP
3880static int
3881mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3882 struct cfg80211_csa_settings *params)
3883{
3884 struct ieee_types_header *chsw_ie;
3885 struct ieee80211_channel_sw_ie *channel_sw;
3886 int chsw_msec;
3887 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3888
3889 if (priv->adapter->scan_processing) {
acebe8c1
ZL
3890 mwifiex_dbg(priv->adapter, ERROR,
3891 "radar detection: scan in process...\n");
7d652034
AP
3892 return -EBUSY;
3893 }
3894
3895 if (priv->wdev.cac_started)
3896 return -EBUSY;
3897
3898 if (cfg80211_chandef_identical(&params->chandef,
3899 &priv->dfs_chandef))
3900 return -EINVAL;
3901
3902 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
3903 params->beacon_csa.tail,
3904 params->beacon_csa.tail_len);
3905 if (!chsw_ie) {
acebe8c1
ZL
3906 mwifiex_dbg(priv->adapter, ERROR,
3907 "Could not parse channel switch announcement IE\n");
7d652034
AP
3908 return -EINVAL;
3909 }
3910
3911 channel_sw = (void *)(chsw_ie + 1);
3912 if (channel_sw->mode) {
3913 if (netif_carrier_ok(priv->netdev))
3914 netif_carrier_off(priv->netdev);
3915 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
3916 }
3917
3918 if (mwifiex_del_mgmt_ies(priv))
acebe8c1
ZL
3919 mwifiex_dbg(priv->adapter, ERROR,
3920 "Failed to delete mgmt IEs!\n");
7d652034
AP
3921
3922 if (mwifiex_set_mgmt_ies(priv, &params->beacon_csa)) {
acebe8c1
ZL
3923 mwifiex_dbg(priv->adapter, ERROR,
3924 "%s: setting mgmt ies failed\n", __func__);
7d652034
AP
3925 return -EFAULT;
3926 }
3927
3928 memcpy(&priv->dfs_chandef, &params->chandef, sizeof(priv->dfs_chandef));
3929 memcpy(&priv->beacon_after, &params->beacon_after,
3930 sizeof(priv->beacon_after));
3931
3932 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
3933 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
3934 msecs_to_jiffies(chsw_msec));
3935 return 0;
3936}
3937
7ee38bf4
XH
3938static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
3939 struct wireless_dev *wdev,
3940 struct cfg80211_chan_def *chandef)
3941{
3942 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3943 struct mwifiex_bssdescriptor *curr_bss;
3944 struct ieee80211_channel *chan;
3945 u8 second_chan_offset;
3946 enum nl80211_channel_type chan_type;
57fbcce3 3947 enum nl80211_band band;
7ee38bf4
XH
3948 int freq;
3949 int ret = -ENODATA;
3950
3951 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
3952 cfg80211_chandef_valid(&priv->bss_chandef)) {
3953 *chandef = priv->bss_chandef;
3954 ret = 0;
3955 } else if (priv->media_connected) {
3956 curr_bss = &priv->curr_bss_params.bss_descriptor;
3957 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
3958 freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
3959 chan = ieee80211_get_channel(wiphy, freq);
3960
44ca509c
NK
3961 if (priv->ht_param_present) {
3962 second_chan_offset = priv->assoc_resp_ht_param &
7ee38bf4
XH
3963 IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
3964 chan_type = mwifiex_sec_chan_offset_to_chan_type
3965 (second_chan_offset);
3966 cfg80211_chandef_create(chandef, chan, chan_type);
3967 } else {
3968 cfg80211_chandef_create(chandef, chan,
3969 NL80211_CHAN_NO_HT);
3970 }
3971 ret = 0;
3972 }
3973
3974 return ret;
3975}
3976
3935ccc1
XH
3977#ifdef CONFIG_NL80211_TESTMODE
3978
3979enum mwifiex_tm_attr {
3980 __MWIFIEX_TM_ATTR_INVALID = 0,
3981 MWIFIEX_TM_ATTR_CMD = 1,
3982 MWIFIEX_TM_ATTR_DATA = 2,
3983
3984 /* keep last */
3985 __MWIFIEX_TM_ATTR_AFTER_LAST,
3986 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
3987};
3988
3989static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
3990 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
3991 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
3992 .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
3993};
3994
3995enum mwifiex_tm_command {
3996 MWIFIEX_TM_CMD_HOSTCMD = 0,
3997};
3998
3999static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
4000 void *data, int len)
4001{
4002 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4003 struct mwifiex_ds_misc_cmd *hostcmd;
4004 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
3935ccc1
XH
4005 struct sk_buff *skb;
4006 int err;
4007
4008 if (!priv)
4009 return -EINVAL;
3935ccc1 4010
fceb6435
JB
4011 err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len, mwifiex_tm_policy,
4012 NULL);
3935ccc1
XH
4013 if (err)
4014 return err;
4015
4016 if (!tb[MWIFIEX_TM_ATTR_CMD])
4017 return -EINVAL;
4018
4019 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
4020 case MWIFIEX_TM_CMD_HOSTCMD:
4021 if (!tb[MWIFIEX_TM_ATTR_DATA])
4022 return -EINVAL;
4023
4024 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
4025 if (!hostcmd)
4026 return -ENOMEM;
4027
4028 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
4029 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
4030 hostcmd->len);
4031
4032 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
4033 dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
4034 return -EFAULT;
4035 }
4036
4037 /* process hostcmd response*/
4038 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
4039 if (!skb)
4040 return -ENOMEM;
4041 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
4042 hostcmd->len, hostcmd->cmd);
4043 if (err) {
4044 kfree_skb(skb);
4045 return -EMSGSIZE;
4046 }
4047
4048 err = cfg80211_testmode_reply(skb);
4049 kfree(hostcmd);
4050 return err;
4051 default:
4052 return -EOPNOTSUPP;
4053 }
4054}
4055#endif
4056
85afb186
AP
4057static int
4058mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
4059 struct net_device *dev,
4060 struct cfg80211_chan_def *chandef,
4061 u32 cac_time_ms)
4062{
4063 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4064 struct mwifiex_radar_params radar_params;
4065
4066 if (priv->adapter->scan_processing) {
acebe8c1
ZL
4067 mwifiex_dbg(priv->adapter, ERROR,
4068 "radar detection: scan already in process...\n");
85afb186
AP
4069 return -EBUSY;
4070 }
4071
cf075eac 4072 if (!mwifiex_is_11h_active(priv)) {
acebe8c1
ZL
4073 mwifiex_dbg(priv->adapter, INFO,
4074 "Enable 11h extensions in FW\n");
cf075eac 4075 if (mwifiex_11h_activate(priv, true)) {
acebe8c1
ZL
4076 mwifiex_dbg(priv->adapter, ERROR,
4077 "Failed to activate 11h extensions!!");
cf075eac
AP
4078 return -1;
4079 }
4080 priv->state_11h.is_11h_active = true;
4081 }
4082
85afb186
AP
4083 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
4084 radar_params.chandef = chandef;
4085 radar_params.cac_time_ms = cac_time_ms;
4086
4087 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
4088
4089 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
4090 HostCmd_ACT_GEN_SET, 0, &radar_params, true))
4091 return -1;
4092
4093 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
4094 msecs_to_jiffies(cac_time_ms));
4095 return 0;
4096}
4097
1f4dfd8a 4098static int
3b3a0162
JB
4099mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
4100 const u8 *mac,
4101 struct station_parameters *params)
1f4dfd8a
AP
4102{
4103 int ret;
4104 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4105
4106 /* we support change_station handler only for TDLS peers*/
4107 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4108 return -ENOTSUPP;
4109
4110 /* make sure we are in station mode and connected */
4111 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
4112 return -ENOTSUPP;
4113
4114 priv->sta_params = params;
4115
4116 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
4117 priv->sta_params = NULL;
4118
4119 return ret;
4120}
4121
5e6e3a92
BZ
4122/* station cfg80211 operations */
4123static struct cfg80211_ops mwifiex_cfg80211_ops = {
93a1df48
YAP
4124 .add_virtual_intf = mwifiex_add_virtual_intf,
4125 .del_virtual_intf = mwifiex_del_virtual_intf,
5e6e3a92
BZ
4126 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
4127 .scan = mwifiex_cfg80211_scan,
4128 .connect = mwifiex_cfg80211_connect,
4129 .disconnect = mwifiex_cfg80211_disconnect,
4130 .get_station = mwifiex_cfg80211_get_station,
f85aae6b 4131 .dump_station = mwifiex_cfg80211_dump_station,
6bc6c49f 4132 .dump_survey = mwifiex_cfg80211_dump_survey,
5e6e3a92 4133 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
5e6e3a92
BZ
4134 .join_ibss = mwifiex_cfg80211_join_ibss,
4135 .leave_ibss = mwifiex_cfg80211_leave_ibss,
4136 .add_key = mwifiex_cfg80211_add_key,
4137 .del_key = mwifiex_cfg80211_del_key,
89951db2 4138 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
e39faa73 4139 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
3cec6870 4140 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
7feb4c48
SP
4141 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
4142 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
5e6e3a92
BZ
4143 .set_default_key = mwifiex_cfg80211_set_default_key,
4144 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
4145 .set_tx_power = mwifiex_cfg80211_set_tx_power,
7d54baca 4146 .get_tx_power = mwifiex_cfg80211_get_tx_power,
5d82c53a 4147 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
12190c5d
AP
4148 .start_ap = mwifiex_cfg80211_start_ap,
4149 .stop_ap = mwifiex_cfg80211_stop_ap,
5370c836 4150 .change_beacon = mwifiex_cfg80211_change_beacon,
fa444bf8 4151 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
8a279d5b 4152 .set_antenna = mwifiex_cfg80211_set_antenna,
3ee71285 4153 .get_antenna = mwifiex_cfg80211_get_antenna,
0f9e9b8b 4154 .del_station = mwifiex_cfg80211_del_station,
0c9b7f22
XH
4155 .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
4156 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
7da060c1
AK
4157#ifdef CONFIG_PM
4158 .suspend = mwifiex_cfg80211_suspend,
4159 .resume = mwifiex_cfg80211_resume,
4160 .set_wakeup = mwifiex_cfg80211_set_wakeup,
f6b1cbe0 4161 .set_rekey_data = mwifiex_set_rekey_data,
7da060c1 4162#endif
d1e2586f 4163 .set_coalesce = mwifiex_cfg80211_set_coalesce,
b23bce29 4164 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
429d90d2 4165 .tdls_oper = mwifiex_cfg80211_tdls_oper,
b0497597
XH
4166 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
4167 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
e48e0de0 4168 .add_station = mwifiex_cfg80211_add_station,
1f4dfd8a 4169 .change_station = mwifiex_cfg80211_change_station,
3935ccc1 4170 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
7ee38bf4 4171 .get_channel = mwifiex_cfg80211_get_channel,
85afb186 4172 .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
7d652034 4173 .channel_switch = mwifiex_cfg80211_channel_switch,
5e6e3a92
BZ
4174};
4175
964dc9e2
JB
4176#ifdef CONFIG_PM
4177static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
7d7f07d8 4178 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
8fa0a0dc
GB
4179 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
4180 WIPHY_WOWLAN_GTK_REKEY_FAILURE,
3f4e854a 4181 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
964dc9e2
JB
4182 .pattern_min_len = 1,
4183 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4184 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
7d7f07d8 4185 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
964dc9e2
JB
4186};
4187#endif
4188
3c68ef5b
AP
4189static bool mwifiex_is_valid_alpha2(const char *alpha2)
4190{
4191 if (!alpha2 || strlen(alpha2) != 2)
4192 return false;
4193
4194 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
4195 return true;
4196
4197 return false;
4198}
4199
562fc5b3
AK
4200static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
4201 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
4202 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
4203 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
4204 .pattern_min_len = 1,
4205 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
4206 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
4207};
4208
bf354433
AP
4209int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
4210{
4211 u32 n_channels_bg, n_channels_a = 0;
4212
4213 n_channels_bg = mwifiex_band_2ghz.n_channels;
4214
4215 if (adapter->config_bands & BAND_A)
4216 n_channels_a = mwifiex_band_5ghz.n_channels;
4217
0a5aa6a2 4218 adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
bf354433
AP
4219 adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
4220 adapter->num_in_chan_stats);
4221
4222 if (!adapter->chan_stats)
4223 return -ENOMEM;
4224
4225 return 0;
4226}
4227
5e6e3a92
BZ
4228/*
4229 * This function registers the device with CFG802.11 subsystem.
4230 *
4231 * The function creates the wireless device/wiphy, populates it with
4232 * default parameters and handler function pointers, and finally
4233 * registers the device.
4234 */
d6bffe8b
AP
4235
4236int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
5e6e3a92 4237{
270e58e8
YAP
4238 int ret;
4239 void *wdev_priv;
d6bffe8b
AP
4240 struct wiphy *wiphy;
4241 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
9e04a7c6 4242 u8 *country_code;
f862bfd1 4243 u32 thr, retry;
5e6e3a92 4244
d6bffe8b
AP
4245 /* create a new wiphy for use with cfg80211 */
4246 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
4247 sizeof(struct mwifiex_adapter *));
4248 if (!wiphy) {
acebe8c1
ZL
4249 mwifiex_dbg(adapter, ERROR,
4250 "%s: creating new wiphy\n", __func__);
5e6e3a92
BZ
4251 return -ENOMEM;
4252 }
d6bffe8b
AP
4253 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4254 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
83719be8 4255 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
7feb4c48 4256 wiphy->max_remain_on_channel_duration = 5000;
d6bffe8b
AP
4257 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4258 BIT(NL80211_IFTYPE_ADHOC) |
197f4a2e
SP
4259 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4260 BIT(NL80211_IFTYPE_P2P_GO) |
d6bffe8b
AP
4261 BIT(NL80211_IFTYPE_AP);
4262
57fbcce3 4263 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
d6bffe8b 4264 if (adapter->config_bands & BAND_A)
57fbcce3 4265 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
d6bffe8b 4266 else
57fbcce3 4267 wiphy->bands[NL80211_BAND_5GHZ] = NULL;
5e6e3a92 4268
de9e9932 4269 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
cc7359b5
AP
4270 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
4271 else if (adapter->is_hw_11ac_capable)
4272 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
de9e9932
AP
4273 else
4274 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
cd8440da
AP
4275 wiphy->n_iface_combinations = 1;
4276
5e6e3a92 4277 /* Initialize cipher suits */
d6bffe8b
AP
4278 wiphy->cipher_suites = mwifiex_cipher_suites;
4279 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
5e6e3a92 4280
72539799
AK
4281 if (adapter->regd) {
4282 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
4283 REGULATORY_DISABLE_BEACON_HINTS |
947d3152 4284 REGULATORY_COUNTRY_IE_IGNORE;
72539799
AK
4285 wiphy_apply_custom_regulatory(wiphy, adapter->regd);
4286 }
947d3152 4287
8d05eb22 4288 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
d6bffe8b 4289 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2dd2bd6b 4290 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
cc0ba0d5 4291 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
54428c57 4292 WIPHY_FLAG_AP_UAPSD |
7d652034 4293 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
c2b6680f
AP
4294 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
4295 WIPHY_FLAG_PS_ON_BY_DEFAULT;
b23bce29
AP
4296
4297 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4298 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4299 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
4300
7da060c1 4301#ifdef CONFIG_PM
964dc9e2 4302 wiphy->wowlan = &mwifiex_wowlan_support;
7da060c1
AK
4303#endif
4304
562fc5b3
AK
4305 wiphy->coalesce = &mwifiex_coalesce_support;
4306
2dd2bd6b 4307 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
e39faa73
SP
4308 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4309 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5e6e3a92 4310
ca986ad9 4311 wiphy->max_sched_scan_reqs = 1;
0c9b7f22
XH
4312 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
4313 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
4314 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
4315
8a279d5b
AK
4316 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
4317 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
5e6e3a92 4318
b292219f 4319 wiphy->features |= NL80211_FEATURE_HT_IBSS |
e45a8419 4320 NL80211_FEATURE_INACTIVITY_TIMER |
d9f5725f 4321 NL80211_FEATURE_LOW_PRIORITY_SCAN |
c2a8f0ff
GB
4322 NL80211_FEATURE_NEED_OBSS_SCAN |
4323 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
4324 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
4325 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
05910f4a 4326
b0497597
XH
4327 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
4328 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
4329
808bbebc
AK
4330 if (adapter->fw_api_ver == MWIFIEX_FW_V15)
4331 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
4332
b5abcf02 4333 /* Reserve space for mwifiex specific private data for BSS */
d6bffe8b 4334 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
5116f3ce 4335
d6bffe8b 4336 wiphy->reg_notifier = mwifiex_reg_notifier;
5e6e3a92 4337
67fdf39e 4338 /* Set struct mwifiex_adapter pointer in wiphy_priv */
d6bffe8b 4339 wdev_priv = wiphy_priv(wiphy);
67fdf39e 4340 *(unsigned long *)wdev_priv = (unsigned long)adapter;
5e6e3a92 4341
2c208890 4342 set_wiphy_dev(wiphy, priv->adapter->dev);
a7b21165 4343
d6bffe8b 4344 ret = wiphy_register(wiphy);
5e6e3a92 4345 if (ret < 0) {
acebe8c1
ZL
4346 mwifiex_dbg(adapter, ERROR,
4347 "%s: wiphy_register failed: %d\n", __func__, ret);
d6bffe8b 4348 wiphy_free(wiphy);
5e6e3a92 4349 return ret;
5e6e3a92 4350 }
3c68ef5b 4351
72539799
AK
4352 if (!adapter->regd) {
4353 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
4354 mwifiex_dbg(adapter, INFO,
4355 "driver hint alpha2: %2.2s\n", reg_alpha2);
4356 regulatory_hint(wiphy, reg_alpha2);
658cb592 4357 } else {
72539799
AK
4358 if (adapter->region_code == 0x00) {
4359 mwifiex_dbg(adapter, WARN,
4360 "Ignore world regulatory domain\n");
4361 } else {
4362 wiphy->regulatory_flags |=
4363 REGULATORY_DISABLE_BEACON_HINTS |
4364 REGULATORY_COUNTRY_IE_IGNORE;
4365 country_code =
4366 mwifiex_11d_code_2_region(
4367 adapter->region_code);
4368 if (country_code &&
4369 regulatory_hint(wiphy, country_code))
4370 mwifiex_dbg(priv->adapter, ERROR,
4371 "regulatory_hint() failed\n");
4372 }
658cb592 4373 }
3c68ef5b 4374 }
5e6e3a92 4375
fa0ecbb9
BZ
4376 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4377 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
f862bfd1 4378 wiphy->frag_threshold = thr;
fa0ecbb9
BZ
4379 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4380 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
f862bfd1 4381 wiphy->rts_threshold = thr;
fa0ecbb9
BZ
4382 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4383 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
f862bfd1 4384 wiphy->retry_short = (u8) retry;
fa0ecbb9
BZ
4385 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4386 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
f862bfd1
UR
4387 wiphy->retry_long = (u8) retry;
4388
d6bffe8b 4389 adapter->wiphy = wiphy;
5e6e3a92
BZ
4390 return ret;
4391}