1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
4 #include <linux/kernel.h>
5 #include <linux/etherdevice.h>
6 #include <linux/vmalloc.h>
7 #include <linux/ieee80211.h>
8 #include <net/cfg80211.h>
9 #include <net/netlink.h>
17 /* Supported rates to be advertised to the cfg80211 */
18 static struct ieee80211_rate qtnf_rates_2g[] = {
19 {.bitrate = 10, .hw_value = 2, },
20 {.bitrate = 20, .hw_value = 4, },
21 {.bitrate = 55, .hw_value = 11, },
22 {.bitrate = 110, .hw_value = 22, },
23 {.bitrate = 60, .hw_value = 12, },
24 {.bitrate = 90, .hw_value = 18, },
25 {.bitrate = 120, .hw_value = 24, },
26 {.bitrate = 180, .hw_value = 36, },
27 {.bitrate = 240, .hw_value = 48, },
28 {.bitrate = 360, .hw_value = 72, },
29 {.bitrate = 480, .hw_value = 96, },
30 {.bitrate = 540, .hw_value = 108, },
33 /* Supported rates to be advertised to the cfg80211 */
34 static struct ieee80211_rate qtnf_rates_5g[] = {
35 {.bitrate = 60, .hw_value = 12, },
36 {.bitrate = 90, .hw_value = 18, },
37 {.bitrate = 120, .hw_value = 24, },
38 {.bitrate = 180, .hw_value = 36, },
39 {.bitrate = 240, .hw_value = 48, },
40 {.bitrate = 360, .hw_value = 72, },
41 {.bitrate = 480, .hw_value = 96, },
42 {.bitrate = 540, .hw_value = 108, },
45 /* Supported crypto cipher suits to be advertised to cfg80211 */
46 static const u32 qtnf_cipher_suites[] = {
47 WLAN_CIPHER_SUITE_TKIP,
48 WLAN_CIPHER_SUITE_CCMP,
49 WLAN_CIPHER_SUITE_AES_CMAC,
52 /* Supported mgmt frame types to be advertised to cfg80211 */
53 static const struct ieee80211_txrx_stypes
54 qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
55 [NL80211_IFTYPE_STATION] = {
56 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
57 BIT(IEEE80211_STYPE_AUTH >> 4),
58 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
59 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
60 BIT(IEEE80211_STYPE_AUTH >> 4),
62 [NL80211_IFTYPE_AP] = {
63 .tx = BIT(IEEE80211_STYPE_ACTION >> 4),
64 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
65 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
66 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
67 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
68 BIT(IEEE80211_STYPE_AUTH >> 4),
73 qtnf_validate_iface_combinations(struct wiphy *wiphy,
74 struct qtnf_vif *change_vif,
75 enum nl80211_iftype new_type)
77 struct qtnf_wmac *mac;
81 struct iface_combination_params params = {
82 .num_different_channels = 1,
85 mac = wiphy_priv(wiphy);
89 for (i = 0; i < QTNF_MAX_INTF; i++) {
90 vif = &mac->iflist[i];
91 if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
92 params.iftype_num[vif->wdev.iftype]++;
96 params.iftype_num[new_type]++;
97 params.iftype_num[change_vif->wdev.iftype]--;
99 params.iftype_num[new_type]++;
102 ret = cfg80211_check_combinations(wiphy, ¶ms);
108 qtnf_change_virtual_intf(struct wiphy *wiphy,
109 struct net_device *dev,
110 enum nl80211_iftype type,
111 struct vif_params *params)
113 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
118 ret = qtnf_validate_iface_combinations(wiphy, vif, type);
120 pr_err("VIF%u.%u combination check: failed to set type %d\n",
121 vif->mac->macid, vif->vifid, type);
126 mac_addr = params->macaddr;
127 use4addr = params->use_4addr;
130 qtnf_scan_done(vif->mac, true);
132 ret = qtnf_cmd_send_change_intf_type(vif, type, use4addr, mac_addr);
134 pr_err("VIF%u.%u: failed to change type to %d\n",
135 vif->mac->macid, vif->vifid, type);
139 vif->wdev.iftype = type;
143 int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
145 struct net_device *netdev = wdev->netdev;
146 struct qtnf_vif *vif;
149 if (WARN_ON(!netdev))
152 vif = qtnf_netdev_get_priv(wdev->netdev);
154 qtnf_scan_done(vif->mac, true);
157 netif_tx_stop_all_queues(netdev);
158 if (netif_carrier_ok(netdev))
159 netif_carrier_off(netdev);
161 while ((skb = skb_dequeue(&vif->high_pri_tx_queue)))
162 dev_kfree_skb_any(skb);
164 cancel_work_sync(&vif->high_pri_tx_work);
166 if (netdev->reg_state == NETREG_REGISTERED)
167 unregister_netdevice(netdev);
169 if (qtnf_cmd_send_del_intf(vif))
170 pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
173 vif->netdev->ieee80211_ptr = NULL;
175 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
180 static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
182 unsigned char name_assign_t,
183 enum nl80211_iftype type,
184 struct vif_params *params)
186 struct qtnf_wmac *mac;
187 struct qtnf_vif *vif;
192 mac = wiphy_priv(wiphy);
195 return ERR_PTR(-EFAULT);
197 ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
199 pr_err("MAC%u invalid combination: failed to add type %d\n",
205 case NL80211_IFTYPE_STATION:
206 case NL80211_IFTYPE_AP:
207 vif = qtnf_mac_get_free_vif(mac);
209 pr_err("MAC%u: no free VIF available\n", mac->macid);
210 return ERR_PTR(-EFAULT);
213 eth_zero_addr(vif->mac_addr);
214 eth_zero_addr(vif->bssid);
215 vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
216 memset(&vif->wdev, 0, sizeof(vif->wdev));
217 vif->wdev.wiphy = wiphy;
218 vif->wdev.iftype = type;
221 pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
222 return ERR_PTR(-ENOTSUPP);
226 mac_addr = params->macaddr;
227 use4addr = params->use_4addr;
230 ret = qtnf_cmd_send_add_intf(vif, type, use4addr, mac_addr);
232 pr_err("VIF%u.%u: failed to add VIF %pM\n",
233 mac->macid, vif->vifid, mac_addr);
237 if (!is_valid_ether_addr(vif->mac_addr)) {
238 pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
239 mac->macid, vif->vifid, vif->mac_addr);
244 ret = qtnf_core_net_attach(mac, vif, name, name_assign_t);
246 pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
251 vif->wdev.netdev = vif->netdev;
257 qtnf_cmd_send_del_intf(vif);
259 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
264 static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
265 const struct cfg80211_beacon_data *info)
269 if (!info->beacon_ies || !info->beacon_ies_len) {
270 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
273 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
275 info->beacon_ies_len);
281 if (!info->proberesp_ies || !info->proberesp_ies_len) {
282 ret = qtnf_cmd_send_mgmt_set_appie(vif,
283 QLINK_IE_SET_PROBE_RESP_IES,
286 ret = qtnf_cmd_send_mgmt_set_appie(vif,
287 QLINK_IE_SET_PROBE_RESP_IES,
289 info->proberesp_ies_len);
295 if (!info->assocresp_ies || !info->assocresp_ies_len) {
296 ret = qtnf_cmd_send_mgmt_set_appie(vif,
297 QLINK_IE_SET_ASSOC_RESP,
300 ret = qtnf_cmd_send_mgmt_set_appie(vif,
301 QLINK_IE_SET_ASSOC_RESP,
303 info->assocresp_ies_len);
310 static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
311 struct cfg80211_beacon_data *info)
313 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
315 return qtnf_mgmt_set_appie(vif, info);
318 static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
319 struct cfg80211_ap_settings *settings)
321 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
324 ret = qtnf_cmd_send_start_ap(vif, settings);
326 pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
332 static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev)
334 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
337 qtnf_scan_done(vif->mac, true);
339 ret = qtnf_cmd_send_stop_ap(vif);
341 pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
342 vif->mac->macid, vif->vifid);
344 netif_carrier_off(vif->netdev);
349 static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
351 struct qtnf_wmac *mac = wiphy_priv(wiphy);
352 struct qtnf_vif *vif;
355 vif = qtnf_mac_get_base_vif(mac);
357 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
361 ret = qtnf_cmd_send_update_phy_params(mac, changed);
363 pr_err("MAC%u: failed to update PHY params\n", mac->macid);
369 qtnf_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
370 u16 frame_type, bool reg)
372 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
375 u16 qlink_frame_type = 0;
377 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
380 new_mask = vif->mgmt_frames_bitmask | BIT(mgmt_type);
382 new_mask = vif->mgmt_frames_bitmask & ~BIT(mgmt_type);
384 if (new_mask == vif->mgmt_frames_bitmask)
387 switch (frame_type & IEEE80211_FCTL_STYPE) {
388 case IEEE80211_STYPE_REASSOC_REQ:
389 case IEEE80211_STYPE_ASSOC_REQ:
390 qlink_frame_type = QLINK_MGMT_FRAME_ASSOC_REQ;
392 case IEEE80211_STYPE_AUTH:
393 qlink_frame_type = QLINK_MGMT_FRAME_AUTH;
395 case IEEE80211_STYPE_PROBE_REQ:
396 qlink_frame_type = QLINK_MGMT_FRAME_PROBE_REQ;
398 case IEEE80211_STYPE_ACTION:
399 qlink_frame_type = QLINK_MGMT_FRAME_ACTION;
402 pr_warn("VIF%u.%u: unsupported frame type: %X\n",
403 vif->mac->macid, vif->vifid,
404 (frame_type & IEEE80211_FCTL_STYPE) >> 4);
408 if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg)) {
409 pr_warn("VIF%u.%u: failed to %sregister mgmt frame type 0x%x\n",
410 vif->mac->macid, vif->vifid, reg ? "" : "un",
415 vif->mgmt_frames_bitmask = new_mask;
416 pr_debug("VIF%u.%u: %sregistered mgmt frame type 0x%x\n",
417 vif->mac->macid, vif->vifid, reg ? "" : "un", frame_type);
421 qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
422 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
424 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
425 const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
426 u32 short_cookie = prandom_u32();
430 *cookie = short_cookie;
433 flags |= QLINK_FRAME_TX_FLAG_OFFCHAN;
436 flags |= QLINK_FRAME_TX_FLAG_NO_CCK;
438 if (params->dont_wait_for_ack)
439 flags |= QLINK_FRAME_TX_FLAG_ACK_NOWAIT;
441 /* If channel is not specified, pass "freq = 0" to tell device
442 * firmware to use current channel.
445 freq = params->chan->center_freq;
449 pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
450 wdev->netdev->name, freq,
451 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
452 params->len, short_cookie, flags);
454 return qtnf_cmd_send_frame(vif, short_cookie, flags,
455 freq, params->buf, params->len);
459 qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
460 const u8 *mac, struct station_info *sinfo)
462 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
464 sinfo->generation = vif->generation;
465 return qtnf_cmd_get_sta_info(vif, mac, sinfo);
469 qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
470 int idx, u8 *mac, struct station_info *sinfo)
472 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
473 const struct qtnf_sta_node *sta_node;
476 switch (vif->wdev.iftype) {
477 case NL80211_IFTYPE_STATION:
478 if (idx != 0 || !vif->wdev.current_bss)
481 ether_addr_copy(mac, vif->bssid);
483 case NL80211_IFTYPE_AP:
484 sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
485 if (unlikely(!sta_node))
488 ether_addr_copy(mac, sta_node->mac_addr);
494 ret = qtnf_cmd_get_sta_info(vif, mac, sinfo);
496 if (vif->wdev.iftype == NL80211_IFTYPE_AP) {
497 if (ret == -ENOENT) {
498 cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
503 sinfo->generation = vif->generation;
508 static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
509 u8 key_index, bool pairwise, const u8 *mac_addr,
510 struct key_params *params)
512 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
515 ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
517 pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
518 vif->mac->macid, vif->vifid, params->cipher, key_index,
524 static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
525 u8 key_index, bool pairwise, const u8 *mac_addr)
527 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
530 ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
532 if (ret == -ENOENT) {
533 pr_debug("VIF%u.%u: key index %d out of bounds\n",
534 vif->mac->macid, vif->vifid, key_index);
536 pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
537 vif->mac->macid, vif->vifid,
538 key_index, pairwise);
545 static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
546 u8 key_index, bool unicast, bool multicast)
548 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
551 ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
553 pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
554 vif->mac->macid, vif->vifid, key_index, unicast,
561 qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
564 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
567 ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
569 pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
570 vif->mac->macid, vif->vifid, key_index);
576 qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
577 const u8 *mac, struct station_parameters *params)
579 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
582 ret = qtnf_cmd_send_change_sta(vif, mac, params);
584 pr_err("VIF%u.%u: failed to change STA %pM\n",
585 vif->mac->macid, vif->vifid, mac);
591 qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
592 struct station_del_parameters *params)
594 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
598 (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
599 !is_broadcast_ether_addr(params->mac) &&
600 !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
603 ret = qtnf_cmd_send_del_sta(vif, params);
605 pr_err("VIF%u.%u: failed to delete STA %pM\n",
606 vif->mac->macid, vif->vifid, params->mac);
612 qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
614 struct qtnf_wmac *mac = wiphy_priv(wiphy);
617 cancel_delayed_work_sync(&mac->scan_timeout);
619 mac->scan_req = request;
621 ret = qtnf_cmd_send_scan(mac);
623 pr_err("MAC%u: failed to start scan\n", mac->macid);
624 mac->scan_req = NULL;
628 pr_debug("MAC%u: scan started\n", mac->macid);
629 queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
630 QTNF_SCAN_TIMEOUT_SEC * HZ);
637 qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
638 struct cfg80211_connect_params *sme)
640 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
643 if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
646 if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
647 !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
648 pr_err("can not offload authentication to userspace\n");
653 ether_addr_copy(vif->bssid, sme->bssid);
655 eth_zero_addr(vif->bssid);
657 ret = qtnf_cmd_send_connect(vif, sme);
659 pr_err("VIF%u.%u: failed to connect\n",
660 vif->mac->macid, vif->vifid);
669 qtnf_external_auth(struct wiphy *wiphy, struct net_device *dev,
670 struct cfg80211_external_auth_params *auth)
672 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
675 if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
678 if (!ether_addr_equal(vif->bssid, auth->bssid))
679 pr_warn("unexpected bssid: %pM", auth->bssid);
681 ret = qtnf_cmd_send_external_auth(vif, auth);
683 pr_err("VIF%u.%u: failed to report external auth\n",
684 vif->mac->macid, vif->vifid);
693 qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
696 struct qtnf_wmac *mac = wiphy_priv(wiphy);
697 struct qtnf_vif *vif;
700 vif = qtnf_mac_get_base_vif(mac);
702 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
706 if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
711 ret = qtnf_cmd_send_disconnect(vif, reason_code);
713 pr_err("VIF%u.%u: failed to disconnect\n",
714 mac->macid, vif->vifid);
716 if (vif->wdev.current_bss) {
717 netif_carrier_off(vif->netdev);
718 cfg80211_disconnected(vif->netdev, reason_code,
719 NULL, 0, true, GFP_KERNEL);
727 qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
728 int idx, struct survey_info *survey)
730 struct qtnf_wmac *mac = wiphy_priv(wiphy);
731 struct wireless_dev *wdev = dev->ieee80211_ptr;
732 struct ieee80211_supported_band *sband;
733 const struct cfg80211_chan_def *chandef = &wdev->chandef;
734 struct ieee80211_channel *chan;
735 struct qtnf_chan_stats stats;
738 sband = wiphy->bands[NL80211_BAND_2GHZ];
739 if (sband && idx >= sband->n_channels) {
740 idx -= sband->n_channels;
745 sband = wiphy->bands[NL80211_BAND_5GHZ];
747 if (!sband || idx >= sband->n_channels)
750 chan = &sband->channels[idx];
751 memset(&stats, 0, sizeof(stats));
753 survey->channel = chan;
754 survey->filled = 0x0;
757 if (chan->hw_value == chandef->chan->hw_value)
758 survey->filled = SURVEY_INFO_IN_USE;
761 ret = qtnf_cmd_get_chan_stats(mac, chan->hw_value, &stats);
764 if (unlikely(stats.chan_num != chan->hw_value)) {
765 pr_err("received stats for channel %d instead of %d\n",
766 stats.chan_num, chan->hw_value);
771 survey->filled |= SURVEY_INFO_TIME |
772 SURVEY_INFO_TIME_SCAN |
773 SURVEY_INFO_TIME_BUSY |
774 SURVEY_INFO_TIME_RX |
775 SURVEY_INFO_TIME_TX |
776 SURVEY_INFO_NOISE_DBM;
778 survey->time_scan = stats.cca_try;
779 survey->time = stats.cca_try;
780 survey->time_tx = stats.cca_tx;
781 survey->time_rx = stats.cca_rx;
782 survey->time_busy = stats.cca_busy;
783 survey->noise = stats.chan_noise;
786 pr_debug("no stats for channel %u\n", chan->hw_value);
790 pr_debug("failed to get chan(%d) stats from card\n",
799 qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
800 struct cfg80211_chan_def *chandef)
802 struct net_device *ndev = wdev->netdev;
803 struct qtnf_vif *vif;
809 vif = qtnf_netdev_get_priv(wdev->netdev);
811 ret = qtnf_cmd_get_channel(vif, chandef);
813 pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
818 if (!cfg80211_chandef_valid(chandef)) {
819 pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
820 ndev->name, chandef->chan->center_freq,
821 chandef->center_freq1, chandef->center_freq2,
831 static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
832 struct cfg80211_csa_settings *params)
834 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
837 pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
838 params->chandef.chan->hw_value, params->count,
839 params->radar_required, params->block_tx);
841 if (!cfg80211_chandef_valid(¶ms->chandef)) {
842 pr_err("%s: invalid channel\n", dev->name);
846 ret = qtnf_cmd_send_chan_switch(vif, params);
848 pr_warn("%s: failed to switch to channel (%u)\n",
849 dev->name, params->chandef.chan->hw_value);
854 static int qtnf_start_radar_detection(struct wiphy *wiphy,
855 struct net_device *ndev,
856 struct cfg80211_chan_def *chandef,
859 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
862 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
865 ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
867 pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
872 static int qtnf_set_mac_acl(struct wiphy *wiphy,
873 struct net_device *dev,
874 const struct cfg80211_acl_data *params)
876 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
879 ret = qtnf_cmd_set_mac_acl(vif, params);
881 pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
886 static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
887 bool enabled, int timeout)
889 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
892 ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
893 QLINK_PM_OFF, timeout);
895 pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
901 static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
903 struct qtnf_wmac *mac = wiphy_priv(wiphy);
904 struct qtnf_vif *vif;
907 vif = qtnf_mac_get_base_vif(mac);
909 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
915 pr_debug("WoWLAN triggers are not enabled\n");
916 qtnf_virtual_intf_cleanup(vif->netdev);
920 qtnf_scan_done(vif->mac, true);
922 ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
924 pr_err("MAC%u: failed to set WoWLAN triggers\n",
933 static int qtnf_resume(struct wiphy *wiphy)
935 struct qtnf_wmac *mac = wiphy_priv(wiphy);
936 struct qtnf_vif *vif;
939 vif = qtnf_mac_get_base_vif(mac);
941 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
946 ret = qtnf_cmd_send_wowlan_set(vif, NULL);
948 pr_err("MAC%u: failed to reset WoWLAN triggers\n",
957 static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
959 struct qtnf_wmac *mac = wiphy_priv(wiphy);
960 struct qtnf_bus *bus = mac->bus;
962 device_set_wakeup_enable(bus->dev, enabled);
966 static struct cfg80211_ops qtn_cfg80211_ops = {
967 .add_virtual_intf = qtnf_add_virtual_intf,
968 .change_virtual_intf = qtnf_change_virtual_intf,
969 .del_virtual_intf = qtnf_del_virtual_intf,
970 .start_ap = qtnf_start_ap,
971 .change_beacon = qtnf_change_beacon,
972 .stop_ap = qtnf_stop_ap,
973 .set_wiphy_params = qtnf_set_wiphy_params,
974 .mgmt_frame_register = qtnf_mgmt_frame_register,
975 .mgmt_tx = qtnf_mgmt_tx,
976 .change_station = qtnf_change_station,
977 .del_station = qtnf_del_station,
978 .get_station = qtnf_get_station,
979 .dump_station = qtnf_dump_station,
980 .add_key = qtnf_add_key,
981 .del_key = qtnf_del_key,
982 .set_default_key = qtnf_set_default_key,
983 .set_default_mgmt_key = qtnf_set_default_mgmt_key,
985 .connect = qtnf_connect,
986 .external_auth = qtnf_external_auth,
987 .disconnect = qtnf_disconnect,
988 .dump_survey = qtnf_dump_survey,
989 .get_channel = qtnf_get_channel,
990 .channel_switch = qtnf_channel_switch,
991 .start_radar_detection = qtnf_start_radar_detection,
992 .set_mac_acl = qtnf_set_mac_acl,
993 .set_power_mgmt = qtnf_set_power_mgmt,
995 .suspend = qtnf_suspend,
996 .resume = qtnf_resume,
997 .set_wakeup = qtnf_set_wakeup,
1001 static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy,
1002 struct regulatory_request *req)
1004 struct qtnf_wmac *mac = wiphy_priv(wiphy);
1005 enum nl80211_band band;
1008 pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
1009 req->alpha2[0], req->alpha2[1]);
1011 ret = qtnf_cmd_reg_notify(mac, req, qtnf_mac_slave_radar_get(wiphy));
1013 pr_err("MAC%u: failed to update region to %c%c: %d\n",
1014 mac->macid, req->alpha2[0], req->alpha2[1], ret);
1018 for (band = 0; band < NUM_NL80211_BANDS; ++band) {
1019 if (!wiphy->bands[band])
1022 ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
1024 pr_err("MAC%u: failed to update band %u\n",
1029 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus)
1031 struct wiphy *wiphy;
1033 if (bus->hw_info.hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
1034 qtn_cfg80211_ops.start_radar_detection = NULL;
1036 if (!(bus->hw_info.hw_capab & QLINK_HW_CAPAB_PWR_MGMT))
1037 qtn_cfg80211_ops.set_power_mgmt = NULL;
1039 wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
1043 set_wiphy_dev(wiphy, bus->dev);
1049 qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
1051 struct ieee80211_iface_combination *if_comb;
1053 u16 interface_modes = 0;
1056 if_comb = mac_info->if_comb;
1057 n_if_comb = mac_info->n_if_comb;
1059 if (!if_comb || !n_if_comb)
1062 for (i = 0; i < n_if_comb; i++) {
1063 if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
1065 for (j = 0; j < if_comb[i].n_limits; j++)
1066 interface_modes |= if_comb[i].limits[j].types;
1069 wiphy->iface_combinations = if_comb;
1070 wiphy->n_iface_combinations = n_if_comb;
1071 wiphy->interface_modes = interface_modes;
1076 int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
1078 struct wiphy *wiphy = priv_to_wiphy(mac);
1079 struct qtnf_mac_info *macinfo = &mac->macinfo;
1081 bool regdomain_is_known;
1084 pr_err("invalid wiphy pointer\n");
1088 wiphy->frag_threshold = macinfo->frag_thr;
1089 wiphy->rts_threshold = macinfo->rts_thr;
1090 wiphy->retry_short = macinfo->sretry_limit;
1091 wiphy->retry_long = macinfo->lretry_limit;
1092 wiphy->coverage_class = macinfo->coverage_class;
1094 wiphy->max_scan_ssids =
1095 (hw_info->max_scan_ssids) ? hw_info->max_scan_ssids : 1;
1096 wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
1097 wiphy->mgmt_stypes = qtnf_mgmt_stypes;
1098 wiphy->max_remain_on_channel_duration = 5000;
1099 wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
1100 wiphy->max_num_csa_counters = 2;
1102 ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
1106 /* Initialize cipher suits */
1107 wiphy->cipher_suites = qtnf_cipher_suites;
1108 wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
1109 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1110 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1111 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1112 WIPHY_FLAG_AP_UAPSD |
1113 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
1114 WIPHY_FLAG_4ADDR_STATION |
1115 WIPHY_FLAG_NETNS_OK;
1116 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1118 if (hw_info->hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
1119 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
1121 if (hw_info->hw_capab & QLINK_HW_CAPAB_SCAN_DWELL)
1122 wiphy_ext_feature_set(wiphy,
1123 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
1125 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1126 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1128 wiphy->available_antennas_tx = macinfo->num_tx_chain;
1129 wiphy->available_antennas_rx = macinfo->num_rx_chain;
1131 wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
1132 wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
1133 wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
1135 ether_addr_copy(wiphy->perm_addr, mac->macaddr);
1137 if (hw_info->hw_capab & QLINK_HW_CAPAB_STA_INACT_TIMEOUT)
1138 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1140 if (hw_info->hw_capab & QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR)
1141 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
1143 if (!(hw_info->hw_capab & QLINK_HW_CAPAB_OBSS_SCAN))
1144 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
1146 if (hw_info->hw_capab & QLINK_HW_CAPAB_SAE)
1147 wiphy->features |= NL80211_FEATURE_SAE;
1150 if (macinfo->wowlan)
1151 wiphy->wowlan = macinfo->wowlan;
1154 regdomain_is_known = isalpha(mac->rd->alpha2[0]) &&
1155 isalpha(mac->rd->alpha2[1]);
1157 if (hw_info->hw_capab & QLINK_HW_CAPAB_REG_UPDATE) {
1158 wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
1160 if (mac->rd->alpha2[0] == '9' && mac->rd->alpha2[1] == '9') {
1161 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
1162 REGULATORY_STRICT_REG;
1163 wiphy_apply_custom_regulatory(wiphy, mac->rd);
1164 } else if (regdomain_is_known) {
1165 wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
1168 wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
1171 if (mac->macinfo.extended_capabilities_len) {
1172 wiphy->extended_capabilities =
1173 mac->macinfo.extended_capabilities;
1174 wiphy->extended_capabilities_mask =
1175 mac->macinfo.extended_capabilities_mask;
1176 wiphy->extended_capabilities_len =
1177 mac->macinfo.extended_capabilities_len;
1180 strlcpy(wiphy->fw_version, hw_info->fw_version,
1181 sizeof(wiphy->fw_version));
1182 wiphy->hw_version = hw_info->hw_version;
1184 ret = wiphy_register(wiphy);
1188 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1189 ret = regulatory_set_wiphy_regd(wiphy, mac->rd);
1190 else if (regdomain_is_known)
1191 ret = regulatory_hint(wiphy, mac->rd->alpha2);
1197 void qtnf_netdev_updown(struct net_device *ndev, bool up)
1199 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1201 if (qtnf_cmd_send_updown_intf(vif, up))
1202 pr_err("failed to send %s command to VIF%u.%u\n",
1203 up ? "UP" : "DOWN", vif->mac->macid, vif->vifid);
1206 void qtnf_virtual_intf_cleanup(struct net_device *ndev)
1208 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1209 struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
1211 if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1212 qtnf_disconnect(vif->wdev.wiphy, ndev,
1213 WLAN_REASON_DEAUTH_LEAVING);
1215 qtnf_scan_done(mac, true);
1218 void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
1220 if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1221 cfg80211_disconnected(vif->netdev, WLAN_REASON_DEAUTH_LEAVING,
1222 NULL, 0, 1, GFP_KERNEL);
1224 cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
1227 void qtnf_band_init_rates(struct ieee80211_supported_band *band)
1229 switch (band->band) {
1230 case NL80211_BAND_2GHZ:
1231 band->bitrates = qtnf_rates_2g;
1232 band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
1234 case NL80211_BAND_5GHZ:
1235 band->bitrates = qtnf_rates_5g;
1236 band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
1239 band->bitrates = NULL;
1240 band->n_bitrates = 0;