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