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