mwifiex: support wowlan magic-packet encapsulated as UDP packet
[deliverable/linux.git] / drivers / net / wireless / mwifiex / cfg80211.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: CFG80211
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "cfg80211.h"
21#include "main.h"
22
3c68ef5b
AP
23static char *reg_alpha2;
24module_param(reg_alpha2, charp, 0);
25
cd8440da
AP
26static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
27 {
a4df8f56
AP
28 .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
29 BIT(NL80211_IFTYPE_P2P_GO) |
30 BIT(NL80211_IFTYPE_P2P_CLIENT),
cd8440da
AP
31 },
32 {
33 .max = 1, .types = BIT(NL80211_IFTYPE_AP),
34 },
35};
36
37static const struct ieee80211_iface_combination mwifiex_iface_comb_ap_sta = {
38 .limits = mwifiex_ap_sta_limits,
39 .num_different_channels = 1,
40 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
41 .max_interfaces = MWIFIEX_MAX_BSS_NUM,
42 .beacon_int_infra_match = true,
43};
44
5e6e3a92
BZ
45/*
46 * This function maps the nl802.11 channel type into driver channel type.
47 *
48 * The mapping is as follows -
21c3ba34
AK
49 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
50 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
51 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
52 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
53 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
5e6e3a92 54 */
7feb4c48 55u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
5e6e3a92 56{
05910f4a 57 switch (chan_type) {
5e6e3a92
BZ
58 case NL80211_CHAN_NO_HT:
59 case NL80211_CHAN_HT20:
21c3ba34 60 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 61 case NL80211_CHAN_HT40PLUS:
21c3ba34 62 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
5e6e3a92 63 case NL80211_CHAN_HT40MINUS:
21c3ba34 64 return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
5e6e3a92 65 default:
21c3ba34 66 return IEEE80211_HT_PARAM_CHA_SEC_NONE;
5e6e3a92 67 }
5e6e3a92
BZ
68}
69
5e6e3a92
BZ
70/*
71 * This function checks whether WEP is set.
72 */
73static int
74mwifiex_is_alg_wep(u32 cipher)
75{
5e6e3a92 76 switch (cipher) {
2be50b8d
YAP
77 case WLAN_CIPHER_SUITE_WEP40:
78 case WLAN_CIPHER_SUITE_WEP104:
270e58e8 79 return 1;
5e6e3a92 80 default:
5e6e3a92
BZ
81 break;
82 }
270e58e8
YAP
83
84 return 0;
5e6e3a92
BZ
85}
86
5e6e3a92
BZ
87/*
88 * This function retrieves the private structure from kernel wiphy structure.
89 */
67fdf39e 90static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
5e6e3a92
BZ
91{
92 return (void *) (*(unsigned long *) wiphy_priv(wiphy));
93}
94
95/*
96 * CFG802.11 operation handler to delete a network key.
97 */
98static int
99mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
100 u8 key_index, bool pairwise, const u8 *mac_addr)
101{
f540f9f3 102 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
75edd2c6
AP
103 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
104 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 105
53b11231 106 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
5e6e3a92
BZ
107 wiphy_err(wiphy, "deleting the crypto keys\n");
108 return -EFAULT;
109 }
110
111 wiphy_dbg(wiphy, "info: crypto keys deleted\n");
112 return 0;
113}
114
e39faa73
SP
115/*
116 * This function forms an skb for management frame.
117 */
118static int
119mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
120{
121 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
122 u16 pkt_len;
123 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
124 struct timeval tv;
125
126 pkt_len = len + ETH_ALEN;
127
128 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
129 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
130 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
131
132 memcpy(skb_push(skb, sizeof(tx_control)),
133 &tx_control, sizeof(tx_control));
134
135 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
136
137 /* Add packet data and address4 */
138 memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
139 sizeof(struct ieee80211_hdr_3addr));
140 memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
141 memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
142 buf + sizeof(struct ieee80211_hdr_3addr),
143 len - sizeof(struct ieee80211_hdr_3addr));
144
145 skb->priority = LOW_PRIO_TID;
146 do_gettimeofday(&tv);
147 skb->tstamp = timeval_to_ktime(tv);
148
149 return 0;
150}
151
152/*
153 * CFG802.11 operation handler to transmit a management frame.
154 */
155static int
156mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
b176e629 157 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
e39faa73 158{
b176e629
AO
159 const u8 *buf = params->buf;
160 size_t len = params->len;
e39faa73
SP
161 struct sk_buff *skb;
162 u16 pkt_len;
163 const struct ieee80211_mgmt *mgmt;
231d83e2 164 struct mwifiex_txinfo *tx_info;
e39faa73
SP
165 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
166
167 if (!buf || !len) {
168 wiphy_err(wiphy, "invalid buffer and length\n");
169 return -EFAULT;
170 }
171
172 mgmt = (const struct ieee80211_mgmt *)buf;
173 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
174 ieee80211_is_probe_resp(mgmt->frame_control)) {
175 /* Since we support offload probe resp, we need to skip probe
176 * resp in AP or GO mode */
177 wiphy_dbg(wiphy,
178 "info: skip to send probe resp in AP or GO mode\n");
179 return 0;
180 }
181
182 pkt_len = len + ETH_ALEN;
183 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
184 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
185 pkt_len + sizeof(pkt_len));
186
187 if (!skb) {
188 wiphy_err(wiphy, "allocate skb failed for management frame\n");
189 return -ENOMEM;
190 }
191
231d83e2
HY
192 tx_info = MWIFIEX_SKB_TXCB(skb);
193 tx_info->bss_num = priv->bss_num;
194 tx_info->bss_type = priv->bss_type;
a1ed4849 195 tx_info->pkt_len = pkt_len;
231d83e2 196
e39faa73
SP
197 mwifiex_form_mgmt_frame(skb, buf, len);
198 mwifiex_queue_tx_pkt(priv, skb);
199
e00adf39 200 *cookie = prandom_u32() | 1;
e39faa73
SP
201 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, GFP_ATOMIC);
202
203 wiphy_dbg(wiphy, "info: management frame transmitted\n");
204 return 0;
205}
206
3cec6870
SP
207/*
208 * CFG802.11 operation handler to register a mgmt frame.
209 */
210static void
211mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
212 struct wireless_dev *wdev,
213 u16 frame_type, bool reg)
214{
215 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
4481b2db 216 u32 mask;
3cec6870
SP
217
218 if (reg)
4481b2db 219 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
3cec6870 220 else
4481b2db
SP
221 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
222
223 if (mask != priv->mgmt_frame_mask) {
224 priv->mgmt_frame_mask = mask;
fa0ecbb9
BZ
225 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
226 HostCmd_ACT_GEN_SET, 0,
227 &priv->mgmt_frame_mask, false);
4481b2db
SP
228 wiphy_dbg(wiphy, "info: mgmt frame registered\n");
229 }
3cec6870
SP
230}
231
7feb4c48
SP
232/*
233 * CFG802.11 operation handler to remain on channel.
234 */
235static int
236mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
237 struct wireless_dev *wdev,
238 struct ieee80211_channel *chan,
7feb4c48
SP
239 unsigned int duration, u64 *cookie)
240{
241 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
242 int ret;
243
244 if (!chan || !cookie) {
245 wiphy_err(wiphy, "Invalid parameter for ROC\n");
246 return -EINVAL;
247 }
248
249 if (priv->roc_cfg.cookie) {
250 wiphy_dbg(wiphy, "info: ongoing ROC, cookie = 0x%llu\n",
251 priv->roc_cfg.cookie);
252 return -EBUSY;
253 }
254
255 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
42d97a59 256 duration);
7feb4c48
SP
257
258 if (!ret) {
e00adf39 259 *cookie = prandom_u32() | 1;
7feb4c48
SP
260 priv->roc_cfg.cookie = *cookie;
261 priv->roc_cfg.chan = *chan;
7feb4c48 262
42d97a59 263 cfg80211_ready_on_channel(wdev, *cookie, chan,
7feb4c48
SP
264 duration, GFP_ATOMIC);
265
266 wiphy_dbg(wiphy, "info: ROC, cookie = 0x%llx\n", *cookie);
267 }
268
269 return ret;
270}
271
272/*
273 * CFG802.11 operation handler to cancel remain on channel.
274 */
275static int
276mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
277 struct wireless_dev *wdev, u64 cookie)
278{
279 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
280 int ret;
281
282 if (cookie != priv->roc_cfg.cookie)
283 return -ENOENT;
284
285 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
42d97a59 286 &priv->roc_cfg.chan, 0);
7feb4c48
SP
287
288 if (!ret) {
289 cfg80211_remain_on_channel_expired(wdev, cookie,
290 &priv->roc_cfg.chan,
7feb4c48
SP
291 GFP_ATOMIC);
292
293 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
294
295 wiphy_dbg(wiphy, "info: cancel ROC, cookie = 0x%llx\n", cookie);
296 }
297
298 return ret;
299}
300
5e6e3a92
BZ
301/*
302 * CFG802.11 operation handler to set Tx power.
303 */
304static int
305mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
c8442118 306 struct wireless_dev *wdev,
5e6e3a92 307 enum nl80211_tx_power_setting type,
742c29fd 308 int mbm)
5e6e3a92 309{
67fdf39e
AP
310 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
311 struct mwifiex_private *priv;
600f5d90 312 struct mwifiex_power_cfg power_cfg;
742c29fd 313 int dbm = MBM_TO_DBM(mbm);
5e6e3a92 314
600f5d90
AK
315 if (type == NL80211_TX_POWER_FIXED) {
316 power_cfg.is_power_auto = 0;
317 power_cfg.power_level = dbm;
318 } else {
319 power_cfg.is_power_auto = 1;
320 }
321
67fdf39e
AP
322 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
323
636c4598 324 return mwifiex_set_tx_power(priv, &power_cfg);
5e6e3a92
BZ
325}
326
327/*
328 * CFG802.11 operation handler to set Power Save option.
329 *
330 * The timeout value, if provided, is currently ignored.
331 */
332static int
333mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
334 struct net_device *dev,
335 bool enabled, int timeout)
336{
f540f9f3 337 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
600f5d90 338 u32 ps_mode;
5e6e3a92
BZ
339
340 if (timeout)
341 wiphy_dbg(wiphy,
aea0701e 342 "info: ignore timeout value for IEEE Power Save\n");
5e6e3a92 343
600f5d90 344 ps_mode = enabled;
5e6e3a92 345
636c4598 346 return mwifiex_drv_set_power(priv, &ps_mode);
5e6e3a92
BZ
347}
348
349/*
350 * CFG802.11 operation handler to set the default network key.
351 */
352static int
353mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
354 u8 key_index, bool unicast,
355 bool multicast)
356{
f540f9f3 357 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
5e6e3a92 358
2d3d0a88 359 /* Return if WEP key not configured */
5eb02e44 360 if (!priv->sec_info.wep_enabled)
2d3d0a88
AK
361 return 0;
362
96893538
AP
363 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
364 priv->wep_key_curr_index = key_index;
53b11231
YL
365 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
366 NULL, 0)) {
636c4598 367 wiphy_err(wiphy, "set default Tx key index\n");
5e6e3a92 368 return -EFAULT;
636c4598 369 }
5e6e3a92
BZ
370
371 return 0;
372}
373
374/*
375 * CFG802.11 operation handler to add a network key.
376 */
377static int
378mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
379 u8 key_index, bool pairwise, const u8 *mac_addr,
380 struct key_params *params)
381{
f540f9f3 382 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
96893538 383 struct mwifiex_wep_key *wep_key;
75edd2c6
AP
384 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
385 const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
5e6e3a92 386
96893538
AP
387 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
388 (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
389 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
390 if (params->key && params->key_len) {
391 wep_key = &priv->wep_key[key_index];
392 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
393 memcpy(wep_key->key_material, params->key,
394 params->key_len);
395 wep_key->key_index = key_index;
396 wep_key->key_length = params->key_len;
397 priv->sec_info.wep_enabled = 1;
398 }
399 return 0;
400 }
401
53b11231 402 if (mwifiex_set_encode(priv, params, params->key, params->key_len,
75edd2c6 403 key_index, peer_mac, 0)) {
636c4598 404 wiphy_err(wiphy, "crypto keys added\n");
5e6e3a92 405 return -EFAULT;
636c4598 406 }
5e6e3a92
BZ
407
408 return 0;
409}
410
411/*
412 * This function sends domain information to the firmware.
413 *
414 * The following information are passed to the firmware -
415 * - Country codes
416 * - Sub bands (first channel, number of channels, maximum Tx power)
417 */
418static int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
419{
420 u8 no_of_triplet = 0;
421 struct ieee80211_country_ie_triplet *t;
422 u8 no_of_parsed_chan = 0;
423 u8 first_chan = 0, next_chan = 0, max_pwr = 0;
424 u8 i, flag = 0;
425 enum ieee80211_band band;
426 struct ieee80211_supported_band *sband;
427 struct ieee80211_channel *ch;
67fdf39e
AP
428 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
429 struct mwifiex_private *priv;
5e6e3a92 430 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
5e6e3a92
BZ
431
432 /* Set country code */
67fdf39e
AP
433 domain_info->country_code[0] = adapter->country_code[0];
434 domain_info->country_code[1] = adapter->country_code[1];
5e6e3a92
BZ
435 domain_info->country_code[2] = ' ';
436
437 band = mwifiex_band_to_radio_type(adapter->config_bands);
438 if (!wiphy->bands[band]) {
439 wiphy_err(wiphy, "11D: setting domain info in FW\n");
440 return -1;
441 }
442
443 sband = wiphy->bands[band];
444
445 for (i = 0; i < sband->n_channels ; i++) {
446 ch = &sband->channels[i];
447 if (ch->flags & IEEE80211_CHAN_DISABLED)
448 continue;
449
450 if (!flag) {
451 flag = 1;
452 first_chan = (u32) ch->hw_value;
453 next_chan = first_chan;
22db2497 454 max_pwr = ch->max_power;
5e6e3a92
BZ
455 no_of_parsed_chan = 1;
456 continue;
457 }
458
459 if (ch->hw_value == next_chan + 1 &&
22db2497 460 ch->max_power == max_pwr) {
5e6e3a92
BZ
461 next_chan++;
462 no_of_parsed_chan++;
463 } else {
464 t = &domain_info->triplet[no_of_triplet];
465 t->chans.first_channel = first_chan;
466 t->chans.num_channels = no_of_parsed_chan;
467 t->chans.max_power = max_pwr;
468 no_of_triplet++;
469 first_chan = (u32) ch->hw_value;
470 next_chan = first_chan;
22db2497 471 max_pwr = ch->max_power;
5e6e3a92
BZ
472 no_of_parsed_chan = 1;
473 }
474 }
475
476 if (flag) {
477 t = &domain_info->triplet[no_of_triplet];
478 t->chans.first_channel = first_chan;
479 t->chans.num_channels = no_of_parsed_chan;
480 t->chans.max_power = max_pwr;
481 no_of_triplet++;
482 }
483
484 domain_info->no_of_triplet = no_of_triplet;
636c4598 485
67fdf39e
AP
486 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
487
fa0ecbb9
BZ
488 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
489 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
5e6e3a92 490 wiphy_err(wiphy, "11D: setting domain info in FW\n");
636c4598
YAP
491 return -1;
492 }
5e6e3a92 493
636c4598 494 return 0;
5e6e3a92
BZ
495}
496
497/*
498 * CFG802.11 regulatory domain callback function.
499 *
500 * This function is called when the regulatory domain is changed due to the
501 * following reasons -
502 * - Set by driver
503 * - Set by system core
504 * - Set by user
505 * - Set bt Country IE
506 */
0c0280bd
LR
507static void mwifiex_reg_notifier(struct wiphy *wiphy,
508 struct regulatory_request *request)
5e6e3a92 509{
67fdf39e 510 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
82efa16a
BZ
511 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
512 MWIFIEX_BSS_ROLE_ANY);
5e6e3a92 513
67fdf39e
AP
514 wiphy_dbg(wiphy, "info: cfg80211 regulatory domain callback for %c%c\n",
515 request->alpha2[0], request->alpha2[1]);
5e6e3a92 516
5e6e3a92
BZ
517 switch (request->initiator) {
518 case NL80211_REGDOM_SET_BY_DRIVER:
519 case NL80211_REGDOM_SET_BY_CORE:
520 case NL80211_REGDOM_SET_BY_USER:
5e6e3a92
BZ
521 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
522 break;
dd4a9ac0
BZ
523 default:
524 wiphy_err(wiphy, "unknown regdom initiator: %d\n",
525 request->initiator);
526 return;
527 }
528
529 /* Don't send world or same regdom info to firmware */
530 if (strncmp(request->alpha2, "00", 2) &&
531 strncmp(request->alpha2, adapter->country_code,
532 sizeof(request->alpha2))) {
533 memcpy(adapter->country_code, request->alpha2,
534 sizeof(request->alpha2));
535 mwifiex_send_domain_info_cmd_fw(wiphy);
b58df446 536 mwifiex_dnld_txpwr_table(priv);
5e6e3a92 537 }
5e6e3a92
BZ
538}
539
5e6e3a92
BZ
540/*
541 * This function sets the fragmentation threshold.
542 *
600f5d90 543 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
5e6e3a92
BZ
544 * and MWIFIEX_FRAG_MAX_VALUE.
545 */
546static int
547mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
548{
aea0701e
YAP
549 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
550 frag_thr > MWIFIEX_FRAG_MAX_VALUE)
9b930eae 551 frag_thr = MWIFIEX_FRAG_MAX_VALUE;
5e6e3a92 552
fa0ecbb9
BZ
553 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
554 HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
555 &frag_thr, true);
5e6e3a92
BZ
556}
557
558/*
559 * This function sets the RTS threshold.
600f5d90
AK
560
561 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
562 * and MWIFIEX_RTS_MAX_VALUE.
5e6e3a92
BZ
563 */
564static int
565mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
566{
5e6e3a92
BZ
567 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
568 rts_thr = MWIFIEX_RTS_MAX_VALUE;
569
fa0ecbb9
BZ
570 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
571 HostCmd_ACT_GEN_SET, RTS_THRESH_I,
572 &rts_thr, true);
5e6e3a92
BZ
573}
574
575/*
576 * CFG802.11 operation handler to set wiphy parameters.
577 *
578 * This function can be used to set the RTS threshold and the
579 * Fragmentation threshold of the driver.
580 */
581static int
582mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
583{
67fdf39e 584 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
9b930eae
AP
585 struct mwifiex_private *priv;
586 struct mwifiex_uap_bss_param *bss_cfg;
587 int ret, bss_started, i;
588
589 for (i = 0; i < adapter->priv_num; i++) {
590 priv = adapter->priv[i];
591
592 switch (priv->bss_role) {
593 case MWIFIEX_BSS_ROLE_UAP:
594 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param),
595 GFP_KERNEL);
596 if (!bss_cfg)
597 return -ENOMEM;
598
599 mwifiex_set_sys_config_invalid_data(bss_cfg);
600
601 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
602 bss_cfg->rts_threshold = wiphy->rts_threshold;
603 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
604 bss_cfg->frag_threshold = wiphy->frag_threshold;
605 if (changed & WIPHY_PARAM_RETRY_LONG)
606 bss_cfg->retry_limit = wiphy->retry_long;
607
608 bss_started = priv->bss_started;
609
fa0ecbb9
BZ
610 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
611 HostCmd_ACT_GEN_SET, 0,
612 NULL, true);
9b930eae
AP
613 if (ret) {
614 wiphy_err(wiphy, "Failed to stop the BSS\n");
615 kfree(bss_cfg);
616 return ret;
617 }
618
fa0ecbb9
BZ
619 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
620 HostCmd_ACT_GEN_SET,
621 UAP_BSS_PARAMS_I, bss_cfg,
622 false);
5e6e3a92 623
9b930eae
AP
624 kfree(bss_cfg);
625
626 if (ret) {
627 wiphy_err(wiphy, "Failed to set bss config\n");
628 return ret;
629 }
5e6e3a92 630
9b930eae
AP
631 if (!bss_started)
632 break;
633
fa0ecbb9
BZ
634 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
635 HostCmd_ACT_GEN_SET, 0,
636 NULL, false);
9b930eae
AP
637 if (ret) {
638 wiphy_err(wiphy, "Failed to start BSS\n");
639 return ret;
640 }
641
642 break;
643 case MWIFIEX_BSS_ROLE_STA:
644 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
645 ret = mwifiex_set_rts(priv,
646 wiphy->rts_threshold);
647 if (ret)
648 return ret;
649 }
650 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
651 ret = mwifiex_set_frag(priv,
652 wiphy->frag_threshold);
653 if (ret)
654 return ret;
655 }
656 break;
657 }
658 }
659
660 return 0;
5e6e3a92
BZ
661}
662
e1a2b7a3
SP
663static int
664mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
665{
666 u16 mode = P2P_MODE_DISABLE;
667
9197ab9e
SP
668 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA)
669 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_STA);
670
fa0ecbb9
BZ
671 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
672 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
673 return -1;
674
675 return 0;
676}
677
678/*
679 * This function initializes the functionalities for P2P client.
680 * The P2P client initialization sequence is:
681 * disable -> device -> client
682 */
683static int
684mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
685{
686 u16 mode;
687
688 if (mwifiex_cfg80211_deinit_p2p(priv))
689 return -1;
690
691 mode = P2P_MODE_DEVICE;
fa0ecbb9
BZ
692 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
693 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
694 return -1;
695
696 mode = P2P_MODE_CLIENT;
fa0ecbb9
BZ
697 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
698 HostCmd_ACT_GEN_SET, 0, &mode, true))
e1a2b7a3
SP
699 return -1;
700
701 return 0;
702}
703
9197ab9e
SP
704/*
705 * This function initializes the functionalities for P2P GO.
706 * The P2P GO initialization sequence is:
707 * disable -> device -> GO
708 */
709static int
710mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
711{
712 u16 mode;
713
714 if (mwifiex_cfg80211_deinit_p2p(priv))
715 return -1;
716
717 mode = P2P_MODE_DEVICE;
fa0ecbb9
BZ
718 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
719 HostCmd_ACT_GEN_SET, 0, &mode, true))
9197ab9e
SP
720 return -1;
721
722 mode = P2P_MODE_GO;
fa0ecbb9
BZ
723 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
724 HostCmd_ACT_GEN_SET, 0, &mode, true))
9197ab9e
SP
725 return -1;
726
727 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
728 mwifiex_set_bss_role(priv, MWIFIEX_BSS_ROLE_UAP);
729
730 return 0;
731}
732
5e6e3a92
BZ
733/*
734 * CFG802.11 operation handler to change interface type.
5e6e3a92
BZ
735 */
736static int
737mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
738 struct net_device *dev,
739 enum nl80211_iftype type, u32 *flags,
740 struct vif_params *params)
741{
270e58e8 742 int ret;
5e6e3a92 743 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 744
4f02341a 745 switch (dev->ieee80211_ptr->iftype) {
5e6e3a92 746 case NL80211_IFTYPE_ADHOC:
4f02341a
AP
747 switch (type) {
748 case NL80211_IFTYPE_STATION:
749 break;
750 case NL80211_IFTYPE_UNSPECIFIED:
751 wiphy_warn(wiphy, "%s: kept type as IBSS\n", dev->name);
752 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
753 return 0;
754 case NL80211_IFTYPE_AP:
755 default:
756 wiphy_err(wiphy, "%s: changing to %d not supported\n",
757 dev->name, type);
758 return -EOPNOTSUPP;
759 }
5e6e3a92
BZ
760 break;
761 case NL80211_IFTYPE_STATION:
4f02341a
AP
762 switch (type) {
763 case NL80211_IFTYPE_ADHOC:
764 break;
e1a2b7a3
SP
765 case NL80211_IFTYPE_P2P_CLIENT:
766 if (mwifiex_cfg80211_init_p2p_client(priv))
767 return -EFAULT;
768 dev->ieee80211_ptr->iftype = type;
769 return 0;
9197ab9e
SP
770 case NL80211_IFTYPE_P2P_GO:
771 if (mwifiex_cfg80211_init_p2p_go(priv))
772 return -EFAULT;
773 dev->ieee80211_ptr->iftype = type;
774 return 0;
4f02341a
AP
775 case NL80211_IFTYPE_UNSPECIFIED:
776 wiphy_warn(wiphy, "%s: kept type as STA\n", dev->name);
777 case NL80211_IFTYPE_STATION: /* This shouldn't happen */
778 return 0;
779 case NL80211_IFTYPE_AP:
780 default:
781 wiphy_err(wiphy, "%s: changing to %d not supported\n",
782 dev->name, type);
783 return -EOPNOTSUPP;
784 }
785 break;
786 case NL80211_IFTYPE_AP:
787 switch (type) {
788 case NL80211_IFTYPE_UNSPECIFIED:
789 wiphy_warn(wiphy, "%s: kept type as AP\n", dev->name);
790 case NL80211_IFTYPE_AP: /* This shouldn't happen */
791 return 0;
792 case NL80211_IFTYPE_ADHOC:
793 case NL80211_IFTYPE_STATION:
794 default:
795 wiphy_err(wiphy, "%s: changing to %d not supported\n",
796 dev->name, type);
797 return -EOPNOTSUPP;
798 }
5e6e3a92 799 break;
e1a2b7a3 800 case NL80211_IFTYPE_P2P_CLIENT:
9197ab9e 801 case NL80211_IFTYPE_P2P_GO:
e1a2b7a3
SP
802 switch (type) {
803 case NL80211_IFTYPE_STATION:
804 if (mwifiex_cfg80211_deinit_p2p(priv))
805 return -EFAULT;
806 dev->ieee80211_ptr->iftype = type;
807 return 0;
808 default:
809 return -EOPNOTSUPP;
810 }
811 break;
5e6e3a92 812 default:
4f02341a
AP
813 wiphy_err(wiphy, "%s: unknown iftype: %d\n",
814 dev->name, dev->ieee80211_ptr->iftype);
815 return -EOPNOTSUPP;
5e6e3a92 816 }
5e6e3a92 817
4f02341a
AP
818 dev->ieee80211_ptr->iftype = type;
819 priv->bss_mode = type;
600f5d90 820 mwifiex_deauthenticate(priv, NULL);
eecd8250 821
f986b6d5 822 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
eecd8250 823
fa0ecbb9
BZ
824 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
825 HostCmd_ACT_GEN_SET, 0, NULL, true);
eecd8250 826
5e6e3a92
BZ
827 return ret;
828}
829
a5f39056
YAP
830static void
831mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
832 struct rate_info *rate)
833{
834 struct mwifiex_adapter *adapter = priv->adapter;
835
836 if (adapter->is_hw_11ac_capable) {
837 /* bit[1-0]: 00=LG 01=HT 10=VHT */
838 if (tx_htinfo & BIT(0)) {
839 /* HT */
840 rate->mcs = priv->tx_rate;
841 rate->flags |= RATE_INFO_FLAGS_MCS;
842 }
843 if (tx_htinfo & BIT(1)) {
844 /* VHT */
845 rate->mcs = priv->tx_rate & 0x0F;
846 rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
847 }
848
849 if (tx_htinfo & (BIT(1) | BIT(0))) {
850 /* HT or VHT */
851 switch (tx_htinfo & (BIT(3) | BIT(2))) {
852 case 0:
853 /* This will be 20MHz */
854 break;
855 case (BIT(2)):
856 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
857 break;
858 case (BIT(3)):
859 rate->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
860 break;
861 case (BIT(3) | BIT(2)):
862 rate->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
863 break;
864 }
865
866 if (tx_htinfo & BIT(4))
867 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
868
869 if ((priv->tx_rate >> 4) == 1)
870 rate->nss = 2;
871 else
872 rate->nss = 1;
873 }
874 } else {
875 /*
876 * Bit 0 in tx_htinfo indicates that current Tx rate
877 * is 11n rate. Valid MCS index values for us are 0 to 15.
878 */
879 if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
880 rate->mcs = priv->tx_rate;
881 rate->flags |= RATE_INFO_FLAGS_MCS;
882 if (tx_htinfo & BIT(1))
883 rate->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
884 if (tx_htinfo & BIT(2))
885 rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
886 }
887 }
888}
889
5e6e3a92
BZ
890/*
891 * This function dumps the station information on a buffer.
892 *
893 * The following information are shown -
894 * - Total bytes transmitted
895 * - Total bytes received
896 * - Total packets transmitted
897 * - Total packets received
898 * - Signal quality level
899 * - Transmission rate
900 */
901static int
902mwifiex_dump_station_info(struct mwifiex_private *priv,
903 struct station_info *sinfo)
904{
006606c0 905 u32 rate;
5e6e3a92
BZ
906
907 sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
7013d3e2
AK
908 STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
909 STATION_INFO_TX_BITRATE |
910 STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
5e6e3a92
BZ
911
912 /* Get signal information from the firmware */
fa0ecbb9
BZ
913 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
914 HostCmd_ACT_GEN_GET, 0, NULL, true)) {
958a4a86
AK
915 dev_err(priv->adapter->dev, "failed to get signal information\n");
916 return -EFAULT;
5e6e3a92
BZ
917 }
918
919 if (mwifiex_drv_get_data_rate(priv, &rate)) {
920 dev_err(priv->adapter->dev, "getting data rate\n");
958a4a86 921 return -EFAULT;
5e6e3a92
BZ
922 }
923
caf60a6c 924 /* Get DTIM period information from firmware */
fa0ecbb9
BZ
925 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
926 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
927 &priv->dtim_period, true);
caf60a6c 928
a5f39056 929 mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
4ec6f9c0 930
7013d3e2 931 sinfo->signal_avg = priv->bcn_rssi_avg;
5e6e3a92
BZ
932 sinfo->rx_bytes = priv->stats.rx_bytes;
933 sinfo->tx_bytes = priv->stats.tx_bytes;
934 sinfo->rx_packets = priv->stats.rx_packets;
935 sinfo->tx_packets = priv->stats.tx_packets;
958a4a86 936 sinfo->signal = priv->bcn_rssi_avg;
4ec6f9c0 937 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
006606c0 938 sinfo->txrate.legacy = rate * 5;
5e6e3a92 939
c4f3b972
AK
940 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
941 sinfo->filled |= STATION_INFO_BSS_PARAM;
942 sinfo->bss_param.flags = 0;
943 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
944 WLAN_CAPABILITY_SHORT_PREAMBLE)
945 sinfo->bss_param.flags |=
946 BSS_PARAM_FLAGS_SHORT_PREAMBLE;
947 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
948 WLAN_CAPABILITY_SHORT_SLOT_TIME)
949 sinfo->bss_param.flags |=
950 BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
caf60a6c 951 sinfo->bss_param.dtim_period = priv->dtim_period;
c4f3b972
AK
952 sinfo->bss_param.beacon_interval =
953 priv->curr_bss_params.bss_descriptor.beacon_period;
954 }
955
958a4a86 956 return 0;
5e6e3a92
BZ
957}
958
959/*
960 * CFG802.11 operation handler to get station information.
961 *
962 * This function only works in connected mode, and dumps the
963 * requested station information, if available.
964 */
965static int
966mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 967 const u8 *mac, struct station_info *sinfo)
5e6e3a92
BZ
968{
969 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 970
5e6e3a92
BZ
971 if (!priv->media_connected)
972 return -ENOENT;
973 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
974 return -ENOENT;
975
636c4598 976 return mwifiex_dump_station_info(priv, sinfo);
5e6e3a92
BZ
977}
978
f85aae6b
AK
979/*
980 * CFG802.11 operation handler to dump station information.
981 */
982static int
983mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
984 int idx, u8 *mac, struct station_info *sinfo)
985{
986 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
987
988 if (!priv->media_connected || idx)
989 return -ENOENT;
990
991 memcpy(mac, priv->cfg_bssid, ETH_ALEN);
992
993 return mwifiex_dump_station_info(priv, sinfo);
994}
995
5e6e3a92 996/* Supported rates to be advertised to the cfg80211 */
5e6e3a92
BZ
997static struct ieee80211_rate mwifiex_rates[] = {
998 {.bitrate = 10, .hw_value = 2, },
999 {.bitrate = 20, .hw_value = 4, },
1000 {.bitrate = 55, .hw_value = 11, },
1001 {.bitrate = 110, .hw_value = 22, },
5e6e3a92
BZ
1002 {.bitrate = 60, .hw_value = 12, },
1003 {.bitrate = 90, .hw_value = 18, },
1004 {.bitrate = 120, .hw_value = 24, },
1005 {.bitrate = 180, .hw_value = 36, },
1006 {.bitrate = 240, .hw_value = 48, },
1007 {.bitrate = 360, .hw_value = 72, },
1008 {.bitrate = 480, .hw_value = 96, },
1009 {.bitrate = 540, .hw_value = 108, },
5e6e3a92
BZ
1010};
1011
1012/* Channel definitions to be advertised to cfg80211 */
5e6e3a92
BZ
1013static struct ieee80211_channel mwifiex_channels_2ghz[] = {
1014 {.center_freq = 2412, .hw_value = 1, },
1015 {.center_freq = 2417, .hw_value = 2, },
1016 {.center_freq = 2422, .hw_value = 3, },
1017 {.center_freq = 2427, .hw_value = 4, },
1018 {.center_freq = 2432, .hw_value = 5, },
1019 {.center_freq = 2437, .hw_value = 6, },
1020 {.center_freq = 2442, .hw_value = 7, },
1021 {.center_freq = 2447, .hw_value = 8, },
1022 {.center_freq = 2452, .hw_value = 9, },
1023 {.center_freq = 2457, .hw_value = 10, },
1024 {.center_freq = 2462, .hw_value = 11, },
1025 {.center_freq = 2467, .hw_value = 12, },
1026 {.center_freq = 2472, .hw_value = 13, },
1027 {.center_freq = 2484, .hw_value = 14, },
1028};
1029
1030static struct ieee80211_supported_band mwifiex_band_2ghz = {
1031 .channels = mwifiex_channels_2ghz,
1032 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
1033 .bitrates = mwifiex_rates,
8763848e 1034 .n_bitrates = ARRAY_SIZE(mwifiex_rates),
5e6e3a92
BZ
1035};
1036
1037static struct ieee80211_channel mwifiex_channels_5ghz[] = {
1038 {.center_freq = 5040, .hw_value = 8, },
1039 {.center_freq = 5060, .hw_value = 12, },
1040 {.center_freq = 5080, .hw_value = 16, },
1041 {.center_freq = 5170, .hw_value = 34, },
1042 {.center_freq = 5190, .hw_value = 38, },
1043 {.center_freq = 5210, .hw_value = 42, },
1044 {.center_freq = 5230, .hw_value = 46, },
1045 {.center_freq = 5180, .hw_value = 36, },
1046 {.center_freq = 5200, .hw_value = 40, },
1047 {.center_freq = 5220, .hw_value = 44, },
1048 {.center_freq = 5240, .hw_value = 48, },
1049 {.center_freq = 5260, .hw_value = 52, },
1050 {.center_freq = 5280, .hw_value = 56, },
1051 {.center_freq = 5300, .hw_value = 60, },
1052 {.center_freq = 5320, .hw_value = 64, },
1053 {.center_freq = 5500, .hw_value = 100, },
1054 {.center_freq = 5520, .hw_value = 104, },
1055 {.center_freq = 5540, .hw_value = 108, },
1056 {.center_freq = 5560, .hw_value = 112, },
1057 {.center_freq = 5580, .hw_value = 116, },
1058 {.center_freq = 5600, .hw_value = 120, },
1059 {.center_freq = 5620, .hw_value = 124, },
1060 {.center_freq = 5640, .hw_value = 128, },
1061 {.center_freq = 5660, .hw_value = 132, },
1062 {.center_freq = 5680, .hw_value = 136, },
1063 {.center_freq = 5700, .hw_value = 140, },
1064 {.center_freq = 5745, .hw_value = 149, },
1065 {.center_freq = 5765, .hw_value = 153, },
1066 {.center_freq = 5785, .hw_value = 157, },
1067 {.center_freq = 5805, .hw_value = 161, },
1068 {.center_freq = 5825, .hw_value = 165, },
1069};
1070
1071static struct ieee80211_supported_band mwifiex_band_5ghz = {
1072 .channels = mwifiex_channels_5ghz,
1073 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
eb416ad3
AP
1074 .bitrates = mwifiex_rates + 4,
1075 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
5e6e3a92
BZ
1076};
1077
1078
1079/* Supported crypto cipher suits to be advertised to cfg80211 */
5e6e3a92
BZ
1080static const u32 mwifiex_cipher_suites[] = {
1081 WLAN_CIPHER_SUITE_WEP40,
1082 WLAN_CIPHER_SUITE_WEP104,
1083 WLAN_CIPHER_SUITE_TKIP,
1084 WLAN_CIPHER_SUITE_CCMP,
53b11231 1085 WLAN_CIPHER_SUITE_AES_CMAC,
5e6e3a92
BZ
1086};
1087
83719be8
SP
1088/* Supported mgmt frame types to be advertised to cfg80211 */
1089static const struct ieee80211_txrx_stypes
1090mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1091 [NL80211_IFTYPE_STATION] = {
1092 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1093 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1094 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1095 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1096 },
1097 [NL80211_IFTYPE_AP] = {
1098 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1099 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1100 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1101 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1102 },
1103 [NL80211_IFTYPE_P2P_CLIENT] = {
1104 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1105 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1106 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1107 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1108 },
1109 [NL80211_IFTYPE_P2P_GO] = {
1110 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1111 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1112 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1113 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
1114 },
1115};
1116
5d82c53a
YAP
1117/*
1118 * CFG802.11 operation handler for setting bit rates.
1119 *
433c3990
AK
1120 * Function configures data rates to firmware using bitrate mask
1121 * provided by cfg80211.
5d82c53a
YAP
1122 */
1123static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
1124 struct net_device *dev,
1125 const u8 *peer,
1126 const struct cfg80211_bitrate_mask *mask)
1127{
5d82c53a 1128 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
433c3990
AK
1129 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
1130 enum ieee80211_band band;
c44379e2 1131 struct mwifiex_adapter *adapter = priv->adapter;
5d82c53a 1132
433c3990 1133 if (!priv->media_connected) {
c44379e2 1134 dev_err(adapter->dev,
433c3990
AK
1135 "Can not set Tx data rate in disconnected state\n");
1136 return -EINVAL;
5d82c53a
YAP
1137 }
1138
433c3990 1139 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5d82c53a 1140
433c3990 1141 memset(bitmap_rates, 0, sizeof(bitmap_rates));
5d82c53a 1142
433c3990
AK
1143 /* Fill HR/DSSS rates. */
1144 if (band == IEEE80211_BAND_2GHZ)
1145 bitmap_rates[0] = mask->control[band].legacy & 0x000f;
5d82c53a 1146
433c3990
AK
1147 /* Fill OFDM rates */
1148 if (band == IEEE80211_BAND_2GHZ)
1149 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
1150 else
1151 bitmap_rates[1] = mask->control[band].legacy;
1152
d1e33e65
JD
1153 /* Fill HT MCS rates */
1154 bitmap_rates[2] = mask->control[band].ht_mcs[0];
c44379e2 1155 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
d1e33e65 1156 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
433c3990 1157
c44379e2
AK
1158 /* Fill VHT MCS rates */
1159 if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
1160 bitmap_rates[10] = mask->control[band].vht_mcs[0];
1161 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
1162 bitmap_rates[11] = mask->control[band].vht_mcs[1];
1163 }
1164
fa0ecbb9
BZ
1165 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
1166 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
5d82c53a
YAP
1167}
1168
fa444bf8
AK
1169/*
1170 * CFG802.11 operation handler for connection quality monitoring.
1171 *
1172 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
1173 * events to FW.
1174 */
1175static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
1176 struct net_device *dev,
1177 s32 rssi_thold, u32 rssi_hyst)
1178{
1179 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1180 struct mwifiex_ds_misc_subsc_evt subsc_evt;
1181
1182 priv->cqm_rssi_thold = rssi_thold;
1183 priv->cqm_rssi_hyst = rssi_hyst;
1184
1185 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
1186 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
1187
1188 /* Subscribe/unsubscribe low and high rssi events */
1189 if (rssi_thold && rssi_hyst) {
1190 subsc_evt.action = HostCmd_ACT_BITWISE_SET;
1191 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
1192 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
1193 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
1194 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
fa0ecbb9
BZ
1195 return mwifiex_send_cmd(priv,
1196 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1197 0, 0, &subsc_evt, true);
fa444bf8
AK
1198 } else {
1199 subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
fa0ecbb9
BZ
1200 return mwifiex_send_cmd(priv,
1201 HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
1202 0, 0, &subsc_evt, true);
fa444bf8
AK
1203 }
1204
1205 return 0;
1206}
1207
5370c836
AP
1208/* cfg80211 operation handler for change_beacon.
1209 * Function retrieves and sets modified management IEs to FW.
1210 */
1211static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
1212 struct net_device *dev,
1213 struct cfg80211_beacon_data *data)
1214{
1215 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1216
9197ab9e 1217 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
5370c836
AP
1218 wiphy_err(wiphy, "%s: bss_type mismatched\n", __func__);
1219 return -EINVAL;
1220 }
1221
1222 if (!priv->bss_started) {
1223 wiphy_err(wiphy, "%s: bss not started\n", __func__);
1224 return -EINVAL;
1225 }
1226
1227 if (mwifiex_set_mgmt_ies(priv, data)) {
1228 wiphy_err(wiphy, "%s: setting mgmt ies failed\n", __func__);
1229 return -EFAULT;
1230 }
1231
1232 return 0;
1233}
1234
0f9e9b8b
AP
1235/* cfg80211 operation handler for del_station.
1236 * Function deauthenticates station which value is provided in mac parameter.
1237 * If mac is NULL/broadcast, all stations in associated station list are
1238 * deauthenticated. If bss is not started or there are no stations in
1239 * associated stations list, no action is taken.
1240 */
1241static int
1242mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 1243 const u8 *mac)
0f9e9b8b
AP
1244{
1245 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1246 struct mwifiex_sta_node *sta_node;
1247 unsigned long flags;
1248
1249 if (list_empty(&priv->sta_list) || !priv->bss_started)
1250 return 0;
1251
1252 if (!mac || is_broadcast_ether_addr(mac)) {
1253 wiphy_dbg(wiphy, "%s: NULL/broadcast mac address\n", __func__);
1254 list_for_each_entry(sta_node, &priv->sta_list, list) {
fa0ecbb9
BZ
1255 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1256 HostCmd_ACT_GEN_SET, 0,
1257 sta_node->mac_addr, true))
0f9e9b8b
AP
1258 return -1;
1259 mwifiex_uap_del_sta_data(priv, sta_node);
1260 }
1261 } else {
1262 wiphy_dbg(wiphy, "%s: mac address %pM\n", __func__, mac);
1263 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1264 sta_node = mwifiex_get_sta_entry(priv, mac);
1265 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1266 if (sta_node) {
fa0ecbb9
BZ
1267 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
1268 HostCmd_ACT_GEN_SET, 0,
1269 sta_node->mac_addr, true))
0f9e9b8b
AP
1270 return -1;
1271 mwifiex_uap_del_sta_data(priv, sta_node);
1272 }
1273 }
1274
1275 return 0;
1276}
1277
8a279d5b
AK
1278static int
1279mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1280{
1281 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
1282 struct mwifiex_private *priv = mwifiex_get_priv(adapter,
1283 MWIFIEX_BSS_ROLE_ANY);
1284 struct mwifiex_ds_ant_cfg ant_cfg;
1285
1286 if (!tx_ant || !rx_ant)
1287 return -EOPNOTSUPP;
1288
1289 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
1290 /* Not a MIMO chip. User should provide specific antenna number
1291 * for Tx/Rx path or enable all antennas for diversity
1292 */
1293 if (tx_ant != rx_ant)
1294 return -EOPNOTSUPP;
1295
1296 if ((tx_ant & (tx_ant - 1)) &&
1297 (tx_ant != BIT(adapter->number_of_antenna) - 1))
1298 return -EOPNOTSUPP;
1299
1300 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
1301 (priv->adapter->number_of_antenna > 1)) {
1302 tx_ant = RF_ANTENNA_AUTO;
1303 rx_ant = RF_ANTENNA_AUTO;
1304 }
a5333914
AK
1305 } else {
1306 struct ieee80211_sta_ht_cap *ht_info;
1307 int rx_mcs_supp;
1308 enum ieee80211_band band;
1309
1310 if ((tx_ant == 0x1 && rx_ant == 0x1)) {
1311 adapter->user_dev_mcs_support = HT_STREAM_1X1;
1312 if (adapter->is_hw_11ac_capable)
1313 adapter->usr_dot_11ac_mcs_support =
1314 MWIFIEX_11AC_MCS_MAP_1X1;
1315 } else {
1316 adapter->user_dev_mcs_support = HT_STREAM_2X2;
1317 if (adapter->is_hw_11ac_capable)
1318 adapter->usr_dot_11ac_mcs_support =
1319 MWIFIEX_11AC_MCS_MAP_2X2;
1320 }
1321
1322 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1323 if (!adapter->wiphy->bands[band])
1324 continue;
1325
1326 ht_info = &adapter->wiphy->bands[band]->ht_cap;
1327 rx_mcs_supp =
1328 GET_RXMCSSUPP(adapter->user_dev_mcs_support);
1329 memset(&ht_info->mcs, 0, adapter->number_of_antenna);
1330 memset(&ht_info->mcs, 0xff, rx_mcs_supp);
1331 }
8a279d5b
AK
1332 }
1333
1334 ant_cfg.tx_ant = tx_ant;
1335 ant_cfg.rx_ant = rx_ant;
1336
fa0ecbb9
BZ
1337 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
1338 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
8a279d5b
AK
1339}
1340
12190c5d
AP
1341/* cfg80211 operation handler for stop ap.
1342 * Function stops BSS running at uAP interface.
1343 */
1344static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1345{
1346 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1347
40bbc21a
AP
1348 if (mwifiex_del_mgmt_ies(priv))
1349 wiphy_err(wiphy, "Failed to delete mgmt IEs!\n");
1350
c8258913
AP
1351 priv->ap_11n_enabled = 0;
1352
fa0ecbb9
BZ
1353 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1354 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
12190c5d
AP
1355 wiphy_err(wiphy, "Failed to stop the BSS\n");
1356 return -1;
1357 }
1358
1359 return 0;
1360}
1361
1362/* cfg80211 operation handler for start_ap.
1363 * Function sets beacon period, DTIM period, SSID and security into
1364 * AP config structure.
1365 * AP is configured with these settings and BSS is started.
1366 */
1367static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
1368 struct net_device *dev,
1369 struct cfg80211_ap_settings *params)
1370{
1371 struct mwifiex_uap_bss_param *bss_cfg;
1372 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
05910f4a 1373 u8 config_bands = 0;
12190c5d 1374
9197ab9e 1375 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
f752dcd5 1376 return -1;
adb6ed0c 1377 if (mwifiex_set_mgmt_ies(priv, &params->beacon))
f31acabe 1378 return -1;
f752dcd5 1379
12190c5d
AP
1380 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
1381 if (!bss_cfg)
1382 return -ENOMEM;
1383
1384 mwifiex_set_sys_config_invalid_data(bss_cfg);
1385
1386 if (params->beacon_interval)
1387 bss_cfg->beacon_period = params->beacon_interval;
1388 if (params->dtim_period)
1389 bss_cfg->dtim_period = params->dtim_period;
1390
1391 if (params->ssid && params->ssid_len) {
1392 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
1393 bss_cfg->ssid.ssid_len = params->ssid_len;
1394 }
1395
7a1c9934
AP
1396 switch (params->hidden_ssid) {
1397 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1398 bss_cfg->bcast_ssid_ctl = 1;
1399 break;
1400 case NL80211_HIDDEN_SSID_ZERO_LEN:
1401 bss_cfg->bcast_ssid_ctl = 0;
1402 break;
1403 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1404 /* firmware doesn't support this type of hidden SSID */
1405 default:
b3190466 1406 kfree(bss_cfg);
7a1c9934
AP
1407 return -EINVAL;
1408 }
1409
683b6d3b
JB
1410 bss_cfg->channel = ieee80211_frequency_to_channel(
1411 params->chandef.chan->center_freq);
0abd79e5 1412
05910f4a 1413 /* Set appropriate bands */
683b6d3b 1414 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
a3c2c4f6 1415 bss_cfg->band_cfg = BAND_CONFIG_BG;
a5f39056 1416 config_bands = BAND_B | BAND_G;
a3c2c4f6 1417
a5f39056
YAP
1418 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1419 config_bands |= BAND_GN;
05910f4a 1420 } else {
a3c2c4f6 1421 bss_cfg->band_cfg = BAND_CONFIG_A;
a5f39056 1422 config_bands = BAND_A;
a3c2c4f6 1423
a5f39056
YAP
1424 if (params->chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
1425 config_bands |= BAND_AN;
1426
1427 if (params->chandef.width > NL80211_CHAN_WIDTH_40)
1428 config_bands |= BAND_AAC;
0abd79e5
AP
1429 }
1430
05910f4a
AK
1431 if (!((config_bands | priv->adapter->fw_bands) &
1432 ~priv->adapter->fw_bands))
1433 priv->adapter->config_bands = config_bands;
1434
a3c2c4f6 1435 mwifiex_set_uap_rates(bss_cfg, params);
05910f4a
AK
1436 mwifiex_send_domain_info_cmd_fw(wiphy);
1437
f752dcd5
AP
1438 if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
1439 kfree(bss_cfg);
1440 wiphy_err(wiphy, "Failed to parse secuirty parameters!\n");
1441 return -1;
1442 }
1443
22281256 1444 mwifiex_set_ht_params(priv, bss_cfg, params);
83c78da9
YAP
1445
1446 if (priv->adapter->is_hw_11ac_capable) {
1447 mwifiex_set_vht_params(priv, bss_cfg, params);
1448 mwifiex_set_vht_width(priv, params->chandef.width,
1449 priv->ap_11ac_enabled);
1450 }
1451
2b6254da
AP
1452 if (priv->ap_11ac_enabled)
1453 mwifiex_set_11ac_ba_params(priv);
1454 else
1455 mwifiex_set_ba_params(priv);
1456
54428c57 1457 mwifiex_set_wmm_params(priv, bss_cfg, params);
22281256 1458
8b4509f6
KG
1459 if (params->inactivity_timeout > 0) {
1460 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
1461 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
1462 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
1463 }
1464
fa0ecbb9
BZ
1465 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
1466 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
12190c5d
AP
1467 wiphy_err(wiphy, "Failed to stop the BSS\n");
1468 kfree(bss_cfg);
1469 return -1;
1470 }
1471
fa0ecbb9
BZ
1472 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
1473 HostCmd_ACT_GEN_SET,
1474 UAP_BSS_PARAMS_I, bss_cfg, false)) {
12190c5d
AP
1475 wiphy_err(wiphy, "Failed to set the SSID\n");
1476 kfree(bss_cfg);
1477 return -1;
1478 }
1479
1480 kfree(bss_cfg);
1481
fa0ecbb9
BZ
1482 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
1483 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
12190c5d
AP
1484 wiphy_err(wiphy, "Failed to start the BSS\n");
1485 return -1;
1486 }
1487
96893538
AP
1488 if (priv->sec_info.wep_enabled)
1489 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1490 else
1491 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1492
fa0ecbb9
BZ
1493 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1494 HostCmd_ACT_GEN_SET, 0,
1495 &priv->curr_pkt_filter, true))
96893538
AP
1496 return -1;
1497
12190c5d
AP
1498 return 0;
1499}
1500
5e6e3a92
BZ
1501/*
1502 * CFG802.11 operation handler for disconnection request.
1503 *
1504 * This function does not work when there is already a disconnection
1505 * procedure going on.
1506 */
1507static int
1508mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1509 u16 reason_code)
1510{
1511 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1512
600f5d90 1513 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1514 return -EFAULT;
1515
1516 wiphy_dbg(wiphy, "info: successfully disconnected from %pM:"
1517 " reason code %d\n", priv->cfg_bssid, reason_code);
1518
38c9d664 1519 memset(priv->cfg_bssid, 0, ETH_ALEN);
587b36d3 1520 priv->hs2_enabled = false;
5e6e3a92
BZ
1521
1522 return 0;
1523}
1524
1525/*
1526 * This function informs the CFG802.11 subsystem of a new IBSS.
1527 *
1528 * The following information are sent to the CFG802.11 subsystem
1529 * to register the new IBSS. If we do not register the new IBSS,
1530 * a kernel panic will result.
1531 * - SSID
1532 * - SSID length
1533 * - BSSID
1534 * - Channel
1535 */
1536static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
1537{
5e6e3a92
BZ
1538 struct ieee80211_channel *chan;
1539 struct mwifiex_bss_info bss_info;
aa95a48d 1540 struct cfg80211_bss *bss;
270e58e8 1541 int ie_len;
5e6e3a92 1542 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
4ed5d521 1543 enum ieee80211_band band;
5e6e3a92 1544
636c4598
YAP
1545 if (mwifiex_get_bss_info(priv, &bss_info))
1546 return -1;
5e6e3a92
BZ
1547
1548 ie_buf[0] = WLAN_EID_SSID;
1549 ie_buf[1] = bss_info.ssid.ssid_len;
1550
1551 memcpy(&ie_buf[sizeof(struct ieee_types_header)],
aea0701e 1552 &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
5e6e3a92
BZ
1553 ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
1554
4ed5d521 1555 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
5e6e3a92
BZ
1556 chan = __ieee80211_get_channel(priv->wdev->wiphy,
1557 ieee80211_channel_to_frequency(bss_info.bss_chan,
4ed5d521 1558 band));
5e6e3a92 1559
aa95a48d 1560 bss = cfg80211_inform_bss(priv->wdev->wiphy, chan,
aea0701e
YAP
1561 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
1562 0, ie_buf, ie_len, 0, GFP_KERNEL);
5b112d3d 1563 cfg80211_put_bss(priv->wdev->wiphy, bss);
5e6e3a92
BZ
1564 memcpy(priv->cfg_bssid, bss_info.bssid, ETH_ALEN);
1565
636c4598 1566 return 0;
5e6e3a92
BZ
1567}
1568
5e6e3a92
BZ
1569/*
1570 * This function connects with a BSS.
1571 *
1572 * This function handles both Infra and Ad-Hoc modes. It also performs
1573 * validity checking on the provided parameters, disconnects from the
1574 * current BSS (if any), sets up the association/scan parameters,
1575 * including security settings, and performs specific SSID scan before
1576 * trying to connect.
1577 *
1578 * For Infra mode, the function returns failure if the specified SSID
1579 * is not found in scan table. However, for Ad-Hoc mode, it can create
1580 * the IBSS if it does not exist. On successful completion in either case,
7c6fa2a8 1581 * the function notifies the CFG802.11 subsystem of the new BSS connection.
5e6e3a92
BZ
1582 */
1583static int
664834de
JM
1584mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
1585 const u8 *ssid, const u8 *bssid, int mode,
1586 struct ieee80211_channel *channel,
5e6e3a92
BZ
1587 struct cfg80211_connect_params *sme, bool privacy)
1588{
b9be5f39 1589 struct cfg80211_ssid req_ssid;
270e58e8 1590 int ret, auth_type = 0;
7c6fa2a8 1591 struct cfg80211_bss *bss = NULL;
d7b9c520 1592 u8 is_scanning_required = 0;
5e6e3a92 1593
b9be5f39 1594 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
5e6e3a92
BZ
1595
1596 req_ssid.ssid_len = ssid_len;
1597 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
1598 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1599 return -EINVAL;
1600 }
1601
1602 memcpy(req_ssid.ssid, ssid, ssid_len);
1603 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
1604 dev_err(priv->adapter->dev, "invalid SSID - aborting\n");
1605 return -EINVAL;
1606 }
1607
1608 /* disconnect before try to associate */
600f5d90 1609 mwifiex_deauthenticate(priv, NULL);
5e6e3a92 1610
6670f15b
AK
1611 /* As this is new association, clear locally stored
1612 * keys and security related flags */
1613 priv->sec_info.wpa_enabled = false;
1614 priv->sec_info.wpa2_enabled = false;
1615 priv->wep_key_curr_index = 0;
00f157b4 1616 priv->sec_info.encryption_mode = 0;
a0f6d6ca 1617 priv->sec_info.is_authtype_auto = 0;
53b11231 1618 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
5e6e3a92 1619
eecd8250 1620 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1621 /* "privacy" is set only for ad-hoc mode */
1622 if (privacy) {
1623 /*
2be50b8d 1624 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
5e6e3a92
BZ
1625 * the firmware can find a matching network from the
1626 * scan. The cfg80211 does not give us the encryption
1627 * mode at this stage so just setting it to WEP here.
1628 */
203afeca 1629 priv->sec_info.encryption_mode =
2be50b8d 1630 WLAN_CIPHER_SUITE_WEP104;
203afeca 1631 priv->sec_info.authentication_mode =
f986b6d5 1632 NL80211_AUTHTYPE_OPEN_SYSTEM;
5e6e3a92
BZ
1633 }
1634
1635 goto done;
1636 }
1637
1638 /* Now handle infra mode. "sme" is valid for infra mode only */
a0f6d6ca 1639 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
f986b6d5 1640 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
a0f6d6ca
AK
1641 priv->sec_info.is_authtype_auto = 1;
1642 } else {
1643 auth_type = sme->auth_type;
1644 }
5e6e3a92
BZ
1645
1646 if (sme->crypto.n_ciphers_pairwise) {
2be50b8d
YAP
1647 priv->sec_info.encryption_mode =
1648 sme->crypto.ciphers_pairwise[0];
203afeca 1649 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1650 }
1651
1652 if (sme->crypto.cipher_group) {
2be50b8d 1653 priv->sec_info.encryption_mode = sme->crypto.cipher_group;
203afeca 1654 priv->sec_info.authentication_mode = auth_type;
5e6e3a92
BZ
1655 }
1656 if (sme->ie)
1657 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
1658
1659 if (sme->key) {
e6faada5 1660 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
5e6e3a92
BZ
1661 dev_dbg(priv->adapter->dev,
1662 "info: setting wep encryption"
1663 " with key len %d\n", sme->key_len);
6670f15b 1664 priv->wep_key_curr_index = sme->key_idx;
53b11231
YL
1665 ret = mwifiex_set_encode(priv, NULL, sme->key,
1666 sme->key_len, sme->key_idx,
1667 NULL, 0);
5e6e3a92
BZ
1668 }
1669 }
1670done:
7c6fa2a8
AK
1671 /*
1672 * Scan entries are valid for some time (15 sec). So we can save one
1673 * active scan time if we just try cfg80211_get_bss first. If it fails
1674 * then request scan and cfg80211_get_bss() again for final output.
1675 */
1676 while (1) {
1677 if (is_scanning_required) {
1678 /* Do specific SSID scanning */
1679 if (mwifiex_request_scan(priv, &req_ssid)) {
1680 dev_err(priv->adapter->dev, "scan error\n");
1681 return -EFAULT;
1682 }
1683 }
5e6e3a92 1684
7c6fa2a8
AK
1685 /* Find the BSS we want using available scan results */
1686 if (mode == NL80211_IFTYPE_ADHOC)
1687 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1688 bssid, ssid, ssid_len,
1689 WLAN_CAPABILITY_IBSS,
1690 WLAN_CAPABILITY_IBSS);
1691 else
1692 bss = cfg80211_get_bss(priv->wdev->wiphy, channel,
1693 bssid, ssid, ssid_len,
1694 WLAN_CAPABILITY_ESS,
1695 WLAN_CAPABILITY_ESS);
1696
1697 if (!bss) {
1698 if (is_scanning_required) {
aea0701e
YAP
1699 dev_warn(priv->adapter->dev,
1700 "assoc: requested bss not found in scan results\n");
7c6fa2a8
AK
1701 break;
1702 }
1703 is_scanning_required = 1;
1704 } else {
aea0701e
YAP
1705 dev_dbg(priv->adapter->dev,
1706 "info: trying to associate to '%s' bssid %pM\n",
1707 (char *) req_ssid.ssid, bss->bssid);
7c6fa2a8
AK
1708 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
1709 break;
1710 }
5e6e3a92
BZ
1711 }
1712
06975884
AK
1713 ret = mwifiex_bss_start(priv, bss, &req_ssid);
1714 if (ret)
1715 return ret;
5e6e3a92 1716
eecd8250 1717 if (mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1718 /* Inform the BSS information to kernel, otherwise
1719 * kernel will give a panic after successful assoc */
1720 if (mwifiex_cfg80211_inform_ibss_bss(priv))
1721 return -EFAULT;
1722 }
1723
1724 return ret;
1725}
1726
1727/*
1728 * CFG802.11 operation handler for association request.
1729 *
1730 * This function does not work when the current mode is set to Ad-Hoc, or
1731 * when there is already an association procedure going on. The given BSS
1732 * information is used to associate.
1733 */
1734static int
1735mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1736 struct cfg80211_connect_params *sme)
1737{
1738 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
8bc77a4d 1739 int ret;
5e6e3a92 1740
953b3539 1741 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
8bc77a4d 1742 wiphy_err(wiphy,
953b3539 1743 "%s: reject infra assoc request in non-STA role\n",
8bc77a4d
BZ
1744 dev->name);
1745 return -EINVAL;
e568634a
AP
1746 }
1747
5e6e3a92 1748 wiphy_dbg(wiphy, "info: Trying to associate to %s and bssid %pM\n",
aea0701e 1749 (char *) sme->ssid, sme->bssid);
5e6e3a92
BZ
1750
1751 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
eecd8250 1752 priv->bss_mode, sme->channel, sme, 0);
38c9d664
AK
1753 if (!ret) {
1754 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
1755 NULL, 0, WLAN_STATUS_SUCCESS,
1756 GFP_KERNEL);
1757 dev_dbg(priv->adapter->dev,
1758 "info: associated to bssid %pM successfully\n",
1759 priv->cfg_bssid);
1760 } else {
1761 dev_dbg(priv->adapter->dev,
1762 "info: association to bssid %pM failed\n",
1763 priv->cfg_bssid);
1764 memset(priv->cfg_bssid, 0, ETH_ALEN);
06975884
AK
1765
1766 if (ret > 0)
1767 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1768 NULL, 0, NULL, 0, ret,
1769 GFP_KERNEL);
1770 else
1771 cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
1772 NULL, 0, NULL, 0,
1773 WLAN_STATUS_UNSPECIFIED_FAILURE,
1774 GFP_KERNEL);
38c9d664
AK
1775 }
1776
06975884 1777 return 0;
5e6e3a92
BZ
1778}
1779
05910f4a
AK
1780/*
1781 * This function sets following parameters for ibss network.
1782 * - channel
1783 * - start band
1784 * - 11n flag
1785 * - secondary channel offset
1786 */
1787static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
1788 struct cfg80211_ibss_params *params)
1789{
1790 struct wiphy *wiphy = priv->wdev->wiphy;
1791 struct mwifiex_adapter *adapter = priv->adapter;
1792 int index = 0, i;
1793 u8 config_bands = 0;
1794
683b6d3b 1795 if (params->chandef.chan->band == IEEE80211_BAND_2GHZ) {
05910f4a
AK
1796 if (!params->basic_rates) {
1797 config_bands = BAND_B | BAND_G;
1798 } else {
1799 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
1800 /*
1801 * Rates below 6 Mbps in the table are CCK
1802 * rates; 802.11b and from 6 they are OFDM;
1803 * 802.11G
1804 */
1805 if (mwifiex_rates[i].bitrate == 60) {
1806 index = 1 << i;
1807 break;
1808 }
1809 }
1810
1811 if (params->basic_rates < index) {
1812 config_bands = BAND_B;
1813 } else {
1814 config_bands = BAND_G;
1815 if (params->basic_rates % index)
1816 config_bands |= BAND_B;
1817 }
1818 }
1819
683b6d3b
JB
1820 if (cfg80211_get_chandef_type(&params->chandef) !=
1821 NL80211_CHAN_NO_HT)
3b86acb8 1822 config_bands |= BAND_G | BAND_GN;
05910f4a 1823 } else {
c3ff0b2d 1824 if (cfg80211_get_chandef_type(&params->chandef) ==
683b6d3b 1825 NL80211_CHAN_NO_HT)
05910f4a
AK
1826 config_bands = BAND_A;
1827 else
1828 config_bands = BAND_AN | BAND_A;
1829 }
1830
1831 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
1832 adapter->config_bands = config_bands;
1833 adapter->adhoc_start_band = config_bands;
1834
1835 if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
1836 adapter->adhoc_11n_enabled = true;
1837 else
1838 adapter->adhoc_11n_enabled = false;
1839 }
1840
1841 adapter->sec_chan_offset =
683b6d3b
JB
1842 mwifiex_chan_type_to_sec_chan_offset(
1843 cfg80211_get_chandef_type(&params->chandef));
1844 priv->adhoc_channel = ieee80211_frequency_to_channel(
1845 params->chandef.chan->center_freq);
05910f4a
AK
1846
1847 wiphy_dbg(wiphy, "info: set ibss band %d, chan %d, chan offset %d\n",
1848 config_bands, priv->adhoc_channel, adapter->sec_chan_offset);
1849
1850 return 0;
1851}
1852
5e6e3a92
BZ
1853/*
1854 * CFG802.11 operation handler to join an IBSS.
1855 *
1856 * This function does not work in any mode other than Ad-Hoc, or if
1857 * a join operation is already in progress.
1858 */
1859static int
1860mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1861 struct cfg80211_ibss_params *params)
1862{
f540f9f3 1863 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1864 int ret = 0;
5e6e3a92 1865
eecd8250 1866 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1867 wiphy_err(wiphy, "request to join ibss received "
1868 "when station is not in ibss mode\n");
1869 goto done;
1870 }
1871
5e6e3a92 1872 wiphy_dbg(wiphy, "info: trying to join to %s and bssid %pM\n",
aea0701e 1873 (char *) params->ssid, params->bssid);
5e6e3a92 1874
05910f4a
AK
1875 mwifiex_set_ibss_params(priv, params);
1876
5e6e3a92 1877 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
aea0701e 1878 params->bssid, priv->bss_mode,
683b6d3b
JB
1879 params->chandef.chan, NULL,
1880 params->privacy);
5e6e3a92 1881done:
38c9d664 1882 if (!ret) {
fe94f3a4
AQ
1883 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
1884 params->chandef.chan, GFP_KERNEL);
38c9d664
AK
1885 dev_dbg(priv->adapter->dev,
1886 "info: joined/created adhoc network with bssid"
1887 " %pM successfully\n", priv->cfg_bssid);
1888 } else {
1889 dev_dbg(priv->adapter->dev,
1890 "info: failed creating/joining adhoc network\n");
1891 }
1892
5e6e3a92
BZ
1893 return ret;
1894}
1895
1896/*
1897 * CFG802.11 operation handler to leave an IBSS.
1898 *
1899 * This function does not work if a leave operation is
1900 * already in progress.
1901 */
1902static int
1903mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1904{
f540f9f3 1905 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
5e6e3a92 1906
5e6e3a92 1907 wiphy_dbg(wiphy, "info: disconnecting from essid %pM\n",
aea0701e 1908 priv->cfg_bssid);
600f5d90 1909 if (mwifiex_deauthenticate(priv, NULL))
5e6e3a92
BZ
1910 return -EFAULT;
1911
38c9d664 1912 memset(priv->cfg_bssid, 0, ETH_ALEN);
5e6e3a92
BZ
1913
1914 return 0;
1915}
1916
1917/*
1918 * CFG802.11 operation handler for scan request.
1919 *
1920 * This function issues a scan request to the firmware based upon
1921 * the user specified scan configuration. On successfull completion,
1922 * it also informs the results.
1923 */
1924static int
fd014284 1925mwifiex_cfg80211_scan(struct wiphy *wiphy,
5e6e3a92
BZ
1926 struct cfg80211_scan_request *request)
1927{
fd014284 1928 struct net_device *dev = request->wdev->netdev;
5e6e3a92 1929 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
c2476335 1930 int i, offset, ret;
38c9d664 1931 struct ieee80211_channel *chan;
ea021f56 1932 struct ieee_types_header *ie;
75ab753d 1933 struct mwifiex_user_scan_cfg *user_scan_cfg;
5e6e3a92
BZ
1934
1935 wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
1936
e45a8419
AK
1937 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
1938 atomic_read(&priv->wmm.tx_pkts_queued) >=
de09364e
AK
1939 MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
1940 dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
1941 return -EBUSY;
1942 }
1943
75ab753d
AK
1944 /* Block scan request if scan operation or scan cleanup when interface
1945 * is disabled is in process
1946 */
1947 if (priv->scan_request || priv->scan_aborting) {
f162cac8
AK
1948 dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
1949 return -EBUSY;
1950 }
1951
75ab753d
AK
1952 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1953 if (!user_scan_cfg)
38c9d664 1954 return -ENOMEM;
be0b281e 1955
6fcf2b10
BZ
1956 priv->scan_request = request;
1957
75ab753d
AK
1958 user_scan_cfg->num_ssids = request->n_ssids;
1959 user_scan_cfg->ssid_list = request->ssids;
be0b281e 1960
13d7ba78 1961 if (request->ie && request->ie_len) {
ea021f56 1962 offset = 0;
13d7ba78
AP
1963 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
1964 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
1965 continue;
1966 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
ea021f56
SP
1967 ie = (struct ieee_types_header *)(request->ie + offset);
1968 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
1969 offset += sizeof(*ie) + ie->len;
1970
1971 if (offset >= request->ie_len)
1972 break;
13d7ba78
AP
1973 }
1974 }
1975
901ceba4
SP
1976 for (i = 0; i < min_t(u32, request->n_channels,
1977 MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
38c9d664 1978 chan = request->channels[i];
75ab753d
AK
1979 user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
1980 user_scan_cfg->chan_list[i].radio_type = chan->band;
38c9d664 1981
8fe02e16 1982 if (chan->flags & IEEE80211_CHAN_NO_IR)
75ab753d 1983 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1984 MWIFIEX_SCAN_TYPE_PASSIVE;
38c9d664 1985 else
75ab753d 1986 user_scan_cfg->chan_list[i].scan_type =
aea0701e 1987 MWIFIEX_SCAN_TYPE_ACTIVE;
38c9d664 1988
75ab753d 1989 user_scan_cfg->chan_list[i].scan_time = 0;
38c9d664 1990 }
c2476335 1991
75ab753d
AK
1992 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1993 kfree(user_scan_cfg);
c2476335
BZ
1994 if (ret) {
1995 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
75ab753d 1996 priv->scan_aborting = false;
6fcf2b10 1997 priv->scan_request = NULL;
c2476335
BZ
1998 return ret;
1999 }
38c9d664 2000
13d7ba78
AP
2001 if (request->ie && request->ie_len) {
2002 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
2003 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
2004 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
2005 memset(&priv->vs_ie[i].ie, 0,
2006 MWIFIEX_MAX_VSIE_LEN);
2007 }
2008 }
2009 }
5e6e3a92
BZ
2010 return 0;
2011}
2012
a5f39056
YAP
2013static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
2014 struct mwifiex_private *priv)
2015{
2016 struct mwifiex_adapter *adapter = priv->adapter;
a5f39056
YAP
2017
2018 vht_info->vht_supported = true;
2019
43283feb 2020 vht_info->cap = adapter->hw_dot_11ac_dev_cap;
a5f39056
YAP
2021 /* Update MCS support for VHT */
2022 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
2023 adapter->hw_dot_11ac_mcs_support & 0xFFFF);
2024 vht_info->vht_mcs.rx_highest = 0;
2025 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
2026 adapter->hw_dot_11ac_mcs_support >> 16);
2027 vht_info->vht_mcs.tx_highest = 0;
2028}
2029
5e6e3a92
BZ
2030/*
2031 * This function sets up the CFG802.11 specific HT capability fields
2032 * with default values.
2033 *
2034 * The following default values are set -
2035 * - HT Supported = True
a46b7b5c
AK
2036 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
2037 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
2038 * - HT Capabilities supported by firmware
5e6e3a92
BZ
2039 * - MCS information, Rx mask = 0xff
2040 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
2041 */
2042static void
2043mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
2044 struct mwifiex_private *priv)
2045{
2046 int rx_mcs_supp;
2047 struct ieee80211_mcs_info mcs_set;
2048 u8 *mcs = (u8 *)&mcs_set;
2049 struct mwifiex_adapter *adapter = priv->adapter;
2050
2051 ht_info->ht_supported = true;
a46b7b5c
AK
2052 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2053 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
5e6e3a92
BZ
2054
2055 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
5e6e3a92 2056
a46b7b5c
AK
2057 /* Fill HT capability information */
2058 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
2059 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2060 else
2061 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2062
2063 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
2064 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
2065 else
2066 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
2067
2068 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
2069 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
2070 else
2071 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
2072
474a41e9
MH
2073 if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
2074 ht_info->cap |= 3 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
a46b7b5c 2075 else
474a41e9 2076 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
a46b7b5c
AK
2077
2078 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
2079 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
2080 else
2081 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
2082
dd0d83c2
AP
2083 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
2084 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
2085 else
2086 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
2087
2088 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
2089 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2090 else
2091 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
2092
2093 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
2094 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
2095 else
2096 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
2097
a46b7b5c
AK
2098 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
2099 ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
2100
a5333914
AK
2101 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
2102 /* Set MCS for 1x1/2x2 */
5e6e3a92
BZ
2103 memset(mcs, 0xff, rx_mcs_supp);
2104 /* Clear all the other values */
2105 memset(&mcs[rx_mcs_supp], 0,
aea0701e 2106 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
eecd8250 2107 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
aea0701e 2108 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
5e6e3a92
BZ
2109 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
2110 SETHT_MCS32(mcs_set.rx_mask);
2111
2112 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
2113
2114 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
2115}
2116
93a1df48
YAP
2117/*
2118 * create a new virtual interface with the given name
2119 */
84efbb84 2120struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
552bff0c 2121 const char *name,
84efbb84
JB
2122 enum nl80211_iftype type,
2123 u32 *flags,
2124 struct vif_params *params)
93a1df48 2125{
67fdf39e
AP
2126 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2127 struct mwifiex_private *priv;
93a1df48
YAP
2128 struct net_device *dev;
2129 void *mdev_priv;
d6bffe8b 2130 struct wireless_dev *wdev;
93a1df48 2131
93a1df48 2132 if (!adapter)
858faa57 2133 return ERR_PTR(-EFAULT);
93a1df48
YAP
2134
2135 switch (type) {
2136 case NL80211_IFTYPE_UNSPECIFIED:
2137 case NL80211_IFTYPE_STATION:
2138 case NL80211_IFTYPE_ADHOC:
d6bffe8b 2139 priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
93a1df48 2140 if (priv->bss_mode) {
d6bffe8b
AP
2141 wiphy_err(wiphy,
2142 "cannot create multiple sta/adhoc ifaces\n");
858faa57 2143 return ERR_PTR(-EINVAL);
93a1df48
YAP
2144 }
2145
d6bffe8b
AP
2146 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2147 if (!wdev)
858faa57 2148 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2149
2150 wdev->wiphy = wiphy;
2151 priv->wdev = wdev;
2152 wdev->iftype = NL80211_IFTYPE_STATION;
2153
93a1df48
YAP
2154 if (type == NL80211_IFTYPE_UNSPECIFIED)
2155 priv->bss_mode = NL80211_IFTYPE_STATION;
2156 else
2157 priv->bss_mode = type;
2158
2159 priv->bss_type = MWIFIEX_BSS_TYPE_STA;
2160 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2161 priv->bss_priority = 0;
93a1df48 2162 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
93a1df48
YAP
2163 priv->bss_num = 0;
2164
d6bffe8b
AP
2165 break;
2166 case NL80211_IFTYPE_AP:
2167 priv = adapter->priv[MWIFIEX_BSS_TYPE_UAP];
2168
2169 if (priv->bss_mode) {
2170 wiphy_err(wiphy, "Can't create multiple AP interfaces");
858faa57 2171 return ERR_PTR(-EINVAL);
d6bffe8b
AP
2172 }
2173
2174 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2175 if (!wdev)
858faa57 2176 return ERR_PTR(-ENOMEM);
d6bffe8b
AP
2177
2178 priv->wdev = wdev;
2179 wdev->wiphy = wiphy;
2180 wdev->iftype = NL80211_IFTYPE_AP;
2181
2182 priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
2183 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
a458c0ae 2184 priv->bss_priority = 0;
d6bffe8b
AP
2185 priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
2186 priv->bss_started = 0;
2187 priv->bss_num = 0;
2188 priv->bss_mode = type;
2189
197f4a2e
SP
2190 break;
2191 case NL80211_IFTYPE_P2P_CLIENT:
2192 priv = adapter->priv[MWIFIEX_BSS_TYPE_P2P];
2193
2194 if (priv->bss_mode) {
2195 wiphy_err(wiphy, "Can't create multiple P2P ifaces");
2196 return ERR_PTR(-EINVAL);
2197 }
2198
2199 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2200 if (!wdev)
2201 return ERR_PTR(-ENOMEM);
2202
2203 priv->wdev = wdev;
2204 wdev->wiphy = wiphy;
2205
2206 /* At start-up, wpa_supplicant tries to change the interface
2207 * to NL80211_IFTYPE_STATION if it is not managed mode.
197f4a2e 2208 */
5586d3e2
PS
2209 wdev->iftype = NL80211_IFTYPE_P2P_CLIENT;
2210 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
197f4a2e
SP
2211
2212 /* Setting bss_type to P2P tells firmware that this interface
2213 * is receiving P2P peers found during find phase and doing
2214 * action frame handshake.
2215 */
2216 priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
2217
2218 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
2219 priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
2220 priv->bss_role = MWIFIEX_BSS_ROLE_STA;
2221 priv->bss_started = 0;
2222 priv->bss_num = 0;
2223
bec568ff
AK
2224 if (mwifiex_cfg80211_init_p2p_client(priv)) {
2225 wdev = ERR_PTR(-EFAULT);
2226 goto done;
2227 }
66aa1ae2 2228
93a1df48
YAP
2229 break;
2230 default:
2231 wiphy_err(wiphy, "type not supported\n");
858faa57 2232 return ERR_PTR(-EINVAL);
93a1df48
YAP
2233 }
2234
47411a06
AP
2235 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
2236 ether_setup, IEEE80211_NUM_ACS, 1);
93a1df48
YAP
2237 if (!dev) {
2238 wiphy_err(wiphy, "no memory available for netdevice\n");
858faa57 2239 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
bec568ff
AK
2240 wdev = ERR_PTR(-ENOMEM);
2241 goto done;
93a1df48
YAP
2242 }
2243
d6bffe8b
AP
2244 mwifiex_init_priv_params(priv, dev);
2245 priv->netdev = dev;
2246
2247 mwifiex_setup_ht_caps(&wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap, priv);
a5f39056
YAP
2248 if (adapter->is_hw_11ac_capable)
2249 mwifiex_setup_vht_caps(
2250 &wiphy->bands[IEEE80211_BAND_2GHZ]->vht_cap, priv);
d6bffe8b
AP
2251
2252 if (adapter->config_bands & BAND_A)
2253 mwifiex_setup_ht_caps(
2254 &wiphy->bands[IEEE80211_BAND_5GHZ]->ht_cap, priv);
2255
a5f39056
YAP
2256 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
2257 mwifiex_setup_vht_caps(
2258 &wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap, priv);
2259
93a1df48
YAP
2260 dev_net_set(dev, wiphy_net(wiphy));
2261 dev->ieee80211_ptr = priv->wdev;
2262 dev->ieee80211_ptr->iftype = priv->bss_mode;
2263 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
93a1df48
YAP
2264 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
2265
2266 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
2267 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
2268 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
0d7f53e3 2269 dev->ethtool_ops = &mwifiex_ethtool_ops;
93a1df48
YAP
2270
2271 mdev_priv = netdev_priv(dev);
2272 *((unsigned long *) mdev_priv) = (unsigned long) priv;
2273
93a1df48
YAP
2274 SET_NETDEV_DEV(dev, adapter->dev);
2275
2276 /* Register network device */
2277 if (register_netdevice(dev)) {
2278 wiphy_err(wiphy, "cannot register virtual network device\n");
858faa57
BZ
2279 free_netdev(dev);
2280 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
bec568ff
AK
2281 priv->netdev = NULL;
2282 wdev = ERR_PTR(-EFAULT);
2283 goto done;
93a1df48
YAP
2284 }
2285
2286 sema_init(&priv->async_sem, 1);
93a1df48
YAP
2287
2288 dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
2289
2290#ifdef CONFIG_DEBUG_FS
2291 mwifiex_dev_debugfs_init(priv);
2292#endif
bec568ff
AK
2293
2294done:
2295 if (IS_ERR(wdev)) {
2296 kfree(priv->wdev);
2297 priv->wdev = NULL;
2298 }
2299
84efbb84 2300 return wdev;
93a1df48
YAP
2301}
2302EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
2303
2304/*
2305 * del_virtual_intf: remove the virtual interface determined by dev
2306 */
84efbb84 2307int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
93a1df48 2308{
84efbb84 2309 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
93a1df48
YAP
2310
2311#ifdef CONFIG_DEBUG_FS
2312 mwifiex_dev_debugfs_remove(priv);
2313#endif
2314
47411a06 2315 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
93a1df48
YAP
2316
2317 if (netif_carrier_ok(priv->netdev))
2318 netif_carrier_off(priv->netdev);
2319
84efbb84
JB
2320 if (wdev->netdev->reg_state == NETREG_REGISTERED)
2321 unregister_netdevice(wdev->netdev);
93a1df48 2322
93a1df48 2323 /* Clear the priv in adapter */
98a4635b 2324 priv->netdev->ieee80211_ptr = NULL;
93a1df48 2325 priv->netdev = NULL;
98a4635b
AK
2326 kfree(wdev);
2327 priv->wdev = NULL;
93a1df48
YAP
2328
2329 priv->media_connected = false;
2330
93a1df48
YAP
2331 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
2332
2333 return 0;
2334}
2335EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
2336
7da060c1 2337static bool
0434c464
AK
2338mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
2339 u8 max_byte_seq)
7da060c1
AK
2340{
2341 int j, k, valid_byte_cnt = 0;
2342 bool dont_care_byte = false;
2343
2344 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
2345 for (k = 0; k < 8; k++) {
2346 if (pat->mask[j] & 1 << k) {
2347 memcpy(byte_seq + valid_byte_cnt,
2348 &pat->pattern[j * 8 + k], 1);
2349 valid_byte_cnt++;
2350 if (dont_care_byte)
2351 return false;
2352 } else {
2353 if (valid_byte_cnt)
2354 dont_care_byte = true;
2355 }
2356
0434c464 2357 if (valid_byte_cnt > max_byte_seq)
7da060c1
AK
2358 return false;
2359 }
2360 }
2361
0434c464 2362 byte_seq[max_byte_seq] = valid_byte_cnt;
7da060c1
AK
2363
2364 return true;
2365}
2366
d1e2586f 2367#ifdef CONFIG_PM
7da060c1
AK
2368static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
2369 struct cfg80211_wowlan *wowlan)
2370{
2371 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2372 struct mwifiex_ds_mef_cfg mef_cfg;
2373 struct mwifiex_mef_entry *mef_entry;
2374 int i, filt_num = 0, ret;
2375 bool first_pat = true;
3f4e854a 2376 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
7da060c1
AK
2377 const u8 ipv4_mc_mac[] = {0x33, 0x33};
2378 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
2379 struct mwifiex_private *priv =
2380 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
2381
2382 if (!wowlan) {
2383 dev_warn(adapter->dev, "None of the WOWLAN triggers enabled\n");
2384 return 0;
2385 }
2386
2387 if (!priv->media_connected) {
2388 dev_warn(adapter->dev,
2389 "Can not configure WOWLAN in disconnected state\n");
2390 return 0;
2391 }
2392
c678fb2a
BZ
2393 mef_entry = kzalloc(sizeof(*mef_entry), GFP_KERNEL);
2394 if (!mef_entry)
2395 return -ENOMEM;
2396
7da060c1
AK
2397 memset(&mef_cfg, 0, sizeof(mef_cfg));
2398 mef_cfg.num_entries = 1;
7da060c1
AK
2399 mef_cfg.mef_entry = mef_entry;
2400 mef_entry->mode = MEF_MODE_HOST_SLEEP;
2401 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
2402
2403 for (i = 0; i < wowlan->n_patterns; i++) {
2404 memset(byte_seq, 0, sizeof(byte_seq));
2405 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
0434c464
AK
2406 byte_seq,
2407 MWIFIEX_MEF_MAX_BYTESEQ)) {
7da060c1
AK
2408 wiphy_err(wiphy, "Pattern not supported\n");
2409 kfree(mef_entry);
2410 return -EOPNOTSUPP;
2411 }
2412
2413 if (!wowlan->patterns[i].pkt_offset) {
2414 if (!(byte_seq[0] & 0x01) &&
3f4e854a 2415 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
7da060c1
AK
2416 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2417 continue;
2418 } else if (is_broadcast_ether_addr(byte_seq)) {
2419 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST;
2420 continue;
2421 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
3f4e854a 2422 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
7da060c1 2423 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
3f4e854a 2424 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
7da060c1
AK
2425 mef_cfg.criteria |= MWIFIEX_CRITERIA_MULTICAST;
2426 continue;
2427 }
2428 }
2429
2430 mef_entry->filter[filt_num].repeat = 1;
2431 mef_entry->filter[filt_num].offset =
2432 wowlan->patterns[i].pkt_offset;
2433 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
2434 sizeof(byte_seq));
2435 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2436
2437 if (first_pat)
2438 first_pat = false;
2439 else
2440 mef_entry->filter[filt_num].filt_action = TYPE_AND;
2441
2442 filt_num++;
2443 }
2444
2445 if (wowlan->magic_pkt) {
2446 mef_cfg.criteria |= MWIFIEX_CRITERIA_UNICAST;
2447 mef_entry->filter[filt_num].repeat = 16;
2448 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2449 ETH_ALEN);
3f4e854a
AK
2450 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
2451 ETH_ALEN;
09e65f5b 2452 mef_entry->filter[filt_num].offset = 28;
7da060c1
AK
2453 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2454 if (filt_num)
2455 mef_entry->filter[filt_num].filt_action = TYPE_OR;
4dbc13fa
ZY
2456
2457 filt_num++;
2458 mef_entry->filter[filt_num].repeat = 16;
2459 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
2460 ETH_ALEN);
2461 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
2462 ETH_ALEN;
2463 mef_entry->filter[filt_num].offset = 56;
2464 mef_entry->filter[filt_num].filt_type = TYPE_EQ;
2465 mef_entry->filter[filt_num].filt_action = TYPE_OR;
7da060c1
AK
2466 }
2467
2468 if (!mef_cfg.criteria)
2469 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
2470 MWIFIEX_CRITERIA_UNICAST |
2471 MWIFIEX_CRITERIA_MULTICAST;
2472
fa0ecbb9
BZ
2473 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
2474 HostCmd_ACT_GEN_SET, 0, &mef_cfg, true);
7da060c1
AK
2475
2476 kfree(mef_entry);
2477 return ret;
2478}
2479
2480static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
2481{
2482 return 0;
2483}
2484
2485static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
2486 bool enabled)
2487{
2488 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2489
2490 device_set_wakeup_enable(adapter->dev, enabled);
2491}
2492#endif
2493
562fc5b3
AK
2494static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
2495{
2496 const u8 ipv4_mc_mac[] = {0x33, 0x33};
2497 const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
2498 const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
2499
2500 if ((byte_seq[0] & 0x01) &&
2501 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
2502 return PACKET_TYPE_UNICAST;
2503 else if (!memcmp(byte_seq, bc_mac, 4))
2504 return PACKET_TYPE_BROADCAST;
2505 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
2506 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
2507 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
2508 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
2509 return PACKET_TYPE_MULTICAST;
2510
2511 return 0;
2512}
2513
2514static int
2515mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
2516 struct cfg80211_coalesce_rules *crule,
2517 struct mwifiex_coalesce_rule *mrule)
2518{
2519 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
2520 struct filt_field_param *param;
2521 int i;
2522
2523 mrule->max_coalescing_delay = crule->delay;
2524
2525 param = mrule->params;
2526
2527 for (i = 0; i < crule->n_patterns; i++) {
2528 memset(byte_seq, 0, sizeof(byte_seq));
2529 if (!mwifiex_is_pattern_supported(&crule->patterns[i],
2530 byte_seq,
2531 MWIFIEX_COALESCE_MAX_BYTESEQ)) {
2532 dev_err(priv->adapter->dev, "Pattern not supported\n");
2533 return -EOPNOTSUPP;
2534 }
2535
2536 if (!crule->patterns[i].pkt_offset) {
2537 u8 pkt_type;
2538
2539 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
2540 if (pkt_type && mrule->pkt_type) {
2541 dev_err(priv->adapter->dev,
2542 "Multiple packet types not allowed\n");
2543 return -EOPNOTSUPP;
2544 } else if (pkt_type) {
2545 mrule->pkt_type = pkt_type;
2546 continue;
2547 }
2548 }
2549
2550 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
2551 param->operation = RECV_FILTER_MATCH_TYPE_EQ;
2552 else
2553 param->operation = RECV_FILTER_MATCH_TYPE_NE;
2554
2555 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
2556 memcpy(param->operand_byte_stream, byte_seq,
2557 param->operand_len);
2558 param->offset = crule->patterns[i].pkt_offset;
2559 param++;
2560
2561 mrule->num_of_fields++;
2562 }
2563
2564 if (!mrule->pkt_type) {
2565 dev_err(priv->adapter->dev,
2566 "Packet type can not be determined\n");
2567 return -EOPNOTSUPP;
2568 }
2569
2570 return 0;
2571}
2572
2573static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
2574 struct cfg80211_coalesce *coalesce)
2575{
2576 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
2577 int i, ret;
2578 struct mwifiex_ds_coalesce_cfg coalesce_cfg;
2579 struct mwifiex_private *priv =
2580 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
2581
2582 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
2583 if (!coalesce) {
2584 dev_dbg(adapter->dev,
2585 "Disable coalesce and reset all previous rules\n");
fa0ecbb9
BZ
2586 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
2587 HostCmd_ACT_GEN_SET, 0,
2588 &coalesce_cfg, true);
562fc5b3
AK
2589 }
2590
2591 coalesce_cfg.num_of_rules = coalesce->n_rules;
2592 for (i = 0; i < coalesce->n_rules; i++) {
2593 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
2594 &coalesce_cfg.rule[i]);
2595 if (ret) {
2596 dev_err(priv->adapter->dev,
2597 "Recheck the patterns provided for rule %d\n",
2598 i + 1);
2599 return ret;
2600 }
2601 }
2602
fa0ecbb9
BZ
2603 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
2604 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
562fc5b3
AK
2605}
2606
b23bce29
AP
2607/* cfg80211 ops handler for tdls_mgmt.
2608 * Function prepares TDLS action frame packets and forwards them to FW
2609 */
2610static int
2611mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 2612 const u8 *peer, u8 action_code, u8 dialog_token,
df942e7b
SDU
2613 u16 status_code, u32 peer_capability,
2614 const u8 *extra_ies, size_t extra_ies_len)
b23bce29
AP
2615{
2616 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2617 int ret;
2618
2619 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2620 return -ENOTSUPP;
2621
2622 /* make sure we are in station mode and connected */
2623 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
2624 return -ENOTSUPP;
2625
2626 switch (action_code) {
2627 case WLAN_TDLS_SETUP_REQUEST:
2628 dev_dbg(priv->adapter->dev,
2629 "Send TDLS Setup Request to %pM status_code=%d\n", peer,
2630 status_code);
2631 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2632 dialog_token, status_code,
2633 extra_ies, extra_ies_len);
2634 break;
2635 case WLAN_TDLS_SETUP_RESPONSE:
2636 dev_dbg(priv->adapter->dev,
2637 "Send TDLS Setup Response to %pM status_code=%d\n",
2638 peer, status_code);
2639 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2640 dialog_token, status_code,
2641 extra_ies, extra_ies_len);
2642 break;
2643 case WLAN_TDLS_SETUP_CONFIRM:
2644 dev_dbg(priv->adapter->dev,
2645 "Send TDLS Confirm to %pM status_code=%d\n", peer,
2646 status_code);
2647 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2648 dialog_token, status_code,
2649 extra_ies, extra_ies_len);
2650 break;
2651 case WLAN_TDLS_TEARDOWN:
2652 dev_dbg(priv->adapter->dev, "Send TDLS Tear down to %pM\n",
2653 peer);
2654 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2655 dialog_token, status_code,
2656 extra_ies, extra_ies_len);
2657 break;
2658 case WLAN_TDLS_DISCOVERY_REQUEST:
2659 dev_dbg(priv->adapter->dev,
2660 "Send TDLS Discovery Request to %pM\n", peer);
2661 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
2662 dialog_token, status_code,
2663 extra_ies, extra_ies_len);
2664 break;
2665 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2666 dev_dbg(priv->adapter->dev,
2667 "Send TDLS Discovery Response to %pM\n", peer);
2668 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
2669 dialog_token, status_code,
2670 extra_ies, extra_ies_len);
2671 break;
2672 default:
2673 dev_warn(priv->adapter->dev,
2674 "Unknown TDLS mgmt/action frame %pM\n", peer);
2675 ret = -EINVAL;
2676 break;
2677 }
2678
2679 return ret;
2680}
2681
429d90d2
AP
2682static int
2683mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 2684 const u8 *peer, enum nl80211_tdls_operation action)
429d90d2
AP
2685{
2686 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2687
2688 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
2689 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2690 return -ENOTSUPP;
2691
2692 /* make sure we are in station mode and connected */
2693 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
2694 return -ENOTSUPP;
2695
2696 dev_dbg(priv->adapter->dev,
2697 "TDLS peer=%pM, oper=%d\n", peer, action);
2698
2699 switch (action) {
2700 case NL80211_TDLS_ENABLE_LINK:
2701 action = MWIFIEX_TDLS_ENABLE_LINK;
2702 break;
2703 case NL80211_TDLS_DISABLE_LINK:
2704 action = MWIFIEX_TDLS_DISABLE_LINK;
2705 break;
2706 case NL80211_TDLS_TEARDOWN:
2707 /* shouldn't happen!*/
2708 dev_warn(priv->adapter->dev,
2709 "tdls_oper: teardown from driver not supported\n");
2710 return -EINVAL;
2711 case NL80211_TDLS_SETUP:
2712 /* shouldn't happen!*/
2713 dev_warn(priv->adapter->dev,
2714 "tdls_oper: setup from driver not supported\n");
2715 return -EINVAL;
2716 case NL80211_TDLS_DISCOVERY_REQ:
2717 /* shouldn't happen!*/
2718 dev_warn(priv->adapter->dev,
2719 "tdls_oper: discovery from driver not supported\n");
2720 return -EINVAL;
2721 default:
2722 dev_err(priv->adapter->dev,
2723 "tdls_oper: operation not supported\n");
2724 return -ENOTSUPP;
2725 }
2726
2727 return mwifiex_tdls_oper(priv, peer, action);
2728}
2729
e48e0de0 2730static int
3b3a0162
JB
2731mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
2732 const u8 *mac, struct station_parameters *params)
e48e0de0
AP
2733{
2734 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2735
2736 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2737 return -ENOTSUPP;
2738
2739 /* make sure we are in station mode and connected */
2740 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
2741 return -ENOTSUPP;
2742
2743 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
2744}
2745
1f4dfd8a 2746static int
3b3a0162
JB
2747mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
2748 const u8 *mac,
2749 struct station_parameters *params)
1f4dfd8a
AP
2750{
2751 int ret;
2752 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
2753
2754 /* we support change_station handler only for TDLS peers*/
2755 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2756 return -ENOTSUPP;
2757
2758 /* make sure we are in station mode and connected */
2759 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
2760 return -ENOTSUPP;
2761
2762 priv->sta_params = params;
2763
2764 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
2765 priv->sta_params = NULL;
2766
2767 return ret;
2768}
2769
5e6e3a92
BZ
2770/* station cfg80211 operations */
2771static struct cfg80211_ops mwifiex_cfg80211_ops = {
93a1df48
YAP
2772 .add_virtual_intf = mwifiex_add_virtual_intf,
2773 .del_virtual_intf = mwifiex_del_virtual_intf,
5e6e3a92
BZ
2774 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
2775 .scan = mwifiex_cfg80211_scan,
2776 .connect = mwifiex_cfg80211_connect,
2777 .disconnect = mwifiex_cfg80211_disconnect,
2778 .get_station = mwifiex_cfg80211_get_station,
f85aae6b 2779 .dump_station = mwifiex_cfg80211_dump_station,
5e6e3a92 2780 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
5e6e3a92
BZ
2781 .join_ibss = mwifiex_cfg80211_join_ibss,
2782 .leave_ibss = mwifiex_cfg80211_leave_ibss,
2783 .add_key = mwifiex_cfg80211_add_key,
2784 .del_key = mwifiex_cfg80211_del_key,
e39faa73 2785 .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
3cec6870 2786 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
7feb4c48
SP
2787 .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
2788 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
5e6e3a92
BZ
2789 .set_default_key = mwifiex_cfg80211_set_default_key,
2790 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
2791 .set_tx_power = mwifiex_cfg80211_set_tx_power,
5d82c53a 2792 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
12190c5d
AP
2793 .start_ap = mwifiex_cfg80211_start_ap,
2794 .stop_ap = mwifiex_cfg80211_stop_ap,
5370c836 2795 .change_beacon = mwifiex_cfg80211_change_beacon,
fa444bf8 2796 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
8a279d5b 2797 .set_antenna = mwifiex_cfg80211_set_antenna,
0f9e9b8b 2798 .del_station = mwifiex_cfg80211_del_station,
7da060c1
AK
2799#ifdef CONFIG_PM
2800 .suspend = mwifiex_cfg80211_suspend,
2801 .resume = mwifiex_cfg80211_resume,
2802 .set_wakeup = mwifiex_cfg80211_set_wakeup,
2803#endif
d1e2586f 2804 .set_coalesce = mwifiex_cfg80211_set_coalesce,
b23bce29 2805 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
429d90d2 2806 .tdls_oper = mwifiex_cfg80211_tdls_oper,
e48e0de0 2807 .add_station = mwifiex_cfg80211_add_station,
1f4dfd8a 2808 .change_station = mwifiex_cfg80211_change_station,
5e6e3a92
BZ
2809};
2810
964dc9e2
JB
2811#ifdef CONFIG_PM
2812static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
2813 .flags = WIPHY_WOWLAN_MAGIC_PKT,
3f4e854a 2814 .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
964dc9e2
JB
2815 .pattern_min_len = 1,
2816 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
2817 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2818};
2819#endif
2820
3c68ef5b
AP
2821static bool mwifiex_is_valid_alpha2(const char *alpha2)
2822{
2823 if (!alpha2 || strlen(alpha2) != 2)
2824 return false;
2825
2826 if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
2827 return true;
2828
2829 return false;
2830}
2831
562fc5b3
AK
2832static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
2833 .n_rules = MWIFIEX_COALESCE_MAX_RULES,
2834 .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
2835 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
2836 .pattern_min_len = 1,
2837 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
2838 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
2839};
2840
5e6e3a92
BZ
2841/*
2842 * This function registers the device with CFG802.11 subsystem.
2843 *
2844 * The function creates the wireless device/wiphy, populates it with
2845 * default parameters and handler function pointers, and finally
2846 * registers the device.
2847 */
d6bffe8b
AP
2848
2849int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
5e6e3a92 2850{
270e58e8
YAP
2851 int ret;
2852 void *wdev_priv;
d6bffe8b
AP
2853 struct wiphy *wiphy;
2854 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
9e04a7c6 2855 u8 *country_code;
f862bfd1 2856 u32 thr, retry;
5e6e3a92 2857
d6bffe8b
AP
2858 /* create a new wiphy for use with cfg80211 */
2859 wiphy = wiphy_new(&mwifiex_cfg80211_ops,
2860 sizeof(struct mwifiex_adapter *));
2861 if (!wiphy) {
2862 dev_err(adapter->dev, "%s: creating new wiphy\n", __func__);
5e6e3a92
BZ
2863 return -ENOMEM;
2864 }
d6bffe8b
AP
2865 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
2866 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
83719be8 2867 wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
7feb4c48 2868 wiphy->max_remain_on_channel_duration = 5000;
d6bffe8b
AP
2869 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2870 BIT(NL80211_IFTYPE_ADHOC) |
197f4a2e
SP
2871 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2872 BIT(NL80211_IFTYPE_P2P_GO) |
d6bffe8b
AP
2873 BIT(NL80211_IFTYPE_AP);
2874
2875 wiphy->bands[IEEE80211_BAND_2GHZ] = &mwifiex_band_2ghz;
2876 if (adapter->config_bands & BAND_A)
2877 wiphy->bands[IEEE80211_BAND_5GHZ] = &mwifiex_band_5ghz;
2878 else
2879 wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
5e6e3a92 2880
cd8440da
AP
2881 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
2882 wiphy->n_iface_combinations = 1;
2883
5e6e3a92 2884 /* Initialize cipher suits */
d6bffe8b
AP
2885 wiphy->cipher_suites = mwifiex_cipher_suites;
2886 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
5e6e3a92 2887
d6bffe8b
AP
2888 memcpy(wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
2889 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2dd2bd6b 2890 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
cc0ba0d5 2891 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
54428c57 2892 WIPHY_FLAG_AP_UAPSD |
7feb4c48 2893 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
b23bce29
AP
2894
2895 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
2896 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
2897 WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
2898
7da060c1 2899#ifdef CONFIG_PM
964dc9e2 2900 wiphy->wowlan = &mwifiex_wowlan_support;
7da060c1
AK
2901#endif
2902
562fc5b3
AK
2903 wiphy->coalesce = &mwifiex_coalesce_support;
2904
2dd2bd6b 2905 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
e39faa73
SP
2906 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2907 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5e6e3a92 2908
8a279d5b
AK
2909 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
2910 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
5e6e3a92 2911
b292219f 2912 wiphy->features |= NL80211_FEATURE_HT_IBSS |
e45a8419 2913 NL80211_FEATURE_INACTIVITY_TIMER |
e3c91683
AK
2914 NL80211_FEATURE_LOW_PRIORITY_SCAN |
2915 NL80211_FEATURE_NEED_OBSS_SCAN;
05910f4a 2916
b5abcf02 2917 /* Reserve space for mwifiex specific private data for BSS */
d6bffe8b 2918 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
5116f3ce 2919
d6bffe8b 2920 wiphy->reg_notifier = mwifiex_reg_notifier;
5e6e3a92 2921
67fdf39e 2922 /* Set struct mwifiex_adapter pointer in wiphy_priv */
d6bffe8b 2923 wdev_priv = wiphy_priv(wiphy);
67fdf39e 2924 *(unsigned long *)wdev_priv = (unsigned long)adapter;
5e6e3a92 2925
2c208890 2926 set_wiphy_dev(wiphy, priv->adapter->dev);
a7b21165 2927
d6bffe8b 2928 ret = wiphy_register(wiphy);
5e6e3a92 2929 if (ret < 0) {
d6bffe8b
AP
2930 dev_err(adapter->dev,
2931 "%s: wiphy_register failed: %d\n", __func__, ret);
2932 wiphy_free(wiphy);
5e6e3a92 2933 return ret;
5e6e3a92 2934 }
3c68ef5b
AP
2935
2936 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
2937 wiphy_info(wiphy, "driver hint alpha2: %2.2s\n", reg_alpha2);
2938 regulatory_hint(wiphy, reg_alpha2);
2939 } else {
2940 country_code = mwifiex_11d_code_2_region(adapter->region_code);
2941 if (country_code)
2942 wiphy_info(wiphy, "ignoring F/W country code %2.2s\n",
2943 country_code);
2944 }
5e6e3a92 2945
fa0ecbb9
BZ
2946 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2947 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
f862bfd1 2948 wiphy->frag_threshold = thr;
fa0ecbb9
BZ
2949 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2950 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
f862bfd1 2951 wiphy->rts_threshold = thr;
fa0ecbb9
BZ
2952 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2953 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
f862bfd1 2954 wiphy->retry_short = (u8) retry;
fa0ecbb9
BZ
2955 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2956 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
f862bfd1
UR
2957 wiphy->retry_long = (u8) retry;
2958
d6bffe8b 2959 adapter->wiphy = wiphy;
5e6e3a92
BZ
2960 return ret;
2961}
This page took 0.708577 seconds and 5 git commands to generate.