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[] = {
55 wil_memdup_ie(u8 **pdst, size_t *pdst_len, const u8 *src, size_t src_len)
61 *pdst = kmemdup(src, src_len, GFP_KERNEL);
67 static int wil_num_supported_channels(struct wil6210_priv *wil)
69 int num_channels = ARRAY_SIZE(wil_60ghz_channels);
71 if (!test_bit(WMI_FW_CAPABILITY_CHANNEL_4, wil->fw_capabilities))
77 void update_supported_bands(struct wil6210_priv *wil)
79 struct wiphy *wiphy = wil_to_wiphy(wil);
81 wil_dbg_misc(wil, "update supported bands");
83 wiphy->bands[NL80211_BAND_60GHZ]->n_channels =
84 wil_num_supported_channels(wil);
87 /* Vendor id to be used in vendor specific command and events
89 * NOTE: The authoritative place for definition of QCA_NL80211_VENDOR_ID,
90 * vendor subcmd definitions prefixed with QCA_NL80211_VENDOR_SUBCMD, and
91 * qca_wlan_vendor_attr is open source file src/common/qca-vendor.h in
92 * git://w1.fi/srv/git/hostap.git; the values here are just a copy of that
95 #define QCA_NL80211_VENDOR_ID 0x001374
97 #define WIL_MAX_RF_SECTORS (128)
98 #define WIL_CID_ALL (0xff)
100 enum qca_wlan_vendor_attr_rf_sector {
101 QCA_ATTR_MAC_ADDR = 6,
104 QCA_ATTR_DMG_RF_SECTOR_INDEX = 30,
105 QCA_ATTR_DMG_RF_SECTOR_TYPE = 31,
106 QCA_ATTR_DMG_RF_MODULE_MASK = 32,
107 QCA_ATTR_DMG_RF_SECTOR_CFG = 33,
108 QCA_ATTR_DMG_RF_SECTOR_MAX,
111 enum qca_wlan_vendor_attr_dmg_rf_sector_type {
112 QCA_ATTR_DMG_RF_SECTOR_TYPE_RX,
113 QCA_ATTR_DMG_RF_SECTOR_TYPE_TX,
114 QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX
117 enum qca_wlan_vendor_attr_dmg_rf_sector_cfg {
118 QCA_ATTR_DMG_RF_SECTOR_CFG_INVALID = 0,
119 QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
120 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
121 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
122 QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
123 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
124 QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
125 QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
128 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST,
129 QCA_ATTR_DMG_RF_SECTOR_CFG_MAX =
130 QCA_ATTR_DMG_RF_SECTOR_CFG_AFTER_LAST - 1
134 nla_policy wil_rf_sector_policy[QCA_ATTR_DMG_RF_SECTOR_MAX + 1] = {
135 [QCA_ATTR_MAC_ADDR] = { .len = ETH_ALEN },
136 [QCA_ATTR_DMG_RF_SECTOR_INDEX] = { .type = NLA_U16 },
137 [QCA_ATTR_DMG_RF_SECTOR_TYPE] = { .type = NLA_U8 },
138 [QCA_ATTR_DMG_RF_MODULE_MASK] = { .type = NLA_U32 },
139 [QCA_ATTR_DMG_RF_SECTOR_CFG] = { .type = NLA_NESTED },
143 nla_policy wil_rf_sector_cfg_policy[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1] = {
144 [QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] = { .type = NLA_U8 },
145 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] = { .type = NLA_U32 },
146 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] = { .type = NLA_U32 },
147 [QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] = { .type = NLA_U32 },
148 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] = { .type = NLA_U32 },
149 [QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] = { .type = NLA_U32 },
150 [QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16] = { .type = NLA_U32 },
153 enum qca_nl80211_vendor_subcmds {
154 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG = 139,
155 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG = 140,
156 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR = 141,
157 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR = 142,
160 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
161 struct wireless_dev *wdev,
162 const void *data, int data_len);
163 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
164 struct wireless_dev *wdev,
165 const void *data, int data_len);
166 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
167 struct wireless_dev *wdev,
168 const void *data, int data_len);
169 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
170 struct wireless_dev *wdev,
171 const void *data, int data_len);
173 /* vendor specific commands */
174 static const struct wiphy_vendor_command wil_nl80211_vendor_commands[] = {
176 .info.vendor_id = QCA_NL80211_VENDOR_ID,
177 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SECTOR_CFG,
178 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
179 WIPHY_VENDOR_CMD_NEED_RUNNING,
180 .doit = wil_rf_sector_get_cfg
183 .info.vendor_id = QCA_NL80211_VENDOR_ID,
184 .info.subcmd = QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SECTOR_CFG,
185 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
186 WIPHY_VENDOR_CMD_NEED_RUNNING,
187 .doit = wil_rf_sector_set_cfg
190 .info.vendor_id = QCA_NL80211_VENDOR_ID,
192 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_GET_SELECTED_SECTOR,
193 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
194 WIPHY_VENDOR_CMD_NEED_RUNNING,
195 .doit = wil_rf_sector_get_selected
198 .info.vendor_id = QCA_NL80211_VENDOR_ID,
200 QCA_NL80211_VENDOR_SUBCMD_DMG_RF_SET_SELECTED_SECTOR,
201 .flags = WIPHY_VENDOR_CMD_NEED_WDEV |
202 WIPHY_VENDOR_CMD_NEED_RUNNING,
203 .doit = wil_rf_sector_set_selected
207 static struct ieee80211_supported_band wil_band_60ghz = {
208 .channels = wil_60ghz_channels,
209 .n_channels = ARRAY_SIZE(wil_60ghz_channels),
211 .ht_supported = true,
213 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
214 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
216 /* MCS 1..12 - SC PHY */
217 .rx_mask = {0xfe, 0x1f}, /* 1..12 */
218 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
223 static const struct ieee80211_txrx_stypes
224 wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
225 [NL80211_IFTYPE_STATION] = {
226 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
227 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
228 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
229 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
231 [NL80211_IFTYPE_AP] = {
232 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
233 BIT(IEEE80211_STYPE_PROBE_RESP >> 4) |
234 BIT(IEEE80211_STYPE_ASSOC_RESP >> 4) |
235 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
236 BIT(IEEE80211_STYPE_AUTH >> 4) |
237 BIT(IEEE80211_STYPE_REASSOC_RESP >> 4),
238 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
239 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
240 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
241 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
242 BIT(IEEE80211_STYPE_AUTH >> 4) |
243 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
244 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4)
246 [NL80211_IFTYPE_P2P_CLIENT] = {
247 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
248 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
249 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
250 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
252 [NL80211_IFTYPE_P2P_GO] = {
253 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
254 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
255 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
256 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
258 [NL80211_IFTYPE_P2P_DEVICE] = {
259 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
260 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
261 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
262 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
266 static const u32 wil_cipher_suites[] = {
267 WLAN_CIPHER_SUITE_GCMP,
270 static const char * const key_usage_str[] = {
271 [WMI_KEY_USE_PAIRWISE] = "PTK",
272 [WMI_KEY_USE_RX_GROUP] = "RX_GTK",
273 [WMI_KEY_USE_TX_GROUP] = "TX_GTK",
276 int wil_iftype_nl2wmi(enum nl80211_iftype type)
278 static const struct {
279 enum nl80211_iftype nl;
280 enum wmi_network_type wmi;
282 {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
283 {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
284 {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
285 {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
286 {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
287 {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
291 for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
292 if (__nl2wmi[i].nl == type)
293 return __nl2wmi[i].wmi;
299 int wil_cid_fill_sinfo(struct wil6210_vif *vif, int cid,
300 struct station_info *sinfo)
302 struct wil6210_priv *wil = vif_to_wil(vif);
303 struct wmi_notify_req_cmd cmd = {
308 struct wmi_cmd_hdr wmi;
309 struct wmi_notify_req_done_event evt;
311 struct wil_net_stats *stats = &wil->sta[cid].stats;
314 memset(&reply, 0, sizeof(reply));
316 rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd),
317 WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
321 wil_dbg_wmi(wil, "Link status for CID %d MID %d: {\n"
322 " MCS %d TSF 0x%016llx\n"
323 " BF status 0x%08x RSSI %d SQI %d%%\n"
324 " Tx Tpt %d goodput %d Rx goodput %d\n"
325 " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
326 cid, vif->mid, le16_to_cpu(reply.evt.bf_mcs),
327 le64_to_cpu(reply.evt.tsf), reply.evt.status,
330 le32_to_cpu(reply.evt.tx_tpt),
331 le32_to_cpu(reply.evt.tx_goodput),
332 le32_to_cpu(reply.evt.rx_goodput),
333 le16_to_cpu(reply.evt.my_rx_sector),
334 le16_to_cpu(reply.evt.my_tx_sector),
335 le16_to_cpu(reply.evt.other_rx_sector),
336 le16_to_cpu(reply.evt.other_tx_sector));
338 sinfo->generation = wil->sinfo_gen;
340 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
341 BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
342 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
343 BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
344 BIT_ULL(NL80211_STA_INFO_RX_BITRATE) |
345 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
346 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
347 BIT_ULL(NL80211_STA_INFO_TX_FAILED);
349 sinfo->txrate.flags = RATE_INFO_FLAGS_60G;
350 sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
351 sinfo->rxrate.mcs = stats->last_mcs_rx;
352 sinfo->rx_bytes = stats->rx_bytes;
353 sinfo->rx_packets = stats->rx_packets;
354 sinfo->rx_dropped_misc = stats->rx_dropped;
355 sinfo->tx_bytes = stats->tx_bytes;
356 sinfo->tx_packets = stats->tx_packets;
357 sinfo->tx_failed = stats->tx_errors;
359 if (test_bit(wil_vif_fwconnected, vif->status)) {
360 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
361 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING,
362 wil->fw_capabilities))
363 sinfo->signal = reply.evt.rssi;
365 sinfo->signal = reply.evt.sqi;
371 static int wil_cfg80211_get_station(struct wiphy *wiphy,
372 struct net_device *ndev,
373 const u8 *mac, struct station_info *sinfo)
375 struct wil6210_vif *vif = ndev_to_vif(ndev);
376 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
379 int cid = wil_find_cid(wil, vif->mid, mac);
381 wil_dbg_misc(wil, "get_station: %pM CID %d MID %d\n", mac, cid,
386 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
392 * Find @idx-th active STA for specific MID for station dump.
394 static int wil_find_cid_by_idx(struct wil6210_priv *wil, u8 mid, int idx)
398 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
399 if (wil->sta[i].status == wil_sta_unused)
401 if (wil->sta[i].mid != mid)
411 static int wil_cfg80211_dump_station(struct wiphy *wiphy,
412 struct net_device *dev, int idx,
413 u8 *mac, struct station_info *sinfo)
415 struct wil6210_vif *vif = ndev_to_vif(dev);
416 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
418 int cid = wil_find_cid_by_idx(wil, vif->mid, idx);
423 ether_addr_copy(mac, wil->sta[cid].addr);
424 wil_dbg_misc(wil, "dump_station: %pM CID %d MID %d\n", mac, cid,
427 rc = wil_cid_fill_sinfo(vif, cid, sinfo);
432 static int wil_cfg80211_start_p2p_device(struct wiphy *wiphy,
433 struct wireless_dev *wdev)
435 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
437 wil_dbg_misc(wil, "start_p2p_device: entered\n");
438 wil->p2p_dev_started = 1;
442 static void wil_cfg80211_stop_p2p_device(struct wiphy *wiphy,
443 struct wireless_dev *wdev)
445 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
447 if (!wil->p2p_dev_started)
450 wil_dbg_misc(wil, "stop_p2p_device: entered\n");
451 mutex_lock(&wil->mutex);
452 mutex_lock(&wil->vif_mutex);
453 wil_p2p_stop_radio_operations(wil);
454 wil->p2p_dev_started = 0;
455 mutex_unlock(&wil->vif_mutex);
456 mutex_unlock(&wil->mutex);
459 static int wil_cfg80211_validate_add_iface(struct wil6210_priv *wil,
460 enum nl80211_iftype new_type)
463 struct wireless_dev *wdev;
464 struct iface_combination_params params = {
465 .num_different_channels = 1,
468 for (i = 0; i < wil->max_vifs; i++) {
470 wdev = vif_to_wdev(wil->vifs[i]);
471 params.iftype_num[wdev->iftype]++;
474 params.iftype_num[new_type]++;
475 return cfg80211_check_combinations(wil->wiphy, ¶ms);
478 static int wil_cfg80211_validate_change_iface(struct wil6210_priv *wil,
479 struct wil6210_vif *vif,
480 enum nl80211_iftype new_type)
483 struct wireless_dev *wdev;
484 struct iface_combination_params params = {
485 .num_different_channels = 1,
487 bool check_combos = false;
489 for (i = 0; i < wil->max_vifs; i++) {
490 struct wil6210_vif *vif_pos = wil->vifs[i];
492 if (vif_pos && vif != vif_pos) {
493 wdev = vif_to_wdev(vif_pos);
494 params.iftype_num[wdev->iftype]++;
500 params.iftype_num[new_type]++;
501 ret = cfg80211_check_combinations(wil->wiphy, ¶ms);
506 static struct wireless_dev *
507 wil_cfg80211_add_iface(struct wiphy *wiphy, const char *name,
508 unsigned char name_assign_type,
509 enum nl80211_iftype type,
510 struct vif_params *params)
512 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
513 struct net_device *ndev_main = wil->main_ndev, *ndev;
514 struct wil6210_vif *vif;
515 struct wireless_dev *p2p_wdev, *wdev;
518 wil_dbg_misc(wil, "add_iface, type %d\n", type);
520 /* P2P device is not a real virtual interface, it is a management-only
521 * interface that shares the main interface.
522 * Skip concurrency checks here.
524 if (type == NL80211_IFTYPE_P2P_DEVICE) {
526 wil_err(wil, "P2P_DEVICE interface already created\n");
527 return ERR_PTR(-EINVAL);
530 p2p_wdev = kzalloc(sizeof(*p2p_wdev), GFP_KERNEL);
532 return ERR_PTR(-ENOMEM);
534 p2p_wdev->iftype = type;
535 p2p_wdev->wiphy = wiphy;
536 /* use our primary ethernet address */
537 ether_addr_copy(p2p_wdev->address, ndev_main->perm_addr);
539 wil->p2p_wdev = p2p_wdev;
544 if (!wil->wiphy->n_iface_combinations) {
545 wil_err(wil, "virtual interfaces not supported\n");
546 return ERR_PTR(-EINVAL);
549 rc = wil_cfg80211_validate_add_iface(wil, type);
551 wil_err(wil, "iface validation failed, err=%d\n", rc);
555 vif = wil_vif_alloc(wil, name, name_assign_type, type);
557 return ERR_CAST(vif);
559 ndev = vif_to_ndev(vif);
560 ether_addr_copy(ndev->perm_addr, ndev_main->perm_addr);
561 if (is_valid_ether_addr(params->macaddr)) {
562 ether_addr_copy(ndev->dev_addr, params->macaddr);
564 ether_addr_copy(ndev->dev_addr, ndev_main->perm_addr);
565 ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << vif->mid)) |
566 0x2; /* locally administered */
568 wdev = vif_to_wdev(vif);
569 ether_addr_copy(wdev->address, ndev->dev_addr);
571 rc = wil_vif_add(wil, vif);
575 wil_info(wil, "added VIF, mid %d iftype %d MAC %pM\n",
576 vif->mid, type, wdev->address);
583 int wil_vif_prepare_stop(struct wil6210_vif *vif)
585 struct wil6210_priv *wil = vif_to_wil(vif);
586 struct wireless_dev *wdev = vif_to_wdev(vif);
587 struct net_device *ndev;
590 if (wdev->iftype != NL80211_IFTYPE_AP)
593 ndev = vif_to_ndev(vif);
594 if (netif_carrier_ok(ndev)) {
595 rc = wmi_pcp_stop(vif);
597 wil_info(wil, "failed to stop AP, status %d\n",
602 netif_carrier_off(ndev);
608 static int wil_cfg80211_del_iface(struct wiphy *wiphy,
609 struct wireless_dev *wdev)
611 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
612 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
615 wil_dbg_misc(wil, "del_iface\n");
617 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
618 if (wdev != wil->p2p_wdev) {
619 wil_err(wil, "delete of incorrect interface 0x%p\n",
624 wil_cfg80211_stop_p2p_device(wiphy, wdev);
625 wil_p2p_wdev_free(wil);
630 wil_err(wil, "cannot remove the main interface\n");
634 rc = wil_vif_prepare_stop(vif);
638 wil_info(wil, "deleted VIF, mid %d iftype %d MAC %pM\n",
639 vif->mid, wdev->iftype, wdev->address);
641 wil_vif_remove(wil, vif->mid);
646 static int wil_cfg80211_change_iface(struct wiphy *wiphy,
647 struct net_device *ndev,
648 enum nl80211_iftype type,
649 struct vif_params *params)
651 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
652 struct wil6210_vif *vif = ndev_to_vif(ndev);
653 struct wireless_dev *wdev = vif_to_wdev(vif);
655 bool fw_reset = false;
657 wil_dbg_misc(wil, "change_iface: type=%d\n", type);
659 if (wiphy->n_iface_combinations) {
660 rc = wil_cfg80211_validate_change_iface(wil, vif, type);
662 wil_err(wil, "iface validation failed, err=%d\n", rc);
667 /* do not reset FW when there are active VIFs,
668 * because it can cause significant disruption
670 if (!wil_has_other_active_ifaces(wil, ndev, true, false) &&
671 netif_running(ndev) && !wil_is_recovery_blocked(wil)) {
672 wil_dbg_misc(wil, "interface is up. resetting...\n");
673 mutex_lock(&wil->mutex);
676 mutex_unlock(&wil->mutex);
684 case NL80211_IFTYPE_STATION:
685 case NL80211_IFTYPE_AP:
686 case NL80211_IFTYPE_P2P_CLIENT:
687 case NL80211_IFTYPE_P2P_GO:
689 case NL80211_IFTYPE_MONITOR:
691 wil->monitor_flags = params->flags;
697 if (vif->mid != 0 && wil_has_active_ifaces(wil, true, false)) {
699 wil_vif_prepare_stop(vif);
700 rc = wmi_port_delete(wil, vif->mid);
703 rc = wmi_port_allocate(wil, vif->mid, ndev->dev_addr, type);
712 static int wil_cfg80211_scan(struct wiphy *wiphy,
713 struct cfg80211_scan_request *request)
715 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
716 struct wireless_dev *wdev = request->wdev;
717 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
719 struct wmi_start_scan_cmd cmd;
725 wil_dbg_misc(wil, "scan: wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
727 /* scan is supported on client interfaces and on AP interface */
728 switch (wdev->iftype) {
729 case NL80211_IFTYPE_STATION:
730 case NL80211_IFTYPE_P2P_CLIENT:
731 case NL80211_IFTYPE_P2P_DEVICE:
732 case NL80211_IFTYPE_AP:
738 /* FW don't support scan after connection attempt */
739 if (test_bit(wil_status_dontscan, wil->status)) {
740 wil_err(wil, "Can't scan now\n");
744 mutex_lock(&wil->mutex);
746 mutex_lock(&wil->vif_mutex);
747 if (vif->scan_request || vif->p2p.discovery_started) {
748 wil_err(wil, "Already scanning\n");
749 mutex_unlock(&wil->vif_mutex);
753 mutex_unlock(&wil->vif_mutex);
755 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
756 if (!wil->p2p_dev_started) {
757 wil_err(wil, "P2P search requested on stopped P2P device\n");
761 /* social scan on P2P_DEVICE is handled as p2p search */
762 if (wil_p2p_is_social_scan(request)) {
763 vif->scan_request = request;
765 wil->radio_wdev = wdev;
766 rc = wil_p2p_search(vif, request);
770 wil->main_ndev->ieee80211_ptr;
771 vif->scan_request = NULL;
777 (void)wil_p2p_stop_discovery(vif);
779 wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
780 wil_dbg_misc(wil, "SSID count: %d", request->n_ssids);
782 for (i = 0; i < request->n_ssids; i++) {
783 wil_dbg_misc(wil, "SSID[%d]", i);
784 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
785 request->ssids[i].ssid,
786 request->ssids[i].ssid_len, true);
789 if (request->n_ssids)
790 rc = wmi_set_ssid(vif, request->ssids[0].ssid_len,
791 request->ssids[0].ssid);
793 rc = wmi_set_ssid(vif, 0, NULL);
796 wil_err(wil, "set SSID for scan request failed: %d\n", rc);
800 vif->scan_request = request;
801 mod_timer(&vif->scan_timer, jiffies + WIL6210_SCAN_TO);
803 memset(&cmd, 0, sizeof(cmd));
804 cmd.cmd.scan_type = WMI_ACTIVE_SCAN;
805 cmd.cmd.num_channels = 0;
806 n = min(request->n_channels, 4U);
807 for (i = 0; i < n; i++) {
808 int ch = request->channels[i]->hw_value;
812 "Scan requested for unknown frequency %dMhz\n",
813 request->channels[i]->center_freq);
816 /* 0-based channel indexes */
817 cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
818 wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
819 request->channels[i]->center_freq);
823 wil_hex_dump_misc("Scan IE ", DUMP_PREFIX_OFFSET, 16, 1,
824 request->ie, request->ie_len, true);
826 wil_dbg_misc(wil, "Scan has no IE's\n");
828 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
829 request->ie_len, request->ie);
833 if (wil->discovery_mode && cmd.cmd.scan_type == WMI_ACTIVE_SCAN) {
834 cmd.cmd.discovery_mode = 1;
835 wil_dbg_misc(wil, "active scan with discovery_mode=1\n");
839 wil->radio_wdev = wdev;
840 rc = wmi_send(wil, WMI_START_SCAN_CMDID, vif->mid,
841 &cmd, sizeof(cmd.cmd) +
842 cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
846 del_timer_sync(&vif->scan_timer);
848 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
849 vif->scan_request = NULL;
852 mutex_unlock(&wil->mutex);
856 static void wil_cfg80211_abort_scan(struct wiphy *wiphy,
857 struct wireless_dev *wdev)
859 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
860 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
862 wil_dbg_misc(wil, "wdev=0x%p iftype=%d\n", wdev, wdev->iftype);
864 mutex_lock(&wil->mutex);
865 mutex_lock(&wil->vif_mutex);
867 if (!vif->scan_request)
870 if (wdev != vif->scan_request->wdev) {
871 wil_dbg_misc(wil, "abort scan was called on the wrong iface\n");
875 if (wdev == wil->p2p_wdev && wil->radio_wdev == wil->p2p_wdev)
876 wil_p2p_stop_radio_operations(wil);
878 wil_abort_scan(vif, true);
881 mutex_unlock(&wil->vif_mutex);
882 mutex_unlock(&wil->mutex);
885 static void wil_print_crypto(struct wil6210_priv *wil,
886 struct cfg80211_crypto_settings *c)
890 wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
891 c->wpa_versions, c->cipher_group);
892 wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
893 n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
894 for (i = 0; i < n; i++)
895 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
896 c->ciphers_pairwise[i]);
897 wil_dbg_misc(wil, "}\n");
898 wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
899 n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
900 for (i = 0; i < n; i++)
901 wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
903 wil_dbg_misc(wil, "}\n");
904 wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
905 c->control_port, be16_to_cpu(c->control_port_ethertype),
906 c->control_port_no_encrypt);
910 wil_get_auth_type_name(enum nl80211_auth_type auth_type)
913 case NL80211_AUTHTYPE_OPEN_SYSTEM:
914 return "OPEN_SYSTEM";
915 case NL80211_AUTHTYPE_SHARED_KEY:
917 case NL80211_AUTHTYPE_FT:
919 case NL80211_AUTHTYPE_NETWORK_EAP:
920 return "NETWORK_EAP";
921 case NL80211_AUTHTYPE_SAE:
923 case NL80211_AUTHTYPE_AUTOMATIC:
929 static void wil_print_connect_params(struct wil6210_priv *wil,
930 struct cfg80211_connect_params *sme)
932 wil_info(wil, "Connecting to:\n");
934 wil_info(wil, " Channel: %d freq %d\n",
935 sme->channel->hw_value, sme->channel->center_freq);
938 wil_info(wil, " BSSID: %pM\n", sme->bssid);
940 print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
941 16, 1, sme->ssid, sme->ssid_len, true);
943 wil_info(wil, " Previous BSSID=%pM\n", sme->prev_bssid);
944 wil_info(wil, " Auth Type: %s\n",
945 wil_get_auth_type_name(sme->auth_type));
946 wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
947 wil_info(wil, " PBSS: %d\n", sme->pbss);
948 wil_print_crypto(wil, &sme->crypto);
951 static int wil_ft_connect(struct wiphy *wiphy,
952 struct net_device *ndev,
953 struct cfg80211_connect_params *sme)
955 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
956 struct wil6210_vif *vif = ndev_to_vif(ndev);
957 struct wmi_ft_auth_cmd auth_cmd;
960 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING, wil->fw_capabilities)) {
961 wil_err(wil, "FT: FW does not support FT roaming\n");
965 if (!sme->prev_bssid) {
966 wil_err(wil, "FT: prev_bssid was not set\n");
970 if (ether_addr_equal(sme->prev_bssid, sme->bssid)) {
971 wil_err(wil, "FT: can not roam to same AP\n");
975 if (!test_bit(wil_vif_fwconnected, vif->status)) {
976 wil_err(wil, "FT: roam while not connected\n");
980 if (vif->privacy != sme->privacy) {
981 wil_err(wil, "FT: privacy mismatch, current (%d) roam (%d)\n",
982 vif->privacy, sme->privacy);
987 wil_err(wil, "FT: roam is not valid for PBSS\n");
991 memset(&auth_cmd, 0, sizeof(auth_cmd));
992 auth_cmd.channel = sme->channel->hw_value - 1;
993 ether_addr_copy(auth_cmd.bssid, sme->bssid);
995 wil_info(wil, "FT: roaming\n");
997 set_bit(wil_vif_ft_roam, vif->status);
998 rc = wmi_send(wil, WMI_FT_AUTH_CMDID, vif->mid,
999 &auth_cmd, sizeof(auth_cmd));
1001 mod_timer(&vif->connect_timer,
1002 jiffies + msecs_to_jiffies(5000));
1004 clear_bit(wil_vif_ft_roam, vif->status);
1009 static int wil_cfg80211_connect(struct wiphy *wiphy,
1010 struct net_device *ndev,
1011 struct cfg80211_connect_params *sme)
1013 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1014 struct wil6210_vif *vif = ndev_to_vif(ndev);
1015 struct cfg80211_bss *bss;
1016 struct wmi_connect_cmd conn;
1021 bool is_ft_roam = false;
1023 enum ieee80211_bss_type bss_type = IEEE80211_BSS_TYPE_ESS;
1025 wil_dbg_misc(wil, "connect, mid=%d\n", vif->mid);
1026 wil_print_connect_params(wil, sme);
1028 if (sme->auth_type == NL80211_AUTHTYPE_FT)
1030 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC &&
1031 test_bit(wil_vif_fwconnected, vif->status))
1035 if (test_bit(wil_vif_fwconnecting, vif->status) ||
1036 test_bit(wil_vif_fwconnected, vif->status))
1039 if (sme->ie_len > WMI_MAX_IE_LEN) {
1040 wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
1045 cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
1047 if (sme->privacy && !rsn_eid) {
1048 wil_info(wil, "WSC connection\n");
1050 wil_err(wil, "No WSC with FT roam\n");
1056 bss_type = IEEE80211_BSS_TYPE_PBSS;
1058 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1059 sme->ssid, sme->ssid_len,
1060 bss_type, IEEE80211_PRIVACY_ANY);
1062 wil_err(wil, "Unable to find BSS\n");
1066 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1068 wil_err(wil, "No SSID\n");
1072 vif->privacy = sme->privacy;
1073 vif->pbss = sme->pbss;
1075 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
1079 switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
1080 case WLAN_CAPABILITY_DMG_TYPE_AP:
1081 network_type = WMI_NETTYPE_INFRA;
1083 case WLAN_CAPABILITY_DMG_TYPE_PBSS:
1084 network_type = WMI_NETTYPE_P2P;
1087 wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
1093 ch = bss->channel->hw_value;
1095 wil_err(wil, "BSS at unknown frequency %dMhz\n",
1096 bss->channel->center_freq);
1102 if (network_type != WMI_NETTYPE_INFRA) {
1103 wil_err(wil, "FT: Unsupported BSS type, capability= 0x%04x\n",
1108 rc = wil_ft_connect(wiphy, ndev, sme);
1115 /* For secure assoc, remove old keys */
1116 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
1117 WMI_KEY_USE_PAIRWISE);
1119 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
1122 rc = wmi_del_cipher_key(vif, 0, bss->bssid,
1123 WMI_KEY_USE_RX_GROUP);
1125 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
1130 /* WMI_CONNECT_CMD */
1131 memset(&conn, 0, sizeof(conn));
1132 conn.network_type = network_type;
1134 if (rsn_eid) { /* regular secure connection */
1135 conn.dot11_auth_mode = WMI_AUTH11_SHARED;
1136 conn.auth_mode = WMI_AUTH_WPA2_PSK;
1137 conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
1138 conn.pairwise_crypto_len = 16;
1139 conn.group_crypto_type = WMI_CRYPT_AES_GCMP;
1140 conn.group_crypto_len = 16;
1142 conn.dot11_auth_mode = WMI_AUTH11_WSC;
1143 conn.auth_mode = WMI_AUTH_NONE;
1145 } else { /* insecure connection */
1146 conn.dot11_auth_mode = WMI_AUTH11_OPEN;
1147 conn.auth_mode = WMI_AUTH_NONE;
1150 conn.ssid_len = min_t(u8, ssid_eid[1], 32);
1151 memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
1152 conn.channel = ch - 1;
1154 ether_addr_copy(conn.bssid, bss->bssid);
1155 ether_addr_copy(conn.dst_mac, bss->bssid);
1157 set_bit(wil_vif_fwconnecting, vif->status);
1159 rc = wmi_send(wil, WMI_CONNECT_CMDID, vif->mid, &conn, sizeof(conn));
1161 netif_carrier_on(ndev);
1162 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1163 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1165 /* Connect can take lots of time */
1166 mod_timer(&vif->connect_timer,
1167 jiffies + msecs_to_jiffies(5000));
1169 clear_bit(wil_vif_fwconnecting, vif->status);
1173 cfg80211_put_bss(wiphy, bss);
1178 static int wil_cfg80211_disconnect(struct wiphy *wiphy,
1179 struct net_device *ndev,
1183 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1184 struct wil6210_vif *vif = ndev_to_vif(ndev);
1186 wil_dbg_misc(wil, "disconnect: reason=%d, mid=%d\n",
1187 reason_code, vif->mid);
1189 if (!(test_bit(wil_vif_fwconnecting, vif->status) ||
1190 test_bit(wil_vif_fwconnected, vif->status))) {
1191 wil_err(wil, "Disconnect was called while disconnected\n");
1195 vif->locally_generated_disc = true;
1196 rc = wmi_call(wil, WMI_DISCONNECT_CMDID, vif->mid, NULL, 0,
1197 WMI_DISCONNECT_EVENTID, NULL, 0,
1198 WIL6210_DISCONNECT_TO_MS);
1200 wil_err(wil, "disconnect error %d\n", rc);
1205 static int wil_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1207 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1210 /* these parameters are explicitly not supported */
1211 if (changed & (WIPHY_PARAM_RETRY_LONG |
1212 WIPHY_PARAM_FRAG_THRESHOLD |
1213 WIPHY_PARAM_RTS_THRESHOLD))
1216 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1217 rc = wmi_set_mgmt_retry(wil, wiphy->retry_short);
1225 int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
1226 struct cfg80211_mgmt_tx_params *params,
1229 const u8 *buf = params->buf;
1230 size_t len = params->len;
1231 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1232 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1236 wil_dbg_misc(wil, "mgmt_tx: channel %d offchan %d, wait %d\n",
1237 params->chan ? params->chan->hw_value : -1,
1241 /* Note, currently we support the "wait" parameter only on AP mode.
1242 * In other modes, user-space must call remain_on_channel before
1243 * mgmt_tx or listen on a channel other than active one.
1246 if (params->chan && params->chan->hw_value == 0) {
1247 wil_err(wil, "invalid channel\n");
1251 if (wdev->iftype != NL80211_IFTYPE_AP) {
1253 "send WMI_SW_TX_REQ_CMDID on non-AP interfaces\n");
1254 rc = wmi_mgmt_tx(vif, buf, len);
1258 if (!params->chan || params->chan->hw_value == vif->channel) {
1260 "send WMI_SW_TX_REQ_CMDID for on-channel\n");
1261 rc = wmi_mgmt_tx(vif, buf, len);
1265 if (params->offchan == 0) {
1267 "invalid channel params: current %d requested %d, off-channel not allowed\n",
1268 vif->channel, params->chan->hw_value);
1272 /* use the wmi_mgmt_tx_ext only on AP mode and off-channel */
1273 rc = wmi_mgmt_tx_ext(vif, buf, len, params->chan->hw_value,
1277 tx_status = (rc == 0);
1278 cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
1279 tx_status, GFP_KERNEL);
1284 static int wil_cfg80211_set_channel(struct wiphy *wiphy,
1285 struct cfg80211_chan_def *chandef)
1287 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1289 wil->monitor_chandef = *chandef;
1294 static enum wmi_key_usage wil_detect_key_usage(struct wireless_dev *wdev,
1297 struct wil6210_priv *wil = wdev_to_wil(wdev);
1298 enum wmi_key_usage rc;
1301 rc = WMI_KEY_USE_PAIRWISE;
1303 switch (wdev->iftype) {
1304 case NL80211_IFTYPE_STATION:
1305 case NL80211_IFTYPE_P2P_CLIENT:
1306 rc = WMI_KEY_USE_RX_GROUP;
1308 case NL80211_IFTYPE_AP:
1309 case NL80211_IFTYPE_P2P_GO:
1310 rc = WMI_KEY_USE_TX_GROUP;
1313 /* TODO: Rx GTK or Tx GTK? */
1314 wil_err(wil, "Can't determine GTK type\n");
1315 rc = WMI_KEY_USE_RX_GROUP;
1319 wil_dbg_misc(wil, "detect_key_usage: -> %s\n", key_usage_str[rc]);
1324 static struct wil_sta_info *
1325 wil_find_sta_by_key_usage(struct wil6210_priv *wil, u8 mid,
1326 enum wmi_key_usage key_usage, const u8 *mac_addr)
1330 if (key_usage == WMI_KEY_USE_TX_GROUP)
1331 return NULL; /* not needed */
1333 /* supplicant provides Rx group key in STA mode with NULL MAC address */
1335 cid = wil_find_cid(wil, mid, mac_addr);
1336 else if (key_usage == WMI_KEY_USE_RX_GROUP)
1337 cid = wil_find_cid_by_idx(wil, mid, 0);
1339 wil_err(wil, "No CID for %pM %s\n", mac_addr,
1340 key_usage_str[key_usage]);
1341 return ERR_PTR(cid);
1344 return &wil->sta[cid];
1347 void wil_set_crypto_rx(u8 key_index, enum wmi_key_usage key_usage,
1348 struct wil_sta_info *cs,
1349 struct key_params *params)
1351 struct wil_tid_crypto_rx_single *cc;
1357 switch (key_usage) {
1358 case WMI_KEY_USE_PAIRWISE:
1359 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1360 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1362 memcpy(cc->pn, params->seq,
1363 IEEE80211_GCMP_PN_LEN);
1365 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1369 case WMI_KEY_USE_RX_GROUP:
1370 cc = &cs->group_crypto_rx.key_id[key_index];
1372 memcpy(cc->pn, params->seq, IEEE80211_GCMP_PN_LEN);
1374 memset(cc->pn, 0, IEEE80211_GCMP_PN_LEN);
1382 static void wil_del_rx_key(u8 key_index, enum wmi_key_usage key_usage,
1383 struct wil_sta_info *cs)
1385 struct wil_tid_crypto_rx_single *cc;
1391 switch (key_usage) {
1392 case WMI_KEY_USE_PAIRWISE:
1393 for (tid = 0; tid < WIL_STA_TID_NUM; tid++) {
1394 cc = &cs->tid_crypto_rx[tid].key_id[key_index];
1395 cc->key_set = false;
1398 case WMI_KEY_USE_RX_GROUP:
1399 cc = &cs->group_crypto_rx.key_id[key_index];
1400 cc->key_set = false;
1407 static int wil_cfg80211_add_key(struct wiphy *wiphy,
1408 struct net_device *ndev,
1409 u8 key_index, bool pairwise,
1411 struct key_params *params)
1414 struct wil6210_vif *vif = ndev_to_vif(ndev);
1415 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1416 struct wireless_dev *wdev = vif_to_wdev(vif);
1417 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1418 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1423 wil_err(wil, "NULL params\n");
1427 wil_dbg_misc(wil, "add_key: %pM %s[%d] PN %*phN\n",
1428 mac_addr, key_usage_str[key_usage], key_index,
1429 params->seq_len, params->seq);
1432 /* in FT, sta info may not be available as add_key may be
1433 * sent by host before FW sends WMI_CONNECT_EVENT
1435 if (!test_bit(wil_vif_ft_roam, vif->status)) {
1436 wil_err(wil, "Not connected, %pM %s[%d] PN %*phN\n",
1437 mac_addr, key_usage_str[key_usage], key_index,
1438 params->seq_len, params->seq);
1444 wil_del_rx_key(key_index, key_usage, cs);
1446 if (params->seq && params->seq_len != IEEE80211_GCMP_PN_LEN) {
1448 "Wrong PN len %d, %pM %s[%d] PN %*phN\n",
1449 params->seq_len, mac_addr,
1450 key_usage_str[key_usage], key_index,
1451 params->seq_len, params->seq);
1455 rc = wmi_add_cipher_key(vif, key_index, mac_addr, params->key_len,
1456 params->key, key_usage);
1457 if (!rc && !IS_ERR(cs)) {
1458 /* update local storage used for AP recovery */
1459 if (key_usage == WMI_KEY_USE_TX_GROUP && params->key &&
1460 params->key_len <= WMI_MAX_KEY_LEN) {
1461 vif->gtk_index = key_index;
1462 memcpy(vif->gtk, params->key, params->key_len);
1463 vif->gtk_len = params->key_len;
1465 /* in FT set crypto will take place upon receiving
1466 * WMI_RING_EN_EVENTID event
1468 wil_set_crypto_rx(key_index, key_usage, cs, params);
1474 static int wil_cfg80211_del_key(struct wiphy *wiphy,
1475 struct net_device *ndev,
1476 u8 key_index, bool pairwise,
1479 struct wil6210_vif *vif = ndev_to_vif(ndev);
1480 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1481 struct wireless_dev *wdev = vif_to_wdev(vif);
1482 enum wmi_key_usage key_usage = wil_detect_key_usage(wdev, pairwise);
1483 struct wil_sta_info *cs = wil_find_sta_by_key_usage(wil, vif->mid,
1487 wil_dbg_misc(wil, "del_key: %pM %s[%d]\n", mac_addr,
1488 key_usage_str[key_usage], key_index);
1491 wil_info(wil, "Not connected, %pM %s[%d]\n",
1492 mac_addr, key_usage_str[key_usage], key_index);
1494 if (!IS_ERR_OR_NULL(cs))
1495 wil_del_rx_key(key_index, key_usage, cs);
1497 return wmi_del_cipher_key(vif, key_index, mac_addr, key_usage);
1500 /* Need to be present or wiphy_new() will WARN */
1501 static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
1502 struct net_device *ndev,
1503 u8 key_index, bool unicast,
1506 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1508 wil_dbg_misc(wil, "set_default_key: entered\n");
1512 static int wil_remain_on_channel(struct wiphy *wiphy,
1513 struct wireless_dev *wdev,
1514 struct ieee80211_channel *chan,
1515 unsigned int duration,
1518 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1522 "remain_on_channel: center_freq=%d, duration=%d iftype=%d\n",
1523 chan->center_freq, duration, wdev->iftype);
1525 rc = wil_p2p_listen(wil, wdev, duration, chan, cookie);
1529 static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
1530 struct wireless_dev *wdev,
1533 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1534 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
1536 wil_dbg_misc(wil, "cancel_remain_on_channel\n");
1538 return wil_p2p_cancel_listen(vif, cookie);
1542 * find a specific IE in a list of IEs
1543 * return a pointer to the beginning of IE in the list
1544 * or NULL if not found
1546 static const u8 *_wil_cfg80211_find_ie(const u8 *ies, u16 ies_len, const u8 *ie,
1549 struct ieee80211_vendor_ie *vie;
1552 /* IE tag at offset 0, length at offset 1 */
1553 if (ie_len < 2 || 2 + ie[1] > ie_len)
1556 if (ie[0] != WLAN_EID_VENDOR_SPECIFIC)
1557 return cfg80211_find_ie(ie[0], ies, ies_len);
1559 /* make sure there is room for 3 bytes OUI + 1 byte OUI type */
1562 vie = (struct ieee80211_vendor_ie *)ie;
1563 oui = vie->oui[0] << 16 | vie->oui[1] << 8 | vie->oui[2];
1564 return cfg80211_find_vendor_ie(oui, vie->oui_type, ies,
1569 * merge the IEs in two lists into a single list.
1570 * do not include IEs from the second list which exist in the first list.
1571 * add only vendor specific IEs from second list to keep
1572 * the merged list sorted (since vendor-specific IE has the
1573 * highest tag number)
1574 * caller must free the allocated memory for merged IEs
1576 static int _wil_cfg80211_merge_extra_ies(const u8 *ies1, u16 ies1_len,
1577 const u8 *ies2, u16 ies2_len,
1578 u8 **merged_ies, u16 *merged_len)
1583 if (ies1_len == 0 && ies2_len == 0) {
1589 buf = kmalloc(ies1_len + ies2_len, GFP_KERNEL);
1592 memcpy(buf, ies1, ies1_len);
1593 dpos = buf + ies1_len;
1595 while (spos + 1 < ies2 + ies2_len) {
1596 /* IE tag at offset 0, length at offset 1 */
1597 u16 ielen = 2 + spos[1];
1599 if (spos + ielen > ies2 + ies2_len)
1601 if (spos[0] == WLAN_EID_VENDOR_SPECIFIC &&
1602 !_wil_cfg80211_find_ie(ies1, ies1_len, spos, ielen)) {
1603 memcpy(dpos, spos, ielen);
1610 *merged_len = dpos - buf;
1614 static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
1616 wil_hex_dump_misc("head ", DUMP_PREFIX_OFFSET, 16, 1,
1617 b->head, b->head_len, true);
1618 wil_hex_dump_misc("tail ", DUMP_PREFIX_OFFSET, 16, 1,
1619 b->tail, b->tail_len, true);
1620 wil_hex_dump_misc("BCON IE ", DUMP_PREFIX_OFFSET, 16, 1,
1621 b->beacon_ies, b->beacon_ies_len, true);
1622 wil_hex_dump_misc("PROBE ", DUMP_PREFIX_OFFSET, 16, 1,
1623 b->probe_resp, b->probe_resp_len, true);
1624 wil_hex_dump_misc("PROBE IE ", DUMP_PREFIX_OFFSET, 16, 1,
1625 b->proberesp_ies, b->proberesp_ies_len, true);
1626 wil_hex_dump_misc("ASSOC IE ", DUMP_PREFIX_OFFSET, 16, 1,
1627 b->assocresp_ies, b->assocresp_ies_len, true);
1630 /* internal functions for device reset and starting AP */
1632 _wil_cfg80211_get_proberesp_ies(const u8 *proberesp, u16 proberesp_len,
1638 struct ieee80211_mgmt *f =
1639 (struct ieee80211_mgmt *)proberesp;
1640 size_t hlen = offsetof(struct ieee80211_mgmt,
1641 u.probe_resp.variable);
1643 ies = f->u.probe_resp.variable;
1645 *ies_len = proberesp_len - hlen;
1651 static int _wil_cfg80211_set_ies(struct wil6210_vif *vif,
1652 struct cfg80211_beacon_data *bcon)
1655 u16 len = 0, proberesp_len = 0;
1656 u8 *ies = NULL, *proberesp;
1658 /* update local storage used for AP recovery */
1659 wil_memdup_ie(&vif->proberesp, &vif->proberesp_len, bcon->probe_resp,
1660 bcon->probe_resp_len);
1661 wil_memdup_ie(&vif->proberesp_ies, &vif->proberesp_ies_len,
1662 bcon->proberesp_ies, bcon->proberesp_ies_len);
1663 wil_memdup_ie(&vif->assocresp_ies, &vif->assocresp_ies_len,
1664 bcon->assocresp_ies, bcon->assocresp_ies_len);
1666 proberesp = _wil_cfg80211_get_proberesp_ies(bcon->probe_resp,
1667 bcon->probe_resp_len,
1669 rc = _wil_cfg80211_merge_extra_ies(proberesp,
1671 bcon->proberesp_ies,
1672 bcon->proberesp_ies_len,
1678 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_RESP, len, ies);
1682 if (bcon->assocresp_ies)
1683 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP,
1684 bcon->assocresp_ies_len, bcon->assocresp_ies);
1686 rc = wmi_set_ie(vif, WMI_FRAME_ASSOC_RESP, len, ies);
1687 #if 0 /* to use beacon IE's, remove this #if 0 */
1691 rc = wmi_set_ie(vif, WMI_FRAME_BEACON,
1692 bcon->tail_len, bcon->tail);
1699 static int _wil_cfg80211_start_ap(struct wiphy *wiphy,
1700 struct net_device *ndev,
1701 const u8 *ssid, size_t ssid_len, u32 privacy,
1703 struct cfg80211_beacon_data *bcon,
1704 u8 hidden_ssid, u32 pbss)
1706 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1707 struct wil6210_vif *vif = ndev_to_vif(ndev);
1709 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1710 u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
1711 u8 is_go = (wdev->iftype == NL80211_IFTYPE_P2P_GO);
1712 u16 proberesp_len = 0;
1717 wmi_nettype = WMI_NETTYPE_P2P;
1719 wil_dbg_misc(wil, "start_ap: mid=%d, is_go=%d\n", vif->mid, is_go);
1720 if (is_go && !pbss) {
1721 wil_err(wil, "P2P GO must be in PBSS\n");
1725 wil_set_recovery_state(wil, fw_recovery_idle);
1727 proberesp = _wil_cfg80211_get_proberesp_ies(bcon->probe_resp,
1728 bcon->probe_resp_len,
1730 /* check that the probe response IEs has a MDE */
1731 if ((proberesp && proberesp_len > 0 &&
1732 cfg80211_find_ie(WLAN_EID_MOBILITY_DOMAIN,
1738 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING,
1739 wil->fw_capabilities)) {
1740 wil_err(wil, "FW does not support FT roaming\n");
1743 set_bit(wil_vif_ft_roam, vif->status);
1746 mutex_lock(&wil->mutex);
1748 if (!wil_has_other_active_ifaces(wil, ndev, true, false)) {
1755 rc = wmi_set_ssid(vif, ssid_len, ssid);
1759 rc = _wil_cfg80211_set_ies(vif, bcon);
1763 vif->privacy = privacy;
1764 vif->channel = chan;
1765 vif->hidden_ssid = hidden_ssid;
1768 memcpy(vif->ssid, ssid, ssid_len);
1769 vif->ssid_len = ssid_len;
1771 netif_carrier_on(ndev);
1772 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1773 wil6210_bus_request(wil, WIL_MAX_BUS_REQUEST_KBPS);
1775 rc = wmi_pcp_start(vif, bi, wmi_nettype, chan, hidden_ssid, is_go);
1779 rc = wil_bcast_init(vif);
1783 goto out; /* success */
1788 netif_carrier_off(ndev);
1789 if (!wil_has_other_active_ifaces(wil, ndev, false, true))
1790 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1792 mutex_unlock(&wil->mutex);
1796 void wil_cfg80211_ap_recovery(struct wil6210_priv *wil)
1799 struct wiphy *wiphy = wil_to_wiphy(wil);
1801 for (i = 0; i < wil->max_vifs; i++) {
1802 struct wil6210_vif *vif = wil->vifs[i];
1803 struct net_device *ndev;
1804 struct cfg80211_beacon_data bcon = {};
1805 struct key_params key_params = {};
1807 if (!vif || vif->ssid_len == 0)
1810 ndev = vif_to_ndev(vif);
1811 bcon.proberesp_ies = vif->proberesp_ies;
1812 bcon.assocresp_ies = vif->assocresp_ies;
1813 bcon.probe_resp = vif->proberesp;
1814 bcon.proberesp_ies_len = vif->proberesp_ies_len;
1815 bcon.assocresp_ies_len = vif->assocresp_ies_len;
1816 bcon.probe_resp_len = vif->proberesp_len;
1819 "AP (vif %d) recovery: privacy %d, bi %d, channel %d, hidden %d, pbss %d\n",
1820 i, vif->privacy, vif->bi, vif->channel,
1821 vif->hidden_ssid, vif->pbss);
1822 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
1823 vif->ssid, vif->ssid_len, true);
1824 rc = _wil_cfg80211_start_ap(wiphy, ndev,
1825 vif->ssid, vif->ssid_len,
1826 vif->privacy, vif->bi,
1827 vif->channel, &bcon,
1828 vif->hidden_ssid, vif->pbss);
1830 wil_err(wil, "vif %d recovery failed (%d)\n", i, rc);
1834 if (!vif->privacy || vif->gtk_len == 0)
1837 key_params.key = vif->gtk;
1838 key_params.key_len = vif->gtk_len;
1839 key_params.seq_len = IEEE80211_GCMP_PN_LEN;
1840 rc = wil_cfg80211_add_key(wiphy, ndev, vif->gtk_index, false,
1843 wil_err(wil, "vif %d recovery add key failed (%d)\n",
1848 static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
1849 struct net_device *ndev,
1850 struct cfg80211_beacon_data *bcon)
1852 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1853 struct wireless_dev *wdev = ndev->ieee80211_ptr;
1854 struct wil6210_vif *vif = ndev_to_vif(ndev);
1858 wil_dbg_misc(wil, "change_beacon, mid=%d\n", vif->mid);
1859 wil_print_bcon_data(bcon);
1862 cfg80211_find_ie(WLAN_EID_RSN, bcon->tail,
1866 memcpy(vif->ssid, wdev->ssid, wdev->ssid_len);
1867 vif->ssid_len = wdev->ssid_len;
1869 /* in case privacy has changed, need to restart the AP */
1870 if (vif->privacy != privacy) {
1871 wil_dbg_misc(wil, "privacy changed %d=>%d. Restarting AP\n",
1872 vif->privacy, privacy);
1874 rc = _wil_cfg80211_start_ap(wiphy, ndev, vif->ssid,
1875 vif->ssid_len, privacy,
1876 wdev->beacon_interval,
1881 rc = _wil_cfg80211_set_ies(vif, bcon);
1887 static int wil_cfg80211_start_ap(struct wiphy *wiphy,
1888 struct net_device *ndev,
1889 struct cfg80211_ap_settings *info)
1892 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1893 struct ieee80211_channel *channel = info->chandef.chan;
1894 struct cfg80211_beacon_data *bcon = &info->beacon;
1895 struct cfg80211_crypto_settings *crypto = &info->crypto;
1898 wil_dbg_misc(wil, "start_ap\n");
1901 wil_err(wil, "AP: No channel???\n");
1905 switch (info->hidden_ssid) {
1906 case NL80211_HIDDEN_SSID_NOT_IN_USE:
1907 hidden_ssid = WMI_HIDDEN_SSID_DISABLED;
1910 case NL80211_HIDDEN_SSID_ZERO_LEN:
1911 hidden_ssid = WMI_HIDDEN_SSID_SEND_EMPTY;
1914 case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
1915 hidden_ssid = WMI_HIDDEN_SSID_CLEAR;
1919 wil_err(wil, "AP: Invalid hidden SSID %d\n", info->hidden_ssid);
1922 wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
1923 channel->center_freq, info->privacy ? "secure" : "open");
1924 wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
1925 info->privacy, info->auth_type);
1926 wil_dbg_misc(wil, "Hidden SSID mode: %d\n",
1928 wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
1930 wil_dbg_misc(wil, "PBSS %d\n", info->pbss);
1931 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
1932 info->ssid, info->ssid_len, true);
1933 wil_print_bcon_data(bcon);
1934 wil_print_crypto(wil, crypto);
1936 rc = _wil_cfg80211_start_ap(wiphy, ndev,
1937 info->ssid, info->ssid_len, info->privacy,
1938 info->beacon_interval, channel->hw_value,
1939 bcon, hidden_ssid, info->pbss);
1944 static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
1945 struct net_device *ndev)
1947 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1948 struct wil6210_vif *vif = ndev_to_vif(ndev);
1951 wil_dbg_misc(wil, "stop_ap, mid=%d\n", vif->mid);
1953 netif_carrier_off(ndev);
1954 last = !wil_has_other_active_ifaces(wil, ndev, false, true);
1956 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1957 wil_set_recovery_state(wil, fw_recovery_idle);
1958 set_bit(wil_status_resetting, wil->status);
1961 mutex_lock(&wil->mutex);
1964 clear_bit(wil_vif_ft_roam, vif->status);
1966 wil_memdup_ie(&vif->proberesp, &vif->proberesp_len, NULL, 0);
1967 wil_memdup_ie(&vif->proberesp_ies, &vif->proberesp_ies_len, NULL, 0);
1968 wil_memdup_ie(&vif->assocresp_ies, &vif->assocresp_ies_len, NULL, 0);
1969 memset(vif->gtk, 0, WMI_MAX_KEY_LEN);
1975 wil_bcast_fini(vif);
1977 mutex_unlock(&wil->mutex);
1982 static int wil_cfg80211_add_station(struct wiphy *wiphy,
1983 struct net_device *dev,
1985 struct station_parameters *params)
1987 struct wil6210_vif *vif = ndev_to_vif(dev);
1988 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
1990 wil_dbg_misc(wil, "add station %pM aid %d mid %d mask 0x%x set 0x%x\n",
1991 mac, params->aid, vif->mid,
1992 params->sta_flags_mask, params->sta_flags_set);
1994 if (!disable_ap_sme) {
1995 wil_err(wil, "not supported with AP SME enabled\n");
1999 if (params->aid > WIL_MAX_DMG_AID) {
2000 wil_err(wil, "invalid aid\n");
2004 return wmi_new_sta(vif, mac, params->aid);
2007 static int wil_cfg80211_del_station(struct wiphy *wiphy,
2008 struct net_device *dev,
2009 struct station_del_parameters *params)
2011 struct wil6210_vif *vif = ndev_to_vif(dev);
2012 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2014 wil_dbg_misc(wil, "del_station: %pM, reason=%d mid=%d\n",
2015 params->mac, params->reason_code, vif->mid);
2017 mutex_lock(&wil->mutex);
2018 wil6210_disconnect(vif, params->mac, params->reason_code);
2019 mutex_unlock(&wil->mutex);
2024 static int wil_cfg80211_change_station(struct wiphy *wiphy,
2025 struct net_device *dev,
2027 struct station_parameters *params)
2029 struct wil6210_vif *vif = ndev_to_vif(dev);
2030 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2033 struct wil_ring_tx_data *txdata = NULL;
2035 wil_dbg_misc(wil, "change station %pM mask 0x%x set 0x%x mid %d\n",
2036 mac, params->sta_flags_mask, params->sta_flags_set,
2039 if (!disable_ap_sme) {
2040 wil_dbg_misc(wil, "not supported with AP SME enabled\n");
2044 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
2047 cid = wil_find_cid(wil, vif->mid, mac);
2049 wil_err(wil, "station not found\n");
2053 for (i = 0; i < ARRAY_SIZE(wil->ring2cid_tid); i++)
2054 if (wil->ring2cid_tid[i][0] == cid) {
2055 txdata = &wil->ring_tx_data[i];
2060 wil_err(wil, "ring data not found\n");
2064 authorize = params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED);
2065 txdata->dot1x_open = authorize ? 1 : 0;
2066 wil_dbg_misc(wil, "cid %d ring %d authorize %d\n", cid, i,
2067 txdata->dot1x_open);
2072 /* probe_client handling */
2073 static void wil_probe_client_handle(struct wil6210_priv *wil,
2074 struct wil6210_vif *vif,
2075 struct wil_probe_client_req *req)
2077 struct net_device *ndev = vif_to_ndev(vif);
2078 struct wil_sta_info *sta = &wil->sta[req->cid];
2079 /* assume STA is alive if it is still connected,
2080 * else FW will disconnect it
2082 bool alive = (sta->status == wil_sta_connected);
2084 cfg80211_probe_status(ndev, sta->addr, req->cookie, alive,
2085 0, false, GFP_KERNEL);
2088 static struct list_head *next_probe_client(struct wil6210_vif *vif)
2090 struct list_head *ret = NULL;
2092 mutex_lock(&vif->probe_client_mutex);
2094 if (!list_empty(&vif->probe_client_pending)) {
2095 ret = vif->probe_client_pending.next;
2099 mutex_unlock(&vif->probe_client_mutex);
2104 void wil_probe_client_worker(struct work_struct *work)
2106 struct wil6210_vif *vif = container_of(work, struct wil6210_vif,
2107 probe_client_worker);
2108 struct wil6210_priv *wil = vif_to_wil(vif);
2109 struct wil_probe_client_req *req;
2110 struct list_head *lh;
2112 while ((lh = next_probe_client(vif)) != NULL) {
2113 req = list_entry(lh, struct wil_probe_client_req, list);
2115 wil_probe_client_handle(wil, vif, req);
2120 void wil_probe_client_flush(struct wil6210_vif *vif)
2122 struct wil_probe_client_req *req, *t;
2123 struct wil6210_priv *wil = vif_to_wil(vif);
2125 wil_dbg_misc(wil, "probe_client_flush\n");
2127 mutex_lock(&vif->probe_client_mutex);
2129 list_for_each_entry_safe(req, t, &vif->probe_client_pending, list) {
2130 list_del(&req->list);
2134 mutex_unlock(&vif->probe_client_mutex);
2137 static int wil_cfg80211_probe_client(struct wiphy *wiphy,
2138 struct net_device *dev,
2139 const u8 *peer, u64 *cookie)
2141 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2142 struct wil6210_vif *vif = ndev_to_vif(dev);
2143 struct wil_probe_client_req *req;
2144 int cid = wil_find_cid(wil, vif->mid, peer);
2146 wil_dbg_misc(wil, "probe_client: %pM => CID %d MID %d\n",
2147 peer, cid, vif->mid);
2152 req = kzalloc(sizeof(*req), GFP_KERNEL);
2159 mutex_lock(&vif->probe_client_mutex);
2160 list_add_tail(&req->list, &vif->probe_client_pending);
2161 mutex_unlock(&vif->probe_client_mutex);
2163 *cookie = req->cookie;
2164 queue_work(wil->wq_service, &vif->probe_client_worker);
2168 static int wil_cfg80211_change_bss(struct wiphy *wiphy,
2169 struct net_device *dev,
2170 struct bss_parameters *params)
2172 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2173 struct wil6210_vif *vif = ndev_to_vif(dev);
2175 if (params->ap_isolate >= 0) {
2176 wil_dbg_misc(wil, "change_bss: ap_isolate MID %d, %d => %d\n",
2177 vif->mid, vif->ap_isolate, params->ap_isolate);
2178 vif->ap_isolate = params->ap_isolate;
2184 static int wil_cfg80211_set_power_mgmt(struct wiphy *wiphy,
2185 struct net_device *dev,
2186 bool enabled, int timeout)
2188 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2189 enum wmi_ps_profile_type ps_profile;
2191 wil_dbg_misc(wil, "enabled=%d, timeout=%d\n",
2195 ps_profile = WMI_PS_PROFILE_TYPE_DEFAULT;
2197 ps_profile = WMI_PS_PROFILE_TYPE_PS_DISABLED;
2199 return wil_ps_update(wil, ps_profile);
2202 static int wil_cfg80211_suspend(struct wiphy *wiphy,
2203 struct cfg80211_wowlan *wow)
2205 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2208 /* Setting the wakeup trigger based on wow is TBD */
2210 if (test_bit(wil_status_suspended, wil->status)) {
2211 wil_dbg_pm(wil, "trying to suspend while suspended\n");
2215 rc = wil_can_suspend(wil, false);
2219 wil_dbg_pm(wil, "suspending\n");
2221 mutex_lock(&wil->mutex);
2222 mutex_lock(&wil->vif_mutex);
2223 wil_p2p_stop_radio_operations(wil);
2224 wil_abort_scan_all_vifs(wil, true);
2225 mutex_unlock(&wil->vif_mutex);
2226 mutex_unlock(&wil->mutex);
2232 static int wil_cfg80211_resume(struct wiphy *wiphy)
2234 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2236 wil_dbg_pm(wil, "resuming\n");
2242 wil_cfg80211_sched_scan_start(struct wiphy *wiphy,
2243 struct net_device *dev,
2244 struct cfg80211_sched_scan_request *request)
2246 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2247 struct wil6210_vif *vif = ndev_to_vif(dev);
2254 "sched scan start: n_ssids %d, ie_len %zu, flags 0x%x\n",
2255 request->n_ssids, request->ie_len, request->flags);
2256 for (i = 0; i < request->n_ssids; i++) {
2257 wil_dbg_misc(wil, "SSID[%d]:", i);
2258 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2259 request->ssids[i].ssid,
2260 request->ssids[i].ssid_len, true);
2262 wil_dbg_misc(wil, "channels:");
2263 for (i = 0; i < request->n_channels; i++)
2264 wil_dbg_misc(wil, " %d%s", request->channels[i]->hw_value,
2265 i == request->n_channels - 1 ? "\n" : "");
2266 wil_dbg_misc(wil, "n_match_sets %d, min_rssi_thold %d, delay %d\n",
2267 request->n_match_sets, request->min_rssi_thold,
2269 for (i = 0; i < request->n_match_sets; i++) {
2270 struct cfg80211_match_set *ms = &request->match_sets[i];
2272 wil_dbg_misc(wil, "MATCHSET[%d]: rssi_thold %d\n",
2274 wil_hex_dump_misc("SSID ", DUMP_PREFIX_OFFSET, 16, 1,
2276 ms->ssid.ssid_len, true);
2278 wil_dbg_misc(wil, "n_scan_plans %d\n", request->n_scan_plans);
2279 for (i = 0; i < request->n_scan_plans; i++) {
2280 struct cfg80211_sched_scan_plan *sp = &request->scan_plans[i];
2282 wil_dbg_misc(wil, "SCAN PLAN[%d]: interval %d iterations %d\n",
2283 i, sp->interval, sp->iterations);
2286 rc = wmi_set_ie(vif, WMI_FRAME_PROBE_REQ,
2287 request->ie_len, request->ie);
2290 return wmi_start_sched_scan(wil, request);
2294 wil_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2297 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2298 struct wil6210_vif *vif = ndev_to_vif(dev);
2304 rc = wmi_stop_sched_scan(wil);
2305 /* device would return error if it thinks PNO is already stopped.
2306 * ignore the return code so user space and driver gets back in-sync
2308 wil_dbg_misc(wil, "sched scan stopped (%d)\n", rc);
2314 wil_cfg80211_update_ft_ies(struct wiphy *wiphy, struct net_device *dev,
2315 struct cfg80211_update_ft_ies_params *ftie)
2317 struct wil6210_priv *wil = wiphy_to_wil(wiphy);
2318 struct wil6210_vif *vif = ndev_to_vif(dev);
2319 struct cfg80211_bss *bss;
2320 struct wmi_ft_reassoc_cmd reassoc;
2323 wil_dbg_misc(wil, "update ft ies, mid=%d\n", vif->mid);
2324 wil_hex_dump_misc("FT IE ", DUMP_PREFIX_OFFSET, 16, 1,
2325 ftie->ie, ftie->ie_len, true);
2327 if (!test_bit(WMI_FW_CAPABILITY_FT_ROAMING, wil->fw_capabilities)) {
2328 wil_err(wil, "FW does not support FT roaming\n");
2332 rc = wmi_update_ft_ies(vif, ftie->ie_len, ftie->ie);
2336 if (!test_bit(wil_vif_ft_roam, vif->status))
2337 /* vif is not roaming */
2340 /* wil_vif_ft_roam is set. wil_cfg80211_update_ft_ies is used as
2341 * a trigger for reassoc
2346 wil_err(wil, "FT: bss is NULL\n");
2350 memset(&reassoc, 0, sizeof(reassoc));
2351 ether_addr_copy(reassoc.bssid, bss->bssid);
2353 rc = wmi_send(wil, WMI_FT_REASSOC_CMDID, vif->mid,
2354 &reassoc, sizeof(reassoc));
2356 wil_err(wil, "FT: reassoc failed (%d)\n", rc);
2361 static const struct cfg80211_ops wil_cfg80211_ops = {
2362 .add_virtual_intf = wil_cfg80211_add_iface,
2363 .del_virtual_intf = wil_cfg80211_del_iface,
2364 .scan = wil_cfg80211_scan,
2365 .abort_scan = wil_cfg80211_abort_scan,
2366 .connect = wil_cfg80211_connect,
2367 .disconnect = wil_cfg80211_disconnect,
2368 .set_wiphy_params = wil_cfg80211_set_wiphy_params,
2369 .change_virtual_intf = wil_cfg80211_change_iface,
2370 .get_station = wil_cfg80211_get_station,
2371 .dump_station = wil_cfg80211_dump_station,
2372 .remain_on_channel = wil_remain_on_channel,
2373 .cancel_remain_on_channel = wil_cancel_remain_on_channel,
2374 .mgmt_tx = wil_cfg80211_mgmt_tx,
2375 .set_monitor_channel = wil_cfg80211_set_channel,
2376 .add_key = wil_cfg80211_add_key,
2377 .del_key = wil_cfg80211_del_key,
2378 .set_default_key = wil_cfg80211_set_default_key,
2380 .change_beacon = wil_cfg80211_change_beacon,
2381 .start_ap = wil_cfg80211_start_ap,
2382 .stop_ap = wil_cfg80211_stop_ap,
2383 .add_station = wil_cfg80211_add_station,
2384 .del_station = wil_cfg80211_del_station,
2385 .change_station = wil_cfg80211_change_station,
2386 .probe_client = wil_cfg80211_probe_client,
2387 .change_bss = wil_cfg80211_change_bss,
2389 .start_p2p_device = wil_cfg80211_start_p2p_device,
2390 .stop_p2p_device = wil_cfg80211_stop_p2p_device,
2391 .set_power_mgmt = wil_cfg80211_set_power_mgmt,
2392 .suspend = wil_cfg80211_suspend,
2393 .resume = wil_cfg80211_resume,
2394 .sched_scan_start = wil_cfg80211_sched_scan_start,
2395 .sched_scan_stop = wil_cfg80211_sched_scan_stop,
2396 .update_ft_ies = wil_cfg80211_update_ft_ies,
2399 static void wil_wiphy_init(struct wiphy *wiphy)
2401 wiphy->max_scan_ssids = 1;
2402 wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
2403 wiphy->max_remain_on_channel_duration = WIL_MAX_ROC_DURATION_MS;
2404 wiphy->max_num_pmkids = 0 /* TODO: */;
2405 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2406 BIT(NL80211_IFTYPE_AP) |
2407 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2408 BIT(NL80211_IFTYPE_P2P_GO) |
2409 BIT(NL80211_IFTYPE_P2P_DEVICE) |
2410 BIT(NL80211_IFTYPE_MONITOR);
2411 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
2412 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
2413 WIPHY_FLAG_PS_ON_BY_DEFAULT;
2414 if (!disable_ap_sme)
2415 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
2416 dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
2417 __func__, wiphy->flags);
2418 wiphy->probe_resp_offload =
2419 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
2420 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
2421 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
2423 wiphy->bands[NL80211_BAND_60GHZ] = &wil_band_60ghz;
2425 /* may change after reading FW capabilities */
2426 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2428 wiphy->cipher_suites = wil_cipher_suites;
2429 wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
2430 wiphy->mgmt_stypes = wil_mgmt_stypes;
2431 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
2433 wiphy->n_vendor_commands = ARRAY_SIZE(wil_nl80211_vendor_commands);
2434 wiphy->vendor_commands = wil_nl80211_vendor_commands;
2437 wiphy->wowlan = &wil_wowlan_support;
2441 int wil_cfg80211_iface_combinations_from_fw(
2442 struct wil6210_priv *wil, const struct wil_fw_record_concurrency *conc)
2444 struct wiphy *wiphy = wil_to_wiphy(wil);
2445 u32 total_limits = 0;
2447 const struct wil_fw_concurrency_combo *combo;
2448 const struct wil_fw_concurrency_limit *limit;
2449 struct ieee80211_iface_combination *iface_combinations;
2450 struct ieee80211_iface_limit *iface_limit;
2453 if (wiphy->iface_combinations) {
2454 wil_dbg_misc(wil, "iface_combinations already set, skipping\n");
2458 combo = conc->combos;
2459 n_combos = le16_to_cpu(conc->n_combos);
2460 for (i = 0; i < n_combos; i++) {
2461 total_limits += combo->n_limits;
2462 limit = combo->limits + combo->n_limits;
2463 combo = (struct wil_fw_concurrency_combo *)limit;
2466 iface_combinations =
2467 kzalloc(n_combos * sizeof(struct ieee80211_iface_combination) +
2468 total_limits * sizeof(struct ieee80211_iface_limit),
2470 if (!iface_combinations)
2472 iface_limit = (struct ieee80211_iface_limit *)(iface_combinations +
2474 combo = conc->combos;
2475 for (i = 0; i < n_combos; i++) {
2476 iface_combinations[i].max_interfaces = combo->max_interfaces;
2477 iface_combinations[i].num_different_channels =
2478 combo->n_diff_channels;
2479 iface_combinations[i].beacon_int_infra_match =
2481 iface_combinations[i].n_limits = combo->n_limits;
2483 "iface_combination %d: max_if %d, num_ch %d, bi_match %d\n",
2484 i, iface_combinations[i].max_interfaces,
2485 iface_combinations[i].num_different_channels,
2486 iface_combinations[i].beacon_int_infra_match);
2487 limit = combo->limits;
2488 for (j = 0; j < combo->n_limits; j++) {
2489 iface_limit[j].max = le16_to_cpu(limit[j].max);
2490 iface_limit[j].types = le16_to_cpu(limit[j].types);
2492 "limit %d: max %d types 0x%x\n", j,
2493 iface_limit[j].max, iface_limit[j].types);
2495 iface_combinations[i].limits = iface_limit;
2496 iface_limit += combo->n_limits;
2497 limit += combo->n_limits;
2498 combo = (struct wil_fw_concurrency_combo *)limit;
2501 wil_dbg_misc(wil, "multiple VIFs supported, n_mids %d\n", conc->n_mids);
2502 wil->max_vifs = conc->n_mids + 1; /* including main interface */
2503 if (wil->max_vifs > WIL_MAX_VIFS) {
2504 wil_info(wil, "limited number of VIFs supported(%d, FW %d)\n",
2505 WIL_MAX_VIFS, wil->max_vifs);
2506 wil->max_vifs = WIL_MAX_VIFS;
2508 wiphy->n_iface_combinations = n_combos;
2509 wiphy->iface_combinations = iface_combinations;
2513 struct wil6210_priv *wil_cfg80211_init(struct device *dev)
2515 struct wiphy *wiphy;
2516 struct wil6210_priv *wil;
2517 struct ieee80211_channel *ch;
2519 dev_dbg(dev, "%s()\n", __func__);
2521 /* Note: the wireless_dev structure is no longer allocated here.
2522 * Instead, it is allocated as part of the net_device structure
2523 * for main interface and each VIF.
2525 wiphy = wiphy_new(&wil_cfg80211_ops, sizeof(struct wil6210_priv));
2527 return ERR_PTR(-ENOMEM);
2529 set_wiphy_dev(wiphy, dev);
2530 wil_wiphy_init(wiphy);
2532 wil = wiphy_to_wil(wiphy);
2535 /* default monitor channel */
2536 ch = wiphy->bands[NL80211_BAND_60GHZ]->channels;
2537 cfg80211_chandef_create(&wil->monitor_chandef, ch, NL80211_CHAN_NO_HT);
2542 void wil_cfg80211_deinit(struct wil6210_priv *wil)
2544 struct wiphy *wiphy = wil_to_wiphy(wil);
2546 dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
2551 kfree(wiphy->iface_combinations);
2552 wiphy->iface_combinations = NULL;
2555 /* do not access wil6210_priv after returning from here */
2558 void wil_p2p_wdev_free(struct wil6210_priv *wil)
2560 struct wireless_dev *p2p_wdev;
2562 mutex_lock(&wil->vif_mutex);
2563 p2p_wdev = wil->p2p_wdev;
2564 wil->p2p_wdev = NULL;
2565 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
2566 mutex_unlock(&wil->vif_mutex);
2568 cfg80211_unregister_wdev(p2p_wdev);
2573 static int wil_rf_sector_status_to_rc(u8 status)
2576 case WMI_RF_SECTOR_STATUS_SUCCESS:
2578 case WMI_RF_SECTOR_STATUS_BAD_PARAMETERS_ERROR:
2580 case WMI_RF_SECTOR_STATUS_BUSY_ERROR:
2582 case WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR:
2589 static int wil_rf_sector_get_cfg(struct wiphy *wiphy,
2590 struct wireless_dev *wdev,
2591 const void *data, int data_len)
2593 struct wil6210_priv *wil = wdev_to_wil(wdev);
2594 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2596 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2600 struct wmi_get_rf_sector_params_cmd cmd;
2602 struct wmi_cmd_hdr wmi;
2603 struct wmi_get_rf_sector_params_done_event evt;
2604 } __packed reply = {
2605 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2607 struct sk_buff *msg;
2608 struct nlattr *nl_cfgs, *nl_cfg;
2610 struct wmi_rf_sector_info *si;
2612 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2615 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2616 wil_rf_sector_policy, NULL);
2618 wil_err(wil, "Invalid rf sector ATTR\n");
2622 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2623 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2624 !tb[QCA_ATTR_DMG_RF_MODULE_MASK]) {
2625 wil_err(wil, "Invalid rf sector spec\n");
2629 sector_index = nla_get_u16(
2630 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2631 if (sector_index >= WIL_MAX_RF_SECTORS) {
2632 wil_err(wil, "Invalid sector index %d\n", sector_index);
2636 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2637 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2638 wil_err(wil, "Invalid sector type %d\n", sector_type);
2642 rf_modules_vec = nla_get_u32(
2643 tb[QCA_ATTR_DMG_RF_MODULE_MASK]);
2644 if (rf_modules_vec >= BIT(WMI_MAX_RF_MODULES_NUM)) {
2645 wil_err(wil, "Invalid rf module mask 0x%x\n", rf_modules_vec);
2649 cmd.sector_idx = cpu_to_le16(sector_index);
2650 cmd.sector_type = sector_type;
2651 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2652 rc = wmi_call(wil, WMI_GET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2653 &cmd, sizeof(cmd), WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID,
2654 &reply, sizeof(reply),
2658 if (reply.evt.status) {
2659 wil_err(wil, "get rf sector cfg failed with status %d\n",
2661 return wil_rf_sector_status_to_rc(reply.evt.status);
2664 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2665 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2669 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2670 le64_to_cpu(reply.evt.tsf),
2672 goto nla_put_failure;
2674 nl_cfgs = nla_nest_start(msg, QCA_ATTR_DMG_RF_SECTOR_CFG);
2676 goto nla_put_failure;
2677 for (i = 0; i < WMI_MAX_RF_MODULES_NUM; i++) {
2678 if (!(rf_modules_vec & BIT(i)))
2680 nl_cfg = nla_nest_start(msg, i);
2682 goto nla_put_failure;
2683 si = &reply.evt.sectors_info[i];
2684 if (nla_put_u8(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX,
2686 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0,
2687 le32_to_cpu(si->etype0)) ||
2688 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1,
2689 le32_to_cpu(si->etype1)) ||
2690 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2,
2691 le32_to_cpu(si->etype2)) ||
2692 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI,
2693 le32_to_cpu(si->psh_hi)) ||
2694 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO,
2695 le32_to_cpu(si->psh_lo)) ||
2696 nla_put_u32(msg, QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16,
2697 le32_to_cpu(si->dtype_swch_off)))
2698 goto nla_put_failure;
2699 nla_nest_end(msg, nl_cfg);
2702 nla_nest_end(msg, nl_cfgs);
2703 rc = cfg80211_vendor_cmd_reply(msg);
2710 static int wil_rf_sector_set_cfg(struct wiphy *wiphy,
2711 struct wireless_dev *wdev,
2712 const void *data, int data_len)
2714 struct wil6210_priv *wil = wdev_to_wil(wdev);
2715 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2717 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2718 struct nlattr *tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MAX + 1];
2719 u16 sector_index, rf_module_index;
2721 u32 rf_modules_vec = 0;
2722 struct wmi_set_rf_sector_params_cmd cmd;
2724 struct wmi_cmd_hdr wmi;
2725 struct wmi_set_rf_sector_params_done_event evt;
2726 } __packed reply = {
2727 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2729 struct nlattr *nl_cfg;
2730 struct wmi_rf_sector_info *si;
2732 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2735 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2736 wil_rf_sector_policy, NULL);
2738 wil_err(wil, "Invalid rf sector ATTR\n");
2742 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2743 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE] ||
2744 !tb[QCA_ATTR_DMG_RF_SECTOR_CFG]) {
2745 wil_err(wil, "Invalid rf sector spec\n");
2749 sector_index = nla_get_u16(
2750 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2751 if (sector_index >= WIL_MAX_RF_SECTORS) {
2752 wil_err(wil, "Invalid sector index %d\n", sector_index);
2756 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2757 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2758 wil_err(wil, "Invalid sector type %d\n", sector_type);
2762 memset(&cmd, 0, sizeof(cmd));
2764 cmd.sector_idx = cpu_to_le16(sector_index);
2765 cmd.sector_type = sector_type;
2766 nla_for_each_nested(nl_cfg, tb[QCA_ATTR_DMG_RF_SECTOR_CFG],
2768 rc = nla_parse_nested(tb2, QCA_ATTR_DMG_RF_SECTOR_CFG_MAX,
2769 nl_cfg, wil_rf_sector_cfg_policy,
2772 wil_err(wil, "invalid sector cfg\n");
2776 if (!tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX] ||
2777 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0] ||
2778 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1] ||
2779 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2] ||
2780 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI] ||
2781 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO] ||
2782 !tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]) {
2783 wil_err(wil, "missing cfg params\n");
2787 rf_module_index = nla_get_u8(
2788 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_MODULE_INDEX]);
2789 if (rf_module_index >= WMI_MAX_RF_MODULES_NUM) {
2790 wil_err(wil, "invalid RF module index %d\n",
2794 rf_modules_vec |= BIT(rf_module_index);
2795 si = &cmd.sectors_info[rf_module_index];
2796 si->etype0 = cpu_to_le32(nla_get_u32(
2797 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE0]));
2798 si->etype1 = cpu_to_le32(nla_get_u32(
2799 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE1]));
2800 si->etype2 = cpu_to_le32(nla_get_u32(
2801 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_ETYPE2]));
2802 si->psh_hi = cpu_to_le32(nla_get_u32(
2803 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_HI]));
2804 si->psh_lo = cpu_to_le32(nla_get_u32(
2805 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_PSH_LO]));
2806 si->dtype_swch_off = cpu_to_le32(nla_get_u32(
2807 tb2[QCA_ATTR_DMG_RF_SECTOR_CFG_DTYPE_X16]));
2810 cmd.rf_modules_vec = rf_modules_vec & 0xFF;
2811 rc = wmi_call(wil, WMI_SET_RF_SECTOR_PARAMS_CMDID, vif->mid,
2812 &cmd, sizeof(cmd), WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID,
2813 &reply, sizeof(reply),
2817 return wil_rf_sector_status_to_rc(reply.evt.status);
2820 static int wil_rf_sector_get_selected(struct wiphy *wiphy,
2821 struct wireless_dev *wdev,
2822 const void *data, int data_len)
2824 struct wil6210_priv *wil = wdev_to_wil(wdev);
2825 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2827 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2828 u8 sector_type, mac_addr[ETH_ALEN];
2830 struct wmi_get_selected_rf_sector_index_cmd cmd;
2832 struct wmi_cmd_hdr wmi;
2833 struct wmi_get_selected_rf_sector_index_done_event evt;
2834 } __packed reply = {
2835 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2837 struct sk_buff *msg;
2839 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2842 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2843 wil_rf_sector_policy, NULL);
2845 wil_err(wil, "Invalid rf sector ATTR\n");
2849 if (!tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2850 wil_err(wil, "Invalid rf sector spec\n");
2853 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2854 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2855 wil_err(wil, "Invalid sector type %d\n", sector_type);
2859 if (tb[QCA_ATTR_MAC_ADDR]) {
2860 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2861 cid = wil_find_cid(wil, vif->mid, mac_addr);
2863 wil_err(wil, "invalid MAC address %pM\n", mac_addr);
2867 if (test_bit(wil_vif_fwconnected, vif->status)) {
2868 wil_err(wil, "must specify MAC address when connected\n");
2873 memset(&cmd, 0, sizeof(cmd));
2875 cmd.sector_type = sector_type;
2876 rc = wmi_call(wil, WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID, vif->mid,
2878 WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2879 &reply, sizeof(reply),
2883 if (reply.evt.status) {
2884 wil_err(wil, "get rf selected sector cfg failed with status %d\n",
2886 return wil_rf_sector_status_to_rc(reply.evt.status);
2889 msg = cfg80211_vendor_cmd_alloc_reply_skb(
2890 wiphy, 64 * WMI_MAX_RF_MODULES_NUM);
2894 if (nla_put_u64_64bit(msg, QCA_ATTR_TSF,
2895 le64_to_cpu(reply.evt.tsf),
2897 nla_put_u16(msg, QCA_ATTR_DMG_RF_SECTOR_INDEX,
2898 le16_to_cpu(reply.evt.sector_idx)))
2899 goto nla_put_failure;
2901 rc = cfg80211_vendor_cmd_reply(msg);
2908 static int wil_rf_sector_wmi_set_selected(struct wil6210_priv *wil,
2909 u8 mid, u16 sector_index,
2910 u8 sector_type, u8 cid)
2912 struct wmi_set_selected_rf_sector_index_cmd cmd;
2914 struct wmi_cmd_hdr wmi;
2915 struct wmi_set_selected_rf_sector_index_done_event evt;
2916 } __packed reply = {
2917 .evt = {.status = WMI_RF_SECTOR_STATUS_NOT_SUPPORTED_ERROR},
2921 memset(&cmd, 0, sizeof(cmd));
2922 cmd.sector_idx = cpu_to_le16(sector_index);
2923 cmd.sector_type = sector_type;
2925 rc = wmi_call(wil, WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID, mid,
2927 WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID,
2928 &reply, sizeof(reply),
2932 return wil_rf_sector_status_to_rc(reply.evt.status);
2935 static int wil_rf_sector_set_selected(struct wiphy *wiphy,
2936 struct wireless_dev *wdev,
2937 const void *data, int data_len)
2939 struct wil6210_priv *wil = wdev_to_wil(wdev);
2940 struct wil6210_vif *vif = wdev_to_vif(wil, wdev);
2942 struct nlattr *tb[QCA_ATTR_DMG_RF_SECTOR_MAX + 1];
2944 u8 sector_type, mac_addr[ETH_ALEN], i;
2947 if (!test_bit(WMI_FW_CAPABILITY_RF_SECTORS, wil->fw_capabilities))
2950 rc = nla_parse(tb, QCA_ATTR_DMG_RF_SECTOR_MAX, data, data_len,
2951 wil_rf_sector_policy, NULL);
2953 wil_err(wil, "Invalid rf sector ATTR\n");
2957 if (!tb[QCA_ATTR_DMG_RF_SECTOR_INDEX] ||
2958 !tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]) {
2959 wil_err(wil, "Invalid rf sector spec\n");
2963 sector_index = nla_get_u16(
2964 tb[QCA_ATTR_DMG_RF_SECTOR_INDEX]);
2965 if (sector_index >= WIL_MAX_RF_SECTORS &&
2966 sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2967 wil_err(wil, "Invalid sector index %d\n", sector_index);
2971 sector_type = nla_get_u8(tb[QCA_ATTR_DMG_RF_SECTOR_TYPE]);
2972 if (sector_type >= QCA_ATTR_DMG_RF_SECTOR_TYPE_MAX) {
2973 wil_err(wil, "Invalid sector type %d\n", sector_type);
2977 if (tb[QCA_ATTR_MAC_ADDR]) {
2978 ether_addr_copy(mac_addr, nla_data(tb[QCA_ATTR_MAC_ADDR]));
2979 if (!is_broadcast_ether_addr(mac_addr)) {
2980 cid = wil_find_cid(wil, vif->mid, mac_addr);
2982 wil_err(wil, "invalid MAC address %pM\n",
2987 if (sector_index != WMI_INVALID_RF_SECTOR_INDEX) {
2988 wil_err(wil, "broadcast MAC valid only with unlocking\n");
2994 if (test_bit(wil_vif_fwconnected, vif->status)) {
2995 wil_err(wil, "must specify MAC address when connected\n");
2998 /* otherwise, using cid=0 for unassociated station */
3002 rc = wil_rf_sector_wmi_set_selected(wil, vif->mid, sector_index,
3005 /* unlock all cids */
3006 rc = wil_rf_sector_wmi_set_selected(
3007 wil, vif->mid, WMI_INVALID_RF_SECTOR_INDEX,
3008 sector_type, WIL_CID_ALL);
3009 if (rc == -EINVAL) {
3010 for (i = 0; i < WIL6210_MAX_CID; i++) {
3011 if (wil->sta[i].mid != vif->mid)
3013 rc = wil_rf_sector_wmi_set_selected(
3015 WMI_INVALID_RF_SECTOR_INDEX,
3017 /* the FW will silently ignore and return
3018 * success for unused cid, so abort the loop
3019 * on any other error
3022 wil_err(wil, "unlock cid %d failed with status %d\n",