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