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