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