2 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/etherdevice.h>
19 #include <linux/moduleparam.h>
20 #include <net/netlink.h>
21 #include <net/cfg80211.h>
26 #define WIL_MAX_ROC_DURATION_MS 5000
29 module_param(disable_ap_sme, bool, 0444);
30 MODULE_PARM_DESC(disable_ap_sme, " let user space handle AP mode SME");
33 static struct wiphy_wowlan_support wil_wowlan_support = {
34 .flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT,
38 #define CHAN60G(_channel, _flags) { \
39 .band = NL80211_BAND_60GHZ, \
40 .center_freq = 56160 + (2160 * (_channel)), \
41 .hw_value = (_channel), \
43 .max_antenna_gain = 0, \
47 static struct ieee80211_channel wil_60ghz_channels[] = {
51 /* channel 4 not supported yet */
54 /* Vendor id to be used in vendor specific command and events
56 * NOTE: The authoritative place for definition of QCA_NL80211_VENDOR_ID,
57 * vendor subcmd definitions prefixed with QCA_NL80211_VENDOR_SUBCMD, and
58 * qca_wlan_vendor_attr is open source file src/common/qca-vendor.h in
59 * git://w1.fi/srv/git/hostap.git; the values here are just a copy of that
62 #define QCA_NL80211_VENDOR_ID 0x001374
64 #define WIL_MAX_RF_SECTORS (128)
65 #define WIL_CID_ALL (0xff)
67 enum qca_wlan_vendor_attr_rf_sector {
68 QCA_ATTR_MAC_ADDR = 6,
71 QCA_ATTR_DMG_RF_SECTOR_INDEX = 30,
72 QCA_ATTR_DMG_RF_SECTOR_TYPE = 31,
73 QCA_ATTR_DMG_RF_MODULE_MASK = 32,
74 QCA_ATTR_DMG_RF_SECTOR_CFG = 33,
75 QCA_ATTR_DMG_RF_SECTOR_MAX,
78 enum qca_wlan_vendor_attr_dmg_rf_sector_type {
79 QCA_ATTR_DMG_RF_SECTOR_TYPE_RX,
80 QCA_ATTR_DMG_RF_SECTOR_TYPE_TX,
81 QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX
84 enum qca_wlan_vendor_attr_dmg_rf_sector_cfg {
85 QCA_ATTR_DMG_RF_SECTOR_CFG_INVALID = 0,
86 QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
87 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
88 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
89 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
90 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
91 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
92 QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
95 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST,
96 QCA_ATTR_DMG_RF_SECTOR_CFG_MAX =
97 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST - 1
101 nla_policy wil_rf_sector_policy[QCA_ATTR_DMG_RF_SECTOR_MAX + 1] = {
102 [QCA_ATTR_MAC_ADDR] = { .len = ETH_ALEN },
103 [QCA_ATTR_DMG_RF_SECTOR_INDEX] = { .type = NLA_U16 },
104 [QCA_ATTR_DMG_RF_SECTOR_TYPE] = { .type = NLA_U8 },
105 [QCA_ATTR_DMG_RF_MODULE_MASK] = { .type = NLA_U32 },
106 [QCA_ATTR_DMG_RF_SECTOR_CFG] = { .type = NLA_NESTED },
110 nla_policy wil_rf_sector_cfg_policy[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1] = {
111 [QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] = { .type = NLA_U8 },
112 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] = { .type = NLA_U32 },
113 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] = { .type = NLA_U32 },
114 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] = { .type = NLA_U32 },
115 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] = { .type = NLA_U32 },
116 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] = { .type = NLA_U32 },
117 [QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16] = { .type = NLA_U32 },
120 enum qca_nl80211_vendor_subcmds {
121 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG = 139,
122 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG = 140,
123 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR = 141,
124 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR = 142,
127 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
128 struct wireless_dev *wdev,
129 const void *data, int data_len);
130 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
131 struct wireless_dev *wdev,
132 const void *data, int data_len);
133 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
134 struct wireless_dev *wdev,
135 const void *data, int data_len);
136 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
137 struct wireless_dev *wdev,
138 const void *data, int data_len);
140 /* vendor specific commands */
141 static const struct wiphy_vendor_command wil_nl80211_vendor_commands[] = {
143 .info.vendor_id = QCA_NL80211_VENDOR_ID,
144 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG,
145 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
146 WIPHY_VENDOR_CMD_NEED_RUNNING,
147 .doit = wil_rf_sector_get_cfg
150 .info.vendor_id = QCA_NL80211_VENDOR_ID,
151 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG,
152 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
153 WIPHY_VENDOR_CMD_NEED_RUNNING,
154 .doit = wil_rf_sector_set_cfg
157 .info.vendor_id = QCA_NL80211_VENDOR_ID,
159 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR,
160 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
161 WIPHY_VENDOR_CMD_NEED_RUNNING,
162 .doit = wil_rf_sector_get_selected
165 .info.vendor_id = QCA_NL80211_VENDOR_ID,
167 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR,
168 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
169 WIPHY_VENDOR_CMD_NEED_RUNNING,
170 .doit = wil_rf_sector_set_selected
174 static struct ieee80211_supported_band wil_band_60ghz = {
175 .channels = wil_60ghz_channels,
176 .n_channels = ARRAY_SIZE(wil_60ghz_channels),
178 .ht_supported = true,
180 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
181 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
183 /* MCS 1..12 - SC PHY */
184 .rx_mask = {0xfe, 0x1f}, /* 1..12 */
185 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
190 static const struct ieee80211_txrx_stypes
191 wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
192 [NL80211_IFTYPE_STATION] = {
193 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
194 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
195 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
196 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
198 [NL80211_IFTYPE_AP] = {
199 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
200 BIT(IEEE80211_STYPE_PROBE_RESP >> 4) |
201 BIT(IEEE80211_STYPE_ASSOC_RESP >> 4) |
202 BIT(IEEE80211_STYPE_DISASSOC >> 4),
203 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
204 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
205 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
206 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
207 BIT(IEEE80211_STYPE_AUTH >> 4) |
208 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
209 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4)
211 [NL80211_IFTYPE_P2P_CLIENT] = {
212 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
213 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
214 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
215 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
217 [NL80211_IFTYPE_P2P_GO] = {
218 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
219 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
220 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
221 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
223 [NL80211_IFTYPE_P2P_DEVICE] = {
224 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
225 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
226 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
227 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
231 static const u32 wil_cipher_suites[] = {
232 WLAN_CIPHER_SUITE_GCMP,
235 static const char * const key_usage_str[] = {
236 [WMI_KEY_USE_PAIRWISE] = "PTK",
237 [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
238 [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
241 int wil_iftype_nl2wmi(enum nl80211_iftype type)
243 static const struct {
244 enum nl80211_iftype nl;
245 enum wmi_network_type wmi;
247 {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
248 {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
249 {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
250 {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
251 {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
252 {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
256 for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
257 if (__nl2wmi[i].nl == type)
258 return __nl2wmi[i].wmi;
264 int wil_cid_fill_sinfo(struct wil6210_vif *vif, int cid,
265 struct station_info *sinfo)
267 struct wil6210_priv *wil = vif_to_wil(vif);
268 struct wmi_notify_req_cmd cmd = {
273 struct wmi_cmd_hdr wmi;
274 struct wmi_notify_req_done_event evt;
276 struct wil_net_stats *stats = &wil->sta[cid].stats;
279 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd),
280 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
284 wil_dbg_wmi(wil, "Link status for CID %d MID %d: {\n"
285 " MCS %d TSF 0x%016llx\n"
286 " BF status 0x%08x RSSI %d SQI %d%%\n"
287 " Tx Tpt %d goodput %d Rx goodput %d\n"
288 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
289 cid, vif->mid, le16_to_cpu(reply.evt.bf_mcs),
290 le64_to_cpu(reply.evt.tsf), reply.evt.status,
293 le32_to_cpu(reply.evt.tx_tpt),
294 le32_to_cpu(reply.evt.tx_goodput),
295 le32_to_cpu(reply.evt.rx_goodput),
296 le16_to_cpu(reply.evt.my_rx_sector),
297 le16_to_cpu(reply.evt.my_tx_sector),
298 le16_to_cpu(reply.evt.other_rx_sector),
299 le16_to_cpu(reply.evt.other_tx_sector));
301 sinfo->generation = wil->sinfo_gen;
303 sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
304 BIT(NL80211_STA_INFO_TX_BYTES) |
305 BIT(NL80211_STA_INFO_RX_PACKETS) |
306 BIT(NL80211_STA_INFO_TX_PACKETS) |
307 BIT(NL80211_STA_INFO_RX_BITRATE) |
308 BIT(NL80211_STA_INFO_TX_BITRATE) |
309 BIT(NL80211_STA_INFO_RX_DROP_MISC) |
310 BIT(NL80211_STA_INFO_TX_FAILED);
312 sinfo->txrate.flags = RATE_INFO_FLAGS_60G;
313 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
314 sinfo->rxrate.mcs = stats->last_mcs_rx;
315 sinfo->rx_bytes = stats->rx_bytes;
316 sinfo->rx_packets = stats->rx_packets;
317 sinfo->rx_dropped_misc = stats->rx_dropped;
318 sinfo->tx_bytes = stats->tx_bytes;
319 sinfo->tx_packets = stats->tx_packets;
320 sinfo->tx_failed = stats->tx_errors;
322 if (test_bit(wil_vif_fwconnected, vif->status)) {
323 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
324 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING,
325 wil->fw_capabilities))
326 sinfo->signal = reply.evt.rssi;
328 sinfo->signal = reply.evt.sqi;
334 static int wil_cfg80211_get_station(struct wiphy *wiphy,
335 struct net_device *ndev,
336 const u8 *mac, struct station_info *sinfo)
338 struct wil6210_vif *vif = ndev_to_vif(ndev);
339 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
342 int cid = wil_find_cid(wil, vif->mid, mac);
344 wil_dbg_misc(wil, "get_station: %pM CID %d MID %d\n", mac, cid,
349 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
355 * Find @idx-th active STA for specific MID for station dump.
357 static int wil_find_cid_by_idx(struct wil6210_priv *wil, u8 mid, int idx)
361 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
362 if (wil->sta[i].status == wil_sta_unused)
364 if (wil->sta[i].mid != mid)
374 static int wil_cfg80211_dump_station(struct wiphy *wiphy,
375 struct net_device *dev, int idx,
376 u8 *mac, struct station_info *sinfo)
378 struct wil6210_vif *vif = ndev_to_vif(dev);
379 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
381 int cid = wil_find_cid_by_idx(wil, vif->mid, idx);
386 ether_addr_copy(mac, wil->sta[cid].addr);
387 wil_dbg_misc(wil, "dump_station: %pM CID %d MID %d\n", mac, cid,
390 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
395 static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
396 struct wireless_dev *wdev)
398 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
400 wil_dbg_misc(wil, "start_p2p_device: entered\n");
401 wil->p2p_dev_started = 1;
405 static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
406 struct wireless_dev *wdev)
408 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
410 if (!wil->p2p_dev_started)
413 wil_dbg_misc(wil, "stop_p2p_device: entered\n");
414 mutex_lock(&wil->mutex);
415 mutex_lock(&wil->vif_mutex);
416 wil_p2p_stop_radio_operations(wil);
417 wil->p2p_dev_started = 0;
418 mutex_unlock(&wil->vif_mutex);
419 mutex_unlock(&wil->mutex);
422 static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
423 enum nl80211_iftype new_type)
426 struct wireless_dev *wdev;
427 struct iface_combination_params params = {
428 .num_different_channels = 1,
431 for (i = 0; i < wil->max_vifs; i++) {
433 wdev = vif_to_wdev(wil->vifs[i]);
434 params.iftype_num[wdev->iftype]++;
437 params.iftype_num[new_type]++;
438 return cfg80211_check_combinations(wil->wiphy, ¶ms);
441 static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
442 struct wil6210_vif *vif,
443 enum nl80211_iftype new_type)
446 struct wireless_dev *wdev;
447 struct iface_combination_params params = {
448 .num_different_channels = 1,
450 bool check_combos = false;
452 for (i = 0; i < wil->max_vifs; i++) {
453 struct wil6210_vif *vif_pos = wil->vifs[i];
455 if (vif_pos && vif != vif_pos) {
456 wdev = vif_to_wdev(vif_pos);
457 params.iftype_num[wdev->iftype]++;
463 params.iftype_num[new_type]++;
464 ret = cfg80211_check_combinations(wil->wiphy, ¶ms);
469 static struct wireless_dev *
470 wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
471 unsigned char name_assign_type,
472 enum nl80211_iftype type,
473 struct vif_params *params)
475 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
476 struct net_device *ndev_main = wil->main_ndev, *ndev;
477 struct wil6210_vif *vif;
478 struct wireless_dev *p2p_wdev, *wdev;
481 wil_dbg_misc(wil, "add_iface, type %d\n", type);
483 /* P2P device is not a real virtual interface, it is a management-only
484 * interface that shares the main interface.
485 * Skip concurrency checks here.
487 if (type == NL80211_IFTYPE_P2P_DEVICE) {
489 wil_err(wil, "P2P_DEVICE interface already created\n");
490 return ERR_PTR(-EINVAL);
493 p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
495 return ERR_PTR(-ENOMEM);
497 p2p_wdev->iftype = type;
498 p2p_wdev->wiphy = wiphy;
499 /* use our primary ethernet address */
500 ether_addr_copy(p2p_wdev->address, ndev_main->perm_addr);
502 wil->p2p_wdev = p2p_wdev;
507 if (!wil->wiphy->n_iface_combinations) {
508 wil_err(wil, "virtual interfaces not supported\n");
509 return ERR_PTR(-EINVAL);
512 rc = wil_cfg80211_validate_add_iface(wil, type);
514 wil_err(wil, "iface validation failed, err=%d\n", rc);
518 vif = wil_vif_alloc(wil, name, name_assign_type, type);
520 return ERR_CAST(vif);
522 ndev = vif_to_ndev(vif);
523 ether_addr_copy(ndev->perm_addr, ndev_main->perm_addr);
524 if (is_valid_ether_addr(params->macaddr)) {
525 ether_addr_copy(ndev->dev_addr, params->macaddr);
527 ether_addr_copy(ndev->dev_addr, ndev_main->perm_addr);
528 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << vif->mid)) |
529 0x2; /* locally administered */
531 wdev = vif_to_wdev(vif);
532 ether_addr_copy(wdev->address, ndev->dev_addr);
534 rc = wil_vif_add(wil, vif);
538 wil_info(wil, "added VIF, mid %d iftype %d MAC %pM\n",
539 vif->mid, type, wdev->address);
546 int wil_vif_prepare_stop(struct wil6210_vif *vif)
548 struct wil6210_priv *wil = vif_to_wil(vif);
549 struct wireless_dev *wdev = vif_to_wdev(vif);
550 struct net_device *ndev;
553 if (wdev->iftype != NL80211_IFTYPE_AP)
556 ndev = vif_to_ndev(vif);
557 if (netif_carrier_ok(ndev)) {
558 rc = wmi_pcp_stop(vif);
560 wil_info(wil, "failed to stop AP, status %d\n",
565 netif_carrier_off(ndev);
571 static int wil_cfg80211_del_iface(struct wiphy *wiphy,
572 struct wireless_dev *wdev)
574 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
575 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
578 wil_dbg_misc(wil, "del_iface\n");
580 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
581 if (wdev != wil->p2p_wdev) {
582 wil_err(wil, "delete of incorrect interface 0x%p\n",
587 wil_cfg80211_stop_p2p_device(wiphy, wdev);
588 wil_p2p_wdev_free(wil);
593 wil_err(wil, "cannot remove the main interface\n");
597 rc = wil_vif_prepare_stop(vif);
601 wil_info(wil, "deleted VIF, mid %d iftype %d MAC %pM\n",
602 vif->mid, wdev->iftype, wdev->address);
604 wil_vif_remove(wil, vif->mid);
609 static int wil_cfg80211_change_iface(struct wiphy *wiphy,
610 struct net_device *ndev,
611 enum nl80211_iftype type,
612 struct vif_params *params)
614 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
615 struct wil6210_vif *vif = ndev_to_vif(ndev);
616 struct wireless_dev *wdev = vif_to_wdev(vif);
618 bool fw_reset = false;
620 wil_dbg_misc(wil, "change_iface: type=%d\n", type);
622 if (wiphy->n_iface_combinations) {
623 rc = wil_cfg80211_validate_change_iface(wil, vif, type);
625 wil_err(wil, "iface validation failed, err=%d\n", rc);
630 /* do not reset FW when there are active VIFs,
631 * because it can cause significant disruption
633 if (!wil_has_other_active_ifaces(wil, ndev, true, false) &&
634 netif_running(ndev) && !wil_is_recovery_blocked(wil)) {
635 wil_dbg_misc(wil, "interface is up. resetting...\n");
636 mutex_lock(&wil->mutex);
639 mutex_unlock(&wil->mutex);
647 case NL80211_IFTYPE_STATION:
648 case NL80211_IFTYPE_AP:
649 case NL80211_IFTYPE_P2P_CLIENT:
650 case NL80211_IFTYPE_P2P_GO:
652 case NL80211_IFTYPE_MONITOR:
654 wil->monitor_flags = params->flags;
660 if (vif->mid != 0 && wil_has_active_ifaces(wil, true, false)) {
662 wil_vif_prepare_stop(vif);
663 rc = wmi_port_delete(wil, vif->mid);
666 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr, type);
675 static int wil_cfg80211_scan(struct wiphy *wiphy,
676 struct cfg80211_scan_request *request)
678 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
679 struct wireless_dev *wdev = request->wdev;
680 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
682 struct wmi_start_scan_cmd cmd;
688 wil_dbg_misc(wil, "scan: wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
690 /* check we are client side */
691 switch (wdev->iftype) {
692 case NL80211_IFTYPE_STATION:
693 case NL80211_IFTYPE_P2P_CLIENT:
694 case NL80211_IFTYPE_P2P_DEVICE:
700 /* FW don't support scan after connection attempt */
701 if (test_bit(wil_status_dontscan, wil->status)) {
702 wil_err(wil, "Can't scan now\n");
706 mutex_lock(&wil->mutex);
708 mutex_lock(&wil->vif_mutex);
709 if (vif->scan_request || vif->p2p.discovery_started) {
710 wil_err(wil, "Already scanning\n");
711 mutex_unlock(&wil->vif_mutex);
715 mutex_unlock(&wil->vif_mutex);
717 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
718 if (!wil->p2p_dev_started) {
719 wil_err(wil, "P2P search requested on stopped P2P device\n");
723 /* social scan on P2P_DEVICE is handled as p2p search */
724 if (wil_p2p_is_social_scan(request)) {
725 vif->scan_request = request;
727 wil->radio_wdev = wdev;
728 rc = wil_p2p_search(vif, request);
732 wil->main_ndev->ieee80211_ptr;
733 vif->scan_request = NULL;
739 (void)wil_p2p_stop_discovery(vif);
741 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
742 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
744 for (i = 0; i < request->n_ssids; i++) {
745 wil_dbg_misc(wil, "SSID[%d]", i);
746 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
747 request->ssids[i].ssid,
748 request->ssids[i].ssid_len, true);
751 if (request->n_ssids)
752 rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
753 request->ssids[0].ssid);
755 rc = wmi_set_ssid(vif, 0, NULL);
758 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
762 vif->scan_request = request;
763 mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
765 memset(&cmd, 0, sizeof(cmd));
766 cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
767 cmd.cmd.num_channels = 0;
768 n = min(request->n_channels, 4U);
769 for (i = 0; i < n; i++) {
770 int ch = request->channels[i]->hw_value;
774 "Scan requested for unknown frequency %dMhz\n",
775 request->channels[i]->center_freq);
778 /* 0-based channel indexes */
779 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
780 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
781 request->channels[i]->center_freq);
785 wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
786 request->ie, request->ie_len, true);
788 wil_dbg_misc(wil, "Scan has no IE's\n");
790 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
791 request->ie_len, request->ie);
795 if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
796 cmd.cmd.discovery_mode = 1;
797 wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
801 wil->radio_wdev = wdev;
802 rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
803 &cmd, sizeof(cmd.cmd) +
804 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
808 del_timer_sync(&vif->scan_timer);
810 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
811 vif->scan_request = NULL;
814 mutex_unlock(&wil->mutex);
818 static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
819 struct wireless_dev *wdev)
821 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
822 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
824 wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
826 mutex_lock(&wil->mutex);
827 mutex_lock(&wil->vif_mutex);
829 if (!vif->scan_request)
832 if (wdev != vif->scan_request->wdev) {
833 wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
837 if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
838 wil_p2p_stop_radio_operations(wil);
840 wil_abort_scan(vif, true);
843 mutex_unlock(&wil->vif_mutex);
844 mutex_unlock(&wil->mutex);
847 static void wil_print_crypto(struct wil6210_priv *wil,
848 struct cfg80211_crypto_settings *c)
852 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
853 c->wpa_versions, c->cipher_group);
854 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
855 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
856 for (i = 0; i < n; i++)
857 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
858 c->ciphers_pairwise[i]);
859 wil_dbg_misc(wil, "}\n");
860 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
861 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
862 for (i = 0; i < n; i++)
863 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
865 wil_dbg_misc(wil, "}\n");
866 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
867 c->control_port, be16_to_cpu(c->control_port_ethertype),
868 c->control_port_no_encrypt);
871 static void wil_print_connect_params(struct wil6210_priv *wil,
872 struct cfg80211_connect_params *sme)
874 wil_info(wil, "Connecting to:\n");
876 wil_info(wil, " Channel: %d freq %d\n",
877 sme->channel->hw_value, sme->channel->center_freq);
880 wil_info(wil, " BSSID: %pM\n", sme->bssid);
882 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
883 16, 1, sme->ssid, sme->ssid_len, true);
884 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
885 wil_info(wil, " PBSS: %d\n", sme->pbss);
886 wil_print_crypto(wil, &sme->crypto);
889 static int wil_cfg80211_connect(struct wiphy *wiphy,
890 struct net_device *ndev,
891 struct cfg80211_connect_params *sme)
893 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
894 struct wil6210_vif *vif = ndev_to_vif(ndev);
895 struct cfg80211_bss *bss;
896 struct wmi_connect_cmd conn;
901 enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
903 wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
904 wil_print_connect_params(wil, sme);
906 if (test_bit(wil_vif_fwconnecting, vif->status) ||
907 test_bit(wil_vif_fwconnected, vif->status))
910 if (sme->ie_len > WMI_MAX_IE_LEN) {
911 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
916 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
918 if (sme->privacy && !rsn_eid)
919 wil_info(wil, "WSC connection\n");
922 bss_type = IEEE80211_BSS_TYPE_PBSS;
924 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
925 sme->ssid, sme->ssid_len,
926 bss_type, IEEE80211_PRIVACY_ANY);
928 wil_err(wil, "Unable to find BSS\n");
932 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
934 wil_err(wil, "No SSID\n");
938 vif->privacy = sme->privacy;
939 vif->pbss = sme->pbss;
942 /* For secure assoc, remove old keys */
943 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
944 WMI_KEY_USE_PAIRWISE);
946 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
949 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
950 WMI_KEY_USE_RX_GROUP);
952 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
957 /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
958 * elements. Send it also in case it's empty, to erase previously set
961 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
965 /* WMI_CONNECT_CMD */
966 memset(&conn, 0, sizeof(conn));
967 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
968 case WLAN_CAPABILITY_DMG_TYPE_AP:
969 conn.network_type = WMI_NETTYPE_INFRA;
971 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
972 conn.network_type = WMI_NETTYPE_P2P;
975 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
980 if (rsn_eid) { /* regular secure connection */
981 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
982 conn.auth_mode = WMI_AUTH_WPA2_PSK;
983 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
984 conn.pairwise_crypto_len = 16;
985 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
986 conn.group_crypto_len = 16;
988 conn.dot11_auth_mode = WMI_AUTH11_WSC;
989 conn.auth_mode = WMI_AUTH_NONE;
991 } else { /* insecure connection */
992 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
993 conn.auth_mode = WMI_AUTH_NONE;
996 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
997 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
999 ch = bss->channel->hw_value;
1001 wil_err(wil, "BSS at unknown frequency %dMhz\n",
1002 bss->channel->center_freq);
1006 conn.channel = ch - 1;
1008 ether_addr_copy(conn.bssid, bss->bssid);
1009 ether_addr_copy(conn.dst_mac, bss->bssid);
1011 set_bit(wil_vif_fwconnecting, vif->status);
1013 rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
1015 netif_carrier_on(ndev);
1016 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1017 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1019 /* Connect can take lots of time */
1020 mod_timer(&vif->connect_timer,
1021 jiffies + msecs_to_jiffies(5000));
1023 clear_bit(wil_vif_fwconnecting, vif->status);
1027 cfg80211_put_bss(wiphy, bss);
1032 static int wil_cfg80211_disconnect(struct wiphy *wiphy,
1033 struct net_device *ndev,
1037 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1038 struct wil6210_vif *vif = ndev_to_vif(ndev);
1040 wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
1041 reason_code, vif->mid);
1043 if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
1044 test_bit(wil_vif_fwconnected, vif->status))) {
1045 wil_err(wil, "Disconnect was called while disconnected\n");
1049 vif->locally_generated_disc = true;
1050 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
1051 WMI_DISCONNECT_EVENTID, NULL, 0,
1052 WIL6210_DISCONNECT_TO_MS);
1054 wil_err(wil, "disconnect error %d\n", rc);
1059 static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1061 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1064 /* these parameters are explicitly not supported */
1065 if (changed & (WIPHY_PARAM_RETRY_LONG |
1066 WIPHY_PARAM_FRAG_THRESHOLD |
1067 WIPHY_PARAM_RTS_THRESHOLD))
1070 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1071 rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
1079 int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
1080 struct cfg80211_mgmt_tx_params *params,
1083 const u8 *buf = params->buf;
1084 size_t len = params->len, total;
1085 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1086 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1088 bool tx_status = false;
1089 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
1090 struct wmi_sw_tx_req_cmd *cmd;
1092 struct wmi_cmd_hdr wmi;
1093 struct wmi_sw_tx_complete_event evt;
1096 /* Note, currently we do not support the "wait" parameter, user-space
1097 * must call remain_on_channel before mgmt_tx or listen on a channel
1098 * another way (AP/PCP or connected station)
1099 * in addition we need to check if specified "chan" argument is
1100 * different from currently "listened" channel and fail if it is.
1103 wil_dbg_misc(wil, "mgmt_tx mid %d\n", vif->mid);
1104 wil_hex_dump_misc("mgmt tx frame ", DUMP_PREFIX_OFFSET, 16, 1, buf,
1107 if (len < sizeof(struct ieee80211_hdr_3addr))
1110 total = sizeof(*cmd) + len;
1114 cmd = kmalloc(total, GFP_KERNEL);
1120 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
1121 cmd->len = cpu_to_le16(len);
1122 memcpy(cmd->payload, buf, len);
1124 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, vif->mid, cmd, total,
1125 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
1127 tx_status = !evt.evt.status;
1131 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
1132 tx_status, GFP_KERNEL);
1136 static int wil_cfg80211_set_channel(struct wiphy *wiphy,
1137 struct cfg80211_chan_def *chandef)
1139 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1141 wil->monitor_chandef = *chandef;
1146 static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
1149 struct wil6210_priv *wil = wdev_to_wil(wdev);
1150 enum wmi_key_usage rc;
1153 rc = WMI_KEY_USE_PAIRWISE;
1155 switch (wdev->iftype) {
1156 case NL80211_IFTYPE_STATION:
1157 case NL80211_IFTYPE_P2P_CLIENT:
1158 rc = WMI_KEY_USE_RX_GROUP;
1160 case NL80211_IFTYPE_AP:
1161 case NL80211_IFTYPE_P2P_GO:
1162 rc = WMI_KEY_USE_TX_GROUP;
1165 /* TODO: Rx GTK or Tx GTK? */
1166 wil_err(wil, "Can't determine GTK type\n");
1167 rc = WMI_KEY_USE_RX_GROUP;
1171 wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
1176 static struct wil_sta_info *
1177 wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
1178 enum wmi_key_usage key_usage, const u8 *mac_addr)
1182 if (key_usage == WMI_KEY_USE_TX_GROUP)
1183 return NULL; /* not needed */
1185 /* supplicant provides Rx group key in STA mode with NULL MAC address */
1187 cid = wil_find_cid(wil, mid, mac_addr);
1188 else if (key_usage == WMI_KEY_USE_RX_GROUP)
1189 cid = wil_find_cid_by_idx(wil, mid, 0);
1191 wil_err(wil, "No CID for %pM %s\n", mac_addr,
1192 key_usage_str[key_usage]);
1193 return ERR_PTR(cid);
1196 return &wil->sta[cid];
1199 static void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
1200 struct wil_sta_info *cs,
1201 struct key_params *params)
1203 struct wil_tid_crypto_rx_single *cc;
1209 switch (key_usage) {
1210 case WMI_KEY_USE_PAIRWISE:
1211 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1212 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1214 memcpy(cc->pn, params->seq,
1215 IEEE80211_GCMP_PN_LEN);
1217 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1221 case WMI_KEY_USE_RX_GROUP:
1222 cc = &cs->group_crypto_rx.key_id[key_index];
1224 memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
1226 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1234 static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
1235 struct wil_sta_info *cs)
1237 struct wil_tid_crypto_rx_single *cc;
1243 switch (key_usage) {
1244 case WMI_KEY_USE_PAIRWISE:
1245 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1246 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1247 cc->key_set = false;
1250 case WMI_KEY_USE_RX_GROUP:
1251 cc = &cs->group_crypto_rx.key_id[key_index];
1252 cc->key_set = false;
1259 static int wil_cfg80211_add_key(struct wiphy *wiphy,
1260 struct net_device *ndev,
1261 u8 key_index, bool pairwise,
1263 struct key_params *params)
1266 struct wil6210_vif *vif = ndev_to_vif(ndev);
1267 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1268 struct wireless_dev *wdev = vif_to_wdev(vif);
1269 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1270 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1275 wil_err(wil, "NULL params\n");
1279 wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
1280 mac_addr, key_usage_str[key_usage], key_index,
1281 params->seq_len, params->seq);
1284 wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
1285 mac_addr, key_usage_str[key_usage], key_index,
1286 params->seq_len, params->seq);
1290 wil_del_rx_key(key_index, key_usage, cs);
1292 if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
1294 "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
1295 params->seq_len, mac_addr,
1296 key_usage_str[key_usage], key_index,
1297 params->seq_len, params->seq);
1301 rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
1302 params->key, key_usage);
1304 wil_set_crypto_rx(key_index, key_usage, cs, params);
1309 static int wil_cfg80211_del_key(struct wiphy *wiphy,
1310 struct net_device *ndev,
1311 u8 key_index, bool pairwise,
1314 struct wil6210_vif *vif = ndev_to_vif(ndev);
1315 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1316 struct wireless_dev *wdev = vif_to_wdev(vif);
1317 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1318 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1322 wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
1323 key_usage_str[key_usage], key_index);
1326 wil_info(wil, "Not connected, %pM %s[%d]\n",
1327 mac_addr, key_usage_str[key_usage], key_index);
1329 if (!IS_ERR_OR_NULL(cs))
1330 wil_del_rx_key(key_index, key_usage, cs);
1332 return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
1335 /* Need to be present or wiphy_new() will WARN */
1336 static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
1337 struct net_device *ndev,
1338 u8 key_index, bool unicast,
1341 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1343 wil_dbg_misc(wil, "set_default_key: entered\n");
1347 static int wil_remain_on_channel(struct wiphy *wiphy,
1348 struct wireless_dev *wdev,
1349 struct ieee80211_channel *chan,
1350 unsigned int duration,
1353 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1357 "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
1358 chan->center_freq, duration, wdev->iftype);
1360 rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
1364 static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
1365 struct wireless_dev *wdev,
1368 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1369 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1371 wil_dbg_misc(wil, "cancel_remain_on_channel\n");
1373 return wil_p2p_cancel_listen(vif, cookie);
1377 * find a specific IE in a list of IEs
1378 * return a pointer to the beginning of IE in the list
1379 * or NULL if not found
1381 static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
1384 struct ieee80211_vendor_ie *vie;
1387 /* IE tag at offset 0, length at offset 1 */
1388 if (ie_len < 2 || 2 + ie[1] > ie_len)
1391 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
1392 return cfg80211_find_ie(ie[0], ies, ies_len);
1394 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
1397 vie = (struct ieee80211_vendor_ie *)ie;
1398 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
1399 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
1404 * merge the IEs in two lists into a single list.
1405 * do not include IEs from the second list which exist in the first list.
1406 * add only vendor specific IEs from second list to keep
1407 * the merged list sorted (since vendor-specific IE has the
1408 * highest tag number)
1409 * caller must free the allocated memory for merged IEs
1411 static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
1412 const u8 *ies2, u16 ies2_len,
1413 u8 **merged_ies, u16 *merged_len)
1418 if (ies1_len == 0 && ies2_len == 0) {
1424 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
1427 memcpy(buf, ies1, ies1_len);
1428 dpos = buf + ies1_len;
1430 while (spos + 1 < ies2 + ies2_len) {
1431 /* IE tag at offset 0, length at offset 1 */
1432 u16 ielen = 2 + spos[1];
1434 if (spos + ielen > ies2 + ies2_len)
1436 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
1437 !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
1438 memcpy(dpos, spos, ielen);
1445 *merged_len = dpos - buf;
1449 static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
1451 wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
1452 b->head, b->head_len, true);
1453 wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
1454 b->tail, b->tail_len, true);
1455 wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
1456 b->beacon_ies, b->beacon_ies_len, true);
1457 wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
1458 b->probe_resp, b->probe_resp_len, true);
1459 wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
1460 b->proberesp_ies, b->proberesp_ies_len, true);
1461 wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
1462 b->assocresp_ies, b->assocresp_ies_len, true);
1465 /* internal functions for device reset and starting AP */
1466 static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
1467 struct cfg80211_beacon_data *bcon)
1470 u16 len = 0, proberesp_len = 0;
1471 u8 *ies = NULL, *proberesp = NULL;
1473 if (bcon->probe_resp) {
1474 struct ieee80211_mgmt *f =
1475 (struct ieee80211_mgmt *)bcon->probe_resp;
1476 size_t hlen = offsetof(struct ieee80211_mgmt,
1477 u.probe_resp.variable);
1478 proberesp = f->u.probe_resp.variable;
1479 proberesp_len = bcon->probe_resp_len - hlen;
1481 rc = _wil_cfg80211_merge_extra_ies(proberesp,
1483 bcon->proberesp_ies,
1484 bcon->proberesp_ies_len,
1490 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
1494 if (bcon->assocresp_ies)
1495 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
1496 bcon->assocresp_ies_len, bcon->assocresp_ies);
1498 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
1499 #if 0 /* to use beacon IE's, remove this #if 0 */
1503 rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
1504 bcon->tail_len, bcon->tail);
1511 static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
1512 struct net_device *ndev,
1513 const u8 *ssid, size_t ssid_len, u32 privacy,
1515 struct cfg80211_beacon_data *bcon,
1516 u8 hidden_ssid, u32 pbss)
1518 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1519 struct wil6210_vif *vif = ndev_to_vif(ndev);
1521 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1522 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
1523 u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
1526 wmi_nettype = WMI_NETTYPE_P2P;
1528 wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
1529 if (is_go && !pbss) {
1530 wil_err(wil, "P2P GO must be in PBSS\n");
1534 wil_set_recovery_state(wil, fw_recovery_idle);
1536 mutex_lock(&wil->mutex);
1538 if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
1545 rc = wmi_set_ssid(vif, ssid_len, ssid);
1549 rc = _wil_cfg80211_set_ies(vif, bcon);
1553 vif->privacy = privacy;
1554 vif->channel = chan;
1555 vif->hidden_ssid = hidden_ssid;
1558 netif_carrier_on(ndev);
1559 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1560 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1562 rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, hidden_ssid, is_go);
1566 rc = wil_bcast_init(vif);
1570 goto out; /* success */
1575 netif_carrier_off(ndev);
1576 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1577 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1579 mutex_unlock(&wil->mutex);
1583 static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
1584 struct net_device *ndev,
1585 struct cfg80211_beacon_data *bcon)
1587 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1588 struct wil6210_vif *vif = ndev_to_vif(ndev);
1592 wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
1593 wil_print_bcon_data(bcon);
1596 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
1600 /* in case privacy has changed, need to restart the AP */
1601 if (vif->privacy != privacy) {
1602 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1604 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
1605 vif->privacy, privacy);
1607 rc = _wil_cfg80211_start_ap(wiphy, ndev, wdev->ssid,
1608 wdev->ssid_len, privacy,
1609 wdev->beacon_interval,
1614 rc = _wil_cfg80211_set_ies(vif, bcon);
1620 static int wil_cfg80211_start_ap(struct wiphy *wiphy,
1621 struct net_device *ndev,
1622 struct cfg80211_ap_settings *info)
1625 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1626 struct ieee80211_channel *channel = info->chandef.chan;
1627 struct cfg80211_beacon_data *bcon = &info->beacon;
1628 struct cfg80211_crypto_settings *crypto = &info->crypto;
1631 wil_dbg_misc(wil, "start_ap\n");
1634 wil_err(wil, "AP: No channel???\n");
1638 switch (info->hidden_ssid) {
1639 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1640 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
1643 case NL80211_HIDDEN_SSID_ZERO_LEN:
1644 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
1647 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1648 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
1652 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
1655 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
1656 channel->center_freq, info->privacy ? "secure" : "open");
1657 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
1658 info->privacy, info->auth_type);
1659 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
1661 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
1663 wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
1664 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
1665 info->ssid, info->ssid_len, true);
1666 wil_print_bcon_data(bcon);
1667 wil_print_crypto(wil, crypto);
1669 rc = _wil_cfg80211_start_ap(wiphy, ndev,
1670 info->ssid, info->ssid_len, info->privacy,
1671 info->beacon_interval, channel->hw_value,
1672 bcon, hidden_ssid, info->pbss);
1677 static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
1678 struct net_device *ndev)
1680 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1681 struct wil6210_vif *vif = ndev_to_vif(ndev);
1684 wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
1686 netif_carrier_off(ndev);
1687 last = !wil_has_other_active_ifaces(wil, ndev, false, true);
1689 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1690 wil_set_recovery_state(wil, fw_recovery_idle);
1691 set_bit(wil_status_resetting, wil->status);
1694 mutex_lock(&wil->mutex);
1701 wil_bcast_fini(vif);
1703 mutex_unlock(&wil->mutex);
1708 static int wil_cfg80211_add_station(struct wiphy *wiphy,
1709 struct net_device *dev,
1711 struct station_parameters *params)
1713 struct wil6210_vif *vif = ndev_to_vif(dev);
1714 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1716 wil_dbg_misc(wil, "add station %pM aid %d mid %d\n",
1717 mac, params->aid, vif->mid);
1719 if (!disable_ap_sme) {
1720 wil_err(wil, "not supported with AP SME enabled\n");
1724 if (params->aid > WIL_MAX_DMG_AID) {
1725 wil_err(wil, "invalid aid\n");
1729 return wmi_new_sta(vif, mac, params->aid);
1732 static int wil_cfg80211_del_station(struct wiphy *wiphy,
1733 struct net_device *dev,
1734 struct station_del_parameters *params)
1736 struct wil6210_vif *vif = ndev_to_vif(dev);
1737 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1739 wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
1740 params->mac, params->reason_code, vif->mid);
1742 mutex_lock(&wil->mutex);
1743 wil6210_disconnect(vif, params->mac, params->reason_code, false);
1744 mutex_unlock(&wil->mutex);
1749 static int wil_cfg80211_change_station(struct wiphy *wiphy,
1750 struct net_device *dev,
1752 struct station_parameters *params)
1754 struct wil6210_vif *vif = ndev_to_vif(dev);
1755 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1758 struct vring_tx_data *txdata = NULL;
1760 wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
1761 mac, params->sta_flags_mask, params->sta_flags_set,
1764 if (!disable_ap_sme) {
1765 wil_dbg_misc(wil, "not supported with AP SME enabled\n");
1769 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1772 cid = wil_find_cid(wil, vif->mid, mac);
1774 wil_err(wil, "station not found\n");
1778 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++)
1779 if (wil->vring2cid_tid[i][0] == cid) {
1780 txdata = &wil->vring_tx_data[i];
1785 wil_err(wil, "vring data not found\n");
1789 authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
1790 txdata->dot1x_open = authorize ? 1 : 0;
1791 wil_dbg_misc(wil, "cid %d vring %d authorize %d\n", cid, i,
1792 txdata->dot1x_open);
1797 /* probe_client handling */
1798 static void wil_probe_client_handle(struct wil6210_priv *wil,
1799 struct wil6210_vif *vif,
1800 struct wil_probe_client_req *req)
1802 struct net_device *ndev = vif_to_ndev(vif);
1803 struct wil_sta_info *sta = &wil->sta[req->cid];
1804 /* assume STA is alive if it is still connected,
1805 * else FW will disconnect it
1807 bool alive = (sta->status == wil_sta_connected);
1809 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive,
1810 0, false, GFP_KERNEL);
1813 static struct list_head *next_probe_client(struct wil6210_vif *vif)
1815 struct list_head *ret = NULL;
1817 mutex_lock(&vif->probe_client_mutex);
1819 if (!list_empty(&vif->probe_client_pending)) {
1820 ret = vif->probe_client_pending.next;
1824 mutex_unlock(&vif->probe_client_mutex);
1829 void wil_probe_client_worker(struct work_struct *work)
1831 struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
1832 probe_client_worker);
1833 struct wil6210_priv *wil = vif_to_wil(vif);
1834 struct wil_probe_client_req *req;
1835 struct list_head *lh;
1837 while ((lh = next_probe_client(vif)) != NULL) {
1838 req = list_entry(lh, struct wil_probe_client_req, list);
1840 wil_probe_client_handle(wil, vif, req);
1845 void wil_probe_client_flush(struct wil6210_vif *vif)
1847 struct wil_probe_client_req *req, *t;
1848 struct wil6210_priv *wil = vif_to_wil(vif);
1850 wil_dbg_misc(wil, "probe_client_flush\n");
1852 mutex_lock(&vif->probe_client_mutex);
1854 list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
1855 list_del(&req->list);
1859 mutex_unlock(&vif->probe_client_mutex);
1862 static int wil_cfg80211_probe_client(struct wiphy *wiphy,
1863 struct net_device *dev,
1864 const u8 *peer, u64 *cookie)
1866 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1867 struct wil6210_vif *vif = ndev_to_vif(dev);
1868 struct wil_probe_client_req *req;
1869 int cid = wil_find_cid(wil, vif->mid, peer);
1871 wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
1872 peer, cid, vif->mid);
1877 req = kzalloc(sizeof(*req), GFP_KERNEL);
1884 mutex_lock(&vif->probe_client_mutex);
1885 list_add_tail(&req->list, &vif->probe_client_pending);
1886 mutex_unlock(&vif->probe_client_mutex);
1888 *cookie = req->cookie;
1889 queue_work(wil->wq_service, &vif->probe_client_worker);
1893 static int wil_cfg80211_change_bss(struct wiphy *wiphy,
1894 struct net_device *dev,
1895 struct bss_parameters *params)
1897 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1898 struct wil6210_vif *vif = ndev_to_vif(dev);
1900 if (params->ap_isolate >= 0) {
1901 wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
1902 vif->mid, vif->ap_isolate, params->ap_isolate);
1903 vif->ap_isolate = params->ap_isolate;
1909 static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1910 struct net_device *dev,
1911 bool enabled, int timeout)
1913 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1914 enum wmi_ps_profile_type ps_profile;
1916 wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
1920 ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
1922 ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
1924 return wil_ps_update(wil, ps_profile);
1927 static int wil_cfg80211_suspend(struct wiphy *wiphy,
1928 struct cfg80211_wowlan *wow)
1930 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1933 /* Setting the wakeup trigger based on wow is TBD */
1935 if (test_bit(wil_status_suspended, wil->status)) {
1936 wil_dbg_pm(wil, "trying to suspend while suspended\n");
1940 rc = wil_can_suspend(wil, false);
1944 wil_dbg_pm(wil, "suspending\n");
1946 mutex_lock(&wil->mutex);
1947 mutex_lock(&wil->vif_mutex);
1948 wil_p2p_stop_radio_operations(wil);
1949 wil_abort_scan_all_vifs(wil, true);
1950 mutex_unlock(&wil->vif_mutex);
1951 mutex_unlock(&wil->mutex);
1957 static int wil_cfg80211_resume(struct wiphy *wiphy)
1959 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1961 wil_dbg_pm(wil, "resuming\n");
1967 wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
1968 struct net_device *dev,
1969 struct cfg80211_sched_scan_request *request)
1971 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1972 struct wil6210_vif *vif = ndev_to_vif(dev);
1979 "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
1980 request->n_ssids, request->ie_len, request->flags);
1981 for (i = 0; i < request->n_ssids; i++) {
1982 wil_dbg_misc(wil, "SSID[%d]:", i);
1983 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
1984 request->ssids[i].ssid,
1985 request->ssids[i].ssid_len, true);
1987 wil_dbg_misc(wil, "channels:");
1988 for (i = 0; i < request->n_channels; i++)
1989 wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
1990 i == request->n_channels - 1 ? "\n" : "");
1991 wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
1992 request->n_match_sets, request->min_rssi_thold,
1994 for (i = 0; i < request->n_match_sets; i++) {
1995 struct cfg80211_match_set *ms = &request->match_sets[i];
1997 wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
1999 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2001 ms->ssid.ssid_len, true);
2003 wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
2004 for (i = 0; i < request->n_scan_plans; i++) {
2005 struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
2007 wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
2008 i, sp->interval, sp->iterations);
2011 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
2012 request->ie_len, request->ie);
2015 return wmi_start_sched_scan(wil, request);
2019 wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2022 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2023 struct wil6210_vif *vif = ndev_to_vif(dev);
2029 rc = wmi_stop_sched_scan(wil);
2030 /* device would return error if it thinks PNO is already stopped.
2031 * ignore the return code so user space and driver gets back in-sync
2033 wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
2038 static const struct cfg80211_ops wil_cfg80211_ops = {
2039 .add_virtual_intf = wil_cfg80211_add_iface,
2040 .del_virtual_intf = wil_cfg80211_del_iface,
2041 .scan = wil_cfg80211_scan,
2042 .abort_scan = wil_cfg80211_abort_scan,
2043 .connect = wil_cfg80211_connect,
2044 .disconnect = wil_cfg80211_disconnect,
2045 .set_wiphy_params = wil_cfg80211_set_wiphy_params,
2046 .change_virtual_intf = wil_cfg80211_change_iface,
2047 .get_station = wil_cfg80211_get_station,
2048 .dump_station = wil_cfg80211_dump_station,
2049 .remain_on_channel = wil_remain_on_channel,
2050 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
2051 .mgmt_tx = wil_cfg80211_mgmt_tx,
2052 .set_monitor_channel = wil_cfg80211_set_channel,
2053 .add_key = wil_cfg80211_add_key,
2054 .del_key = wil_cfg80211_del_key,
2055 .set_default_key = wil_cfg80211_set_default_key,
2057 .change_beacon = wil_cfg80211_change_beacon,
2058 .start_ap = wil_cfg80211_start_ap,
2059 .stop_ap = wil_cfg80211_stop_ap,
2060 .add_station = wil_cfg80211_add_station,
2061 .del_station = wil_cfg80211_del_station,
2062 .change_station = wil_cfg80211_change_station,
2063 .probe_client = wil_cfg80211_probe_client,
2064 .change_bss = wil_cfg80211_change_bss,
2066 .start_p2p_device = wil_cfg80211_start_p2p_device,
2067 .stop_p2p_device = wil_cfg80211_stop_p2p_device,
2068 .set_power_mgmt = wil_cfg80211_set_power_mgmt,
2069 .suspend = wil_cfg80211_suspend,
2070 .resume = wil_cfg80211_resume,
2071 .sched_scan_start = wil_cfg80211_sched_scan_start,
2072 .sched_scan_stop = wil_cfg80211_sched_scan_stop,
2075 static void wil_wiphy_init(struct wiphy *wiphy)
2077 wiphy->max_scan_ssids = 1;
2078 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
2079 wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
2080 wiphy->max_num_pmkids = 0 /* TODO: */;
2081 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2082 BIT(NL80211_IFTYPE_AP) |
2083 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2084 BIT(NL80211_IFTYPE_P2P_GO) |
2085 BIT(NL80211_IFTYPE_P2P_DEVICE) |
2086 BIT(NL80211_IFTYPE_MONITOR);
2087 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
2088 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
2089 WIPHY_FLAG_PS_ON_BY_DEFAULT;
2090 if (!disable_ap_sme)
2091 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
2092 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
2093 __func__, wiphy->flags);
2094 wiphy->probe_resp_offload =
2095 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
2096 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2097 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
2099 wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
2101 /* may change after reading FW capabilities */
2102 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2104 wiphy->cipher_suites = wil_cipher_suites;
2105 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
2106 wiphy->mgmt_stypes = wil_mgmt_stypes;
2107 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
2109 wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
2110 wiphy->vendor_commands = wil_nl80211_vendor_commands;
2113 wiphy->wowlan = &wil_wowlan_support;
2117 int wil_cfg80211_iface_combinations_from_fw(
2118 struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
2120 struct wiphy *wiphy = wil_to_wiphy(wil);
2121 u32 total_limits = 0;
2123 const struct wil_fw_concurrency_combo *combo;
2124 const struct wil_fw_concurrency_limit *limit;
2125 struct ieee80211_iface_combination *iface_combinations;
2126 struct ieee80211_iface_limit *iface_limit;
2129 if (wiphy->iface_combinations) {
2130 wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
2134 combo = conc->combos;
2135 n_combos = le16_to_cpu(conc->n_combos);
2136 for (i = 0; i < n_combos; i++) {
2137 total_limits += combo->n_limits;
2138 limit = combo->limits + combo->n_limits;
2139 combo = (struct wil_fw_concurrency_combo *)limit;
2142 iface_combinations =
2143 kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
2144 total_limits * sizeof(struct ieee80211_iface_limit),
2146 if (!iface_combinations)
2148 iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
2150 combo = conc->combos;
2151 for (i = 0; i < n_combos; i++) {
2152 iface_combinations[i].max_interfaces = combo->max_interfaces;
2153 iface_combinations[i].num_different_channels =
2154 combo->n_diff_channels;
2155 iface_combinations[i].beacon_int_infra_match =
2157 iface_combinations[i].n_limits = combo->n_limits;
2159 "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
2160 i, iface_combinations[i].max_interfaces,
2161 iface_combinations[i].num_different_channels,
2162 iface_combinations[i].beacon_int_infra_match);
2163 limit = combo->limits;
2164 for (j = 0; j < combo->n_limits; j++) {
2165 iface_limit[j].max = le16_to_cpu(limit[j].max);
2166 iface_limit[j].types = le16_to_cpu(limit[j].types);
2168 "limit %d: max %d types 0x%x\n", j,
2169 iface_limit[j].max, iface_limit[j].types);
2171 iface_combinations[i].limits = iface_limit;
2172 iface_limit += combo->n_limits;
2173 limit += combo->n_limits;
2174 combo = (struct wil_fw_concurrency_combo *)limit;
2177 wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
2178 wil->max_vifs = conc->n_mids + 1; /* including main interface */
2179 if (wil->max_vifs > WIL_MAX_VIFS) {
2180 wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
2181 WIL_MAX_VIFS, wil->max_vifs);
2182 wil->max_vifs = WIL_MAX_VIFS;
2184 wiphy->n_iface_combinations = n_combos;
2185 wiphy->iface_combinations = iface_combinations;
2189 struct wil6210_priv *wil_cfg80211_init(struct device *dev)
2191 struct wiphy *wiphy;
2192 struct wil6210_priv *wil;
2193 struct ieee80211_channel *ch;
2195 dev_dbg(dev, "%s()\n", __func__);
2197 /* Note: the wireless_dev structure is no longer allocated here.
2198 * Instead, it is allocated as part of the net_device structure
2199 * for main interface and each VIF.
2201 wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
2203 return ERR_PTR(-ENOMEM);
2205 set_wiphy_dev(wiphy, dev);
2206 wil_wiphy_init(wiphy);
2208 wil = wiphy_to_wil(wiphy);
2211 /* default monitor channel */
2212 ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
2213 cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
2218 void wil_cfg80211_deinit(struct wil6210_priv *wil)
2220 struct wiphy *wiphy = wil_to_wiphy(wil);
2222 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
2227 kfree(wiphy->iface_combinations);
2228 wiphy->iface_combinations = NULL;
2231 /* do not access wil6210_priv after returning from here */
2234 void wil_p2p_wdev_free(struct wil6210_priv *wil)
2236 struct wireless_dev *p2p_wdev;
2238 mutex_lock(&wil->vif_mutex);
2239 p2p_wdev = wil->p2p_wdev;
2240 wil->p2p_wdev = NULL;
2241 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
2242 mutex_unlock(&wil->vif_mutex);
2244 cfg80211_unregister_wdev(p2p_wdev);
2249 static int wil_rf_sector_status_to_rc(u8 status)
2252 case WMI_RF_SECTOR_STATUS_SUCCESS:
2254 case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
2256 case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
2258 case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
2265 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
2266 struct wireless_dev *wdev,
2267 const void *data, int data_len)
2269 struct wil6210_priv *wil = wdev_to_wil(wdev);
2270 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2272 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2276 struct wmi_get_rf_sector_params_cmd cmd;
2278 struct wmi_cmd_hdr wmi;
2279 struct wmi_get_rf_sector_params_done_event evt;
2281 struct sk_buff *msg;
2282 struct nlattr *nl_cfgs, *nl_cfg;
2284 struct wmi_rf_sector_info *si;
2286 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2289 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2290 wil_rf_sector_policy, NULL);
2292 wil_err(wil, "Invalid rf sector ATTR\n");
2296 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2297 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2298 !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
2299 wil_err(wil, "Invalid rf sector spec\n");
2303 sector_index = nla_get_u16(
2304 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2305 if (sector_index >= WIL_MAX_RF_SECTORS) {
2306 wil_err(wil, "Invalid sector index %d\n", sector_index);
2310 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2311 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2312 wil_err(wil, "Invalid sector type %d\n", sector_type);
2316 rf_modules_vec = nla_get_u32(
2317 tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
2318 if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
2319 wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
2323 cmd.sector_idx = cpu_to_le16(sector_index);
2324 cmd.sector_type = sector_type;
2325 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2326 memset(&reply, 0, sizeof(reply));
2327 rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2328 &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
2329 &reply, sizeof(reply),
2333 if (reply.evt.status) {
2334 wil_err(wil, "get rf sector cfg failed with status %d\n",
2336 return wil_rf_sector_status_to_rc(reply.evt.status);
2339 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2340 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2344 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2345 le64_to_cpu(reply.evt.tsf),
2347 goto nla_put_failure;
2349 nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
2351 goto nla_put_failure;
2352 for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
2353 if (!(rf_modules_vec & BIT(i)))
2355 nl_cfg = nla_nest_start(msg, i);
2357 goto nla_put_failure;
2358 si = &reply.evt.sectors_info[i];
2359 if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
2361 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
2362 le32_to_cpu(si->etype0)) ||
2363 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
2364 le32_to_cpu(si->etype1)) ||
2365 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
2366 le32_to_cpu(si->etype2)) ||
2367 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
2368 le32_to_cpu(si->psh_hi)) ||
2369 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
2370 le32_to_cpu(si->psh_lo)) ||
2371 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
2372 le32_to_cpu(si->dtype_swch_off)))
2373 goto nla_put_failure;
2374 nla_nest_end(msg, nl_cfg);
2377 nla_nest_end(msg, nl_cfgs);
2378 rc = cfg80211_vendor_cmd_reply(msg);
2385 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
2386 struct wireless_dev *wdev,
2387 const void *data, int data_len)
2389 struct wil6210_priv *wil = wdev_to_wil(wdev);
2390 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2392 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2393 struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
2394 u16 sector_index, rf_module_index;
2396 u32 rf_modules_vec = 0;
2397 struct wmi_set_rf_sector_params_cmd cmd;
2399 struct wmi_cmd_hdr wmi;
2400 struct wmi_set_rf_sector_params_done_event evt;
2402 struct nlattr *nl_cfg;
2403 struct wmi_rf_sector_info *si;
2405 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2408 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2409 wil_rf_sector_policy, NULL);
2411 wil_err(wil, "Invalid rf sector ATTR\n");
2415 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2416 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2417 !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
2418 wil_err(wil, "Invalid rf sector spec\n");
2422 sector_index = nla_get_u16(
2423 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2424 if (sector_index >= WIL_MAX_RF_SECTORS) {
2425 wil_err(wil, "Invalid sector index %d\n", sector_index);
2429 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2430 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2431 wil_err(wil, "Invalid sector type %d\n", sector_type);
2435 memset(&cmd, 0, sizeof(cmd));
2437 cmd.sector_idx = cpu_to_le16(sector_index);
2438 cmd.sector_type = sector_type;
2439 nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
2441 rc = nla_parse_nested(tb2, QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
2442 nl_cfg, wil_rf_sector_cfg_policy,
2445 wil_err(wil, "invalid sector cfg\n");
2449 if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
2450 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
2451 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
2452 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
2453 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
2454 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
2455 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
2456 wil_err(wil, "missing cfg params\n");
2460 rf_module_index = nla_get_u8(
2461 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
2462 if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
2463 wil_err(wil, "invalid RF module index %d\n",
2467 rf_modules_vec |= BIT(rf_module_index);
2468 si = &cmd.sectors_info[rf_module_index];
2469 si->etype0 = cpu_to_le32(nla_get_u32(
2470 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
2471 si->etype1 = cpu_to_le32(nla_get_u32(
2472 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
2473 si->etype2 = cpu_to_le32(nla_get_u32(
2474 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
2475 si->psh_hi = cpu_to_le32(nla_get_u32(
2476 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
2477 si->psh_lo = cpu_to_le32(nla_get_u32(
2478 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
2479 si->dtype_swch_off = cpu_to_le32(nla_get_u32(
2480 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
2483 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2484 memset(&reply, 0, sizeof(reply));
2485 rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2486 &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
2487 &reply, sizeof(reply),
2491 return wil_rf_sector_status_to_rc(reply.evt.status);
2494 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
2495 struct wireless_dev *wdev,
2496 const void *data, int data_len)
2498 struct wil6210_priv *wil = wdev_to_wil(wdev);
2499 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2501 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2502 u8 sector_type, mac_addr[ETH_ALEN];
2504 struct wmi_get_selected_rf_sector_index_cmd cmd;
2506 struct wmi_cmd_hdr wmi;
2507 struct wmi_get_selected_rf_sector_index_done_event evt;
2509 struct sk_buff *msg;
2511 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2514 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2515 wil_rf_sector_policy, NULL);
2517 wil_err(wil, "Invalid rf sector ATTR\n");
2521 if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2522 wil_err(wil, "Invalid rf sector spec\n");
2525 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2526 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2527 wil_err(wil, "Invalid sector type %d\n", sector_type);
2531 if (tb[QCA_ATTR_MAC_ADDR]) {
2532 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2533 cid = wil_find_cid(wil, vif->mid, mac_addr);
2535 wil_err(wil, "invalid MAC address %pM\n", mac_addr);
2539 if (test_bit(wil_vif_fwconnected, vif->status)) {
2540 wil_err(wil, "must specify MAC address when connected\n");
2545 memset(&cmd, 0, sizeof(cmd));
2547 cmd.sector_type = sector_type;
2548 memset(&reply, 0, sizeof(reply));
2549 rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
2551 WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2552 &reply, sizeof(reply),
2556 if (reply.evt.status) {
2557 wil_err(wil, "get rf selected sector cfg failed with status %d\n",
2559 return wil_rf_sector_status_to_rc(reply.evt.status);
2562 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2563 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2567 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2568 le64_to_cpu(reply.evt.tsf),
2570 nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
2571 le16_to_cpu(reply.evt.sector_idx)))
2572 goto nla_put_failure;
2574 rc = cfg80211_vendor_cmd_reply(msg);
2581 static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
2582 u8 mid, u16 sector_index,
2583 u8 sector_type, u8 cid)
2585 struct wmi_set_selected_rf_sector_index_cmd cmd;
2587 struct wmi_cmd_hdr wmi;
2588 struct wmi_set_selected_rf_sector_index_done_event evt;
2592 memset(&cmd, 0, sizeof(cmd));
2593 cmd.sector_idx = cpu_to_le16(sector_index);
2594 cmd.sector_type = sector_type;
2596 memset(&reply, 0, sizeof(reply));
2597 rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
2599 WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2600 &reply, sizeof(reply),
2604 return wil_rf_sector_status_to_rc(reply.evt.status);
2607 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
2608 struct wireless_dev *wdev,
2609 const void *data, int data_len)
2611 struct wil6210_priv *wil = wdev_to_wil(wdev);
2612 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2614 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2616 u8 sector_type, mac_addr[ETH_ALEN], i;
2619 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2622 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2623 wil_rf_sector_policy, NULL);
2625 wil_err(wil, "Invalid rf sector ATTR\n");
2629 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2630 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2631 wil_err(wil, "Invalid rf sector spec\n");
2635 sector_index = nla_get_u16(
2636 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2637 if (sector_index >= WIL_MAX_RF_SECTORS &&
2638 sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2639 wil_err(wil, "Invalid sector index %d\n", sector_index);
2643 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2644 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2645 wil_err(wil, "Invalid sector type %d\n", sector_type);
2649 if (tb[QCA_ATTR_MAC_ADDR]) {
2650 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2651 if (!is_broadcast_ether_addr(mac_addr)) {
2652 cid = wil_find_cid(wil, vif->mid, mac_addr);
2654 wil_err(wil, "invalid MAC address %pM\n",
2659 if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2660 wil_err(wil, "broadcast MAC valid only with unlocking\n");
2666 if (test_bit(wil_vif_fwconnected, vif->status)) {
2667 wil_err(wil, "must specify MAC address when connected\n");
2670 /* otherwise, using cid=0 for unassociated station */
2674 rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
2677 /* unlock all cids */
2678 rc = wil_rf_sector_wmi_set_selected(
2679 wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
2680 sector_type, WIL_CID_ALL);
2681 if (rc == -EINVAL) {
2682 for (i = 0; i < WIL6210_MAX_CID; i++) {
2683 if (wil->sta[i].mid != vif->mid)
2685 rc = wil_rf_sector_wmi_set_selected(
2687 WMI_INVALID_RF_SECTOR_INDEX,
2689 /* the FW will silently ignore and return
2690 * success for unused cid, so abort the loop
2691 * on any other error
2694 wil_err(wil, "unlock cid %d failed with status %d\n",