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