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