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