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