2 * Copyright (c) 2012-2012 Quantenna Communications, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/etherdevice.h>
19 #include <linux/vmalloc.h>
20 #include <linux/ieee80211.h>
21 #include <net/cfg80211.h>
22 #include <net/netlink.h>
30 /* Supported rates to be advertised to the cfg80211 */
31 static struct ieee80211_rate qtnf_rates_2g[] = {
32 {.bitrate = 10, .hw_value = 2, },
33 {.bitrate = 20, .hw_value = 4, },
34 {.bitrate = 55, .hw_value = 11, },
35 {.bitrate = 110, .hw_value = 22, },
36 {.bitrate = 60, .hw_value = 12, },
37 {.bitrate = 90, .hw_value = 18, },
38 {.bitrate = 120, .hw_value = 24, },
39 {.bitrate = 180, .hw_value = 36, },
40 {.bitrate = 240, .hw_value = 48, },
41 {.bitrate = 360, .hw_value = 72, },
42 {.bitrate = 480, .hw_value = 96, },
43 {.bitrate = 540, .hw_value = 108, },
46 /* Supported rates to be advertised to the cfg80211 */
47 static struct ieee80211_rate qtnf_rates_5g[] = {
48 {.bitrate = 60, .hw_value = 12, },
49 {.bitrate = 90, .hw_value = 18, },
50 {.bitrate = 120, .hw_value = 24, },
51 {.bitrate = 180, .hw_value = 36, },
52 {.bitrate = 240, .hw_value = 48, },
53 {.bitrate = 360, .hw_value = 72, },
54 {.bitrate = 480, .hw_value = 96, },
55 {.bitrate = 540, .hw_value = 108, },
58 /* Supported crypto cipher suits to be advertised to cfg80211 */
59 static const u32 qtnf_cipher_suites[] = {
60 WLAN_CIPHER_SUITE_TKIP,
61 WLAN_CIPHER_SUITE_CCMP,
62 WLAN_CIPHER_SUITE_AES_CMAC,
65 /* Supported mgmt frame types to be advertised to cfg80211 */
66 static const struct ieee80211_txrx_stypes
67 qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
68 [NL80211_IFTYPE_STATION] = {
69 .tx = BIT(IEEE80211_STYPE_ACTION >> 4),
70 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
71 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
73 [NL80211_IFTYPE_AP] = {
74 .tx = BIT(IEEE80211_STYPE_ACTION >> 4),
75 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
76 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
81 qtnf_change_virtual_intf(struct wiphy *wiphy,
82 struct net_device *dev,
83 enum nl80211_iftype type,
84 struct vif_params *params)
86 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
91 mac_addr = params->macaddr;
95 qtnf_scan_done(vif->mac, true);
97 ret = qtnf_cmd_send_change_intf_type(vif, type, mac_addr);
99 pr_err("VIF%u.%u: failed to change VIF type: %d\n",
100 vif->mac->macid, vif->vifid, ret);
104 vif->wdev.iftype = type;
108 int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
110 struct net_device *netdev = wdev->netdev;
111 struct qtnf_vif *vif;
113 if (WARN_ON(!netdev))
116 vif = qtnf_netdev_get_priv(wdev->netdev);
118 if (qtnf_cmd_send_del_intf(vif))
119 pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
123 netif_tx_stop_all_queues(netdev);
124 if (netif_carrier_ok(netdev))
125 netif_carrier_off(netdev);
127 if (netdev->reg_state == NETREG_REGISTERED)
128 unregister_netdevice(netdev);
130 vif->netdev->ieee80211_ptr = NULL;
132 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
133 eth_zero_addr(vif->mac_addr);
138 static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
140 unsigned char name_assign_t,
141 enum nl80211_iftype type,
142 struct vif_params *params)
144 struct qtnf_wmac *mac;
145 struct qtnf_vif *vif;
148 mac = wiphy_priv(wiphy);
151 return ERR_PTR(-EFAULT);
154 case NL80211_IFTYPE_STATION:
155 case NL80211_IFTYPE_AP:
156 vif = qtnf_mac_get_free_vif(mac);
158 pr_err("MAC%u: no free VIF available\n", mac->macid);
159 return ERR_PTR(-EFAULT);
162 eth_zero_addr(vif->mac_addr);
163 vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
164 vif->wdev.wiphy = wiphy;
165 vif->wdev.iftype = type;
166 vif->sta_state = QTNF_STA_DISCONNECTED;
169 pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
170 return ERR_PTR(-ENOTSUPP);
174 mac_addr = params->macaddr;
176 if (qtnf_cmd_send_add_intf(vif, type, mac_addr)) {
177 pr_err("VIF%u.%u: failed to add VIF\n", mac->macid, vif->vifid);
181 if (!is_valid_ether_addr(vif->mac_addr)) {
182 pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
183 mac->macid, vif->vifid, vif->mac_addr);
187 if (qtnf_core_net_attach(mac, vif, name, name_assign_t, type)) {
188 pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
193 vif->wdev.netdev = vif->netdev;
199 qtnf_cmd_send_del_intf(vif);
201 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
203 return ERR_PTR(-EFAULT);
206 static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
207 const struct cfg80211_beacon_data *info)
211 if (!info->beacon_ies || !info->beacon_ies_len) {
212 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_MGMT_FRAME_BEACON,
215 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_MGMT_FRAME_BEACON,
217 info->beacon_ies_len);
223 if (!info->proberesp_ies || !info->proberesp_ies_len) {
224 ret = qtnf_cmd_send_mgmt_set_appie(vif,
225 QLINK_MGMT_FRAME_PROBE_RESP,
228 ret = qtnf_cmd_send_mgmt_set_appie(vif,
229 QLINK_MGMT_FRAME_PROBE_RESP,
231 info->proberesp_ies_len);
237 if (!info->assocresp_ies || !info->assocresp_ies_len) {
238 ret = qtnf_cmd_send_mgmt_set_appie(vif,
239 QLINK_MGMT_FRAME_ASSOC_RESP,
242 ret = qtnf_cmd_send_mgmt_set_appie(vif,
243 QLINK_MGMT_FRAME_ASSOC_RESP,
245 info->assocresp_ies_len);
252 static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
253 struct cfg80211_beacon_data *info)
255 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
257 if (!(vif->bss_status & QTNF_STATE_AP_START)) {
258 pr_err("VIF%u.%u: not started\n", vif->mac->macid, vif->vifid);
262 return qtnf_mgmt_set_appie(vif, info);
265 static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
266 struct cfg80211_ap_settings *settings)
268 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
269 struct qtnf_wmac *mac = wiphy_priv(wiphy);
270 struct qtnf_bss_config *bss_cfg;
273 if (!cfg80211_chandef_identical(&mac->chandef, &settings->chandef)) {
274 memcpy(&mac->chandef, &settings->chandef, sizeof(mac->chandef));
276 pr_warn("%s: unexpected chan %u (%u MHz)\n", dev->name,
277 settings->chandef.chan->hw_value,
278 settings->chandef.chan->center_freq);
281 bss_cfg = &vif->bss_cfg;
282 memset(bss_cfg, 0, sizeof(*bss_cfg));
284 bss_cfg->bcn_period = settings->beacon_interval;
285 bss_cfg->dtim = settings->dtim_period;
286 bss_cfg->auth_type = settings->auth_type;
287 bss_cfg->privacy = settings->privacy;
289 bss_cfg->ssid_len = settings->ssid_len;
290 memcpy(&bss_cfg->ssid, settings->ssid, bss_cfg->ssid_len);
292 memcpy(&bss_cfg->crypto, &settings->crypto,
293 sizeof(struct cfg80211_crypto_settings));
295 ret = qtnf_cmd_send_config_ap(vif);
297 pr_err("VIF%u.%u: failed to push config to FW\n",
298 vif->mac->macid, vif->vifid);
302 if (!(vif->bss_status & QTNF_STATE_AP_CONFIG)) {
303 pr_err("VIF%u.%u: AP config failed in FW\n", vif->mac->macid,
309 ret = qtnf_mgmt_set_appie(vif, &settings->beacon);
311 pr_err("VIF%u.%u: failed to add IEs to beacon\n",
312 vif->mac->macid, vif->vifid);
316 ret = qtnf_cmd_send_start_ap(vif);
318 pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
323 if (!(vif->bss_status & QTNF_STATE_AP_START)) {
324 pr_err("VIF%u.%u: FW failed to start AP operation\n",
325 vif->mac->macid, vif->vifid);
333 static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev)
335 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
338 ret = qtnf_cmd_send_stop_ap(vif);
340 pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
341 vif->mac->macid, vif->vifid);
342 vif->bss_status &= ~QTNF_STATE_AP_START;
343 vif->bss_status &= ~QTNF_STATE_AP_CONFIG;
345 netif_carrier_off(vif->netdev);
351 static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
353 struct qtnf_wmac *mac = wiphy_priv(wiphy);
354 struct qtnf_vif *vif;
357 vif = qtnf_mac_get_base_vif(mac);
359 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
363 if (changed & (WIPHY_PARAM_RETRY_LONG | WIPHY_PARAM_RETRY_SHORT)) {
364 pr_err("MAC%u: can't modify retry params\n", mac->macid);
368 ret = qtnf_cmd_send_update_phy_params(mac, changed);
370 pr_err("MAC%u: failed to update PHY params\n", mac->macid);
376 qtnf_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
377 u16 frame_type, bool reg)
379 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
382 u16 qlink_frame_type = 0;
384 mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
387 new_mask = vif->mgmt_frames_bitmask | BIT(mgmt_type);
389 new_mask = vif->mgmt_frames_bitmask & ~BIT(mgmt_type);
391 if (new_mask == vif->mgmt_frames_bitmask)
394 switch (frame_type & IEEE80211_FCTL_STYPE) {
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();
429 *cookie = short_cookie;
432 flags |= QLINK_MGMT_FRAME_TX_FLAG_OFFCHAN;
435 flags |= QLINK_MGMT_FRAME_TX_FLAG_NO_CCK;
437 if (params->dont_wait_for_ack)
438 flags |= QLINK_MGMT_FRAME_TX_FLAG_ACK_NOWAIT;
440 pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
441 wdev->netdev->name, params->chan->center_freq,
442 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
443 params->len, short_cookie, flags);
445 return qtnf_cmd_send_mgmt_frame(vif, short_cookie, flags,
446 params->chan->center_freq,
447 params->buf, params->len);
451 qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
452 const u8 *mac, struct station_info *sinfo)
454 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
456 return qtnf_cmd_get_sta_info(vif, mac, sinfo);
460 qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
461 int idx, u8 *mac, struct station_info *sinfo)
463 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
464 const struct qtnf_sta_node *sta_node;
467 sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
469 if (unlikely(!sta_node))
472 ether_addr_copy(mac, sta_node->mac_addr);
474 ret = qtnf_cmd_get_sta_info(vif, sta_node->mac_addr, sinfo);
476 if (unlikely(ret == -ENOENT)) {
477 qtnf_sta_list_del(&vif->sta_list, mac);
478 cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
485 static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
486 u8 key_index, bool pairwise, const u8 *mac_addr,
487 struct key_params *params)
489 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
492 ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
494 pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
495 vif->mac->macid, vif->vifid, params->cipher, key_index,
501 static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
502 u8 key_index, bool pairwise, const u8 *mac_addr)
504 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
507 ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
509 pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
510 vif->mac->macid, vif->vifid, key_index, pairwise);
515 static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
516 u8 key_index, bool unicast, bool multicast)
518 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
521 ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
523 pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
524 vif->mac->macid, vif->vifid, key_index, unicast,
531 qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
534 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
537 ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
539 pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
540 vif->mac->macid, vif->vifid, key_index);
546 qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
547 const u8 *mac, struct station_parameters *params)
549 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
552 ret = qtnf_cmd_send_change_sta(vif, mac, params);
554 pr_err("VIF%u.%u: failed to change STA %pM\n",
555 vif->mac->macid, vif->vifid, mac);
561 qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
562 struct station_del_parameters *params)
564 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
568 (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
569 !is_broadcast_ether_addr(params->mac) &&
570 !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
573 qtnf_scan_done(vif->mac, true);
575 ret = qtnf_cmd_send_del_sta(vif, params);
577 pr_err("VIF%u.%u: failed to delete STA %pM\n",
578 vif->mac->macid, vif->vifid, params->mac);
582 static void qtnf_scan_timeout(unsigned long data)
584 struct qtnf_wmac *mac = (struct qtnf_wmac *)data;
586 pr_warn("mac%d scan timed out\n", mac->macid);
587 qtnf_scan_done(mac, true);
591 qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
593 struct qtnf_wmac *mac = wiphy_priv(wiphy);
595 mac->scan_req = request;
597 if (qtnf_cmd_send_scan(mac)) {
598 pr_err("MAC%u: failed to start scan\n", mac->macid);
599 mac->scan_req = NULL;
603 mac->scan_timeout.data = (unsigned long)mac;
604 mac->scan_timeout.function = qtnf_scan_timeout;
605 mod_timer(&mac->scan_timeout,
606 jiffies + QTNF_SCAN_TIMEOUT_SEC * HZ);
612 qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
613 struct cfg80211_connect_params *sme)
615 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
616 struct qtnf_wmac *mac = wiphy_priv(wiphy);
617 struct cfg80211_chan_def chandef;
618 struct qtnf_bss_config *bss_cfg;
621 if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
624 if (vif->sta_state != QTNF_STA_DISCONNECTED)
627 bss_cfg = &vif->bss_cfg;
628 memset(bss_cfg, 0, sizeof(*bss_cfg));
631 /* FIXME: need to set proper nl80211_channel_type value */
632 cfg80211_chandef_create(&chandef, sme->channel,
634 /* fall-back to minimal safe chandef description */
635 if (!cfg80211_chandef_valid(&chandef))
636 cfg80211_chandef_create(&chandef, sme->channel,
639 memcpy(&mac->chandef, &chandef, sizeof(mac->chandef));
642 bss_cfg->ssid_len = sme->ssid_len;
643 memcpy(&bss_cfg->ssid, sme->ssid, bss_cfg->ssid_len);
644 bss_cfg->auth_type = sme->auth_type;
645 bss_cfg->privacy = sme->privacy;
646 bss_cfg->mfp = sme->mfp;
648 if ((sme->bg_scan_period > 0) &&
649 (sme->bg_scan_period <= QTNF_MAX_BG_SCAN_PERIOD))
650 bss_cfg->bg_scan_period = sme->bg_scan_period;
651 else if (sme->bg_scan_period == -1)
652 bss_cfg->bg_scan_period = QTNF_DEFAULT_BG_SCAN_PERIOD;
654 bss_cfg->bg_scan_period = 0; /* disabled */
656 bss_cfg->connect_flags = 0;
658 if (sme->flags & ASSOC_REQ_DISABLE_HT)
659 bss_cfg->connect_flags |= QLINK_STA_CONNECT_DISABLE_HT;
660 if (sme->flags & ASSOC_REQ_DISABLE_VHT)
661 bss_cfg->connect_flags |= QLINK_STA_CONNECT_DISABLE_VHT;
662 if (sme->flags & ASSOC_REQ_USE_RRM)
663 bss_cfg->connect_flags |= QLINK_STA_CONNECT_USE_RRM;
665 memcpy(&bss_cfg->crypto, &sme->crypto, sizeof(bss_cfg->crypto));
667 ether_addr_copy(bss_cfg->bssid, sme->bssid);
669 eth_zero_addr(bss_cfg->bssid);
671 ret = qtnf_cmd_send_connect(vif, sme);
673 pr_err("VIF%u.%u: failed to connect\n", vif->mac->macid,
678 vif->sta_state = QTNF_STA_CONNECTING;
683 qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
686 struct qtnf_wmac *mac = wiphy_priv(wiphy);
687 struct qtnf_vif *vif;
690 vif = qtnf_mac_get_base_vif(mac);
692 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
696 if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
699 if (vif->sta_state == QTNF_STA_DISCONNECTED)
702 ret = qtnf_cmd_send_disconnect(vif, reason_code);
704 pr_err("VIF%u.%u: failed to disconnect\n", mac->macid,
709 vif->sta_state = QTNF_STA_DISCONNECTED;
714 qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
715 int idx, struct survey_info *survey)
717 struct qtnf_wmac *mac = wiphy_priv(wiphy);
718 struct ieee80211_supported_band *sband;
719 struct cfg80211_chan_def *chandef;
720 struct ieee80211_channel *chan;
721 struct qtnf_chan_stats stats;
722 struct qtnf_vif *vif;
725 vif = qtnf_netdev_get_priv(dev);
726 chandef = &mac->chandef;
728 sband = wiphy->bands[NL80211_BAND_2GHZ];
729 if (sband && idx >= sband->n_channels) {
730 idx -= sband->n_channels;
735 sband = wiphy->bands[NL80211_BAND_5GHZ];
737 if (!sband || idx >= sband->n_channels)
740 chan = &sband->channels[idx];
741 memset(&stats, 0, sizeof(stats));
743 survey->channel = chan;
744 survey->filled = 0x0;
747 if (chan->hw_value == chandef->chan->hw_value)
748 survey->filled = SURVEY_INFO_IN_USE;
751 ret = qtnf_cmd_get_chan_stats(mac, chan->hw_value, &stats);
754 if (unlikely(stats.chan_num != chan->hw_value)) {
755 pr_err("received stats for channel %d instead of %d\n",
756 stats.chan_num, chan->hw_value);
761 survey->filled |= SURVEY_INFO_TIME |
762 SURVEY_INFO_TIME_SCAN |
763 SURVEY_INFO_TIME_BUSY |
764 SURVEY_INFO_TIME_RX |
765 SURVEY_INFO_TIME_TX |
766 SURVEY_INFO_NOISE_DBM;
768 survey->time_scan = stats.cca_try;
769 survey->time = stats.cca_try;
770 survey->time_tx = stats.cca_tx;
771 survey->time_rx = stats.cca_rx;
772 survey->time_busy = stats.cca_busy;
773 survey->noise = stats.chan_noise;
776 pr_debug("no stats for channel %u\n", chan->hw_value);
780 pr_debug("failed to get chan(%d) stats from card\n",
790 qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
791 struct cfg80211_chan_def *chandef)
793 struct qtnf_wmac *mac = wiphy_priv(wiphy);
794 struct net_device *ndev = wdev->netdev;
795 struct qtnf_vif *vif;
800 vif = qtnf_netdev_get_priv(wdev->netdev);
802 switch (vif->wdev.iftype) {
803 case NL80211_IFTYPE_STATION:
804 if (vif->sta_state == QTNF_STA_DISCONNECTED) {
805 pr_warn("%s: STA disconnected\n", ndev->name);
809 case NL80211_IFTYPE_AP:
810 if (!(vif->bss_status & QTNF_STATE_AP_START)) {
811 pr_warn("%s: AP not started\n", ndev->name);
816 pr_err("unsupported vif type (%d)\n", vif->wdev.iftype);
820 if (!cfg80211_chandef_valid(&mac->chandef)) {
821 pr_err("invalid channel settings on %s\n", ndev->name);
825 memcpy(chandef, &mac->chandef, sizeof(*chandef));
829 static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
830 struct cfg80211_csa_settings *params)
832 struct qtnf_wmac *mac = wiphy_priv(wiphy);
833 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
836 pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
837 params->chandef.chan->hw_value, params->count,
838 params->radar_required, params->block_tx);
840 switch (vif->wdev.iftype) {
841 case NL80211_IFTYPE_AP:
842 if (!(vif->bss_status & QTNF_STATE_AP_START)) {
843 pr_warn("AP not started on %s\n", dev->name);
848 pr_err("unsupported vif type (%d) on %s\n",
849 vif->wdev.iftype, dev->name);
853 if (vif->vifid != 0) {
854 if (!(mac->status & QTNF_MAC_CSA_ACTIVE))
857 if (!cfg80211_chandef_identical(¶ms->chandef,
864 if (!cfg80211_chandef_valid(¶ms->chandef)) {
865 pr_err("%s: invalid channel\n", dev->name);
869 if (cfg80211_chandef_identical(¶ms->chandef, &mac->chandef)) {
870 pr_err("%s: switch request to the same channel\n", dev->name);
874 ret = qtnf_cmd_send_chan_switch(mac, params);
876 pr_warn("%s: failed to switch to channel (%u)\n",
877 dev->name, params->chandef.chan->hw_value);
882 static struct cfg80211_ops qtn_cfg80211_ops = {
883 .add_virtual_intf = qtnf_add_virtual_intf,
884 .change_virtual_intf = qtnf_change_virtual_intf,
885 .del_virtual_intf = qtnf_del_virtual_intf,
886 .start_ap = qtnf_start_ap,
887 .change_beacon = qtnf_change_beacon,
888 .stop_ap = qtnf_stop_ap,
889 .set_wiphy_params = qtnf_set_wiphy_params,
890 .mgmt_frame_register = qtnf_mgmt_frame_register,
891 .mgmt_tx = qtnf_mgmt_tx,
892 .change_station = qtnf_change_station,
893 .del_station = qtnf_del_station,
894 .get_station = qtnf_get_station,
895 .dump_station = qtnf_dump_station,
896 .add_key = qtnf_add_key,
897 .del_key = qtnf_del_key,
898 .set_default_key = qtnf_set_default_key,
899 .set_default_mgmt_key = qtnf_set_default_mgmt_key,
901 .connect = qtnf_connect,
902 .disconnect = qtnf_disconnect,
903 .dump_survey = qtnf_dump_survey,
904 .get_channel = qtnf_get_channel,
905 .channel_switch = qtnf_channel_switch
908 static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy_in,
909 struct regulatory_request *req)
911 struct qtnf_wmac *mac = wiphy_priv(wiphy_in);
912 struct qtnf_bus *bus = mac->bus;
914 unsigned int mac_idx;
915 enum nl80211_band band;
918 pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
919 req->alpha2[0], req->alpha2[1]);
921 ret = qtnf_cmd_reg_notify(bus, req);
923 if (ret != -EOPNOTSUPP && ret != -EALREADY)
924 pr_err("failed to update reg domain to %c%c\n",
925 req->alpha2[0], req->alpha2[1]);
929 for (mac_idx = 0; mac_idx < QTNF_MAX_MAC; ++mac_idx) {
930 if (!(bus->hw_info.mac_bitmap & (1 << mac_idx)))
933 mac = bus->mac[mac_idx];
934 wiphy = priv_to_wiphy(mac);
936 for (band = 0; band < NUM_NL80211_BANDS; ++band) {
937 if (!wiphy->bands[band])
940 ret = qtnf_cmd_get_mac_chan_info(mac,
943 pr_err("failed to get chan info for mac %u band %u\n",
949 void qtnf_band_setup_htvht_caps(struct qtnf_mac_info *macinfo,
950 struct ieee80211_supported_band *band)
952 struct ieee80211_sta_ht_cap *ht_cap;
953 struct ieee80211_sta_vht_cap *vht_cap;
955 ht_cap = &band->ht_cap;
956 ht_cap->ht_supported = true;
957 memcpy(&ht_cap->cap, &macinfo->ht_cap.cap_info,
959 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
960 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
961 memcpy(&ht_cap->mcs, &macinfo->ht_cap.mcs,
962 sizeof(ht_cap->mcs));
964 if (macinfo->phymode_cap & QLINK_PHYMODE_AC) {
965 vht_cap = &band->vht_cap;
966 vht_cap->vht_supported = true;
967 memcpy(&vht_cap->cap,
968 &macinfo->vht_cap.vht_cap_info, sizeof(u32));
969 /* Update MCS support for VHT */
970 memcpy(&vht_cap->vht_mcs,
971 &macinfo->vht_cap.supp_mcs,
972 sizeof(struct ieee80211_vht_mcs_info));
976 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus)
980 wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
984 set_wiphy_dev(wiphy, bus->dev);
989 static int qtnf_wiphy_setup_if_comb(struct wiphy *wiphy,
990 struct ieee80211_iface_combination *if_comb,
991 const struct qtnf_mac_info *mac_info)
993 size_t max_interfaces = 0;
994 u16 interface_modes = 0;
997 if (unlikely(!mac_info->limits || !mac_info->n_limits))
1000 if_comb->limits = mac_info->limits;
1001 if_comb->n_limits = mac_info->n_limits;
1003 for (i = 0; i < mac_info->n_limits; i++) {
1004 max_interfaces += mac_info->limits[i].max;
1005 interface_modes |= mac_info->limits[i].types;
1008 if_comb->num_different_channels = 1;
1009 if_comb->beacon_int_infra_match = true;
1010 if_comb->max_interfaces = max_interfaces;
1011 if_comb->radar_detect_widths = mac_info->radar_detect_widths;
1012 wiphy->interface_modes = interface_modes;
1017 int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
1019 struct wiphy *wiphy = priv_to_wiphy(mac);
1020 struct ieee80211_iface_combination *iface_comb = NULL;
1024 pr_err("invalid wiphy pointer\n");
1028 iface_comb = kzalloc(sizeof(*iface_comb), GFP_KERNEL);
1032 ret = qtnf_wiphy_setup_if_comb(wiphy, iface_comb, &mac->macinfo);
1036 pr_info("MAC%u: phymode=%#x radar=%#x\n", mac->macid,
1037 mac->macinfo.phymode_cap, mac->macinfo.radar_detect_widths);
1039 wiphy->frag_threshold = mac->macinfo.frag_thr;
1040 wiphy->rts_threshold = mac->macinfo.rts_thr;
1041 wiphy->retry_short = mac->macinfo.sretry_limit;
1042 wiphy->retry_long = mac->macinfo.lretry_limit;
1043 wiphy->coverage_class = mac->macinfo.coverage_class;
1045 wiphy->max_scan_ssids = QTNF_MAX_SSID_LIST_LENGTH;
1046 wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
1047 wiphy->mgmt_stypes = qtnf_mgmt_stypes;
1048 wiphy->max_remain_on_channel_duration = 5000;
1050 wiphy->iface_combinations = iface_comb;
1051 wiphy->n_iface_combinations = 1;
1052 wiphy->max_num_csa_counters = 2;
1054 /* Initialize cipher suits */
1055 wiphy->cipher_suites = qtnf_cipher_suites;
1056 wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
1057 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1058 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1059 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1060 WIPHY_FLAG_AP_UAPSD |
1061 WIPHY_FLAG_HAS_CHANNEL_SWITCH;
1063 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1064 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1066 wiphy->available_antennas_tx = mac->macinfo.num_tx_chain;
1067 wiphy->available_antennas_rx = mac->macinfo.num_rx_chain;
1069 wiphy->max_ap_assoc_sta = mac->macinfo.max_ap_assoc_sta;
1071 ether_addr_copy(wiphy->perm_addr, mac->macaddr);
1073 if (hw_info->hw_capab & QLINK_HW_SUPPORTS_REG_UPDATE) {
1074 wiphy->regulatory_flags |= REGULATORY_STRICT_REG |
1075 REGULATORY_CUSTOM_REG;
1076 wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
1077 wiphy_apply_custom_regulatory(wiphy, hw_info->rd);
1079 wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
1082 ret = wiphy_register(wiphy);
1086 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1087 ret = regulatory_set_wiphy_regd(wiphy, hw_info->rd);
1088 else if (isalpha(hw_info->rd->alpha2[0]) &&
1089 isalpha(hw_info->rd->alpha2[1]))
1090 ret = regulatory_hint(wiphy, hw_info->rd->alpha2);
1101 void qtnf_netdev_updown(struct net_device *ndev, bool up)
1103 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1105 if (qtnf_cmd_send_updown_intf(vif, up))
1106 pr_err("failed to send up/down command to FW\n");
1109 void qtnf_virtual_intf_cleanup(struct net_device *ndev)
1111 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1112 struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
1114 if (vif->wdev.iftype == NL80211_IFTYPE_STATION) {
1115 switch (vif->sta_state) {
1116 case QTNF_STA_DISCONNECTED:
1118 case QTNF_STA_CONNECTING:
1119 cfg80211_connect_result(vif->netdev,
1120 vif->bss_cfg.bssid, NULL, 0,
1122 WLAN_STATUS_UNSPECIFIED_FAILURE,
1124 qtnf_disconnect(vif->wdev.wiphy, ndev,
1125 WLAN_REASON_DEAUTH_LEAVING);
1127 case QTNF_STA_CONNECTED:
1128 cfg80211_disconnected(vif->netdev,
1129 WLAN_REASON_DEAUTH_LEAVING,
1130 NULL, 0, 1, GFP_KERNEL);
1131 qtnf_disconnect(vif->wdev.wiphy, ndev,
1132 WLAN_REASON_DEAUTH_LEAVING);
1136 vif->sta_state = QTNF_STA_DISCONNECTED;
1137 qtnf_scan_done(mac, true);
1141 void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
1143 if (vif->wdev.iftype == NL80211_IFTYPE_STATION) {
1144 switch (vif->sta_state) {
1145 case QTNF_STA_CONNECTING:
1146 cfg80211_connect_result(vif->netdev,
1147 vif->bss_cfg.bssid, NULL, 0,
1149 WLAN_STATUS_UNSPECIFIED_FAILURE,
1152 case QTNF_STA_CONNECTED:
1153 cfg80211_disconnected(vif->netdev,
1154 WLAN_REASON_DEAUTH_LEAVING,
1155 NULL, 0, 1, GFP_KERNEL);
1157 case QTNF_STA_DISCONNECTED:
1162 cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
1163 vif->sta_state = QTNF_STA_DISCONNECTED;
1166 void qtnf_band_init_rates(struct ieee80211_supported_band *band)
1168 switch (band->band) {
1169 case NL80211_BAND_2GHZ:
1170 band->bitrates = qtnf_rates_2g;
1171 band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
1173 case NL80211_BAND_5GHZ:
1174 band->bitrates = qtnf_rates_5g;
1175 band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
1178 band->bitrates = NULL;
1179 band->n_bitrates = 0;